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"
33 /* make it use a definition from string.h */
38 static char *buf_to_string(const unsigned char *bin
, int len
, int nr
)
40 static char buf
[2][1024];
44 for (i
= 0; i
< len
; i
++)
46 sprintf(w
, "%02x ", (unsigned char)bin
[i
]);
52 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
53 #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)); }
55 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
56 static int (__cdecl
*p_memcpy_s
)(void *, size_t, const void *, size_t);
57 static int (__cdecl
*p_memmove_s
)(void *, size_t, const void *, size_t);
58 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
59 static int (__cdecl
*p_strcpy
)(char *dst
, const char *src
);
60 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
61 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
62 static int (__cdecl
*p_mbscat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
);
63 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
64 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
65 static int (__cdecl
*p__mbscpy_s
)(unsigned char*, size_t, const unsigned char*);
66 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
67 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
68 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
69 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
70 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
71 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
72 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
73 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
74 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
75 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
76 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
77 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
78 static int (__cdecl
*p_mbsrtowcs_s
)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
79 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
80 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
81 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
82 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
83 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
84 static int *p__mb_cur_max
;
85 static unsigned char *p_mbctype
;
86 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
87 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
88 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
89 static int (__cdecl
*p_wctob
)(wint_t);
90 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
91 static int (__cdecl
*p_tolower
)(int);
92 static int (__cdecl
*p_towlower
)(wint_t);
93 static int (__cdecl
*p__towlower_l
)(wint_t, _locale_t
);
94 static int (__cdecl
*p_towupper
)(wint_t);
95 static int (__cdecl
*p__towupper_l
)(wint_t, _locale_t
);
96 static _locale_t(__cdecl
*p__create_locale
)(int, const char*);
97 static void(__cdecl
*p__free_locale
)(_locale_t
);
98 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
99 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
100 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
101 static double (__cdecl
*p__atof_l
)(const char*,_locale_t
);
102 static double (__cdecl
*p__strtod_l
)(const char *,char**,_locale_t
);
103 static int (__cdecl
*p__strnset_s
)(char*,size_t,int,size_t);
104 static int (__cdecl
*p__wcsnset_s
)(wchar_t*,size_t,wchar_t,size_t);
105 static int (__cdecl
*p__wcsset_s
)(wchar_t*,size_t,wchar_t);
106 static size_t (__cdecl
*p__mbsnlen
)(const unsigned char*, size_t);
107 static int (__cdecl
*p__mbccpy_s
)(unsigned char*, size_t, int*, const unsigned char*);
108 static int (__cdecl
*p__memicmp
)(const char*, const char*, size_t);
109 static int (__cdecl
*p__memicmp_l
)(const char*, const char*, size_t, _locale_t
);
110 static size_t (__cdecl
*p___strncnt
)(const char*, size_t);
112 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
113 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
115 static HMODULE hMsvcrt
;
117 static void test_swab( void ) {
118 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
119 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
120 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
121 char expected3
[] = "$";
128 /* Test 1 - normal even case */
129 memset(to
,'$', sizeof(to
));
130 memset(from
,'@', sizeof(from
));
132 memcpy(from
, original
, testsize
);
133 _swab( from
, to
, testsize
);
134 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
136 /* Test 2 - uneven case */
137 memset(to
,'$', sizeof(to
));
138 memset(from
,'@', sizeof(from
));
140 memcpy(from
, original
, testsize
);
141 _swab( from
, to
, testsize
);
142 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
144 /* Test 3 - from = to */
145 memset(to
,'$', sizeof(to
));
146 memset(from
,'@', sizeof(from
));
148 memcpy(to
, original
, testsize
);
149 _swab( to
, to
, testsize
);
150 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
152 /* Test 4 - 1 bytes */
153 memset(to
,'$', sizeof(to
));
154 memset(from
,'@', sizeof(from
));
156 memcpy(from
, original
, testsize
);
157 _swab( from
, to
, testsize
);
158 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
161 #if 0 /* use this to generate more tests */
163 static void test_codepage(int cp
)
169 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
172 printf("static int result_cp_%d_mbctype[] = { ", cp
);
173 for (i
= 1; i
< 257; i
++)
175 if (p_mbctype
[i
] != prev
)
177 printf("0x%x,%d, ", prev
, count
);
184 printf("0x%x,%d };\n", prev
, count
);
189 /* RLE-encoded mbctype tables for given codepages */
190 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
191 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
192 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
194 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
196 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
197 0x0,2, 0x4,32, 0xc,94, 0,1 };
199 static void test_cp_table(int cp
, int *result
)
205 for (i
= 0; i
< 256; i
++)
213 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
);
218 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
222 static void test_mbcp(void)
224 int mb_orig_max
= *p__mb_cur_max
;
225 int curr_mbcp
= _getmbcp();
226 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
227 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
228 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
229 unsigned char buf
[16];
235 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
236 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
237 * CP1252 (or the ACP?) so we test only a few ASCII characters */
239 expect_eq(p_mbctype
[10], 0, char, "%x");
240 expect_eq(p_mbctype
[50], 0, char, "%x");
241 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
242 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
243 expect_eq(p_mbctype
[128], 0, char, "%x");
245 expect_eq(p_mbctype
[10], 0, char, "%x");
246 expect_eq(p_mbctype
[50], 0, char, "%x");
247 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
248 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
249 expect_eq(p_mbctype
[128], 0, char, "%x");
251 /* double byte code pages */
258 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
);
259 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
260 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
261 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
262 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
263 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
264 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
267 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
268 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
269 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
270 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
271 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
272 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
273 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
274 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
275 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
277 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
278 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
279 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
280 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
283 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
284 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
285 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
286 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
287 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
288 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
289 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
290 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
291 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
293 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
294 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
295 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
296 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
297 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
298 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
301 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
302 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
303 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
304 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
305 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
306 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
307 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
308 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
309 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
311 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
312 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
313 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
314 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
315 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
316 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
319 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
320 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
321 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
323 /* _mbclen/_mbslen */
324 expect_eq(_mbclen(mbstring
), 2, int, "%d");
325 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
326 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
327 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
328 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
329 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
332 win_skip("_mbsnlen tests\n");
334 expect_eq(p__mbsnlen(mbstring
, 8), 8, int, "%d");
335 expect_eq(p__mbsnlen(mbstring
, 9), 4, int, "%d");
336 expect_eq(p__mbsnlen(mbstring
, 10), 4, int, "%d");
337 expect_eq(p__mbsnlen(mbsonlylead
, 0), 0, int, "%d");
338 expect_eq(p__mbsnlen(mbsonlylead
, 1), 1, int, "%d");
339 expect_eq(p__mbsnlen(mbsonlylead
, 2), 0, int, "%d");
340 expect_eq(p__mbsnlen(mbstring2
, 7), 7, int, "%d");
341 expect_eq(p__mbsnlen(mbstring2
, 8), 4, int, "%d");
342 expect_eq(p__mbsnlen(mbstring2
, 9), 4, int, "%d");
346 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
347 win_skip("mbrlen tests\n");
350 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
351 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
352 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
353 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
354 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
355 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
356 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
360 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
361 win_skip("mbrtowc tests\n");
365 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
366 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
367 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
368 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
369 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
370 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
371 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
372 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
373 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
374 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
375 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
376 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
377 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
378 ok(state
== 0, "incorrect state value (%x)\n", state
);
380 setlocale(LC_ALL
, "C");
382 /* _mbccpy/_mbsncpy */
383 memset(buf
, 0xff, sizeof(buf
));
384 _mbccpy(buf
, mbstring
);
385 expect_bin(buf
, "\xb0\xb1\xff", 3);
388 win_skip("_mbccpy_s tests\n");
392 memset(buf
, 0xff, sizeof(buf
));
394 err
= p__mbccpy_s(buf
, 0, &copied
, mbstring
);
395 ok(err
== EINVAL
, "_mbccpy_s returned %d\n", err
);
396 ok(!copied
, "copied = %d\n", copied
);
397 ok(buf
[0] == 0xff, "buf[0] = %x\n", buf
[0]);
399 memset(buf
, 0xff, sizeof(buf
));
401 err
= p__mbccpy_s(buf
, 1, &copied
, mbstring
);
402 ok(err
== ERANGE
, "_mbccpy_s returned %d\n", err
);
403 ok(!copied
, "copied = %d\n", copied
);
404 ok(!buf
[0], "buf[0] = %x\n", buf
[0]);
406 memset(buf
, 0xff, sizeof(buf
));
408 err
= p__mbccpy_s(buf
, 2, &copied
, mbstring
);
409 ok(!err
, "_mbccpy_s returned %d\n", err
);
410 ok(copied
== 2, "copied = %d\n", copied
);
411 expect_bin(buf
, "\xb0\xb1\xff", 3);
413 memset(buf
, 0xff, sizeof(buf
));
415 err
= p__mbccpy_s(buf
, 2, &copied
, (unsigned char *)"\xb0");
416 ok(err
== EILSEQ
, "_mbccpy_s returned %d\n", err
);
417 ok(copied
== 1, "copied = %d\n", copied
);
418 expect_bin(buf
, "\x00\xff", 2);
421 memset(buf
, 0xff, sizeof(buf
));
422 _mbsncpy(buf
, mbstring
, 1);
423 expect_bin(buf
, "\xb0\xb1\xff", 3);
424 memset(buf
, 0xff, sizeof(buf
));
425 _mbsncpy(buf
, mbstring
, 2);
426 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
427 memset(buf
, 0xff, sizeof(buf
));
428 _mbsncpy(buf
, mbstring
, 3);
429 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
430 memset(buf
, 0xff, sizeof(buf
));
431 _mbsncpy(buf
, mbstring
, 4);
432 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
433 memset(buf
, 0xff, sizeof(buf
));
434 _mbsncpy(buf
, mbstring
, 5);
435 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
436 memset(buf
, 0xff, sizeof(buf
));
437 _mbsncpy(buf
, mbsonlylead
, 6);
438 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
440 memset(buf
, 0xff, sizeof(buf
));
441 _mbsnbcpy(buf
, mbstring2
, 2);
442 expect_bin(buf
, "\xb0\xb1\xff", 3);
443 _mbsnbcpy(buf
, mbstring2
, 3);
444 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
445 _mbsnbcpy(buf
, mbstring2
, 4);
446 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
447 memset(buf
, 0xff, sizeof(buf
));
448 _mbsnbcpy(buf
, mbsonlylead
, 5);
449 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
452 step
= _mbsinc(mbstring
) - mbstring
;
453 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
454 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
455 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
457 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
458 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
459 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
460 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
461 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
462 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
463 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
464 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
465 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
466 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
467 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
468 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
469 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
470 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
471 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
472 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
473 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
474 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
476 /* functions that depend on locale codepage, not mbcp.
477 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
478 * (as of Wine 0.9.43)
480 GetCPInfo(GetACP(), &cp_info
);
481 if (cp_info
.MaxCharSize
== 1)
483 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
484 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
487 skip("Current locale has double-byte charset - could lead to false positives\n");
490 expect_eq(_ismbblead(0x80), 0, int, "%d");
492 expect_eq(_ismbblead(0x81), 1, int, "%d");
493 expect_eq(_ismbblead(0x83), 1, int, "%d");
495 expect_eq(_ismbblead(0x84), 1, int, "%d");
496 expect_eq(_ismbblead(0xd3), 1, int, "%d");
497 expect_eq(_ismbblead(0xd7), 0, int, "%d");
498 expect_eq(_ismbblead(0xd8), 1, int, "%d");
499 expect_eq(_ismbblead(0xd9), 1, int, "%d");
501 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
502 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
503 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
504 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
505 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
506 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
507 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
508 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
513 static void test_mbsspn( void)
515 unsigned char str1
[]="cabernet";
516 unsigned char str2
[]="shiraz";
517 unsigned char set
[]="abc";
518 unsigned char empty
[]="";
519 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
520 unsigned char mbset1
[]="0123456789 \x94\x4e";
521 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
522 int ret
, cp
= _getmbcp();
524 ret
=_mbsspn( str1
, set
);
525 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
526 ret
=_mbsspn( str2
, set
);
527 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
528 ret
=_mbsspn( str1
, empty
);
529 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
532 ret
=_mbsspn( mbstr
, mbset1
);
533 ok( ret
==8, "_mbsspn returns %d should be 8\n", ret
);
534 ret
=_mbsspn( mbstr
, mbset2
);
535 ok( ret
==1, "_mbsspn returns %d should be 1\n", ret
);
536 ret
=_mbsspn( mbstr
+8, mbset1
);
537 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
538 ret
=_mbsspn( mbstr
+8, mbset2
);
539 ok( ret
==2, "_mbsspn returns %d should be 2\n", ret
);
544 static void test_mbsspnp( void)
546 unsigned char str1
[]="cabernet";
547 unsigned char str2
[]="shiraz";
548 unsigned char set
[]="abc";
549 unsigned char empty
[]="";
550 unsigned char full
[]="abcenrt";
551 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
552 unsigned char mbset1
[]="0123456789 \x94\x4e";
553 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
557 ret
=_mbsspnp( str1
, set
);
558 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
559 ret
=_mbsspnp( str2
, set
);
560 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
561 ret
=_mbsspnp( str1
, empty
);
562 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
563 ret
=_mbsspnp( str1
, full
);
564 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
567 ret
=_mbsspnp( mbstr
, mbset1
);
568 todo_wine
ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
569 ret
=_mbsspnp( mbstr
, mbset2
);
570 ok( ret
==mbstr
+1, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+1);
571 ret
=_mbsspnp( mbstr
+8, mbset1
);
572 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
573 ret
=_mbsspnp( mbstr
+8, mbset2
);
574 todo_wine
ok( ret
==mbstr
+10, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+10);
579 static void test_strdup(void)
583 ok( str
== 0, "strdup returns %s should be 0\n", str
);
587 static void test_strcpy_s(void)
590 const char small
[] = "small";
591 const char big
[] = "atoolongstringforthislittledestination";
596 win_skip("strcpy_s not found\n");
600 memset(dest
, 'X', sizeof(dest
));
601 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
602 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
603 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
604 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
605 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
606 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
608 memset(dest
, 'X', sizeof(dest
));
609 ret
= pstrcpy_s(dest
, 0, big
);
610 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
611 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
612 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
613 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
614 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
615 ret
= pstrcpy_s(dest
, 0, NULL
);
616 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
617 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
618 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
619 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
620 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
622 memset(dest
, 'X', sizeof(dest
));
623 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
624 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
625 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
626 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
627 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
628 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
630 memset(dest
, 'X', sizeof(dest
));
631 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
632 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
633 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
634 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
635 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
636 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
638 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
639 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
641 /* strcpy overlapping buffers test */
642 memset(dest
, 'X', sizeof(dest
));
643 memcpy(dest
+1, small
, sizeof(small
));
644 p_strcpy(dest
, dest
+1);
645 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
646 dest
[4] == 'l' && dest
[5] == '\0' && dest
[6] == '\0' && dest
[7] == 'X',
647 "Unexpected return data from strcpy: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
648 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
651 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
652 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
653 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
654 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
655 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
657 static void test_memcpy_s(void)
659 static char dest
[8], buf
[32];
660 static const char tiny
[] = {'T',0,'I','N','Y',0};
661 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
664 win_skip("memcpy_s not found\n");
669 memset(dest
, 'X', sizeof(dest
));
670 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
671 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
672 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
674 /* Vary source size */
676 memset(dest
, 'X', sizeof(dest
));
677 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
678 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
679 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
680 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
682 /* Replace source with NULL */
684 memset(dest
, 'X', sizeof(dest
));
685 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
686 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
687 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
688 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
692 memset(dest
, 'X', sizeof(dest
));
693 ret
= p_memcpy_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
694 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
695 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
696 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
698 /* Replace dest with NULL */
700 ret
= p_memcpy_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
701 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
702 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
706 memset(dest
, 'X', sizeof(dest
));
707 ret
= p_memcpy_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
708 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
709 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
710 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
712 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), big
, ARRAY_SIZE(big
));
713 ok(!ret
, "memcpy_s returned %d\n", ret
);
714 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
716 ret
= p_memcpy_s(buf
+ 1, ARRAY_SIZE(buf
) - 1, buf
, ARRAY_SIZE(big
));
717 ok(!ret
, "memcpy_s returned %d\n", ret
);
718 ok(!memcmp(buf
+ 1, big
, sizeof(big
)), "unexpected buf\n");
720 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), buf
+ 1, ARRAY_SIZE(big
));
721 ok(!ret
, "memcpy_s returned %d\n", ret
);
722 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
725 static void test_memmove_s(void)
728 static const char tiny
[] = {'T',0,'I','N','Y',0};
729 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
732 win_skip("memmove_s not found\n");
737 memset(dest
, 'X', sizeof(dest
));
738 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
739 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
740 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
743 memcpy(dest
, big
, sizeof(dest
));
744 ret
= p_memmove_s(dest
+1, ARRAY_SIZE(dest
)-1, dest
, ARRAY_SIZE(dest
)-1);
745 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
746 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
748 /* Vary source size */
750 memset(dest
, 'X', sizeof(dest
));
751 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
752 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
753 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
754 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
756 /* Replace source with NULL */
758 memset(dest
, 'X', sizeof(dest
));
759 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
760 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
761 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
762 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
766 memset(dest
, 'X', sizeof(dest
));
767 ret
= p_memmove_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
768 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
769 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
770 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
772 /* Replace dest with NULL */
774 ret
= p_memmove_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
775 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
776 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
780 memset(dest
, 'X', sizeof(dest
));
781 ret
= p_memmove_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
782 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
783 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
784 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
787 static void test_strcat_s(void)
790 const char *small
= "sma";
795 win_skip("strcat_s not found\n");
799 memset(dest
, 'X', sizeof(dest
));
801 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
802 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
803 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
804 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
805 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
806 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
807 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
808 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
809 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
810 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
811 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
812 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
814 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
815 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
816 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
817 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
818 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
819 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
821 memset(dest
, 'X', sizeof(dest
));
825 ret
= pstrcat_s(dest
, 0, small
);
826 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
827 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
828 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
829 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
830 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
832 ret
= pstrcat_s(dest
, 0, NULL
);
833 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
834 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
835 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
836 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
837 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
839 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
840 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
841 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
842 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
843 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
844 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
846 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
847 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
850 static void test__mbscat_s(void)
852 unsigned char dst
[8], src
[4];
854 int prev_cp
= _getmbcp();
858 win_skip("_mbscat_s not found\n");
864 err
= p_mbscat_s(NULL
, sizeof(dst
), src
);
865 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
867 err
= p_mbscat_s(dst
, sizeof(dst
), NULL
);
868 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
871 err
= p_mbscat_s(dst
, 1, src
);
872 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
874 memset(dst
, 'a', sizeof(dst
));
879 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
880 ok(err
== 0, "_mbscat_s returned %d\n", err
);
881 ok(!memcmp(dst
, "aaaaaab", 8), "dst = %s\n", dst
);
883 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
884 ok(err
== ERANGE
, "_mbscat_s returned %d\n", err
);
885 ok(!dst
[0], "dst[0] = %c\n", dst
[0]);
886 ok(dst
[1] == 'a', "dst[1] = %c\n", dst
[1]);
889 /* test invalid str in dst */
896 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
897 ok(err
== 0, "_mbscat_s returned %d\n", err
);
899 /* test invalid str in src */
905 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
906 ok(err
== 0, "_mbscat_s returned %d\n", err
);
908 /* test dst with leading byte on the end of buffer */
914 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
915 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
916 ok(!memcmp(dst
, "aR", 3), "dst = %s\n", dst
);
918 /* test src with leading byte on the end of buffer */
924 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
925 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
926 ok(!memcmp(dst
, "ab", 3), "dst = %s\n", dst
);
930 static void test__mbsnbcpy_s(void)
932 unsigned char dest
[8];
933 const unsigned char big
[] = "atoolongstringforthislittledestination";
934 const unsigned char small
[] = "small";
939 win_skip("_mbsnbcpy_s not found\n");
943 memset(dest
, 'X', sizeof(dest
));
944 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
945 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
946 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
947 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
948 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
949 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
952 memset(dest
, 'X', sizeof(dest
));
953 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
954 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
955 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
956 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
957 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
958 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
960 memset(dest
, 'X', sizeof(dest
));
961 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
962 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
963 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
964 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
965 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
966 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
968 memset(dest
, 'X', sizeof(dest
));
969 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
970 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
971 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
972 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
973 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
974 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
977 static void test__mbscpy_s(void)
979 const unsigned char src
[] = "source string";
980 unsigned char dest
[16];
985 win_skip("_mbscpy_s not found\n");
989 ret
= p__mbscpy_s(NULL
, 0, src
);
990 ok(ret
== EINVAL
, "got %d\n", ret
);
991 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
992 ok(ret
== EINVAL
, "got %d\n", ret
);
993 ret
= p__mbscpy_s(dest
, 0, src
);
994 ok(ret
== EINVAL
, "got %d\n", ret
);
996 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
997 ok(ret
== EINVAL
, "got %d\n", ret
);
998 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
1000 memset(dest
, 'X', sizeof(dest
));
1001 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
1002 ok(!ret
, "got %d\n", ret
);
1003 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
1004 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
1006 memset(dest
, 'X', sizeof(dest
));
1007 ret
= p__mbscpy_s(dest
, 4, src
);
1008 ok(ret
== ERANGE
, "got %d\n", ret
);
1009 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
1010 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
1013 static void test_wcscpy_s(void)
1015 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
1016 static WCHAR szDest
[18];
1017 static WCHAR szDestShort
[8];
1022 win_skip("wcscpy_s not found\n");
1026 /* Test NULL Dest */
1028 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
1029 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
1030 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1032 /* Test NULL Source */
1035 ret
= p_wcscpy_s(szDest
, 18, NULL
);
1036 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1037 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1038 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
1040 /* Test invalid size */
1043 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
1044 /* Later versions changed the return value for this case to EINVAL,
1045 * and don't modify the result if the dest size is 0.
1047 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1048 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1049 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1051 /* Copy same buffer size */
1052 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
1053 ok(ret
== 0, "expected 0 got %d\n", ret
);
1054 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1056 /* dest == source */
1057 ret
= p_wcscpy_s(szDest
, 18, szDest
);
1058 ok(ret
== 0, "expected 0 got %d\n", ret
);
1059 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1061 /* Copy smaller buffer size */
1064 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
1065 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1066 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1067 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1071 win_skip("wcsncpy_s not found\n");
1075 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1076 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
1079 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
1080 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1081 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1084 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
1085 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
1086 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1089 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, ARRAY_SIZE(szLongText
));
1090 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1091 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1093 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1094 ok(ret
== 0, "expected 0 got %d\n", ret
);
1095 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1098 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, ARRAY_SIZE(szLongText
));
1099 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1100 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1103 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
1104 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
1105 ok(szDest
[4] == 0, "szDest[4] not 0\n");
1106 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
1108 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
1109 ok(ret
== 0, "ret = %d\n", ret
);
1111 szDestShort
[0] = '1';
1113 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
1114 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
1115 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
1116 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
1119 static void test__wcsupr_s(void)
1121 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1122 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1123 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
1124 'W', 'E', 'R', 'U', 'P', 'P', 'E',
1126 WCHAR testBuffer
[2*ARRAY_SIZE(mixedString
)];
1131 win_skip("_wcsupr_s not found\n");
1135 /* Test NULL input string and invalid size. */
1137 ret
= p_wcsupr_s(NULL
, 0);
1138 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1139 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1141 /* Test NULL input string and valid size. */
1143 ret
= p_wcsupr_s(NULL
, ARRAY_SIZE(testBuffer
));
1144 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1145 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1147 /* Test empty string with zero size. */
1149 testBuffer
[0] = '\0';
1150 ret
= p_wcsupr_s(testBuffer
, 0);
1151 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1152 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1153 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1155 /* Test empty string with size of one. */
1156 testBuffer
[0] = '\0';
1157 ret
= p_wcsupr_s(testBuffer
, 1);
1158 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1159 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1161 /* Test one-byte buffer with zero size. */
1163 testBuffer
[0] = 'x';
1164 ret
= p_wcsupr_s(testBuffer
, 0);
1165 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1166 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1167 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1169 /* Test one-byte buffer with size of one. */
1171 testBuffer
[0] = 'x';
1172 ret
= p_wcsupr_s(testBuffer
, 1);
1173 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1174 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1175 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1177 /* Test invalid size. */
1178 wcscpy(testBuffer
, mixedString
);
1180 ret
= p_wcsupr_s(testBuffer
, 0);
1181 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1182 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1183 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1185 /* Test normal string uppercasing. */
1186 wcscpy(testBuffer
, mixedString
);
1187 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
));
1188 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1189 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1191 /* Test uppercasing with a shorter buffer size count. */
1192 wcscpy(testBuffer
, mixedString
);
1194 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
) - 1);
1195 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1196 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1197 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1199 /* Test uppercasing with a longer buffer size count. */
1200 wcscpy(testBuffer
, mixedString
);
1201 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(testBuffer
));
1202 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1203 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1206 static void test__wcslwr_s(void)
1208 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1209 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1210 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1211 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1213 WCHAR buffer
[2*ARRAY_SIZE(mixedString
)];
1218 win_skip("_wcslwr_s not found\n");
1222 /* Test NULL input string and invalid size. */
1224 ret
= p_wcslwr_s(NULL
, 0);
1225 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1226 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1228 /* Test NULL input string and valid size. */
1230 ret
= p_wcslwr_s(NULL
, ARRAY_SIZE(buffer
));
1231 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1232 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1234 /* Test empty string with zero size. */
1237 ret
= p_wcslwr_s(buffer
, 0);
1238 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1239 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1240 ok(buffer
[0] == 0, "expected empty string\n");
1242 /* Test empty string with size of one. */
1244 ret
= p_wcslwr_s(buffer
, 1);
1245 ok(ret
== 0, "got %d\n", ret
);
1246 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1248 /* Test one-byte buffer with zero size. */
1251 ret
= p_wcslwr_s(buffer
, 0);
1252 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1253 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1254 ok(buffer
[0] == '\0', "expected empty string\n");
1256 /* Test one-byte buffer with size of one. */
1259 ret
= p_wcslwr_s(buffer
, 1);
1260 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1261 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1262 ok(buffer
[0] == '\0', "expected empty string\n");
1264 /* Test invalid size. */
1265 wcscpy(buffer
, mixedString
);
1267 ret
= p_wcslwr_s(buffer
, 0);
1268 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1269 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1270 ok(buffer
[0] == '\0', "expected empty string\n");
1272 /* Test normal string uppercasing. */
1273 wcscpy(buffer
, mixedString
);
1274 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
));
1275 ok(ret
== 0, "expected 0, got %d\n", ret
);
1276 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1278 /* Test uppercasing with a shorter buffer size count. */
1279 wcscpy(buffer
, mixedString
);
1281 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
) - 1);
1282 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1283 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1284 ok(buffer
[0] == '\0', "expected empty string\n");
1286 /* Test uppercasing with a longer buffer size count. */
1287 wcscpy(buffer
, mixedString
);
1288 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(buffer
));
1289 ok(ret
== 0, "expected 0, got %d\n", ret
);
1290 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1293 static void test_mbcjisjms(void)
1295 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1296 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1297 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1298 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1299 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1300 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1302 int prev_cp
= _getmbcp();
1304 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1307 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1309 unsigned int ret
, exp
;
1310 ret
= _mbcjistojms(jisjms
[j
][0]);
1311 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1312 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1313 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1319 static void test_mbcjmsjis(void)
1321 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1322 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1323 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1324 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1325 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1326 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1327 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1328 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1330 int prev_cp
= _getmbcp();
1332 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1335 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1337 unsigned int ret
, exp
;
1338 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1339 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1340 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1341 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1347 static void test_mbctohira(void)
1349 static const unsigned int mbchira_932
[][2] = {
1350 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1351 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1352 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1353 {0x8396, 0x8396}, {0x8397, 0x8397},
1354 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1356 unsigned int prev_cp
= _getmbcp();
1358 _setmbcp(_MB_CP_SBCS
);
1359 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1361 int ret
, exp
= mbchira_932
[i
][0];
1362 ret
= _mbctohira(mbchira_932
[i
][0]);
1363 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1367 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1369 unsigned int ret
, exp
;
1370 ret
= _mbctohira(mbchira_932
[i
][0]);
1371 exp
= mbchira_932
[i
][1];
1372 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1377 static void test_mbctokata(void)
1379 static const unsigned int mbckata_932
[][2] = {
1380 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1381 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1382 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1383 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1385 unsigned int prev_cp
= _getmbcp();
1387 _setmbcp(_MB_CP_SBCS
);
1388 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1390 int ret
, exp
= mbckata_932
[i
][0];
1391 ret
= _mbctokata(mbckata_932
[i
][0]);
1392 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1396 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1398 unsigned int ret
, exp
;
1399 ret
= _mbctokata(mbckata_932
[i
][0]);
1400 exp
= mbckata_932
[i
][1];
1401 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1406 static void test_mbbtombc(void)
1408 static const unsigned int mbbmbc
[][2] = {
1409 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1410 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1411 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1412 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1413 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1415 int prev_cp
= _getmbcp();
1417 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1420 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1422 unsigned int exp
, ret
;
1423 ret
= _mbbtombc(mbbmbc
[j
][0]);
1424 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1425 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1426 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1432 static void test_mbctombb(void)
1434 static const unsigned int mbcmbb_932
[][2] = {
1435 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1436 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1437 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1438 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1439 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1440 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1441 unsigned int exp
, ret
, i
;
1442 unsigned int prev_cp
= _getmbcp();
1445 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1447 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1448 exp
= mbcmbb_932
[i
][1];
1449 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1454 static void test_ismbckata(void) {
1455 struct katakana_pair
{
1459 static const struct katakana_pair tests
[] = {
1460 {0x8152, FALSE
}, {0x8153, FALSE
}, {0x8154, FALSE
}, {0x8155, FALSE
},
1461 {0x82a0, FALSE
}, {0x833f, FALSE
}, {0x8340, TRUE
}, {0x837e, TRUE
},
1462 {0x837f, FALSE
}, {0x8380, TRUE
}, {0x8396, TRUE
}, {0x8397, FALSE
},
1463 {0xa5, FALSE
}, {0xb0, FALSE
}, {0xdd, FALSE
}
1465 unsigned int prev_cp
= _getmbcp();
1469 _setmbcp(_MB_CP_SBCS
);
1470 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1471 ret
= _ismbckata(tests
[i
].c
);
1472 ok(!ret
, "expected 0, got %d for %04x\n", ret
, tests
[i
].c
);
1476 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1477 ret
= _ismbckata(tests
[i
].c
);
1478 ok(!!ret
== tests
[i
].exp
, "expected %d, got %d for %04x\n",
1479 tests
[i
].exp
, !!ret
, tests
[i
].c
);
1485 static void test_ismbclegal(void) {
1486 unsigned int prev_cp
= _getmbcp();
1490 _setmbcp(932); /* Japanese */
1492 for(i
= 0; i
< 0x10000; i
++) {
1493 ret
= _ismbclegal(i
);
1494 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1495 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1496 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1497 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1503 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1504 _setmbcp(936); /* Chinese (GBK) */
1506 for(i
= 0; i
< 0x10000; i
++) {
1507 ret
= _ismbclegal(i
);
1508 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1509 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1515 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1516 _setmbcp(949); /* Korean */
1518 for(i
= 0; i
< 0x10000; i
++) {
1519 ret
= _ismbclegal(i
);
1520 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1521 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1527 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1528 _setmbcp(950); /* Chinese (Big5) */
1530 for(i
= 0; i
< 0x10000; i
++) {
1531 ret
= _ismbclegal(i
);
1532 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1533 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1534 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1540 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1541 _setmbcp(1361); /* Korean (Johab) */
1543 for(i
= 0; i
< 0x10000; i
++) {
1544 ret
= _ismbclegal(i
);
1545 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1546 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1547 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1548 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1555 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1560 static const struct {
1562 const char* delimiter
;
1563 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1565 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1567 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1569 } testcases_strtok
[] = {
1570 { "red cabernet", " ", 0, 4, -1 },
1571 { "sparkling white riesling", " ", 0, 10, 16 },
1572 { " pale cream sherry", "e ", 1, 6, 9 },
1577 static void test_strtok(void)
1582 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1583 strcpy( teststr
, testcases_strtok
[i
].string
);
1584 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1585 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1586 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1587 "string (%p) \'%s\' return %p\n",
1588 teststr
, testcases_strtok
[i
].string
, strret
);
1589 if( !strret
) continue;
1590 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1591 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1592 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1593 "second call string (%p) \'%s\' return %p\n",
1594 teststr
, testcases_strtok
[i
].string
, strret
);
1595 if( !strret
) continue;
1596 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1597 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1598 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1599 "third call string (%p) \'%s\' return %p\n",
1600 teststr
, testcases_strtok
[i
].string
, strret
);
1604 static void test_strtol(void)
1606 static char neg
[] = "-0x";
1612 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1613 /* errno is modified on W2K8+ */
1615 l
= strtol("-1234", &e
, 0);
1616 ok(l
==-1234, "wrong value %d\n", l
);
1617 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1619 ul
= strtoul("1234", &e
, 0);
1620 ok(ul
==1234, "wrong value %u\n", ul
);
1621 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1624 l
= strtol("2147483647L", &e
, 0);
1625 ok(l
==2147483647, "wrong value %d\n", l
);
1626 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1628 l
= strtol("-2147483648L", &e
, 0);
1629 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1630 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1632 ul
= strtoul("4294967295UL", &e
, 0);
1633 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1634 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1637 l
= strtol("9223372036854775807L", &e
, 0);
1638 ok(l
==2147483647, "wrong value %d\n", l
);
1639 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1641 ul
= strtoul("9223372036854775807L", &e
, 0);
1642 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1643 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1646 ul
= strtoul("-2", NULL
, 0);
1647 ok(ul
== -2, "wrong value %u\n", ul
);
1648 ok(errno
== 0, "wrong errno %d\n", errno
);
1651 ul
= strtoul("-4294967294", NULL
, 0);
1652 ok(ul
== 2, "wrong value %u\n", ul
);
1653 ok(errno
== 0, "wrong errno %d\n", errno
);
1656 ul
= strtoul("-4294967295", NULL
, 0);
1657 ok(ul
==1, "wrong value %u\n", ul
);
1658 ok(errno
== 0, "wrong errno %d\n", errno
);
1661 ul
= strtoul("-4294967296", NULL
, 0);
1662 ok(ul
== 1, "wrong value %u\n", ul
);
1663 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1666 l
= strtol(neg
, &e
, 0);
1667 ok(l
== 0, "wrong value %d\n", l
);
1668 ok(errno
== 0, "wrong errno %d\n", errno
);
1669 ok(e
== neg
, "e = %p, neg = %p\n", e
, neg
);
1672 static void test_strnlen(void)
1674 static const char str
[] = "string";
1678 win_skip("strnlen not found\n");
1682 res
= p_strnlen(str
, 20);
1683 ok(res
== 6, "Returned length = %d\n", (int)res
);
1685 res
= p_strnlen(str
, 3);
1686 ok(res
== 3, "Returned length = %d\n", (int)res
);
1688 res
= p_strnlen(NULL
, 0);
1689 ok(res
== 0, "Returned length = %d\n", (int)res
);
1692 static void test__strtoi64(void)
1694 static const char no1
[] = "31923";
1695 static const char no2
[] = "-213312";
1696 static const char no3
[] = "12aa";
1697 static const char no4
[] = "abc12";
1698 static const char overflow
[] = "99999999999999999999";
1699 static const char neg_overflow
[] = "-99999999999999999999";
1700 static const char hex
[] = "0x123";
1701 static const char oct
[] = "000123";
1702 static const char blanks
[] = " 12 212.31";
1705 unsigned __int64 ures
;
1708 if(!p_strtoi64
|| !p_strtoui64
) {
1709 win_skip("_strtoi64 or _strtoui64 not found\n");
1714 res
= p_strtoi64(no1
, NULL
, 10);
1715 ok(res
== 31923, "res != 31923\n");
1716 res
= p_strtoi64(no2
, NULL
, 10);
1717 ok(res
== -213312, "res != -213312\n");
1718 res
= p_strtoi64(no3
, NULL
, 10);
1719 ok(res
== 12, "res != 12\n");
1720 res
= p_strtoi64(no4
, &endpos
, 10);
1721 ok(res
== 0, "res != 0\n");
1722 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1723 res
= p_strtoi64(hex
, &endpos
, 10);
1724 ok(res
== 0, "res != 0\n");
1725 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1726 res
= p_strtoi64(oct
, &endpos
, 10);
1727 ok(res
== 123, "res != 123\n");
1728 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1729 res
= p_strtoi64(blanks
, &endpos
, 10);
1730 ok(res
== 12, "res != 12\n");
1731 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1732 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1735 res
= p_strtoi64(overflow
, &endpos
, 10);
1736 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1737 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1738 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1741 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1742 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1743 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1744 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1747 res
= p_strtoi64(no1
, &endpos
, 16);
1748 ok(res
== 203043, "res != 203043\n");
1749 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1750 res
= p_strtoi64(no2
, &endpos
, 16);
1751 ok(res
== -2175762, "res != -2175762\n");
1752 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1753 res
= p_strtoi64(no3
, &endpos
, 16);
1754 ok(res
== 4778, "res != 4778\n");
1755 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1756 res
= p_strtoi64(no4
, &endpos
, 16);
1757 ok(res
== 703506, "res != 703506\n");
1758 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1759 res
= p_strtoi64(hex
, &endpos
, 16);
1760 ok(res
== 291, "res != 291\n");
1761 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1762 res
= p_strtoi64(oct
, &endpos
, 16);
1763 ok(res
== 291, "res != 291\n");
1764 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1765 res
= p_strtoi64(blanks
, &endpos
, 16);
1766 ok(res
== 18, "res != 18\n");
1767 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1768 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1771 res
= p_strtoi64(hex
, &endpos
, 36);
1772 ok(res
== 1541019, "res != 1541019\n");
1773 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1774 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1777 res
= p_strtoi64(no1
, &endpos
, 0);
1778 ok(res
== 31923, "res != 31923\n");
1779 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1780 res
= p_strtoi64(no2
, &endpos
, 0);
1781 ok(res
== -213312, "res != -213312\n");
1782 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1783 res
= p_strtoi64(no3
, &endpos
, 10);
1784 ok(res
== 12, "res != 12\n");
1785 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1786 res
= p_strtoi64(no4
, &endpos
, 10);
1787 ok(res
== 0, "res != 0\n");
1788 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1789 res
= p_strtoi64(hex
, &endpos
, 10);
1790 ok(res
== 0, "res != 0\n");
1791 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1792 res
= p_strtoi64(oct
, &endpos
, 10);
1793 ok(res
== 123, "res != 123\n");
1794 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1795 res
= p_strtoi64(blanks
, &endpos
, 10);
1796 ok(res
== 12, "res != 12\n");
1797 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1798 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1801 ures
= p_strtoui64(no1
, &endpos
, 0);
1802 ok(ures
== 31923, "ures != 31923\n");
1803 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1804 ures
= p_strtoui64(no2
, &endpos
, 0);
1805 ok(ures
== -213312, "ures != -213312\n");
1806 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1807 ures
= p_strtoui64(no3
, &endpos
, 10);
1808 ok(ures
== 12, "ures != 12\n");
1809 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1810 ures
= p_strtoui64(no4
, &endpos
, 10);
1811 ok(ures
== 0, "ures != 0\n");
1812 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1813 ures
= p_strtoui64(hex
, &endpos
, 10);
1814 ok(ures
== 0, "ures != 0\n");
1815 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1816 ures
= p_strtoui64(oct
, &endpos
, 10);
1817 ok(ures
== 123, "ures != 123\n");
1818 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1819 ures
= p_strtoui64(blanks
, &endpos
, 10);
1820 ok(ures
== 12, "ures != 12\n");
1821 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1822 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1825 ures
= p_strtoui64(overflow
, &endpos
, 10);
1826 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1827 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1828 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1831 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1832 ok(ures
== 1, "ures != 1\n");
1833 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1834 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1837 static inline BOOL
almost_equal(double d1
, double d2
) {
1838 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1843 static void test__strtod(void)
1845 const char double1
[] = "12.1";
1846 const char double2
[] = "-13.721";
1847 const char double3
[] = "INF";
1848 const char double4
[] = ".21e12";
1849 const char double5
[] = "214353e-3";
1850 const char double6
[] = "NAN";
1851 const char overflow
[] = "1d9999999999999999999";
1852 const char white_chars
[] = " d10";
1857 d
= strtod(double1
, &end
);
1858 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1859 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1861 d
= strtod(double2
, &end
);
1862 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1863 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1865 d
= strtod(double3
, &end
);
1866 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1867 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1869 d
= strtod(double4
, &end
);
1870 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1871 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1873 d
= strtod(double5
, &end
);
1874 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1875 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1877 d
= strtod(double6
, &end
);
1878 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1879 ok(end
== double6
, "incorrect end (%d)\n", (int)(end
-double6
));
1881 d
= strtod("12.1d2", NULL
);
1882 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1884 d
= strtod(white_chars
, &end
);
1885 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1886 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1889 win_skip("_strtod_l not found\n");
1893 d
= strtod(NULL
, NULL
);
1894 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1895 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1898 end
= (char *)0xdeadbeef;
1899 d
= strtod(NULL
, &end
);
1900 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1901 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1902 ok(!end
, "incorrect end ptr %p\n", end
);
1905 d
= p__strtod_l(NULL
, NULL
, NULL
);
1906 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1907 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1910 /* Set locale with non '.' decimal point (',') */
1911 if(!setlocale(LC_ALL
, "Polish")) {
1912 win_skip("system with limited locales\n");
1916 d
= strtod("12.1", NULL
);
1917 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1919 d
= strtod("12,1", NULL
);
1920 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1922 setlocale(LC_ALL
, "C");
1924 /* Precision tests */
1925 d
= strtod("0.1", NULL
);
1926 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1927 d
= strtod("-0.1", NULL
);
1928 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1929 d
= strtod("0.1281832188491894198128921", NULL
);
1930 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1931 d
= strtod("0.82181281288121", NULL
);
1932 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1933 d
= strtod("21921922352523587651128218821", NULL
);
1934 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1935 d
= strtod("0.1d238", NULL
);
1936 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1937 d
= strtod("0.1D-4736", NULL
);
1938 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1941 strtod(overflow
, &end
);
1942 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1943 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1946 strtod("-1d309", NULL
);
1947 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1950 static void test_mbstowcs(void)
1952 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1953 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1954 static const wchar_t wEmpty
[] = { 0 };
1955 static const char mSimple
[] = "text";
1956 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1957 static const char mEmpty
[] = { 0 };
1959 const wchar_t *pwstr
;
1967 wOut
[4] = '!'; wOut
[5] = '\0';
1968 mOut
[4] = '!'; mOut
[5] = '\0';
1971 /* crashes on some systems */
1973 ret
= mbstowcs(wOut
, NULL
, 4);
1974 ok(ret
== -1, "mbstowcs did not return -1\n");
1975 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1978 ret
= mbstowcs(NULL
, mSimple
, 0);
1979 ok(ret
== 4, "mbstowcs did not return 4\n");
1981 ret
= mbstowcs(wOut
, mSimple
, 4);
1982 ok(ret
== 4, "mbstowcs did not return 4\n");
1983 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1984 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1986 ret
= mbstowcs(NULL
, mEmpty
, 1);
1987 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
1989 ret
= mbstowcs(wOut
, mEmpty
, 1);
1990 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
1991 ok(!memcmp(wOut
, wEmpty
, sizeof(wEmpty
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1993 ret
= wcstombs(NULL
, wSimple
, 0);
1994 ok(ret
== 4, "wcstombs did not return 4\n");
1996 ret
= wcstombs(mOut
, wSimple
, 6);
1997 ok(ret
== 4, "wcstombs did not return 4\n");
1998 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2000 ret
= wcstombs(mOut
, wSimple
, 2);
2001 ok(ret
== 2, "wcstombs did not return 2\n");
2002 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2004 ret
= wcstombs(NULL
, wEmpty
, 1);
2005 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2007 ret
= wcstombs(mOut
, wEmpty
, 1);
2008 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2009 ok(!memcmp(mOut
, mEmpty
, sizeof(mEmpty
)), "mOut = %s\n", mOut
);
2011 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
2012 win_skip("Japanese_Japan.932 locale not available\n");
2016 ret
= mbstowcs(wOut
, mHiragana
, 6);
2017 ok(ret
== 2, "mbstowcs did not return 2\n");
2018 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2020 ret
= mbstowcs(wOut
, mEmpty
, 6);
2021 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2022 ok(!memcmp(wOut
, wEmpty
, sizeof(wEmpty
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2024 ret
= wcstombs(mOut
, wHiragana
, 6);
2025 ok(ret
== 4, "wcstombs did not return 4\n");
2026 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2028 ret
= wcstombs(mOut
, wEmpty
, 6);
2029 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2030 ok(!memcmp(mOut
, mEmpty
, sizeof(mEmpty
)), "mOut = %s\n", mOut
);
2032 if(!pmbstowcs_s
|| !pwcstombs_s
) {
2033 setlocale(LC_ALL
, "C");
2034 win_skip("mbstowcs_s or wcstombs_s not available\n");
2038 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
2039 ok(err
== 0, "err = %d\n", err
);
2040 ok(ret
== 5, "mbstowcs_s did not return 5\n");
2041 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2043 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
2044 ok(err
== 0, "err = %d\n", err
);
2045 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2046 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2048 err
= pmbstowcs_s(&ret
, wOut
, 6, mEmpty
, _TRUNCATE
);
2049 ok(err
== 0, "err = %d\n", err
);
2050 ok(ret
== 1, "mbstowcs_s did not return 1, got %d\n", (int)ret
);
2051 ok(!memcmp(wOut
, wEmpty
, sizeof(wEmpty
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2053 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
2054 ok(err
== 0, "err = %d\n", err
);
2055 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2057 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
2058 ok(err
== 0, "err = %d\n", err
);
2059 ok(ret
== 5, "wcstombs_s did not return 5\n");
2060 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2062 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
2063 ok(err
== 0, "err = %d\n", err
);
2064 ok(ret
== 5, "wcstombs_s did not return 5\n");
2065 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2067 err
= pwcstombs_s(&ret
, mOut
, 6, wEmpty
, _TRUNCATE
);
2068 ok(err
== 0, "err = %d\n", err
);
2069 ok(ret
== 1, "wcstombs_s did not return 1, got %d\n", (int)ret
);
2070 ok(!memcmp(mOut
, mEmpty
, sizeof(mEmpty
)), "mOut = %s\n", mOut
);
2072 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
2073 ok(err
== 0, "err = %d\n", err
);
2074 ok(ret
== 5, "wcstombs_s did not return 5\n");
2077 setlocale(LC_ALL
, "C");
2078 win_skip("wcsrtombs not available\n");
2084 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
2085 ok(ret
== 4, "wcsrtombs did not return 4\n");
2086 ok(err
== 0, "err = %d\n", err
);
2087 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
2088 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
2091 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
2092 ok(ret
== 4, "wcsrtombs did not return 4\n");
2093 ok(pwstr
== NULL
, "pwstr != NULL\n");
2094 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2097 setlocale(LC_ALL
, "C");
2098 win_skip("mbsrtowcs not available\n");
2103 ret
= p_mbsrtowcs(NULL
, &pmbstr
, 6, NULL
);
2104 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2105 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2108 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
2109 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2110 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2111 ok(!pmbstr
, "pmbstr != NULL\n");
2113 state
= mHiragana
[0];
2114 pmbstr
= mHiragana
+1;
2115 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
2116 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2117 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
2118 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
2119 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
2120 ok(!pmbstr
, "pmbstr != NULL\n");
2123 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
2124 ok(ret
== -1, "mbsrtowcs did not return -1\n");
2125 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2127 if(!p_mbsrtowcs_s
) {
2128 setlocale(LC_ALL
, "C");
2129 win_skip("mbsrtowcs_s not available\n");
2134 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, NULL
, 6, NULL
);
2135 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2136 ok(err
== EINVAL
, "err = %d\n", err
);
2137 err
= p_mbsrtowcs_s(&ret
, NULL
, 1, &pmbstr
, 6, NULL
);
2138 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2139 ok(err
== EINVAL
, "err = %d\n", err
);
2140 err
= p_mbsrtowcs_s(&ret
, wOut
, 0, &pmbstr
, 6, NULL
);
2141 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2142 ok(err
== EINVAL
, "err = %d\n", err
);
2146 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, &pmbstr
, 6, NULL
);
2147 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2148 ok(err
== 0, "err = %d\n", err
);
2149 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2150 ok(errno
== 0, "errno = %d\n", errno
);
2153 err
= p_mbsrtowcs_s(&ret
, wOut
, 1, &pmbstr
, 6, NULL
);
2154 ok(ret
== 2, "mbsrtowcs_s did not return 2\n");
2155 ok(err
== 0, "err = %d\n", err
);
2156 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2157 ok(pmbstr
== mHiragana
+2, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+2);
2158 ok(errno
== 0, "errno = %d\n", errno
);
2161 err
= p_mbsrtowcs_s(&ret
, wOut
, 2, &pmbstr
, 6, NULL
);
2162 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2163 ok(err
== 0, "err = %d\n", err
);
2164 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2165 ok(pmbstr
== mHiragana
+4, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+4);
2166 ok(errno
== 0, "errno = %d\n", errno
);
2169 err
= p_mbsrtowcs_s(&ret
, wOut
, 3, &pmbstr
, 6, NULL
);
2170 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2171 ok(err
== 0, "err = %d\n", err
);
2172 ok(!pmbstr
, "pmbstr != NULL\n");
2173 ok(errno
== 0, "errno = %d\n", errno
);
2175 setlocale(LC_ALL
, "C");
2178 static void test_gcvt(void)
2180 char buf
[1024], *res
;
2184 win_skip("Skipping _gcvt tests\n");
2189 res
= _gcvt(1.2, -1, buf
);
2190 ok(res
== NULL
, "res != NULL\n");
2191 ok(errno
== ERANGE
, "errno = %d\n", errno
);
2194 res
= _gcvt(1.2, 5, NULL
);
2195 ok(res
== NULL
, "res != NULL\n");
2196 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2198 res
= gcvt(1.2, 5, buf
);
2199 ok(res
== buf
, "res != buf\n");
2200 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
2203 err
= p_gcvt_s(buf
, 5, 1.2, 10);
2204 ok(err
== ERANGE
, "err = %d\n", err
);
2205 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2208 err
= p_gcvt_s(buf
, 4, 123456, 2);
2209 ok(err
== ERANGE
, "err = %d\n", err
);
2210 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2213 static void test__itoa_s(void)
2220 win_skip("Skipping _itoa_s tests\n");
2225 ret
= p_itoa_s(0, NULL
, 0, 0);
2226 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2227 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2229 memset(buffer
, 'X', sizeof(buffer
));
2231 ret
= p_itoa_s(0, buffer
, 0, 0);
2232 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2233 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2234 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2236 memset(buffer
, 'X', sizeof(buffer
));
2238 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
2239 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2240 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2241 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2243 memset(buffer
, 'X', sizeof(buffer
));
2245 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
2246 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2247 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2248 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2250 memset(buffer
, 'X', sizeof(buffer
));
2252 ret
= p_itoa_s(12345678, buffer
, 4, 10);
2253 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2254 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2255 ok(!memcmp(buffer
, "\000765", 4),
2256 "Expected the output buffer to be null terminated with truncated output\n");
2258 memset(buffer
, 'X', sizeof(buffer
));
2260 ret
= p_itoa_s(12345678, buffer
, 8, 10);
2261 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2262 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2263 ok(!memcmp(buffer
, "\0007654321", 8),
2264 "Expected the output buffer to be null terminated with truncated output\n");
2266 memset(buffer
, 'X', sizeof(buffer
));
2268 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
2269 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2270 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2271 ok(!memcmp(buffer
, "\00087654321", 9),
2272 "Expected the output buffer to be null terminated with truncated output\n");
2274 ret
= p_itoa_s(12345678, buffer
, 9, 10);
2275 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2276 ok(!strcmp(buffer
, "12345678"),
2277 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2280 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
2281 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2282 ok(!strcmp(buffer
, "1010101010101010"),
2283 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2286 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
2287 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2288 ok(!strcmp(buffer
, "nell"),
2289 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2292 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
2293 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2294 ok(!strcmp(buffer
, "hag"),
2295 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2298 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
2299 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2300 ok(!strcmp(buffer
, "-12345678"),
2301 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2304 itoa(100, buffer
, 100);
2305 ok(!strcmp(buffer
, "10"),
2306 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
2309 static void test__strlwr_s(void)
2316 win_skip("Skipping _strlwr_s tests\n");
2321 ret
= p_strlwr_s(NULL
, 0);
2322 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2323 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2326 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
2327 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2328 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2331 ret
= p_strlwr_s(buffer
, 0);
2332 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2333 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2335 strcpy(buffer
, "GoRrIsTeR");
2337 ret
= p_strlwr_s(buffer
, 5);
2338 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2339 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2340 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2341 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2343 strcpy(buffer
, "GoRrIsTeR");
2345 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
2346 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2347 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2348 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2349 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2351 strcpy(buffer
, "GoRrIsTeR");
2352 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
2353 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2354 ok(!strcmp(buffer
, "gorrister"),
2355 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2358 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2359 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
2360 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2361 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2362 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2366 static void test_wcsncat_s(void)
2368 static wchar_t abcW
[] = {'a','b','c',0};
2375 win_skip("skipping wcsncat_s tests\n");
2379 memcpy(src
, abcW
, sizeof(abcW
));
2381 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
2382 ok(ret
== EINVAL
, "err = %d\n", ret
);
2383 ret
= p_wcsncat_s(dst
, 0, src
, 4);
2384 ok(ret
== EINVAL
, "err = %d\n", ret
);
2385 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
2386 ok(ret
== EINVAL
, "err = %d\n", ret
);
2387 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
2388 ok(ret
== 0, "err = %d\n", ret
);
2391 ret
= p_wcsncat_s(dst
, 2, src
, 4);
2392 ok(ret
== ERANGE
, "err = %d\n", ret
);
2395 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
2396 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
2397 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2399 memcpy(dst
, abcW
, sizeof(abcW
));
2401 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2402 ok(ret
== EINVAL
, "err = %d\n", ret
);
2405 static void test__mbsnbcat_s(void)
2407 unsigned char dest
[16];
2408 const unsigned char first
[] = "dinosaur";
2409 const unsigned char second
[] = "duck";
2414 win_skip("Skipping _mbsnbcat_s tests\n");
2418 /* Test invalid arguments. */
2419 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2420 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2423 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2424 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2425 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2428 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2429 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2430 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2432 memset(dest
, 'X', sizeof(dest
));
2434 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2435 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2436 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2437 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2439 memset(dest
, 'X', sizeof(dest
));
2441 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2442 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2443 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2444 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2446 memset(dest
, 'X', sizeof(dest
));
2448 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2449 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2450 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2451 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2453 memset(dest
, 'X', sizeof(dest
));
2455 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2456 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2457 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2458 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2460 memset(dest
, 'X', sizeof(dest
));
2462 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2463 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2464 ok(!memcmp(dest
, second
, sizeof(second
)),
2465 "Expected the output buffer string to be \"duck\"\n");
2467 /* Test source truncation behavior. */
2468 memset(dest
, 'X', sizeof(dest
));
2469 memcpy(dest
, first
, sizeof(first
));
2470 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2471 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2472 ok(!memcmp(dest
, first
, sizeof(first
)),
2473 "Expected the output buffer string to be \"dinosaur\"\n");
2475 memset(dest
, 'X', sizeof(dest
));
2476 memcpy(dest
, first
, sizeof(first
));
2477 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2478 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2479 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2480 "Expected the output buffer string to be \"dinosaurduck\"\n");
2482 memset(dest
, 'X', sizeof(dest
));
2483 memcpy(dest
, first
, sizeof(first
));
2484 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2485 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2486 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2487 "Expected the output buffer string to be \"dinosaurduck\"\n");
2489 memset(dest
, 'X', sizeof(dest
));
2490 memcpy(dest
, first
, sizeof(first
));
2491 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2492 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2493 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2494 "Expected the output buffer string to be \"dinosaurduck\"\n");
2496 memset(dest
, 'X', sizeof(dest
));
2497 memcpy(dest
, first
, sizeof(first
));
2498 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2499 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2500 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2501 "Expected the output buffer string to be \"dinosaurduc\"\n");
2503 /* Test destination truncation behavior. */
2504 memset(dest
, 'X', sizeof(dest
));
2505 memcpy(dest
, first
, sizeof(first
));
2507 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2508 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2509 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2510 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2511 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2513 memset(dest
, 'X', sizeof(dest
));
2514 memcpy(dest
, first
, sizeof(first
));
2516 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2517 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2518 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2519 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2520 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2522 memset(dest
, 'X', sizeof(dest
));
2523 memcpy(dest
, first
, sizeof(first
));
2525 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2526 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2527 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2528 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2529 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2532 static void test__mbsupr_s(void)
2535 unsigned char buffer
[20];
2539 win_skip("Skipping _mbsupr_s tests\n");
2544 ret
= p_mbsupr_s(NULL
, 0);
2545 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2548 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2549 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2550 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2553 ret
= p_mbsupr_s(buffer
, 0);
2554 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2555 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2557 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2559 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2560 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2561 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2562 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2565 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2567 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2568 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2569 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2570 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2573 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2575 ret
= p_mbsupr_s(buffer
, 4);
2576 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2577 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2579 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2581 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2582 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2583 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2584 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2589 static void test__mbslwr_s(void)
2592 unsigned char buffer
[20];
2596 win_skip("Skipping _mbslwr_s tests\n");
2601 ret
= p_mbslwr_s(NULL
, 0);
2602 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2605 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2606 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2607 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2610 ret
= p_mbslwr_s(buffer
, 0);
2611 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2612 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2614 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2616 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2617 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2618 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2619 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2622 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2624 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2625 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2626 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2627 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2630 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2632 ret
= p_mbslwr_s(buffer
, 4);
2633 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2634 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2636 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2638 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2639 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2640 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2641 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2645 static void test__mbstok(void)
2647 const unsigned char delim
[] = "t";
2649 char str
[] = "!.!test";
2654 ret
= _mbstok(NULL
, delim
);
2655 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2656 ok(!ret
|| broken((char*)ret
==str
+4),
2657 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2659 ret
= _mbstok(NULL
, delim
);
2660 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2663 static void test__ultoa_s(void)
2670 win_skip("Skipping _ultoa_s tests\n");
2675 ret
= p_ultoa_s(0, NULL
, 0, 0);
2676 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2677 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2679 memset(buffer
, 'X', sizeof(buffer
));
2681 ret
= p_ultoa_s(0, buffer
, 0, 0);
2682 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2683 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2684 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2686 memset(buffer
, 'X', sizeof(buffer
));
2688 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2689 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2690 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2691 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2693 memset(buffer
, 'X', sizeof(buffer
));
2695 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2696 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2697 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2698 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2700 memset(buffer
, 'X', sizeof(buffer
));
2702 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2703 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2704 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2705 ok(!memcmp(buffer
, "\000765", 4),
2706 "Expected the output buffer to be null terminated with truncated output\n");
2708 memset(buffer
, 'X', sizeof(buffer
));
2710 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2711 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2712 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2713 ok(!memcmp(buffer
, "\0007654321", 8),
2714 "Expected the output buffer to be null terminated with truncated output\n");
2716 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2717 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2718 ok(!strcmp(buffer
, "12345678"),
2719 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2722 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2723 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2724 ok(!strcmp(buffer
, "1010101010101010"),
2725 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2728 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2729 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2730 ok(!strcmp(buffer
, "nell"),
2731 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2734 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2735 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2736 ok(!strcmp(buffer
, "hag"),
2737 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2741 static void test_wctob(void)
2743 int ret
, cp
= _getmbcp();
2745 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2746 win_skip("Skipping wctob tests\n");
2750 ret
= p_wctob(0x8141);
2751 ok(ret
== EOF
, "ret = %x\n", ret
);
2753 ret
= p_wctob(0x81);
2754 ok(ret
== EOF
, "ret = %x\n", ret
);
2756 ret
= p_wctob(0xe0);
2757 ok(ret
== 0x61, "ret = %x\n", ret
);
2760 ret
= p_wctob(0x81);
2761 ok(ret
== EOF
, "ret = %x\n", ret
);
2763 setlocale(LC_ALL
, "C");
2764 ret
= p_wctob(0x8141);
2765 ok(ret
== EOF
, "ret = %x\n", ret
);
2767 ret
= p_wctob(0x81);
2768 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2770 ret
= p_wctob(0x9f);
2771 ok(ret
== (int)(char)0x9f, "ret = %x\n", ret
);
2773 ret
= p_wctob(0xe0);
2774 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2779 static void test_wctomb(void)
2782 unsigned char dst
[10];
2785 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
2786 win_skip("wcrtomb tests\n");
2790 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
2791 ok(ret
== 2, "wcrtomb did not return 2\n");
2795 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
2796 ok(ret
== 2, "wcrtomb did not return 2\n");
2797 ok(state
== 0, "state != 0\n");
2798 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2799 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
2800 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
2802 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
2803 ok(ret
== 2, "wcrtomb did not return 2\n");
2804 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2805 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
2807 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
2808 ok(ret
== 1, "wcrtomb did not return 1\n");
2809 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
2811 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
2812 ok(ret
== -1, "wcrtomb did not return -1\n");
2813 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
2815 setlocale(LC_ALL
, "C");
2818 static void test_tolower(void)
2824 /* test C locale when locale was never changed */
2825 ret
= p_tolower(0x41);
2826 ok(ret
== 0x61, "ret = %x\n", ret
);
2828 ret
= p_tolower(0xF4);
2829 ok(ret
== 0xF4, "ret = %x\n", ret
);
2832 ret
= p_tolower((char)0xF4);
2833 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
2834 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2837 ret
= p_tolower((char)0xD0);
2838 ok(ret
== (char)0xD0, "ret = %x\n", ret
);
2839 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2841 setlocale(LC_ALL
, "C");
2843 ret
= p_tolower((char)0xF4);
2844 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
2845 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2847 /* test C locale after setting locale */
2848 if(!setlocale(LC_ALL
, "us")) {
2849 win_skip("skipping tolower tests that depends on locale\n");
2852 setlocale(LC_ALL
, "C");
2856 ret
= p_tolower(ch
);
2857 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
2858 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
2859 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
2862 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2864 ok(ret
== ch
, "ret = %x\n", ret
);
2865 if(!len
|| ret
==(unsigned char)lch
)
2866 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2870 ret
= p_tolower(ch
);
2871 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
2872 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
2873 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
2876 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2878 ok(ret
== ch
, "ret = %x\n", ret
);
2879 if(!len
|| ret
==(unsigned char)lch
)
2880 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2882 ret
= p_tolower(0xD0);
2883 ok(ret
== 0xD0, "ret = %x\n", ret
);
2885 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
2887 ret
= p_tolower((char)0xD0);
2888 ok(ret
== 0xF0, "ret = %x\n", ret
);
2890 ret
= p_tolower(0xD0);
2891 ok(ret
== 0xF0, "ret = %x\n", ret
);
2893 setlocale(LC_ALL
, "C");
2896 static void test__atodbl(void)
2903 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2904 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2905 win_skip("_atodbl_l is not available\n");
2910 ret
= p__atodbl_l(&d
, num
, NULL
);
2911 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
2912 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2913 ret
= _atodbl(&d
, num
);
2914 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
2915 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2918 ret
= p__atodbl_l(&d
, num
, NULL
);
2919 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
2920 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2921 ret
= _atodbl(&d
, num
);
2922 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
2923 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2926 ret
= p__atodbl_l(&d
, num
, NULL
);
2927 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
2928 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2929 ret
= _atodbl(&d
, num
);
2930 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
2931 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2934 ret
= p__atodbl_l(&d
, num
, NULL
);
2935 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
2936 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2937 ret
= _atodbl(&d
, num
);
2938 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
2939 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2941 strcpy(num
, "1e-309");
2942 ret
= p__atodbl_l(&d
, num
, NULL
);
2943 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
2944 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2945 ret
= _atodbl(&d
, num
);
2946 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
2947 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2949 strcpy(num
, "1e309");
2950 ret
= p__atodbl_l(&d
, num
, NULL
);
2951 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
2952 ret
= _atodbl(&d
, num
);
2953 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
2956 static void test__stricmp(void)
2960 ret
= _stricmp("test", "test");
2961 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2962 ret
= _stricmp("a", "z");
2963 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2964 ret
= _stricmp("z", "a");
2965 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2966 ret
= _stricmp("\xa5", "\xb9");
2967 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2969 if(!setlocale(LC_ALL
, "polish")) {
2970 win_skip("stricmp tests\n");
2974 ret
= _stricmp("test", "test");
2975 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2976 ret
= _stricmp("a", "z");
2977 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2978 ret
= _stricmp("z", "a");
2979 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2980 ret
= _stricmp("\xa5", "\xb9");
2981 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2982 ret
= _stricmp("a", "\xb9");
2983 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2985 setlocale(LC_ALL
, "C");
2988 static void test__wcstoi64(void)
2990 static const WCHAR digit
[] = { '9', 0 };
2991 static const WCHAR space
[] = { ' ', 0 };
2992 static const WCHAR stock
[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2993 static const WCHAR cjk_1
[] = { 0x4e00, 0 }; /* CJK Ideograph, First */
2994 static const WCHAR tamil
[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2995 static const WCHAR thai
[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2996 static const WCHAR fullwidth
[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2997 static const WCHAR superscript1
[] = { 0xb9, 0 }; /* SUPERSCRIPT ONE */
2998 static const WCHAR minus_0x91
[] = { '-', 0x0e50, 'x', 0xff19, '1', 0 };
2999 static const WCHAR plus_071
[] = { '+', 0x0e50, 0xff17, '1', 0 };
3000 static const WCHAR hex
[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
3001 static const WCHAR zeros
[] = {
3002 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3003 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3008 unsigned __int64 ures
;
3011 if (!p_wcstoi64
|| !p_wcstoui64
) {
3012 win_skip("_wcstoi64 or _wcstoui64 not found\n");
3016 res
= p_wcstoi64(digit
, NULL
, 10);
3017 ok(res
== 9, "res != 9\n");
3018 res
= p_wcstoi64(space
, &endpos
, 0);
3019 ok(endpos
== space
, "endpos != space\n");
3020 res
= p_wcstoi64(stock
, &endpos
, 10);
3021 ok(res
== 0, "res != 0\n");
3022 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
3023 res
= p_wcstoi64(cjk_1
, NULL
, 0);
3024 ok(res
== 0, "res != 0\n");
3025 res
= p_wcstoi64(tamil
, &endpos
, 10);
3026 ok(res
== 0, "res != 0\n");
3027 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
3028 res
= p_wcstoi64(thai
, NULL
, 10);
3029 ok(res
== 9, "res != 9\n");
3030 res
= p_wcstoi64(fullwidth
, NULL
, 10);
3031 ok(res
== 9, "res != 9\n");
3032 res
= p_wcstoi64(superscript1
, NULL
, 10);
3033 ok(res
== 0, "res != 0\n");
3034 res
= p_wcstoi64(hex
, NULL
, 16);
3035 ok(res
== 0x9f9, "res != 0x9f9\n");
3036 res
= p_wcstoi64(minus_0x91
, NULL
, 0);
3037 ok(res
== -0x91, "res != -0x91\n");
3038 res
= p_wcstoi64(plus_071
, NULL
, 0);
3039 ok(res
== 071, "res != 071\n");
3041 ures
= p_wcstoui64(digit
, NULL
, 10);
3042 ok(ures
== 9, "ures != 9\n");
3043 ures
= p_wcstoui64(space
, &endpos
, 0);
3044 ok(endpos
== space
, "endpos != space\n");
3045 ures
= p_wcstoui64(stock
, &endpos
, 10);
3046 ok(ures
== 0, "ures != 0\n");
3047 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
3048 ures
= p_wcstoui64(tamil
, &endpos
, 10);
3049 ok(ures
== 0, "ures != 0\n");
3050 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
3051 ures
= p_wcstoui64(thai
, NULL
, 10);
3052 ok(ures
== 9, "ures != 9\n");
3053 ures
= p_wcstoui64(fullwidth
, NULL
, 10);
3054 ok(ures
== 9, "ures != 9\n");
3055 ures
= p_wcstoui64(superscript1
, NULL
, 10);
3056 ok(ures
== 0, "ures != 0\n");
3057 ures
= p_wcstoui64(hex
, NULL
, 16);
3058 ok(ures
== 0x9f9, "ures != 0x9f9\n");
3059 ures
= p_wcstoui64(plus_071
, NULL
, 0);
3060 ok(ures
== 071, "ures != 071\n");
3062 /* Test various unicode digits */
3063 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3064 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3065 res
= p_wcstoi64(tmp
, NULL
, 0);
3066 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3067 tmp
[1] = zeros
[i
] + 10;
3068 res
= p_wcstoi64(tmp
, NULL
, 16);
3069 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3075 static void test_atoi(void)
3080 ok(r
== 0, "atoi(0) = %d\n", r
);
3083 ok(r
== -1, "atoi(-1) = %d\n", r
);
3086 ok(r
== 1, "atoi(1) = %d\n", r
);
3088 r
= atoi("4294967296");
3089 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
3092 static void test_atol(void)
3097 ok(r
== 0, "atol(0) = %d\n", r
);
3100 ok(r
== -1, "atol(-1) = %d\n", r
);
3103 ok(r
== 1, "atol(1) = %d\n", r
);
3105 r
= atol("4294967296");
3106 ok(r
== 0, "atol(4294967296) = %d\n", r
);
3109 static void test_atof(void)
3114 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
3117 ok(almost_equal(d
, 1.0), "d = %lf\n", d
);
3120 ok(almost_equal(d
, -1.0), "d = %lf\n", d
);
3124 win_skip("_atof_l not found\n");
3130 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
3131 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3134 d
= p__atof_l(NULL
, NULL
);
3135 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
3136 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3139 static void test_strncpy(void)
3141 #define TEST_STRNCPY_LEN 10
3142 /* use function pointer to bypass gcc builtin */
3143 char *(__cdecl
*p_strncpy
)(char*,const char*,size_t);
3145 char dst
[TEST_STRNCPY_LEN
+ 1];
3146 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
3148 p_strncpy
= (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "strncpy");
3150 /* strlen(src) > TEST_STRNCPY_LEN */
3151 ret
= p_strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
3152 ok(ret
== dst
, "ret != dst\n");
3153 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3155 /* without null-terminated */
3156 ret
= p_strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
3157 ok(ret
== dst
, "ret != dst\n");
3158 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3160 /* strlen(src) < TEST_STRNCPY_LEN */
3161 strcpy(dst
, "0123456789");
3162 ret
= p_strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
3163 ok(ret
== dst
, "ret != dst\n");
3164 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
3165 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
3167 /* strlen(src) == TEST_STRNCPY_LEN */
3168 ret
= p_strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
3169 ok(ret
== dst
, "ret != dst\n");
3170 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3173 static void test_strxfrm(void)
3178 /* crashes on old version of msvcrt */
3181 ret
= strxfrm(NULL
, "src", 1);
3182 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3183 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3186 ret
= strxfrm(dest
, NULL
, 100);
3187 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3188 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3191 ret
= strxfrm(NULL
, "src", 0);
3192 ok(ret
== 3, "ret = %d\n", (int)ret
);
3194 ret
= strxfrm(dest
, "src", 0);
3195 ok(ret
== 3, "ret = %d\n", (int)ret
);
3196 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3199 ret
= strxfrm(dest
, "src", 5);
3200 ok(ret
== 3, "ret = %d\n", (int)ret
);
3201 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
3205 ret
= strxfrm(dest
, "src", 1);
3206 ok(ret
== 3, "ret = %d\n", (int)ret
);
3207 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
3208 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
3209 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3211 ret
= strxfrm(dest
, "", 5);
3212 ok(ret
== 0, "ret = %d\n", (int)ret
);
3213 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
3215 if(!setlocale(LC_ALL
, "polish")) {
3216 win_skip("stxfrm tests\n");
3220 ret
= strxfrm(NULL
, "src", 0);
3221 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3223 ret
= strxfrm(dest
, "src", 0);
3224 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3225 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3227 ret
= strxfrm(dest
, "src", ret
+1);
3228 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3229 ok(dest
[0], "dest[0] = 0\n");
3233 ret
= strxfrm(dest
, "src", 5);
3234 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3235 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
3237 setlocale(LC_ALL
, "C");
3240 static void test__strnset_s(void)
3246 win_skip("_strnset_s not available\n");
3250 r
= p__strnset_s(NULL
, 0, 'a', 0);
3251 ok(r
== 0, "r = %d\n", r
);
3253 buf
[0] = buf
[1] = buf
[2] = 'b';
3254 r
= p__strnset_s(buf
, sizeof(buf
), 'a', 2);
3255 ok(r
== 0, "r = %d\n", r
);
3256 ok(!strcmp(buf
, "aab"), "buf = %s\n", buf
);
3258 r
= p__strnset_s(buf
, 0, 'a', 0);
3259 ok(r
== EINVAL
, "r = %d\n", r
);
3261 r
= p__strnset_s(NULL
, 0, 'a', 1);
3262 ok(r
== EINVAL
, "r = %d\n", r
);
3265 r
= p__strnset_s(buf
, sizeof(buf
)-1, 'c', 2);
3266 ok(r
== EINVAL
, "r = %d\n", r
);
3267 ok(!buf
[0] && buf
[1]=='c' && buf
[2]=='b', "buf = %s\n", buf
);
3270 static void test__wcsnset_s(void)
3272 wchar_t text
[] = { 't','e','x','t',0 };
3276 win_skip("_wcsnset_s not available\n");
3280 r
= p__wcsnset_s(NULL
, 0, 'a', 0);
3281 ok(r
== 0, "r = %d\n", r
);
3283 r
= p__wcsnset_s(text
, 0, 'a', 1);
3284 ok(r
== EINVAL
, "r = %d\n", r
);
3285 ok(text
[0] == 't', "text[0] = %d\n", text
[0]);
3287 r
= p__wcsnset_s(NULL
, 2, 'a', 1);
3288 ok(r
== EINVAL
, "r = %d\n", r
);
3290 r
= p__wcsnset_s(text
, 2, 'a', 3);
3291 ok(r
== EINVAL
, "r = %d\n", r
);
3292 ok(text
[0] == 0, "text[0] = %d\n", text
[0]);
3293 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3296 r
= p__wcsnset_s(text
, 5, 'a', 1);
3297 ok(r
== 0, "r = %d\n", r
);
3298 ok(text
[0] == 'a', "text[0] = %d\n", text
[0]);
3299 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3302 r
= p__wcsnset_s(text
, 5, 'b', 3);
3303 ok(r
== 0, "r = %d\n", r
);
3304 ok(text
[0] == 'b', "text[0] = %d\n", text
[0]);
3305 ok(text
[1] == 0, "text[1] = %d\n", text
[1]);
3306 ok(text
[2] == 'x', "text[2] = %d\n", text
[2]);
3309 static void test__wcsset_s(void)
3315 win_skip("_wcsset_s not available\n");
3319 r
= p__wcsset_s(NULL
, 0, 'a');
3320 ok(r
== EINVAL
, "r = %d\n", r
);
3323 r
= p__wcsset_s(str
, 0, 'a');
3324 ok(r
== EINVAL
, "r = %d\n", r
);
3325 ok(str
[0] == 'a', "str[0] = %d\n", str
[0]);
3329 r
= p__wcsset_s(str
, 2, 'c');
3330 ok(r
== EINVAL
, "r = %d\n", r
);
3331 ok(!str
[0], "str[0] = %d\n", str
[0]);
3332 ok(str
[1] == 'b', "str[1] = %d\n", str
[1]);
3337 r
= p__wcsset_s(str
, 3, 'c');
3338 ok(r
== 0, "r = %d\n", r
);
3339 ok(str
[0] == 'c', "str[0] = %d\n", str
[0]);
3340 ok(str
[1] == 0, "str[1] = %d\n", str
[1]);
3341 ok(str
[2] == 'b', "str[2] = %d\n", str
[2]);
3344 static void test__mbscmp(void)
3346 static const unsigned char a
[] = {'a',0}, b
[] = {'b',0};
3351 win_skip("_mbscmp tests\n");
3355 ret
= _mbscmp(NULL
, NULL
);
3356 ok(ret
== INT_MAX
, "got %d\n", ret
);
3358 ret
= _mbscmp(a
, NULL
);
3359 ok(ret
== INT_MAX
, "got %d\n", ret
);
3361 ret
= _mbscmp(NULL
, a
);
3362 ok(ret
== INT_MAX
, "got %d\n", ret
);
3364 ret
= _mbscmp(a
, a
);
3365 ok(!ret
, "got %d\n", ret
);
3367 ret
= _mbscmp(a
, b
);
3368 ok(ret
== -1, "got %d\n", ret
);
3370 ret
= _mbscmp(b
, a
);
3371 ok(ret
== 1, "got %d\n", ret
);
3374 static void test__ismbclx(void)
3376 int ret
, cp
= _getmbcp();
3379 ok(!ret
, "got %d\n", ret
);
3382 ok(!ret
, "got %d\n", ret
);
3385 ok(!ret
, "got %d\n", ret
);
3389 ret
= _ismbcl0(0x8140);
3390 ok(!ret
, "got %d\n", ret
);
3392 ret
= _ismbcl1(0x889f);
3393 ok(!ret
, "got %d\n", ret
);
3395 ret
= _ismbcl2(0x989f);
3396 ok(!ret
, "got %d\n", ret
);
3401 ok(!ret
, "got %d\n", ret
);
3403 ret
= _ismbcl0(0x8140);
3404 ok(ret
, "got %d\n", ret
);
3406 ret
= _ismbcl0(0x817f);
3407 ok(!ret
, "got %d\n", ret
);
3410 ok(!ret
, "got %d\n", ret
);
3412 ret
= _ismbcl1(0x889f);
3413 ok(ret
, "got %d\n", ret
);
3415 ret
= _ismbcl1(0x88fd);
3416 ok(!ret
, "got %d\n", ret
);
3419 ok(!ret
, "got %d\n", ret
);
3421 ret
= _ismbcl2(0x989f);
3422 ok(ret
, "got %d\n", ret
);
3424 ret
= _ismbcl2(0x993f);
3425 ok(!ret
, "got %d\n", ret
);
3430 static void test__memicmp(void)
3432 static const char *s1
= "abc";
3433 static const char *s2
= "aBd";
3436 ret
= p__memicmp(NULL
, NULL
, 0);
3437 ok(!ret
, "got %d\n", ret
);
3439 ret
= p__memicmp(s1
, s2
, 2);
3440 ok(!ret
, "got %d\n", ret
);
3442 ret
= p__memicmp(s1
, s2
, 3);
3443 ok(ret
== -1, "got %d\n", ret
);
3448 /* Following calls crash on WinXP/W2k3. */
3450 ret
= p__memicmp(NULL
, NULL
, 1);
3451 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3452 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3455 ret
= p__memicmp(s1
, NULL
, 1);
3456 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3457 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3460 ret
= p__memicmp(NULL
, s2
, 1);
3461 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3462 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3465 static void test__memicmp_l(void)
3467 static const char *s1
= "abc";
3468 static const char *s2
= "aBd";
3473 win_skip("_memicmp_l not found.\n");
3478 ret
= p__memicmp_l(NULL
, NULL
, 0, NULL
);
3479 ok(!ret
, "got %d\n", ret
);
3480 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3483 ret
= p__memicmp_l(NULL
, NULL
, 1, NULL
);
3484 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3485 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3488 ret
= p__memicmp_l(s1
, NULL
, 1, NULL
);
3489 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3490 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3493 ret
= p__memicmp_l(NULL
, s2
, 1, NULL
);
3494 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3495 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3498 ret
= p__memicmp_l(s1
, s2
, 2, NULL
);
3499 ok(!ret
, "got %d\n", ret
);
3500 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3503 ret
= p__memicmp_l(s1
, s2
, 3, NULL
);
3504 ok(ret
== -1, "got %d\n", ret
);
3505 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3508 static void test__strupr(void)
3510 const char str
[] = "123";
3515 mem
= VirtualAlloc(NULL
, sizeof(str
), MEM_COMMIT
, PAGE_READWRITE
);
3516 ok(mem
!= NULL
, "VirtualAlloc failed\n");
3517 memcpy(mem
, str
, sizeof(str
));
3518 ok(VirtualProtect(mem
, sizeof(str
), PAGE_READONLY
, &prot
), "VirtualProtect failed\n");
3520 strcpy(str2
, "aBc");
3522 ok(p
== str2
, "_strupr returned %p\n", p
);
3523 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3526 ok(p
== mem
, "_strupr returned %p\n", p
);
3527 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3529 if(!setlocale(LC_ALL
, "english")) {
3530 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3531 win_skip("English locale _strupr tests\n");
3535 strcpy(str2
, "aBc");
3537 ok(p
== str2
, "_strupr returned %p\n", p
);
3538 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3540 if (0) /* crashes on Windows */
3543 ok(p
== mem
, "_strupr returned %p\n", p
);
3544 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3547 setlocale(LC_ALL
, "C");
3548 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3551 static void test__tcsncoll(void)
3560 static const struct test tests
[] = {
3561 { "English", "ABCD", "ABCD", 4, 0 },
3562 { "English", "ABCD", "ABCD", 10, 0 },
3564 { "English", "ABC", "ABCD", 3, 0 },
3565 { "English", "ABC", "ABCD", 4, -1 },
3566 { "English", "ABC", "ABCD", 10, -1 },
3568 { "English", "ABCD", "ABC", 3, 0 },
3569 { "English", "ABCD", "ABC", 4, 1 },
3570 { "English", "ABCD", "ABC", 10, 1 },
3572 { "English", "ABCe", "ABCf", 3, 0 },
3573 { "English", "abcd", "ABCD", 10, -1 },
3575 { "C", "ABCD", "ABCD", 4, 0 },
3576 { "C", "ABCD", "ABCD", 10, 0 },
3578 { "C", "ABC", "ABCD", 3, 0 },
3579 { "C", "ABC", "ABCD", 10, -1 },
3581 { "C", "ABCD", "ABC", 3, 0 },
3582 { "C", "ABCD", "ABC", 10, 1 },
3584 { "C", "ABCe", "ABCf", 3, 0 },
3585 { "C", "abcd", "ABCD", 10, 1 },
3594 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3596 if (!setlocale(LC_ALL
, tests
[i
].locale
))
3598 win_skip("%s locale _tcsncoll tests\n", tests
[i
].locale
);
3599 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
3600 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
3604 memset(str1
, 0xee, sizeof(str1
));
3605 strcpy(str1
, tests
[i
].str1
);
3607 memset(str2
, 0xff, sizeof(str2
));
3608 strcpy(str2
, tests
[i
].str2
);
3610 ret
= _strncoll(str1
, str2
, tests
[i
].count
);
3612 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3613 else if (tests
[i
].exp
< 0)
3614 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3616 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3618 memset(str1W
, 0xee, sizeof(str1W
));
3619 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
3622 memset(str2W
, 0xff, sizeof(str2W
));
3623 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
3626 ret
= _wcsncoll(str1W
, str2W
, tests
[i
].count
);
3628 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3629 else if (tests
[i
].exp
< 0)
3630 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3632 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3636 static void test__tcsnicoll(void)
3645 static const struct test tests
[] = {
3646 { "English", "abcd", "ABCD", 4, 0 },
3647 { "English", "abcd", "ABCD", 10, 0 },
3649 { "English", "abc", "ABCD", 3, 0 },
3650 { "English", "abc", "ABCD", 4, -1 },
3651 { "English", "abc", "ABCD", 10, -1 },
3653 { "English", "abcd", "ABC", 3, 0 },
3654 { "English", "abcd", "ABC", 4, 1 },
3655 { "English", "abcd", "ABC", 10, 1 },
3657 { "English", "abcE", "ABCF", 3, 0 },
3659 { "C", "abcd", "ABCD", 4, 0 },
3660 { "C", "abcd", "ABCD", 10, 0 },
3662 { "C", "abc", "ABCD", 3, 0 },
3663 { "C", "abc", "ABCD", 10, -1 },
3665 { "C", "abcd", "ABC", 3, 0 },
3666 { "C", "abcd", "ABC", 10, 1 },
3668 { "C", "abce", "ABCf", 3, 0 },
3677 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3679 if (!setlocale(LC_ALL
, tests
[i
].locale
))
3681 win_skip("%s locale _tcsnicoll tests\n", tests
[i
].locale
);
3682 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
3683 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
3687 memset(str1
, 0xee, sizeof(str1
));
3688 strcpy(str1
, tests
[i
].str1
);
3690 memset(str2
, 0xff, sizeof(str2
));
3691 strcpy(str2
, tests
[i
].str2
);
3693 ret
= _strnicoll(str1
, str2
, tests
[i
].count
);
3695 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3696 else if (tests
[i
].exp
< 0)
3697 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3699 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3701 memset(str1W
, 0xee, sizeof(str1W
));
3702 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
3705 memset(str2W
, 0xff, sizeof(str2W
));
3706 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
3709 ret
= _wcsnicoll(str1W
, str2W
, tests
[i
].count
);
3711 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3712 else if (tests
[i
].exp
< 0)
3713 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3715 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3719 static void test___strncnt(void)
3740 win_skip("__strncnt() is not available.\n");
3744 if (0) /* crashes */
3745 ret
= p___strncnt(NULL
, 1);
3747 for (i
= 0; i
< ARRAY_SIZE(strncnt_tests
); ++i
)
3749 ret
= p___strncnt(strncnt_tests
[i
].str
, strncnt_tests
[i
].size
);
3750 ok(ret
== strncnt_tests
[i
].ret
, "%u: unexpected return value %u.\n", i
, (int)ret
);
3754 static void test_C_locale(void)
3759 static const char *locales
[] = { NULL
, "C" };
3761 /* C locale only converts case for [a-zA-Z] */
3762 setlocale(LC_ALL
, "C");
3763 for (i
= 0; i
<= 0xffff; i
++)
3765 ret
= p_towlower(i
);
3766 if (i
>= 'A' && i
<= 'Z')
3768 exp
= i
+ 'a' - 'A';
3769 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
3772 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
3774 ret
= p_towupper(i
);
3775 if (i
>= 'a' && i
<= 'z')
3777 exp
= i
+ 'A' - 'a';
3778 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
3781 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
3784 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
3786 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
3790 for (i
= 0; i
< ARRAY_SIZE(locales
); i
++) {
3791 locale
= locales
[i
] ? p__create_locale(LC_ALL
, locales
[i
]) : NULL
;
3793 for (j
= 0; j
<= 0xffff; j
++) {
3794 ret
= p__towlower_l(j
, locale
);
3795 if (j
>= 'A' && j
<= 'Z')
3797 exp
= j
+ 'a' - 'A';
3798 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
3801 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
3803 ret
= p__towupper_l(j
, locale
);
3804 if (j
>= 'a' && j
<= 'z')
3806 exp
= j
+ 'A' - 'a';
3807 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
3810 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
3813 p__free_locale(locale
);
3820 static const char xilstring
[]="c:/xilinx";
3823 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
3825 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
3826 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
3827 SET(pmemcpy
,"memcpy");
3828 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
3829 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
3830 SET(pmemcmp
,"memcmp");
3831 SET(p_mbctype
,"_mbctype");
3832 SET(p__mb_cur_max
,"__mb_cur_max");
3833 SET(p_strcpy
, "strcpy");
3834 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
3835 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
3836 p_mbscat_s
= (void*)GetProcAddress( hMsvcrt
, "_mbscat_s" );
3837 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
3838 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
3839 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
3840 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
3841 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
3842 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
3843 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
3844 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
3845 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
3846 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
3847 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
3848 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
3849 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
3850 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
3851 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
3852 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
3853 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
3854 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
3855 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
3856 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
3857 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
3858 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
3859 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
3860 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
3861 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
3862 p_towlower
= (void*)GetProcAddress(hMsvcrt
, "towlower");
3863 p__towlower_l
= (void*)GetProcAddress(hMsvcrt
, "_towlower_l");
3864 p_towupper
= (void*)GetProcAddress(hMsvcrt
, "towupper");
3865 p__towupper_l
= (void*)GetProcAddress(hMsvcrt
, "_towupper_l");
3866 p__create_locale
= (void*)GetProcAddress(hMsvcrt
, "_create_locale");
3867 p__free_locale
= (void*)GetProcAddress(hMsvcrt
, "_free_locale");
3868 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
3869 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
3870 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
3871 p_mbsrtowcs_s
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs_s");
3872 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
3873 p__atof_l
= (void*)GetProcAddress(hMsvcrt
, "_atof_l");
3874 p__strtod_l
= (void*)GetProcAddress(hMsvcrt
, "_strtod_l");
3875 p__strnset_s
= (void*)GetProcAddress(hMsvcrt
, "_strnset_s");
3876 p__wcsnset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsnset_s");
3877 p__wcsset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsset_s");
3878 p__mbsnlen
= (void*)GetProcAddress(hMsvcrt
, "_mbsnlen");
3879 p__mbccpy_s
= (void*)GetProcAddress(hMsvcrt
, "_mbccpy_s");
3880 p__memicmp
= (void*)GetProcAddress(hMsvcrt
, "_memicmp");
3881 p__memicmp_l
= (void*)GetProcAddress(hMsvcrt
, "_memicmp_l");
3882 p___strncnt
= (void*)GetProcAddress(hMsvcrt
, "__strncnt");
3884 /* MSVCRT memcpy behaves like memmove for overlapping moves,
3885 MFC42 CString::Insert seems to rely on that behaviour */
3886 strcpy(mem
,xilstring
);
3887 nLen
=strlen(xilstring
);
3888 pmemcpy(mem
+5, mem
,nLen
+1);
3889 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
3890 "Got result %s\n",mem
+5);
3892 /* run tolower tests first */