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