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