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';
414 result = p_itow(ulong2str[0].value, NULL, 10);
416 "(test a): _itow(%d, NULL, 10) has result %p, expected: NULL\n",
417 ulong2str[0].value, result);
419 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
420 expected_wstr[pos] = ulong2str[0].Buffer[pos];
422 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
423 result = p_ltow(ulong2str[0].value, NULL, 10);
425 "(test b): _ltow(%d, NULL, 10) has result %p, expected: NULL\n",
426 ulong2str[0].value, result);
428 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
429 expected_wstr[pos] = ulong2str[0].Buffer[pos];
431 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
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);
438 #define ULL(a,b) (((ULONGLONG)(a) << 32) | (b))
444 int mask; /* ntdll/msvcrt: 0x01=i64toa, 0x02=ui64toa, 0x04=wrong _i64toa try next example */
445 /* 0x10=i64tow, 0x20=ui64tow, 0x40=wrong _i64tow try next example */
448 static const ulonglong2str_t ulonglong2str[] = {
449 {10, 123, "123\0---------------------------------------------------------------", 0x33},
451 { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x33},
452 { 2, -2147483647, "1111111111111111111111111111111110000000000000000000000000000001\0--", 0x33},
453 { 2, -65537, "1111111111111111111111111111111111111111111111101111111111111111\0--", 0x33},
454 { 2, -65536, "1111111111111111111111111111111111111111111111110000000000000000\0--", 0x33},
455 { 2, -65535, "1111111111111111111111111111111111111111111111110000000000000001\0--", 0x33},
456 { 2, -32768, "1111111111111111111111111111111111111111111111111000000000000000\0--", 0x33},
457 { 2, -32767, "1111111111111111111111111111111111111111111111111000000000000001\0--", 0x33},
458 { 2, -2, "1111111111111111111111111111111111111111111111111111111111111110\0--", 0x33},
459 { 2, -1, "1111111111111111111111111111111111111111111111111111111111111111\0--", 0x33},
460 { 2, 0, "0\0-----------------------------------------------------------------", 0x33},
461 { 2, 1, "1\0-----------------------------------------------------------------", 0x33},
462 { 2, 10, "1010\0--------------------------------------------------------------", 0x33},
463 { 2, 100, "1100100\0-----------------------------------------------------------", 0x33},
464 { 2, 1000, "1111101000\0--------------------------------------------------------", 0x33},
465 { 2, 10000, "10011100010000\0----------------------------------------------------", 0x33},
466 { 2, 32767, "111111111111111\0---------------------------------------------------", 0x33},
467 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
468 { 2, 65535, "1111111111111111\0--------------------------------------------------", 0x33},
469 { 2, 100000, "11000011010100000\0-------------------------------------------------", 0x33},
470 { 2, 234567, "111001010001000111\0------------------------------------------------", 0x33},
471 { 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x33},
472 { 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x33},
473 { 2, 524288, "10000000000000000000\0----------------------------------------------", 0x33},
474 { 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x33},
475 { 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x33},
476 { 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x33},
477 { 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x33},
478 { 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x33},
479 { 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x33},
480 { 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x33},
481 { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x33},
482 { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x33},
483 { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x33},
484 { 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x33},
485 { 2, ULL(0x1,0xffffffff), "111111111111111111111111111111111\0---------------------------------", 0x33},
486 { 2, ((ULONGLONG)100000)*100000, "1001010100000010111110010000000000\0--------------------------------", 0x33},
487 { 2, ULL(0x3,0xffffffff), "1111111111111111111111111111111111\0--------------------------------", 0x33},
488 { 2, ULL(0x7,0xffffffff), "11111111111111111111111111111111111\0-------------------------------", 0x33},
489 { 2, ULL(0xf,0xffffffff), "111111111111111111111111111111111111\0------------------------------", 0x33},
490 { 2, ((ULONGLONG)100000)*1000000, "1011101001000011101101110100000000000\0-----------------------------", 0x33},
491 { 2, ULL(0x1f,0xffffffff), "1111111111111111111111111111111111111\0-----------------------------", 0x33},
492 { 2, ULL(0x3f,0xffffffff), "11111111111111111111111111111111111111\0----------------------------", 0x33},
493 { 2, ULL(0x7f,0xffffffff), "111111111111111111111111111111111111111\0---------------------------", 0x33},
494 { 2, ULL(0xff,0xffffffff), "1111111111111111111111111111111111111111\0--------------------------", 0x33},
496 { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x33},
497 { 8, -2147483647, "1777777777760000000001\0--------------------------------------------", 0x33},
498 { 8, -2, "1777777777777777777776\0--------------------------------------------", 0x33},
499 { 8, -1, "1777777777777777777777\0--------------------------------------------", 0x33},
500 { 8, 0, "0\0-----------------------------------------------------------------", 0x33},
501 { 8, 1, "1\0-----------------------------------------------------------------", 0x33},
502 { 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x33},
503 { 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x33},
504 { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x33},
505 { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x33},
506 { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x33},
507 { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x33},
509 {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x33},
510 {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x55},
511 {10, -2147483647, "-18446744071562067969\0---------------------------------------------", 0x00},
512 {10, -2147483647, "18446744071562067969\0----------------------------------------------", 0x22},
513 {10, -2, "-2\0----------------------------------------------------------------", 0x55},
514 {10, -2, "-18446744073709551614\0---------------------------------------------", 0x00},
515 {10, -2, "18446744073709551614\0----------------------------------------------", 0x22},
516 {10, -1, "-1\0----------------------------------------------------------------", 0x55},
517 {10, -1, "-18446744073709551615\0---------------------------------------------", 0x00},
518 {10, -1, "18446744073709551615\0----------------------------------------------", 0x22},
519 {10, 0, "0\0-----------------------------------------------------------------", 0x33},
520 {10, 1, "1\0-----------------------------------------------------------------", 0x33},
521 {10, 12, "12\0----------------------------------------------------------------", 0x33},
522 {10, 123, "123\0---------------------------------------------------------------", 0x33},
523 {10, 1234, "1234\0--------------------------------------------------------------", 0x33},
524 {10, 12345, "12345\0-------------------------------------------------------------", 0x33},
525 {10, 123456, "123456\0------------------------------------------------------------", 0x33},
526 {10, 1234567, "1234567\0-----------------------------------------------------------", 0x33},
527 {10, 12345678, "12345678\0----------------------------------------------------------", 0x33},
528 {10, 123456789, "123456789\0---------------------------------------------------------", 0x33},
529 {10, 2147483646, "2147483646\0--------------------------------------------------------", 0x33},
530 {10, 2147483647, "2147483647\0--------------------------------------------------------", 0x33},
531 {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x33},
532 {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x33},
533 {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x33},
534 {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x33},
535 {10, ULL(0x2,0xdfdc1c35), "12345678901\0-------------------------------------------------------", 0x33},
536 {10, ULL(0xe5,0xf4c8f374), "987654321012\0------------------------------------------------------", 0x33},
537 {10, ULL(0x1c0,0xfc161e3e), "1928374656574\0-----------------------------------------------------", 0x33},
538 {10, ULL(0xbad,0xcafeface), "12841062955726\0----------------------------------------------------", 0x33},
539 {10, ULL(0x5bad,0xcafeface), "100801993177806\0---------------------------------------------------", 0x33},
540 {10, ULL(0xaface,0xbeefcafe), "3090515640699646\0--------------------------------------------------", 0x33},
541 {10, ULL(0xa5beef,0xabcdcafe), "46653307746110206\0-------------------------------------------------", 0x33},
542 {10, ULL(0x1f8cf9b,0xf2df3af1), "142091656963767025\0------------------------------------------------", 0x33},
543 {10, ULL(0x0fffffff,0xffffffff), "1152921504606846975\0-----------------------------------------------", 0x33},
544 {10, ULL(0x7fffffff,0xffffffff), "9223372036854775807\0-----------------------------------------------", 0x33},
545 {10, ULL(0x80000000,0x00000000), "-9223372036854775808\0----------------------------------------------", 0x11},
546 {10, ULL(0x80000000,0x00000000), "9223372036854775808\0-----------------------------------------------", 0x22},
547 {10, ULL(0x80000000,0x00000001), "-9223372036854775807\0----------------------------------------------", 0x55},
548 {10, ULL(0x80000000,0x00000001), "-9223372036854775809\0----------------------------------------------", 0x00},
549 {10, ULL(0x80000000,0x00000001), "9223372036854775809\0-----------------------------------------------", 0x22},
550 {10, ULL(0x80000000,0x00000002), "-9223372036854775806\0----------------------------------------------", 0x55},
551 {10, ULL(0x80000000,0x00000002), "-9223372036854775810\0----------------------------------------------", 0x00},
552 {10, ULL(0x80000000,0x00000002), "9223372036854775810\0-----------------------------------------------", 0x22},
553 {10, ULL(0xffffffff,0xfffffffe), "-2\0----------------------------------------------------------------", 0x55},
554 {10, ULL(0xffffffff,0xfffffffe), "-18446744073709551614\0---------------------------------------------", 0x00},
555 {10, ULL(0xffffffff,0xfffffffe), "18446744073709551614\0----------------------------------------------", 0x22},
556 {10, ULL(0xffffffff,0xffffffff), "-1\0----------------------------------------------------------------", 0x55},
557 {10, ULL(0xffffffff,0xffffffff), "-18446744073709551615\0---------------------------------------------", 0x00},
558 {10, ULL(0xffffffff,0xffffffff), "18446744073709551615\0----------------------------------------------", 0x22},
560 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
561 {16, 1, "1\0-----------------------------------------------------------------", 0x33},
562 {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x33},
563 {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x33},
564 {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x33},
565 {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x33},
566 {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x33},
567 {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x33},
568 {16, ULL(0x1,0x00000000), "100000000\0---------------------------------------------------------", 0x33},
569 {16, ULL(0xbad,0xdeadbeef), "baddeadbeef\0-------------------------------------------------------", 0x33},
570 {16, ULL(0x80000000,0x00000000), "8000000000000000\0--------------------------------------------------", 0x33},
571 {16, ULL(0xfedcba98,0x76543210), "fedcba9876543210\0--------------------------------------------------", 0x33},
572 {16, ULL(0xffffffff,0x80000001), "ffffffff80000001\0--------------------------------------------------", 0x33},
573 {16, ULL(0xffffffff,0xfffffffe), "fffffffffffffffe\0--------------------------------------------------", 0x33},
574 {16, ULL(0xffffffff,0xffffffff), "ffffffffffffffff\0--------------------------------------------------", 0x33},
576 { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
577 { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x33},
578 { 2, 131072, "100000000000000000\0------------------------------------------------", 0x33},
579 {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x33},
580 {16, 0xa, "a\0-----------------------------------------------------------------", 0x33},
581 {16, 0, "0\0-----------------------------------------------------------------", 0x33},
582 {20, 3368421, "111111\0------------------------------------------------------------", 0x33},
583 {36, 62193781, "111111\0------------------------------------------------------------", 0x33},
584 {37, 71270178, "111111\0------------------------------------------------------------", 0x33},
585 {99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33},
587 #define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str))
590 static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
593 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
595 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
596 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
597 result = p_i64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
598 ok(result == dest_str,
599 "(test %d): _i64toa(%Lu, [out], %d) has result %p, expected: %p\n",
600 test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str);
601 if (ulonglong2str->mask & 0x04) {
602 if (memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
603 if (memcmp(dest_str, ulonglong2str[1].Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
604 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
605 "(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
606 test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
610 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
611 "(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
612 test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
617 static void one_ui64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
620 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
622 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
623 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
624 result = p_ui64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
625 ok(result == dest_str,
626 "(test %d): _ui64toa(%Lu, [out], %d) has result %p, expected: %p\n",
627 test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str);
628 ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
629 "(test %d): _ui64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
630 test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
634 static void test_ulonglongtoa(void)
638 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
639 if (ulonglong2str[test_num].mask & 0x01) {
640 one_i64toa_test(test_num, &ulonglong2str[test_num]);
642 if (p_ui64toa != NULL) {
643 if (ulonglong2str[test_num].mask & 0x02) {
644 one_ui64toa_test(test_num, &ulonglong2str[test_num]);
651 static void one_i64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
654 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
655 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
656 UNICODE_STRING unicode_string;
660 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
661 expected_wstr[pos] = ulonglong2str->Buffer[pos];
663 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
665 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
666 dest_wstr[pos] = '-';
668 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
669 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
670 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
671 unicode_string.Buffer = dest_wstr;
673 result = p_i64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
674 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
675 ok(result == dest_wstr,
676 "(test %d): _i64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
677 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
678 ulonglong2str->base, result, dest_wstr);
679 if (ulonglong2str->mask & 0x04) {
680 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
681 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
682 expected_wstr[pos] = ulonglong2str[1].Buffer[pos];
684 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
685 if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) {
686 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
687 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
688 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
689 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
693 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
694 "(test %d): _i64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
695 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
696 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
698 pRtlFreeAnsiString(&ansi_str);
702 static void one_ui64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
705 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
706 WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
707 UNICODE_STRING unicode_string;
711 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
712 expected_wstr[pos] = ulonglong2str->Buffer[pos];
714 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
716 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
717 dest_wstr[pos] = '-';
719 dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
720 unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR);
721 unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR);
722 unicode_string.Buffer = dest_wstr;
724 result = p_ui64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base);
725 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
726 ok(result == dest_wstr,
727 "(test %d): _ui64tow(0x%x%08x, [out], %d) has result %p, expected: %p\n",
728 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
729 ulonglong2str->base, result, dest_wstr);
730 ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
731 "(test %d): _ui64tow(0x%x%08x, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
732 test_num, (DWORD)(ulonglong2str->value >> 32), (DWORD)ulonglong2str->value,
733 ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer);
734 pRtlFreeAnsiString(&ansi_str);
738 static void test_ulonglongtow(void)
742 WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
745 for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
746 if (ulonglong2str[test_num].mask & 0x10) {
747 one_i64tow_test(test_num, &ulonglong2str[test_num]);
750 if (ulonglong2str[test_num].mask & 0x20) {
751 one_ui64tow_test(test_num, &ulonglong2str[test_num]);
756 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
757 expected_wstr[pos] = ulong2str[0].Buffer[pos];
759 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
760 result = p_i64tow(ulong2str[0].value, NULL, 10);
762 "(test d): _i64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
763 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
766 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
767 expected_wstr[pos] = ulong2str[0].Buffer[pos];
769 expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
770 result = p_ui64tow(ulong2str[0].value, NULL, 10);
772 "(test e): _ui64tow(0x%x%08x, NULL, 10) has result %p, expected: NULL\n",
773 (DWORD)(ulonglong2str[0].value >> 32), (DWORD)ulonglong2str[0].value, result);
783 static const str2long_t str2long[] = {
784 { "1011101100", 1011101100 },
785 { "1234567", 1234567 },
787 { "+214", 214 }, /* The + sign is allowed also */
788 { "--214", 0 }, /* Do not accept more than one sign */
792 { "\00141", 0 }, /* not whitespace char 1 */
793 { "\00242", 0 }, /* not whitespace char 2 */
794 { "\00343", 0 }, /* not whitespace char 3 */
795 { "\00444", 0 }, /* not whitespace char 4 */
796 { "\00545", 0 }, /* not whitespace char 5 */
797 { "\00646", 0 }, /* not whitespace char 6 */
798 { "\00747", 0 }, /* not whitespace char 7 */
799 { "\01050", 0 }, /* not whitespace char 8 */
800 { "\01151", 51 }, /* is whitespace char 9 (tab) */
801 { "\01252", 52 }, /* is whitespace char 10 (lf) */
802 { "\01353", 53 }, /* is whitespace char 11 (vt) */
803 { "\01454", 54 }, /* is whitespace char 12 (ff) */
804 { "\01555", 55 }, /* is whitespace char 13 (cr) */
805 { "\01656", 0 }, /* not whitespace char 14 */
806 { "\01757", 0 }, /* not whitespace char 15 */
807 { "\02060", 0 }, /* not whitespace char 16 */
808 { "\02161", 0 }, /* not whitespace char 17 */
809 { "\02262", 0 }, /* not whitespace char 18 */
810 { "\02363", 0 }, /* not whitespace char 19 */
811 { "\02464", 0 }, /* not whitespace char 20 */
812 { "\02565", 0 }, /* not whitespace char 21 */
813 { "\02666", 0 }, /* not whitespace char 22 */
814 { "\02767", 0 }, /* not whitespace char 23 */
815 { "\03070", 0 }, /* not whitespace char 24 */
816 { "\03171", 0 }, /* not whitespace char 25 */
817 { "\03272", 0 }, /* not whitespace char 26 */
818 { "\03373", 0 }, /* not whitespace char 27 */
819 { "\03474", 0 }, /* not whitespace char 28 */
820 { "\03575", 0 }, /* not whitespace char 29 */
821 { "\03676", 0 }, /* not whitespace char 30 */
822 { "\03777", 0 }, /* not whitespace char 31 */
823 { "\04080", 80 }, /* is whitespace char 32 (space) */
824 { " \n \r \t214", 214 },
825 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
826 { " \n \r \t-214", -214 },
827 { "+214 0", 214 }, /* Space terminates the number */
828 { " 214.01", 214 }, /* Decimal point not accepted */
829 { " 214,01", 214 }, /* Decimal comma not accepted */
831 { "0x12345", 0 }, /* Hex not accepted */
835 { "-9999999999", -1410065407 }, /* Big negative integer */
836 { "-2147483649", 2147483647 }, /* Too small to fit in 32 Bits */
837 { "-2147483648", 0x80000000 }, /* Smallest negative integer */
838 { "-2147483647", -2147483647 },
842 { "2147483646", 2147483646 },
843 { "2147483647", 2147483647 }, /* Largest signed positive integer */
844 { "2147483648", 2147483648UL }, /* Positive int equal to smallest negative int */
845 { "2147483649", 2147483649UL },
846 { "4294967294", 4294967294UL },
847 { "4294967295", 4294967295UL }, /* Largest unsigned integer */
848 { "4294967296", 0 }, /* Too big to fit in 32 Bits */
849 { "9999999999", 1410065407 }, /* Big positive integer */
850 { "056789", 56789 }, /* Leading zero and still decimal */
851 { "b1011101100", 0 }, /* Binary (b-notation) */
852 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
853 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
854 { "0b1011101100", 0 }, /* Binary (0b-notation) */
855 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
856 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
857 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
858 { "0b1", 0 }, /* one digit binary */
859 { "0b2", 0 }, /* empty binary */
860 { "0b", 0 }, /* empty binary */
861 { "o1234567", 0 }, /* Octal (o-notation) */
862 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
863 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
864 { "0o1234567", 0 }, /* Octal (0o-notation) */
865 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
866 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
867 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
868 { "0o7", 0 }, /* one digit octal */
869 { "0o8", 0 }, /* empty octal */
870 { "0o", 0 }, /* empty octal */
871 { "0d1011101100", 0 }, /* explizit decimal with 0d */
872 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
873 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
874 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
875 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
876 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
877 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
878 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
879 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
880 { "0xF", 0 }, /* one digit hexadecimal */
881 { "0xG", 0 }, /* empty hexadecimal */
882 { "0x", 0 }, /* empty hexadecimal */
883 { "", 0 }, /* empty string */
884 /* { NULL, 0 }, */ /* NULL as string */
886 #define NB_STR2LONG (sizeof(str2long)/sizeof(*str2long))
889 static void test_wtoi(void)
895 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
896 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
897 result = p_wtoi(uni.Buffer);
898 ok(result == str2long[test_num].value,
899 "(test %d): call failed: _wtoi(\"%s\") has result %d, expected: %d\n",
900 test_num, str2long[test_num].str, result, str2long[test_num].value);
901 pRtlFreeUnicodeString(&uni);
906 static void test_wtol(void)
912 for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
913 pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
914 result = p_wtol(uni.Buffer);
915 ok(result == str2long[test_num].value,
916 "(test %d): call failed: _wtol(\"%s\") has result %d, expected: %d\n",
917 test_num, str2long[test_num].str, result, str2long[test_num].value);
918 pRtlFreeUnicodeString(&uni);
928 static const str2longlong_t str2longlong[] = {
929 { "1011101100", 1011101100 },
930 { "1234567", 1234567 },
932 { "+214", 214 }, /* The + sign is allowed also */
933 { "--214", 0 }, /* Do not accept more than one sign */
937 { "\00141", 0 }, /* not whitespace char 1 */
938 { "\00242", 0 }, /* not whitespace char 2 */
939 { "\00343", 0 }, /* not whitespace char 3 */
940 { "\00444", 0 }, /* not whitespace char 4 */
941 { "\00545", 0 }, /* not whitespace char 5 */
942 { "\00646", 0 }, /* not whitespace char 6 */
943 { "\00747", 0 }, /* not whitespace char 7 */
944 { "\01050", 0 }, /* not whitespace char 8 */
945 { "\01151", 51 }, /* is whitespace char 9 (tab) */
946 { "\01252", 52 }, /* is whitespace char 10 (lf) */
947 { "\01353", 53 }, /* is whitespace char 11 (vt) */
948 { "\01454", 54 }, /* is whitespace char 12 (ff) */
949 { "\01555", 55 }, /* is whitespace char 13 (cr) */
950 { "\01656", 0 }, /* not whitespace char 14 */
951 { "\01757", 0 }, /* not whitespace char 15 */
952 { "\02060", 0 }, /* not whitespace char 16 */
953 { "\02161", 0 }, /* not whitespace char 17 */
954 { "\02262", 0 }, /* not whitespace char 18 */
955 { "\02363", 0 }, /* not whitespace char 19 */
956 { "\02464", 0 }, /* not whitespace char 20 */
957 { "\02565", 0 }, /* not whitespace char 21 */
958 { "\02666", 0 }, /* not whitespace char 22 */
959 { "\02767", 0 }, /* not whitespace char 23 */
960 { "\03070", 0 }, /* not whitespace char 24 */
961 { "\03171", 0 }, /* not whitespace char 25 */
962 { "\03272", 0 }, /* not whitespace char 26 */
963 { "\03373", 0 }, /* not whitespace char 27 */
964 { "\03474", 0 }, /* not whitespace char 28 */
965 { "\03575", 0 }, /* not whitespace char 29 */
966 { "\03676", 0 }, /* not whitespace char 30 */
967 { "\03777", 0 }, /* not whitespace char 31 */
968 { "\04080", 80 }, /* is whitespace char 32 (space) */
969 { " \n \r \t214", 214 },
970 { " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
971 { " \n \r \t-214", -214 },
972 { "+214 0", 214 }, /* Space terminates the number */
973 { " 214.01", 214 }, /* Decimal point not accepted */
974 { " 214,01", 214 }, /* Decimal comma not accepted */
976 { "0x12345", 0 }, /* Hex not accepted */
980 { "-99999999999999999999", -ULL(0x6bc75e2d,0x630fffff) }, /* Big negative integer */
981 { "-9223372036854775809", ULL(0x7fffffff,0xffffffff) }, /* Too small to fit in 64 bits */
982 { "-9223372036854775808", ULL(0x80000000,0x00000000) }, /* Smallest negative 64 bit integer */
983 { "-9223372036854775807", -ULL(0x7fffffff,0xffffffff) },
984 { "-9999999999", -ULL(0x00000002,0x540be3ff) },
985 { "-2147483649", -ULL(0x00000000,0x80000001) }, /* Too small to fit in 32 bits */
986 { "-2147483648", -ULL(0x00000000,0x80000000) }, /* Smallest 32 bits negative integer */
987 { "-2147483647", -2147483647 },
991 { "2147483646", 2147483646 },
992 { "2147483647", 2147483647 }, /* Largest signed positive 32 bit integer */
993 { "2147483648", ULL(0x00000000,0x80000000) }, /* Pos int equal to smallest neg 32 bit int */
994 { "2147483649", ULL(0x00000000,0x80000001) },
995 { "4294967294", ULL(0x00000000,0xfffffffe) },
996 { "4294967295", ULL(0x00000000,0xffffffff) }, /* Largest unsigned 32 bit integer */
997 { "4294967296", ULL(0x00000001,0x00000000) }, /* Too big to fit in 32 Bits */
998 { "9999999999", ULL(0x00000002,0x540be3ff) },
999 { "9223372036854775806", ULL(0x7fffffff,0xfffffffe) },
1000 { "9223372036854775807", ULL(0x7fffffff,0xffffffff) }, /* Largest signed positive 64 bit integer */
1001 { "9223372036854775808", ULL(0x80000000,0x00000000) }, /* Pos int equal to smallest neg 64 bit int */
1002 { "9223372036854775809", ULL(0x80000000,0x00000001) },
1003 { "18446744073709551614", ULL(0xffffffff,0xfffffffe) },
1004 { "18446744073709551615", ULL(0xffffffff,0xffffffff) }, /* Largest unsigned 64 bit integer */
1005 { "18446744073709551616", 0 }, /* Too big to fit in 64 bits */
1006 { "99999999999999999999", ULL(0x6bc75e2d,0x630fffff) }, /* Big positive integer */
1007 { "056789", 56789 }, /* Leading zero and still decimal */
1008 { "b1011101100", 0 }, /* Binary (b-notation) */
1009 { "-b1011101100", 0 }, /* Negative Binary (b-notation) */
1010 { "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1011 { "0b1011101100", 0 }, /* Binary (0b-notation) */
1012 { "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
1013 { "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
1014 { "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
1015 { "0b1", 0 }, /* one digit binary */
1016 { "0b2", 0 }, /* empty binary */
1017 { "0b", 0 }, /* empty binary */
1018 { "o1234567", 0 }, /* Octal (o-notation) */
1019 { "-o1234567", 0 }, /* Negative Octal (o-notation) */
1020 { "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1021 { "0o1234567", 0 }, /* Octal (0o-notation) */
1022 { "-0o1234567", 0 }, /* Negative octal (0o-notation) */
1023 { "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
1024 { "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
1025 { "0o7", 0 }, /* one digit octal */
1026 { "0o8", 0 }, /* empty octal */
1027 { "0o", 0 }, /* empty octal */
1028 { "0d1011101100", 0 }, /* explizit decimal with 0d */
1029 { "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
1030 { "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
1031 { "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
1032 { "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
1033 { "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
1034 { "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
1035 { "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
1036 { "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
1037 { "0xF", 0 }, /* one digit hexadecimal */
1038 { "0xG", 0 }, /* empty hexadecimal */
1039 { "0x", 0 }, /* empty hexadecimal */
1040 { "", 0 }, /* empty string */
1041 /* { NULL, 0 }, */ /* NULL as string */
1043 #define NB_STR2LONGLONG (sizeof(str2longlong)/sizeof(*str2longlong))
1046 static void test_atoi64(void)
1051 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1052 result = p_atoi64(str2longlong[test_num].str);
1053 ok(result == str2longlong[test_num].value,
1054 "(test %d): call failed: _atoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1055 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1056 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1061 static void test_wtoi64(void)
1067 for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
1068 pRtlCreateUnicodeStringFromAsciiz(&uni, str2longlong[test_num].str);
1069 result = p_wtoi64(uni.Buffer);
1070 ok(result == str2longlong[test_num].value,
1071 "(test %d): call failed: _wtoi64(\"%s\") has result 0x%x%08x, expected: 0x%x%08x\n",
1072 test_num, str2longlong[test_num].str, (DWORD)(result >> 32), (DWORD)result,
1073 (DWORD)(str2longlong[test_num].value >> 32), (DWORD)str2longlong[test_num].value);
1074 pRtlFreeUnicodeString(&uni);
1078 static void test_wcsfuncs(void)
1080 static const WCHAR testing[] = {'T','e','s','t','i','n','g',0};
1081 ok (p_wcschr(testing,0)!=NULL, "wcschr Not finding terminating character\n");
1082 ok (p_wcsrchr(testing,0)!=NULL, "wcsrchr Not finding terminating character\n");
1092 test_ulonglongtoa();
1098 test_ulonglongtow();
1105 if (p_wcschr && p_wcsrchr)