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