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