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