1 /* Unit test suite for string functions and some wcstring functions
3 * Copyright 2003 Thomas Mertes
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.
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.
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
20 * We use function pointers here as there is no import library for NTDLL on
26 #include "ntdll_test.h"
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);
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)(ULONG, LPSTR, INT);
42 static LPSTR (WINAPIV *p_i64toa)(LONGLONG, LPSTR, INT);
43 static LPSTR (WINAPIV *p_ui64toa)(ULONGLONG, LPSTR, INT);
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)(ULONG, LPWSTR, INT);
51 static LPWSTR (WINAPIV *p_i64tow)(LONGLONG, LPWSTR, INT);
52 static LPWSTR (WINAPIV *p_ui64tow)(ULONGLONG, LPWSTR, INT);
54 static long (WINAPIV *pwcstol)(LPCWSTR, LPWSTR *, INT);
55 static ULONG (WINAPIV *pwcstoul)(LPCWSTR, LPWSTR *, INT);
57 static LPWSTR (WINAPIV *p_wcschr)(LPCWSTR, WCHAR);
58 static LPWSTR (WINAPIV *p_wcsrchr)(LPCWSTR, WCHAR);
60 static void (__cdecl *p_qsort)(void *,size_t,size_t, int(__cdecl *compar)(const void *, const void *) );
61 static void* (__cdecl *p_bsearch)(void *,void*,size_t,size_t, int(__cdecl *compar)(const void *, const void *) );
64 static void InitFunctionPtrs(void)
66 hntdll = LoadLibraryA("ntdll.dll");
67 ok(hntdll != 0, "LoadLibrary failed\n");
69 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
70 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
71 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
72 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
74 patoi = (void *)GetProcAddress(hntdll, "atoi");
75 patol = (void *)GetProcAddress(hntdll, "atol");
76 p_atoi64 = (void *)GetProcAddress(hntdll, "_atoi64");
77 p_itoa = (void *)GetProcAddress(hntdll, "_itoa");
78 p_ltoa = (void *)GetProcAddress(hntdll, "_ltoa");
79 p_ultoa = (void *)GetProcAddress(hntdll, "_ultoa");
80 p_i64toa = (void *)GetProcAddress(hntdll, "_i64toa");
81 p_ui64toa = (void *)GetProcAddress(hntdll, "_ui64toa");
83 p_wtoi = (void *)GetProcAddress(hntdll, "_wtoi");
84 p_wtol = (void *)GetProcAddress(hntdll, "_wtol");
85 p_wtoi64 = (void *)GetProcAddress(hntdll, "_wtoi64");
86 p_itow = (void *)GetProcAddress(hntdll, "_itow");
87 p_ltow = (void *)GetProcAddress(hntdll, "_ltow");
88 p_ultow = (void *)GetProcAddress(hntdll, "_ultow");
89 p_i64tow = (void *)GetProcAddress(hntdll, "_i64tow");
90 p_ui64tow = (void *)GetProcAddress(hntdll, "_ui64tow");
92 pwcstol = (void *)GetProcAddress(hntdll, "wcstol");
93 pwcstoul = (void *)GetProcAddress(hntdll, "wcstoul");
95 p_wcschr= (void *)GetProcAddress(hntdll, "wcschr");
96 p_wcsrchr= (void *)GetProcAddress(hntdll, "wcsrchr");
97 p_qsort= (void *)GetProcAddress(hntdll, "qsort");
98 p_bsearch= (void *)GetProcAddress(hntdll, "bsearch");
103 #define LARGE_STRI_BUFFER_LENGTH 67
109 int mask; /* ntdll/msvcrt: 0x01=itoa, 0x02=ltoa, 0x04=ultoa */
110 /* 0x10=itow, 0x20=ltow, 0x40=ultow */
113 static const ulong2str_t ulong2str[] = {
114 {10, 123, "123\0---------------------------------------------------------------", 0x77},
116 { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x67},
117 { 2, -2147483647, "10000000000000000000000000000001\0----------------------------------", 0x67},
118 { 2, -65537, "11111111111111101111111111111111\0----------------------------------", 0x67},
119 { 2, -65536, "11111111111111110000000000000000\0----------------------------------", 0x67},
120 { 2, -65535, "11111111111111110000000000000001\0----------------------------------", 0x67},
121 { 2, -32768, "11111111111111111000000000000000\0----------------------------------", 0x67},
122 { 2, -32767, "11111111111111111000000000000001\0----------------------------------", 0x67},
123 { 2, -2, "11111111111111111111111111111110\0----------------------------------", 0x67},
124 { 2, -1, "11111111111111111111111111111111\0----------------------------------", 0x67},
125 { 2, 0, "0\0-----------------------------------------------------------------", 0x77},
126 { 2, 1, "1\0-----------------------------------------------------------------", 0x77},
127 { 2, 10, "1010\0--------------------------------------------------------------", 0x77},
128 { 2, 100, "1100100\0-----------------------------------------------------------", 0x77},
129 { 2, 1000, "1111101000\0--------------------------------------------------------", 0x77},
130 { 2, 10000, "10011100010000\0----------------------------------------------------", 0x77},
131 { 2, 32767, "111111111111111\0---------------------------------------------------", 0x77},
132 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x77},
133 { 2, 65535, "1111111111111111\0--------------------------------------------------", 0x77},
134 { 2, 100000, "11000011010100000\0-------------------------------------------------", 0x77},
135 { 2, 234567, "111001010001000111\0------------------------------------------------", 0x77},
136 { 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x77},
137 { 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x77},
138 { 2, 524288, "10000000000000000000\0----------------------------------------------", 0x67},
139 { 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x67},
140 { 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x67},
141 { 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x67},
142 { 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x67},
143 { 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x67},
144 { 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x67},
145 { 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x67},
146 { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x67},
147 { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x67},
148 { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x67},
149 { 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x67},
151 { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x77},
152 { 8, -2147483647, "20000000001\0-------------------------------------------------------", 0x77},
153 { 8, -2, "37777777776\0-------------------------------------------------------", 0x77},
154 { 8, -1, "37777777777\0-------------------------------------------------------", 0x77},
155 { 8, 0, "0\0-----------------------------------------------------------------", 0x77},
156 { 8, 1, "1\0-----------------------------------------------------------------", 0x77},
157 { 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x77},
158 { 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x77},
159 { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x77},
160 { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x77},
161 { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x77},
162 { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x77},
164 {10, 0x80000000U, "-2147483648\0-------------------------------------------------------", 0x33},
165 {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x44},
166 {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x33},
167 {10, -2147483647, "2147483649\0--------------------------------------------------------", 0x44},
168 {10, -2, "-2\0----------------------------------------------------------------", 0x33},
169 {10, -2, "4294967294\0--------------------------------------------------------", 0x44},
170 {10, -1, "-1\0----------------------------------------------------------------", 0x33},
171 {10, -1, "4294967295\0--------------------------------------------------------", 0x44},
172 {10, 0, "0\0-----------------------------------------------------------------", 0x77},
173 {10, 1, "1\0-----------------------------------------------------------------", 0x77},
174 {10, 12, "12\0----------------------------------------------------------------", 0x77},
175 {10, 123, "123\0---------------------------------------------------------------", 0x77},
176 {10, 1234, "1234\0--------------------------------------------------------------", 0x77},
177 {10, 12345, "12345\0-------------------------------------------------------------", 0x77},
178 {10, 123456, "123456\0------------------------------------------------------------", 0x77},
179 {10, 1234567, "1234567\0-----------------------------------------------------------", 0x77},
180 {10, 12345678, "12345678\0----------------------------------------------------------", 0x77},
181 {10, 123456789, "123456789\0---------------------------------------------------------", 0x77},
182 {10, 2147483646, "2147483646\0--------------------------------------------------------", 0x77},
183 {10, 2147483647, "2147483647\0--------------------------------------------------------", 0x77},
184 {10, 2147483648U, "-2147483648\0-------------------------------------------------------", 0x33},
185 {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x44},
186 {10, 2147483649U, "-2147483647\0-------------------------------------------------------", 0x33},
187 {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x44},
188 {10, 4294967294U, "-2\0----------------------------------------------------------------", 0x33},
189 {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x44},
190 {10, 4294967295U, "-1\0----------------------------------------------------------------", 0x33},
191 {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x44},
193 {16, 0, "0\0-----------------------------------------------------------------", 0x77},
194 {16, 1, "1\0-----------------------------------------------------------------", 0x77},
195 {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x77},
196 {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x77},
197 {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x77},
198 {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x77},
199 {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x77},
200 {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x77},
202 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x77},
203 { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x77},
204 { 2, 131072, "100000000000000000\0------------------------------------------------", 0x77},
205 {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x77},
206 {16, 0xa, "a\0-----------------------------------------------------------------", 0x77},
207 {16, 0, "0\0-----------------------------------------------------------------", 0x77},
208 {20, 3368421, "111111\0------------------------------------------------------------", 0x77},
209 {36, 62193781, "111111\0------------------------------------------------------------", 0x77},
210 {37, 71270178, "111111\0------------------------------------------------------------", 0x77},
212 #define NB_ULONG2STR (sizeof(ulong2str)/sizeof(*ulong2str))
215 static void one_itoa_test(int test_num, const ulong2str_t *ulong2str)
217 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
221 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
222 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
223 value = ulong2str->value;
224 result = p_itoa(value, dest_str, ulong2str->base);
225 ok(result == dest_str,
226 "(test %d): _itoa(%d, [out], %d) has result %p, expected: %p\n",
227 test_num, value, ulong2str->base, result, dest_str);
228 ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
229 "(test %d): _itoa(%d, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
230 test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);
234 static void one_ltoa_test(int test_num, const ulong2str_t *ulong2str)
236 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
240 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
241 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
242 value = ulong2str->value;
243 result = p_ltoa(ulong2str->value, dest_str, ulong2str->base);
244 ok(result == dest_str,
245 "(test %d): _ltoa(%d, [out], %d) has result %p, expected: %p\n",
246 test_num, value, ulong2str->base, result, dest_str);
247 ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
248 "(test %d): _ltoa(%d, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
249 test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);
253 static void one_ultoa_test(int test_num, const ulong2str_t *ulong2str)
255 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
259 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
260 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
261 value = ulong2str->value;
262 result = p_ultoa(ulong2str->value, dest_str, ulong2str->base);
263 ok(result == dest_str,
264 "(test %d): _ultoa(%u, [out], %d) has result %p, expected: %p\n",
265 test_num, value, ulong2str->base, result, dest_str);
266 ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
267 "(test %d): _ultoa(%u, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
268 test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);
272 static void test_ulongtoa(void)
276 for (test_num = 0; test_num < NB_ULONG2STR; test_num++) {
277 if (ulong2str[test_num].mask & 0x01) {
278 one_itoa_test(test_num, &ulong2str[test_num]);
280 if (ulong2str[test_num].mask & 0x02) {
281 one_ltoa_test(test_num, &ulong2str[test_num]);
283 if (ulong2str[test_num].mask & 0x04) {
284 one_ultoa_test(test_num, &ulong2str[test_num]);
290 static void one_itow_test(int test_num, const ulong2str_t *ulong2str)
293 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
294 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
295 UNICODE_STRING unicode_string;
300 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
301 expected_wstr[pos] = ulong2str->Buffer[pos];
303 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
305 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
306 dest_wstr[pos] = '-';
308 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
309 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
310 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
311 unicode_string.Buffer = dest_wstr;
312 value = ulong2str->value;
313 result = p_itow(value, dest_wstr, ulong2str->base);
314 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
315 ok(result == dest_wstr,
316 "(test %d): _itow(%d, [out], %d) has result %p, expected: %p\n",
317 test_num, value, ulong2str->base, result, dest_wstr);
318 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
319 "(test %d): _itow(%d, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
320 test_num, value, ulong2str->base, ansi_str.Buffer, ulong2str->Buffer);
321 pRtlFreeAnsiString(&ansi_str);
325 static void one_ltow_test(int test_num, const ulong2str_t *ulong2str)
328 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
329 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
330 UNICODE_STRING unicode_string;
335 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
336 expected_wstr[pos] = ulong2str->Buffer[pos];
338 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
340 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
341 dest_wstr[pos] = '-';
343 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
344 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
345 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
346 unicode_string.Buffer = dest_wstr;
348 value = ulong2str->value;
349 result = p_ltow(value, dest_wstr, ulong2str->base);
350 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
351 ok(result == dest_wstr,
352 "(test %d): _ltow(%d, [out], %d) has result %p, expected: %p\n",
353 test_num, value, ulong2str->base, result, dest_wstr);
354 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
355 "(test %d): _ltow(%d, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
356 test_num, value, ulong2str->base, ansi_str.Buffer, ulong2str->Buffer);
357 pRtlFreeAnsiString(&ansi_str);
361 static void one_ultow_test(int test_num, const ulong2str_t *ulong2str)
364 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
365 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
366 UNICODE_STRING unicode_string;
371 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
372 expected_wstr[pos] = ulong2str->Buffer[pos];
374 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
376 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
377 dest_wstr[pos] = '-';
379 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
380 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
381 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
382 unicode_string.Buffer = dest_wstr;
384 value = ulong2str->value;
385 result = p_ultow(value, dest_wstr, ulong2str->base);
386 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
387 ok(result == dest_wstr,
388 "(test %d): _ultow(%u, [out], %d) has result %p, expected: %p\n",
389 test_num, value, ulong2str->base, result, dest_wstr);
390 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
391 "(test %d): _ultow(%u, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
392 test_num, value, ulong2str->base, ansi_str.Buffer, ulong2str->Buffer);
393 pRtlFreeAnsiString(&ansi_str);
397 static void test_ulongtow(void)
402 for (test_num = 0; test_num < NB_ULONG2STR; test_num++) {
403 if (ulong2str[test_num].mask & 0x10) {
404 one_itow_test(test_num, &ulong2str[test_num]);
406 if (ulong2str[test_num].mask & 0x20) {
407 one_ltow_test(test_num, &ulong2str[test_num]);
409 if (ulong2str[test_num].mask & 0x40) {
410 one_ultow_test(test_num, &ulong2str[test_num]);
415 /* Crashes on XP and W2K3 */
416 result = p_itow(ulong2str[0].value, NULL, 10);
418 "(test a): _itow(%d, NULL, 10) has result %p, expected: NULL\n",
419 ulong2str[0].value, result);
423 /* Crashes on XP and W2K3 */
424 result = p_ltow(ulong2str[0].value, NULL, 10);
426 "(test b): _ltow(%d, NULL, 10) has result %p, expected: NULL\n",
427 ulong2str[0].value, result);
431 /* Crashes on XP and W2K3 */
432 result = p_ultow(ulong2str[0].value, NULL, 10);
434 "(test c): _ultow(%d, NULL, 10) has result %p, expected: NULL\n",
435 ulong2str[0].value, result);
439 #define ULL(a,b) (((ULONGLONG)(a) << 32) | (b))
445 int mask; /* ntdll/msvcrt: 0x01=i64toa, 0x02=ui64toa, 0x04=wrong _i64toa try next example */
446 /* 0x10=i64tow, 0x20=ui64tow, 0x40=wrong _i64tow try next example */
449 static const ulonglong2str_t ulonglong2str[] = {
450 {10, 123, "123\0---------------------------------------------------------------", 0x33},
452 { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x33},
453 { 2, -2147483647, "1111111111111111111111111111111110000000000000000000000000000001\0--", 0x33},
454 { 2, -65537, "1111111111111111111111111111111111111111111111101111111111111111\0--", 0x33},
455 { 2, -65536, "1111111111111111111111111111111111111111111111110000000000000000\0--", 0x33},
456 { 2, -65535, "1111111111111111111111111111111111111111111111110000000000000001\0--", 0x33},
457 { 2, -32768, "1111111111111111111111111111111111111111111111111000000000000000\0--", 0x33},
458 { 2, -32767, "1111111111111111111111111111111111111111111111111000000000000001\0--", 0x33},
459 { 2, -2, "1111111111111111111111111111111111111111111111111111111111111110\0--", 0x33},
460 { 2, -1, "1111111111111111111111111111111111111111111111111111111111111111\0--", 0x33},
461 { 2, 0, "0\0-----------------------------------------------------------------", 0x33},
462 { 2, 1, "1\0-----------------------------------------------------------------", 0x33},
463 { 2, 10, "1010\0--------------------------------------------------------------", 0x33},
464 { 2, 100, "1100100\0-----------------------------------------------------------", 0x33},
465 { 2, 1000, "1111101000\0--------------------------------------------------------", 0x33},
466 { 2, 10000, "10011100010000\0----------------------------------------------------", 0x33},
467 { 2, 32767, "111111111111111\0---------------------------------------------------", 0x33},
468 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
469 { 2, 65535, "1111111111111111\0--------------------------------------------------", 0x33},
470 { 2, 100000, "11000011010100000\0-------------------------------------------------", 0x33},
471 { 2, 234567, "111001010001000111\0------------------------------------------------", 0x33},
472 { 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x33},
473 { 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x33},
474 { 2, 524288, "10000000000000000000\0----------------------------------------------", 0x33},
475 { 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x33},
476 { 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x33},
477 { 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x33},
478 { 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x33},
479 { 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x33},
480 { 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x33},
481 { 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x33},
482 { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x33},
483 { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x33},
484 { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x33},
485 { 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x33},
486 { 2, ULL(0x1,0xffffffff), "111111111111111111111111111111111\0---------------------------------", 0x33},
487 { 2, ((ULONGLONG)100000)*100000, "1001010100000010111110010000000000\0--------------------------------", 0x33},
488 { 2, ULL(0x3,0xffffffff), "1111111111111111111111111111111111\0--------------------------------", 0x33},
489 { 2, ULL(0x7,0xffffffff), "11111111111111111111111111111111111\0-------------------------------", 0x33},
490 { 2, ULL(0xf,0xffffffff), "111111111111111111111111111111111111\0------------------------------", 0x33},
491 { 2, ((ULONGLONG)100000)*1000000, "1011101001000011101101110100000000000\0-----------------------------", 0x33},
492 { 2, ULL(0x1f,0xffffffff), "1111111111111111111111111111111111111\0-----------------------------", 0x33},
493 { 2, ULL(0x3f,0xffffffff), "11111111111111111111111111111111111111\0----------------------------", 0x33},
494 { 2, ULL(0x7f,0xffffffff), "111111111111111111111111111111111111111\0---------------------------", 0x33},
495 { 2, ULL(0xff,0xffffffff), "1111111111111111111111111111111111111111\0--------------------------", 0x33},
497 { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x33},
498 { 8, -2147483647, "1777777777760000000001\0--------------------------------------------", 0x33},
499 { 8, -2, "1777777777777777777776\0--------------------------------------------", 0x33},
500 { 8, -1, "1777777777777777777777\0--------------------------------------------", 0x33},
501 { 8, 0, "0\0-----------------------------------------------------------------", 0x33},
502 { 8, 1, "1\0-----------------------------------------------------------------", 0x33},
503 { 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x33},
504 { 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x33},
505 { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x33},
506 { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x33},
507 { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x33},
508 { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x33},
510 {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x33},
511 {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x55},
512 {10, -2147483647, "-18446744071562067969\0---------------------------------------------", 0x00},
513 {10, -2147483647, "18446744071562067969\0----------------------------------------------", 0x22},
514 {10, -2, "-2\0----------------------------------------------------------------", 0x55},
515 {10, -2, "-18446744073709551614\0---------------------------------------------", 0x00},
516 {10, -2, "18446744073709551614\0----------------------------------------------", 0x22},
517 {10, -1, "-1\0----------------------------------------------------------------", 0x55},
518 {10, -1, "-18446744073709551615\0---------------------------------------------", 0x00},
519 {10, -1, "18446744073709551615\0----------------------------------------------", 0x22},
520 {10, 0, "0\0-----------------------------------------------------------------", 0x33},
521 {10, 1, "1\0-----------------------------------------------------------------", 0x33},
522 {10, 12, "12\0----------------------------------------------------------------", 0x33},
523 {10, 123, "123\0---------------------------------------------------------------", 0x33},
524 {10, 1234, "1234\0--------------------------------------------------------------", 0x33},
525 {10, 12345, "12345\0-------------------------------------------------------------", 0x33},
526 {10, 123456, "123456\0------------------------------------------------------------", 0x33},
527 {10, 1234567, "1234567\0-----------------------------------------------------------", 0x33},
528 {10, 12345678, "12345678\0----------------------------------------------------------", 0x33},
529 {10, 123456789, "123456789\0---------------------------------------------------------", 0x33},
530 {10, 2147483646, "2147483646\0--------------------------------------------------------", 0x33},
531 {10, 2147483647, "2147483647\0--------------------------------------------------------", 0x33},
532 {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x33},
533 {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x33},
534 {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x33},
535 {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x33},
536 {10, ULL(0x2,0xdfdc1c35), "12345678901\0-------------------------------------------------------", 0x33},
537 {10, ULL(0xe5,0xf4c8f374), "987654321012\0------------------------------------------------------", 0x33},
538 {10, ULL(0x1c0,0xfc161e3e), "1928374656574\0-----------------------------------------------------", 0x33},
539 {10, ULL(0xbad,0xcafeface), "12841062955726\0----------------------------------------------------", 0x33},
540 {10, ULL(0x5bad,0xcafeface), "100801993177806\0---------------------------------------------------", 0x33},
541 {10, ULL(0xaface,0xbeefcafe), "3090515640699646\0--------------------------------------------------", 0x33},
542 {10, ULL(0xa5beef,0xabcdcafe), "46653307746110206\0-------------------------------------------------", 0x33},
543 {10, ULL(0x1f8cf9b,0xf2df3af1), "142091656963767025\0------------------------------------------------", 0x33},
544 {10, ULL(0x0fffffff,0xffffffff), "1152921504606846975\0-----------------------------------------------", 0x33},
545 {10, ULL(0x7fffffff,0xffffffff), "9223372036854775807\0-----------------------------------------------", 0x33},
546 {10, ULL(0x80000000,0x00000000), "-9223372036854775808\0----------------------------------------------", 0x11},
547 {10, ULL(0x80000000,0x00000000), "9223372036854775808\0-----------------------------------------------", 0x22},
548 {10, ULL(0x80000000,0x00000001), "-9223372036854775807\0----------------------------------------------", 0x55},
549 {10, ULL(0x80000000,0x00000001), "-9223372036854775809\0----------------------------------------------", 0x00},
550 {10, ULL(0x80000000,0x00000001), "9223372036854775809\0-----------------------------------------------", 0x22},
551 {10, ULL(0x80000000,0x00000002), "-9223372036854775806\0----------------------------------------------", 0x55},
552 {10, ULL(0x80000000,0x00000002), "-9223372036854775810\0----------------------------------------------", 0x00},
553 {10, ULL(0x80000000,0x00000002), "9223372036854775810\0-----------------------------------------------", 0x22},
554 {10, ULL(0xffffffff,0xfffffffe), "-2\0----------------------------------------------------------------", 0x55},
555 {10, ULL(0xffffffff,0xfffffffe), "-18446744073709551614\0---------------------------------------------", 0x00},
556 {10, ULL(0xffffffff,0xfffffffe), "18446744073709551614\0----------------------------------------------", 0x22},
557 {10, ULL(0xffffffff,0xffffffff), "-1\0----------------------------------------------------------------", 0x55},
558 {10, ULL(0xffffffff,0xffffffff), "-18446744073709551615\0---------------------------------------------", 0x00},
559 {10, ULL(0xffffffff,0xffffffff), "18446744073709551615\0----------------------------------------------", 0x22},
561 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
562 {16, 1, "1\0-----------------------------------------------------------------", 0x33},
563 {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x33},
564 {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x33},
565 {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x33},
566 {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x33},
567 {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x33},
568 {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x33},
569 {16, ULL(0x1,0x00000000), "100000000\0---------------------------------------------------------", 0x33},
570 {16, ULL(0xbad,0xdeadbeef), "baddeadbeef\0-------------------------------------------------------", 0x33},
571 {16, ULL(0x80000000,0x00000000), "8000000000000000\0--------------------------------------------------", 0x33},
572 {16, ULL(0xfedcba98,0x76543210), "fedcba9876543210\0--------------------------------------------------", 0x33},
573 {16, ULL(0xffffffff,0x80000001), "ffffffff80000001\0--------------------------------------------------", 0x33},
574 {16, ULL(0xffffffff,0xfffffffe), "fffffffffffffffe\0--------------------------------------------------", 0x33},
575 {16, ULL(0xffffffff,0xffffffff), "ffffffffffffffff\0--------------------------------------------------", 0x33},
577 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
578 { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x33},
579 { 2, 131072, "100000000000000000\0------------------------------------------------", 0x33},
580 {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x33},
581 {16, 0xa, "a\0-----------------------------------------------------------------", 0x33},
582 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
583 {20, 3368421, "111111\0------------------------------------------------------------", 0x33},
584 {36, 62193781, "111111\0------------------------------------------------------------", 0x33},
585 {37, 71270178, "111111\0------------------------------------------------------------", 0x33},
586 {99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33},
588 #define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str))
591 static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
594 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
596 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
597 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
598 result = p_i64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
599 ok(result == dest_str,
600 "(test %d): _i64toa(%08x%08x, [out], %d) has result %p, expected: %p\n",
601 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
602 ulonglong2str->base, result, dest_str);
603 if (ulonglong2str->mask & 0x04) {
604 if (memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
605 if (memcmp(dest_str, ulonglong2str[1].Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
606 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
607 "(test %d): _i64toa(%08x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
608 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
609 ulonglong2str->base, dest_str, ulonglong2str->Buffer);
613 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
614 "(test %d): _i64toa(%08x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
615 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
616 ulonglong2str->base, dest_str, ulonglong2str->Buffer);
621 static void one_ui64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
624 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
626 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
627 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
628 result = p_ui64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
629 ok(result == dest_str,
630 "(test %d): _ui64toa(%08x%08x, [out], %d) has result %p, expected: %p\n",
631 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
632 ulonglong2str->base, result, dest_str);
633 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
634 "(test %d): _ui64toa(%08x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
635 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
636 ulonglong2str->base, dest_str, ulonglong2str->Buffer);
640 static void test_ulonglongtoa(void)
644 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
645 if (ulonglong2str[test_num].mask & 0x01) {
646 one_i64toa_test(test_num, &ulonglong2str[test_num]);
648 if (p_ui64toa != NULL) {
649 if (ulonglong2str[test_num].mask & 0x02) {
650 one_ui64toa_test(test_num, &ulonglong2str[test_num]);
657 static void one_i64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
660 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
661 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
662 UNICODE_STRING unicode_string;
666 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
667 expected_wstr[pos] = ulonglong2str->Buffer[pos];
669 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
671 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
672 dest_wstr[pos] = '-';
674 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
675 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
676 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
677 unicode_string.Buffer = dest_wstr;
679 result = p_i64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
680 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
681 ok(result == dest_wstr,
682 "(test %d): _i64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
683 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
684 ulonglong2str->base, result, dest_wstr);
685 if (ulonglong2str->mask & 0x04) {
686 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
687 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
688 expected_wstr[pos] = ulonglong2str[1].Buffer[pos];
690 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
691 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
692 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
693 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
694 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
695 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
699 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
700 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
701 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
702 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
704 pRtlFreeAnsiString(&ansi_str);
708 static void one_ui64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
711 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
712 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
713 UNICODE_STRING unicode_string;
717 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
718 expected_wstr[pos] = ulonglong2str->Buffer[pos];
720 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
722 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
723 dest_wstr[pos] = '-';
725 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
726 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
727 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
728 unicode_string.Buffer = dest_wstr;
730 result = p_ui64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
731 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
732 ok(result == dest_wstr,
733 "(test %d): _ui64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
734 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
735 ulonglong2str->base, result, dest_wstr);
736 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
737 "(test %d): _ui64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
738 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
739 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
740 pRtlFreeAnsiString(&ansi_str);
744 static void test_ulonglongtow(void)
749 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
750 if (ulonglong2str[test_num].mask & 0x10) {
751 one_i64tow_test(test_num, &ulonglong2str[test_num]);
754 if (ulonglong2str[test_num].mask & 0x20) {
755 one_ui64tow_test(test_num, &ulonglong2str[test_num]);
761 /* Crashes on XP and W2K3 */
762 result = p_i64tow(ulonglong2str[0].value, NULL, 10);
764 "(test d): _i64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
765 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
770 /* Crashes on XP and W2K3 */
771 result = p_ui64tow(ulonglong2str[0].value, NULL, 10);
773 "(test e): _ui64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
774 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
785 static const str2long_t str2long[] = {
786 { "1011101100", 1011101100 },
787 { "1234567", 1234567 },
789 { "+214", 214 }, /* The + sign is allowed also */
790 { "--214", 0 }, /* Do not accept more than one sign */
794 { "\00141", 0 }, /* not whitespace char 1 */
795 { "\00242", 0 }, /* not whitespace char 2 */
796 { "\00343", 0 }, /* not whitespace char 3 */
797 { "\00444", 0 }, /* not whitespace char 4 */
798 { "\00545", 0 }, /* not whitespace char 5 */
799 { "\00646", 0 }, /* not whitespace char 6 */
800 { "\00747", 0 }, /* not whitespace char 7 */
801 { "\01050", 0 }, /* not whitespace char 8 */
802 { "\01151", 51 }, /* is whitespace char 9 (tab) */
803 { "\01252", 52 }, /* is whitespace char 10 (lf) */
804 { "\01353", 53 }, /* is whitespace char 11 (vt) */
805 { "\01454", 54 }, /* is whitespace char 12 (ff) */
806 { "\01555", 55 }, /* is whitespace char 13 (cr) */
807 { "\01656", 0 }, /* not whitespace char 14 */
808 { "\01757", 0 }, /* not whitespace char 15 */
809 { "\02060", 0 }, /* not whitespace char 16 */
810 { "\02161", 0 }, /* not whitespace char 17 */
811 { "\02262", 0 }, /* not whitespace char 18 */
812 { "\02363", 0 }, /* not whitespace char 19 */
813 { "\02464", 0 }, /* not whitespace char 20 */
814 { "\02565", 0 }, /* not whitespace char 21 */
815 { "\02666", 0 }, /* not whitespace char 22 */
816 { "\02767", 0 }, /* not whitespace char 23 */
817 { "\03070", 0 }, /* not whitespace char 24 */
818 { "\03171", 0 }, /* not whitespace char 25 */
819 { "\03272", 0 }, /* not whitespace char 26 */
820 { "\03373", 0 }, /* not whitespace char 27 */
821 { "\03474", 0 }, /* not whitespace char 28 */
822 { "\03575", 0 }, /* not whitespace char 29 */
823 { "\03676", 0 }, /* not whitespace char 30 */
824 { "\03777", 0 }, /* not whitespace char 31 */
825 { "\04080", 80 }, /* is whitespace char 32 (space) */
826 { " \n \r \t214", 214 },
827 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
828 { " \n \r \t-214", -214 },
829 { "+214 0", 214 }, /* Space terminates the number */
830 { " 214.01", 214 }, /* Decimal point not accepted */
831 { " 214,01", 214 }, /* Decimal comma not accepted */
833 { "0x12345", 0 }, /* Hex not accepted */
837 { "-9999999999", -1410065407 }, /* Big negative integer */
838 { "-2147483649", 2147483647 }, /* Too small to fit in 32 Bits */
839 { "-2147483648", 0x80000000 }, /* Smallest negative integer */
840 { "-2147483647", -2147483647 },
844 { "2147483646", 2147483646 },
845 { "2147483647", 2147483647 }, /* Largest signed positive integer */
846 { "2147483648", 2147483648UL }, /* Positive int equal to smallest negative int */
847 { "2147483649", 2147483649UL },
848 { "4294967294", 4294967294UL },
849 { "4294967295", 4294967295UL }, /* Largest unsigned integer */
850 { "4294967296", 0 }, /* Too big to fit in 32 Bits */
851 { "9999999999", 1410065407 }, /* Big positive integer */
852 { "056789", 56789 }, /* Leading zero and still decimal */
853 { "b1011101100", 0 }, /* Binary (b-notation) */
854 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
855 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
856 { "0b1011101100", 0 }, /* Binary (0b-notation) */
857 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
858 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
859 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
860 { "0b1", 0 }, /* one digit binary */
861 { "0b2", 0 }, /* empty binary */
862 { "0b", 0 }, /* empty binary */
863 { "o1234567", 0 }, /* Octal (o-notation) */
864 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
865 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
866 { "0o1234567", 0 }, /* Octal (0o-notation) */
867 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
868 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
869 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
870 { "0o7", 0 }, /* one digit octal */
871 { "0o8", 0 }, /* empty octal */
872 { "0o", 0 }, /* empty octal */
873 { "0d1011101100", 0 }, /* explicit decimal with 0d */
874 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
875 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
876 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
877 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
878 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
879 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
880 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
881 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
882 { "0xF", 0 }, /* one digit hexadecimal */
883 { "0xG", 0 }, /* empty hexadecimal */
884 { "0x", 0 }, /* empty hexadecimal */
885 { "", 0 }, /* empty string */
886 /* { NULL, 0 }, */ /* NULL as string */
888 #define NB_STR2LONG (sizeof(str2long)/sizeof(*str2long))
891 static void test_wtoi(void)
897 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
898 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
899 result = p_wtoi(uni.Buffer);
900 ok(result == str2long[test_num].value,
901 "(test %d): call failed: _wtoi(\"%s\") has result %d, expected: %d\n",
902 test_num, str2long[test_num].str, result, str2long[test_num].value);
903 pRtlFreeUnicodeString(&uni);
907 static void test_atoi(void)
912 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
913 result = patoi(str2long[test_num].str);
914 ok(result == str2long[test_num].value,
915 "(test %d): call failed: _atoi(\"%s\") has result %d, expected: %d\n",
916 test_num, str2long[test_num].str, result, str2long[test_num].value);
920 static void test_atol(void)
925 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
926 result = patol(str2long[test_num].str);
927 ok(result == str2long[test_num].value,
928 "(test %d): call failed: _atol(\"%s\") has result %d, expected: %d\n",
929 test_num, str2long[test_num].str, result, str2long[test_num].value);
933 static void test_wtol(void)
939 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
940 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
941 result = p_wtol(uni.Buffer);
942 ok(result == str2long[test_num].value,
943 "(test %d): call failed: _wtol(\"%s\") has result %d, expected: %d\n",
944 test_num, str2long[test_num].str, result, str2long[test_num].value);
945 pRtlFreeUnicodeString(&uni);
956 static const str2longlong_t str2longlong[] = {
957 { "1011101100", 1011101100 },
958 { "1234567", 1234567 },
960 { "+214", 214 }, /* The + sign is allowed also */
961 { "--214", 0 }, /* Do not accept more than one sign */
965 { "\00141", 0 }, /* not whitespace char 1 */
966 { "\00242", 0 }, /* not whitespace char 2 */
967 { "\00343", 0 }, /* not whitespace char 3 */
968 { "\00444", 0 }, /* not whitespace char 4 */
969 { "\00545", 0 }, /* not whitespace char 5 */
970 { "\00646", 0 }, /* not whitespace char 6 */
971 { "\00747", 0 }, /* not whitespace char 7 */
972 { "\01050", 0 }, /* not whitespace char 8 */
973 { "\01151", 51 }, /* is whitespace char 9 (tab) */
974 { "\01252", 52 }, /* is whitespace char 10 (lf) */
975 { "\01353", 53 }, /* is whitespace char 11 (vt) */
976 { "\01454", 54 }, /* is whitespace char 12 (ff) */
977 { "\01555", 55 }, /* is whitespace char 13 (cr) */
978 { "\01656", 0 }, /* not whitespace char 14 */
979 { "\01757", 0 }, /* not whitespace char 15 */
980 { "\02060", 0 }, /* not whitespace char 16 */
981 { "\02161", 0 }, /* not whitespace char 17 */
982 { "\02262", 0 }, /* not whitespace char 18 */
983 { "\02363", 0 }, /* not whitespace char 19 */
984 { "\02464", 0 }, /* not whitespace char 20 */
985 { "\02565", 0 }, /* not whitespace char 21 */
986 { "\02666", 0 }, /* not whitespace char 22 */
987 { "\02767", 0 }, /* not whitespace char 23 */
988 { "\03070", 0 }, /* not whitespace char 24 */
989 { "\03171", 0 }, /* not whitespace char 25 */
990 { "\03272", 0 }, /* not whitespace char 26 */
991 { "\03373", 0 }, /* not whitespace char 27 */
992 { "\03474", 0 }, /* not whitespace char 28 */
993 { "\03575", 0 }, /* not whitespace char 29 */
994 { "\03676", 0 }, /* not whitespace char 30 */
995 { "\03777", 0 }, /* not whitespace char 31 */
996 { "\04080", 80 }, /* is whitespace char 32 (space) */
997 { " \n \r \t214", 214 },
998 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
999 { " \n \r \t-214", -214 },
1000 { "+214 0", 214 }, /* Space terminates the number */
1001 { " 214.01", 214 }, /* Decimal point not accepted */
1002 { " 214,01", 214 }, /* Decimal comma not accepted */
1004 { "0x12345", 0 }, /* Hex not accepted */
1008 { "-99999999999999999999", -ULL(0x6bc75e2d,0x630fffff), -1 }, /* Big negative integer */
1009 { "-9223372036854775809", ULL(0x7fffffff,0xffffffff), -1 }, /* Too small to fit in 64 bits */
1010 { "-9223372036854775808", ULL(0x80000000,0x00000000) }, /* Smallest negative 64 bit integer */
1011 { "-9223372036854775807", -ULL(0x7fffffff,0xffffffff) },
1012 { "-9999999999", -ULL(0x00000002,0x540be3ff) },
1013 { "-2147483649", -ULL(0x00000000,0x80000001) }, /* Too small to fit in 32 bits */
1014 { "-2147483648", -ULL(0x00000000,0x80000000) }, /* Smallest 32 bits negative integer */
1015 { "-2147483647", -2147483647 },
1019 { "2147483646", 2147483646 },
1020 { "2147483647", 2147483647 }, /* Largest signed positive 32 bit integer */
1021 { "2147483648", ULL(0x00000000,0x80000000) }, /* Pos int equal to smallest neg 32 bit int */
1022 { "2147483649", ULL(0x00000000,0x80000001) },
1023 { "4294967294", ULL(0x00000000,0xfffffffe) },
1024 { "4294967295", ULL(0x00000000,0xffffffff) }, /* Largest unsigned 32 bit integer */
1025 { "4294967296", ULL(0x00000001,0x00000000) }, /* Too big to fit in 32 Bits */
1026 { "9999999999", ULL(0x00000002,0x540be3ff) },
1027 { "9223372036854775806", ULL(0x7fffffff,0xfffffffe) },
1028 { "9223372036854775807", ULL(0x7fffffff,0xffffffff) }, /* Largest signed positive 64 bit integer */
1029 { "9223372036854775808", ULL(0x80000000,0x00000000), 1 }, /* Pos int equal to smallest neg 64 bit int */
1030 { "9223372036854775809", ULL(0x80000000,0x00000001), 1 },
1031 { "18446744073709551614", ULL(0xffffffff,0xfffffffe), 1 },
1032 { "18446744073709551615", ULL(0xffffffff,0xffffffff), 1 }, /* Largest unsigned 64 bit integer */
1033 { "18446744073709551616", 0, 1 }, /* Too big to fit in 64 bits */
1034 { "99999999999999999999", ULL(0x6bc75e2d,0x630fffff), 1 }, /* Big positive integer */
1035 { "056789", 56789 }, /* Leading zero and still decimal */
1036 { "b1011101100", 0 }, /* Binary (b-notation) */
1037 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
1038 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1039 { "0b1011101100", 0 }, /* Binary (0b-notation) */
1040 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
1041 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1042 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
1043 { "0b1", 0 }, /* one digit binary */
1044 { "0b2", 0 }, /* empty binary */
1045 { "0b", 0 }, /* empty binary */
1046 { "o1234567", 0 }, /* Octal (o-notation) */
1047 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
1048 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1049 { "0o1234567", 0 }, /* Octal (0o-notation) */
1050 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
1051 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1052 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
1053 { "0o7", 0 }, /* one digit octal */
1054 { "0o8", 0 }, /* empty octal */
1055 { "0o", 0 }, /* empty octal */
1056 { "0d1011101100", 0 }, /* explicit decimal with 0d */
1057 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
1058 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
1059 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
1060 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
1061 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
1062 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
1063 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
1064 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
1065 { "0xF", 0 }, /* one digit hexadecimal */
1066 { "0xG", 0 }, /* empty hexadecimal */
1067 { "0x", 0 }, /* empty hexadecimal */
1068 { "", 0 }, /* empty string */
1069 /* { NULL, 0 }, */ /* NULL as string */
1071 #define NB_STR2LONGLONG (sizeof(str2longlong)/sizeof(*str2longlong))
1074 static void test_atoi64(void)
1079 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1080 result = p_atoi64(str2longlong[test_num].str);
1081 if (str2longlong[test_num].overflow)
1082 ok(result == str2longlong[test_num].value ||
1083 (result == (str2longlong[test_num].overflow == -1) ?
1084 ULL(0x80000000,0x00000000) : ULL(0x7fffffff,0xffffffff)),
1085 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1086 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1087 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1089 ok(result == str2longlong[test_num].value,
1090 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1091 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1092 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1097 static void test_wtoi64(void)
1103 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1104 pRtlCreateUnicodeStringFromAsciiz(&uni, str2longlong[test_num].str);
1105 result = p_wtoi64(uni.Buffer);
1106 if (str2longlong[test_num].overflow)
1107 ok(result == str2longlong[test_num].value ||
1108 (result == (str2longlong[test_num].overflow == -1) ?
1109 ULL(0x80000000,0x00000000) : ULL(0x7fffffff,0xffffffff)),
1110 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1111 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1112 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1114 ok(result == str2longlong[test_num].value,
1115 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1116 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1117 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1118 pRtlFreeUnicodeString(&uni);
1122 static void test_wcschr(void)
1124 static const WCHAR teststringW[] = {'a','b','r','a','c','a','d','a','b','r','a',0};
1126 ok(p_wcschr(teststringW, 'a') == teststringW + 0,
1127 "wcschr should have returned a pointer to the first 'a' character\n");
1128 ok(p_wcschr(teststringW, 0) == teststringW + 11,
1129 "wcschr should have returned a pointer to the null terminator\n");
1130 ok(p_wcschr(teststringW, 'x') == NULL,
1131 "wcschr should have returned NULL\n");
1134 static void test_wcsrchr(void)
1136 static const WCHAR teststringW[] = {'a','b','r','a','c','a','d','a','b','r','a',0};
1138 ok(p_wcsrchr(teststringW, 'a') == teststringW + 10,
1139 "wcsrchr should have returned a pointer to the last 'a' character\n");
1140 ok(p_wcsrchr(teststringW, 0) == teststringW + 11,
1141 "wcsrchr should have returned a pointer to the null terminator\n");
1142 ok(p_wcsrchr(teststringW, 'x') == NULL,
1143 "wcsrchr should have returned NULL\n");
1146 static __cdecl int intcomparefunc(const void *a, const void*b)
1148 ok (a != b, "must never get the same pointer\n");
1149 return (*(int*)a) - (*(int*)b);
1152 static __cdecl int charcomparefunc(const void *a, const void*b)
1154 ok (a != b, "must never get the same pointer\n");
1155 return (*(char*)a) - (*(char*)b);
1158 static __cdecl int strcomparefunc(const void *a, const void*b)
1160 ok (a != b, "must never get the same pointer\n");
1161 return lstrcmpA(*(char**)a,*(char**)b);
1164 static void test_qsort(void)
1166 int arr[5] = { 23, 42, 8, 4, 16 };
1167 char carr[5] = { 42, 23, 4, 8, 16 };
1168 const char *strarr[7] = {
1178 p_qsort ((void*)arr, 0, sizeof(int), intcomparefunc);
1179 ok(arr[0] == 23, "badly sorted, nmemb=0, arr[0] is %d\n", arr[0]);
1180 ok(arr[1] == 42, "badly sorted, nmemb=0, arr[1] is %d\n", arr[1]);
1181 ok(arr[2] == 8, "badly sorted, nmemb=0, arr[2] is %d\n", arr[2]);
1182 ok(arr[3] == 4, "badly sorted, nmemb=0, arr[3] is %d\n", arr[3]);
1183 ok(arr[4] == 16, "badly sorted, nmemb=0, arr[4] is %d\n", arr[4]);
1185 p_qsort ((void*)arr, 1, sizeof(int), intcomparefunc);
1186 ok(arr[0] == 23, "badly sorted, nmemb=1, arr[0] is %d\n", arr[0]);
1187 ok(arr[1] == 42, "badly sorted, nmemb=1, arr[1] is %d\n", arr[1]);
1188 ok(arr[2] == 8, "badly sorted, nmemb=1, arr[2] is %d\n", arr[2]);
1189 ok(arr[3] == 4, "badly sorted, nmemb=1, arr[3] is %d\n", arr[3]);
1190 ok(arr[4] == 16, "badly sorted, nmemb=1, arr[4] is %d\n", arr[4]);
1192 p_qsort ((void*)arr, 5, 0, intcomparefunc);
1193 ok(arr[0] == 23, "badly sorted, size=0, arr[0] is %d\n", arr[0]);
1194 ok(arr[1] == 42, "badly sorted, size=0, arr[1] is %d\n", arr[1]);
1195 ok(arr[2] == 8, "badly sorted, size=0, arr[2] is %d\n", arr[2]);
1196 ok(arr[3] == 4, "badly sorted, size=0, arr[3] is %d\n", arr[3]);
1197 ok(arr[4] == 16, "badly sorted, size=0, arr[4] is %d\n", arr[4]);
1199 p_qsort ((void*)arr, 5, sizeof(int), intcomparefunc);
1200 ok(arr[0] == 4, "badly sorted, arr[0] is %d\n", arr[0]);
1201 ok(arr[1] == 8, "badly sorted, arr[1] is %d\n", arr[1]);
1202 ok(arr[2] == 16, "badly sorted, arr[2] is %d\n", arr[2]);
1203 ok(arr[3] == 23, "badly sorted, arr[3] is %d\n", arr[3]);
1204 ok(arr[4] == 42, "badly sorted, arr[4] is %d\n", arr[4]);
1206 p_qsort ((void*)carr, 5, sizeof(char), charcomparefunc);
1207 ok(carr[0] == 4, "badly sorted, carr[0] is %d\n", carr[0]);
1208 ok(carr[1] == 8, "badly sorted, carr[1] is %d\n", carr[1]);
1209 ok(carr[2] == 16, "badly sorted, carr[2] is %d\n", carr[2]);
1210 ok(carr[3] == 23, "badly sorted, carr[3] is %d\n", carr[3]);
1211 ok(carr[4] == 42, "badly sorted, carr[4] is %d\n", carr[4]);
1213 p_qsort ((void*)strarr, 7, sizeof(char*), strcomparefunc);
1214 ok(!strcmp(strarr[0],"!"), "badly sorted, strarr[0] is %s\n", strarr[0]);
1215 ok(!strcmp(strarr[1],"."), "badly sorted, strarr[1] is %s\n", strarr[1]);
1216 ok(!strcmp(strarr[2],"Hello"), "badly sorted, strarr[2] is %s\n", strarr[2]);
1217 ok(!strcmp(strarr[3],"Hopefully"), "badly sorted, strarr[3] is %s\n", strarr[3]);
1218 ok(!strcmp(strarr[4],"Sorted"), "badly sorted, strarr[4] is %s\n", strarr[4]);
1219 ok(!strcmp(strarr[5],"Wine"), "badly sorted, strarr[5] is %s\n", strarr[5]);
1220 ok(!strcmp(strarr[6],"World"), "badly sorted, strarr[6] is %s\n", strarr[6]);
1223 static void test_bsearch(void)
1225 int arr[7] = { 1, 3, 4, 8, 16, 23, 42 };
1228 /* just try all all sizes */
1229 for (j=1;j<sizeof(arr)/sizeof(arr[0]);j++) {
1232 x = p_bsearch (&l, arr, j, sizeof(arr[0]), intcomparefunc);
1233 ok (x == &arr[i], "bsearch did not find %d entry in loopsize %d.\n", i, j);
1236 x = p_bsearch (&l, arr, j, sizeof(arr[0]), intcomparefunc);
1237 ok (x == NULL, "bsearch did find 4242 entry in loopsize %d.\n", j);
1248 test_ulonglongtoa();
1254 test_ulonglongtow();