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)(unsigned long, 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)(unsigned long, 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 InitFunctionPtrs(void)
62 hntdll = LoadLibraryA("ntdll.dll");
63 ok(hntdll != 0, "LoadLibrary failed\n");
65 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
66 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
67 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
68 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
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");
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");
88 pwcstol = (void *)GetProcAddress(hntdll, "wcstol");
89 pwcstoul = (void *)GetProcAddress(hntdll, "wcstoul");
91 p_wcschr= (void *)GetProcAddress(hntdll, "wcschr");
92 p_wcsrchr= (void *)GetProcAddress(hntdll, "wcsrchr");
97 #define LARGE_STRI_BUFFER_LENGTH 67
103 int mask; /* ntdll/msvcrt: 0x01=itoa, 0x02=ltoa, 0x04=ultoa */
104 /* 0x10=itow, 0x20=ltow, 0x40=ultow */
107 static const ulong2str_t ulong2str[] = {
108 {10, 123, "123\0---------------------------------------------------------------", 0x77},
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},
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},
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},
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},
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},
206 #define NB_ULONG2STR (sizeof(ulong2str)/sizeof(*ulong2str))
209 static void one_itoa_test(int test_num, const ulong2str_t *ulong2str)
211 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
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);
228 static void one_ltoa_test(int test_num, const ulong2str_t *ulong2str)
230 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
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);
247 static void one_ultoa_test(int test_num, const ulong2str_t *ulong2str)
249 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
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);
266 static void test_ulongtoa(void)
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]);
274 if (ulong2str[test_num].mask & 0x02) {
275 one_ltoa_test(test_num, &ulong2str[test_num]);
277 if (ulong2str[test_num].mask & 0x04) {
278 one_ultoa_test(test_num, &ulong2str[test_num]);
284 static void one_itow_test(int test_num, const ulong2str_t *ulong2str)
287 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
288 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
289 UNICODE_STRING unicode_string;
294 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
295 expected_wstr[pos] = ulong2str->Buffer[pos];
297 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
299 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
300 dest_wstr[pos] = '-';
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);
319 static void one_ltow_test(int test_num, const ulong2str_t *ulong2str)
322 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
323 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
324 UNICODE_STRING unicode_string;
329 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
330 expected_wstr[pos] = ulong2str->Buffer[pos];
332 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
334 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
335 dest_wstr[pos] = '-';
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;
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);
355 static void one_ultow_test(int test_num, const ulong2str_t *ulong2str)
358 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
359 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
360 UNICODE_STRING unicode_string;
365 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
366 expected_wstr[pos] = ulong2str->Buffer[pos];
368 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
370 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
371 dest_wstr[pos] = '-';
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;
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);
391 static void test_ulongtow(void)
395 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
398 for (test_num = 0; test_num < NB_ULONG2STR; test_num++) {
399 if (ulong2str[test_num].mask & 0x10) {
400 one_itow_test(test_num, &ulong2str[test_num]);
402 if (ulong2str[test_num].mask & 0x20) {
403 one_ltow_test(test_num, &ulong2str[test_num]);
405 if (ulong2str[test_num].mask & 0x40) {
406 one_ultow_test(test_num, &ulong2str[test_num]);
410 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
411 expected_wstr[pos] = ulong2str[0].Buffer[pos];
413 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
416 /* Crashes on XP and W2K3 */
417 result = p_itow(ulong2str[0].value, NULL, 10);
419 "(test a): _itow(%d, NULL, 10) has result %p, expected: NULL\n",
420 ulong2str[0].value, result);
423 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
424 expected_wstr[pos] = ulong2str[0].Buffer[pos];
426 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
429 /* Crashes on XP and W2K3 */
430 result = p_ltow(ulong2str[0].value, NULL, 10);
432 "(test b): _ltow(%d, NULL, 10) has result %p, expected: NULL\n",
433 ulong2str[0].value, result);
436 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
437 expected_wstr[pos] = ulong2str[0].Buffer[pos];
439 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
442 /* Crashes on XP and W2K3 */
443 result = p_ultow(ulong2str[0].value, NULL, 10);
445 "(test c): _ultow(%d, NULL, 10) has result %p, expected: NULL\n",
446 ulong2str[0].value, result);
450 #define ULL(a,b) (((ULONGLONG)(a) << 32) | (b))
456 int mask; /* ntdll/msvcrt: 0x01=i64toa, 0x02=ui64toa, 0x04=wrong _i64toa try next example */
457 /* 0x10=i64tow, 0x20=ui64tow, 0x40=wrong _i64tow try next example */
460 static const ulonglong2str_t ulonglong2str[] = {
461 {10, 123, "123\0---------------------------------------------------------------", 0x33},
463 { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x33},
464 { 2, -2147483647, "1111111111111111111111111111111110000000000000000000000000000001\0--", 0x33},
465 { 2, -65537, "1111111111111111111111111111111111111111111111101111111111111111\0--", 0x33},
466 { 2, -65536, "1111111111111111111111111111111111111111111111110000000000000000\0--", 0x33},
467 { 2, -65535, "1111111111111111111111111111111111111111111111110000000000000001\0--", 0x33},
468 { 2, -32768, "1111111111111111111111111111111111111111111111111000000000000000\0--", 0x33},
469 { 2, -32767, "1111111111111111111111111111111111111111111111111000000000000001\0--", 0x33},
470 { 2, -2, "1111111111111111111111111111111111111111111111111111111111111110\0--", 0x33},
471 { 2, -1, "1111111111111111111111111111111111111111111111111111111111111111\0--", 0x33},
472 { 2, 0, "0\0-----------------------------------------------------------------", 0x33},
473 { 2, 1, "1\0-----------------------------------------------------------------", 0x33},
474 { 2, 10, "1010\0--------------------------------------------------------------", 0x33},
475 { 2, 100, "1100100\0-----------------------------------------------------------", 0x33},
476 { 2, 1000, "1111101000\0--------------------------------------------------------", 0x33},
477 { 2, 10000, "10011100010000\0----------------------------------------------------", 0x33},
478 { 2, 32767, "111111111111111\0---------------------------------------------------", 0x33},
479 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
480 { 2, 65535, "1111111111111111\0--------------------------------------------------", 0x33},
481 { 2, 100000, "11000011010100000\0-------------------------------------------------", 0x33},
482 { 2, 234567, "111001010001000111\0------------------------------------------------", 0x33},
483 { 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x33},
484 { 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x33},
485 { 2, 524288, "10000000000000000000\0----------------------------------------------", 0x33},
486 { 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x33},
487 { 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x33},
488 { 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x33},
489 { 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x33},
490 { 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x33},
491 { 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x33},
492 { 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x33},
493 { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x33},
494 { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x33},
495 { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x33},
496 { 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x33},
497 { 2, ULL(0x1,0xffffffff), "111111111111111111111111111111111\0---------------------------------", 0x33},
498 { 2, ((ULONGLONG)100000)*100000, "1001010100000010111110010000000000\0--------------------------------", 0x33},
499 { 2, ULL(0x3,0xffffffff), "1111111111111111111111111111111111\0--------------------------------", 0x33},
500 { 2, ULL(0x7,0xffffffff), "11111111111111111111111111111111111\0-------------------------------", 0x33},
501 { 2, ULL(0xf,0xffffffff), "111111111111111111111111111111111111\0------------------------------", 0x33},
502 { 2, ((ULONGLONG)100000)*1000000, "1011101001000011101101110100000000000\0-----------------------------", 0x33},
503 { 2, ULL(0x1f,0xffffffff), "1111111111111111111111111111111111111\0-----------------------------", 0x33},
504 { 2, ULL(0x3f,0xffffffff), "11111111111111111111111111111111111111\0----------------------------", 0x33},
505 { 2, ULL(0x7f,0xffffffff), "111111111111111111111111111111111111111\0---------------------------", 0x33},
506 { 2, ULL(0xff,0xffffffff), "1111111111111111111111111111111111111111\0--------------------------", 0x33},
508 { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x33},
509 { 8, -2147483647, "1777777777760000000001\0--------------------------------------------", 0x33},
510 { 8, -2, "1777777777777777777776\0--------------------------------------------", 0x33},
511 { 8, -1, "1777777777777777777777\0--------------------------------------------", 0x33},
512 { 8, 0, "0\0-----------------------------------------------------------------", 0x33},
513 { 8, 1, "1\0-----------------------------------------------------------------", 0x33},
514 { 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x33},
515 { 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x33},
516 { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x33},
517 { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x33},
518 { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x33},
519 { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x33},
521 {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x33},
522 {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x55},
523 {10, -2147483647, "-18446744071562067969\0---------------------------------------------", 0x00},
524 {10, -2147483647, "18446744071562067969\0----------------------------------------------", 0x22},
525 {10, -2, "-2\0----------------------------------------------------------------", 0x55},
526 {10, -2, "-18446744073709551614\0---------------------------------------------", 0x00},
527 {10, -2, "18446744073709551614\0----------------------------------------------", 0x22},
528 {10, -1, "-1\0----------------------------------------------------------------", 0x55},
529 {10, -1, "-18446744073709551615\0---------------------------------------------", 0x00},
530 {10, -1, "18446744073709551615\0----------------------------------------------", 0x22},
531 {10, 0, "0\0-----------------------------------------------------------------", 0x33},
532 {10, 1, "1\0-----------------------------------------------------------------", 0x33},
533 {10, 12, "12\0----------------------------------------------------------------", 0x33},
534 {10, 123, "123\0---------------------------------------------------------------", 0x33},
535 {10, 1234, "1234\0--------------------------------------------------------------", 0x33},
536 {10, 12345, "12345\0-------------------------------------------------------------", 0x33},
537 {10, 123456, "123456\0------------------------------------------------------------", 0x33},
538 {10, 1234567, "1234567\0-----------------------------------------------------------", 0x33},
539 {10, 12345678, "12345678\0----------------------------------------------------------", 0x33},
540 {10, 123456789, "123456789\0---------------------------------------------------------", 0x33},
541 {10, 2147483646, "2147483646\0--------------------------------------------------------", 0x33},
542 {10, 2147483647, "2147483647\0--------------------------------------------------------", 0x33},
543 {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x33},
544 {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x33},
545 {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x33},
546 {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x33},
547 {10, ULL(0x2,0xdfdc1c35), "12345678901\0-------------------------------------------------------", 0x33},
548 {10, ULL(0xe5,0xf4c8f374), "987654321012\0------------------------------------------------------", 0x33},
549 {10, ULL(0x1c0,0xfc161e3e), "1928374656574\0-----------------------------------------------------", 0x33},
550 {10, ULL(0xbad,0xcafeface), "12841062955726\0----------------------------------------------------", 0x33},
551 {10, ULL(0x5bad,0xcafeface), "100801993177806\0---------------------------------------------------", 0x33},
552 {10, ULL(0xaface,0xbeefcafe), "3090515640699646\0--------------------------------------------------", 0x33},
553 {10, ULL(0xa5beef,0xabcdcafe), "46653307746110206\0-------------------------------------------------", 0x33},
554 {10, ULL(0x1f8cf9b,0xf2df3af1), "142091656963767025\0------------------------------------------------", 0x33},
555 {10, ULL(0x0fffffff,0xffffffff), "1152921504606846975\0-----------------------------------------------", 0x33},
556 {10, ULL(0x7fffffff,0xffffffff), "9223372036854775807\0-----------------------------------------------", 0x33},
557 {10, ULL(0x80000000,0x00000000), "-9223372036854775808\0----------------------------------------------", 0x11},
558 {10, ULL(0x80000000,0x00000000), "9223372036854775808\0-----------------------------------------------", 0x22},
559 {10, ULL(0x80000000,0x00000001), "-9223372036854775807\0----------------------------------------------", 0x55},
560 {10, ULL(0x80000000,0x00000001), "-9223372036854775809\0----------------------------------------------", 0x00},
561 {10, ULL(0x80000000,0x00000001), "9223372036854775809\0-----------------------------------------------", 0x22},
562 {10, ULL(0x80000000,0x00000002), "-9223372036854775806\0----------------------------------------------", 0x55},
563 {10, ULL(0x80000000,0x00000002), "-9223372036854775810\0----------------------------------------------", 0x00},
564 {10, ULL(0x80000000,0x00000002), "9223372036854775810\0-----------------------------------------------", 0x22},
565 {10, ULL(0xffffffff,0xfffffffe), "-2\0----------------------------------------------------------------", 0x55},
566 {10, ULL(0xffffffff,0xfffffffe), "-18446744073709551614\0---------------------------------------------", 0x00},
567 {10, ULL(0xffffffff,0xfffffffe), "18446744073709551614\0----------------------------------------------", 0x22},
568 {10, ULL(0xffffffff,0xffffffff), "-1\0----------------------------------------------------------------", 0x55},
569 {10, ULL(0xffffffff,0xffffffff), "-18446744073709551615\0---------------------------------------------", 0x00},
570 {10, ULL(0xffffffff,0xffffffff), "18446744073709551615\0----------------------------------------------", 0x22},
572 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
573 {16, 1, "1\0-----------------------------------------------------------------", 0x33},
574 {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x33},
575 {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x33},
576 {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x33},
577 {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x33},
578 {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x33},
579 {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x33},
580 {16, ULL(0x1,0x00000000), "100000000\0---------------------------------------------------------", 0x33},
581 {16, ULL(0xbad,0xdeadbeef), "baddeadbeef\0-------------------------------------------------------", 0x33},
582 {16, ULL(0x80000000,0x00000000), "8000000000000000\0--------------------------------------------------", 0x33},
583 {16, ULL(0xfedcba98,0x76543210), "fedcba9876543210\0--------------------------------------------------", 0x33},
584 {16, ULL(0xffffffff,0x80000001), "ffffffff80000001\0--------------------------------------------------", 0x33},
585 {16, ULL(0xffffffff,0xfffffffe), "fffffffffffffffe\0--------------------------------------------------", 0x33},
586 {16, ULL(0xffffffff,0xffffffff), "ffffffffffffffff\0--------------------------------------------------", 0x33},
588 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
589 { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x33},
590 { 2, 131072, "100000000000000000\0------------------------------------------------", 0x33},
591 {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x33},
592 {16, 0xa, "a\0-----------------------------------------------------------------", 0x33},
593 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
594 {20, 3368421, "111111\0------------------------------------------------------------", 0x33},
595 {36, 62193781, "111111\0------------------------------------------------------------", 0x33},
596 {37, 71270178, "111111\0------------------------------------------------------------", 0x33},
597 {99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33},
599 #define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str))
602 static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
605 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
607 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
608 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
609 result = p_i64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
610 ok(result == dest_str,
611 "(test %d): _i64toa(%Lu, [out], %d) has result %p, expected: %p\n",
612 test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str);
613 if (ulonglong2str->mask & 0x04) {
614 if (memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
615 if (memcmp(dest_str, ulonglong2str[1].Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
616 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
617 "(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
618 test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
622 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
623 "(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
624 test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
629 static void one_ui64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
632 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
634 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
635 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
636 result = p_ui64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
637 ok(result == dest_str,
638 "(test %d): _ui64toa(%Lu, [out], %d) has result %p, expected: %p\n",
639 test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str);
640 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
641 "(test %d): _ui64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
642 test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
646 static void test_ulonglongtoa(void)
650 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
651 if (ulonglong2str[test_num].mask & 0x01) {
652 one_i64toa_test(test_num, &ulonglong2str[test_num]);
654 if (p_ui64toa != NULL) {
655 if (ulonglong2str[test_num].mask & 0x02) {
656 one_ui64toa_test(test_num, &ulonglong2str[test_num]);
663 static void one_i64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
666 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
667 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
668 UNICODE_STRING unicode_string;
672 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
673 expected_wstr[pos] = ulonglong2str->Buffer[pos];
675 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
677 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
678 dest_wstr[pos] = '-';
680 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
681 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
682 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
683 unicode_string.Buffer = dest_wstr;
685 result = p_i64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
686 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
687 ok(result == dest_wstr,
688 "(test %d): _i64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
689 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
690 ulonglong2str->base, result, dest_wstr);
691 if (ulonglong2str->mask & 0x04) {
692 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
693 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
694 expected_wstr[pos] = ulonglong2str[1].Buffer[pos];
696 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
697 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
698 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
699 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
700 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
701 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
705 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
706 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
707 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
708 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
710 pRtlFreeAnsiString(&ansi_str);
714 static void one_ui64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
717 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
718 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
719 UNICODE_STRING unicode_string;
723 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
724 expected_wstr[pos] = ulonglong2str->Buffer[pos];
726 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
728 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
729 dest_wstr[pos] = '-';
731 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
732 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
733 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
734 unicode_string.Buffer = dest_wstr;
736 result = p_ui64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
737 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
738 ok(result == dest_wstr,
739 "(test %d): _ui64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
740 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
741 ulonglong2str->base, result, dest_wstr);
742 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
743 "(test %d): _ui64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
744 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
745 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
746 pRtlFreeAnsiString(&ansi_str);
750 static void test_ulonglongtow(void)
754 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
757 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
758 if (ulonglong2str[test_num].mask & 0x10) {
759 one_i64tow_test(test_num, &ulonglong2str[test_num]);
762 if (ulonglong2str[test_num].mask & 0x20) {
763 one_ui64tow_test(test_num, &ulonglong2str[test_num]);
768 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
769 expected_wstr[pos] = ulong2str[0].Buffer[pos];
771 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
772 result = p_i64tow(ulong2str[0].value, NULL, 10);
774 "(test d): _i64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
775 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
778 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
779 expected_wstr[pos] = ulong2str[0].Buffer[pos];
781 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
782 result = p_ui64tow(ulong2str[0].value, NULL, 10);
784 "(test e): _ui64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
785 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
795 static const str2long_t str2long[] = {
796 { "1011101100", 1011101100 },
797 { "1234567", 1234567 },
799 { "+214", 214 }, /* The + sign is allowed also */
800 { "--214", 0 }, /* Do not accept more than one sign */
804 { "\00141", 0 }, /* not whitespace char 1 */
805 { "\00242", 0 }, /* not whitespace char 2 */
806 { "\00343", 0 }, /* not whitespace char 3 */
807 { "\00444", 0 }, /* not whitespace char 4 */
808 { "\00545", 0 }, /* not whitespace char 5 */
809 { "\00646", 0 }, /* not whitespace char 6 */
810 { "\00747", 0 }, /* not whitespace char 7 */
811 { "\01050", 0 }, /* not whitespace char 8 */
812 { "\01151", 51 }, /* is whitespace char 9 (tab) */
813 { "\01252", 52 }, /* is whitespace char 10 (lf) */
814 { "\01353", 53 }, /* is whitespace char 11 (vt) */
815 { "\01454", 54 }, /* is whitespace char 12 (ff) */
816 { "\01555", 55 }, /* is whitespace char 13 (cr) */
817 { "\01656", 0 }, /* not whitespace char 14 */
818 { "\01757", 0 }, /* not whitespace char 15 */
819 { "\02060", 0 }, /* not whitespace char 16 */
820 { "\02161", 0 }, /* not whitespace char 17 */
821 { "\02262", 0 }, /* not whitespace char 18 */
822 { "\02363", 0 }, /* not whitespace char 19 */
823 { "\02464", 0 }, /* not whitespace char 20 */
824 { "\02565", 0 }, /* not whitespace char 21 */
825 { "\02666", 0 }, /* not whitespace char 22 */
826 { "\02767", 0 }, /* not whitespace char 23 */
827 { "\03070", 0 }, /* not whitespace char 24 */
828 { "\03171", 0 }, /* not whitespace char 25 */
829 { "\03272", 0 }, /* not whitespace char 26 */
830 { "\03373", 0 }, /* not whitespace char 27 */
831 { "\03474", 0 }, /* not whitespace char 28 */
832 { "\03575", 0 }, /* not whitespace char 29 */
833 { "\03676", 0 }, /* not whitespace char 30 */
834 { "\03777", 0 }, /* not whitespace char 31 */
835 { "\04080", 80 }, /* is whitespace char 32 (space) */
836 { " \n \r \t214", 214 },
837 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
838 { " \n \r \t-214", -214 },
839 { "+214 0", 214 }, /* Space terminates the number */
840 { " 214.01", 214 }, /* Decimal point not accepted */
841 { " 214,01", 214 }, /* Decimal comma not accepted */
843 { "0x12345", 0 }, /* Hex not accepted */
847 { "-9999999999", -1410065407 }, /* Big negative integer */
848 { "-2147483649", 2147483647 }, /* Too small to fit in 32 Bits */
849 { "-2147483648", 0x80000000 }, /* Smallest negative integer */
850 { "-2147483647", -2147483647 },
854 { "2147483646", 2147483646 },
855 { "2147483647", 2147483647 }, /* Largest signed positive integer */
856 { "2147483648", 2147483648UL }, /* Positive int equal to smallest negative int */
857 { "2147483649", 2147483649UL },
858 { "4294967294", 4294967294UL },
859 { "4294967295", 4294967295UL }, /* Largest unsigned integer */
860 { "4294967296", 0 }, /* Too big to fit in 32 Bits */
861 { "9999999999", 1410065407 }, /* Big positive integer */
862 { "056789", 56789 }, /* Leading zero and still decimal */
863 { "b1011101100", 0 }, /* Binary (b-notation) */
864 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
865 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
866 { "0b1011101100", 0 }, /* Binary (0b-notation) */
867 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
868 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
869 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
870 { "0b1", 0 }, /* one digit binary */
871 { "0b2", 0 }, /* empty binary */
872 { "0b", 0 }, /* empty binary */
873 { "o1234567", 0 }, /* Octal (o-notation) */
874 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
875 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
876 { "0o1234567", 0 }, /* Octal (0o-notation) */
877 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
878 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
879 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
880 { "0o7", 0 }, /* one digit octal */
881 { "0o8", 0 }, /* empty octal */
882 { "0o", 0 }, /* empty octal */
883 { "0d1011101100", 0 }, /* explizit decimal with 0d */
884 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
885 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
886 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
887 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
888 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
889 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
890 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
891 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
892 { "0xF", 0 }, /* one digit hexadecimal */
893 { "0xG", 0 }, /* empty hexadecimal */
894 { "0x", 0 }, /* empty hexadecimal */
895 { "", 0 }, /* empty string */
896 /* { NULL, 0 }, */ /* NULL as string */
898 #define NB_STR2LONG (sizeof(str2long)/sizeof(*str2long))
901 static void test_wtoi(void)
907 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
908 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
909 result = p_wtoi(uni.Buffer);
910 ok(result == str2long[test_num].value,
911 "(test %d): call failed: _wtoi(\"%s\") has result %d, expected: %d\n",
912 test_num, str2long[test_num].str, result, str2long[test_num].value);
913 pRtlFreeUnicodeString(&uni);
918 static void test_wtol(void)
924 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
925 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
926 result = p_wtol(uni.Buffer);
927 ok(result == str2long[test_num].value,
928 "(test %d): call failed: _wtol(\"%s\") has result %d, expected: %d\n",
929 test_num, str2long[test_num].str, result, str2long[test_num].value);
930 pRtlFreeUnicodeString(&uni);
940 static const str2longlong_t str2longlong[] = {
941 { "1011101100", 1011101100 },
942 { "1234567", 1234567 },
944 { "+214", 214 }, /* The + sign is allowed also */
945 { "--214", 0 }, /* Do not accept more than one sign */
949 { "\00141", 0 }, /* not whitespace char 1 */
950 { "\00242", 0 }, /* not whitespace char 2 */
951 { "\00343", 0 }, /* not whitespace char 3 */
952 { "\00444", 0 }, /* not whitespace char 4 */
953 { "\00545", 0 }, /* not whitespace char 5 */
954 { "\00646", 0 }, /* not whitespace char 6 */
955 { "\00747", 0 }, /* not whitespace char 7 */
956 { "\01050", 0 }, /* not whitespace char 8 */
957 { "\01151", 51 }, /* is whitespace char 9 (tab) */
958 { "\01252", 52 }, /* is whitespace char 10 (lf) */
959 { "\01353", 53 }, /* is whitespace char 11 (vt) */
960 { "\01454", 54 }, /* is whitespace char 12 (ff) */
961 { "\01555", 55 }, /* is whitespace char 13 (cr) */
962 { "\01656", 0 }, /* not whitespace char 14 */
963 { "\01757", 0 }, /* not whitespace char 15 */
964 { "\02060", 0 }, /* not whitespace char 16 */
965 { "\02161", 0 }, /* not whitespace char 17 */
966 { "\02262", 0 }, /* not whitespace char 18 */
967 { "\02363", 0 }, /* not whitespace char 19 */
968 { "\02464", 0 }, /* not whitespace char 20 */
969 { "\02565", 0 }, /* not whitespace char 21 */
970 { "\02666", 0 }, /* not whitespace char 22 */
971 { "\02767", 0 }, /* not whitespace char 23 */
972 { "\03070", 0 }, /* not whitespace char 24 */
973 { "\03171", 0 }, /* not whitespace char 25 */
974 { "\03272", 0 }, /* not whitespace char 26 */
975 { "\03373", 0 }, /* not whitespace char 27 */
976 { "\03474", 0 }, /* not whitespace char 28 */
977 { "\03575", 0 }, /* not whitespace char 29 */
978 { "\03676", 0 }, /* not whitespace char 30 */
979 { "\03777", 0 }, /* not whitespace char 31 */
980 { "\04080", 80 }, /* is whitespace char 32 (space) */
981 { " \n \r \t214", 214 },
982 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
983 { " \n \r \t-214", -214 },
984 { "+214 0", 214 }, /* Space terminates the number */
985 { " 214.01", 214 }, /* Decimal point not accepted */
986 { " 214,01", 214 }, /* Decimal comma not accepted */
988 { "0x12345", 0 }, /* Hex not accepted */
992 { "-99999999999999999999", -ULL(0x6bc75e2d,0x630fffff) }, /* Big negative integer */
993 { "-9223372036854775809", ULL(0x7fffffff,0xffffffff) }, /* Too small to fit in 64 bits */
994 { "-9223372036854775808", ULL(0x80000000,0x00000000) }, /* Smallest negative 64 bit integer */
995 { "-9223372036854775807", -ULL(0x7fffffff,0xffffffff) },
996 { "-9999999999", -ULL(0x00000002,0x540be3ff) },
997 { "-2147483649", -ULL(0x00000000,0x80000001) }, /* Too small to fit in 32 bits */
998 { "-2147483648", -ULL(0x00000000,0x80000000) }, /* Smallest 32 bits negative integer */
999 { "-2147483647", -2147483647 },
1003 { "2147483646", 2147483646 },
1004 { "2147483647", 2147483647 }, /* Largest signed positive 32 bit integer */
1005 { "2147483648", ULL(0x00000000,0x80000000) }, /* Pos int equal to smallest neg 32 bit int */
1006 { "2147483649", ULL(0x00000000,0x80000001) },
1007 { "4294967294", ULL(0x00000000,0xfffffffe) },
1008 { "4294967295", ULL(0x00000000,0xffffffff) }, /* Largest unsigned 32 bit integer */
1009 { "4294967296", ULL(0x00000001,0x00000000) }, /* Too big to fit in 32 Bits */
1010 { "9999999999", ULL(0x00000002,0x540be3ff) },
1011 { "9223372036854775806", ULL(0x7fffffff,0xfffffffe) },
1012 { "9223372036854775807", ULL(0x7fffffff,0xffffffff) }, /* Largest signed positive 64 bit integer */
1013 { "9223372036854775808", ULL(0x80000000,0x00000000) }, /* Pos int equal to smallest neg 64 bit int */
1014 { "9223372036854775809", ULL(0x80000000,0x00000001) },
1015 { "18446744073709551614", ULL(0xffffffff,0xfffffffe) },
1016 { "18446744073709551615", ULL(0xffffffff,0xffffffff) }, /* Largest unsigned 64 bit integer */
1017 { "18446744073709551616", 0 }, /* Too big to fit in 64 bits */
1018 { "99999999999999999999", ULL(0x6bc75e2d,0x630fffff) }, /* Big positive integer */
1019 { "056789", 56789 }, /* Leading zero and still decimal */
1020 { "b1011101100", 0 }, /* Binary (b-notation) */
1021 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
1022 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1023 { "0b1011101100", 0 }, /* Binary (0b-notation) */
1024 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
1025 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1026 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
1027 { "0b1", 0 }, /* one digit binary */
1028 { "0b2", 0 }, /* empty binary */
1029 { "0b", 0 }, /* empty binary */
1030 { "o1234567", 0 }, /* Octal (o-notation) */
1031 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
1032 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1033 { "0o1234567", 0 }, /* Octal (0o-notation) */
1034 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
1035 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1036 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
1037 { "0o7", 0 }, /* one digit octal */
1038 { "0o8", 0 }, /* empty octal */
1039 { "0o", 0 }, /* empty octal */
1040 { "0d1011101100", 0 }, /* explizit decimal with 0d */
1041 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
1042 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
1043 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
1044 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
1045 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
1046 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
1047 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
1048 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
1049 { "0xF", 0 }, /* one digit hexadecimal */
1050 { "0xG", 0 }, /* empty hexadecimal */
1051 { "0x", 0 }, /* empty hexadecimal */
1052 { "", 0 }, /* empty string */
1053 /* { NULL, 0 }, */ /* NULL as string */
1055 #define NB_STR2LONGLONG (sizeof(str2longlong)/sizeof(*str2longlong))
1058 static void test_atoi64(void)
1063 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1064 result = p_atoi64(str2longlong[test_num].str);
1065 ok(result == str2longlong[test_num].value,
1066 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1067 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1068 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1073 static void test_wtoi64(void)
1079 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1080 pRtlCreateUnicodeStringFromAsciiz(&uni, str2longlong[test_num].str);
1081 result = p_wtoi64(uni.Buffer);
1082 ok(result == str2longlong[test_num].value,
1083 "(test %d): call failed: _wtoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1084 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1085 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1086 pRtlFreeUnicodeString(&uni);
1090 static void test_wcsfuncs(void)
1092 static const WCHAR testing[] = {'T','e','s','t','i','n','g',0};
1093 ok (p_wcschr(testing,0)!=NULL, "wcschr Not finding terminating character\n");
1094 ok (p_wcsrchr(testing,0)!=NULL, "wcsrchr Not finding terminating character\n");
1104 test_ulonglongtoa();
1110 test_ulonglongtow();
1117 if (p_wcschr && p_wcsrchr)