2 * Unit test suite for string functions.
4 * Copyright 2004 Uwe Bonnes
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
34 /* make it use a definition from string.h */
41 static char *buf_to_string(const unsigned char *bin
, int len
, int nr
)
43 static char buf
[2][1024];
47 for (i
= 0; i
< len
; i
++)
49 sprintf(w
, "%02x ", (unsigned char)bin
[i
]);
55 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
56 #define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); }
58 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
59 static int (__cdecl
*p_memcpy_s
)(void *, size_t, const void *, size_t);
60 static int (__cdecl
*p_memmove_s
)(void *, size_t, const void *, size_t);
61 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
62 static int (__cdecl
*p_strcmp
)(const char *, const char *);
63 static int (__cdecl
*p_strncmp
)(const char *, const char *, size_t);
64 static int (__cdecl
*p_strcpy
)(char *dst
, const char *src
);
65 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
66 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
67 static int (__cdecl
*p_mbscat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
);
68 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
69 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
70 static int (__cdecl
*p__mbscpy_s
)(unsigned char*, size_t, const unsigned char*);
71 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
72 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
73 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
74 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
75 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
76 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
77 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
78 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
79 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
80 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
81 static int (__cdecl
*p_wcstombs_s_l
)(size_t*,char*,size_t,const wchar_t*,size_t,_locale_t
);
82 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
83 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
84 static int (__cdecl
*p_mbsrtowcs_s
)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
85 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
86 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
87 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
88 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
89 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
90 static int *p__mb_cur_max
;
91 static unsigned char *p_mbctype
;
92 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
93 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
94 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
95 static int (__cdecl
*p_wctob
)(wint_t);
96 static wint_t (__cdecl
*p_btowc
)(int);
97 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
98 static int (__cdecl
*p_wcrtomb_s
)(size_t*, char*, size_t, wchar_t, mbstate_t*);
99 static int (__cdecl
*p_tolower
)(int);
100 static int (__cdecl
*p_towlower
)(wint_t);
101 static int (__cdecl
*p__towlower_l
)(wint_t, _locale_t
);
102 static int (__cdecl
*p_towupper
)(wint_t);
103 static int (__cdecl
*p__towupper_l
)(wint_t, _locale_t
);
104 static _locale_t(__cdecl
*p__create_locale
)(int, const char*);
105 static void(__cdecl
*p__free_locale
)(_locale_t
);
106 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
107 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
108 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
109 static double (__cdecl
*p__atof_l
)(const char*,_locale_t
);
110 static double (__cdecl
*p__strtod_l
)(const char *,char**,_locale_t
);
111 static int (__cdecl
*p__strnset_s
)(char*,size_t,int,size_t);
112 static int (__cdecl
*p__wcsnset_s
)(wchar_t*,size_t,wchar_t,size_t);
113 static int (__cdecl
*p__wcsset_s
)(wchar_t*,size_t,wchar_t);
114 static size_t (__cdecl
*p__mbsnlen
)(const unsigned char*, size_t);
115 static int (__cdecl
*p__mbccpy_s
)(unsigned char*, size_t, int*, const unsigned char*);
116 static int (__cdecl
*p__memicmp
)(const char*, const char*, size_t);
117 static int (__cdecl
*p__memicmp_l
)(const char*, const char*, size_t, _locale_t
);
118 static size_t (__cdecl
*p___strncnt
)(const char*, size_t);
119 static unsigned int (__cdecl
*p_mbsnextc_l
)(const unsigned char*, _locale_t
);
120 static int (__cdecl
*p_mbscmp_l
)(const unsigned char*, const unsigned char*, _locale_t
);
122 int CDECL
__STRINGTOLD(_LDOUBLE
*, char**, const char*, int);
124 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
125 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
127 static HMODULE hMsvcrt
;
129 static void test_swab( void ) {
130 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
131 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
132 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
133 char expected3
[] = "$";
140 /* Test 1 - normal even case */
141 memset(to
,'$', sizeof(to
));
142 memset(from
,'@', sizeof(from
));
144 memcpy(from
, original
, testsize
);
145 _swab( from
, to
, testsize
);
146 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
148 /* Test 2 - uneven case */
149 memset(to
,'$', sizeof(to
));
150 memset(from
,'@', sizeof(from
));
152 memcpy(from
, original
, testsize
);
153 _swab( from
, to
, testsize
);
154 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
156 /* Test 3 - from = to */
157 memset(to
,'$', sizeof(to
));
158 memset(from
,'@', sizeof(from
));
160 memcpy(to
, original
, testsize
);
161 _swab( to
, to
, testsize
);
162 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
164 /* Test 4 - 1 bytes */
165 memset(to
,'$', sizeof(to
));
166 memset(from
,'@', sizeof(from
));
168 memcpy(from
, original
, testsize
);
169 _swab( from
, to
, testsize
);
170 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
173 static void test_strcspn(void)
175 static const struct {
184 { "a\xf1", "\xf1", 1 }
188 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
190 r
= strcspn(tests
[i
].str
, tests
[i
].rej
);
191 ok(r
== tests
[i
].ret
, "strcspn(\"%s\", \"%s\") = %d, expected %d\n",
192 tests
[i
].str
, tests
[i
].rej
, r
, tests
[i
].ret
);
196 #if 0 /* use this to generate more tests */
198 static void test_codepage(int cp
)
204 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
207 printf("static int result_cp_%d_mbctype[] = { ", cp
);
208 for (i
= 1; i
< 257; i
++)
210 if (p_mbctype
[i
] != prev
)
212 printf("0x%x,%d, ", prev
, count
);
219 printf("0x%x,%d };\n", prev
, count
);
224 /* RLE-encoded mbctype tables for given codepages */
225 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
226 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
227 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
229 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
231 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
232 0x0,2, 0x4,32, 0xc,94, 0,1 };
234 static void test_cp_table(int cp
, int *result
)
240 for (i
= 0; i
< 256; i
++)
248 ok(p_mbctype
[i
] == curr
, "CP%d: Mismatch in ctype for character %d - %d instead of %d\n", cp
, i
-1, p_mbctype
[i
], curr
);
253 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
257 static void test_mbcp(void)
259 int mb_orig_max
= *p__mb_cur_max
;
260 int curr_mbcp
= _getmbcp();
261 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
262 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
263 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
264 unsigned char buf
[16];
270 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
271 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
272 * CP1252 (or the ACP?) so we test only a few ASCII characters */
274 expect_eq(p_mbctype
[10], 0, char, "%x");
275 expect_eq(p_mbctype
[50], 0, char, "%x");
276 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
277 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
278 expect_eq(p_mbctype
[128], 0, char, "%x");
280 expect_eq(p_mbctype
[10], 0, char, "%x");
281 expect_eq(p_mbctype
[50], 0, char, "%x");
282 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
283 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
284 expect_eq(p_mbctype
[128], 0, char, "%x");
286 /* double byte code pages */
293 ok(*p__mb_cur_max
== mb_orig_max
, "__mb_cur_max shouldn't be updated (is %d != %d)\n", *p__mb_cur_max
, mb_orig_max
);
294 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
295 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
296 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
297 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
298 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
299 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
302 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
303 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
304 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
305 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
306 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
307 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
308 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
309 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
310 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
312 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
313 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
314 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
315 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
318 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
319 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
320 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
321 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
322 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
323 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
324 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
325 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
326 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
328 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
329 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
330 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
331 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
332 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
333 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
336 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
337 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
338 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
339 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
340 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
341 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
342 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
343 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
344 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
346 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
347 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
348 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
349 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
350 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
351 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
354 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
355 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
356 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
359 win_skip("_mbsnextc_l tests\n");
361 expect_eq(p_mbsnextc_l(mbstring
, NULL
), 0xb0b1, int, "%x");
363 /* _mbclen/_mbslen */
364 expect_eq(_mbclen(mbstring
), 2, int, "%d");
365 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
366 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
367 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
368 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
369 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
372 win_skip("_mbsnlen tests\n");
374 expect_eq(p__mbsnlen(mbstring
, 8), 8, int, "%d");
375 expect_eq(p__mbsnlen(mbstring
, 9), 4, int, "%d");
376 expect_eq(p__mbsnlen(mbstring
, 10), 4, int, "%d");
377 expect_eq(p__mbsnlen(mbsonlylead
, 0), 0, int, "%d");
378 expect_eq(p__mbsnlen(mbsonlylead
, 1), 1, int, "%d");
379 expect_eq(p__mbsnlen(mbsonlylead
, 2), 0, int, "%d");
380 expect_eq(p__mbsnlen(mbstring2
, 7), 7, int, "%d");
381 expect_eq(p__mbsnlen(mbstring2
, 8), 4, int, "%d");
382 expect_eq(p__mbsnlen(mbstring2
, 9), 4, int, "%d");
386 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
387 win_skip("mbrlen tests\n");
390 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
391 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
392 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
393 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
394 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
395 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
396 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
400 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
401 win_skip("mbrtowc tests\n");
405 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
406 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
407 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
408 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
409 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
410 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
411 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
412 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
413 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
414 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
415 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
416 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
417 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
418 ok(state
== 0, "incorrect state value (%x)\n", state
);
420 setlocale(LC_ALL
, "C");
422 /* _mbccpy/_mbsncpy */
423 memset(buf
, 0xff, sizeof(buf
));
424 _mbccpy(buf
, mbstring
);
425 expect_bin(buf
, "\xb0\xb1\xff", 3);
428 win_skip("_mbccpy_s tests\n");
432 memset(buf
, 0xff, sizeof(buf
));
434 err
= p__mbccpy_s(buf
, 0, &copied
, mbstring
);
435 ok(err
== EINVAL
, "_mbccpy_s returned %d\n", err
);
436 ok(!copied
, "copied = %d\n", copied
);
437 ok(buf
[0] == 0xff, "buf[0] = %x\n", buf
[0]);
439 memset(buf
, 0xff, sizeof(buf
));
441 err
= p__mbccpy_s(buf
, 1, &copied
, mbstring
);
442 ok(err
== ERANGE
, "_mbccpy_s returned %d\n", err
);
443 ok(!copied
, "copied = %d\n", copied
);
444 ok(!buf
[0], "buf[0] = %x\n", buf
[0]);
446 memset(buf
, 0xff, sizeof(buf
));
448 err
= p__mbccpy_s(buf
, 2, &copied
, mbstring
);
449 ok(!err
, "_mbccpy_s returned %d\n", err
);
450 ok(copied
== 2, "copied = %d\n", copied
);
451 expect_bin(buf
, "\xb0\xb1\xff", 3);
453 memset(buf
, 0xff, sizeof(buf
));
455 err
= p__mbccpy_s(buf
, 2, &copied
, (unsigned char *)"\xb0");
456 ok(err
== EILSEQ
, "_mbccpy_s returned %d\n", err
);
457 ok(copied
== 1, "copied = %d\n", copied
);
458 expect_bin(buf
, "\x00\xff", 2);
461 memset(buf
, 0xff, sizeof(buf
));
462 _mbsncpy(buf
, mbstring
, 1);
463 expect_bin(buf
, "\xb0\xb1\xff", 3);
464 memset(buf
, 0xff, sizeof(buf
));
465 _mbsncpy(buf
, mbstring
, 2);
466 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
467 memset(buf
, 0xff, sizeof(buf
));
468 _mbsncpy(buf
, mbstring
, 3);
469 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
470 memset(buf
, 0xff, sizeof(buf
));
471 _mbsncpy(buf
, mbstring
, 4);
472 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
473 memset(buf
, 0xff, sizeof(buf
));
474 _mbsncpy(buf
, mbstring
, 5);
475 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
476 memset(buf
, 0xff, sizeof(buf
));
477 _mbsncpy(buf
, mbsonlylead
, 6);
478 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
480 memset(buf
, 0xff, sizeof(buf
));
481 _mbsnbcpy(buf
, mbstring2
, 2);
482 expect_bin(buf
, "\xb0\xb1\xff", 3);
483 _mbsnbcpy(buf
, mbstring2
, 3);
484 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
485 _mbsnbcpy(buf
, mbstring2
, 4);
486 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
487 memset(buf
, 0xff, sizeof(buf
));
488 _mbsnbcpy(buf
, mbsonlylead
, 5);
489 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
492 step
= _mbsinc(mbstring
) - mbstring
;
493 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
494 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
495 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
497 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
498 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
499 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
500 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
501 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
502 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
503 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
504 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
505 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
506 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
507 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
508 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
509 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
510 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
511 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
512 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
513 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
514 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
516 /* functions that depend on locale codepage, not mbcp.
517 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
518 * (as of Wine 0.9.43)
520 GetCPInfo(GetACP(), &cp_info
);
521 if (cp_info
.MaxCharSize
== 1)
523 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
524 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
527 skip("Current locale has double-byte charset - could lead to false positives\n");
530 expect_eq(_ismbblead(0x80), 0, int, "%d");
532 expect_eq(_ismbblead(0x81), 1, int, "%d");
533 expect_eq(_ismbblead(0x83), 1, int, "%d");
535 expect_eq(_ismbblead(0x84), 1, int, "%d");
536 expect_eq(_ismbblead(0xd3), 1, int, "%d");
537 expect_eq(_ismbblead(0xd7), 0, int, "%d");
538 expect_eq(_ismbblead(0xd8), 1, int, "%d");
539 expect_eq(_ismbblead(0xd9), 1, int, "%d");
541 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
542 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
543 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
544 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
545 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
546 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
547 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
548 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
553 static void test_mbsspn( void)
555 unsigned char str1
[]="cabernet";
556 unsigned char str2
[]="shiraz";
557 unsigned char set
[]="abc";
558 unsigned char empty
[]="";
559 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
560 unsigned char mbset1
[]="0123456789 \x94\x4e";
561 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
562 unsigned char mbset3
[]="\x8e";
563 int ret
, cp
= _getmbcp();
565 ret
=_mbsspn( str1
, set
);
566 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
567 ret
=_mbsspn( str2
, set
);
568 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
569 ret
=_mbsspn( str1
, empty
);
570 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
572 ret
=_mbscspn( str1
, set
);
573 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
574 ret
=_mbscspn( str2
, set
);
575 ok( ret
==4, "_mbscspn returns %d should be 4\n", ret
);
576 ret
=_mbscspn( str1
, empty
);
577 ok( ret
==8, "_mbscspn returns %d should be 8\n", ret
);
580 ret
=_mbsspn( mbstr
, mbset1
);
581 ok( ret
==8, "_mbsspn returns %d should be 8\n", ret
);
582 ret
=_mbsspn( mbstr
, mbset2
);
583 ok( ret
==1, "_mbsspn returns %d should be 1\n", ret
);
584 ret
=_mbsspn( mbstr
+8, mbset1
);
585 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
586 ret
=_mbsspn( mbstr
+8, mbset2
);
587 ok( ret
==2, "_mbsspn returns %d should be 2\n", ret
);
588 ret
=_mbsspn( mbstr
, mbset3
);
589 ok( ret
==14, "_mbsspn returns %d should be 14\n", ret
);
591 ret
=_mbscspn( mbstr
, mbset1
);
592 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
593 ret
=_mbscspn( mbstr
, mbset2
);
594 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
595 ret
=_mbscspn( mbstr
+8, mbset1
);
596 ok( ret
==2, "_mbscspn returns %d should be 2\n", ret
);
597 ret
=_mbscspn( mbstr
+8, mbset2
);
598 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
599 ret
=_mbscspn( mbstr
, mbset3
);
600 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
605 static void test_mbsspnp( void)
607 unsigned char str1
[]="cabernet";
608 unsigned char str2
[]="shiraz";
609 unsigned char set
[]="abc";
610 unsigned char empty
[]="";
611 unsigned char full
[]="abcenrt";
612 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
613 unsigned char mbset1
[]="0123456789 \x94\x4e";
614 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
618 ret
=_mbsspnp( str1
, set
);
619 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
620 ret
=_mbsspnp( str2
, set
);
621 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
622 ret
=_mbsspnp( str1
, empty
);
623 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
624 ret
=_mbsspnp( str1
, full
);
625 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
628 ret
=_mbsspnp( mbstr
, mbset1
);
629 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
630 ret
=_mbsspnp( mbstr
, mbset2
);
631 ok( ret
==mbstr
+1, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+1);
632 ret
=_mbsspnp( mbstr
+8, mbset1
);
633 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
634 ret
=_mbsspnp( mbstr
+8, mbset2
);
635 ok( ret
==mbstr
+10, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+10);
640 static void test_strdup(void)
644 ok( str
== 0, "strdup returns %s should be 0\n", str
);
648 static void test_strcmp(void)
650 int ret
= p_strcmp( "abc", "abcd" );
651 ok( ret
== -1, "wrong ret %d\n", ret
);
652 ret
= p_strcmp( "", "abc" );
653 ok( ret
== -1, "wrong ret %d\n", ret
);
654 ret
= p_strcmp( "abc", "ab\xa0" );
655 ok( ret
== -1, "wrong ret %d\n", ret
);
656 ret
= p_strcmp( "ab\xb0", "ab\xa0" );
657 ok( ret
== 1, "wrong ret %d\n", ret
);
658 ret
= p_strcmp( "ab\xc2", "ab\xc2" );
659 ok( ret
== 0, "wrong ret %d\n", ret
);
661 ret
= p_strncmp( "abc", "abcd", 3 );
662 ok( ret
== 0, "wrong ret %d\n", ret
);
663 ret
= p_strncmp( "", "abc", 3 );
664 ok( ret
== 0 - 'a' || ret
== -1, "wrong ret %d\n", ret
);
665 ret
= p_strncmp( "abc", "ab\xa0", 4 );
666 ok( ret
== 'c' - 0xa0 || ret
== -1, "wrong ret %d\n", ret
);
667 ret
= p_strncmp( "ab\xb0", "ab\xa0", 3 );
668 ok( ret
== 0xb0 - 0xa0 || ret
== 1, "wrong ret %d\n", ret
);
669 ret
= p_strncmp( "ab\xb0", "ab\xa0", 2 );
670 ok( ret
== 0, "wrong ret %d\n", ret
);
671 ret
= p_strncmp( "ab\xc2", "ab\xc2", 3 );
672 ok( ret
== 0, "wrong ret %d\n", ret
);
673 ret
= p_strncmp( "abc", "abd", 0 );
674 ok( ret
== 0, "wrong ret %d\n", ret
);
675 ret
= p_strncmp( "abc", "abc", 12 );
676 ok( ret
== 0, "wrong ret %d\n", ret
);
679 static void test_strcpy_s(void)
682 const char small
[] = "small";
683 const char big
[] = "atoolongstringforthislittledestination";
688 win_skip("strcpy_s not found\n");
692 memset(dest
, 'X', sizeof(dest
));
693 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
694 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
695 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
696 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
697 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
698 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
700 memset(dest
, 'X', sizeof(dest
));
701 ret
= pstrcpy_s(dest
, 0, big
);
702 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
703 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
704 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
705 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
706 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
707 ret
= pstrcpy_s(dest
, 0, NULL
);
708 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
709 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
710 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
711 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
712 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
714 memset(dest
, 'X', sizeof(dest
));
715 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
716 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
717 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
718 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
719 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
720 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
722 memset(dest
, 'X', sizeof(dest
));
723 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
724 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
725 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
726 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
727 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
728 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
730 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
731 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
733 /* strcpy overlapping buffers test */
734 memset(dest
, 'X', sizeof(dest
));
735 memcpy(dest
+1, small
, sizeof(small
));
736 p_strcpy(dest
, dest
+1);
737 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
738 dest
[4] == 'l' && dest
[5] == '\0' && dest
[6] == '\0' && dest
[7] == 'X',
739 "Unexpected return data from strcpy: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
740 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
743 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
744 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
745 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
746 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
747 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
749 static void test_memcpy_s(void)
751 static char dest
[8], buf
[32];
752 static const char tiny
[] = {'T',0,'I','N','Y',0};
753 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
756 win_skip("memcpy_s not found\n");
761 memset(dest
, 'X', sizeof(dest
));
762 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
763 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
764 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
766 /* Vary source size */
768 memset(dest
, 'X', sizeof(dest
));
769 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
770 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
771 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
772 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
774 /* Replace source with NULL */
776 memset(dest
, 'X', sizeof(dest
));
777 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
778 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
779 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
780 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
784 memset(dest
, 'X', sizeof(dest
));
785 ret
= p_memcpy_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
786 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
787 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
788 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
790 /* Replace dest with NULL */
792 ret
= p_memcpy_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
793 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
794 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
798 memset(dest
, 'X', sizeof(dest
));
799 ret
= p_memcpy_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
800 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
801 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
802 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
804 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), big
, ARRAY_SIZE(big
));
805 ok(!ret
, "memcpy_s returned %d\n", ret
);
806 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
808 ret
= p_memcpy_s(buf
+ 1, ARRAY_SIZE(buf
) - 1, buf
, ARRAY_SIZE(big
));
809 ok(!ret
, "memcpy_s returned %d\n", ret
);
810 ok(!memcmp(buf
+ 1, big
, sizeof(big
)), "unexpected buf\n");
812 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), buf
+ 1, ARRAY_SIZE(big
));
813 ok(!ret
, "memcpy_s returned %d\n", ret
);
814 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
817 static void test_memmove_s(void)
820 static const char tiny
[] = {'T',0,'I','N','Y',0};
821 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
824 win_skip("memmove_s not found\n");
829 memset(dest
, 'X', sizeof(dest
));
830 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
831 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
832 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
835 memcpy(dest
, big
, sizeof(dest
));
836 ret
= p_memmove_s(dest
+1, ARRAY_SIZE(dest
)-1, dest
, ARRAY_SIZE(dest
)-1);
837 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
838 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
840 /* Vary source size */
842 memset(dest
, 'X', sizeof(dest
));
843 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
844 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
845 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
846 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
848 /* Replace source with NULL */
850 memset(dest
, 'X', sizeof(dest
));
851 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
852 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
853 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
854 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
858 memset(dest
, 'X', sizeof(dest
));
859 ret
= p_memmove_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
860 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
861 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
862 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
864 /* Replace dest with NULL */
866 ret
= p_memmove_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
867 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
868 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
872 memset(dest
, 'X', sizeof(dest
));
873 ret
= p_memmove_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
874 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
875 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
876 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
879 static void test_strcat_s(void)
882 const char *small
= "sma";
887 win_skip("strcat_s not found\n");
891 memset(dest
, 'X', sizeof(dest
));
893 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
894 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
895 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
896 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
897 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
898 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
899 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
900 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
901 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
902 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
903 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
904 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
906 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
907 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
908 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
909 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
910 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
911 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
913 memset(dest
, 'X', sizeof(dest
));
917 ret
= pstrcat_s(dest
, 0, small
);
918 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
919 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
920 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
921 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
922 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
924 ret
= pstrcat_s(dest
, 0, NULL
);
925 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
926 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
927 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
928 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
929 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
931 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
932 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
933 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
934 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
935 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
936 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
938 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
939 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
942 static void test__mbscat_s(void)
944 unsigned char dst
[8], src
[4];
946 int prev_cp
= _getmbcp();
950 win_skip("_mbscat_s not found\n");
956 err
= p_mbscat_s(NULL
, sizeof(dst
), src
);
957 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
959 err
= p_mbscat_s(dst
, sizeof(dst
), NULL
);
960 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
963 err
= p_mbscat_s(dst
, 1, src
);
964 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
966 memset(dst
, 'a', sizeof(dst
));
971 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
972 ok(err
== 0, "_mbscat_s returned %d\n", err
);
973 ok(!memcmp(dst
, "aaaaaab", 8), "dst = %s\n", dst
);
975 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
976 ok(err
== ERANGE
, "_mbscat_s returned %d\n", err
);
977 ok(!dst
[0], "dst[0] = %c\n", dst
[0]);
978 ok(dst
[1] == 'a', "dst[1] = %c\n", dst
[1]);
981 /* test invalid str in dst */
988 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
989 ok(err
== 0, "_mbscat_s returned %d\n", err
);
991 /* test invalid str in src */
997 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
998 ok(err
== 0, "_mbscat_s returned %d\n", err
);
1000 /* test dst with leading byte on the end of buffer */
1006 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
1007 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
1008 ok(!memcmp(dst
, "aR", 3), "dst = %s\n", dst
);
1010 /* test src with leading byte on the end of buffer */
1016 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
1017 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
1018 ok(!memcmp(dst
, "ab", 3), "dst = %s\n", dst
);
1022 static void test__mbsnbcpy_s(void)
1024 unsigned char dest
[8];
1025 const unsigned char big
[] = "atoolongstringforthislittledestination";
1026 const unsigned char small
[] = "small";
1031 win_skip("_mbsnbcpy_s not found\n");
1035 memset(dest
, 'X', sizeof(dest
));
1036 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
1037 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
1038 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
1039 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
1040 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1041 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1044 memset(dest
, 'X', sizeof(dest
));
1045 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
1046 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
1047 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
1048 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
1049 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1050 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1052 memset(dest
, 'X', sizeof(dest
));
1053 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
1054 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
1055 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
1056 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
1057 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1058 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1060 memset(dest
, 'X', sizeof(dest
));
1061 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
1062 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
1063 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
1064 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
1065 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1066 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1069 static void test__mbscpy_s(void)
1071 const unsigned char src
[] = "source string";
1072 unsigned char dest
[16];
1077 win_skip("_mbscpy_s not found\n");
1081 ret
= p__mbscpy_s(NULL
, 0, src
);
1082 ok(ret
== EINVAL
, "got %d\n", ret
);
1083 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
1084 ok(ret
== EINVAL
, "got %d\n", ret
);
1085 ret
= p__mbscpy_s(dest
, 0, src
);
1086 ok(ret
== EINVAL
, "got %d\n", ret
);
1088 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
1089 ok(ret
== EINVAL
, "got %d\n", ret
);
1090 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
1092 memset(dest
, 'X', sizeof(dest
));
1093 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
1094 ok(!ret
, "got %d\n", ret
);
1095 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
1096 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
1098 memset(dest
, 'X', sizeof(dest
));
1099 ret
= p__mbscpy_s(dest
, 4, src
);
1100 ok(ret
== ERANGE
, "got %d\n", ret
);
1101 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
1102 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
1105 static void test_wcscpy_s(void)
1107 static const WCHAR szLongText
[] = L
"ThisALongstring";
1108 static WCHAR szDest
[18];
1109 static WCHAR szDestShort
[8];
1114 win_skip("wcscpy_s not found\n");
1118 /* Test NULL Dest */
1120 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
1121 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
1122 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1124 /* Test NULL Source */
1127 ret
= p_wcscpy_s(szDest
, 18, NULL
);
1128 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1129 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1130 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
1132 /* Test invalid size */
1135 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
1136 /* Later versions changed the return value for this case to EINVAL,
1137 * and don't modify the result if the dest size is 0.
1139 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1140 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1141 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1143 /* Copy same buffer size */
1144 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
1145 ok(ret
== 0, "expected 0 got %d\n", ret
);
1146 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1148 /* dest == source */
1149 ret
= p_wcscpy_s(szDest
, 18, szDest
);
1150 ok(ret
== 0, "expected 0 got %d\n", ret
);
1151 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1153 /* Copy smaller buffer size */
1156 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
1157 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1158 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1159 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1163 win_skip("wcsncpy_s not found\n");
1167 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1168 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
1171 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
1172 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1173 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1176 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
1177 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
1178 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1181 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, ARRAY_SIZE(szLongText
));
1182 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1183 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1185 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1186 ok(ret
== 0, "expected 0 got %d\n", ret
);
1187 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1190 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, ARRAY_SIZE(szLongText
));
1191 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1192 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1195 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
1196 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
1197 ok(szDest
[4] == 0, "szDest[4] not 0\n");
1198 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
1200 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
1201 ok(ret
== 0, "ret = %d\n", ret
);
1203 szDestShort
[0] = '1';
1205 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
1206 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
1207 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
1208 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
1211 static void test__wcsupr_s(void)
1213 static const WCHAR mixedString
[] = L
"MiXeDlowerUPPER";
1214 static const WCHAR expectedString
[] = L
"MIXEDLOWERUPPER";
1215 WCHAR testBuffer
[2*ARRAY_SIZE(mixedString
)];
1220 win_skip("_wcsupr_s not found\n");
1224 /* Test NULL input string and invalid size. */
1226 ret
= p_wcsupr_s(NULL
, 0);
1227 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1228 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1230 /* Test NULL input string and valid size. */
1232 ret
= p_wcsupr_s(NULL
, ARRAY_SIZE(testBuffer
));
1233 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1234 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1236 /* Test empty string with zero size. */
1238 testBuffer
[0] = '\0';
1239 ret
= p_wcsupr_s(testBuffer
, 0);
1240 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1241 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1242 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1244 /* Test empty string with size of one. */
1245 testBuffer
[0] = '\0';
1246 ret
= p_wcsupr_s(testBuffer
, 1);
1247 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1248 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1250 /* Test one-byte buffer with zero size. */
1252 testBuffer
[0] = 'x';
1253 ret
= p_wcsupr_s(testBuffer
, 0);
1254 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1255 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1256 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1258 /* Test one-byte buffer with size of one. */
1260 testBuffer
[0] = 'x';
1261 ret
= p_wcsupr_s(testBuffer
, 1);
1262 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1263 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1264 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1266 /* Test invalid size. */
1267 wcscpy(testBuffer
, mixedString
);
1269 ret
= p_wcsupr_s(testBuffer
, 0);
1270 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1271 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1272 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1274 /* Test normal string uppercasing. */
1275 wcscpy(testBuffer
, mixedString
);
1276 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
));
1277 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1278 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1280 /* Test uppercasing with a shorter buffer size count. */
1281 wcscpy(testBuffer
, mixedString
);
1283 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
) - 1);
1284 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1285 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1286 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1288 /* Test uppercasing with a longer buffer size count. */
1289 wcscpy(testBuffer
, mixedString
);
1290 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(testBuffer
));
1291 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1292 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1295 static void test__wcslwr_s(void)
1297 static const WCHAR mixedString
[] = L
"MiXeDlowerUPPER";
1298 static const WCHAR expectedString
[] = L
"mixedlowerupper";
1299 WCHAR buffer
[2*ARRAY_SIZE(mixedString
)];
1304 win_skip("_wcslwr_s not found\n");
1308 /* Test NULL input string and invalid size. */
1310 ret
= p_wcslwr_s(NULL
, 0);
1311 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1312 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1314 /* Test NULL input string and valid size. */
1316 ret
= p_wcslwr_s(NULL
, ARRAY_SIZE(buffer
));
1317 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1318 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1320 /* Test empty string with zero size. */
1323 ret
= p_wcslwr_s(buffer
, 0);
1324 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1325 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1326 ok(buffer
[0] == 0, "expected empty string\n");
1328 /* Test empty string with size of one. */
1330 ret
= p_wcslwr_s(buffer
, 1);
1331 ok(ret
== 0, "got %d\n", ret
);
1332 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1334 /* Test one-byte buffer with zero size. */
1337 ret
= p_wcslwr_s(buffer
, 0);
1338 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1339 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1340 ok(buffer
[0] == '\0', "expected empty string\n");
1342 /* Test one-byte buffer with size of one. */
1345 ret
= p_wcslwr_s(buffer
, 1);
1346 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1347 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1348 ok(buffer
[0] == '\0', "expected empty string\n");
1350 /* Test invalid size. */
1351 wcscpy(buffer
, mixedString
);
1353 ret
= p_wcslwr_s(buffer
, 0);
1354 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1355 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1356 ok(buffer
[0] == '\0', "expected empty string\n");
1358 /* Test normal string uppercasing. */
1359 wcscpy(buffer
, mixedString
);
1360 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
));
1361 ok(ret
== 0, "expected 0, got %d\n", ret
);
1362 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1364 /* Test uppercasing with a shorter buffer size count. */
1365 wcscpy(buffer
, mixedString
);
1367 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
) - 1);
1368 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1369 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1370 ok(buffer
[0] == '\0', "expected empty string\n");
1372 /* Test uppercasing with a longer buffer size count. */
1373 wcscpy(buffer
, mixedString
);
1374 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(buffer
));
1375 ok(ret
== 0, "expected 0, got %d\n", ret
);
1376 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1379 static void test_mbcjisjms(void)
1381 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1382 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1383 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1384 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1385 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1386 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1388 int prev_cp
= _getmbcp();
1390 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1393 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1395 unsigned int ret
, exp
;
1396 ret
= _mbcjistojms(jisjms
[j
][0]);
1397 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1398 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1399 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1405 static void test_mbcjmsjis(void)
1407 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1408 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1409 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1410 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1411 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1412 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1413 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1414 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1416 int prev_cp
= _getmbcp();
1418 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1421 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1423 unsigned int ret
, exp
;
1424 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1425 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1426 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1427 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1433 static void test_mbctohira(void)
1435 static const unsigned int mbchira_932
[][2] = {
1436 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1437 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1438 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1439 {0x8396, 0x8396}, {0x8397, 0x8397},
1440 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1442 unsigned int prev_cp
= _getmbcp();
1444 _setmbcp(_MB_CP_SBCS
);
1445 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1447 int ret
, exp
= mbchira_932
[i
][0];
1448 ret
= _mbctohira(mbchira_932
[i
][0]);
1449 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1453 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1455 unsigned int ret
, exp
;
1456 ret
= _mbctohira(mbchira_932
[i
][0]);
1457 exp
= mbchira_932
[i
][1];
1458 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1463 static void test_mbctokata(void)
1465 static const unsigned int mbckata_932
[][2] = {
1466 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1467 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1468 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1469 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1471 unsigned int prev_cp
= _getmbcp();
1473 _setmbcp(_MB_CP_SBCS
);
1474 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1476 int ret
, exp
= mbckata_932
[i
][0];
1477 ret
= _mbctokata(mbckata_932
[i
][0]);
1478 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1482 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1484 unsigned int ret
, exp
;
1485 ret
= _mbctokata(mbckata_932
[i
][0]);
1486 exp
= mbckata_932
[i
][1];
1487 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1492 static void test_mbbtombc(void)
1494 static const unsigned int mbbmbc
[][2] = {
1495 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1496 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1497 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1498 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1499 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1501 int prev_cp
= _getmbcp();
1503 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1506 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1508 unsigned int exp
, ret
;
1509 ret
= _mbbtombc(mbbmbc
[j
][0]);
1510 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1511 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1512 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1518 static void test_mbctombb(void)
1520 static const unsigned int mbcmbb_932
[][2] = {
1521 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1522 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1523 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1524 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1525 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1526 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1527 unsigned int exp
, ret
, i
;
1528 unsigned int prev_cp
= _getmbcp();
1531 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1533 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1534 exp
= mbcmbb_932
[i
][1];
1535 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1540 static void test_ismbckata(void) {
1541 struct katakana_pair
{
1545 static const struct katakana_pair tests
[] = {
1546 {0x8152, FALSE
}, {0x8153, FALSE
}, {0x8154, FALSE
}, {0x8155, FALSE
},
1547 {0x82a0, FALSE
}, {0x833f, FALSE
}, {0x8340, TRUE
}, {0x837e, TRUE
},
1548 {0x837f, FALSE
}, {0x8380, TRUE
}, {0x8396, TRUE
}, {0x8397, FALSE
},
1549 {0xa5, FALSE
}, {0xb0, FALSE
}, {0xdd, FALSE
}
1551 unsigned int prev_cp
= _getmbcp();
1555 _setmbcp(_MB_CP_SBCS
);
1556 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1557 ret
= _ismbckata(tests
[i
].c
);
1558 ok(!ret
, "expected 0, got %d for %04x\n", ret
, tests
[i
].c
);
1562 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1563 ret
= _ismbckata(tests
[i
].c
);
1564 ok(!!ret
== tests
[i
].exp
, "expected %d, got %d for %04x\n",
1565 tests
[i
].exp
, !!ret
, tests
[i
].c
);
1571 static void test_ismbclegal(void) {
1572 unsigned int prev_cp
= _getmbcp();
1576 _setmbcp(932); /* Japanese */
1578 for(i
= 0; i
< 0x10000; i
++) {
1579 ret
= _ismbclegal(i
);
1580 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1581 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1582 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1583 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1589 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1590 _setmbcp(936); /* Chinese (GBK) */
1592 for(i
= 0; i
< 0x10000; i
++) {
1593 ret
= _ismbclegal(i
);
1594 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1595 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1601 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1602 _setmbcp(949); /* Korean */
1604 for(i
= 0; i
< 0x10000; i
++) {
1605 ret
= _ismbclegal(i
);
1606 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1607 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1613 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1614 _setmbcp(950); /* Chinese (Big5) */
1616 for(i
= 0; i
< 0x10000; i
++) {
1617 ret
= _ismbclegal(i
);
1618 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1619 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1620 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1626 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1627 _setmbcp(1361); /* Korean (Johab) */
1629 for(i
= 0; i
< 0x10000; i
++) {
1630 ret
= _ismbclegal(i
);
1631 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1632 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1633 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1634 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1641 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1646 static const struct {
1648 const char* delimiter
;
1649 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1651 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1653 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1655 } testcases_strtok
[] = {
1656 { "red cabernet", " ", 0, 4, -1 },
1657 { "sparkling white riesling", " ", 0, 10, 16 },
1658 { " pale cream sherry", "e ", 1, 6, 9 },
1663 static void test_strtok(void)
1668 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1669 strcpy( teststr
, testcases_strtok
[i
].string
);
1670 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1671 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1672 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1673 "string (%p) \'%s\' return %p\n",
1674 teststr
, testcases_strtok
[i
].string
, strret
);
1675 if( !strret
) continue;
1676 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1677 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1678 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1679 "second call string (%p) \'%s\' return %p\n",
1680 teststr
, testcases_strtok
[i
].string
, strret
);
1681 if( !strret
) continue;
1682 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1683 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1684 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1685 "third call string (%p) \'%s\' return %p\n",
1686 teststr
, testcases_strtok
[i
].string
, strret
);
1689 strcpy( teststr
, "test a=b" );
1690 strret
= strtok( teststr
, " " );
1691 ok( strret
== teststr
, "strret = %p, expected %p\n", strret
, teststr
);
1692 strret
= strtok( NULL
, "ab=" );
1693 ok( !strret
, "strret = %p, expected NULL\n", strret
);
1694 strret
= strtok( NULL
, "=" );
1695 ok( !strret
, "strret = %p, expected NULL\n", strret
);
1698 static void test_strtol(void)
1700 static char neg
[] = "-0x";
1706 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1707 /* errno is modified on W2K8+ */
1709 l
= strtol("-1234", &e
, 0);
1710 ok(l
==-1234, "wrong value %ld\n", l
);
1711 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1713 ul
= strtoul("1234", &e
, 0);
1714 ok(ul
==1234, "wrong value %lu\n", ul
);
1715 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1718 l
= strtol("2147483647L", &e
, 0);
1719 ok(l
==2147483647, "wrong value %ld\n", l
);
1720 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1722 l
= strtol("-2147483648L", &e
, 0);
1723 ok(l
==-2147483647L - 1, "wrong value %ld\n", l
);
1724 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1726 ul
= strtoul("4294967295UL", &e
, 0);
1727 ok(ul
==4294967295ul, "wrong value %lu\n", ul
);
1728 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1731 l
= strtol("9223372036854775807L", &e
, 0);
1732 ok(l
==2147483647, "wrong value %ld\n", l
);
1733 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1735 ul
= strtoul("9223372036854775807L", &e
, 0);
1736 ok(ul
==4294967295ul, "wrong value %lu\n", ul
);
1737 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1740 ul
= strtoul("-2", NULL
, 0);
1741 ok(ul
== -2, "wrong value %lu\n", ul
);
1742 ok(errno
== 0, "wrong errno %d\n", errno
);
1745 ul
= strtoul("-4294967294", NULL
, 0);
1746 ok(ul
== 2, "wrong value %lu\n", ul
);
1747 ok(errno
== 0, "wrong errno %d\n", errno
);
1750 ul
= strtoul("-4294967295", NULL
, 0);
1751 ok(ul
==1, "wrong value %lu\n", ul
);
1752 ok(errno
== 0, "wrong errno %d\n", errno
);
1755 ul
= strtoul("-4294967296", NULL
, 0);
1756 ok(ul
== 1, "wrong value %lu\n", ul
);
1757 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1760 l
= strtol(neg
, &e
, 0);
1761 ok(l
== 0, "wrong value %ld\n", l
);
1762 ok(errno
== 0, "wrong errno %d\n", errno
);
1763 ok(e
== neg
, "e = %p, neg = %p\n", e
, neg
);
1766 static void test_strnlen(void)
1768 static const char str
[] = "string";
1772 win_skip("strnlen not found\n");
1776 res
= p_strnlen(str
, 20);
1777 ok(res
== 6, "Returned length = %d\n", (int)res
);
1779 res
= p_strnlen(str
, 3);
1780 ok(res
== 3, "Returned length = %d\n", (int)res
);
1782 res
= p_strnlen(NULL
, 0);
1783 ok(res
== 0, "Returned length = %d\n", (int)res
);
1786 static void test__strtoi64(void)
1788 static const char no1
[] = "31923";
1789 static const char no2
[] = "-213312";
1790 static const char no3
[] = "12aa";
1791 static const char no4
[] = "abc12";
1792 static const char overflow
[] = "99999999999999999999";
1793 static const char neg_overflow
[] = "-99999999999999999999";
1794 static const char hex
[] = "0x123";
1795 static const char oct
[] = "000123";
1796 static const char blanks
[] = " 12 212.31";
1799 unsigned __int64 ures
;
1802 if(!p_strtoi64
|| !p_strtoui64
) {
1803 win_skip("_strtoi64 or _strtoui64 not found\n");
1808 res
= p_strtoi64(no1
, NULL
, 10);
1809 ok(res
== 31923, "res != 31923\n");
1810 res
= p_strtoi64(no2
, NULL
, 10);
1811 ok(res
== -213312, "res != -213312\n");
1812 res
= p_strtoi64(no3
, NULL
, 10);
1813 ok(res
== 12, "res != 12\n");
1814 res
= p_strtoi64(no4
, &endpos
, 10);
1815 ok(res
== 0, "res != 0\n");
1816 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1817 res
= p_strtoi64(hex
, &endpos
, 10);
1818 ok(res
== 0, "res != 0\n");
1819 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1820 res
= p_strtoi64(oct
, &endpos
, 10);
1821 ok(res
== 123, "res != 123\n");
1822 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1823 res
= p_strtoi64(blanks
, &endpos
, 10);
1824 ok(res
== 12, "res != 12\n");
1825 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1826 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1829 res
= p_strtoi64(overflow
, &endpos
, 10);
1830 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1831 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1832 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1835 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1836 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1837 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1838 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1841 res
= p_strtoi64(no1
, &endpos
, 16);
1842 ok(res
== 203043, "res != 203043\n");
1843 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1844 res
= p_strtoi64(no2
, &endpos
, 16);
1845 ok(res
== -2175762, "res != -2175762\n");
1846 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1847 res
= p_strtoi64(no3
, &endpos
, 16);
1848 ok(res
== 4778, "res != 4778\n");
1849 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1850 res
= p_strtoi64(no4
, &endpos
, 16);
1851 ok(res
== 703506, "res != 703506\n");
1852 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1853 res
= p_strtoi64(hex
, &endpos
, 16);
1854 ok(res
== 291, "res != 291\n");
1855 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1856 res
= p_strtoi64(oct
, &endpos
, 16);
1857 ok(res
== 291, "res != 291\n");
1858 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1859 res
= p_strtoi64(blanks
, &endpos
, 16);
1860 ok(res
== 18, "res != 18\n");
1861 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1862 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1865 res
= p_strtoi64(hex
, &endpos
, 36);
1866 ok(res
== 1541019, "res != 1541019\n");
1867 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1868 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1871 res
= p_strtoi64(no1
, &endpos
, 0);
1872 ok(res
== 31923, "res != 31923\n");
1873 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1874 res
= p_strtoi64(no2
, &endpos
, 0);
1875 ok(res
== -213312, "res != -213312\n");
1876 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1877 res
= p_strtoi64(no3
, &endpos
, 10);
1878 ok(res
== 12, "res != 12\n");
1879 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1880 res
= p_strtoi64(no4
, &endpos
, 10);
1881 ok(res
== 0, "res != 0\n");
1882 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1883 res
= p_strtoi64(hex
, &endpos
, 10);
1884 ok(res
== 0, "res != 0\n");
1885 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1886 res
= p_strtoi64(oct
, &endpos
, 10);
1887 ok(res
== 123, "res != 123\n");
1888 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1889 res
= p_strtoi64(blanks
, &endpos
, 10);
1890 ok(res
== 12, "res != 12\n");
1891 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1892 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1895 ures
= p_strtoui64(no1
, &endpos
, 0);
1896 ok(ures
== 31923, "ures != 31923\n");
1897 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1898 ures
= p_strtoui64(no2
, &endpos
, 0);
1899 ok(ures
== -213312, "ures != -213312\n");
1900 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1901 ures
= p_strtoui64(no3
, &endpos
, 10);
1902 ok(ures
== 12, "ures != 12\n");
1903 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1904 ures
= p_strtoui64(no4
, &endpos
, 10);
1905 ok(ures
== 0, "ures != 0\n");
1906 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1907 ures
= p_strtoui64(hex
, &endpos
, 10);
1908 ok(ures
== 0, "ures != 0\n");
1909 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1910 ures
= p_strtoui64(oct
, &endpos
, 10);
1911 ok(ures
== 123, "ures != 123\n");
1912 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1913 ures
= p_strtoui64(blanks
, &endpos
, 10);
1914 ok(ures
== 12, "ures != 12\n");
1915 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1916 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1919 ures
= p_strtoui64(overflow
, &endpos
, 10);
1920 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1921 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1922 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1925 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1926 ok(ures
== 1, "ures != 1\n");
1927 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1928 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1931 static inline BOOL
compare_double(double f
, double g
, unsigned int ulps
)
1933 ULONGLONG x
= *(ULONGLONG
*)&f
;
1934 ULONGLONG y
= *(ULONGLONG
*)&g
;
1939 x
|= ((ULONGLONG
)1)<<63;
1943 y
|= ((ULONGLONG
)1)<<63;
1945 return (x
>y
? x
-y
: y
-x
) <= ulps
;
1948 static void test__strtod(void)
1950 static const struct {
1956 { "12.1", 4, 12.1 },
1957 { "-13.721", 7, -13.721 },
1959 { ".21e12", 6, 210000000000.0 },
1960 { "214353e-3", 9, 214.353 },
1962 { "12.1d2", 6, 12.1e2
},
1965 { "-0.1", 4, -0.1 },
1966 { "0.1281832188491894198128921", 27, 0.1281832188491894198128921 },
1967 { "0.82181281288121", 16, 0.82181281288121 },
1968 { "21921922352523587651128218821", 29, 21921922352523587651128218821.0 },
1969 { "0.1d238", 7, 0.1e238
},
1970 { "0.1D-4736", 9, 0, ERANGE
},
1971 { "3.4028234663852887e38", 21, FLT_MAX
},
1972 { "1.1754943508222875e-38", 22, FLT_MIN
},
1973 { "1.7976931348623158e+308", 23, DBL_MAX
},
1974 { "1.7976931348623159e+308", 23, INFINITY
, ERANGE
},
1975 { "2.2250738585072014e-308", 23, DBL_MIN
},
1976 { "-1.7976931348623158e+308", 24, -DBL_MAX
},
1977 { "-1.7976931348623159e+308", 24, -INFINITY
, ERANGE
},
1984 const char overflow
[] = "1d9999999999999999999";
1990 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
1993 d
= strtod(tests
[i
].str
, &end
);
1994 ok(d
== tests
[i
].ret
, "%d) d = %.16e\n", i
, d
);
1995 ok(end
== tests
[i
].str
+ tests
[i
].len
, "%d) len = %d\n",
1996 i
, (int)(end
- tests
[i
].str
));
1997 ok(errno
== tests
[i
].err
|| (!tests
[i
].err
&& errno
== 0xdeadbeef) /* <= 2003 */,
1998 "%d) errno = %d\n", i
, errno
);
2002 win_skip("_strtod_l not found\n");
2006 d
= strtod(NULL
, NULL
);
2007 ok(d
== 0.0, "d = %.16e\n", d
);
2008 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2011 end
= (char *)0xdeadbeef;
2012 d
= strtod(NULL
, &end
);
2013 ok(d
== 0.0, "d = %.16e\n", d
);
2014 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2015 ok(!end
, "incorrect end ptr %p\n", end
);
2018 d
= p__strtod_l(NULL
, NULL
, NULL
);
2019 ok(d
== 0.0, "d = %.16e\n", d
);
2020 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2023 /* Set locale with non '.' decimal point (',') */
2024 if(!setlocale(LC_ALL
, "Polish")) {
2025 win_skip("system with limited locales\n");
2029 d
= strtod("12.1", NULL
);
2030 ok(d
== 12.0, "d = %.16e\n", d
);
2032 d
= strtod("12,1", NULL
);
2033 ok(d
== 12.1, "d = %.16e\n", d
);
2035 setlocale(LC_ALL
, "C");
2038 strtod(overflow
, &end
);
2039 ok(errno
== ERANGE
, "errno = %x\n", errno
);
2040 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
2043 strtod("-1d309", NULL
);
2044 ok(errno
== ERANGE
, "errno = %x\n", errno
);
2047 static void test_mbstowcs(void)
2049 static const wchar_t wSimple
[] = L
"text";
2050 static const wchar_t wHiragana
[] = L
"\x3042\x3043";
2051 static const char mSimple
[] = "text";
2052 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
2054 const wchar_t *pwstr
;
2062 wOut
[4] = '!'; wOut
[5] = '\0';
2063 mOut
[4] = '!'; mOut
[5] = '\0';
2066 /* crashes on some systems */
2068 ret
= mbstowcs(wOut
, NULL
, 4);
2069 ok(ret
== -1, "mbstowcs did not return -1\n");
2070 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2073 ret
= mbstowcs(NULL
, mSimple
, 0);
2074 ok(ret
== 4, "mbstowcs did not return 4\n");
2076 ret
= mbstowcs(wOut
, mSimple
, 4);
2077 ok(ret
== 4, "mbstowcs did not return 4\n");
2078 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2079 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
2081 ret
= mbstowcs(NULL
, "", 1);
2082 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2084 ret
= mbstowcs(wOut
, "", 1);
2085 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2086 ok(!wOut
[0], "wOut = %s\n", wine_dbgstr_w(wOut
));
2088 ret
= wcstombs(NULL
, wSimple
, 0);
2089 ok(ret
== 4, "wcstombs did not return 4\n");
2091 ret
= wcstombs(mOut
, wSimple
, 6);
2092 ok(ret
== 4, "wcstombs did not return 4\n");
2093 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2095 ret
= wcstombs(mOut
, wSimple
, 2);
2096 ok(ret
== 2, "wcstombs did not return 2\n");
2097 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2099 ret
= wcstombs(NULL
, L
"", 1);
2100 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2102 ret
= wcstombs(mOut
, L
"", 1);
2103 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2104 ok(!mOut
[0], "mOut = %s\n", mOut
);
2109 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
2110 ok(ret
== 4, "wcsrtombs did not return 4\n");
2111 ok(err
== 0, "err = %d\n", err
);
2112 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
2113 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
2116 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
2117 ok(ret
== 4, "wcsrtombs did not return 4\n");
2118 ok(pwstr
== NULL
, "pwstr != NULL\n");
2119 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2122 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
2123 win_skip("Japanese_Japan.932 locale not available\n");
2127 ret
= mbstowcs(wOut
, mHiragana
, 6);
2128 ok(ret
== 2, "mbstowcs did not return 2\n");
2129 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2131 ret
= mbstowcs(wOut
, "", 6);
2132 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2133 ok(!wOut
[0], "wOut = %s\n", wine_dbgstr_w(wOut
));
2136 ret
= mbstowcs(wOut
, mHiragana
+1, 5);
2137 ok(ret
== -1, "mbstowcs did not return -1\n");
2138 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2140 ret
= wcstombs(mOut
, wHiragana
, 6);
2141 ok(ret
== 4, "wcstombs did not return 4\n");
2142 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2144 ret
= wcstombs(mOut
, L
"", 6);
2145 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2146 ok(!mOut
[0], "mOut = %s\n", mOut
);
2148 if(!pmbstowcs_s
|| !pwcstombs_s
) {
2149 setlocale(LC_ALL
, "C");
2150 win_skip("mbstowcs_s or wcstombs_s not available\n");
2154 err
= pmbstowcs_s(&ret
, wOut
, 1, mSimple
, _TRUNCATE
);
2155 ok(err
== STRUNCATE
, "err = %d\n", err
);
2156 ok(ret
== 1, "mbstowcs_s did not return 0\n");
2157 ok(!wOut
[0], "wOut[0] = %d\n", wOut
[0]);
2159 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
2160 ok(err
== 0, "err = %d\n", err
);
2161 ok(ret
== 5, "mbstowcs_s did not return 5\n");
2162 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2164 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
2165 ok(err
== 0, "err = %d\n", err
);
2166 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2167 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2169 err
= pmbstowcs_s(&ret
, wOut
, 6, "", _TRUNCATE
);
2170 ok(err
== 0, "err = %d\n", err
);
2171 ok(ret
== 1, "mbstowcs_s did not return 1, got %d\n", (int)ret
);
2172 ok(!wOut
[0], "wOut = %s\n", wine_dbgstr_w(wOut
));
2174 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
2175 ok(err
== 0, "err = %d\n", err
);
2176 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2178 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
2179 ok(err
== 0, "err = %d\n", err
);
2180 ok(ret
== 5, "wcstombs_s did not return 5\n");
2181 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2183 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
2184 ok(err
== 0, "err = %d\n", err
);
2185 ok(ret
== 5, "wcstombs_s did not return 5\n");
2186 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2188 err
= pwcstombs_s(&ret
, mOut
, 6, L
"", _TRUNCATE
);
2189 ok(err
== 0, "err = %d\n", err
);
2190 ok(ret
== 1, "wcstombs_s did not return 1, got %d\n", (int)ret
);
2191 ok(!mOut
[0], "mOut = %s\n", mOut
);
2193 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
2194 ok(err
== 0, "err = %d\n", err
);
2195 ok(ret
== 5, "wcstombs_s did not return 5\n");
2198 setlocale(LC_ALL
, "C");
2199 win_skip("wcsrtombs not available\n");
2205 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
2206 ok(ret
== 4, "wcsrtombs did not return 4\n");
2207 ok(err
== 0, "err = %d\n", err
);
2208 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
2209 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
2212 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
2213 ok(ret
== 4, "wcsrtombs did not return 4\n");
2214 ok(pwstr
== NULL
, "pwstr != NULL\n");
2215 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2218 setlocale(LC_ALL
, "C");
2219 win_skip("mbsrtowcs not available\n");
2224 ret
= p_mbsrtowcs(NULL
, &pmbstr
, 6, NULL
);
2225 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2226 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2229 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
2230 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2231 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2232 ok(!pmbstr
, "pmbstr != NULL\n");
2234 state
= mHiragana
[0];
2235 pmbstr
= mHiragana
+1;
2236 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
2237 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2238 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
2239 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
2240 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
2241 ok(!pmbstr
, "pmbstr != NULL\n");
2244 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
2245 ok(ret
== -1, "mbsrtowcs did not return -1\n");
2246 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2248 if(!p_mbsrtowcs_s
) {
2249 setlocale(LC_ALL
, "C");
2250 win_skip("mbsrtowcs_s not available\n");
2255 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, NULL
, 6, NULL
);
2256 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2257 ok(err
== EINVAL
, "err = %d\n", err
);
2258 err
= p_mbsrtowcs_s(&ret
, NULL
, 1, &pmbstr
, 6, NULL
);
2259 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2260 ok(err
== EINVAL
, "err = %d\n", err
);
2261 err
= p_mbsrtowcs_s(&ret
, wOut
, 0, &pmbstr
, 6, NULL
);
2262 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2263 ok(err
== EINVAL
, "err = %d\n", err
);
2267 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, &pmbstr
, 6, NULL
);
2268 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2269 ok(err
== 0, "err = %d\n", err
);
2270 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2271 ok(errno
== 0, "errno = %d\n", errno
);
2274 err
= p_mbsrtowcs_s(&ret
, wOut
, 1, &pmbstr
, 6, NULL
);
2275 ok(ret
== 2, "mbsrtowcs_s did not return 2\n");
2276 ok(err
== 0, "err = %d\n", err
);
2277 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2278 ok(pmbstr
== mHiragana
+2, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+2);
2279 ok(errno
== 0, "errno = %d\n", errno
);
2282 err
= p_mbsrtowcs_s(&ret
, wOut
, 2, &pmbstr
, 6, NULL
);
2283 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2284 ok(err
== 0, "err = %d\n", err
);
2285 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2286 ok(pmbstr
== mHiragana
+4, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+4);
2287 ok(errno
== 0, "errno = %d\n", errno
);
2290 err
= p_mbsrtowcs_s(&ret
, wOut
, 3, &pmbstr
, 6, NULL
);
2291 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2292 ok(err
== 0, "err = %d\n", err
);
2293 ok(!pmbstr
, "pmbstr != NULL\n");
2294 ok(errno
== 0, "errno = %d\n", errno
);
2296 setlocale(LC_ALL
, "C");
2299 static void test__wcstombs_s_l(void)
2302 const wchar_t *wstr
;
2310 /* wstr str ret err locale */
2311 { L
"", 0, NULL
, 0, 1, 0, NULL
},
2312 { L
"\xfffd", 1, NULL
, 0, 2, 0, NULL
},
2313 { L
"\xfffd", 1, "", 1, 0, EILSEQ
, NULL
},
2314 { L
"\xfffd", 1, "", 6, 0, EILSEQ
, NULL
},
2315 { L
"text", _TRUNCATE
, "text", 5, 5, 0, NULL
},
2316 { L
"text", _TRUNCATE
, "", 1, 1, STRUNCATE
, NULL
},
2317 { L
"text", 5, "", 3, 0, ERANGE
, NULL
},
2319 { L
"", 0, NULL
, 0, 1, 0, "English_United States.1252" },
2320 { L
"\xfffd", 1, NULL
, 0, 0, EILSEQ
, "English_United States.1252" },
2321 { L
"\xfffd", 1, "", 1, 0, EILSEQ
, "English_United States.1252" },
2322 { L
"\xfffd", 1, "", 6, 0, EILSEQ
, "English_United States.1252" },
2323 { L
"text", _TRUNCATE
, "text", 5, 5, 0, "English_United States.1252" },
2324 { L
"text", _TRUNCATE
, "", 1, 1, STRUNCATE
, "English_United States.1252" },
2325 { L
"text", 5, "", 3, 0, ERANGE
, "English_United States.1252" },
2333 if(!p__create_locale
) {
2334 win_skip("_create_locale not available\n");
2338 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
2342 locale
= p__create_locale(LC_ALL
, tests
[i
].locale
);
2343 ok(locale
!= NULL
, "_create_locale failed for %s\n", tests
[i
].locale
);
2349 memset(out
, 0xcc, sizeof(out
));
2350 err
= p_wcstombs_s_l(&ret
, tests
[i
].str
? out
: NULL
, tests
[i
].len
,
2351 tests
[i
].wstr
, tests
[i
].wlen
, locale
);
2352 ok(ret
== tests
[i
].ret
, "%d: expected ret %Id, got %Id for '%s' in locale %s\n", i
, tests
[i
].ret
, ret
,
2353 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2354 ok(err
== tests
[i
].err
, "%d: expected err %d, got %d for '%s' in locale %s\n", i
, tests
[i
].err
, err
,
2355 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2357 ok(!memcmp(out
, tests
[i
].str
, strlen(tests
[i
].str
)+1),
2358 "%d: expected out %s, got %s for '%s' in locale %s\n", i
, tests
[i
].str
, out
,
2359 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2361 p__free_locale(locale
);
2365 static void test_gcvt(void)
2367 char buf
[1024], *res
;
2371 win_skip("Skipping _gcvt tests\n");
2376 res
= _gcvt(1.2, -1, buf
);
2377 ok(res
== NULL
, "res != NULL\n");
2378 ok(errno
== ERANGE
, "errno = %d\n", errno
);
2381 res
= _gcvt(1.2, 5, NULL
);
2382 ok(res
== NULL
, "res != NULL\n");
2383 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2385 res
= gcvt(1.2, 5, buf
);
2386 ok(res
== buf
, "res != buf\n");
2387 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
2390 err
= p_gcvt_s(buf
, 5, 1.2, 10);
2391 ok(err
== ERANGE
, "err = %d\n", err
);
2392 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2395 err
= p_gcvt_s(buf
, 4, 123456, 2);
2396 ok(err
== ERANGE
, "err = %d\n", err
);
2397 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2400 static void test__itoa_s(void)
2407 win_skip("Skipping _itoa_s tests\n");
2412 ret
= p_itoa_s(0, NULL
, 0, 0);
2413 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2414 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2416 memset(buffer
, 'X', sizeof(buffer
));
2418 ret
= p_itoa_s(0, buffer
, 0, 0);
2419 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2420 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2421 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2423 memset(buffer
, 'X', sizeof(buffer
));
2425 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
2426 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2427 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2428 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2430 memset(buffer
, 'X', sizeof(buffer
));
2432 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
2433 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2434 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2435 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2437 memset(buffer
, 'X', sizeof(buffer
));
2439 ret
= p_itoa_s(12345678, buffer
, 4, 10);
2440 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2441 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2442 ok(!memcmp(buffer
, "\000765", 4),
2443 "Expected the output buffer to be null terminated with truncated output\n");
2445 memset(buffer
, 'X', sizeof(buffer
));
2447 ret
= p_itoa_s(12345678, buffer
, 8, 10);
2448 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2449 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2450 ok(!memcmp(buffer
, "\0007654321", 8),
2451 "Expected the output buffer to be null terminated with truncated output\n");
2453 memset(buffer
, 'X', sizeof(buffer
));
2455 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
2456 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2457 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2458 ok(!memcmp(buffer
, "\00087654321", 9),
2459 "Expected the output buffer to be null terminated with truncated output\n");
2461 ret
= p_itoa_s(12345678, buffer
, 9, 10);
2462 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2463 ok(!strcmp(buffer
, "12345678"),
2464 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2467 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
2468 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2469 ok(!strcmp(buffer
, "1010101010101010"),
2470 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2473 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
2474 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2475 ok(!strcmp(buffer
, "nell"),
2476 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2479 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
2480 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2481 ok(!strcmp(buffer
, "hag"),
2482 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2485 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
2486 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2487 ok(!strcmp(buffer
, "-12345678"),
2488 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2491 itoa(100, buffer
, 100);
2492 ok(!strcmp(buffer
, "10"),
2493 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
2496 static void test__strlwr_s(void)
2503 win_skip("Skipping _strlwr_s tests\n");
2508 ret
= p_strlwr_s(NULL
, 0);
2509 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2510 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2513 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
2514 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2515 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2518 ret
= p_strlwr_s(buffer
, 0);
2519 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2520 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2522 strcpy(buffer
, "GoRrIsTeR");
2524 ret
= p_strlwr_s(buffer
, 5);
2525 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2526 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2527 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2528 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2530 strcpy(buffer
, "GoRrIsTeR");
2532 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
2533 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2534 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2535 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2536 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2538 strcpy(buffer
, "GoRrIsTeR");
2539 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
2540 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2541 ok(!strcmp(buffer
, "gorrister"),
2542 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2545 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2546 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
2547 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2548 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2549 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2552 ret
= p_strlwr_s((char *)"already_lowercase", sizeof("already_lowercase"));
2553 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2556 static void test_wcsncat_s(void)
2564 win_skip("skipping wcsncat_s tests\n");
2568 wcscpy(src
, L
"abc");
2570 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
2571 ok(ret
== EINVAL
, "err = %d\n", ret
);
2572 ret
= p_wcsncat_s(dst
, 0, src
, 4);
2573 ok(ret
== EINVAL
, "err = %d\n", ret
);
2574 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
2575 ok(ret
== EINVAL
, "err = %d\n", ret
);
2576 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
2577 ok(ret
== 0, "err = %d\n", ret
);
2580 ret
= p_wcsncat_s(dst
, 2, src
, 4);
2581 ok(ret
== ERANGE
, "err = %d\n", ret
);
2584 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
2585 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
2586 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2588 wcscpy(dst
, L
"abc");
2590 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2591 ok(ret
== EINVAL
, "err = %d\n", ret
);
2594 static void test__mbsnbcat_s(void)
2596 unsigned char dest
[16];
2597 const unsigned char first
[] = "dinosaur";
2598 const unsigned char second
[] = "duck";
2603 win_skip("Skipping _mbsnbcat_s tests\n");
2607 /* Test invalid arguments. */
2608 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2609 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2612 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2613 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2614 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2617 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2618 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2619 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2621 memset(dest
, 'X', sizeof(dest
));
2623 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2624 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2625 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2626 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2628 memset(dest
, 'X', sizeof(dest
));
2630 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2631 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2632 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2633 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2635 memset(dest
, 'X', sizeof(dest
));
2637 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2638 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2639 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2640 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2642 memset(dest
, 'X', sizeof(dest
));
2644 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2645 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2646 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2647 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2649 memset(dest
, 'X', sizeof(dest
));
2651 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2652 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2653 ok(!memcmp(dest
, second
, sizeof(second
)),
2654 "Expected the output buffer string to be \"duck\"\n");
2656 /* Test source truncation behavior. */
2657 memset(dest
, 'X', sizeof(dest
));
2658 memcpy(dest
, first
, sizeof(first
));
2659 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2660 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2661 ok(!memcmp(dest
, first
, sizeof(first
)),
2662 "Expected the output buffer string to be \"dinosaur\"\n");
2664 memset(dest
, 'X', sizeof(dest
));
2665 memcpy(dest
, first
, sizeof(first
));
2666 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2667 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2668 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2669 "Expected the output buffer string to be \"dinosaurduck\"\n");
2671 memset(dest
, 'X', sizeof(dest
));
2672 memcpy(dest
, first
, sizeof(first
));
2673 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2674 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2675 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2676 "Expected the output buffer string to be \"dinosaurduck\"\n");
2678 memset(dest
, 'X', sizeof(dest
));
2679 memcpy(dest
, first
, sizeof(first
));
2680 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2681 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2682 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2683 "Expected the output buffer string to be \"dinosaurduck\"\n");
2685 memset(dest
, 'X', sizeof(dest
));
2686 memcpy(dest
, first
, sizeof(first
));
2687 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2688 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2689 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2690 "Expected the output buffer string to be \"dinosaurduc\"\n");
2692 /* Test destination truncation behavior. */
2693 memset(dest
, 'X', sizeof(dest
));
2694 memcpy(dest
, first
, sizeof(first
));
2696 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2697 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2698 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2699 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2700 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2702 memset(dest
, 'X', sizeof(dest
));
2703 memcpy(dest
, first
, sizeof(first
));
2705 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2706 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2707 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2708 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2709 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2711 memset(dest
, 'X', sizeof(dest
));
2712 memcpy(dest
, first
, sizeof(first
));
2714 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2715 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2716 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2717 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2718 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2721 static void test__mbsupr_s(void)
2724 unsigned char buffer
[20];
2728 win_skip("Skipping _mbsupr_s tests\n");
2733 ret
= p_mbsupr_s(NULL
, 0);
2734 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2737 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2738 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2739 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2742 ret
= p_mbsupr_s(buffer
, 0);
2743 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2744 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2746 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2748 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2749 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2750 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2751 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2754 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2756 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2757 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2758 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2759 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2762 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2764 ret
= p_mbsupr_s(buffer
, 4);
2765 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2766 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2768 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2770 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2771 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2772 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2773 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2778 static void test__mbslwr_s(void)
2781 unsigned char buffer
[20];
2785 win_skip("Skipping _mbslwr_s tests\n");
2790 ret
= p_mbslwr_s(NULL
, 0);
2791 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2794 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2795 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2796 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2799 ret
= p_mbslwr_s(buffer
, 0);
2800 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2801 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2803 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2805 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2806 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2807 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2808 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2811 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2813 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2814 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2815 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2816 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2819 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2821 ret
= p_mbslwr_s(buffer
, 4);
2822 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2823 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2825 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2827 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2828 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2829 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2830 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2834 static void test__mbstok(void)
2836 const unsigned char delim
[] = "t";
2838 char str
[] = "!.!test";
2843 ret
= _mbstok(NULL
, delim
);
2844 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2845 ok(!ret
|| broken((char*)ret
==str
+4),
2846 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2848 ret
= _mbstok(NULL
, delim
);
2849 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2852 static void test__ultoa_s(void)
2859 win_skip("Skipping _ultoa_s tests\n");
2864 ret
= p_ultoa_s(0, NULL
, 0, 0);
2865 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2866 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2868 memset(buffer
, 'X', sizeof(buffer
));
2870 ret
= p_ultoa_s(0, buffer
, 0, 0);
2871 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2872 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2873 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2875 memset(buffer
, 'X', sizeof(buffer
));
2877 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2878 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2879 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2880 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2882 memset(buffer
, 'X', sizeof(buffer
));
2884 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2885 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2886 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2887 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2889 memset(buffer
, 'X', sizeof(buffer
));
2891 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2892 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2893 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2894 ok(!memcmp(buffer
, "\000765", 4),
2895 "Expected the output buffer to be null terminated with truncated output\n");
2897 memset(buffer
, 'X', sizeof(buffer
));
2899 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2900 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2901 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2902 ok(!memcmp(buffer
, "\0007654321", 8),
2903 "Expected the output buffer to be null terminated with truncated output\n");
2905 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2906 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2907 ok(!strcmp(buffer
, "12345678"),
2908 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2911 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2912 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2913 ok(!strcmp(buffer
, "1010101010101010"),
2914 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2917 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2918 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2919 ok(!strcmp(buffer
, "nell"),
2920 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2923 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2924 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2925 ok(!strcmp(buffer
, "hag"),
2926 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2930 static void test_wctob(void)
2932 int ret
, cp
= _getmbcp();
2934 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2935 win_skip("Skipping wctob tests\n");
2939 ret
= p_wctob(0x8141);
2940 ok(ret
== EOF
, "ret = %x\n", ret
);
2942 ret
= p_wctob(0x81);
2943 ok(ret
== EOF
, "ret = %x\n", ret
);
2945 ret
= p_wctob(0xe0);
2946 ok(ret
== 0x61, "ret = %x\n", ret
);
2949 ret
= p_wctob(0x81);
2950 ok(ret
== EOF
, "ret = %x\n", ret
);
2952 setlocale(LC_ALL
, "C");
2953 ret
= p_wctob(0x8141);
2954 ok(ret
== EOF
, "ret = %x\n", ret
);
2956 ret
= p_wctob(0x81);
2957 ok(ret
== (signed char)0x81, "ret = %x\n", ret
);
2959 ret
= p_wctob(0x9f);
2960 ok(ret
== (signed char)0x9f, "ret = %x\n", ret
);
2962 ret
= p_wctob(0xe0);
2963 ok(ret
== (signed char)0xe0, "ret = %x\n", ret
);
2968 static void test_btowc(void)
2971 int cp
= _getmbcp();
2973 if(!p_btowc
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2974 win_skip("Skipping btowc tests\n");
2979 ok(ret
== WEOF
, "ret = %x\n", ret
);
2981 ret
= p_btowc(0x61);
2982 ok(ret
== 0x61, "ret = %x\n", ret
);
2984 ret
= p_btowc(0x81);
2985 ok(ret
== WEOF
, "ret = %x\n", ret
);
2987 ret
= p_btowc(0xe0);
2988 ok(ret
== WEOF
, "ret = %x\n", ret
);
2991 ret
= p_btowc(0x61);
2992 ok(ret
== 0x61, "ret = %x\n", ret
);
2994 ret
= p_btowc(0x81);
2995 ok(ret
== WEOF
, "ret = %x\n", ret
);
2997 ret
= p_btowc(0xe0);
2998 ok(ret
== WEOF
, "ret = %x\n", ret
);
3000 if(!setlocale(LC_CTYPE
, ".1250")) {
3001 win_skip("No codepage 1250 support\n");
3002 setlocale(LC_ALL
, "C");
3007 ret
= p_btowc(0x61);
3008 ok(ret
== 0x61, "ret = %x\n", ret
);
3010 ret
= p_btowc(0x81);
3011 ok(ret
== 0x81, "ret = %x\n", ret
);
3013 ret
= p_btowc(0xe0);
3014 ok(ret
== 0x155, "ret = %x\n", ret
);
3016 ret
= p_btowc(0x100);
3017 ok(ret
== 0x00, "ret = %x\n", ret
);
3019 ret
= p_btowc(0x1e0);
3020 ok(ret
== 0x155, "ret = %x\n", ret
);
3022 setlocale(LC_ALL
, "C");
3023 ret
= p_btowc(0x61);
3024 ok(ret
== 0x61, "ret = %x\n", ret
);
3026 ret
= p_btowc(0x81);
3027 ok(ret
== 0x81, "ret = %x\n", ret
);
3029 ret
= p_btowc(0x9f);
3030 ok(ret
== 0x9f, "ret = %x\n", ret
);
3032 ret
= p_btowc(0xe0);
3033 ok(ret
== 0xe0, "ret = %x\n", ret
);
3035 ret
= p_btowc(0x100);
3036 ok(ret
== 0x00, "ret = %x\n", ret
);
3038 ret
= p_btowc(0x1e0);
3039 ok(ret
== 0xe0, "ret = %x\n", ret
);
3044 static void test_wctomb(void)
3047 unsigned char dst
[10];
3051 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
3052 win_skip("wcrtomb tests\n");
3056 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
3057 ok(ret
== 2, "wcrtomb did not return 2\n");
3061 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
3062 ok(ret
== 2, "wcrtomb did not return 2\n");
3063 ok(state
== 0, "state != 0\n");
3064 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3065 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3066 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
3068 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
3069 ok(ret
== 2, "wcrtomb did not return 2\n");
3070 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3071 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
3073 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
3074 ok(ret
== 1, "wcrtomb did not return 1\n");
3075 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
3077 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
3078 ok(ret
== -1, "wcrtomb did not return -1\n");
3079 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
3082 win_skip("wcrtomb_s tests\n");
3083 setlocale(LC_ALL
, "C");
3089 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x3042, &state
);
3090 ok(!err
, "err = %d\n", err
);
3091 ok(ret
== 2, "ret != 2\n");
3092 ok(!state
, "state != 0\n");
3093 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3094 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3095 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
3097 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x3042, NULL
);
3098 ok(!err
, "err = %d\n", err
);
3099 ok(ret
== 2, "ret != 2\n");
3100 ok(!state
, "state != 0\n");
3101 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3102 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3104 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x20, NULL
);
3105 ok(!err
, "err = %d\n", err
);
3106 ok(ret
== 1, "ret != 1\n");
3107 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
3109 err
= p_wcrtomb_s(&ret
, NULL
, 0, 0x20, NULL
);
3110 ok(!err
, "err = %d\n", err
);
3111 ok(ret
== 1, "ret != 1\n");
3113 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0xffff, NULL
);
3114 ok(err
== EILSEQ
, "err = %d\n", err
);
3115 ok(ret
== -1, "wcrtomb did not return -1\n");
3116 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
3118 setlocale(LC_ALL
, "C");
3121 static void test_tolower(void)
3127 /* test C locale when locale was never changed */
3128 ret
= p_tolower(0x41);
3129 ok(ret
== 0x61, "ret = %x\n", ret
);
3131 ret
= p_tolower(0xF4);
3132 ok(ret
== 0xF4, "ret = %x\n", ret
);
3135 ret
= p_tolower((char)0xF4);
3136 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
3137 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3140 ret
= p_tolower((char)0xD0);
3141 ok(ret
== (char)0xD0, "ret = %x\n", ret
);
3142 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3144 setlocale(LC_ALL
, "C");
3146 ret
= p_tolower((char)0xF4);
3147 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
3148 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3150 /* test C locale after setting locale */
3151 if(!setlocale(LC_ALL
, "us")) {
3152 win_skip("skipping tolower tests that depends on locale\n");
3155 setlocale(LC_ALL
, "C");
3159 ret
= p_tolower((signed char)ch
);
3160 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
3161 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
3162 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
3165 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
3167 ok(ret
== ch
, "ret = %x\n", ret
);
3168 if(!len
|| ret
==(unsigned char)lch
)
3169 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
3173 ret
= p_tolower((signed char)ch
);
3174 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
3175 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
3176 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
3179 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
3181 ok(ret
== ch
, "ret = %x\n", ret
);
3182 if(!len
|| ret
==(unsigned char)lch
)
3183 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
3185 ret
= p_tolower((unsigned char)0xD0);
3186 ok(ret
== 0xD0, "ret = %x\n", ret
);
3188 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
3190 ret
= p_tolower((signed char)0xD0);
3191 ok(ret
== 0xF0, "ret = %x\n", ret
);
3193 ret
= p_tolower((unsigned char)0xD0);
3194 ok(ret
== 0xF0, "ret = %x\n", ret
);
3196 setlocale(LC_ALL
, "C");
3199 static double mul_pow10(double x
, double exp
)
3201 int fpexcept
= _EM_DENORMAL
|_EM_INVALID
|_EM_ZERODIVIDE
|_EM_OVERFLOW
|_EM_UNDERFLOW
|_EM_INEXACT
;
3202 BOOL negexp
= (exp
< 0);
3208 fpcontrol
= _control87(0, 0);
3209 _control87(fpexcept
, 0xffffffff);
3210 ret
= pow(10.0, exp
);
3211 ret
= (negexp
? x
/ret
: x
*ret
);
3212 _control87(fpcontrol
, 0xffffffff);
3216 static void test__atodbl(void)
3223 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
3224 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
3225 win_skip("_atodbl_l is not available\n");
3230 ret
= p__atodbl_l(&d
, num
, NULL
);
3231 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
3232 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3233 ret
= _atodbl(&d
, num
);
3234 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
3235 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3238 ret
= p__atodbl_l(&d
, num
, NULL
);
3239 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
3240 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3241 ret
= _atodbl(&d
, num
);
3242 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
3243 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3246 ret
= p__atodbl_l(&d
, num
, NULL
);
3247 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
3248 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3249 ret
= _atodbl(&d
, num
);
3250 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
3251 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3254 ret
= p__atodbl_l(&d
, num
, NULL
);
3255 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
3256 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
3257 ret
= _atodbl(&d
, num
);
3258 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
3259 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
3261 /* check over the whole range of (simple) normal doubles */
3262 for (j
= DBL_MIN_10_EXP
; j
<= DBL_MAX_10_EXP
; j
++) {
3263 for (i
= 1; i
<= 9; i
++) {
3264 double expected
= mul_pow10(i
, j
);
3265 if (expected
< DBL_MIN
|| expected
> DBL_MAX
) continue;
3266 snprintf(num
, sizeof(num
), "%de%d", i
, j
);
3267 ret
= _atodbl(&d
, num
);
3268 ok(compare_double(d
.x
, expected
, 2), "d.x = %.16e, expected %.16e\n", d
.x
, expected
);
3272 /* check with denormal doubles */
3273 strcpy(num
, "1e-309");
3274 ret
= p__atodbl_l(&d
, num
, NULL
);
3275 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
3276 ok(compare_double(d
.x
, 1e-309, 1), "d.x = %.16e, expected 0\n", d
.x
);
3277 ret
= _atodbl(&d
, num
);
3278 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
3279 ok(compare_double(d
.x
, 1e-309, 1), "d.x = %.16e, expected 0\n", d
.x
);
3281 strcpy(num
, "1e309");
3282 ret
= p__atodbl_l(&d
, num
, NULL
);
3283 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
3284 ret
= _atodbl(&d
, num
);
3285 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
3288 static void test__stricmp(void)
3292 ret
= _stricmp("test", "test");
3293 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3294 ret
= _stricmp("a", "z");
3295 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3296 ret
= _stricmp("z", "a");
3297 ok(ret
> 0, "_stricmp returned %d\n", ret
);
3298 ret
= _stricmp("\xa5", "\xb9");
3299 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3301 if(!setlocale(LC_ALL
, "polish")) {
3302 win_skip("stricmp tests\n");
3306 ret
= _stricmp("test", "test");
3307 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3308 ret
= _stricmp("a", "z");
3309 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3310 ret
= _stricmp("z", "a");
3311 ok(ret
> 0, "_stricmp returned %d\n", ret
);
3312 ret
= _stricmp("\xa5", "\xb9");
3313 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3314 ret
= _stricmp("a", "\xb9");
3315 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3317 setlocale(LC_ALL
, "C");
3320 static void test__wcstoi64(void)
3322 static const struct { WCHAR str
[24]; __int64 res
; unsigned __int64 ures
; int base
; } tests
[] =
3326 { L
"-1234", -1234, -1234 },
3327 { L
"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
3328 { L
"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
3329 { { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
3330 { { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
3331 { { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
3332 { { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
3333 { { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
3334 { { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
3335 { { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
3336 { { '+',0x0e50,0xff17,'1' }, 071, 071 },
3337 { { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
3338 { L
"4294967295", 4294967295, 4294967295 },
3339 { L
"4294967296", 4294967296, 4294967296 },
3340 { L
"9223372036854775807", 9223372036854775807, 9223372036854775807 },
3341 { L
"9223372036854775808", _I64_MAX
, 9223372036854775808u },
3342 { L
"18446744073709551615", _I64_MAX
, _UI64_MAX
},
3343 { L
"18446744073709551616", _I64_MAX
, _UI64_MAX
},
3344 { L
"-4294967295", -4294967295, -4294967295 },
3345 { L
"-4294967296", -4294967296, -4294967296 },
3346 { L
"-9223372036854775807", -9223372036854775807, -9223372036854775807 },
3347 { L
"-9223372036854775808", _I64_MIN
, 9223372036854775808u },
3348 { L
"-18446744073709551615", _I64_MIN
, 1 },
3349 { L
"-18446744073709551616", _I64_MIN
, 1 },
3351 static const WCHAR zeros
[] = {
3352 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3353 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3358 unsigned __int64 ures
;
3361 if (!p_wcstoi64
|| !p_wcstoui64
) {
3362 win_skip("_wcstoi64 or _wcstoui64 not found\n");
3366 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3368 res
= p_wcstoi64( tests
[i
].str
, &endpos
, tests
[i
].base
);
3369 ok( res
== tests
[i
].res
, "%u: %s res %s\n",
3370 i
, wine_dbgstr_w(tests
[i
].str
), wine_dbgstr_longlong(res
) );
3371 if (!res
) ok( endpos
== tests
[i
].str
, "%u: wrong endpos %p/%p\n", i
, endpos
, tests
[i
].str
);
3372 ures
= p_wcstoui64( tests
[i
].str
, &endpos
, tests
[i
].base
);
3373 ok( ures
== tests
[i
].ures
, "%u: %s res %s\n",
3374 i
, wine_dbgstr_w(tests
[i
].str
), wine_dbgstr_longlong(ures
) );
3377 /* Test various unicode digits */
3378 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3379 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3380 res
= p_wcstoi64(tmp
, NULL
, 0);
3381 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3382 tmp
[1] = zeros
[i
] + 10;
3383 res
= p_wcstoi64(tmp
, NULL
, 16);
3384 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3388 static void test__wcstol(void)
3390 static const struct { WCHAR str
[24]; long res
; unsigned long ures
; int base
; } tests
[] =
3394 { L
"-1234", -1234, -1234 },
3395 { L
"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
3396 { L
"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
3397 { { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
3398 { { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
3399 { { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
3400 { { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
3401 { { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
3402 { { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
3403 { { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
3404 { { '+',0x0e50,0xff17,'1' }, 071, 071 },
3405 { { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
3406 { L
"2147483647", 2147483647, 2147483647 },
3407 { L
"2147483648", LONG_MAX
, 2147483648 },
3408 { L
"4294967295", LONG_MAX
, 4294967295 },
3409 { L
"4294967296", LONG_MAX
, ULONG_MAX
},
3410 { L
"9223372036854775807", LONG_MAX
, ULONG_MAX
},
3411 { L
"-2147483647", -2147483647, -2147483647 },
3412 { L
"-2147483648", LONG_MIN
, LONG_MIN
},
3413 { L
"-4294967295", LONG_MIN
, 1 },
3414 { L
"-4294967296", LONG_MIN
, 1 },
3415 { L
"-9223372036854775807", LONG_MIN
, 1 },
3417 static const WCHAR zeros
[] = {
3418 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3419 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3427 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3429 res
= wcstol( tests
[i
].str
, &endpos
, tests
[i
].base
);
3430 ok( res
== tests
[i
].res
, "%u: %s res %08lx\n",
3431 i
, wine_dbgstr_w(tests
[i
].str
), res
);
3432 if (!res
) ok( endpos
== tests
[i
].str
, "%u: wrong endpos %p/%p\n", i
, endpos
, tests
[i
].str
);
3433 ures
= wcstoul( tests
[i
].str
, &endpos
, tests
[i
].base
);
3434 ok( ures
== tests
[i
].ures
, "%u: %s res %08lx\n",
3435 i
, wine_dbgstr_w(tests
[i
].str
), ures
);
3438 /* Test various unicode digits */
3439 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3440 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3441 res
= wcstol(tmp
, NULL
, 0);
3442 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3443 tmp
[1] = zeros
[i
] + 10;
3444 res
= wcstol(tmp
, NULL
, 16);
3445 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3449 static void test_atoi(void)
3454 ok(r
== 0, "atoi(0) = %d\n", r
);
3457 ok(r
== -1, "atoi(-1) = %d\n", r
);
3460 ok(r
== 1, "atoi(1) = %d\n", r
);
3462 r
= atoi("4294967296");
3463 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
3466 static void test_atol(void)
3471 ok(r
== 0, "atol(0) = %d\n", r
);
3474 ok(r
== -1, "atol(-1) = %d\n", r
);
3477 ok(r
== 1, "atol(1) = %d\n", r
);
3479 r
= atol("4294967296");
3480 ok(r
== 0, "atol(4294967296) = %d\n", r
);
3483 static void test_atof(void)
3488 ok(d
== 0.0, "d = %lf\n", d
);
3491 ok(d
== 1.0, "d = %lf\n", d
);
3494 ok(d
== -1.0, "d = %lf\n", d
);
3498 win_skip("_atof_l not found\n");
3504 ok(d
== 0.0, "d = %lf\n", d
);
3505 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3508 d
= p__atof_l(NULL
, NULL
);
3509 ok(d
== 0.0, "d = %lf\n", d
);
3510 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3513 static void test_strncpy(void)
3515 #define TEST_STRNCPY_LEN 10
3516 /* use function pointer to bypass gcc builtin */
3517 char *(__cdecl
*p_strncpy
)(char*,const char*,size_t);
3519 char dst
[TEST_STRNCPY_LEN
+ 1];
3520 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
3522 p_strncpy
= (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "strncpy");
3524 /* strlen(src) > TEST_STRNCPY_LEN */
3525 ret
= p_strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
3526 ok(ret
== dst
, "ret != dst\n");
3527 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3529 /* without null-terminated */
3530 ret
= p_strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
3531 ok(ret
== dst
, "ret != dst\n");
3532 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3534 /* strlen(src) < TEST_STRNCPY_LEN */
3535 strcpy(dst
, "0123456789");
3536 ret
= p_strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
3537 ok(ret
== dst
, "ret != dst\n");
3538 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
3539 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
3541 /* strlen(src) == TEST_STRNCPY_LEN */
3542 ret
= p_strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
3543 ok(ret
== dst
, "ret != dst\n");
3544 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3547 static void test_strxfrm(void)
3552 /* crashes on old version of msvcrt */
3555 ret
= strxfrm(NULL
, "src", 1);
3556 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3557 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3560 ret
= strxfrm(dest
, NULL
, 100);
3561 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3562 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3565 ret
= strxfrm(NULL
, "src", 0);
3566 ok(ret
== 3, "ret = %d\n", (int)ret
);
3568 ret
= strxfrm(dest
, "src", 0);
3569 ok(ret
== 3, "ret = %d\n", (int)ret
);
3570 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3573 ret
= strxfrm(dest
, "src", 5);
3574 ok(ret
== 3, "ret = %d\n", (int)ret
);
3575 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
3579 ret
= strxfrm(dest
, "src", 1);
3580 ok(ret
== 3, "ret = %d\n", (int)ret
);
3581 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
3582 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
3583 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3585 ret
= strxfrm(dest
, "", 5);
3586 ok(ret
== 0, "ret = %d\n", (int)ret
);
3587 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
3589 if(!setlocale(LC_ALL
, "polish")) {
3590 win_skip("stxfrm tests\n");
3594 ret
= strxfrm(NULL
, "src", 0);
3595 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3597 ret
= strxfrm(dest
, "src", 0);
3598 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3599 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3601 ret
= strxfrm(dest
, "src", ret
+1);
3602 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3603 ok(dest
[0], "dest[0] = 0\n");
3607 ret
= strxfrm(dest
, "src", 5);
3608 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3609 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
3611 setlocale(LC_ALL
, "C");
3614 static void test__strnset_s(void)
3620 win_skip("_strnset_s not available\n");
3624 r
= p__strnset_s(NULL
, 0, 'a', 0);
3625 ok(r
== 0, "r = %d\n", r
);
3627 buf
[0] = buf
[1] = buf
[2] = 'b';
3628 r
= p__strnset_s(buf
, sizeof(buf
), 'a', 2);
3629 ok(r
== 0, "r = %d\n", r
);
3630 ok(!strcmp(buf
, "aab"), "buf = %s\n", buf
);
3632 r
= p__strnset_s(buf
, 0, 'a', 0);
3633 ok(r
== EINVAL
, "r = %d\n", r
);
3635 r
= p__strnset_s(NULL
, 0, 'a', 1);
3636 ok(r
== EINVAL
, "r = %d\n", r
);
3639 r
= p__strnset_s(buf
, sizeof(buf
)-1, 'c', 2);
3640 ok(r
== EINVAL
, "r = %d\n", r
);
3641 ok(!buf
[0] && buf
[1]=='c' && buf
[2]=='b', "buf = %s\n", buf
);
3644 static void test__wcsnset_s(void)
3646 wchar_t text
[] = L
"text";
3650 win_skip("_wcsnset_s not available\n");
3654 r
= p__wcsnset_s(NULL
, 0, 'a', 0);
3655 ok(r
== 0, "r = %d\n", r
);
3657 r
= p__wcsnset_s(text
, 0, 'a', 1);
3658 ok(r
== EINVAL
, "r = %d\n", r
);
3659 ok(text
[0] == 't', "text[0] = %d\n", text
[0]);
3661 r
= p__wcsnset_s(NULL
, 2, 'a', 1);
3662 ok(r
== EINVAL
, "r = %d\n", r
);
3664 r
= p__wcsnset_s(text
, 2, 'a', 3);
3665 ok(r
== EINVAL
, "r = %d\n", r
);
3666 ok(text
[0] == 0, "text[0] = %d\n", text
[0]);
3667 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3670 r
= p__wcsnset_s(text
, 5, 'a', 1);
3671 ok(r
== 0, "r = %d\n", r
);
3672 ok(text
[0] == 'a', "text[0] = %d\n", text
[0]);
3673 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3676 r
= p__wcsnset_s(text
, 5, 'b', 3);
3677 ok(r
== 0, "r = %d\n", r
);
3678 ok(text
[0] == 'b', "text[0] = %d\n", text
[0]);
3679 ok(text
[1] == 0, "text[1] = %d\n", text
[1]);
3680 ok(text
[2] == 'x', "text[2] = %d\n", text
[2]);
3683 static void test__wcsset_s(void)
3689 win_skip("_wcsset_s not available\n");
3693 r
= p__wcsset_s(NULL
, 0, 'a');
3694 ok(r
== EINVAL
, "r = %d\n", r
);
3697 r
= p__wcsset_s(str
, 0, 'a');
3698 ok(r
== EINVAL
, "r = %d\n", r
);
3699 ok(str
[0] == 'a', "str[0] = %d\n", str
[0]);
3703 r
= p__wcsset_s(str
, 2, 'c');
3704 ok(r
== EINVAL
, "r = %d\n", r
);
3705 ok(!str
[0], "str[0] = %d\n", str
[0]);
3706 ok(str
[1] == 'b', "str[1] = %d\n", str
[1]);
3711 r
= p__wcsset_s(str
, 3, 'c');
3712 ok(r
== 0, "r = %d\n", r
);
3713 ok(str
[0] == 'c', "str[0] = %d\n", str
[0]);
3714 ok(str
[1] == 0, "str[1] = %d\n", str
[1]);
3715 ok(str
[2] == 'b', "str[2] = %d\n", str
[2]);
3718 static void test__mbscmp(void)
3720 static const unsigned char a
[] = {'a',0}, b
[] = {'b',0};
3725 win_skip("_mbscmp tests\n");
3729 ret
= _mbscmp(NULL
, NULL
);
3730 ok(ret
== INT_MAX
, "got %d\n", ret
);
3732 ret
= _mbscmp(a
, NULL
);
3733 ok(ret
== INT_MAX
, "got %d\n", ret
);
3735 ret
= _mbscmp(NULL
, a
);
3736 ok(ret
== INT_MAX
, "got %d\n", ret
);
3738 ret
= _mbscmp(a
, a
);
3739 ok(!ret
, "got %d\n", ret
);
3741 ret
= _mbscmp(a
, b
);
3742 ok(ret
== -1, "got %d\n", ret
);
3744 ret
= _mbscmp(b
, a
);
3745 ok(ret
== 1, "got %d\n", ret
);
3749 win_skip("_mbscmp_l tests\n");
3753 ret
= p_mbscmp_l(a
, b
, NULL
);
3754 ok(ret
== -1, "got %d\n", ret
);
3757 static void test__ismbclx(void)
3759 int ret
, cp
= _getmbcp();
3762 ok(!ret
, "got %d\n", ret
);
3765 ok(!ret
, "got %d\n", ret
);
3768 ok(!ret
, "got %d\n", ret
);
3772 ret
= _ismbcl0(0x8140);
3773 ok(!ret
, "got %d\n", ret
);
3775 ret
= _ismbcl1(0x889f);
3776 ok(!ret
, "got %d\n", ret
);
3778 ret
= _ismbcl2(0x989f);
3779 ok(!ret
, "got %d\n", ret
);
3784 ok(!ret
, "got %d\n", ret
);
3786 ret
= _ismbcl0(0x8140);
3787 ok(ret
, "got %d\n", ret
);
3789 ret
= _ismbcl0(0x817f);
3790 ok(!ret
, "got %d\n", ret
);
3793 ok(!ret
, "got %d\n", ret
);
3795 ret
= _ismbcl1(0x889f);
3796 ok(ret
, "got %d\n", ret
);
3798 ret
= _ismbcl1(0x88fd);
3799 ok(!ret
, "got %d\n", ret
);
3802 ok(!ret
, "got %d\n", ret
);
3804 ret
= _ismbcl2(0x989f);
3805 ok(ret
, "got %d\n", ret
);
3807 ret
= _ismbcl2(0x993f);
3808 ok(!ret
, "got %d\n", ret
);
3813 static void test__memicmp(void)
3815 static const char *s1
= "abc";
3816 static const char *s2
= "aBd";
3819 ret
= p__memicmp(NULL
, NULL
, 0);
3820 ok(!ret
, "got %d\n", ret
);
3822 ret
= p__memicmp(s1
, s2
, 2);
3823 ok(!ret
, "got %d\n", ret
);
3825 ret
= p__memicmp(s1
, s2
, 3);
3826 ok(ret
== -1, "got %d\n", ret
);
3831 /* Following calls crash on WinXP/W2k3. */
3833 ret
= p__memicmp(NULL
, NULL
, 1);
3834 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3835 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3838 ret
= p__memicmp(s1
, NULL
, 1);
3839 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3840 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3843 ret
= p__memicmp(NULL
, s2
, 1);
3844 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3845 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3848 static void test__memicmp_l(void)
3850 static const char *s1
= "abc";
3851 static const char *s2
= "aBd";
3856 win_skip("_memicmp_l not found.\n");
3861 ret
= p__memicmp_l(NULL
, NULL
, 0, NULL
);
3862 ok(!ret
, "got %d\n", ret
);
3863 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3866 ret
= p__memicmp_l(NULL
, NULL
, 1, NULL
);
3867 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3868 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3871 ret
= p__memicmp_l(s1
, NULL
, 1, NULL
);
3872 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3873 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3876 ret
= p__memicmp_l(NULL
, s2
, 1, NULL
);
3877 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3878 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3881 ret
= p__memicmp_l(s1
, s2
, 2, NULL
);
3882 ok(!ret
, "got %d\n", ret
);
3883 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3886 ret
= p__memicmp_l(s1
, s2
, 3, NULL
);
3887 ok(ret
== -1, "got %d\n", ret
);
3888 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3891 static void test__strupr(void)
3893 const char str
[] = "123";
3894 const char *const_p
;
3899 mem
= VirtualAlloc(NULL
, sizeof(str
), MEM_COMMIT
, PAGE_READWRITE
);
3900 ok(mem
!= NULL
, "VirtualAlloc failed\n");
3901 memcpy(mem
, str
, sizeof(str
));
3902 ok(VirtualProtect(mem
, sizeof(str
), PAGE_READONLY
, &prot
), "VirtualProtect failed\n");
3904 strcpy(str2
, "aBc");
3906 ok(p
== str2
, "_strupr returned %p\n", p
);
3907 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3910 ok(p
== mem
, "_strupr returned %p\n", p
);
3911 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3913 const_p
= "ALREADY_UPPERCASE";
3914 p
= _strupr((char *)const_p
);
3915 ok(p
== const_p
, "_strupr returned %p\n", p
);
3917 if(!setlocale(LC_ALL
, "english")) {
3918 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3919 win_skip("English locale _strupr tests\n");
3923 strcpy(str2
, "aBc");
3925 ok(p
== str2
, "_strupr returned %p\n", p
);
3926 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3928 if (0) /* crashes on Windows */
3931 ok(p
== mem
, "_strupr returned %p\n", p
);
3932 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3935 setlocale(LC_ALL
, "C");
3936 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3939 static void test__tcsncoll(void)
3948 static const struct test tests
[] = {
3949 { "English", "ABCD", "ABCD", 4, 0 },
3950 { "English", "ABCD", "ABCD", 10, 0 },
3952 { "English", "ABC", "ABCD", 3, 0 },
3953 { "English", "ABC", "ABCD", 4, -1 },
3954 { "English", "ABC", "ABCD", 10, -1 },
3956 { "English", "ABCD", "ABC", 3, 0 },
3957 { "English", "ABCD", "ABC", 4, 1 },
3958 { "English", "ABCD", "ABC", 10, 1 },
3960 { "English", "ABCe", "ABCf", 3, 0 },
3961 { "English", "abcd", "ABCD", 10, -1 },
3963 { "C", "ABCD", "ABCD", 4, 0 },
3964 { "C", "ABCD", "ABCD", 10, 0 },
3966 { "C", "ABC", "ABCD", 3, 0 },
3967 { "C", "ABC", "ABCD", 10, -1 },
3969 { "C", "ABCD", "ABC", 3, 0 },
3970 { "C", "ABCD", "ABC", 10, 1 },
3972 { "C", "ABCe", "ABCf", 3, 0 },
3973 { "C", "abcd", "ABCD", 10, 1 },
3982 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3984 if (!setlocale(LC_ALL
, tests
[i
].locale
))
3986 win_skip("%s locale _tcsncoll tests\n", tests
[i
].locale
);
3987 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
3988 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
3992 memset(str1
, 0xee, sizeof(str1
));
3993 strcpy(str1
, tests
[i
].str1
);
3995 memset(str2
, 0xff, sizeof(str2
));
3996 strcpy(str2
, tests
[i
].str2
);
3998 ret
= _strncoll(str1
, str2
, tests
[i
].count
);
4000 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4001 else if (tests
[i
].exp
< 0)
4002 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4004 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4006 memset(str1W
, 0xee, sizeof(str1W
));
4007 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
4010 memset(str2W
, 0xff, sizeof(str2W
));
4011 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
4014 ret
= _wcsncoll(str1W
, str2W
, tests
[i
].count
);
4016 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4017 else if (tests
[i
].exp
< 0)
4018 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4020 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4024 static void test__tcsnicoll(void)
4033 static const struct test tests
[] = {
4034 { "English", "abcd", "ABCD", 4, 0 },
4035 { "English", "abcd", "ABCD", 10, 0 },
4037 { "English", "abc", "ABCD", 3, 0 },
4038 { "English", "abc", "ABCD", 4, -1 },
4039 { "English", "abc", "ABCD", 10, -1 },
4041 { "English", "abcd", "ABC", 3, 0 },
4042 { "English", "abcd", "ABC", 4, 1 },
4043 { "English", "abcd", "ABC", 10, 1 },
4045 { "English", "abcE", "ABCF", 3, 0 },
4047 { "C", "abcd", "ABCD", 4, 0 },
4048 { "C", "abcd", "ABCD", 10, 0 },
4050 { "C", "abc", "ABCD", 3, 0 },
4051 { "C", "abc", "ABCD", 10, -1 },
4053 { "C", "abcd", "ABC", 3, 0 },
4054 { "C", "abcd", "ABC", 10, 1 },
4056 { "C", "abce", "ABCf", 3, 0 },
4065 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4067 if (!setlocale(LC_ALL
, tests
[i
].locale
))
4069 win_skip("%s locale _tcsnicoll tests\n", tests
[i
].locale
);
4070 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
4071 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
4075 memset(str1
, 0xee, sizeof(str1
));
4076 strcpy(str1
, tests
[i
].str1
);
4078 memset(str2
, 0xff, sizeof(str2
));
4079 strcpy(str2
, tests
[i
].str2
);
4081 ret
= _strnicoll(str1
, str2
, tests
[i
].count
);
4083 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4084 else if (tests
[i
].exp
< 0)
4085 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4087 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4089 memset(str1W
, 0xee, sizeof(str1W
));
4090 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
4093 memset(str2W
, 0xff, sizeof(str2W
));
4094 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
4097 ret
= _wcsnicoll(str1W
, str2W
, tests
[i
].count
);
4099 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4100 else if (tests
[i
].exp
< 0)
4101 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4103 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4107 static void test___strncnt(void)
4128 win_skip("__strncnt() is not available.\n");
4132 if (0) /* crashes */
4133 ret
= p___strncnt(NULL
, 1);
4135 for (i
= 0; i
< ARRAY_SIZE(strncnt_tests
); ++i
)
4137 ret
= p___strncnt(strncnt_tests
[i
].str
, strncnt_tests
[i
].size
);
4138 ok(ret
== strncnt_tests
[i
].ret
, "%u: unexpected return value %u.\n", i
, (int)ret
);
4142 static void test_C_locale(void)
4147 static const char *locales
[] = { NULL
, "C" };
4149 /* C locale only converts case for [a-zA-Z] */
4150 setlocale(LC_ALL
, "C");
4151 for (i
= 0; i
<= 0xffff; i
++)
4153 ret
= p_towlower(i
);
4154 if (i
>= 'A' && i
<= 'Z')
4156 exp
= i
+ 'a' - 'A';
4157 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4160 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
4162 ret
= p_towupper(i
);
4163 if (i
>= 'a' && i
<= 'z')
4165 exp
= i
+ 'A' - 'a';
4166 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4169 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
4172 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
4174 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
4178 for (i
= 0; i
< ARRAY_SIZE(locales
); i
++) {
4179 locale
= locales
[i
] ? p__create_locale(LC_ALL
, locales
[i
]) : NULL
;
4181 for (j
= 0; j
<= 0xffff; j
++) {
4182 ret
= p__towlower_l(j
, locale
);
4183 if (j
>= 'A' && j
<= 'Z')
4185 exp
= j
+ 'a' - 'A';
4186 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4189 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
4191 ret
= p__towupper_l(j
, locale
);
4192 if (j
>= 'a' && j
<= 'z')
4194 exp
= j
+ 'A' - 'a';
4195 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4198 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
4201 p__free_locale(locale
);
4205 static void test_strstr(void)
4207 static char long_str
[1024];
4209 const char *haystack
;
4216 { "aabc", "abc", 1 },
4217 { "aaaa", "aaaa", 0 },
4218 { "simple", "simple", 0 },
4219 { "aaaaxaaaaxaaaa", "aaaaa", -1 },
4220 { "aaaaxaaaaxaaaaa", "aaaaa", 10 },
4221 { "abcabcdababcdabcdabde", "abcdabd", 13 },
4222 { "abababababcabababcababbba", "abababcaba", 4 },
4223 { long_str
, long_str
+1, 0 }
4225 const char *r
, *exp
;
4228 memset(long_str
, 'a', sizeof(long_str
)-1);
4230 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
4232 r
= strstr(tests
[i
].haystack
, tests
[i
].needle
);
4233 exp
= tests
[i
].off
== -1 ? NULL
: tests
[i
].haystack
+ tests
[i
].off
;
4234 ok(r
== exp
, "%d) strstr returned %p, expected %p\n", i
, r
, exp
);
4238 static void test_iswdigit(void)
4240 static const struct {
4247 { 0xff16, C1_DIGIT
},
4248 { 0x0660, C1_DIGIT
},
4249 { 0x0ce6, C1_DIGIT
}
4253 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4255 r
= iswdigit(tests
[i
].c
);
4256 ok(r
== tests
[i
].r
, "iswdigit returned %x for %x\n", r
, tests
[i
].c
);
4260 static void test_wcscmp(void)
4264 r
= wcscmp(L
"a", L
"z");
4265 ok(r
== -1, "wcscmp returned %d\n", r
);
4267 r
= wcscmp(L
"z", L
"a");
4268 ok(r
== 1, "wcscmp returned %d\n", r
);
4270 r
= wcscmp(L
"f", L
"f");
4271 ok(!r
, "wcscmp returned %d\n", r
);
4274 static const char* debugstr_ldouble(_LDOUBLE
*v
)
4276 static char buf
[2 * ARRAY_SIZE(v
->ld
) + 1];
4279 for(i
=0; i
<ARRAY_SIZE(v
->ld
); i
++)
4281 buf
[2*i
] = v
->ld
[i
] / 16 + '0';
4282 if(buf
[2*i
] > '9') buf
[2*i
] -= 10 + '0' - 'a';
4283 buf
[2*i
+1] = v
->ld
[i
] % 16 + '0';
4284 if(buf
[2*i
+1] > '9') buf
[2*i
+1] -= 10 + '0' - 'a';
4286 buf
[2 * ARRAY_SIZE(v
->ld
)] = 0;
4290 static void test___STRINGTOLD(void)
4292 static const struct {
4302 { "-0.0", 4, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }} },
4303 { "1e0", 3, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f }} },
4304 { "1.7976931348623158e+308", 23, 0, {{ 0xaf, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x43 }} },
4305 { "1.7976931348623159e+308", 23, 0, {{ 0xb1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x43 }} },
4306 { "3.65e-4951", 10, 0, {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} },
4307 { "1.82e-4951", 10, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}, TRUE
},
4308 { "1e-99999", 8, 1, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} },
4309 { "1.18e+4932", 10, 0, {{ 0x25, 0x75, 0x06, 0x68, 0x8a, 0xf1, 0xe7, 0xfd, 0xfe, 0x7f }} },
4310 { "1.19e+4932", 10, 2, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f }} },
4311 { "1e+99999", 8, 2, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f }} },
4318 for(i
=0; i
<ARRAY_SIZE(tests
); i
++)
4321 r
= __STRINGTOLD(&v
, &endptr
, tests
[i
].str
, 0);
4322 todo_wine_if(tests
[i
].todo
)
4323 ok(r
== tests
[i
].r
, "%d) r = %d\n", i
, r
);
4324 ok(endptr
== tests
[i
].str
+ tests
[i
].endptr
, "%d) endptr = %p, expected %p\n",
4325 i
, endptr
, tests
[i
].str
+tests
[i
].endptr
);
4326 ok(!memcmp(&v
, &tests
[i
].v
, sizeof(v
)), "%d) v = %s\n", i
, debugstr_ldouble(&v
));
4327 ok(errno
== 0xdeadbeef, "%d) errno = %x\n", i
, errno
);
4331 static void test_SpecialCasing(void)
4342 struct test ucases
[] = {
4343 {"English", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
4344 {"English", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
4346 {"Turkish", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
4347 {"Turkish", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
4349 struct test lcases
[] = {
4350 {"English", 'i', 'I'}, /* LATIN SMALL LETTER I */
4351 {"English", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
4353 {"Turkish", 'i', 'I'}, /* LATIN SMALL LETTER I */
4354 {"Turkish", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
4357 for (i
= 0; i
< ARRAY_SIZE(ucases
); i
++) {
4358 if (!setlocale(LC_ALL
, ucases
[i
].lang
)) {
4359 win_skip("skipping special case tests for %s\n", ucases
[i
].lang
);
4363 ret
= p_towlower(ucases
[i
].ch
);
4364 exp
= ucases
[i
].exp
? ucases
[i
].exp
: ucases
[i
].ch
;
4365 ok(ret
== exp
, "expected lowercase %x, got %x for locale %s\n", exp
, ret
, ucases
[i
].lang
);
4368 for (i
= 0; i
< ARRAY_SIZE(lcases
); i
++) {
4369 if (!setlocale(LC_ALL
, lcases
[i
].lang
)) {
4370 win_skip("skipping special case tests for %s\n", lcases
[i
].lang
);
4374 ret
= p_towupper(lcases
[i
].ch
);
4375 exp
= lcases
[i
].exp
? lcases
[i
].exp
: lcases
[i
].ch
;
4376 ok(ret
== exp
, "expected uppercase %x, got %x for locale %s\n", exp
, ret
, lcases
[i
].lang
);
4379 setlocale(LC_ALL
, "C");
4381 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
4383 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
4387 /* test _towlower_l creating locale */
4388 for (i
= 0; i
< ARRAY_SIZE(ucases
); i
++) {
4389 if (!(locale
= p__create_locale(LC_ALL
, ucases
[i
].lang
))) {
4390 win_skip("locale %s not available. skipping\n", ucases
[i
].lang
);
4394 ret
= p__towlower_l(ucases
[i
].ch
, locale
);
4395 exp
= ucases
[i
].exp
? ucases
[i
].exp
: ucases
[i
].ch
;
4396 ok(ret
== exp
, "expected lowercase %x, got %x for locale %s\n", exp
, ret
, ucases
[i
].lang
);
4398 p__free_locale(locale
);
4401 /* test _towupper_l creating locale */
4402 for (i
= 0; i
< ARRAY_SIZE(lcases
); i
++) {
4403 if (!(locale
= p__create_locale(LC_ALL
, lcases
[i
].lang
))) {
4404 win_skip("locale %s not available. skipping\n", lcases
[i
].lang
);
4408 ret
= p__towupper_l(lcases
[i
].ch
, locale
);
4409 exp
= lcases
[i
].exp
? lcases
[i
].exp
: lcases
[i
].ch
;
4410 ok(ret
== exp
, "expected uppercase %x, got %x for locale %s\n", exp
, ret
, lcases
[i
].lang
);
4412 p__free_locale(locale
);
4417 static void test__mbbtype(void)
4419 static const char *test_locales
[] =
4423 "English_Australia",
4431 "Portuguese_Brazil",
4433 "Spanish_Argentina",
4442 for (i
= 0; i
< ARRAY_SIZE(test_locales
); ++i
)
4444 setlocale(LC_ALL
, test_locales
[i
]);
4445 _setmbcp(_MB_CP_LOCALE
);
4446 for (c
= 0; c
< 256; ++c
)
4449 expected
= _MBC_LEAD
;
4450 else if (isprint(c
))
4451 expected
= _MBC_SINGLE
;
4453 expected
= _MBC_ILLEGAL
;
4455 ret
= _mbbtype(c
, 0);
4456 ok(ret
== expected
, "test %u, c %#x, got ret %#x, expected %#x.\n", i
, c
, ret
, expected
);
4459 expected
= _MBC_TRAIL
;
4461 expected
= _MBC_ILLEGAL
;
4463 ret
= _mbbtype(c
, 1);
4464 ok(ret
== expected
, "test %u, c %#x, got ret %#x, expected %#x.\n", i
, c
, ret
, expected
);
4469 static void test_wcsncpy(void)
4473 memset(dst
, 0xff, sizeof(dst
));
4474 p
= wcsncpy(dst
, L
"1234567", 6);
4475 ok(p
== dst
, "Unexpected return value.\n");
4476 ok(!memcmp(dst
, L
"123456", sizeof(dst
)), "unexpected buffer %s\n",
4477 wine_dbgstr_wn(dst
, ARRAY_SIZE(dst
)));
4483 static const char xilstring
[]="c:/xilinx";
4486 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
4488 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
4489 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
4490 SET(pmemcpy
,"memcpy");
4491 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
4492 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
4493 SET(pmemcmp
,"memcmp");
4494 SET(p_mbctype
,"_mbctype");
4495 SET(p__mb_cur_max
,"__mb_cur_max");
4496 SET(p_strcpy
, "strcpy");
4497 SET(p_strcmp
, "strcmp");
4498 SET(p_strncmp
, "strncmp");
4499 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
4500 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
4501 p_mbscat_s
= (void*)GetProcAddress( hMsvcrt
, "_mbscat_s" );
4502 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
4503 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
4504 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
4505 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
4506 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
4507 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
4508 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
4509 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
4510 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
4511 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
4512 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
4513 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
4514 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
4515 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
4516 p_wcstombs_s_l
= (void *)GetProcAddress(hMsvcrt
, "_wcstombs_s_l");
4517 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
4518 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
4519 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
4520 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
4521 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
4522 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
4523 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
4524 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
4525 p_btowc
= (void*)GetProcAddress(hMsvcrt
, "btowc");
4526 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
4527 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
4528 p_wcrtomb_s
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb_s");
4529 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
4530 p_towlower
= (void*)GetProcAddress(hMsvcrt
, "towlower");
4531 p__towlower_l
= (void*)GetProcAddress(hMsvcrt
, "_towlower_l");
4532 p_towupper
= (void*)GetProcAddress(hMsvcrt
, "towupper");
4533 p__towupper_l
= (void*)GetProcAddress(hMsvcrt
, "_towupper_l");
4534 p__create_locale
= (void*)GetProcAddress(hMsvcrt
, "_create_locale");
4535 p__free_locale
= (void*)GetProcAddress(hMsvcrt
, "_free_locale");
4536 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
4537 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
4538 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
4539 p_mbsrtowcs_s
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs_s");
4540 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
4541 p__atof_l
= (void*)GetProcAddress(hMsvcrt
, "_atof_l");
4542 p__strtod_l
= (void*)GetProcAddress(hMsvcrt
, "_strtod_l");
4543 p__strnset_s
= (void*)GetProcAddress(hMsvcrt
, "_strnset_s");
4544 p__wcsnset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsnset_s");
4545 p__wcsset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsset_s");
4546 p__mbsnlen
= (void*)GetProcAddress(hMsvcrt
, "_mbsnlen");
4547 p__mbccpy_s
= (void*)GetProcAddress(hMsvcrt
, "_mbccpy_s");
4548 p__memicmp
= (void*)GetProcAddress(hMsvcrt
, "_memicmp");
4549 p__memicmp_l
= (void*)GetProcAddress(hMsvcrt
, "_memicmp_l");
4550 p___strncnt
= (void*)GetProcAddress(hMsvcrt
, "__strncnt");
4551 p_mbsnextc_l
= (void*)GetProcAddress(hMsvcrt
, "_mbsnextc_l");
4552 p_mbscmp_l
= (void*)GetProcAddress(hMsvcrt
, "_mbscmp_l");
4554 /* MSVCRT memcpy behaves like memmove for overlapping moves,
4555 MFC42 CString::Insert seems to rely on that behaviour */
4556 strcpy(mem
,xilstring
);
4557 nLen
=strlen(xilstring
);
4558 pmemcpy(mem
+5, mem
,nLen
+1);
4559 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
4560 "Got result %s\n",mem
+5);
4562 /* run tolower tests first */
4595 test__wcstombs_s_l();
4632 test___STRINGTOLD();
4633 test_SpecialCasing();