[NTDLL_WINETEST]
[reactos.git] / rostests / winetests / ntdll / string.c
1 /* Unit test suite for string functions and some wcstring functions
2 *
3 * Copyright 2003 Thomas Mertes
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 *
19 * NOTES
20 * We use function pointers here as there is no import library for NTDLL on
21 * windows.
22 */
23
24 #include <stdlib.h>
25
26 #include "ntdll_test.h"
27
28
29 /* Function ptrs for ntdll calls */
30 static HMODULE hntdll = 0;
31 static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);
32 static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING);
33 static BOOLEAN (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING,LPCSTR);
34 static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
35
36 static int (WINAPIV *patoi)(const char *);
37 static long (WINAPIV *patol)(const char *);
38 static LONGLONG (WINAPIV *p_atoi64)(const char *);
39 static LPSTR (WINAPIV *p_itoa)(int, LPSTR, INT);
40 static LPSTR (WINAPIV *p_ltoa)(long, LPSTR, INT);
41 static LPSTR (WINAPIV *p_ultoa)(unsigned long, LPSTR, INT);
42 static LPSTR (WINAPIV *p_i64toa)(LONGLONG, LPSTR, INT);
43 static LPSTR (WINAPIV *p_ui64toa)(ULONGLONG, LPSTR, INT);
44
45 static int (WINAPIV *p_wtoi)(LPWSTR);
46 static long (WINAPIV *p_wtol)(LPWSTR);
47 static LONGLONG (WINAPIV *p_wtoi64)(LPWSTR);
48 static LPWSTR (WINAPIV *p_itow)(int, LPWSTR, int);
49 static LPWSTR (WINAPIV *p_ltow)(long, LPWSTR, INT);
50 static LPWSTR (WINAPIV *p_ultow)(unsigned long, LPWSTR, INT);
51 static LPWSTR (WINAPIV *p_i64tow)(LONGLONG, LPWSTR, INT);
52 static LPWSTR (WINAPIV *p_ui64tow)(ULONGLONG, LPWSTR, INT);
53
54 static long (WINAPIV *pwcstol)(LPCWSTR, LPWSTR *, INT);
55 static ULONG (WINAPIV *pwcstoul)(LPCWSTR, LPWSTR *, INT);
56
57 static LPWSTR (WINAPIV *p_wcschr)(LPCWSTR, WCHAR);
58 static LPWSTR (WINAPIV *p_wcsrchr)(LPCWSTR, WCHAR);
59
60 static void InitFunctionPtrs(void)
61 {
62 hntdll = LoadLibraryA("ntdll.dll");
63 ok(hntdll != 0, "LoadLibrary failed\n");
64 if (hntdll) {
65 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
66 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
67 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
68 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
69
70 patoi = (void *)GetProcAddress(hntdll, "atoi");
71 patol = (void *)GetProcAddress(hntdll, "atol");
72 p_atoi64 = (void *)GetProcAddress(hntdll, "_atoi64");
73 p_itoa = (void *)GetProcAddress(hntdll, "_itoa");
74 p_ltoa = (void *)GetProcAddress(hntdll, "_ltoa");
75 p_ultoa = (void *)GetProcAddress(hntdll, "_ultoa");
76 p_i64toa = (void *)GetProcAddress(hntdll, "_i64toa");
77 p_ui64toa = (void *)GetProcAddress(hntdll, "_ui64toa");
78
79 p_wtoi = (void *)GetProcAddress(hntdll, "_wtoi");
80 p_wtol = (void *)GetProcAddress(hntdll, "_wtol");
81 p_wtoi64 = (void *)GetProcAddress(hntdll, "_wtoi64");
82 p_itow = (void *)GetProcAddress(hntdll, "_itow");
83 p_ltow = (void *)GetProcAddress(hntdll, "_ltow");
84 p_ultow = (void *)GetProcAddress(hntdll, "_ultow");
85 p_i64tow = (void *)GetProcAddress(hntdll, "_i64tow");
86 p_ui64tow = (void *)GetProcAddress(hntdll, "_ui64tow");
87
88 pwcstol = (void *)GetProcAddress(hntdll, "wcstol");
89 pwcstoul = (void *)GetProcAddress(hntdll, "wcstoul");
90
91 p_wcschr= (void *)GetProcAddress(hntdll, "wcschr");
92 p_wcsrchr= (void *)GetProcAddress(hntdll, "wcsrchr");
93 } /* if */
94 }
95
96
97 #define LARGE_STRI_BUFFER_LENGTH 67
98
99 typedef struct {
100 int base;
101 ULONG value;
102 const char *Buffer;
103 int mask; /* ntdll/msvcrt: 0x01=itoa, 0x02=ltoa, 0x04=ultoa */
104 /* 0x10=itow, 0x20=ltow, 0x40=ultow */
105 } ulong2str_t;
106
107 static const ulong2str_t ulong2str[] = {
108 {10, 123, "123\0---------------------------------------------------------------", 0x77},
109
110 { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x67},
111 { 2, -2147483647, "10000000000000000000000000000001\0----------------------------------", 0x67},
112 { 2, -65537, "11111111111111101111111111111111\0----------------------------------", 0x67},
113 { 2, -65536, "11111111111111110000000000000000\0----------------------------------", 0x67},
114 { 2, -65535, "11111111111111110000000000000001\0----------------------------------", 0x67},
115 { 2, -32768, "11111111111111111000000000000000\0----------------------------------", 0x67},
116 { 2, -32767, "11111111111111111000000000000001\0----------------------------------", 0x67},
117 { 2, -2, "11111111111111111111111111111110\0----------------------------------", 0x67},
118 { 2, -1, "11111111111111111111111111111111\0----------------------------------", 0x67},
119 { 2, 0, "0\0-----------------------------------------------------------------", 0x77},
120 { 2, 1, "1\0-----------------------------------------------------------------", 0x77},
121 { 2, 10, "1010\0--------------------------------------------------------------", 0x77},
122 { 2, 100, "1100100\0-----------------------------------------------------------", 0x77},
123 { 2, 1000, "1111101000\0--------------------------------------------------------", 0x77},
124 { 2, 10000, "10011100010000\0----------------------------------------------------", 0x77},
125 { 2, 32767, "111111111111111\0---------------------------------------------------", 0x77},
126 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x77},
127 { 2, 65535, "1111111111111111\0--------------------------------------------------", 0x77},
128 { 2, 100000, "11000011010100000\0-------------------------------------------------", 0x77},
129 { 2, 234567, "111001010001000111\0------------------------------------------------", 0x77},
130 { 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x77},
131 { 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x77},
132 { 2, 524288, "10000000000000000000\0----------------------------------------------", 0x67},
133 { 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x67},
134 { 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x67},
135 { 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x67},
136 { 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x67},
137 { 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x67},
138 { 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x67},
139 { 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x67},
140 { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x67},
141 { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x67},
142 { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x67},
143 { 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x67},
144
145 { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x77},
146 { 8, -2147483647, "20000000001\0-------------------------------------------------------", 0x77},
147 { 8, -2, "37777777776\0-------------------------------------------------------", 0x77},
148 { 8, -1, "37777777777\0-------------------------------------------------------", 0x77},
149 { 8, 0, "0\0-----------------------------------------------------------------", 0x77},
150 { 8, 1, "1\0-----------------------------------------------------------------", 0x77},
151 { 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x77},
152 { 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x77},
153 { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x77},
154 { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x77},
155 { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x77},
156 { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x77},
157
158 {10, 0x80000000U, "-2147483648\0-------------------------------------------------------", 0x33},
159 {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x44},
160 {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x33},
161 {10, -2147483647, "2147483649\0--------------------------------------------------------", 0x44},
162 {10, -2, "-2\0----------------------------------------------------------------", 0x33},
163 {10, -2, "4294967294\0--------------------------------------------------------", 0x44},
164 {10, -1, "-1\0----------------------------------------------------------------", 0x33},
165 {10, -1, "4294967295\0--------------------------------------------------------", 0x44},
166 {10, 0, "0\0-----------------------------------------------------------------", 0x77},
167 {10, 1, "1\0-----------------------------------------------------------------", 0x77},
168 {10, 12, "12\0----------------------------------------------------------------", 0x77},
169 {10, 123, "123\0---------------------------------------------------------------", 0x77},
170 {10, 1234, "1234\0--------------------------------------------------------------", 0x77},
171 {10, 12345, "12345\0-------------------------------------------------------------", 0x77},
172 {10, 123456, "123456\0------------------------------------------------------------", 0x77},
173 {10, 1234567, "1234567\0-----------------------------------------------------------", 0x77},
174 {10, 12345678, "12345678\0----------------------------------------------------------", 0x77},
175 {10, 123456789, "123456789\0---------------------------------------------------------", 0x77},
176 {10, 2147483646, "2147483646\0--------------------------------------------------------", 0x77},
177 {10, 2147483647, "2147483647\0--------------------------------------------------------", 0x77},
178 {10, 2147483648U, "-2147483648\0-------------------------------------------------------", 0x33},
179 {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x44},
180 {10, 2147483649U, "-2147483647\0-------------------------------------------------------", 0x33},
181 {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x44},
182 {10, 4294967294U, "-2\0----------------------------------------------------------------", 0x33},
183 {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x44},
184 {10, 4294967295U, "-1\0----------------------------------------------------------------", 0x33},
185 {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x44},
186
187 {16, 0, "0\0-----------------------------------------------------------------", 0x77},
188 {16, 1, "1\0-----------------------------------------------------------------", 0x77},
189 {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x77},
190 {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x77},
191 {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x77},
192 {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x77},
193 {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x77},
194 {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x77},
195
196 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x77},
197 { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x77},
198 { 2, 131072, "100000000000000000\0------------------------------------------------", 0x77},
199 {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x77},
200 {16, 0xa, "a\0-----------------------------------------------------------------", 0x77},
201 {16, 0, "0\0-----------------------------------------------------------------", 0x77},
202 {20, 3368421, "111111\0------------------------------------------------------------", 0x77},
203 {36, 62193781, "111111\0------------------------------------------------------------", 0x77},
204 {37, 71270178, "111111\0------------------------------------------------------------", 0x77},
205 };
206 #define NB_ULONG2STR (sizeof(ulong2str)/sizeof(*ulong2str))
207
208
209 static void one_itoa_test(int test_num, const ulong2str_t *ulong2str)
210 {
211 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
212 int value;
213 LPSTR result;
214
215 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
216 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
217 value = ulong2str->value;
218 result = p_itoa(value, dest_str, ulong2str->base);
219 ok(result == dest_str,
220 "(test %d): _itoa(%d, [out], %d) has result %p, expected: %p\n",
221 test_num, value, ulong2str->base, result, dest_str);
222 ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
223 "(test %d): _itoa(%d, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
224 test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);
225 }
226
227
228 static void one_ltoa_test(int test_num, const ulong2str_t *ulong2str)
229 {
230 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
231 long value;
232 LPSTR result;
233
234 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
235 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
236 value = ulong2str->value;
237 result = p_ltoa(ulong2str->value, dest_str, ulong2str->base);
238 ok(result == dest_str,
239 "(test %d): _ltoa(%ld, [out], %d) has result %p, expected: %p\n",
240 test_num, value, ulong2str->base, result, dest_str);
241 ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
242 "(test %d): _ltoa(%ld, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
243 test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);
244 }
245
246
247 static void one_ultoa_test(int test_num, const ulong2str_t *ulong2str)
248 {
249 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
250 unsigned long value;
251 LPSTR result;
252
253 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
254 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
255 value = ulong2str->value;
256 result = p_ultoa(ulong2str->value, dest_str, ulong2str->base);
257 ok(result == dest_str,
258 "(test %d): _ultoa(%lu, [out], %d) has result %p, expected: %p\n",
259 test_num, value, ulong2str->base, result, dest_str);
260 ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
261 "(test %d): _ultoa(%lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
262 test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);
263 }
264
265
266 static void test_ulongtoa(void)
267 {
268 int test_num;
269
270 for (test_num = 0; test_num < NB_ULONG2STR; test_num++) {
271 if (ulong2str[test_num].mask & 0x01) {
272 one_itoa_test(test_num, &ulong2str[test_num]);
273 } /* if */
274 if (ulong2str[test_num].mask & 0x02) {
275 one_ltoa_test(test_num, &ulong2str[test_num]);
276 } /* if */
277 if (ulong2str[test_num].mask & 0x04) {
278 one_ultoa_test(test_num, &ulong2str[test_num]);
279 } /* if */
280 } /* for */
281 }
282
283
284 static void one_itow_test(int test_num, const ulong2str_t *ulong2str)
285 {
286 int pos;
287 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
288 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
289 UNICODE_STRING unicode_string;
290 STRING ansi_str;
291 int value;
292 LPWSTR result;
293
294 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
295 expected_wstr[pos] = ulong2str->Buffer[pos];
296 } /* for */
297 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
298
299 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
300 dest_wstr[pos] = '-';
301 } /* for */
302 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
303 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
304 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
305 unicode_string.Buffer = dest_wstr;
306 value = ulong2str->value;
307 result = p_itow(value, dest_wstr, ulong2str->base);
308 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
309 ok(result == dest_wstr,
310 "(test %d): _itow(%d, [out], %d) has result %p, expected: %p\n",
311 test_num, value, ulong2str->base, result, dest_wstr);
312 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
313 "(test %d): _itow(%d, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
314 test_num, value, ulong2str->base, ansi_str.Buffer, ulong2str->Buffer);
315 pRtlFreeAnsiString(&ansi_str);
316 }
317
318
319 static void one_ltow_test(int test_num, const ulong2str_t *ulong2str)
320 {
321 int pos;
322 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
323 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
324 UNICODE_STRING unicode_string;
325 STRING ansi_str;
326 long value;
327 LPWSTR result;
328
329 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
330 expected_wstr[pos] = ulong2str->Buffer[pos];
331 } /* for */
332 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
333
334 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
335 dest_wstr[pos] = '-';
336 } /* for */
337 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
338 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
339 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
340 unicode_string.Buffer = dest_wstr;
341
342 value = ulong2str->value;
343 result = p_ltow(value, dest_wstr, ulong2str->base);
344 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
345 ok(result == dest_wstr,
346 "(test %d): _ltow(%ld, [out], %d) has result %p, expected: %p\n",
347 test_num, value, ulong2str->base, result, dest_wstr);
348 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
349 "(test %d): _ltow(%ld, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
350 test_num, value, ulong2str->base, ansi_str.Buffer, ulong2str->Buffer);
351 pRtlFreeAnsiString(&ansi_str);
352 }
353
354
355 static void one_ultow_test(int test_num, const ulong2str_t *ulong2str)
356 {
357 int pos;
358 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
359 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
360 UNICODE_STRING unicode_string;
361 STRING ansi_str;
362 unsigned long value;
363 LPWSTR result;
364
365 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
366 expected_wstr[pos] = ulong2str->Buffer[pos];
367 } /* for */
368 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
369
370 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
371 dest_wstr[pos] = '-';
372 } /* for */
373 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
374 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
375 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
376 unicode_string.Buffer = dest_wstr;
377
378 value = ulong2str->value;
379 result = p_ultow(value, dest_wstr, ulong2str->base);
380 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
381 ok(result == dest_wstr,
382 "(test %d): _ultow(%lu, [out], %d) has result %p, expected: %p\n",
383 test_num, value, ulong2str->base, result, dest_wstr);
384 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
385 "(test %d): _ultow(%lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
386 test_num, value, ulong2str->base, ansi_str.Buffer, ulong2str->Buffer);
387 pRtlFreeAnsiString(&ansi_str);
388 }
389
390
391 static void test_ulongtow(void)
392 {
393 int test_num;
394 LPWSTR result;
395
396 for (test_num = 0; test_num < NB_ULONG2STR; test_num++) {
397 if (ulong2str[test_num].mask & 0x10) {
398 one_itow_test(test_num, &ulong2str[test_num]);
399 } /* if */
400 if (ulong2str[test_num].mask & 0x20) {
401 one_ltow_test(test_num, &ulong2str[test_num]);
402 } /* if */
403 if (ulong2str[test_num].mask & 0x40) {
404 one_ultow_test(test_num, &ulong2str[test_num]);
405 } /* if */
406 } /* for */
407
408 if (0) {
409 /* Crashes on XP and W2K3 */
410 result = p_itow(ulong2str[0].value, NULL, 10);
411 ok(result == NULL,
412 "(test a): _itow(%d, NULL, 10) has result %p, expected: NULL\n",
413 ulong2str[0].value, result);
414 }
415
416 if (0) {
417 /* Crashes on XP and W2K3 */
418 result = p_ltow(ulong2str[0].value, NULL, 10);
419 ok(result == NULL,
420 "(test b): _ltow(%d, NULL, 10) has result %p, expected: NULL\n",
421 ulong2str[0].value, result);
422 }
423
424 if (0) {
425 /* Crashes on XP and W2K3 */
426 result = p_ultow(ulong2str[0].value, NULL, 10);
427 ok(result == NULL,
428 "(test c): _ultow(%d, NULL, 10) has result %p, expected: NULL\n",
429 ulong2str[0].value, result);
430 }
431 }
432
433 #define ULL(a,b) (((ULONGLONG)(a) << 32) | (b))
434
435 typedef struct {
436 int base;
437 ULONGLONG value;
438 const char *Buffer;
439 int mask; /* ntdll/msvcrt: 0x01=i64toa, 0x02=ui64toa, 0x04=wrong _i64toa try next example */
440 /* 0x10=i64tow, 0x20=ui64tow, 0x40=wrong _i64tow try next example */
441 } ulonglong2str_t;
442
443 static const ulonglong2str_t ulonglong2str[] = {
444 {10, 123, "123\0---------------------------------------------------------------", 0x33},
445
446 { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x33},
447 { 2, -2147483647, "1111111111111111111111111111111110000000000000000000000000000001\0--", 0x33},
448 { 2, -65537, "1111111111111111111111111111111111111111111111101111111111111111\0--", 0x33},
449 { 2, -65536, "1111111111111111111111111111111111111111111111110000000000000000\0--", 0x33},
450 { 2, -65535, "1111111111111111111111111111111111111111111111110000000000000001\0--", 0x33},
451 { 2, -32768, "1111111111111111111111111111111111111111111111111000000000000000\0--", 0x33},
452 { 2, -32767, "1111111111111111111111111111111111111111111111111000000000000001\0--", 0x33},
453 { 2, -2, "1111111111111111111111111111111111111111111111111111111111111110\0--", 0x33},
454 { 2, -1, "1111111111111111111111111111111111111111111111111111111111111111\0--", 0x33},
455 { 2, 0, "0\0-----------------------------------------------------------------", 0x33},
456 { 2, 1, "1\0-----------------------------------------------------------------", 0x33},
457 { 2, 10, "1010\0--------------------------------------------------------------", 0x33},
458 { 2, 100, "1100100\0-----------------------------------------------------------", 0x33},
459 { 2, 1000, "1111101000\0--------------------------------------------------------", 0x33},
460 { 2, 10000, "10011100010000\0----------------------------------------------------", 0x33},
461 { 2, 32767, "111111111111111\0---------------------------------------------------", 0x33},
462 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
463 { 2, 65535, "1111111111111111\0--------------------------------------------------", 0x33},
464 { 2, 100000, "11000011010100000\0-------------------------------------------------", 0x33},
465 { 2, 234567, "111001010001000111\0------------------------------------------------", 0x33},
466 { 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x33},
467 { 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x33},
468 { 2, 524288, "10000000000000000000\0----------------------------------------------", 0x33},
469 { 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x33},
470 { 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x33},
471 { 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x33},
472 { 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x33},
473 { 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x33},
474 { 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x33},
475 { 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x33},
476 { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x33},
477 { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x33},
478 { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x33},
479 { 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x33},
480 { 2, ULL(0x1,0xffffffff), "111111111111111111111111111111111\0---------------------------------", 0x33},
481 { 2, ((ULONGLONG)100000)*100000, "1001010100000010111110010000000000\0--------------------------------", 0x33},
482 { 2, ULL(0x3,0xffffffff), "1111111111111111111111111111111111\0--------------------------------", 0x33},
483 { 2, ULL(0x7,0xffffffff), "11111111111111111111111111111111111\0-------------------------------", 0x33},
484 { 2, ULL(0xf,0xffffffff), "111111111111111111111111111111111111\0------------------------------", 0x33},
485 { 2, ((ULONGLONG)100000)*1000000, "1011101001000011101101110100000000000\0-----------------------------", 0x33},
486 { 2, ULL(0x1f,0xffffffff), "1111111111111111111111111111111111111\0-----------------------------", 0x33},
487 { 2, ULL(0x3f,0xffffffff), "11111111111111111111111111111111111111\0----------------------------", 0x33},
488 { 2, ULL(0x7f,0xffffffff), "111111111111111111111111111111111111111\0---------------------------", 0x33},
489 { 2, ULL(0xff,0xffffffff), "1111111111111111111111111111111111111111\0--------------------------", 0x33},
490
491 { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x33},
492 { 8, -2147483647, "1777777777760000000001\0--------------------------------------------", 0x33},
493 { 8, -2, "1777777777777777777776\0--------------------------------------------", 0x33},
494 { 8, -1, "1777777777777777777777\0--------------------------------------------", 0x33},
495 { 8, 0, "0\0-----------------------------------------------------------------", 0x33},
496 { 8, 1, "1\0-----------------------------------------------------------------", 0x33},
497 { 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x33},
498 { 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x33},
499 { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x33},
500 { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x33},
501 { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x33},
502 { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x33},
503
504 {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x33},
505 {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x55},
506 {10, -2147483647, "-18446744071562067969\0---------------------------------------------", 0x00},
507 {10, -2147483647, "18446744071562067969\0----------------------------------------------", 0x22},
508 {10, -2, "-2\0----------------------------------------------------------------", 0x55},
509 {10, -2, "-18446744073709551614\0---------------------------------------------", 0x00},
510 {10, -2, "18446744073709551614\0----------------------------------------------", 0x22},
511 {10, -1, "-1\0----------------------------------------------------------------", 0x55},
512 {10, -1, "-18446744073709551615\0---------------------------------------------", 0x00},
513 {10, -1, "18446744073709551615\0----------------------------------------------", 0x22},
514 {10, 0, "0\0-----------------------------------------------------------------", 0x33},
515 {10, 1, "1\0-----------------------------------------------------------------", 0x33},
516 {10, 12, "12\0----------------------------------------------------------------", 0x33},
517 {10, 123, "123\0---------------------------------------------------------------", 0x33},
518 {10, 1234, "1234\0--------------------------------------------------------------", 0x33},
519 {10, 12345, "12345\0-------------------------------------------------------------", 0x33},
520 {10, 123456, "123456\0------------------------------------------------------------", 0x33},
521 {10, 1234567, "1234567\0-----------------------------------------------------------", 0x33},
522 {10, 12345678, "12345678\0----------------------------------------------------------", 0x33},
523 {10, 123456789, "123456789\0---------------------------------------------------------", 0x33},
524 {10, 2147483646, "2147483646\0--------------------------------------------------------", 0x33},
525 {10, 2147483647, "2147483647\0--------------------------------------------------------", 0x33},
526 {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x33},
527 {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x33},
528 {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x33},
529 {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x33},
530 {10, ULL(0x2,0xdfdc1c35), "12345678901\0-------------------------------------------------------", 0x33},
531 {10, ULL(0xe5,0xf4c8f374), "987654321012\0------------------------------------------------------", 0x33},
532 {10, ULL(0x1c0,0xfc161e3e), "1928374656574\0-----------------------------------------------------", 0x33},
533 {10, ULL(0xbad,0xcafeface), "12841062955726\0----------------------------------------------------", 0x33},
534 {10, ULL(0x5bad,0xcafeface), "100801993177806\0---------------------------------------------------", 0x33},
535 {10, ULL(0xaface,0xbeefcafe), "3090515640699646\0--------------------------------------------------", 0x33},
536 {10, ULL(0xa5beef,0xabcdcafe), "46653307746110206\0-------------------------------------------------", 0x33},
537 {10, ULL(0x1f8cf9b,0xf2df3af1), "142091656963767025\0------------------------------------------------", 0x33},
538 {10, ULL(0x0fffffff,0xffffffff), "1152921504606846975\0-----------------------------------------------", 0x33},
539 {10, ULL(0x7fffffff,0xffffffff), "9223372036854775807\0-----------------------------------------------", 0x33},
540 {10, ULL(0x80000000,0x00000000), "-9223372036854775808\0----------------------------------------------", 0x11},
541 {10, ULL(0x80000000,0x00000000), "9223372036854775808\0-----------------------------------------------", 0x22},
542 {10, ULL(0x80000000,0x00000001), "-9223372036854775807\0----------------------------------------------", 0x55},
543 {10, ULL(0x80000000,0x00000001), "-9223372036854775809\0----------------------------------------------", 0x00},
544 {10, ULL(0x80000000,0x00000001), "9223372036854775809\0-----------------------------------------------", 0x22},
545 {10, ULL(0x80000000,0x00000002), "-9223372036854775806\0----------------------------------------------", 0x55},
546 {10, ULL(0x80000000,0x00000002), "-9223372036854775810\0----------------------------------------------", 0x00},
547 {10, ULL(0x80000000,0x00000002), "9223372036854775810\0-----------------------------------------------", 0x22},
548 {10, ULL(0xffffffff,0xfffffffe), "-2\0----------------------------------------------------------------", 0x55},
549 {10, ULL(0xffffffff,0xfffffffe), "-18446744073709551614\0---------------------------------------------", 0x00},
550 {10, ULL(0xffffffff,0xfffffffe), "18446744073709551614\0----------------------------------------------", 0x22},
551 {10, ULL(0xffffffff,0xffffffff), "-1\0----------------------------------------------------------------", 0x55},
552 {10, ULL(0xffffffff,0xffffffff), "-18446744073709551615\0---------------------------------------------", 0x00},
553 {10, ULL(0xffffffff,0xffffffff), "18446744073709551615\0----------------------------------------------", 0x22},
554
555 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
556 {16, 1, "1\0-----------------------------------------------------------------", 0x33},
557 {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x33},
558 {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x33},
559 {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x33},
560 {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x33},
561 {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x33},
562 {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x33},
563 {16, ULL(0x1,0x00000000), "100000000\0---------------------------------------------------------", 0x33},
564 {16, ULL(0xbad,0xdeadbeef), "baddeadbeef\0-------------------------------------------------------", 0x33},
565 {16, ULL(0x80000000,0x00000000), "8000000000000000\0--------------------------------------------------", 0x33},
566 {16, ULL(0xfedcba98,0x76543210), "fedcba9876543210\0--------------------------------------------------", 0x33},
567 {16, ULL(0xffffffff,0x80000001), "ffffffff80000001\0--------------------------------------------------", 0x33},
568 {16, ULL(0xffffffff,0xfffffffe), "fffffffffffffffe\0--------------------------------------------------", 0x33},
569 {16, ULL(0xffffffff,0xffffffff), "ffffffffffffffff\0--------------------------------------------------", 0x33},
570
571 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
572 { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x33},
573 { 2, 131072, "100000000000000000\0------------------------------------------------", 0x33},
574 {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x33},
575 {16, 0xa, "a\0-----------------------------------------------------------------", 0x33},
576 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
577 {20, 3368421, "111111\0------------------------------------------------------------", 0x33},
578 {36, 62193781, "111111\0------------------------------------------------------------", 0x33},
579 {37, 71270178, "111111\0------------------------------------------------------------", 0x33},
580 {99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33},
581 };
582 #define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str))
583
584
585 static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
586 {
587 LPSTR result;
588 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
589
590 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
591 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
592 result = p_i64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
593 ok(result == dest_str,
594 "(test %d): _i64toa(%08x%08x, [out], %d) has result %p, expected: %p\n",
595 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
596 ulonglong2str->base, result, dest_str);
597 if (ulonglong2str->mask & 0x04) {
598 if (memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
599 if (memcmp(dest_str, ulonglong2str[1].Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
600 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
601 "(test %d): _i64toa(%08x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
602 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
603 ulonglong2str->base, dest_str, ulonglong2str->Buffer);
604 } /* if */
605 } /* if */
606 } else {
607 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
608 "(test %d): _i64toa(%08x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
609 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
610 ulonglong2str->base, dest_str, ulonglong2str->Buffer);
611 } /* if */
612 }
613
614
615 static void one_ui64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
616 {
617 LPSTR result;
618 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
619
620 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
621 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
622 result = p_ui64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
623 ok(result == dest_str,
624 "(test %d): _ui64toa(%08x%08x, [out], %d) has result %p, expected: %p\n",
625 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
626 ulonglong2str->base, result, dest_str);
627 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
628 "(test %d): _ui64toa(%08x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
629 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
630 ulonglong2str->base, dest_str, ulonglong2str->Buffer);
631 }
632
633
634 static void test_ulonglongtoa(void)
635 {
636 int test_num;
637
638 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
639 if (ulonglong2str[test_num].mask & 0x01) {
640 one_i64toa_test(test_num, &ulonglong2str[test_num]);
641 } /* if */
642 if (p_ui64toa != NULL) {
643 if (ulonglong2str[test_num].mask & 0x02) {
644 one_ui64toa_test(test_num, &ulonglong2str[test_num]);
645 } /* if */
646 } /* if */
647 } /* for */
648 }
649
650
651 static void one_i64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
652 {
653 int pos;
654 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
655 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
656 UNICODE_STRING unicode_string;
657 STRING ansi_str;
658 LPWSTR result;
659
660 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
661 expected_wstr[pos] = ulonglong2str->Buffer[pos];
662 } /* for */
663 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
664
665 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
666 dest_wstr[pos] = '-';
667 } /* for */
668 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
669 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
670 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
671 unicode_string.Buffer = dest_wstr;
672
673 result = p_i64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
674 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
675 ok(result == dest_wstr,
676 "(test %d): _i64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
677 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
678 ulonglong2str->base, result, dest_wstr);
679 if (ulonglong2str->mask & 0x04) {
680 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
681 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
682 expected_wstr[pos] = ulonglong2str[1].Buffer[pos];
683 } /* for */
684 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
685 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
686 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
687 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
688 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
689 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
690 } /* if */
691 } /* if */
692 } else {
693 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
694 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
695 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
696 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
697 } /* if */
698 pRtlFreeAnsiString(&ansi_str);
699 }
700
701
702 static void one_ui64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
703 {
704 int pos;
705 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
706 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
707 UNICODE_STRING unicode_string;
708 STRING ansi_str;
709 LPWSTR result;
710
711 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
712 expected_wstr[pos] = ulonglong2str->Buffer[pos];
713 } /* for */
714 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
715
716 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
717 dest_wstr[pos] = '-';
718 } /* for */
719 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
720 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
721 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
722 unicode_string.Buffer = dest_wstr;
723
724 result = p_ui64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
725 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
726 ok(result == dest_wstr,
727 "(test %d): _ui64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
728 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
729 ulonglong2str->base, result, dest_wstr);
730 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
731 "(test %d): _ui64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
732 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
733 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
734 pRtlFreeAnsiString(&ansi_str);
735 }
736
737
738 static void test_ulonglongtow(void)
739 {
740 int test_num;
741 LPWSTR result;
742
743 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
744 if (ulonglong2str[test_num].mask & 0x10) {
745 one_i64tow_test(test_num, &ulonglong2str[test_num]);
746 } /* if */
747 if (p_ui64tow) {
748 if (ulonglong2str[test_num].mask & 0x20) {
749 one_ui64tow_test(test_num, &ulonglong2str[test_num]);
750 } /* if */
751 } /* if */
752 } /* for */
753
754 if (0) {
755 /* Crashes on XP and W2K3 */
756 result = p_i64tow(ulonglong2str[0].value, NULL, 10);
757 ok(result == NULL,
758 "(test d): _i64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
759 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
760 }
761
762 if (p_ui64tow) {
763 if (0) {
764 /* Crashes on XP and W2K3 */
765 result = p_ui64tow(ulonglong2str[0].value, NULL, 10);
766 ok(result == NULL,
767 "(test e): _ui64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
768 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
769 }
770 } /* if */
771 }
772
773
774 typedef struct {
775 const char *str;
776 LONG value;
777 } str2long_t;
778
779 static const str2long_t str2long[] = {
780 { "1011101100", 1011101100 },
781 { "1234567", 1234567 },
782 { "-214", -214 },
783 { "+214", 214 }, /* The + sign is allowed also */
784 { "--214", 0 }, /* Do not accept more than one sign */
785 { "-+214", 0 },
786 { "++214", 0 },
787 { "+-214", 0 },
788 { "\00141", 0 }, /* not whitespace char 1 */
789 { "\00242", 0 }, /* not whitespace char 2 */
790 { "\00343", 0 }, /* not whitespace char 3 */
791 { "\00444", 0 }, /* not whitespace char 4 */
792 { "\00545", 0 }, /* not whitespace char 5 */
793 { "\00646", 0 }, /* not whitespace char 6 */
794 { "\00747", 0 }, /* not whitespace char 7 */
795 { "\01050", 0 }, /* not whitespace char 8 */
796 { "\01151", 51 }, /* is whitespace char 9 (tab) */
797 { "\01252", 52 }, /* is whitespace char 10 (lf) */
798 { "\01353", 53 }, /* is whitespace char 11 (vt) */
799 { "\01454", 54 }, /* is whitespace char 12 (ff) */
800 { "\01555", 55 }, /* is whitespace char 13 (cr) */
801 { "\01656", 0 }, /* not whitespace char 14 */
802 { "\01757", 0 }, /* not whitespace char 15 */
803 { "\02060", 0 }, /* not whitespace char 16 */
804 { "\02161", 0 }, /* not whitespace char 17 */
805 { "\02262", 0 }, /* not whitespace char 18 */
806 { "\02363", 0 }, /* not whitespace char 19 */
807 { "\02464", 0 }, /* not whitespace char 20 */
808 { "\02565", 0 }, /* not whitespace char 21 */
809 { "\02666", 0 }, /* not whitespace char 22 */
810 { "\02767", 0 }, /* not whitespace char 23 */
811 { "\03070", 0 }, /* not whitespace char 24 */
812 { "\03171", 0 }, /* not whitespace char 25 */
813 { "\03272", 0 }, /* not whitespace char 26 */
814 { "\03373", 0 }, /* not whitespace char 27 */
815 { "\03474", 0 }, /* not whitespace char 28 */
816 { "\03575", 0 }, /* not whitespace char 29 */
817 { "\03676", 0 }, /* not whitespace char 30 */
818 { "\03777", 0 }, /* not whitespace char 31 */
819 { "\04080", 80 }, /* is whitespace char 32 (space) */
820 { " \n \r \t214", 214 },
821 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
822 { " \n \r \t-214", -214 },
823 { "+214 0", 214 }, /* Space terminates the number */
824 { " 214.01", 214 }, /* Decimal point not accepted */
825 { " 214,01", 214 }, /* Decimal comma not accepted */
826 { "f81", 0 },
827 { "0x12345", 0 }, /* Hex not accepted */
828 { "00x12345", 0 },
829 { "0xx12345", 0 },
830 { "1x34", 1 },
831 { "-9999999999", -1410065407 }, /* Big negative integer */
832 { "-2147483649", 2147483647 }, /* Too small to fit in 32 Bits */
833 { "-2147483648", 0x80000000 }, /* Smallest negative integer */
834 { "-2147483647", -2147483647 },
835 { "-1", -1 },
836 { "0", 0 },
837 { "1", 1 },
838 { "2147483646", 2147483646 },
839 { "2147483647", 2147483647 }, /* Largest signed positive integer */
840 { "2147483648", 2147483648UL }, /* Positive int equal to smallest negative int */
841 { "2147483649", 2147483649UL },
842 { "4294967294", 4294967294UL },
843 { "4294967295", 4294967295UL }, /* Largest unsigned integer */
844 { "4294967296", 0 }, /* Too big to fit in 32 Bits */
845 { "9999999999", 1410065407 }, /* Big positive integer */
846 { "056789", 56789 }, /* Leading zero and still decimal */
847 { "b1011101100", 0 }, /* Binary (b-notation) */
848 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
849 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
850 { "0b1011101100", 0 }, /* Binary (0b-notation) */
851 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
852 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
853 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
854 { "0b1", 0 }, /* one digit binary */
855 { "0b2", 0 }, /* empty binary */
856 { "0b", 0 }, /* empty binary */
857 { "o1234567", 0 }, /* Octal (o-notation) */
858 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
859 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
860 { "0o1234567", 0 }, /* Octal (0o-notation) */
861 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
862 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
863 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
864 { "0o7", 0 }, /* one digit octal */
865 { "0o8", 0 }, /* empty octal */
866 { "0o", 0 }, /* empty octal */
867 { "0d1011101100", 0 }, /* explicit decimal with 0d */
868 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
869 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
870 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
871 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
872 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
873 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
874 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
875 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
876 { "0xF", 0 }, /* one digit hexadecimal */
877 { "0xG", 0 }, /* empty hexadecimal */
878 { "0x", 0 }, /* empty hexadecimal */
879 { "", 0 }, /* empty string */
880 /* { NULL, 0 }, */ /* NULL as string */
881 };
882 #define NB_STR2LONG (sizeof(str2long)/sizeof(*str2long))
883
884
885 static void test_wtoi(void)
886 {
887 int test_num;
888 UNICODE_STRING uni;
889 int result;
890
891 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
892 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
893 result = p_wtoi(uni.Buffer);
894 ok(result == str2long[test_num].value,
895 "(test %d): call failed: _wtoi(\"%s\") has result %d, expected: %d\n",
896 test_num, str2long[test_num].str, result, str2long[test_num].value);
897 pRtlFreeUnicodeString(&uni);
898 } /* for */
899 }
900
901 static void test_atoi(void)
902 {
903 int test_num;
904 int result;
905
906 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
907 result = patoi(str2long[test_num].str);
908 ok(result == str2long[test_num].value,
909 "(test %d): call failed: _atoi(\"%s\") has result %d, expected: %d\n",
910 test_num, str2long[test_num].str, result, str2long[test_num].value);
911 }
912 }
913
914 static void test_atol(void)
915 {
916 int test_num;
917 int result;
918
919 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
920 result = patol(str2long[test_num].str);
921 ok(result == str2long[test_num].value,
922 "(test %d): call failed: _atol(\"%s\") has result %d, expected: %d\n",
923 test_num, str2long[test_num].str, result, str2long[test_num].value);
924 }
925 }
926
927 static void test_wtol(void)
928 {
929 int test_num;
930 UNICODE_STRING uni;
931 LONG result;
932
933 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
934 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
935 result = p_wtol(uni.Buffer);
936 ok(result == str2long[test_num].value,
937 "(test %d): call failed: _wtol(\"%s\") has result %d, expected: %d\n",
938 test_num, str2long[test_num].str, result, str2long[test_num].value);
939 pRtlFreeUnicodeString(&uni);
940 } /* for */
941 }
942
943
944 typedef struct {
945 const char *str;
946 LONGLONG value;
947 int overflow;
948 } str2longlong_t;
949
950 static const str2longlong_t str2longlong[] = {
951 { "1011101100", 1011101100 },
952 { "1234567", 1234567 },
953 { "-214", -214 },
954 { "+214", 214 }, /* The + sign is allowed also */
955 { "--214", 0 }, /* Do not accept more than one sign */
956 { "-+214", 0 },
957 { "++214", 0 },
958 { "+-214", 0 },
959 { "\00141", 0 }, /* not whitespace char 1 */
960 { "\00242", 0 }, /* not whitespace char 2 */
961 { "\00343", 0 }, /* not whitespace char 3 */
962 { "\00444", 0 }, /* not whitespace char 4 */
963 { "\00545", 0 }, /* not whitespace char 5 */
964 { "\00646", 0 }, /* not whitespace char 6 */
965 { "\00747", 0 }, /* not whitespace char 7 */
966 { "\01050", 0 }, /* not whitespace char 8 */
967 { "\01151", 51 }, /* is whitespace char 9 (tab) */
968 { "\01252", 52 }, /* is whitespace char 10 (lf) */
969 { "\01353", 53 }, /* is whitespace char 11 (vt) */
970 { "\01454", 54 }, /* is whitespace char 12 (ff) */
971 { "\01555", 55 }, /* is whitespace char 13 (cr) */
972 { "\01656", 0 }, /* not whitespace char 14 */
973 { "\01757", 0 }, /* not whitespace char 15 */
974 { "\02060", 0 }, /* not whitespace char 16 */
975 { "\02161", 0 }, /* not whitespace char 17 */
976 { "\02262", 0 }, /* not whitespace char 18 */
977 { "\02363", 0 }, /* not whitespace char 19 */
978 { "\02464", 0 }, /* not whitespace char 20 */
979 { "\02565", 0 }, /* not whitespace char 21 */
980 { "\02666", 0 }, /* not whitespace char 22 */
981 { "\02767", 0 }, /* not whitespace char 23 */
982 { "\03070", 0 }, /* not whitespace char 24 */
983 { "\03171", 0 }, /* not whitespace char 25 */
984 { "\03272", 0 }, /* not whitespace char 26 */
985 { "\03373", 0 }, /* not whitespace char 27 */
986 { "\03474", 0 }, /* not whitespace char 28 */
987 { "\03575", 0 }, /* not whitespace char 29 */
988 { "\03676", 0 }, /* not whitespace char 30 */
989 { "\03777", 0 }, /* not whitespace char 31 */
990 { "\04080", 80 }, /* is whitespace char 32 (space) */
991 { " \n \r \t214", 214 },
992 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
993 { " \n \r \t-214", -214 },
994 { "+214 0", 214 }, /* Space terminates the number */
995 { " 214.01", 214 }, /* Decimal point not accepted */
996 { " 214,01", 214 }, /* Decimal comma not accepted */
997 { "f81", 0 },
998 { "0x12345", 0 }, /* Hex not accepted */
999 { "00x12345", 0 },
1000 { "0xx12345", 0 },
1001 { "1x34", 1 },
1002 { "-99999999999999999999", -ULL(0x6bc75e2d,0x630fffff), -1 }, /* Big negative integer */
1003 { "-9223372036854775809", ULL(0x7fffffff,0xffffffff), -1 }, /* Too small to fit in 64 bits */
1004 { "-9223372036854775808", ULL(0x80000000,0x00000000) }, /* Smallest negative 64 bit integer */
1005 { "-9223372036854775807", -ULL(0x7fffffff,0xffffffff) },
1006 { "-9999999999", -ULL(0x00000002,0x540be3ff) },
1007 { "-2147483649", -ULL(0x00000000,0x80000001) }, /* Too small to fit in 32 bits */
1008 { "-2147483648", -ULL(0x00000000,0x80000000) }, /* Smallest 32 bits negative integer */
1009 { "-2147483647", -2147483647 },
1010 { "-1", -1 },
1011 { "0", 0 },
1012 { "1", 1 },
1013 { "2147483646", 2147483646 },
1014 { "2147483647", 2147483647 }, /* Largest signed positive 32 bit integer */
1015 { "2147483648", ULL(0x00000000,0x80000000) }, /* Pos int equal to smallest neg 32 bit int */
1016 { "2147483649", ULL(0x00000000,0x80000001) },
1017 { "4294967294", ULL(0x00000000,0xfffffffe) },
1018 { "4294967295", ULL(0x00000000,0xffffffff) }, /* Largest unsigned 32 bit integer */
1019 { "4294967296", ULL(0x00000001,0x00000000) }, /* Too big to fit in 32 Bits */
1020 { "9999999999", ULL(0x00000002,0x540be3ff) },
1021 { "9223372036854775806", ULL(0x7fffffff,0xfffffffe) },
1022 { "9223372036854775807", ULL(0x7fffffff,0xffffffff) }, /* Largest signed positive 64 bit integer */
1023 { "9223372036854775808", ULL(0x80000000,0x00000000), 1 }, /* Pos int equal to smallest neg 64 bit int */
1024 { "9223372036854775809", ULL(0x80000000,0x00000001), 1 },
1025 { "18446744073709551614", ULL(0xffffffff,0xfffffffe), 1 },
1026 { "18446744073709551615", ULL(0xffffffff,0xffffffff), 1 }, /* Largest unsigned 64 bit integer */
1027 { "18446744073709551616", 0, 1 }, /* Too big to fit in 64 bits */
1028 { "99999999999999999999", ULL(0x6bc75e2d,0x630fffff), 1 }, /* Big positive integer */
1029 { "056789", 56789 }, /* Leading zero and still decimal */
1030 { "b1011101100", 0 }, /* Binary (b-notation) */
1031 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
1032 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1033 { "0b1011101100", 0 }, /* Binary (0b-notation) */
1034 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
1035 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1036 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
1037 { "0b1", 0 }, /* one digit binary */
1038 { "0b2", 0 }, /* empty binary */
1039 { "0b", 0 }, /* empty binary */
1040 { "o1234567", 0 }, /* Octal (o-notation) */
1041 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
1042 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1043 { "0o1234567", 0 }, /* Octal (0o-notation) */
1044 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
1045 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1046 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
1047 { "0o7", 0 }, /* one digit octal */
1048 { "0o8", 0 }, /* empty octal */
1049 { "0o", 0 }, /* empty octal */
1050 { "0d1011101100", 0 }, /* explicit decimal with 0d */
1051 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
1052 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
1053 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
1054 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
1055 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
1056 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
1057 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
1058 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
1059 { "0xF", 0 }, /* one digit hexadecimal */
1060 { "0xG", 0 }, /* empty hexadecimal */
1061 { "0x", 0 }, /* empty hexadecimal */
1062 { "", 0 }, /* empty string */
1063 /* { NULL, 0 }, */ /* NULL as string */
1064 };
1065 #define NB_STR2LONGLONG (sizeof(str2longlong)/sizeof(*str2longlong))
1066
1067
1068 static void test_atoi64(void)
1069 {
1070 int test_num;
1071 LONGLONG result;
1072
1073 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1074 result = p_atoi64(str2longlong[test_num].str);
1075 if (str2longlong[test_num].overflow)
1076 ok(result == str2longlong[test_num].value ||
1077 (result == (str2longlong[test_num].overflow == -1) ?
1078 ULL(0x80000000,0x00000000) : ULL(0x7fffffff,0xffffffff)),
1079 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1080 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1081 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1082 else
1083 ok(result == str2longlong[test_num].value,
1084 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1085 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1086 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1087 }
1088 }
1089
1090
1091 static void test_wtoi64(void)
1092 {
1093 int test_num;
1094 UNICODE_STRING uni;
1095 LONGLONG result;
1096
1097 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1098 pRtlCreateUnicodeStringFromAsciiz(&uni, str2longlong[test_num].str);
1099 result = p_wtoi64(uni.Buffer);
1100 if (str2longlong[test_num].overflow)
1101 ok(result == str2longlong[test_num].value ||
1102 (result == (str2longlong[test_num].overflow == -1) ?
1103 ULL(0x80000000,0x00000000) : ULL(0x7fffffff,0xffffffff)),
1104 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1105 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1106 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1107 else
1108 ok(result == str2longlong[test_num].value,
1109 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1110 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1111 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1112 pRtlFreeUnicodeString(&uni);
1113 }
1114 }
1115
1116 static void test_wcschr(void)
1117 {
1118 static const WCHAR teststringW[] = {'a','b','r','a','c','a','d','a','b','r','a',0};
1119
1120 ok(p_wcschr(teststringW, 'a') == teststringW + 0,
1121 "wcschr should have returned a pointer to the first 'a' character\n");
1122 ok(p_wcschr(teststringW, 0) == teststringW + 11,
1123 "wcschr should have returned a pointer to the null terminator\n");
1124 ok(p_wcschr(teststringW, 'x') == NULL,
1125 "wcschr should have returned NULL\n");
1126 }
1127
1128 static void test_wcsrchr(void)
1129 {
1130 static const WCHAR teststringW[] = {'a','b','r','a','c','a','d','a','b','r','a',0};
1131
1132 ok(p_wcsrchr(teststringW, 'a') == teststringW + 10,
1133 "wcsrchr should have returned a pointer to the last 'a' character\n");
1134 ok(p_wcsrchr(teststringW, 0) == teststringW + 11,
1135 "wcsrchr should have returned a pointer to the null terminator\n");
1136 ok(p_wcsrchr(teststringW, 'x') == NULL,
1137 "wcsrchr should have returned NULL\n");
1138 }
1139
1140 START_TEST(string)
1141 {
1142 InitFunctionPtrs();
1143
1144 if (p_ultoa)
1145 test_ulongtoa();
1146 if (p_ui64toa)
1147 test_ulonglongtoa();
1148 if (p_atoi64)
1149 test_atoi64();
1150 if (p_ultow)
1151 test_ulongtow();
1152 if (p_ui64tow)
1153 test_ulonglongtow();
1154 if (p_wtoi)
1155 test_wtoi();
1156 if (p_wtol)
1157 test_wtol();
1158 if (p_wtoi64)
1159 test_wtoi64();
1160 if (p_wcschr)
1161 test_wcschr();
1162 if (p_wcsrchr)
1163 test_wcsrchr();
1164 if (patoi)
1165 test_atoi();
1166 if (patol)
1167 test_atol();
1168 }