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 */
40 static char *buf_to_string(const unsigned char *bin
, int len
, int nr
)
42 static char buf
[2][1024];
46 for (i
= 0; i
< len
; i
++)
48 sprintf(w
, "%02x ", (unsigned char)bin
[i
]);
54 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
55 #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)); }
57 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
58 static int (__cdecl
*p_memcpy_s
)(void *, size_t, const void *, size_t);
59 static int (__cdecl
*p_memmove_s
)(void *, size_t, const void *, size_t);
60 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
61 static int (__cdecl
*p_strcmp
)(const char *, const char *);
62 static int (__cdecl
*p_strncmp
)(const char *, const char *, size_t);
63 static int (__cdecl
*p_strcpy
)(char *dst
, const char *src
);
64 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
65 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
66 static int (__cdecl
*p_mbscat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
);
67 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
68 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
69 static int (__cdecl
*p__mbscpy_s
)(unsigned char*, size_t, const unsigned char*);
70 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
71 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
72 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
73 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
74 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
75 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
76 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
77 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
78 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
79 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
80 static int (__cdecl
*p_wcstombs_s_l
)(size_t*,char*,size_t,const wchar_t*,size_t,_locale_t
);
81 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
82 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
83 static int (__cdecl
*p_mbsrtowcs_s
)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
84 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
85 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
86 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
87 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
88 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
89 static int *p__mb_cur_max
;
90 static unsigned char *p_mbctype
;
91 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
92 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
93 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
94 static int (__cdecl
*p_wctob
)(wint_t);
95 static wint_t (__cdecl
*p_btowc
)(int);
96 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
97 static int (__cdecl
*p_wcrtomb_s
)(size_t*, char*, size_t, wchar_t, mbstate_t*);
98 static int (__cdecl
*p_tolower
)(int);
99 static int (__cdecl
*p_towlower
)(wint_t);
100 static int (__cdecl
*p__towlower_l
)(wint_t, _locale_t
);
101 static int (__cdecl
*p_towupper
)(wint_t);
102 static int (__cdecl
*p__towupper_l
)(wint_t, _locale_t
);
103 static _locale_t(__cdecl
*p__create_locale
)(int, const char*);
104 static void(__cdecl
*p__free_locale
)(_locale_t
);
105 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
106 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
107 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
108 static double (__cdecl
*p__atof_l
)(const char*,_locale_t
);
109 static double (__cdecl
*p__strtod_l
)(const char *,char**,_locale_t
);
110 static int (__cdecl
*p__strnset_s
)(char*,size_t,int,size_t);
111 static int (__cdecl
*p__wcsnset_s
)(wchar_t*,size_t,wchar_t,size_t);
112 static int (__cdecl
*p__wcsset_s
)(wchar_t*,size_t,wchar_t);
113 static size_t (__cdecl
*p__mbsnlen
)(const unsigned char*, size_t);
114 static int (__cdecl
*p__mbccpy_s
)(unsigned char*, size_t, int*, const unsigned char*);
115 static int (__cdecl
*p__memicmp
)(const char*, const char*, size_t);
116 static int (__cdecl
*p__memicmp_l
)(const char*, const char*, size_t, _locale_t
);
117 static size_t (__cdecl
*p___strncnt
)(const char*, size_t);
118 static unsigned int (__cdecl
*p_mbsnextc_l
)(const unsigned char*, _locale_t
);
119 static int (__cdecl
*p_mbscmp_l
)(const unsigned char*, const unsigned char*, _locale_t
);
121 int CDECL
__STRINGTOLD(_LDOUBLE
*, char**, const char*, int);
123 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
124 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
126 static HMODULE hMsvcrt
;
128 static void test_swab( void ) {
129 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
130 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
131 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
132 char expected3
[] = "$";
139 /* Test 1 - normal even case */
140 memset(to
,'$', sizeof(to
));
141 memset(from
,'@', sizeof(from
));
143 memcpy(from
, original
, testsize
);
144 _swab( from
, to
, testsize
);
145 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
147 /* Test 2 - uneven case */
148 memset(to
,'$', sizeof(to
));
149 memset(from
,'@', sizeof(from
));
151 memcpy(from
, original
, testsize
);
152 _swab( from
, to
, testsize
);
153 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
155 /* Test 3 - from = to */
156 memset(to
,'$', sizeof(to
));
157 memset(from
,'@', sizeof(from
));
159 memcpy(to
, original
, testsize
);
160 _swab( to
, to
, testsize
);
161 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
163 /* Test 4 - 1 bytes */
164 memset(to
,'$', sizeof(to
));
165 memset(from
,'@', sizeof(from
));
167 memcpy(from
, original
, testsize
);
168 _swab( from
, to
, testsize
);
169 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
172 static void test_strcspn(void)
174 static const struct {
183 { "a\xf1", "\xf1", 1 }
187 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
189 r
= strcspn(tests
[i
].str
, tests
[i
].rej
);
190 ok(r
== tests
[i
].ret
, "strcspn(\"%s\", \"%s\") = %d, expected %d\n",
191 tests
[i
].str
, tests
[i
].rej
, r
, tests
[i
].ret
);
195 #if 0 /* use this to generate more tests */
197 static void test_codepage(int cp
)
203 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
206 printf("static int result_cp_%d_mbctype[] = { ", cp
);
207 for (i
= 1; i
< 257; i
++)
209 if (p_mbctype
[i
] != prev
)
211 printf("0x%x,%d, ", prev
, count
);
218 printf("0x%x,%d };\n", prev
, count
);
223 /* RLE-encoded mbctype tables for given codepages */
224 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
225 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
226 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
228 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
230 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
231 0x0,2, 0x4,32, 0xc,94, 0,1 };
233 static void test_cp_table(int cp
, int *result
)
239 for (i
= 0; i
< 256; i
++)
247 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
);
252 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
256 static void test_mbcp(void)
258 int mb_orig_max
= *p__mb_cur_max
;
259 int curr_mbcp
= _getmbcp();
260 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
261 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
262 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
263 unsigned char buf
[16];
269 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
270 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
271 * CP1252 (or the ACP?) so we test only a few ASCII characters */
273 expect_eq(p_mbctype
[10], 0, char, "%x");
274 expect_eq(p_mbctype
[50], 0, char, "%x");
275 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
276 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
277 expect_eq(p_mbctype
[128], 0, char, "%x");
279 expect_eq(p_mbctype
[10], 0, char, "%x");
280 expect_eq(p_mbctype
[50], 0, char, "%x");
281 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
282 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
283 expect_eq(p_mbctype
[128], 0, char, "%x");
285 /* double byte code pages */
292 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
);
293 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
294 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
295 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
296 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
297 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
298 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
301 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
302 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
303 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
304 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
305 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
306 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
307 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
308 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
309 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
311 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
312 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
313 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
314 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
317 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
318 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
319 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
320 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
321 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
322 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
323 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
324 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
325 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
327 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
328 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
329 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
330 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
331 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
332 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
335 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
336 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
337 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
338 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
339 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
340 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
341 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
342 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
343 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
345 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
346 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
347 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
348 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
349 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
350 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
353 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
354 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
355 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
358 win_skip("_mbsnextc_l tests\n");
360 expect_eq(p_mbsnextc_l(mbstring
, NULL
), 0xb0b1, int, "%x");
362 /* _mbclen/_mbslen */
363 expect_eq(_mbclen(mbstring
), 2, int, "%d");
364 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
365 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
366 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
367 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
368 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
371 win_skip("_mbsnlen tests\n");
373 expect_eq(p__mbsnlen(mbstring
, 8), 8, int, "%d");
374 expect_eq(p__mbsnlen(mbstring
, 9), 4, int, "%d");
375 expect_eq(p__mbsnlen(mbstring
, 10), 4, int, "%d");
376 expect_eq(p__mbsnlen(mbsonlylead
, 0), 0, int, "%d");
377 expect_eq(p__mbsnlen(mbsonlylead
, 1), 1, int, "%d");
378 expect_eq(p__mbsnlen(mbsonlylead
, 2), 0, int, "%d");
379 expect_eq(p__mbsnlen(mbstring2
, 7), 7, int, "%d");
380 expect_eq(p__mbsnlen(mbstring2
, 8), 4, int, "%d");
381 expect_eq(p__mbsnlen(mbstring2
, 9), 4, int, "%d");
385 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
386 win_skip("mbrlen tests\n");
389 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
390 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
391 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
392 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
393 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
394 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
395 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
399 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
400 win_skip("mbrtowc tests\n");
404 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
405 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
406 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
407 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
408 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
409 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
410 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
411 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
412 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
413 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
414 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
415 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
416 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
417 ok(state
== 0, "incorrect state value (%x)\n", state
);
419 setlocale(LC_ALL
, "C");
421 /* _mbccpy/_mbsncpy */
422 memset(buf
, 0xff, sizeof(buf
));
423 _mbccpy(buf
, mbstring
);
424 expect_bin(buf
, "\xb0\xb1\xff", 3);
427 win_skip("_mbccpy_s tests\n");
431 memset(buf
, 0xff, sizeof(buf
));
433 err
= p__mbccpy_s(buf
, 0, &copied
, mbstring
);
434 ok(err
== EINVAL
, "_mbccpy_s returned %d\n", err
);
435 ok(!copied
, "copied = %d\n", copied
);
436 ok(buf
[0] == 0xff, "buf[0] = %x\n", buf
[0]);
438 memset(buf
, 0xff, sizeof(buf
));
440 err
= p__mbccpy_s(buf
, 1, &copied
, mbstring
);
441 ok(err
== ERANGE
, "_mbccpy_s returned %d\n", err
);
442 ok(!copied
, "copied = %d\n", copied
);
443 ok(!buf
[0], "buf[0] = %x\n", buf
[0]);
445 memset(buf
, 0xff, sizeof(buf
));
447 err
= p__mbccpy_s(buf
, 2, &copied
, mbstring
);
448 ok(!err
, "_mbccpy_s returned %d\n", err
);
449 ok(copied
== 2, "copied = %d\n", copied
);
450 expect_bin(buf
, "\xb0\xb1\xff", 3);
452 memset(buf
, 0xff, sizeof(buf
));
454 err
= p__mbccpy_s(buf
, 2, &copied
, (unsigned char *)"\xb0");
455 ok(err
== EILSEQ
, "_mbccpy_s returned %d\n", err
);
456 ok(copied
== 1, "copied = %d\n", copied
);
457 expect_bin(buf
, "\x00\xff", 2);
460 memset(buf
, 0xff, sizeof(buf
));
461 _mbsncpy(buf
, mbstring
, 1);
462 expect_bin(buf
, "\xb0\xb1\xff", 3);
463 memset(buf
, 0xff, sizeof(buf
));
464 _mbsncpy(buf
, mbstring
, 2);
465 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
466 memset(buf
, 0xff, sizeof(buf
));
467 _mbsncpy(buf
, mbstring
, 3);
468 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
469 memset(buf
, 0xff, sizeof(buf
));
470 _mbsncpy(buf
, mbstring
, 4);
471 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
472 memset(buf
, 0xff, sizeof(buf
));
473 _mbsncpy(buf
, mbstring
, 5);
474 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
475 memset(buf
, 0xff, sizeof(buf
));
476 _mbsncpy(buf
, mbsonlylead
, 6);
477 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
479 memset(buf
, 0xff, sizeof(buf
));
480 _mbsnbcpy(buf
, mbstring2
, 2);
481 expect_bin(buf
, "\xb0\xb1\xff", 3);
482 _mbsnbcpy(buf
, mbstring2
, 3);
483 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
484 _mbsnbcpy(buf
, mbstring2
, 4);
485 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
486 memset(buf
, 0xff, sizeof(buf
));
487 _mbsnbcpy(buf
, mbsonlylead
, 5);
488 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
491 step
= _mbsinc(mbstring
) - mbstring
;
492 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
493 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
494 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
496 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
497 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
498 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
499 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
500 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
501 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
502 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
503 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
504 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
505 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
506 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
507 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
508 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
509 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
510 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
511 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
512 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
513 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
515 /* functions that depend on locale codepage, not mbcp.
516 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
517 * (as of Wine 0.9.43)
519 GetCPInfo(GetACP(), &cp_info
);
520 if (cp_info
.MaxCharSize
== 1)
522 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
523 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
526 skip("Current locale has double-byte charset - could lead to false positives\n");
529 expect_eq(_ismbblead(0x80), 0, int, "%d");
531 expect_eq(_ismbblead(0x81), 1, int, "%d");
532 expect_eq(_ismbblead(0x83), 1, int, "%d");
534 expect_eq(_ismbblead(0x84), 1, int, "%d");
535 expect_eq(_ismbblead(0xd3), 1, int, "%d");
536 expect_eq(_ismbblead(0xd7), 0, int, "%d");
537 expect_eq(_ismbblead(0xd8), 1, int, "%d");
538 expect_eq(_ismbblead(0xd9), 1, int, "%d");
540 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
541 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
542 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
543 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
544 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
545 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
546 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
547 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
552 static void test_mbsspn( void)
554 unsigned char str1
[]="cabernet";
555 unsigned char str2
[]="shiraz";
556 unsigned char set
[]="abc";
557 unsigned char empty
[]="";
558 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
559 unsigned char mbset1
[]="0123456789 \x94\x4e";
560 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
561 unsigned char mbset3
[]="\x8e";
562 int ret
, cp
= _getmbcp();
564 ret
=_mbsspn( str1
, set
);
565 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
566 ret
=_mbsspn( str2
, set
);
567 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
568 ret
=_mbsspn( str1
, empty
);
569 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
571 ret
=_mbscspn( str1
, set
);
572 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
573 ret
=_mbscspn( str2
, set
);
574 ok( ret
==4, "_mbscspn returns %d should be 4\n", ret
);
575 ret
=_mbscspn( str1
, empty
);
576 ok( ret
==8, "_mbscspn returns %d should be 8\n", ret
);
579 ret
=_mbsspn( mbstr
, mbset1
);
580 ok( ret
==8, "_mbsspn returns %d should be 8\n", ret
);
581 ret
=_mbsspn( mbstr
, mbset2
);
582 ok( ret
==1, "_mbsspn returns %d should be 1\n", ret
);
583 ret
=_mbsspn( mbstr
+8, mbset1
);
584 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
585 ret
=_mbsspn( mbstr
+8, mbset2
);
586 ok( ret
==2, "_mbsspn returns %d should be 2\n", ret
);
587 ret
=_mbsspn( mbstr
, mbset3
);
588 ok( ret
==14, "_mbsspn returns %d should be 14\n", ret
);
590 ret
=_mbscspn( mbstr
, mbset1
);
591 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
592 ret
=_mbscspn( mbstr
, mbset2
);
593 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
594 ret
=_mbscspn( mbstr
+8, mbset1
);
595 ok( ret
==2, "_mbscspn returns %d should be 2\n", ret
);
596 ret
=_mbscspn( mbstr
+8, mbset2
);
597 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
598 ret
=_mbscspn( mbstr
, mbset3
);
599 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
604 static void test_mbsspnp( void)
606 unsigned char str1
[]="cabernet";
607 unsigned char str2
[]="shiraz";
608 unsigned char set
[]="abc";
609 unsigned char empty
[]="";
610 unsigned char full
[]="abcenrt";
611 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
612 unsigned char mbset1
[]="0123456789 \x94\x4e";
613 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
617 ret
=_mbsspnp( str1
, set
);
618 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
619 ret
=_mbsspnp( str2
, set
);
620 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
621 ret
=_mbsspnp( str1
, empty
);
622 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
623 ret
=_mbsspnp( str1
, full
);
624 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
627 ret
=_mbsspnp( mbstr
, mbset1
);
628 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
629 ret
=_mbsspnp( mbstr
, mbset2
);
630 ok( ret
==mbstr
+1, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+1);
631 ret
=_mbsspnp( mbstr
+8, mbset1
);
632 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
633 ret
=_mbsspnp( mbstr
+8, mbset2
);
634 ok( ret
==mbstr
+10, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+10);
639 static void test_strdup(void)
643 ok( str
== 0, "strdup returns %s should be 0\n", str
);
647 static void test_strcmp(void)
649 int ret
= p_strcmp( "abc", "abcd" );
650 ok( ret
== -1, "wrong ret %d\n", ret
);
651 ret
= p_strcmp( "", "abc" );
652 ok( ret
== -1, "wrong ret %d\n", ret
);
653 ret
= p_strcmp( "abc", "ab\xa0" );
654 ok( ret
== -1, "wrong ret %d\n", ret
);
655 ret
= p_strcmp( "ab\xb0", "ab\xa0" );
656 ok( ret
== 1, "wrong ret %d\n", ret
);
657 ret
= p_strcmp( "ab\xc2", "ab\xc2" );
658 ok( ret
== 0, "wrong ret %d\n", ret
);
660 ret
= p_strncmp( "abc", "abcd", 3 );
661 ok( ret
== 0, "wrong ret %d\n", ret
);
662 ret
= p_strncmp( "", "abc", 3 );
663 ok( ret
== 0 - 'a' || ret
== -1, "wrong ret %d\n", ret
);
664 ret
= p_strncmp( "abc", "ab\xa0", 4 );
665 ok( ret
== 'c' - 0xa0 || ret
== -1, "wrong ret %d\n", ret
);
666 ret
= p_strncmp( "ab\xb0", "ab\xa0", 3 );
667 ok( ret
== 0xb0 - 0xa0 || ret
== 1, "wrong ret %d\n", ret
);
668 ret
= p_strncmp( "ab\xb0", "ab\xa0", 2 );
669 ok( ret
== 0, "wrong ret %d\n", ret
);
670 ret
= p_strncmp( "ab\xc2", "ab\xc2", 3 );
671 ok( ret
== 0, "wrong ret %d\n", ret
);
672 ret
= p_strncmp( "abc", "abd", 0 );
673 ok( ret
== 0, "wrong ret %d\n", ret
);
674 ret
= p_strncmp( "abc", "abc", 12 );
675 ok( ret
== 0, "wrong ret %d\n", ret
);
678 static void test_strcpy_s(void)
681 const char small
[] = "small";
682 const char big
[] = "atoolongstringforthislittledestination";
687 win_skip("strcpy_s not found\n");
691 memset(dest
, 'X', sizeof(dest
));
692 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
693 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
694 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
695 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
696 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
697 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
699 memset(dest
, 'X', sizeof(dest
));
700 ret
= pstrcpy_s(dest
, 0, big
);
701 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
702 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
703 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
704 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
705 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
706 ret
= pstrcpy_s(dest
, 0, NULL
);
707 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
708 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
709 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
710 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
711 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
713 memset(dest
, 'X', sizeof(dest
));
714 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
715 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
716 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
717 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
718 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
719 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
721 memset(dest
, 'X', sizeof(dest
));
722 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
723 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
724 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
725 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
726 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
727 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
729 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
730 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
732 /* strcpy overlapping buffers test */
733 memset(dest
, 'X', sizeof(dest
));
734 memcpy(dest
+1, small
, sizeof(small
));
735 p_strcpy(dest
, dest
+1);
736 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
737 dest
[4] == 'l' && dest
[5] == '\0' && dest
[6] == '\0' && dest
[7] == 'X',
738 "Unexpected return data from strcpy: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
739 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
742 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
743 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
744 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
745 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
746 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
748 static void test_memcpy_s(void)
750 static char dest
[8], buf
[32];
751 static const char tiny
[] = {'T',0,'I','N','Y',0};
752 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
755 win_skip("memcpy_s not found\n");
760 memset(dest
, 'X', sizeof(dest
));
761 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
762 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
763 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
765 /* Vary source size */
767 memset(dest
, 'X', sizeof(dest
));
768 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
769 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
770 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
771 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
773 /* Replace source with NULL */
775 memset(dest
, 'X', sizeof(dest
));
776 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
777 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
778 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
779 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
783 memset(dest
, 'X', sizeof(dest
));
784 ret
= p_memcpy_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
785 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
786 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
787 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
789 /* Replace dest with NULL */
791 ret
= p_memcpy_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
792 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
793 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
797 memset(dest
, 'X', sizeof(dest
));
798 ret
= p_memcpy_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
799 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
800 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
801 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
803 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), big
, ARRAY_SIZE(big
));
804 ok(!ret
, "memcpy_s returned %d\n", ret
);
805 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
807 ret
= p_memcpy_s(buf
+ 1, ARRAY_SIZE(buf
) - 1, buf
, ARRAY_SIZE(big
));
808 ok(!ret
, "memcpy_s returned %d\n", ret
);
809 ok(!memcmp(buf
+ 1, big
, sizeof(big
)), "unexpected buf\n");
811 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), buf
+ 1, ARRAY_SIZE(big
));
812 ok(!ret
, "memcpy_s returned %d\n", ret
);
813 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
816 static void test_memmove_s(void)
819 static const char tiny
[] = {'T',0,'I','N','Y',0};
820 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
823 win_skip("memmove_s not found\n");
828 memset(dest
, 'X', sizeof(dest
));
829 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
830 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
831 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
834 memcpy(dest
, big
, sizeof(dest
));
835 ret
= p_memmove_s(dest
+1, ARRAY_SIZE(dest
)-1, dest
, ARRAY_SIZE(dest
)-1);
836 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
837 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
839 /* Vary source size */
841 memset(dest
, 'X', sizeof(dest
));
842 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
843 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
844 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
845 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
847 /* Replace source with NULL */
849 memset(dest
, 'X', sizeof(dest
));
850 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
851 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
852 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
853 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
857 memset(dest
, 'X', sizeof(dest
));
858 ret
= p_memmove_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
859 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
860 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
861 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
863 /* Replace dest with NULL */
865 ret
= p_memmove_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
866 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
867 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
871 memset(dest
, 'X', sizeof(dest
));
872 ret
= p_memmove_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
873 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
874 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
875 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
878 static void test_strcat_s(void)
881 const char *small
= "sma";
886 win_skip("strcat_s not found\n");
890 memset(dest
, 'X', sizeof(dest
));
892 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
893 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
894 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
895 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
896 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
897 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
898 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
899 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
900 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
901 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
902 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
903 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
905 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
906 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
907 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
908 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
909 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
910 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
912 memset(dest
, 'X', sizeof(dest
));
916 ret
= pstrcat_s(dest
, 0, small
);
917 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
918 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
919 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
920 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
921 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
923 ret
= pstrcat_s(dest
, 0, NULL
);
924 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
925 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
926 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
927 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
928 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
930 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
931 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
932 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
933 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
934 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
935 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
937 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
938 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
941 static void test__mbscat_s(void)
943 unsigned char dst
[8], src
[4];
945 int prev_cp
= _getmbcp();
949 win_skip("_mbscat_s not found\n");
955 err
= p_mbscat_s(NULL
, sizeof(dst
), src
);
956 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
958 err
= p_mbscat_s(dst
, sizeof(dst
), NULL
);
959 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
962 err
= p_mbscat_s(dst
, 1, src
);
963 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
965 memset(dst
, 'a', sizeof(dst
));
970 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
971 ok(err
== 0, "_mbscat_s returned %d\n", err
);
972 ok(!memcmp(dst
, "aaaaaab", 8), "dst = %s\n", dst
);
974 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
975 ok(err
== ERANGE
, "_mbscat_s returned %d\n", err
);
976 ok(!dst
[0], "dst[0] = %c\n", dst
[0]);
977 ok(dst
[1] == 'a', "dst[1] = %c\n", dst
[1]);
980 /* test invalid str in dst */
987 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
988 ok(err
== 0, "_mbscat_s returned %d\n", err
);
990 /* test invalid str in src */
996 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
997 ok(err
== 0, "_mbscat_s returned %d\n", err
);
999 /* test dst with leading byte on the end of buffer */
1005 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
1006 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
1007 ok(!memcmp(dst
, "aR", 3), "dst = %s\n", dst
);
1009 /* test src with leading byte on the end of buffer */
1015 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
1016 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
1017 ok(!memcmp(dst
, "ab", 3), "dst = %s\n", dst
);
1021 static void test__mbsnbcpy_s(void)
1023 unsigned char dest
[8];
1024 const unsigned char big
[] = "atoolongstringforthislittledestination";
1025 const unsigned char small
[] = "small";
1030 win_skip("_mbsnbcpy_s not found\n");
1034 memset(dest
, 'X', sizeof(dest
));
1035 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
1036 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
1037 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
1038 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
1039 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1040 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1043 memset(dest
, 'X', sizeof(dest
));
1044 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
1045 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
1046 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
1047 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
1048 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1049 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1051 memset(dest
, 'X', sizeof(dest
));
1052 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
1053 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
1054 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
1055 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
1056 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1057 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1059 memset(dest
, 'X', sizeof(dest
));
1060 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
1061 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
1062 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
1063 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
1064 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1065 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1068 static void test__mbscpy_s(void)
1070 const unsigned char src
[] = "source string";
1071 unsigned char dest
[16];
1076 win_skip("_mbscpy_s not found\n");
1080 ret
= p__mbscpy_s(NULL
, 0, src
);
1081 ok(ret
== EINVAL
, "got %d\n", ret
);
1082 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
1083 ok(ret
== EINVAL
, "got %d\n", ret
);
1084 ret
= p__mbscpy_s(dest
, 0, src
);
1085 ok(ret
== EINVAL
, "got %d\n", ret
);
1087 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
1088 ok(ret
== EINVAL
, "got %d\n", ret
);
1089 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
1091 memset(dest
, 'X', sizeof(dest
));
1092 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
1093 ok(!ret
, "got %d\n", ret
);
1094 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
1095 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
1097 memset(dest
, 'X', sizeof(dest
));
1098 ret
= p__mbscpy_s(dest
, 4, src
);
1099 ok(ret
== ERANGE
, "got %d\n", ret
);
1100 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
1101 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
1104 static void test_wcscpy_s(void)
1106 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
1107 static WCHAR szDest
[18];
1108 static WCHAR szDestShort
[8];
1113 win_skip("wcscpy_s not found\n");
1117 /* Test NULL Dest */
1119 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
1120 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
1121 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1123 /* Test NULL Source */
1126 ret
= p_wcscpy_s(szDest
, 18, NULL
);
1127 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1128 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1129 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
1131 /* Test invalid size */
1134 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
1135 /* Later versions changed the return value for this case to EINVAL,
1136 * and don't modify the result if the dest size is 0.
1138 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1139 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1140 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1142 /* Copy same buffer size */
1143 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
1144 ok(ret
== 0, "expected 0 got %d\n", ret
);
1145 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1147 /* dest == source */
1148 ret
= p_wcscpy_s(szDest
, 18, szDest
);
1149 ok(ret
== 0, "expected 0 got %d\n", ret
);
1150 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1152 /* Copy smaller buffer size */
1155 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
1156 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1157 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1158 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1162 win_skip("wcsncpy_s not found\n");
1166 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1167 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
1170 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
1171 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1172 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1175 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
1176 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
1177 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1180 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, ARRAY_SIZE(szLongText
));
1181 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1182 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1184 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1185 ok(ret
== 0, "expected 0 got %d\n", ret
);
1186 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1189 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, ARRAY_SIZE(szLongText
));
1190 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1191 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1194 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
1195 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
1196 ok(szDest
[4] == 0, "szDest[4] not 0\n");
1197 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
1199 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
1200 ok(ret
== 0, "ret = %d\n", ret
);
1202 szDestShort
[0] = '1';
1204 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
1205 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
1206 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
1207 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
1210 static void test__wcsupr_s(void)
1212 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1213 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1214 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
1215 'W', 'E', 'R', 'U', 'P', 'P', 'E',
1217 WCHAR testBuffer
[2*ARRAY_SIZE(mixedString
)];
1222 win_skip("_wcsupr_s not found\n");
1226 /* Test NULL input string and invalid size. */
1228 ret
= p_wcsupr_s(NULL
, 0);
1229 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1230 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1232 /* Test NULL input string and valid size. */
1234 ret
= p_wcsupr_s(NULL
, ARRAY_SIZE(testBuffer
));
1235 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1236 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1238 /* Test empty string with zero size. */
1240 testBuffer
[0] = '\0';
1241 ret
= p_wcsupr_s(testBuffer
, 0);
1242 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1243 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1244 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1246 /* Test empty string with size of one. */
1247 testBuffer
[0] = '\0';
1248 ret
= p_wcsupr_s(testBuffer
, 1);
1249 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1250 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1252 /* Test one-byte buffer with zero size. */
1254 testBuffer
[0] = 'x';
1255 ret
= p_wcsupr_s(testBuffer
, 0);
1256 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1257 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1258 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1260 /* Test one-byte buffer with size of one. */
1262 testBuffer
[0] = 'x';
1263 ret
= p_wcsupr_s(testBuffer
, 1);
1264 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1265 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1266 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1268 /* Test invalid size. */
1269 wcscpy(testBuffer
, mixedString
);
1271 ret
= p_wcsupr_s(testBuffer
, 0);
1272 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1273 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1274 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1276 /* Test normal string uppercasing. */
1277 wcscpy(testBuffer
, mixedString
);
1278 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
));
1279 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1280 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1282 /* Test uppercasing with a shorter buffer size count. */
1283 wcscpy(testBuffer
, mixedString
);
1285 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
) - 1);
1286 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1287 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1288 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1290 /* Test uppercasing with a longer buffer size count. */
1291 wcscpy(testBuffer
, mixedString
);
1292 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(testBuffer
));
1293 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1294 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1297 static void test__wcslwr_s(void)
1299 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1300 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1301 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1302 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1304 WCHAR buffer
[2*ARRAY_SIZE(mixedString
)];
1309 win_skip("_wcslwr_s not found\n");
1313 /* Test NULL input string and invalid size. */
1315 ret
= p_wcslwr_s(NULL
, 0);
1316 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1317 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1319 /* Test NULL input string and valid size. */
1321 ret
= p_wcslwr_s(NULL
, ARRAY_SIZE(buffer
));
1322 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1323 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1325 /* Test empty string with zero size. */
1328 ret
= p_wcslwr_s(buffer
, 0);
1329 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1330 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1331 ok(buffer
[0] == 0, "expected empty string\n");
1333 /* Test empty string with size of one. */
1335 ret
= p_wcslwr_s(buffer
, 1);
1336 ok(ret
== 0, "got %d\n", ret
);
1337 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1339 /* Test one-byte buffer with zero size. */
1342 ret
= p_wcslwr_s(buffer
, 0);
1343 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1344 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1345 ok(buffer
[0] == '\0', "expected empty string\n");
1347 /* Test one-byte buffer with size of one. */
1350 ret
= p_wcslwr_s(buffer
, 1);
1351 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1352 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1353 ok(buffer
[0] == '\0', "expected empty string\n");
1355 /* Test invalid size. */
1356 wcscpy(buffer
, mixedString
);
1358 ret
= p_wcslwr_s(buffer
, 0);
1359 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1360 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1361 ok(buffer
[0] == '\0', "expected empty string\n");
1363 /* Test normal string uppercasing. */
1364 wcscpy(buffer
, mixedString
);
1365 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
));
1366 ok(ret
== 0, "expected 0, got %d\n", ret
);
1367 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1369 /* Test uppercasing with a shorter buffer size count. */
1370 wcscpy(buffer
, mixedString
);
1372 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
) - 1);
1373 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1374 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1375 ok(buffer
[0] == '\0', "expected empty string\n");
1377 /* Test uppercasing with a longer buffer size count. */
1378 wcscpy(buffer
, mixedString
);
1379 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(buffer
));
1380 ok(ret
== 0, "expected 0, got %d\n", ret
);
1381 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1384 static void test_mbcjisjms(void)
1386 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1387 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1388 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1389 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1390 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1391 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1393 int prev_cp
= _getmbcp();
1395 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1398 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1400 unsigned int ret
, exp
;
1401 ret
= _mbcjistojms(jisjms
[j
][0]);
1402 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1403 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1404 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1410 static void test_mbcjmsjis(void)
1412 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1413 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1414 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1415 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1416 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1417 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1418 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1419 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1421 int prev_cp
= _getmbcp();
1423 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1426 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1428 unsigned int ret
, exp
;
1429 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1430 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1431 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1432 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1438 static void test_mbctohira(void)
1440 static const unsigned int mbchira_932
[][2] = {
1441 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1442 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1443 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1444 {0x8396, 0x8396}, {0x8397, 0x8397},
1445 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1447 unsigned int prev_cp
= _getmbcp();
1449 _setmbcp(_MB_CP_SBCS
);
1450 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1452 int ret
, exp
= mbchira_932
[i
][0];
1453 ret
= _mbctohira(mbchira_932
[i
][0]);
1454 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1458 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1460 unsigned int ret
, exp
;
1461 ret
= _mbctohira(mbchira_932
[i
][0]);
1462 exp
= mbchira_932
[i
][1];
1463 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1468 static void test_mbctokata(void)
1470 static const unsigned int mbckata_932
[][2] = {
1471 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1472 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1473 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1474 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1476 unsigned int prev_cp
= _getmbcp();
1478 _setmbcp(_MB_CP_SBCS
);
1479 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1481 int ret
, exp
= mbckata_932
[i
][0];
1482 ret
= _mbctokata(mbckata_932
[i
][0]);
1483 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1487 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1489 unsigned int ret
, exp
;
1490 ret
= _mbctokata(mbckata_932
[i
][0]);
1491 exp
= mbckata_932
[i
][1];
1492 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1497 static void test_mbbtombc(void)
1499 static const unsigned int mbbmbc
[][2] = {
1500 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1501 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1502 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1503 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1504 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1506 int prev_cp
= _getmbcp();
1508 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1511 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1513 unsigned int exp
, ret
;
1514 ret
= _mbbtombc(mbbmbc
[j
][0]);
1515 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1516 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1517 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1523 static void test_mbctombb(void)
1525 static const unsigned int mbcmbb_932
[][2] = {
1526 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1527 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1528 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1529 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1530 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1531 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1532 unsigned int exp
, ret
, i
;
1533 unsigned int prev_cp
= _getmbcp();
1536 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1538 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1539 exp
= mbcmbb_932
[i
][1];
1540 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1545 static void test_ismbckata(void) {
1546 struct katakana_pair
{
1550 static const struct katakana_pair tests
[] = {
1551 {0x8152, FALSE
}, {0x8153, FALSE
}, {0x8154, FALSE
}, {0x8155, FALSE
},
1552 {0x82a0, FALSE
}, {0x833f, FALSE
}, {0x8340, TRUE
}, {0x837e, TRUE
},
1553 {0x837f, FALSE
}, {0x8380, TRUE
}, {0x8396, TRUE
}, {0x8397, FALSE
},
1554 {0xa5, FALSE
}, {0xb0, FALSE
}, {0xdd, FALSE
}
1556 unsigned int prev_cp
= _getmbcp();
1560 _setmbcp(_MB_CP_SBCS
);
1561 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1562 ret
= _ismbckata(tests
[i
].c
);
1563 ok(!ret
, "expected 0, got %d for %04x\n", ret
, tests
[i
].c
);
1567 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1568 ret
= _ismbckata(tests
[i
].c
);
1569 ok(!!ret
== tests
[i
].exp
, "expected %d, got %d for %04x\n",
1570 tests
[i
].exp
, !!ret
, tests
[i
].c
);
1576 static void test_ismbclegal(void) {
1577 unsigned int prev_cp
= _getmbcp();
1581 _setmbcp(932); /* Japanese */
1583 for(i
= 0; i
< 0x10000; i
++) {
1584 ret
= _ismbclegal(i
);
1585 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1586 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1587 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1588 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1594 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1595 _setmbcp(936); /* Chinese (GBK) */
1597 for(i
= 0; i
< 0x10000; i
++) {
1598 ret
= _ismbclegal(i
);
1599 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1600 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1606 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1607 _setmbcp(949); /* Korean */
1609 for(i
= 0; i
< 0x10000; i
++) {
1610 ret
= _ismbclegal(i
);
1611 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1612 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1618 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1619 _setmbcp(950); /* Chinese (Big5) */
1621 for(i
= 0; i
< 0x10000; i
++) {
1622 ret
= _ismbclegal(i
);
1623 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1624 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1625 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1631 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1632 _setmbcp(1361); /* Korean (Johab) */
1634 for(i
= 0; i
< 0x10000; i
++) {
1635 ret
= _ismbclegal(i
);
1636 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1637 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1638 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1639 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1646 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1651 static const struct {
1653 const char* delimiter
;
1654 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1656 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1658 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1660 } testcases_strtok
[] = {
1661 { "red cabernet", " ", 0, 4, -1 },
1662 { "sparkling white riesling", " ", 0, 10, 16 },
1663 { " pale cream sherry", "e ", 1, 6, 9 },
1668 static void test_strtok(void)
1673 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1674 strcpy( teststr
, testcases_strtok
[i
].string
);
1675 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1676 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1677 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1678 "string (%p) \'%s\' return %p\n",
1679 teststr
, testcases_strtok
[i
].string
, strret
);
1680 if( !strret
) continue;
1681 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1682 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1683 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1684 "second call string (%p) \'%s\' return %p\n",
1685 teststr
, testcases_strtok
[i
].string
, strret
);
1686 if( !strret
) continue;
1687 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1688 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1689 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1690 "third call string (%p) \'%s\' return %p\n",
1691 teststr
, testcases_strtok
[i
].string
, strret
);
1695 static void test_strtol(void)
1697 static char neg
[] = "-0x";
1703 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1704 /* errno is modified on W2K8+ */
1706 l
= strtol("-1234", &e
, 0);
1707 ok(l
==-1234, "wrong value %d\n", l
);
1708 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1710 ul
= strtoul("1234", &e
, 0);
1711 ok(ul
==1234, "wrong value %u\n", ul
);
1712 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1715 l
= strtol("2147483647L", &e
, 0);
1716 ok(l
==2147483647, "wrong value %d\n", l
);
1717 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1719 l
= strtol("-2147483648L", &e
, 0);
1720 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1721 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1723 ul
= strtoul("4294967295UL", &e
, 0);
1724 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1725 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1728 l
= strtol("9223372036854775807L", &e
, 0);
1729 ok(l
==2147483647, "wrong value %d\n", l
);
1730 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1732 ul
= strtoul("9223372036854775807L", &e
, 0);
1733 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1734 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1737 ul
= strtoul("-2", NULL
, 0);
1738 ok(ul
== -2, "wrong value %u\n", ul
);
1739 ok(errno
== 0, "wrong errno %d\n", errno
);
1742 ul
= strtoul("-4294967294", NULL
, 0);
1743 ok(ul
== 2, "wrong value %u\n", ul
);
1744 ok(errno
== 0, "wrong errno %d\n", errno
);
1747 ul
= strtoul("-4294967295", NULL
, 0);
1748 ok(ul
==1, "wrong value %u\n", ul
);
1749 ok(errno
== 0, "wrong errno %d\n", errno
);
1752 ul
= strtoul("-4294967296", NULL
, 0);
1753 ok(ul
== 1, "wrong value %u\n", ul
);
1754 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1757 l
= strtol(neg
, &e
, 0);
1758 ok(l
== 0, "wrong value %d\n", l
);
1759 ok(errno
== 0, "wrong errno %d\n", errno
);
1760 ok(e
== neg
, "e = %p, neg = %p\n", e
, neg
);
1763 static void test_strnlen(void)
1765 static const char str
[] = "string";
1769 win_skip("strnlen not found\n");
1773 res
= p_strnlen(str
, 20);
1774 ok(res
== 6, "Returned length = %d\n", (int)res
);
1776 res
= p_strnlen(str
, 3);
1777 ok(res
== 3, "Returned length = %d\n", (int)res
);
1779 res
= p_strnlen(NULL
, 0);
1780 ok(res
== 0, "Returned length = %d\n", (int)res
);
1783 static void test__strtoi64(void)
1785 static const char no1
[] = "31923";
1786 static const char no2
[] = "-213312";
1787 static const char no3
[] = "12aa";
1788 static const char no4
[] = "abc12";
1789 static const char overflow
[] = "99999999999999999999";
1790 static const char neg_overflow
[] = "-99999999999999999999";
1791 static const char hex
[] = "0x123";
1792 static const char oct
[] = "000123";
1793 static const char blanks
[] = " 12 212.31";
1796 unsigned __int64 ures
;
1799 if(!p_strtoi64
|| !p_strtoui64
) {
1800 win_skip("_strtoi64 or _strtoui64 not found\n");
1805 res
= p_strtoi64(no1
, NULL
, 10);
1806 ok(res
== 31923, "res != 31923\n");
1807 res
= p_strtoi64(no2
, NULL
, 10);
1808 ok(res
== -213312, "res != -213312\n");
1809 res
= p_strtoi64(no3
, NULL
, 10);
1810 ok(res
== 12, "res != 12\n");
1811 res
= p_strtoi64(no4
, &endpos
, 10);
1812 ok(res
== 0, "res != 0\n");
1813 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1814 res
= p_strtoi64(hex
, &endpos
, 10);
1815 ok(res
== 0, "res != 0\n");
1816 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1817 res
= p_strtoi64(oct
, &endpos
, 10);
1818 ok(res
== 123, "res != 123\n");
1819 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1820 res
= p_strtoi64(blanks
, &endpos
, 10);
1821 ok(res
== 12, "res != 12\n");
1822 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1823 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1826 res
= p_strtoi64(overflow
, &endpos
, 10);
1827 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1828 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1829 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1832 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1833 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1834 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1835 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1838 res
= p_strtoi64(no1
, &endpos
, 16);
1839 ok(res
== 203043, "res != 203043\n");
1840 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1841 res
= p_strtoi64(no2
, &endpos
, 16);
1842 ok(res
== -2175762, "res != -2175762\n");
1843 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1844 res
= p_strtoi64(no3
, &endpos
, 16);
1845 ok(res
== 4778, "res != 4778\n");
1846 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1847 res
= p_strtoi64(no4
, &endpos
, 16);
1848 ok(res
== 703506, "res != 703506\n");
1849 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1850 res
= p_strtoi64(hex
, &endpos
, 16);
1851 ok(res
== 291, "res != 291\n");
1852 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1853 res
= p_strtoi64(oct
, &endpos
, 16);
1854 ok(res
== 291, "res != 291\n");
1855 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1856 res
= p_strtoi64(blanks
, &endpos
, 16);
1857 ok(res
== 18, "res != 18\n");
1858 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1859 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1862 res
= p_strtoi64(hex
, &endpos
, 36);
1863 ok(res
== 1541019, "res != 1541019\n");
1864 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1865 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1868 res
= p_strtoi64(no1
, &endpos
, 0);
1869 ok(res
== 31923, "res != 31923\n");
1870 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1871 res
= p_strtoi64(no2
, &endpos
, 0);
1872 ok(res
== -213312, "res != -213312\n");
1873 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1874 res
= p_strtoi64(no3
, &endpos
, 10);
1875 ok(res
== 12, "res != 12\n");
1876 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1877 res
= p_strtoi64(no4
, &endpos
, 10);
1878 ok(res
== 0, "res != 0\n");
1879 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1880 res
= p_strtoi64(hex
, &endpos
, 10);
1881 ok(res
== 0, "res != 0\n");
1882 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1883 res
= p_strtoi64(oct
, &endpos
, 10);
1884 ok(res
== 123, "res != 123\n");
1885 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1886 res
= p_strtoi64(blanks
, &endpos
, 10);
1887 ok(res
== 12, "res != 12\n");
1888 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1889 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1892 ures
= p_strtoui64(no1
, &endpos
, 0);
1893 ok(ures
== 31923, "ures != 31923\n");
1894 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1895 ures
= p_strtoui64(no2
, &endpos
, 0);
1896 ok(ures
== -213312, "ures != -213312\n");
1897 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1898 ures
= p_strtoui64(no3
, &endpos
, 10);
1899 ok(ures
== 12, "ures != 12\n");
1900 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1901 ures
= p_strtoui64(no4
, &endpos
, 10);
1902 ok(ures
== 0, "ures != 0\n");
1903 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1904 ures
= p_strtoui64(hex
, &endpos
, 10);
1905 ok(ures
== 0, "ures != 0\n");
1906 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1907 ures
= p_strtoui64(oct
, &endpos
, 10);
1908 ok(ures
== 123, "ures != 123\n");
1909 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1910 ures
= p_strtoui64(blanks
, &endpos
, 10);
1911 ok(ures
== 12, "ures != 12\n");
1912 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1913 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1916 ures
= p_strtoui64(overflow
, &endpos
, 10);
1917 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1918 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1919 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1922 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1923 ok(ures
== 1, "ures != 1\n");
1924 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1925 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1928 static inline BOOL
compare_double(double f
, double g
, unsigned int ulps
)
1930 ULONGLONG x
= *(ULONGLONG
*)&f
;
1931 ULONGLONG y
= *(ULONGLONG
*)&g
;
1936 x
|= ((ULONGLONG
)1)<<63;
1940 y
|= ((ULONGLONG
)1)<<63;
1942 return (x
>y
? x
-y
: y
-x
) <= ulps
;
1945 static void test__strtod(void)
1947 static const struct {
1953 { "12.1", 4, 12.1 },
1954 { "-13.721", 7, -13.721 },
1956 { ".21e12", 6, 210000000000.0 },
1957 { "214353e-3", 9, 214.353 },
1959 { "12.1d2", 6, 12.1e2
},
1962 { "-0.1", 4, -0.1 },
1963 { "0.1281832188491894198128921", 27, 0.1281832188491894198128921 },
1964 { "0.82181281288121", 16, 0.82181281288121 },
1965 { "21921922352523587651128218821", 29, 21921922352523587651128218821.0 },
1966 { "0.1d238", 7, 0.1e238
},
1967 { "0.1D-4736", 9, 0, ERANGE
},
1968 { "3.4028234663852887e38", 21, FLT_MAX
},
1969 { "1.1754943508222875e-38", 22, FLT_MIN
},
1970 { "1.7976931348623158e+308", 23, DBL_MAX
},
1971 { "1.7976931348623159e+308", 23, INFINITY
, ERANGE
},
1972 { "2.2250738585072014e-308", 23, DBL_MIN
},
1973 { "-1.7976931348623158e+308", 24, -DBL_MAX
},
1974 { "-1.7976931348623159e+308", 24, -INFINITY
, ERANGE
},
1981 const char overflow
[] = "1d9999999999999999999";
1987 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
1990 d
= strtod(tests
[i
].str
, &end
);
1991 ok(d
== tests
[i
].ret
, "%d) d = %.16e\n", i
, d
);
1992 ok(end
== tests
[i
].str
+ tests
[i
].len
, "%d) len = %d\n",
1993 i
, (int)(end
- tests
[i
].str
));
1994 ok(errno
== tests
[i
].err
|| (!tests
[i
].err
&& errno
== 0xdeadbeef) /* <= 2003 */,
1995 "%d) errno = %d\n", i
, errno
);
1999 win_skip("_strtod_l not found\n");
2003 d
= strtod(NULL
, NULL
);
2004 ok(d
== 0.0, "d = %.16e\n", d
);
2005 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2008 end
= (char *)0xdeadbeef;
2009 d
= strtod(NULL
, &end
);
2010 ok(d
== 0.0, "d = %.16e\n", d
);
2011 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2012 ok(!end
, "incorrect end ptr %p\n", end
);
2015 d
= p__strtod_l(NULL
, NULL
, NULL
);
2016 ok(d
== 0.0, "d = %.16e\n", d
);
2017 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2020 /* Set locale with non '.' decimal point (',') */
2021 if(!setlocale(LC_ALL
, "Polish")) {
2022 win_skip("system with limited locales\n");
2026 d
= strtod("12.1", NULL
);
2027 ok(d
== 12.0, "d = %.16e\n", d
);
2029 d
= strtod("12,1", NULL
);
2030 ok(d
== 12.1, "d = %.16e\n", d
);
2032 setlocale(LC_ALL
, "C");
2035 strtod(overflow
, &end
);
2036 ok(errno
== ERANGE
, "errno = %x\n", errno
);
2037 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
2040 strtod("-1d309", NULL
);
2041 ok(errno
== ERANGE
, "errno = %x\n", errno
);
2044 static void test_mbstowcs(void)
2046 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
2047 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
2048 static const wchar_t wEmpty
[] = { 0 };
2049 static const char mSimple
[] = "text";
2050 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
2051 static const char mEmpty
[] = { 0 };
2053 const wchar_t *pwstr
;
2061 wOut
[4] = '!'; wOut
[5] = '\0';
2062 mOut
[4] = '!'; mOut
[5] = '\0';
2065 /* crashes on some systems */
2067 ret
= mbstowcs(wOut
, NULL
, 4);
2068 ok(ret
== -1, "mbstowcs did not return -1\n");
2069 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2072 ret
= mbstowcs(NULL
, mSimple
, 0);
2073 ok(ret
== 4, "mbstowcs did not return 4\n");
2075 ret
= mbstowcs(wOut
, mSimple
, 4);
2076 ok(ret
== 4, "mbstowcs did not return 4\n");
2077 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2078 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
2080 ret
= mbstowcs(NULL
, mEmpty
, 1);
2081 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2083 ret
= mbstowcs(wOut
, mEmpty
, 1);
2084 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2085 ok(!memcmp(wOut
, wEmpty
, sizeof(wEmpty
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2087 ret
= wcstombs(NULL
, wSimple
, 0);
2088 ok(ret
== 4, "wcstombs did not return 4\n");
2090 ret
= wcstombs(mOut
, wSimple
, 6);
2091 ok(ret
== 4, "wcstombs did not return 4\n");
2092 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2094 ret
= wcstombs(mOut
, wSimple
, 2);
2095 ok(ret
== 2, "wcstombs did not return 2\n");
2096 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2098 ret
= wcstombs(NULL
, wEmpty
, 1);
2099 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2101 ret
= wcstombs(mOut
, wEmpty
, 1);
2102 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2103 ok(!memcmp(mOut
, mEmpty
, sizeof(mEmpty
)), "mOut = %s\n", mOut
);
2105 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
2106 win_skip("Japanese_Japan.932 locale not available\n");
2110 ret
= mbstowcs(wOut
, mHiragana
, 6);
2111 ok(ret
== 2, "mbstowcs did not return 2\n");
2112 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2114 ret
= mbstowcs(wOut
, mEmpty
, 6);
2115 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2116 ok(!memcmp(wOut
, wEmpty
, sizeof(wEmpty
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2119 ret
= mbstowcs(wOut
, mHiragana
+1, 5);
2120 ok(ret
== -1, "mbstowcs did not return -1\n");
2121 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2123 ret
= wcstombs(mOut
, wHiragana
, 6);
2124 ok(ret
== 4, "wcstombs did not return 4\n");
2125 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2127 ret
= wcstombs(mOut
, wEmpty
, 6);
2128 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2129 ok(!memcmp(mOut
, mEmpty
, sizeof(mEmpty
)), "mOut = %s\n", mOut
);
2131 if(!pmbstowcs_s
|| !pwcstombs_s
) {
2132 setlocale(LC_ALL
, "C");
2133 win_skip("mbstowcs_s or wcstombs_s not available\n");
2137 err
= pmbstowcs_s(&ret
, wOut
, 1, mSimple
, _TRUNCATE
);
2138 ok(err
== STRUNCATE
, "err = %d\n", err
);
2139 ok(ret
== 1, "mbstowcs_s did not return 0\n");
2140 ok(!wOut
[0], "wOut[0] = %d\n", wOut
[0]);
2142 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
2143 ok(err
== 0, "err = %d\n", err
);
2144 ok(ret
== 5, "mbstowcs_s did not return 5\n");
2145 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2147 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
2148 ok(err
== 0, "err = %d\n", err
);
2149 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2150 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2152 err
= pmbstowcs_s(&ret
, wOut
, 6, mEmpty
, _TRUNCATE
);
2153 ok(err
== 0, "err = %d\n", err
);
2154 ok(ret
== 1, "mbstowcs_s did not return 1, got %d\n", (int)ret
);
2155 ok(!memcmp(wOut
, wEmpty
, sizeof(wEmpty
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2157 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
2158 ok(err
== 0, "err = %d\n", err
);
2159 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2161 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
2162 ok(err
== 0, "err = %d\n", err
);
2163 ok(ret
== 5, "wcstombs_s did not return 5\n");
2164 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2166 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
2167 ok(err
== 0, "err = %d\n", err
);
2168 ok(ret
== 5, "wcstombs_s did not return 5\n");
2169 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2171 err
= pwcstombs_s(&ret
, mOut
, 6, wEmpty
, _TRUNCATE
);
2172 ok(err
== 0, "err = %d\n", err
);
2173 ok(ret
== 1, "wcstombs_s did not return 1, got %d\n", (int)ret
);
2174 ok(!memcmp(mOut
, mEmpty
, sizeof(mEmpty
)), "mOut = %s\n", mOut
);
2176 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
2177 ok(err
== 0, "err = %d\n", err
);
2178 ok(ret
== 5, "wcstombs_s did not return 5\n");
2181 setlocale(LC_ALL
, "C");
2182 win_skip("wcsrtombs not available\n");
2188 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
2189 ok(ret
== 4, "wcsrtombs did not return 4\n");
2190 ok(err
== 0, "err = %d\n", err
);
2191 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
2192 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
2195 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
2196 ok(ret
== 4, "wcsrtombs did not return 4\n");
2197 ok(pwstr
== NULL
, "pwstr != NULL\n");
2198 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2201 setlocale(LC_ALL
, "C");
2202 win_skip("mbsrtowcs not available\n");
2207 ret
= p_mbsrtowcs(NULL
, &pmbstr
, 6, NULL
);
2208 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2209 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2212 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
2213 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2214 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2215 ok(!pmbstr
, "pmbstr != NULL\n");
2217 state
= mHiragana
[0];
2218 pmbstr
= mHiragana
+1;
2219 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
2220 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2221 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
2222 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
2223 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
2224 ok(!pmbstr
, "pmbstr != NULL\n");
2227 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
2228 ok(ret
== -1, "mbsrtowcs did not return -1\n");
2229 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2231 if(!p_mbsrtowcs_s
) {
2232 setlocale(LC_ALL
, "C");
2233 win_skip("mbsrtowcs_s not available\n");
2238 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, NULL
, 6, NULL
);
2239 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2240 ok(err
== EINVAL
, "err = %d\n", err
);
2241 err
= p_mbsrtowcs_s(&ret
, NULL
, 1, &pmbstr
, 6, NULL
);
2242 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2243 ok(err
== EINVAL
, "err = %d\n", err
);
2244 err
= p_mbsrtowcs_s(&ret
, wOut
, 0, &pmbstr
, 6, NULL
);
2245 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2246 ok(err
== EINVAL
, "err = %d\n", err
);
2250 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, &pmbstr
, 6, NULL
);
2251 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2252 ok(err
== 0, "err = %d\n", err
);
2253 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2254 ok(errno
== 0, "errno = %d\n", errno
);
2257 err
= p_mbsrtowcs_s(&ret
, wOut
, 1, &pmbstr
, 6, NULL
);
2258 ok(ret
== 2, "mbsrtowcs_s did not return 2\n");
2259 ok(err
== 0, "err = %d\n", err
);
2260 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2261 ok(pmbstr
== mHiragana
+2, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+2);
2262 ok(errno
== 0, "errno = %d\n", errno
);
2265 err
= p_mbsrtowcs_s(&ret
, wOut
, 2, &pmbstr
, 6, NULL
);
2266 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2267 ok(err
== 0, "err = %d\n", err
);
2268 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2269 ok(pmbstr
== mHiragana
+4, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+4);
2270 ok(errno
== 0, "errno = %d\n", errno
);
2273 err
= p_mbsrtowcs_s(&ret
, wOut
, 3, &pmbstr
, 6, NULL
);
2274 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2275 ok(err
== 0, "err = %d\n", err
);
2276 ok(!pmbstr
, "pmbstr != NULL\n");
2277 ok(errno
== 0, "errno = %d\n", errno
);
2279 setlocale(LC_ALL
, "C");
2282 static void test__wcstombs_s_l(void)
2285 const wchar_t *wstr
;
2293 /* wstr str ret err locale */
2294 { L
"", 0, NULL
, 0, 1, 0, NULL
},
2295 { L
"\xfffd", 1, NULL
, 0, 2, 0, NULL
},
2296 { L
"\xfffd", 1, "", 1, 0, EILSEQ
, NULL
},
2297 { L
"\xfffd", 1, "", 6, 0, EILSEQ
, NULL
},
2298 { L
"text", _TRUNCATE
, "text", 5, 5, 0, NULL
},
2299 { L
"text", _TRUNCATE
, "", 1, 1, STRUNCATE
, NULL
},
2300 { L
"text", 5, "", 3, 0, ERANGE
, NULL
},
2302 { L
"", 0, NULL
, 0, 1, 0, "English_United States.1252" },
2303 { L
"\xfffd", 1, NULL
, 0, 0, EILSEQ
, "English_United States.1252" },
2304 { L
"\xfffd", 1, "", 1, 0, EILSEQ
, "English_United States.1252" },
2305 { L
"\xfffd", 1, "", 6, 0, EILSEQ
, "English_United States.1252" },
2306 { L
"text", _TRUNCATE
, "text", 5, 5, 0, "English_United States.1252" },
2307 { L
"text", _TRUNCATE
, "", 1, 1, STRUNCATE
, "English_United States.1252" },
2308 { L
"text", 5, "", 3, 0, ERANGE
, "English_United States.1252" },
2316 if(!p__create_locale
) {
2317 win_skip("_create_locale not available\n");
2321 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
2325 locale
= p__create_locale(LC_ALL
, tests
[i
].locale
);
2326 ok(locale
!= NULL
, "_create_locale failed for %s\n", tests
[i
].locale
);
2332 memset(out
, 0xcc, sizeof(out
));
2333 err
= p_wcstombs_s_l(&ret
, tests
[i
].str
? out
: NULL
, tests
[i
].len
,
2334 tests
[i
].wstr
, tests
[i
].wlen
, locale
);
2335 ok(ret
== tests
[i
].ret
, "%d: expected ret %d, got %d for '%s' in locale %s\n", i
, tests
[i
].ret
, ret
,
2336 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2337 ok(err
== tests
[i
].err
, "%d: expected err %d, got %d for '%s' in locale %s\n", i
, tests
[i
].err
, err
,
2338 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2340 ok(!memcmp(out
, tests
[i
].str
, strlen(tests
[i
].str
)+1),
2341 "%d: expected out %s, got %s for '%s' in locale %s\n", i
, tests
[i
].str
, out
,
2342 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2344 p__free_locale(locale
);
2348 static void test_gcvt(void)
2350 char buf
[1024], *res
;
2354 win_skip("Skipping _gcvt tests\n");
2359 res
= _gcvt(1.2, -1, buf
);
2360 ok(res
== NULL
, "res != NULL\n");
2361 ok(errno
== ERANGE
, "errno = %d\n", errno
);
2364 res
= _gcvt(1.2, 5, NULL
);
2365 ok(res
== NULL
, "res != NULL\n");
2366 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2368 res
= gcvt(1.2, 5, buf
);
2369 ok(res
== buf
, "res != buf\n");
2370 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
2373 err
= p_gcvt_s(buf
, 5, 1.2, 10);
2374 ok(err
== ERANGE
, "err = %d\n", err
);
2375 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2378 err
= p_gcvt_s(buf
, 4, 123456, 2);
2379 ok(err
== ERANGE
, "err = %d\n", err
);
2380 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2383 static void test__itoa_s(void)
2390 win_skip("Skipping _itoa_s tests\n");
2395 ret
= p_itoa_s(0, NULL
, 0, 0);
2396 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2397 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2399 memset(buffer
, 'X', sizeof(buffer
));
2401 ret
= p_itoa_s(0, buffer
, 0, 0);
2402 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2403 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2404 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2406 memset(buffer
, 'X', sizeof(buffer
));
2408 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
2409 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2410 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2411 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2413 memset(buffer
, 'X', sizeof(buffer
));
2415 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
2416 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2417 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2418 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2420 memset(buffer
, 'X', sizeof(buffer
));
2422 ret
= p_itoa_s(12345678, buffer
, 4, 10);
2423 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2424 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2425 ok(!memcmp(buffer
, "\000765", 4),
2426 "Expected the output buffer to be null terminated with truncated output\n");
2428 memset(buffer
, 'X', sizeof(buffer
));
2430 ret
= p_itoa_s(12345678, buffer
, 8, 10);
2431 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2432 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2433 ok(!memcmp(buffer
, "\0007654321", 8),
2434 "Expected the output buffer to be null terminated with truncated output\n");
2436 memset(buffer
, 'X', sizeof(buffer
));
2438 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
2439 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2440 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2441 ok(!memcmp(buffer
, "\00087654321", 9),
2442 "Expected the output buffer to be null terminated with truncated output\n");
2444 ret
= p_itoa_s(12345678, buffer
, 9, 10);
2445 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2446 ok(!strcmp(buffer
, "12345678"),
2447 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2450 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
2451 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2452 ok(!strcmp(buffer
, "1010101010101010"),
2453 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2456 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
2457 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2458 ok(!strcmp(buffer
, "nell"),
2459 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2462 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
2463 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2464 ok(!strcmp(buffer
, "hag"),
2465 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2468 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
2469 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2470 ok(!strcmp(buffer
, "-12345678"),
2471 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2474 itoa(100, buffer
, 100);
2475 ok(!strcmp(buffer
, "10"),
2476 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
2479 static void test__strlwr_s(void)
2486 win_skip("Skipping _strlwr_s tests\n");
2491 ret
= p_strlwr_s(NULL
, 0);
2492 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2493 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2496 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
2497 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2498 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2501 ret
= p_strlwr_s(buffer
, 0);
2502 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2503 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2505 strcpy(buffer
, "GoRrIsTeR");
2507 ret
= p_strlwr_s(buffer
, 5);
2508 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2509 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2510 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2511 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2513 strcpy(buffer
, "GoRrIsTeR");
2515 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
2516 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2517 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2518 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2519 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2521 strcpy(buffer
, "GoRrIsTeR");
2522 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
2523 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2524 ok(!strcmp(buffer
, "gorrister"),
2525 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2528 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2529 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
2530 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2531 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2532 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2535 ret
= p_strlwr_s((char *)"already_lowercase", sizeof("already_lowercase"));
2536 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2539 static void test_wcsncat_s(void)
2541 static wchar_t abcW
[] = {'a','b','c',0};
2548 win_skip("skipping wcsncat_s tests\n");
2552 memcpy(src
, abcW
, sizeof(abcW
));
2554 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
2555 ok(ret
== EINVAL
, "err = %d\n", ret
);
2556 ret
= p_wcsncat_s(dst
, 0, src
, 4);
2557 ok(ret
== EINVAL
, "err = %d\n", ret
);
2558 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
2559 ok(ret
== EINVAL
, "err = %d\n", ret
);
2560 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
2561 ok(ret
== 0, "err = %d\n", ret
);
2564 ret
= p_wcsncat_s(dst
, 2, src
, 4);
2565 ok(ret
== ERANGE
, "err = %d\n", ret
);
2568 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
2569 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
2570 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2572 memcpy(dst
, abcW
, sizeof(abcW
));
2574 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2575 ok(ret
== EINVAL
, "err = %d\n", ret
);
2578 static void test__mbsnbcat_s(void)
2580 unsigned char dest
[16];
2581 const unsigned char first
[] = "dinosaur";
2582 const unsigned char second
[] = "duck";
2587 win_skip("Skipping _mbsnbcat_s tests\n");
2591 /* Test invalid arguments. */
2592 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2593 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2596 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2597 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2598 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2601 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2602 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2603 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2605 memset(dest
, 'X', sizeof(dest
));
2607 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2608 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2609 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2610 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2612 memset(dest
, 'X', sizeof(dest
));
2614 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2615 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2616 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2617 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2619 memset(dest
, 'X', sizeof(dest
));
2621 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2622 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2623 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2624 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2626 memset(dest
, 'X', sizeof(dest
));
2628 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2629 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2630 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2631 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2633 memset(dest
, 'X', sizeof(dest
));
2635 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2636 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2637 ok(!memcmp(dest
, second
, sizeof(second
)),
2638 "Expected the output buffer string to be \"duck\"\n");
2640 /* Test source truncation behavior. */
2641 memset(dest
, 'X', sizeof(dest
));
2642 memcpy(dest
, first
, sizeof(first
));
2643 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2644 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2645 ok(!memcmp(dest
, first
, sizeof(first
)),
2646 "Expected the output buffer string to be \"dinosaur\"\n");
2648 memset(dest
, 'X', sizeof(dest
));
2649 memcpy(dest
, first
, sizeof(first
));
2650 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2651 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2652 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2653 "Expected the output buffer string to be \"dinosaurduck\"\n");
2655 memset(dest
, 'X', sizeof(dest
));
2656 memcpy(dest
, first
, sizeof(first
));
2657 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2658 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2659 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2660 "Expected the output buffer string to be \"dinosaurduck\"\n");
2662 memset(dest
, 'X', sizeof(dest
));
2663 memcpy(dest
, first
, sizeof(first
));
2664 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2665 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2666 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2667 "Expected the output buffer string to be \"dinosaurduck\"\n");
2669 memset(dest
, 'X', sizeof(dest
));
2670 memcpy(dest
, first
, sizeof(first
));
2671 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2672 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2673 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2674 "Expected the output buffer string to be \"dinosaurduc\"\n");
2676 /* Test destination truncation behavior. */
2677 memset(dest
, 'X', sizeof(dest
));
2678 memcpy(dest
, first
, sizeof(first
));
2680 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2681 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2682 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2683 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2684 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2686 memset(dest
, 'X', sizeof(dest
));
2687 memcpy(dest
, first
, sizeof(first
));
2689 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2690 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2691 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2692 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2693 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2695 memset(dest
, 'X', sizeof(dest
));
2696 memcpy(dest
, first
, sizeof(first
));
2698 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2699 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2700 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2701 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2702 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2705 static void test__mbsupr_s(void)
2708 unsigned char buffer
[20];
2712 win_skip("Skipping _mbsupr_s tests\n");
2717 ret
= p_mbsupr_s(NULL
, 0);
2718 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2721 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2722 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2723 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2726 ret
= p_mbsupr_s(buffer
, 0);
2727 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2728 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2730 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2732 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2733 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2734 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2735 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2738 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2740 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2741 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2742 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2743 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2746 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2748 ret
= p_mbsupr_s(buffer
, 4);
2749 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2750 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2752 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2754 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2755 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2756 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2757 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2762 static void test__mbslwr_s(void)
2765 unsigned char buffer
[20];
2769 win_skip("Skipping _mbslwr_s tests\n");
2774 ret
= p_mbslwr_s(NULL
, 0);
2775 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2778 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2779 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2780 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2783 ret
= p_mbslwr_s(buffer
, 0);
2784 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2785 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2787 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2789 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2790 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2791 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2792 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2795 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2797 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2798 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2799 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2800 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2803 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2805 ret
= p_mbslwr_s(buffer
, 4);
2806 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2807 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2809 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2811 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2812 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2813 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2814 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2818 static void test__mbstok(void)
2820 const unsigned char delim
[] = "t";
2822 char str
[] = "!.!test";
2827 ret
= _mbstok(NULL
, delim
);
2828 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2829 ok(!ret
|| broken((char*)ret
==str
+4),
2830 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2832 ret
= _mbstok(NULL
, delim
);
2833 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2836 static void test__ultoa_s(void)
2843 win_skip("Skipping _ultoa_s tests\n");
2848 ret
= p_ultoa_s(0, NULL
, 0, 0);
2849 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2850 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2852 memset(buffer
, 'X', sizeof(buffer
));
2854 ret
= p_ultoa_s(0, buffer
, 0, 0);
2855 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2856 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2857 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2859 memset(buffer
, 'X', sizeof(buffer
));
2861 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2862 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2863 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2864 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2866 memset(buffer
, 'X', sizeof(buffer
));
2868 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2869 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2870 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2871 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2873 memset(buffer
, 'X', sizeof(buffer
));
2875 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2876 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2877 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2878 ok(!memcmp(buffer
, "\000765", 4),
2879 "Expected the output buffer to be null terminated with truncated output\n");
2881 memset(buffer
, 'X', sizeof(buffer
));
2883 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2884 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2885 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2886 ok(!memcmp(buffer
, "\0007654321", 8),
2887 "Expected the output buffer to be null terminated with truncated output\n");
2889 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2890 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2891 ok(!strcmp(buffer
, "12345678"),
2892 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2895 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2896 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2897 ok(!strcmp(buffer
, "1010101010101010"),
2898 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2901 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2902 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2903 ok(!strcmp(buffer
, "nell"),
2904 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2907 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2908 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2909 ok(!strcmp(buffer
, "hag"),
2910 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2914 static void test_wctob(void)
2916 int ret
, cp
= _getmbcp();
2918 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2919 win_skip("Skipping wctob tests\n");
2923 ret
= p_wctob(0x8141);
2924 ok(ret
== EOF
, "ret = %x\n", ret
);
2926 ret
= p_wctob(0x81);
2927 ok(ret
== EOF
, "ret = %x\n", ret
);
2929 ret
= p_wctob(0xe0);
2930 ok(ret
== 0x61, "ret = %x\n", ret
);
2933 ret
= p_wctob(0x81);
2934 ok(ret
== EOF
, "ret = %x\n", ret
);
2936 setlocale(LC_ALL
, "C");
2937 ret
= p_wctob(0x8141);
2938 ok(ret
== EOF
, "ret = %x\n", ret
);
2940 ret
= p_wctob(0x81);
2941 ok(ret
== (signed char)0x81, "ret = %x\n", ret
);
2943 ret
= p_wctob(0x9f);
2944 ok(ret
== (signed char)0x9f, "ret = %x\n", ret
);
2946 ret
= p_wctob(0xe0);
2947 ok(ret
== (signed char)0xe0, "ret = %x\n", ret
);
2952 static void test_btowc(void)
2955 int cp
= _getmbcp();
2957 if(!p_btowc
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2958 win_skip("Skipping btowc tests\n");
2963 ok(ret
== WEOF
, "ret = %x\n", ret
);
2965 ret
= p_btowc(0x61);
2966 ok(ret
== 0x61, "ret = %x\n", ret
);
2968 ret
= p_btowc(0x81);
2969 ok(ret
== WEOF
, "ret = %x\n", ret
);
2971 ret
= p_btowc(0xe0);
2972 ok(ret
== WEOF
, "ret = %x\n", ret
);
2975 ret
= p_btowc(0x61);
2976 ok(ret
== 0x61, "ret = %x\n", ret
);
2978 ret
= p_btowc(0x81);
2979 ok(ret
== WEOF
, "ret = %x\n", ret
);
2981 ret
= p_btowc(0xe0);
2982 ok(ret
== WEOF
, "ret = %x\n", ret
);
2984 if(!setlocale(LC_CTYPE
, ".1250")) {
2985 win_skip("No codepage 1250 support\n");
2986 setlocale(LC_ALL
, "C");
2991 ret
= p_btowc(0x61);
2992 ok(ret
== 0x61, "ret = %x\n", ret
);
2994 ret
= p_btowc(0x81);
2995 ok(ret
== 0x81, "ret = %x\n", ret
);
2997 ret
= p_btowc(0xe0);
2998 ok(ret
== 0x155, "ret = %x\n", ret
);
3000 ret
= p_btowc(0x100);
3001 ok(ret
== 0x00, "ret = %x\n", ret
);
3003 ret
= p_btowc(0x1e0);
3004 ok(ret
== 0x155, "ret = %x\n", ret
);
3006 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(0x9f);
3014 ok(ret
== 0x9f, "ret = %x\n", ret
);
3016 ret
= p_btowc(0xe0);
3017 ok(ret
== 0xe0, "ret = %x\n", ret
);
3019 ret
= p_btowc(0x100);
3020 ok(ret
== 0x00, "ret = %x\n", ret
);
3022 ret
= p_btowc(0x1e0);
3023 ok(ret
== 0xe0, "ret = %x\n", ret
);
3028 static void test_wctomb(void)
3031 unsigned char dst
[10];
3035 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
3036 win_skip("wcrtomb tests\n");
3040 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
3041 ok(ret
== 2, "wcrtomb did not return 2\n");
3045 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
3046 ok(ret
== 2, "wcrtomb did not return 2\n");
3047 ok(state
== 0, "state != 0\n");
3048 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3049 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3050 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
3052 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
3053 ok(ret
== 2, "wcrtomb did not return 2\n");
3054 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3055 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
3057 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
3058 ok(ret
== 1, "wcrtomb did not return 1\n");
3059 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
3061 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
3062 ok(ret
== -1, "wcrtomb did not return -1\n");
3063 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
3066 win_skip("wcrtomb_s tests\n");
3067 setlocale(LC_ALL
, "C");
3073 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x3042, &state
);
3074 ok(!err
, "err = %d\n", err
);
3075 ok(ret
== 2, "ret != 2\n");
3076 ok(!state
, "state != 0\n");
3077 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3078 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3079 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
3081 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x3042, NULL
);
3082 ok(!err
, "err = %d\n", err
);
3083 ok(ret
== 2, "ret != 2\n");
3084 ok(!state
, "state != 0\n");
3085 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3086 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3088 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x20, NULL
);
3089 ok(!err
, "err = %d\n", err
);
3090 ok(ret
== 1, "ret != 1\n");
3091 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
3093 err
= p_wcrtomb_s(&ret
, NULL
, 0, 0x20, NULL
);
3094 ok(!err
, "err = %d\n", err
);
3095 ok(ret
== 1, "ret != 1\n");
3097 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0xffff, NULL
);
3098 ok(err
== EILSEQ
, "err = %d\n", err
);
3099 ok(ret
== -1, "wcrtomb did not return -1\n");
3100 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
3102 setlocale(LC_ALL
, "C");
3105 static void test_tolower(void)
3111 /* test C locale when locale was never changed */
3112 ret
= p_tolower(0x41);
3113 ok(ret
== 0x61, "ret = %x\n", ret
);
3115 ret
= p_tolower(0xF4);
3116 ok(ret
== 0xF4, "ret = %x\n", ret
);
3119 ret
= p_tolower((char)0xF4);
3120 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
3121 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3124 ret
= p_tolower((char)0xD0);
3125 ok(ret
== (char)0xD0, "ret = %x\n", ret
);
3126 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3128 setlocale(LC_ALL
, "C");
3130 ret
= p_tolower((char)0xF4);
3131 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
3132 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3134 /* test C locale after setting locale */
3135 if(!setlocale(LC_ALL
, "us")) {
3136 win_skip("skipping tolower tests that depends on locale\n");
3139 setlocale(LC_ALL
, "C");
3143 ret
= p_tolower((signed char)ch
);
3144 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
3145 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
3146 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
3149 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
3151 ok(ret
== ch
, "ret = %x\n", ret
);
3152 if(!len
|| ret
==(unsigned char)lch
)
3153 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
3157 ret
= p_tolower((signed char)ch
);
3158 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
3159 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
3160 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
3163 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
3165 ok(ret
== ch
, "ret = %x\n", ret
);
3166 if(!len
|| ret
==(unsigned char)lch
)
3167 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
3169 ret
= p_tolower((unsigned char)0xD0);
3170 ok(ret
== 0xD0, "ret = %x\n", ret
);
3172 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
3174 ret
= p_tolower((signed char)0xD0);
3175 ok(ret
== 0xF0, "ret = %x\n", ret
);
3177 ret
= p_tolower((unsigned char)0xD0);
3178 ok(ret
== 0xF0, "ret = %x\n", ret
);
3180 setlocale(LC_ALL
, "C");
3183 static double mul_pow10(double x
, double exp
)
3185 int fpexcept
= _EM_DENORMAL
|_EM_INVALID
|_EM_ZERODIVIDE
|_EM_OVERFLOW
|_EM_UNDERFLOW
|_EM_INEXACT
;
3186 BOOL negexp
= (exp
< 0);
3192 fpcontrol
= _control87(0, 0);
3193 _control87(fpexcept
, 0xffffffff);
3194 ret
= pow(10.0, exp
);
3195 ret
= (negexp
? x
/ret
: x
*ret
);
3196 _control87(fpcontrol
, 0xffffffff);
3200 static void test__atodbl(void)
3207 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
3208 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
3209 win_skip("_atodbl_l is not available\n");
3214 ret
= p__atodbl_l(&d
, num
, NULL
);
3215 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
3216 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3217 ret
= _atodbl(&d
, num
);
3218 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
3219 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3222 ret
= p__atodbl_l(&d
, num
, NULL
);
3223 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
3224 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3225 ret
= _atodbl(&d
, num
);
3226 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
3227 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3230 ret
= p__atodbl_l(&d
, num
, NULL
);
3231 ok(ret
== 0, "_atodbl_l(&d, \"0\", 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, \"0\") 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, \"123\", NULL) returned %d, expected 0\n", ret
);
3240 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
3241 ret
= _atodbl(&d
, num
);
3242 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
3243 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
3245 /* check over the whole range of (simple) normal doubles */
3246 for (j
= DBL_MIN_10_EXP
; j
<= DBL_MAX_10_EXP
; j
++) {
3247 for (i
= 1; i
<= 9; i
++) {
3248 double expected
= mul_pow10(i
, j
);
3249 if (expected
< DBL_MIN
|| expected
> DBL_MAX
) continue;
3250 snprintf(num
, sizeof(num
), "%de%d", i
, j
);
3251 ret
= _atodbl(&d
, num
);
3252 ok(compare_double(d
.x
, expected
, 2), "d.x = %.16e, expected %.16e\n", d
.x
, expected
);
3256 /* check with denormal doubles */
3257 strcpy(num
, "1e-309");
3258 ret
= p__atodbl_l(&d
, num
, NULL
);
3259 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
3260 ok(compare_double(d
.x
, 1e-309, 1), "d.x = %.16e, expected 0\n", d
.x
);
3261 ret
= _atodbl(&d
, num
);
3262 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
3263 ok(compare_double(d
.x
, 1e-309, 1), "d.x = %.16e, expected 0\n", d
.x
);
3265 strcpy(num
, "1e309");
3266 ret
= p__atodbl_l(&d
, num
, NULL
);
3267 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
3268 ret
= _atodbl(&d
, num
);
3269 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
3272 static void test__stricmp(void)
3276 ret
= _stricmp("test", "test");
3277 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3278 ret
= _stricmp("a", "z");
3279 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3280 ret
= _stricmp("z", "a");
3281 ok(ret
> 0, "_stricmp returned %d\n", ret
);
3282 ret
= _stricmp("\xa5", "\xb9");
3283 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3285 if(!setlocale(LC_ALL
, "polish")) {
3286 win_skip("stricmp tests\n");
3290 ret
= _stricmp("test", "test");
3291 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3292 ret
= _stricmp("a", "z");
3293 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3294 ret
= _stricmp("z", "a");
3295 ok(ret
> 0, "_stricmp returned %d\n", ret
);
3296 ret
= _stricmp("\xa5", "\xb9");
3297 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3298 ret
= _stricmp("a", "\xb9");
3299 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3301 setlocale(LC_ALL
, "C");
3304 static void test__wcstoi64(void)
3306 static const struct { WCHAR str
[24]; __int64 res
; unsigned __int64 ures
; int base
; } tests
[] =
3310 { L
"-1234", -1234, -1234 },
3311 { L
"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
3312 { L
"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
3313 { { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
3314 { { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
3315 { { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
3316 { { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
3317 { { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
3318 { { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
3319 { { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
3320 { { '+',0x0e50,0xff17,'1' }, 071, 071 },
3321 { { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
3322 { L
"4294967295", 4294967295, 4294967295 },
3323 { L
"4294967296", 4294967296, 4294967296 },
3324 { L
"9223372036854775807", 9223372036854775807, 9223372036854775807 },
3325 { L
"9223372036854775808", _I64_MAX
, 9223372036854775808u },
3326 { L
"18446744073709551615", _I64_MAX
, _UI64_MAX
},
3327 { L
"18446744073709551616", _I64_MAX
, _UI64_MAX
},
3328 { L
"-4294967295", -4294967295, -4294967295 },
3329 { L
"-4294967296", -4294967296, -4294967296 },
3330 { L
"-9223372036854775807", -9223372036854775807, -9223372036854775807 },
3331 { L
"-9223372036854775808", _I64_MIN
, 9223372036854775808u },
3332 { L
"-18446744073709551615", _I64_MIN
, 1 },
3333 { L
"-18446744073709551616", _I64_MIN
, 1 },
3335 static const WCHAR zeros
[] = {
3336 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3337 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3342 unsigned __int64 ures
;
3345 if (!p_wcstoi64
|| !p_wcstoui64
) {
3346 win_skip("_wcstoi64 or _wcstoui64 not found\n");
3350 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3352 res
= p_wcstoi64( tests
[i
].str
, &endpos
, tests
[i
].base
);
3353 ok( res
== tests
[i
].res
, "%u: %s res %s\n",
3354 i
, wine_dbgstr_w(tests
[i
].str
), wine_dbgstr_longlong(res
) );
3355 if (!res
) ok( endpos
== tests
[i
].str
, "%u: wrong endpos %p/%p\n", i
, endpos
, tests
[i
].str
);
3356 ures
= p_wcstoui64( tests
[i
].str
, &endpos
, tests
[i
].base
);
3357 ok( ures
== tests
[i
].ures
, "%u: %s res %s\n",
3358 i
, wine_dbgstr_w(tests
[i
].str
), wine_dbgstr_longlong(ures
) );
3361 /* Test various unicode digits */
3362 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3363 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3364 res
= p_wcstoi64(tmp
, NULL
, 0);
3365 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3366 tmp
[1] = zeros
[i
] + 10;
3367 res
= p_wcstoi64(tmp
, NULL
, 16);
3368 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3372 static void test__wcstol(void)
3374 static const struct { WCHAR str
[24]; long res
; unsigned long ures
; int base
; } tests
[] =
3378 { L
"-1234", -1234, -1234 },
3379 { L
"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
3380 { L
"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
3381 { { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
3382 { { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
3383 { { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
3384 { { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
3385 { { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
3386 { { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
3387 { { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
3388 { { '+',0x0e50,0xff17,'1' }, 071, 071 },
3389 { { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
3390 { L
"2147483647", 2147483647, 2147483647 },
3391 { L
"2147483648", LONG_MAX
, 2147483648 },
3392 { L
"4294967295", LONG_MAX
, 4294967295 },
3393 { L
"4294967296", LONG_MAX
, ULONG_MAX
},
3394 { L
"9223372036854775807", LONG_MAX
, ULONG_MAX
},
3395 { L
"-2147483647", -2147483647, -2147483647 },
3396 { L
"-2147483648", LONG_MIN
, LONG_MIN
},
3397 { L
"-4294967295", LONG_MIN
, 1 },
3398 { L
"-4294967296", LONG_MIN
, 1 },
3399 { L
"-9223372036854775807", LONG_MIN
, 1 },
3401 static const WCHAR zeros
[] = {
3402 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3403 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3411 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3413 res
= wcstol( tests
[i
].str
, &endpos
, tests
[i
].base
);
3414 ok( res
== tests
[i
].res
, "%u: %s res %08lx\n",
3415 i
, wine_dbgstr_w(tests
[i
].str
), res
);
3416 if (!res
) ok( endpos
== tests
[i
].str
, "%u: wrong endpos %p/%p\n", i
, endpos
, tests
[i
].str
);
3417 ures
= wcstoul( tests
[i
].str
, &endpos
, tests
[i
].base
);
3418 ok( ures
== tests
[i
].ures
, "%u: %s res %08lx\n",
3419 i
, wine_dbgstr_w(tests
[i
].str
), ures
);
3422 /* Test various unicode digits */
3423 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3424 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3425 res
= wcstol(tmp
, NULL
, 0);
3426 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3427 tmp
[1] = zeros
[i
] + 10;
3428 res
= wcstol(tmp
, NULL
, 16);
3429 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3433 static void test_atoi(void)
3438 ok(r
== 0, "atoi(0) = %d\n", r
);
3441 ok(r
== -1, "atoi(-1) = %d\n", r
);
3444 ok(r
== 1, "atoi(1) = %d\n", r
);
3446 r
= atoi("4294967296");
3447 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
3450 static void test_atol(void)
3455 ok(r
== 0, "atol(0) = %d\n", r
);
3458 ok(r
== -1, "atol(-1) = %d\n", r
);
3461 ok(r
== 1, "atol(1) = %d\n", r
);
3463 r
= atol("4294967296");
3464 ok(r
== 0, "atol(4294967296) = %d\n", r
);
3467 static void test_atof(void)
3472 ok(d
== 0.0, "d = %lf\n", d
);
3475 ok(d
== 1.0, "d = %lf\n", d
);
3478 ok(d
== -1.0, "d = %lf\n", d
);
3482 win_skip("_atof_l not found\n");
3488 ok(d
== 0.0, "d = %lf\n", d
);
3489 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3492 d
= p__atof_l(NULL
, NULL
);
3493 ok(d
== 0.0, "d = %lf\n", d
);
3494 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3497 static void test_strncpy(void)
3499 #define TEST_STRNCPY_LEN 10
3500 /* use function pointer to bypass gcc builtin */
3501 char *(__cdecl
*p_strncpy
)(char*,const char*,size_t);
3503 char dst
[TEST_STRNCPY_LEN
+ 1];
3504 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
3506 p_strncpy
= (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "strncpy");
3508 /* strlen(src) > TEST_STRNCPY_LEN */
3509 ret
= p_strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
3510 ok(ret
== dst
, "ret != dst\n");
3511 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3513 /* without null-terminated */
3514 ret
= p_strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
3515 ok(ret
== dst
, "ret != dst\n");
3516 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3518 /* strlen(src) < TEST_STRNCPY_LEN */
3519 strcpy(dst
, "0123456789");
3520 ret
= p_strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
3521 ok(ret
== dst
, "ret != dst\n");
3522 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
3523 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
3525 /* strlen(src) == TEST_STRNCPY_LEN */
3526 ret
= p_strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
3527 ok(ret
== dst
, "ret != dst\n");
3528 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3531 static void test_strxfrm(void)
3536 /* crashes on old version of msvcrt */
3539 ret
= strxfrm(NULL
, "src", 1);
3540 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3541 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3544 ret
= strxfrm(dest
, NULL
, 100);
3545 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3546 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3549 ret
= strxfrm(NULL
, "src", 0);
3550 ok(ret
== 3, "ret = %d\n", (int)ret
);
3552 ret
= strxfrm(dest
, "src", 0);
3553 ok(ret
== 3, "ret = %d\n", (int)ret
);
3554 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3557 ret
= strxfrm(dest
, "src", 5);
3558 ok(ret
== 3, "ret = %d\n", (int)ret
);
3559 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
3563 ret
= strxfrm(dest
, "src", 1);
3564 ok(ret
== 3, "ret = %d\n", (int)ret
);
3565 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
3566 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
3567 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3569 ret
= strxfrm(dest
, "", 5);
3570 ok(ret
== 0, "ret = %d\n", (int)ret
);
3571 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
3573 if(!setlocale(LC_ALL
, "polish")) {
3574 win_skip("stxfrm tests\n");
3578 ret
= strxfrm(NULL
, "src", 0);
3579 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3581 ret
= strxfrm(dest
, "src", 0);
3582 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3583 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3585 ret
= strxfrm(dest
, "src", ret
+1);
3586 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3587 ok(dest
[0], "dest[0] = 0\n");
3591 ret
= strxfrm(dest
, "src", 5);
3592 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3593 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
3595 setlocale(LC_ALL
, "C");
3598 static void test__strnset_s(void)
3604 win_skip("_strnset_s not available\n");
3608 r
= p__strnset_s(NULL
, 0, 'a', 0);
3609 ok(r
== 0, "r = %d\n", r
);
3611 buf
[0] = buf
[1] = buf
[2] = 'b';
3612 r
= p__strnset_s(buf
, sizeof(buf
), 'a', 2);
3613 ok(r
== 0, "r = %d\n", r
);
3614 ok(!strcmp(buf
, "aab"), "buf = %s\n", buf
);
3616 r
= p__strnset_s(buf
, 0, 'a', 0);
3617 ok(r
== EINVAL
, "r = %d\n", r
);
3619 r
= p__strnset_s(NULL
, 0, 'a', 1);
3620 ok(r
== EINVAL
, "r = %d\n", r
);
3623 r
= p__strnset_s(buf
, sizeof(buf
)-1, 'c', 2);
3624 ok(r
== EINVAL
, "r = %d\n", r
);
3625 ok(!buf
[0] && buf
[1]=='c' && buf
[2]=='b', "buf = %s\n", buf
);
3628 static void test__wcsnset_s(void)
3630 wchar_t text
[] = { 't','e','x','t',0 };
3634 win_skip("_wcsnset_s not available\n");
3638 r
= p__wcsnset_s(NULL
, 0, 'a', 0);
3639 ok(r
== 0, "r = %d\n", r
);
3641 r
= p__wcsnset_s(text
, 0, 'a', 1);
3642 ok(r
== EINVAL
, "r = %d\n", r
);
3643 ok(text
[0] == 't', "text[0] = %d\n", text
[0]);
3645 r
= p__wcsnset_s(NULL
, 2, 'a', 1);
3646 ok(r
== EINVAL
, "r = %d\n", r
);
3648 r
= p__wcsnset_s(text
, 2, 'a', 3);
3649 ok(r
== EINVAL
, "r = %d\n", r
);
3650 ok(text
[0] == 0, "text[0] = %d\n", text
[0]);
3651 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3654 r
= p__wcsnset_s(text
, 5, 'a', 1);
3655 ok(r
== 0, "r = %d\n", r
);
3656 ok(text
[0] == 'a', "text[0] = %d\n", text
[0]);
3657 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3660 r
= p__wcsnset_s(text
, 5, 'b', 3);
3661 ok(r
== 0, "r = %d\n", r
);
3662 ok(text
[0] == 'b', "text[0] = %d\n", text
[0]);
3663 ok(text
[1] == 0, "text[1] = %d\n", text
[1]);
3664 ok(text
[2] == 'x', "text[2] = %d\n", text
[2]);
3667 static void test__wcsset_s(void)
3673 win_skip("_wcsset_s not available\n");
3677 r
= p__wcsset_s(NULL
, 0, 'a');
3678 ok(r
== EINVAL
, "r = %d\n", r
);
3681 r
= p__wcsset_s(str
, 0, 'a');
3682 ok(r
== EINVAL
, "r = %d\n", r
);
3683 ok(str
[0] == 'a', "str[0] = %d\n", str
[0]);
3687 r
= p__wcsset_s(str
, 2, 'c');
3688 ok(r
== EINVAL
, "r = %d\n", r
);
3689 ok(!str
[0], "str[0] = %d\n", str
[0]);
3690 ok(str
[1] == 'b', "str[1] = %d\n", str
[1]);
3695 r
= p__wcsset_s(str
, 3, 'c');
3696 ok(r
== 0, "r = %d\n", r
);
3697 ok(str
[0] == 'c', "str[0] = %d\n", str
[0]);
3698 ok(str
[1] == 0, "str[1] = %d\n", str
[1]);
3699 ok(str
[2] == 'b', "str[2] = %d\n", str
[2]);
3702 static void test__mbscmp(void)
3704 static const unsigned char a
[] = {'a',0}, b
[] = {'b',0};
3709 win_skip("_mbscmp tests\n");
3713 ret
= _mbscmp(NULL
, NULL
);
3714 ok(ret
== INT_MAX
, "got %d\n", ret
);
3716 ret
= _mbscmp(a
, NULL
);
3717 ok(ret
== INT_MAX
, "got %d\n", ret
);
3719 ret
= _mbscmp(NULL
, a
);
3720 ok(ret
== INT_MAX
, "got %d\n", ret
);
3722 ret
= _mbscmp(a
, a
);
3723 ok(!ret
, "got %d\n", ret
);
3725 ret
= _mbscmp(a
, b
);
3726 ok(ret
== -1, "got %d\n", ret
);
3728 ret
= _mbscmp(b
, a
);
3729 ok(ret
== 1, "got %d\n", ret
);
3733 win_skip("_mbscmp_l tests\n");
3737 ret
= p_mbscmp_l(a
, b
, NULL
);
3738 ok(ret
== -1, "got %d\n", ret
);
3741 static void test__ismbclx(void)
3743 int ret
, cp
= _getmbcp();
3746 ok(!ret
, "got %d\n", ret
);
3749 ok(!ret
, "got %d\n", ret
);
3752 ok(!ret
, "got %d\n", ret
);
3756 ret
= _ismbcl0(0x8140);
3757 ok(!ret
, "got %d\n", ret
);
3759 ret
= _ismbcl1(0x889f);
3760 ok(!ret
, "got %d\n", ret
);
3762 ret
= _ismbcl2(0x989f);
3763 ok(!ret
, "got %d\n", ret
);
3768 ok(!ret
, "got %d\n", ret
);
3770 ret
= _ismbcl0(0x8140);
3771 ok(ret
, "got %d\n", ret
);
3773 ret
= _ismbcl0(0x817f);
3774 ok(!ret
, "got %d\n", ret
);
3777 ok(!ret
, "got %d\n", ret
);
3779 ret
= _ismbcl1(0x889f);
3780 ok(ret
, "got %d\n", ret
);
3782 ret
= _ismbcl1(0x88fd);
3783 ok(!ret
, "got %d\n", ret
);
3786 ok(!ret
, "got %d\n", ret
);
3788 ret
= _ismbcl2(0x989f);
3789 ok(ret
, "got %d\n", ret
);
3791 ret
= _ismbcl2(0x993f);
3792 ok(!ret
, "got %d\n", ret
);
3797 static void test__memicmp(void)
3799 static const char *s1
= "abc";
3800 static const char *s2
= "aBd";
3803 ret
= p__memicmp(NULL
, NULL
, 0);
3804 ok(!ret
, "got %d\n", ret
);
3806 ret
= p__memicmp(s1
, s2
, 2);
3807 ok(!ret
, "got %d\n", ret
);
3809 ret
= p__memicmp(s1
, s2
, 3);
3810 ok(ret
== -1, "got %d\n", ret
);
3815 /* Following calls crash on WinXP/W2k3. */
3817 ret
= p__memicmp(NULL
, NULL
, 1);
3818 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3819 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3822 ret
= p__memicmp(s1
, NULL
, 1);
3823 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3824 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3827 ret
= p__memicmp(NULL
, s2
, 1);
3828 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3829 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3832 static void test__memicmp_l(void)
3834 static const char *s1
= "abc";
3835 static const char *s2
= "aBd";
3840 win_skip("_memicmp_l not found.\n");
3845 ret
= p__memicmp_l(NULL
, NULL
, 0, NULL
);
3846 ok(!ret
, "got %d\n", ret
);
3847 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3850 ret
= p__memicmp_l(NULL
, NULL
, 1, NULL
);
3851 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3852 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3855 ret
= p__memicmp_l(s1
, NULL
, 1, NULL
);
3856 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3857 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3860 ret
= p__memicmp_l(NULL
, s2
, 1, NULL
);
3861 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3862 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3865 ret
= p__memicmp_l(s1
, s2
, 2, NULL
);
3866 ok(!ret
, "got %d\n", ret
);
3867 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3870 ret
= p__memicmp_l(s1
, s2
, 3, NULL
);
3871 ok(ret
== -1, "got %d\n", ret
);
3872 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3875 static void test__strupr(void)
3877 const char str
[] = "123";
3878 const char *const_p
;
3883 mem
= VirtualAlloc(NULL
, sizeof(str
), MEM_COMMIT
, PAGE_READWRITE
);
3884 ok(mem
!= NULL
, "VirtualAlloc failed\n");
3885 memcpy(mem
, str
, sizeof(str
));
3886 ok(VirtualProtect(mem
, sizeof(str
), PAGE_READONLY
, &prot
), "VirtualProtect failed\n");
3888 strcpy(str2
, "aBc");
3890 ok(p
== str2
, "_strupr returned %p\n", p
);
3891 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3894 ok(p
== mem
, "_strupr returned %p\n", p
);
3895 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3897 const_p
= "ALREADY_UPPERCASE";
3898 p
= _strupr((char *)const_p
);
3899 ok(p
== const_p
, "_strupr returned %p\n", p
);
3901 if(!setlocale(LC_ALL
, "english")) {
3902 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3903 win_skip("English locale _strupr tests\n");
3907 strcpy(str2
, "aBc");
3909 ok(p
== str2
, "_strupr returned %p\n", p
);
3910 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3912 if (0) /* crashes on Windows */
3915 ok(p
== mem
, "_strupr returned %p\n", p
);
3916 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3919 setlocale(LC_ALL
, "C");
3920 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3923 static void test__tcsncoll(void)
3932 static const struct test tests
[] = {
3933 { "English", "ABCD", "ABCD", 4, 0 },
3934 { "English", "ABCD", "ABCD", 10, 0 },
3936 { "English", "ABC", "ABCD", 3, 0 },
3937 { "English", "ABC", "ABCD", 4, -1 },
3938 { "English", "ABC", "ABCD", 10, -1 },
3940 { "English", "ABCD", "ABC", 3, 0 },
3941 { "English", "ABCD", "ABC", 4, 1 },
3942 { "English", "ABCD", "ABC", 10, 1 },
3944 { "English", "ABCe", "ABCf", 3, 0 },
3945 { "English", "abcd", "ABCD", 10, -1 },
3947 { "C", "ABCD", "ABCD", 4, 0 },
3948 { "C", "ABCD", "ABCD", 10, 0 },
3950 { "C", "ABC", "ABCD", 3, 0 },
3951 { "C", "ABC", "ABCD", 10, -1 },
3953 { "C", "ABCD", "ABC", 3, 0 },
3954 { "C", "ABCD", "ABC", 10, 1 },
3956 { "C", "ABCe", "ABCf", 3, 0 },
3957 { "C", "abcd", "ABCD", 10, 1 },
3966 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3968 if (!setlocale(LC_ALL
, tests
[i
].locale
))
3970 win_skip("%s locale _tcsncoll tests\n", tests
[i
].locale
);
3971 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
3972 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
3976 memset(str1
, 0xee, sizeof(str1
));
3977 strcpy(str1
, tests
[i
].str1
);
3979 memset(str2
, 0xff, sizeof(str2
));
3980 strcpy(str2
, tests
[i
].str2
);
3982 ret
= _strncoll(str1
, str2
, tests
[i
].count
);
3984 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3985 else if (tests
[i
].exp
< 0)
3986 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3988 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3990 memset(str1W
, 0xee, sizeof(str1W
));
3991 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
3994 memset(str2W
, 0xff, sizeof(str2W
));
3995 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
3998 ret
= _wcsncoll(str1W
, str2W
, 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
);
4008 static void test__tcsnicoll(void)
4017 static const struct test tests
[] = {
4018 { "English", "abcd", "ABCD", 4, 0 },
4019 { "English", "abcd", "ABCD", 10, 0 },
4021 { "English", "abc", "ABCD", 3, 0 },
4022 { "English", "abc", "ABCD", 4, -1 },
4023 { "English", "abc", "ABCD", 10, -1 },
4025 { "English", "abcd", "ABC", 3, 0 },
4026 { "English", "abcd", "ABC", 4, 1 },
4027 { "English", "abcd", "ABC", 10, 1 },
4029 { "English", "abcE", "ABCF", 3, 0 },
4031 { "C", "abcd", "ABCD", 4, 0 },
4032 { "C", "abcd", "ABCD", 10, 0 },
4034 { "C", "abc", "ABCD", 3, 0 },
4035 { "C", "abc", "ABCD", 10, -1 },
4037 { "C", "abcd", "ABC", 3, 0 },
4038 { "C", "abcd", "ABC", 10, 1 },
4040 { "C", "abce", "ABCf", 3, 0 },
4049 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4051 if (!setlocale(LC_ALL
, tests
[i
].locale
))
4053 win_skip("%s locale _tcsnicoll tests\n", tests
[i
].locale
);
4054 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
4055 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
4059 memset(str1
, 0xee, sizeof(str1
));
4060 strcpy(str1
, tests
[i
].str1
);
4062 memset(str2
, 0xff, sizeof(str2
));
4063 strcpy(str2
, tests
[i
].str2
);
4065 ret
= _strnicoll(str1
, str2
, tests
[i
].count
);
4067 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4068 else if (tests
[i
].exp
< 0)
4069 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4071 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4073 memset(str1W
, 0xee, sizeof(str1W
));
4074 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
4077 memset(str2W
, 0xff, sizeof(str2W
));
4078 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
4081 ret
= _wcsnicoll(str1W
, str2W
, 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
);
4091 static void test___strncnt(void)
4112 win_skip("__strncnt() is not available.\n");
4116 if (0) /* crashes */
4117 ret
= p___strncnt(NULL
, 1);
4119 for (i
= 0; i
< ARRAY_SIZE(strncnt_tests
); ++i
)
4121 ret
= p___strncnt(strncnt_tests
[i
].str
, strncnt_tests
[i
].size
);
4122 ok(ret
== strncnt_tests
[i
].ret
, "%u: unexpected return value %u.\n", i
, (int)ret
);
4126 static void test_C_locale(void)
4131 static const char *locales
[] = { NULL
, "C" };
4133 /* C locale only converts case for [a-zA-Z] */
4134 setlocale(LC_ALL
, "C");
4135 for (i
= 0; i
<= 0xffff; i
++)
4137 ret
= p_towlower(i
);
4138 if (i
>= 'A' && i
<= 'Z')
4140 exp
= i
+ 'a' - 'A';
4141 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4144 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
4146 ret
= p_towupper(i
);
4147 if (i
>= 'a' && i
<= 'z')
4149 exp
= i
+ 'A' - 'a';
4150 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4153 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
4156 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
4158 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
4162 for (i
= 0; i
< ARRAY_SIZE(locales
); i
++) {
4163 locale
= locales
[i
] ? p__create_locale(LC_ALL
, locales
[i
]) : NULL
;
4165 for (j
= 0; j
<= 0xffff; j
++) {
4166 ret
= p__towlower_l(j
, locale
);
4167 if (j
>= 'A' && j
<= 'Z')
4169 exp
= j
+ 'a' - 'A';
4170 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4173 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
4175 ret
= p__towupper_l(j
, locale
);
4176 if (j
>= 'a' && j
<= 'z')
4178 exp
= j
+ 'A' - 'a';
4179 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4182 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
4185 p__free_locale(locale
);
4189 static void test_strstr(void)
4191 static char long_str
[1024];
4193 const char *haystack
;
4200 { "aabc", "abc", 1 },
4201 { "aaaa", "aaaa", 0 },
4202 { "simple", "simple", 0 },
4203 { "aaaaxaaaaxaaaa", "aaaaa", -1 },
4204 { "aaaaxaaaaxaaaaa", "aaaaa", 10 },
4205 { "abcabcdababcdabcdabde", "abcdabd", 13 },
4206 { "abababababcabababcababbba", "abababcaba", 4 },
4207 { long_str
, long_str
+1, 0 }
4209 const char *r
, *exp
;
4212 memset(long_str
, 'a', sizeof(long_str
)-1);
4214 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
4216 r
= strstr(tests
[i
].haystack
, tests
[i
].needle
);
4217 exp
= tests
[i
].off
== -1 ? NULL
: tests
[i
].haystack
+ tests
[i
].off
;
4218 ok(r
== exp
, "%d) strstr returned %p, expected %p\n", i
, r
, exp
);
4222 static void test_iswdigit(void)
4224 static const struct {
4231 { 0xff16, C1_DIGIT
},
4232 { 0x0660, C1_DIGIT
},
4233 { 0x0ce6, C1_DIGIT
}
4237 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4239 r
= iswdigit(tests
[i
].c
);
4240 ok(r
== tests
[i
].r
, "iswdigit returned %x for %x\n", r
, tests
[i
].c
);
4244 static void test_wcscmp(void)
4248 r
= wcscmp(L
"a", L
"z");
4249 ok(r
== -1, "wcscmp returned %d\n", r
);
4251 r
= wcscmp(L
"z", L
"a");
4252 ok(r
== 1, "wcscmp returned %d\n", r
);
4254 r
= wcscmp(L
"f", L
"f");
4255 ok(!r
, "wcscmp returned %d\n", r
);
4258 static const char* debugstr_ldouble(_LDOUBLE
*v
)
4260 static char buf
[2 * ARRAY_SIZE(v
->ld
) + 1];
4263 for(i
=0; i
<ARRAY_SIZE(v
->ld
); i
++)
4265 buf
[2*i
] = v
->ld
[i
] / 16 + '0';
4266 if(buf
[2*i
] > '9') buf
[2*i
] -= 10 + '0' - 'a';
4267 buf
[2*i
+1] = v
->ld
[i
] % 16 + '0';
4268 if(buf
[2*i
+1] > '9') buf
[2*i
+1] -= 10 + '0' - 'a';
4270 buf
[2 * ARRAY_SIZE(v
->ld
)] = 0;
4274 static void test___STRINGTOLD(void)
4276 static const struct {
4286 { "-0.0", 4, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }} },
4287 { "1e0", 3, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f }} },
4288 { "1.7976931348623158e+308", 23, 0, {{ 0xaf, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x43 }} },
4289 { "1.7976931348623159e+308", 23, 0, {{ 0xb1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x43 }} },
4290 { "3.65e-4951", 10, 0, {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} },
4291 { "1.82e-4951", 10, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}, TRUE
},
4292 { "1e-99999", 8, 1, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} },
4293 { "1.18e+4932", 10, 0, {{ 0x25, 0x75, 0x06, 0x68, 0x8a, 0xf1, 0xe7, 0xfd, 0xfe, 0x7f }} },
4294 { "1.19e+4932", 10, 2, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f }} },
4295 { "1e+99999", 8, 2, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f }} },
4302 for(i
=0; i
<ARRAY_SIZE(tests
); i
++)
4305 r
= __STRINGTOLD(&v
, &endptr
, tests
[i
].str
, 0);
4306 todo_wine_if(tests
[i
].todo
)
4307 ok(r
== tests
[i
].r
, "%d) r = %d\n", i
, r
);
4308 ok(endptr
== tests
[i
].str
+ tests
[i
].endptr
, "%d) endptr = %p, expected %p\n",
4309 i
, endptr
, tests
[i
].str
+tests
[i
].endptr
);
4310 ok(!memcmp(&v
, &tests
[i
].v
, sizeof(v
)), "%d) v = %s\n", i
, debugstr_ldouble(&v
));
4311 ok(errno
== 0xdeadbeef, "%d) errno = %x\n", i
, errno
);
4315 static void test_SpecialCasing(void)
4326 struct test ucases
[] = {
4327 {"English", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
4328 {"English", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
4330 {"Turkish", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
4331 {"Turkish", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
4333 struct test lcases
[] = {
4334 {"English", 'i', 'I'}, /* LATIN SMALL LETTER I */
4335 {"English", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
4337 {"Turkish", 'i', 'I'}, /* LATIN SMALL LETTER I */
4338 {"Turkish", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
4341 for (i
= 0; i
< ARRAY_SIZE(ucases
); i
++) {
4342 if (!setlocale(LC_ALL
, ucases
[i
].lang
)) {
4343 win_skip("skipping special case tests for %s\n", ucases
[i
].lang
);
4347 ret
= p_towlower(ucases
[i
].ch
);
4348 exp
= ucases
[i
].exp
? ucases
[i
].exp
: ucases
[i
].ch
;
4349 ok(ret
== exp
, "expected lowercase %x, got %x for locale %s\n", exp
, ret
, ucases
[i
].lang
);
4352 for (i
= 0; i
< ARRAY_SIZE(lcases
); i
++) {
4353 if (!setlocale(LC_ALL
, lcases
[i
].lang
)) {
4354 win_skip("skipping special case tests for %s\n", lcases
[i
].lang
);
4358 ret
= p_towupper(lcases
[i
].ch
);
4359 exp
= lcases
[i
].exp
? lcases
[i
].exp
: lcases
[i
].ch
;
4360 ok(ret
== exp
, "expected uppercase %x, got %x for locale %s\n", exp
, ret
, lcases
[i
].lang
);
4363 setlocale(LC_ALL
, "C");
4365 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
4367 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
4371 /* test _towlower_l creating locale */
4372 for (i
= 0; i
< ARRAY_SIZE(ucases
); i
++) {
4373 if (!(locale
= p__create_locale(LC_ALL
, ucases
[i
].lang
))) {
4374 win_skip("locale %s not available. skipping\n", ucases
[i
].lang
);
4378 ret
= p__towlower_l(ucases
[i
].ch
, locale
);
4379 exp
= ucases
[i
].exp
? ucases
[i
].exp
: ucases
[i
].ch
;
4380 ok(ret
== exp
, "expected lowercase %x, got %x for locale %s\n", exp
, ret
, ucases
[i
].lang
);
4382 p__free_locale(locale
);
4385 /* test _towupper_l creating locale */
4386 for (i
= 0; i
< ARRAY_SIZE(lcases
); i
++) {
4387 if (!(locale
= p__create_locale(LC_ALL
, lcases
[i
].lang
))) {
4388 win_skip("locale %s not available. skipping\n", lcases
[i
].lang
);
4392 ret
= p__towupper_l(lcases
[i
].ch
, locale
);
4393 exp
= lcases
[i
].exp
? lcases
[i
].exp
: lcases
[i
].ch
;
4394 ok(ret
== exp
, "expected uppercase %x, got %x for locale %s\n", exp
, ret
, lcases
[i
].lang
);
4396 p__free_locale(locale
);
4401 static void test__mbbtype(void)
4403 static const char *test_locales
[] =
4407 "English_Australia",
4415 "Portuguese_Brazil",
4417 "Spanish_Argentina",
4426 for (i
= 0; i
< ARRAY_SIZE(test_locales
); ++i
)
4428 setlocale(LC_ALL
, test_locales
[i
]);
4429 _setmbcp(_MB_CP_LOCALE
);
4430 for (c
= 0; c
< 256; ++c
)
4433 expected
= _MBC_LEAD
;
4434 else if (isprint(c
))
4435 expected
= _MBC_SINGLE
;
4437 expected
= _MBC_ILLEGAL
;
4439 ret
= _mbbtype(c
, 0);
4440 ok(ret
== expected
, "test %u, c %#x, got ret %#x, expected %#x.\n", i
, c
, ret
, expected
);
4443 expected
= _MBC_TRAIL
;
4445 expected
= _MBC_ILLEGAL
;
4447 ret
= _mbbtype(c
, 1);
4448 ok(ret
== expected
, "test %u, c %#x, got ret %#x, expected %#x.\n", i
, c
, ret
, expected
);
4456 static const char xilstring
[]="c:/xilinx";
4459 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
4461 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
4462 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
4463 SET(pmemcpy
,"memcpy");
4464 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
4465 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
4466 SET(pmemcmp
,"memcmp");
4467 SET(p_mbctype
,"_mbctype");
4468 SET(p__mb_cur_max
,"__mb_cur_max");
4469 SET(p_strcpy
, "strcpy");
4470 SET(p_strcmp
, "strcmp");
4471 SET(p_strncmp
, "strncmp");
4472 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
4473 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
4474 p_mbscat_s
= (void*)GetProcAddress( hMsvcrt
, "_mbscat_s" );
4475 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
4476 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
4477 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
4478 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
4479 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
4480 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
4481 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
4482 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
4483 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
4484 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
4485 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
4486 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
4487 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
4488 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
4489 p_wcstombs_s_l
= (void *)GetProcAddress(hMsvcrt
, "_wcstombs_s_l");
4490 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
4491 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
4492 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
4493 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
4494 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
4495 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
4496 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
4497 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
4498 p_btowc
= (void*)GetProcAddress(hMsvcrt
, "btowc");
4499 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
4500 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
4501 p_wcrtomb_s
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb_s");
4502 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
4503 p_towlower
= (void*)GetProcAddress(hMsvcrt
, "towlower");
4504 p__towlower_l
= (void*)GetProcAddress(hMsvcrt
, "_towlower_l");
4505 p_towupper
= (void*)GetProcAddress(hMsvcrt
, "towupper");
4506 p__towupper_l
= (void*)GetProcAddress(hMsvcrt
, "_towupper_l");
4507 p__create_locale
= (void*)GetProcAddress(hMsvcrt
, "_create_locale");
4508 p__free_locale
= (void*)GetProcAddress(hMsvcrt
, "_free_locale");
4509 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
4510 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
4511 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
4512 p_mbsrtowcs_s
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs_s");
4513 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
4514 p__atof_l
= (void*)GetProcAddress(hMsvcrt
, "_atof_l");
4515 p__strtod_l
= (void*)GetProcAddress(hMsvcrt
, "_strtod_l");
4516 p__strnset_s
= (void*)GetProcAddress(hMsvcrt
, "_strnset_s");
4517 p__wcsnset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsnset_s");
4518 p__wcsset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsset_s");
4519 p__mbsnlen
= (void*)GetProcAddress(hMsvcrt
, "_mbsnlen");
4520 p__mbccpy_s
= (void*)GetProcAddress(hMsvcrt
, "_mbccpy_s");
4521 p__memicmp
= (void*)GetProcAddress(hMsvcrt
, "_memicmp");
4522 p__memicmp_l
= (void*)GetProcAddress(hMsvcrt
, "_memicmp_l");
4523 p___strncnt
= (void*)GetProcAddress(hMsvcrt
, "__strncnt");
4524 p_mbsnextc_l
= (void*)GetProcAddress(hMsvcrt
, "_mbsnextc_l");
4525 p_mbscmp_l
= (void*)GetProcAddress(hMsvcrt
, "_mbscmp_l");
4527 /* MSVCRT memcpy behaves like memmove for overlapping moves,
4528 MFC42 CString::Insert seems to rely on that behaviour */
4529 strcpy(mem
,xilstring
);
4530 nLen
=strlen(xilstring
);
4531 pmemcpy(mem
+5, mem
,nLen
+1);
4532 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
4533 "Got result %s\n",mem
+5);
4535 /* run tolower tests first */
4568 test__wcstombs_s_l();
4605 test___STRINGTOLD();
4606 test_SpecialCasing();