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
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
60 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
61 static int (__cdecl
*p_mbscat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
);
62 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
63 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
64 static int (__cdecl
*p__mbscpy_s
)(unsigned char*, size_t, const unsigned char*);
65 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
66 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
67 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
68 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
69 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
70 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
71 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
72 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
73 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
74 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
75 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
76 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
77 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
78 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
79 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
80 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
81 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
82 static int *p__mb_cur_max
;
83 static unsigned char *p_mbctype
;
84 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
85 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
86 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
87 static int (__cdecl
*p_wctob
)(wint_t);
88 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
89 static int (__cdecl
*p_tolower
)(int);
90 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
91 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
92 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
93 static double (__cdecl
*p__atof_l
)(const char*,_locale_t
);
94 static double (__cdecl
*p__strtod_l
)(const char *,char**,_locale_t
);
95 static int (__cdecl
*p__strnset_s
)(char*,size_t,int,size_t);
96 static int (__cdecl
*p__wcsset_s
)(wchar_t*,size_t,wchar_t);
98 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
99 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
101 static HMODULE hMsvcrt
;
103 static void test_swab( void ) {
104 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
105 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
106 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
107 char expected3
[] = "$";
114 /* Test 1 - normal even case */
115 memset(to
,'$', sizeof(to
));
116 memset(from
,'@', sizeof(from
));
118 memcpy(from
, original
, testsize
);
119 _swab( from
, to
, testsize
);
120 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
122 /* Test 2 - uneven case */
123 memset(to
,'$', sizeof(to
));
124 memset(from
,'@', sizeof(from
));
126 memcpy(from
, original
, testsize
);
127 _swab( from
, to
, testsize
);
128 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
130 /* Test 3 - from = to */
131 memset(to
,'$', sizeof(to
));
132 memset(from
,'@', sizeof(from
));
134 memcpy(to
, original
, testsize
);
135 _swab( to
, to
, testsize
);
136 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
138 /* Test 4 - 1 bytes */
139 memset(to
,'$', sizeof(to
));
140 memset(from
,'@', sizeof(from
));
142 memcpy(from
, original
, testsize
);
143 _swab( from
, to
, testsize
);
144 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
147 #if 0 /* use this to generate more tests */
149 static void test_codepage(int cp
)
155 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
158 printf("static int result_cp_%d_mbctype[] = { ", cp
);
159 for (i
= 1; i
< 257; i
++)
161 if (p_mbctype
[i
] != prev
)
163 printf("0x%x,%d, ", prev
, count
);
170 printf("0x%x,%d };\n", prev
, count
);
175 /* RLE-encoded mbctype tables for given codepages */
176 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
177 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
178 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
180 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
182 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
183 0x0,2, 0x4,32, 0xc,94, 0,1 };
185 static void test_cp_table(int cp
, int *result
)
191 for (i
= 0; i
< 256; i
++)
199 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
);
204 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
208 static void test_mbcp(void)
210 int mb_orig_max
= *p__mb_cur_max
;
211 int curr_mbcp
= _getmbcp();
212 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
213 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
214 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
215 unsigned char buf
[16];
221 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
222 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
223 * CP1252 (or the ACP?) so we test only a few ASCII characters */
225 expect_eq(p_mbctype
[10], 0, char, "%x");
226 expect_eq(p_mbctype
[50], 0, char, "%x");
227 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
228 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
229 expect_eq(p_mbctype
[128], 0, char, "%x");
231 expect_eq(p_mbctype
[10], 0, char, "%x");
232 expect_eq(p_mbctype
[50], 0, char, "%x");
233 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
234 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
235 expect_eq(p_mbctype
[128], 0, char, "%x");
237 /* double byte code pages */
244 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
);
245 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
246 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
247 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
248 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
249 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
250 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
253 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
254 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
255 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
256 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
257 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
258 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
259 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
260 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
261 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
263 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
264 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
265 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
266 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
269 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
270 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
271 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
272 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
273 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
274 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
275 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
276 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
277 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
279 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
280 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
281 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
282 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
283 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
284 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
287 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
288 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
289 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
290 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
291 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
292 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
293 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
294 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
295 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
297 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
298 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
299 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
300 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
301 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
302 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
305 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
306 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
307 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
309 /* _mbclen/_mbslen */
310 expect_eq(_mbclen(mbstring
), 2, int, "%d");
311 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
312 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
313 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
314 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
315 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
318 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
319 win_skip("mbrlen tests\n");
322 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
323 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
324 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
325 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
326 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
327 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
328 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
332 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
333 win_skip("mbrtowc tests\n");
337 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
338 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
339 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
340 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
341 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
342 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
343 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
344 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
345 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
346 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
347 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
348 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
349 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
350 ok(state
== 0, "incorrect state value (%x)\n", state
);
352 setlocale(LC_ALL
, "C");
354 /* _mbccpy/_mbsncpy */
355 memset(buf
, 0xff, sizeof(buf
));
356 _mbccpy(buf
, mbstring
);
357 expect_bin(buf
, "\xb0\xb1\xff", 3);
359 memset(buf
, 0xff, sizeof(buf
));
360 _mbsncpy(buf
, mbstring
, 1);
361 expect_bin(buf
, "\xb0\xb1\xff", 3);
362 memset(buf
, 0xff, sizeof(buf
));
363 _mbsncpy(buf
, mbstring
, 2);
364 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
365 memset(buf
, 0xff, sizeof(buf
));
366 _mbsncpy(buf
, mbstring
, 3);
367 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
368 memset(buf
, 0xff, sizeof(buf
));
369 _mbsncpy(buf
, mbstring
, 4);
370 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
371 memset(buf
, 0xff, sizeof(buf
));
372 _mbsncpy(buf
, mbstring
, 5);
373 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
374 memset(buf
, 0xff, sizeof(buf
));
375 _mbsncpy(buf
, mbsonlylead
, 6);
376 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
378 memset(buf
, 0xff, sizeof(buf
));
379 _mbsnbcpy(buf
, mbstring2
, 2);
380 expect_bin(buf
, "\xb0\xb1\xff", 3);
381 _mbsnbcpy(buf
, mbstring2
, 3);
382 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
383 _mbsnbcpy(buf
, mbstring2
, 4);
384 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
385 memset(buf
, 0xff, sizeof(buf
));
386 _mbsnbcpy(buf
, mbsonlylead
, 5);
387 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
390 step
= _mbsinc(mbstring
) - mbstring
;
391 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
392 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
393 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
395 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
396 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
397 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
398 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
399 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
400 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
401 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
402 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
403 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
404 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
405 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
406 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
407 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
408 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
409 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
410 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
411 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
412 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
414 /* functions that depend on locale codepage, not mbcp.
415 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
416 * (as of Wine 0.9.43)
418 GetCPInfo(GetACP(), &cp_info
);
419 if (cp_info
.MaxCharSize
== 1)
421 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
422 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
425 skip("Current locale has double-byte charset - could lead to false positives\n");
428 expect_eq(_ismbblead(0x80), 0, int, "%d");
430 expect_eq(_ismbblead(0x81), 1, int, "%d");
431 expect_eq(_ismbblead(0x83), 1, int, "%d");
433 expect_eq(_ismbblead(0x84), 1, int, "%d");
434 expect_eq(_ismbblead(0xd3), 1, int, "%d");
435 expect_eq(_ismbblead(0xd7), 0, int, "%d");
436 expect_eq(_ismbblead(0xd8), 1, int, "%d");
437 expect_eq(_ismbblead(0xd9), 1, int, "%d");
439 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
440 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
441 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
442 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
443 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
444 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
445 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
446 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
451 static void test_mbsspn( void)
453 unsigned char str1
[]="cabernet";
454 unsigned char str2
[]="shiraz";
455 unsigned char set
[]="abc";
456 unsigned char empty
[]="";
458 ret
=_mbsspn( str1
, set
);
459 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
460 ret
=_mbsspn( str2
, set
);
461 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
462 ret
=_mbsspn( str1
, empty
);
463 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
466 static void test_mbsspnp( void)
468 unsigned char str1
[]="cabernet";
469 unsigned char str2
[]="shiraz";
470 unsigned char set
[]="abc";
471 unsigned char empty
[]="";
472 unsigned char full
[]="abcenrt";
474 ret
=_mbsspnp( str1
, set
);
475 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
476 ret
=_mbsspnp( str2
, set
);
477 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
478 ret
=_mbsspnp( str1
, empty
);
479 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
480 ret
=_mbsspnp( str1
, full
);
481 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
484 static void test_strdup(void)
488 ok( str
== 0, "strdup returns %s should be 0\n", str
);
492 static void test_strcpy_s(void)
495 const char *small
= "small";
496 const char *big
= "atoolongstringforthislittledestination";
501 win_skip("strcpy_s not found\n");
505 memset(dest
, 'X', sizeof(dest
));
506 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
507 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
508 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
509 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
510 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
511 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
513 memset(dest
, 'X', sizeof(dest
));
514 ret
= pstrcpy_s(dest
, 0, big
);
515 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
516 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
517 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
518 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
519 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
520 ret
= pstrcpy_s(dest
, 0, NULL
);
521 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
522 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
523 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
524 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
525 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
527 memset(dest
, 'X', sizeof(dest
));
528 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
529 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
530 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
531 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
532 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
533 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
535 memset(dest
, 'X', sizeof(dest
));
536 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
537 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
538 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
539 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
540 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
541 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
543 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
544 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
547 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
549 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
550 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
551 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
552 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
553 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
555 static void test_memcpy_s(void)
558 static const char tiny
[] = {'T',0,'I','N','Y',0};
559 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
562 win_skip("memcpy_s not found\n");
567 memset(dest
, 'X', sizeof(dest
));
568 ret
= p_memcpy_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
569 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
570 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
572 /* Vary source size */
574 memset(dest
, 'X', sizeof(dest
));
575 ret
= p_memcpy_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
576 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
577 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
578 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
580 /* Replace source with NULL */
582 memset(dest
, 'X', sizeof(dest
));
583 ret
= p_memcpy_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
584 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
585 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
586 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
590 memset(dest
, 'X', sizeof(dest
));
591 ret
= p_memcpy_s(dest
, 0, tiny
, NUMELMS(tiny
));
592 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
593 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
594 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
596 /* Replace dest with NULL */
598 ret
= p_memcpy_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
599 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
600 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
604 memset(dest
, 'X', sizeof(dest
));
605 ret
= p_memcpy_s(dest
, 0, NULL
, NUMELMS(tiny
));
606 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
607 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
608 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
611 static void test_memmove_s(void)
614 static const char tiny
[] = {'T',0,'I','N','Y',0};
615 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
618 win_skip("memmove_s not found\n");
623 memset(dest
, 'X', sizeof(dest
));
624 ret
= p_memmove_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
625 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
626 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
629 memcpy(dest
, big
, sizeof(dest
));
630 ret
= p_memmove_s(dest
+1, NUMELMS(dest
)-1, dest
, NUMELMS(dest
)-1);
631 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
632 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
634 /* Vary source size */
636 memset(dest
, 'X', sizeof(dest
));
637 ret
= p_memmove_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
638 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
639 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
640 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
642 /* Replace source with NULL */
644 memset(dest
, 'X', sizeof(dest
));
645 ret
= p_memmove_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
646 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
647 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
648 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
652 memset(dest
, 'X', sizeof(dest
));
653 ret
= p_memmove_s(dest
, 0, tiny
, NUMELMS(tiny
));
654 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
655 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
656 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
658 /* Replace dest with NULL */
660 ret
= p_memmove_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
661 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
662 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
666 memset(dest
, 'X', sizeof(dest
));
667 ret
= p_memmove_s(dest
, 0, NULL
, NUMELMS(tiny
));
668 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
669 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
670 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
673 static void test_strcat_s(void)
676 const char *small
= "sma";
681 win_skip("strcat_s not found\n");
685 memset(dest
, 'X', sizeof(dest
));
687 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
688 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
689 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
690 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
691 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
692 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
693 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
694 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
695 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
696 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
697 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
698 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
700 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
701 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
702 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
703 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
704 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
705 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
707 memset(dest
, 'X', sizeof(dest
));
711 ret
= pstrcat_s(dest
, 0, small
);
712 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
713 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
714 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
715 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
716 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
718 ret
= pstrcat_s(dest
, 0, NULL
);
719 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
720 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
721 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
722 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
723 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
725 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
726 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
727 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
728 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
729 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
730 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
732 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
733 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
736 static void test__mbscat_s(void)
738 unsigned char dst
[8], src
[4];
740 int prev_cp
= _getmbcp();
744 win_skip("_mbscat_s not found\n");
750 err
= p_mbscat_s(NULL
, sizeof(dst
), src
);
751 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
753 err
= p_mbscat_s(dst
, sizeof(dst
), NULL
);
754 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
757 err
= p_mbscat_s(dst
, 1, src
);
758 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
760 memset(dst
, 'a', sizeof(dst
));
765 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
766 ok(err
== 0, "_mbscat_s returned %d\n", err
);
767 ok(!memcmp(dst
, "aaaaaab", 8), "dst = %s\n", dst
);
769 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
770 ok(err
== ERANGE
, "_mbscat_s returned %d\n", err
);
771 ok(!dst
[0], "dst[0] = %c\n", dst
[0]);
772 ok(dst
[1] == 'a', "dst[1] = %c\n", dst
[1]);
775 /* test invalid str in dst */
782 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
783 ok(err
== 0, "_mbscat_s returned %d\n", err
);
785 /* test invalid str in src */
791 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
792 ok(err
== 0, "_mbscat_s returned %d\n", err
);
794 /* test dst with leading byte on the end of buffer */
800 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
801 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
802 ok(!memcmp(dst
, "aR", 3), "dst = %s\n", dst
);
804 /* test src with leading byte on the end of buffer */
810 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
811 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
812 ok(!memcmp(dst
, "ab", 3), "dst = %s\n", dst
);
816 static void test__mbsnbcpy_s(void)
818 unsigned char dest
[8];
819 const unsigned char big
[] = "atoolongstringforthislittledestination";
820 const unsigned char small
[] = "small";
825 win_skip("_mbsnbcpy_s not found\n");
829 memset(dest
, 'X', sizeof(dest
));
830 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
831 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
832 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
833 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
834 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
835 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
838 memset(dest
, 'X', sizeof(dest
));
839 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
840 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
841 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
842 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
843 "Unexpected return data from _mbsnbcpy_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 memset(dest
, 'X', sizeof(dest
));
847 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
848 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
849 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
850 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
851 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
852 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
854 memset(dest
, 'X', sizeof(dest
));
855 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
856 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
857 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
858 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
859 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
860 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
863 static void test__mbscpy_s(void)
865 const unsigned char src
[] = "source string";
866 unsigned char dest
[16];
871 win_skip("_mbscpy_s not found\n");
875 ret
= p__mbscpy_s(NULL
, 0, src
);
876 ok(ret
== EINVAL
, "got %d\n", ret
);
877 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
878 ok(ret
== EINVAL
, "got %d\n", ret
);
879 ret
= p__mbscpy_s(dest
, 0, src
);
880 ok(ret
== EINVAL
, "got %d\n", ret
);
882 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
883 ok(ret
== EINVAL
, "got %d\n", ret
);
884 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
886 memset(dest
, 'X', sizeof(dest
));
887 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
888 ok(!ret
, "got %d\n", ret
);
889 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
890 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
892 memset(dest
, 'X', sizeof(dest
));
893 ret
= p__mbscpy_s(dest
, 4, src
);
894 ok(ret
== ERANGE
, "got %d\n", ret
);
895 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
896 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
899 static void test_wcscpy_s(void)
901 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
902 static WCHAR szDest
[18];
903 static WCHAR szDestShort
[8];
908 win_skip("wcscpy_s not found\n");
914 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
915 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
916 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
918 /* Test NULL Source */
921 ret
= p_wcscpy_s(szDest
, 18, NULL
);
922 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
923 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
924 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
926 /* Test invalid size */
929 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
930 /* Later versions changed the return value for this case to EINVAL,
931 * and don't modify the result if the dest size is 0.
933 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
934 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
935 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
937 /* Copy same buffer size */
938 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
939 ok(ret
== 0, "expected 0 got %d\n", ret
);
940 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
942 /* Copy smaller buffer size */
945 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
946 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
947 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
948 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
952 win_skip("wcsncpy_s not found\n");
956 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
957 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
960 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
961 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
962 ok(szDest
[0] == 0, "szDest[0] not 0\n");
965 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
966 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
967 ok(szDest
[0] == 0, "szDest[0] not 0\n");
970 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
971 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
972 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
974 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
975 ok(ret
== 0, "expected 0 got %d\n", ret
);
976 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
979 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
980 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
981 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
984 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
985 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
986 ok(szDest
[4] == 0, "szDest[4] not 0\n");
987 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
989 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
990 ok(ret
== 0, "ret = %d\n", ret
);
992 szDestShort
[0] = '1';
994 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
995 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
996 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
997 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
1000 static void test__wcsupr_s(void)
1002 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1003 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1004 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
1005 'W', 'E', 'R', 'U', 'P', 'P', 'E',
1007 WCHAR testBuffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
1012 win_skip("_wcsupr_s not found\n");
1016 /* Test NULL input string and invalid size. */
1018 ret
= p_wcsupr_s(NULL
, 0);
1019 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1020 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1022 /* Test NULL input string and valid size. */
1024 ret
= p_wcsupr_s(NULL
, sizeof(testBuffer
)/sizeof(WCHAR
));
1025 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1026 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1028 /* Test empty string with zero size. */
1030 testBuffer
[0] = '\0';
1031 ret
= p_wcsupr_s(testBuffer
, 0);
1032 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1033 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1034 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1036 /* Test empty string with size of one. */
1037 testBuffer
[0] = '\0';
1038 ret
= p_wcsupr_s(testBuffer
, 1);
1039 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1040 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1042 /* Test one-byte buffer with zero size. */
1044 testBuffer
[0] = 'x';
1045 ret
= p_wcsupr_s(testBuffer
, 0);
1046 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1047 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1048 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1050 /* Test one-byte buffer with size of one. */
1052 testBuffer
[0] = 'x';
1053 ret
= p_wcsupr_s(testBuffer
, 1);
1054 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1055 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1056 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1058 /* Test invalid size. */
1059 wcscpy(testBuffer
, mixedString
);
1061 ret
= p_wcsupr_s(testBuffer
, 0);
1062 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1063 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1064 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1066 /* Test normal string uppercasing. */
1067 wcscpy(testBuffer
, mixedString
);
1068 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
));
1069 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1070 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1072 /* Test uppercasing with a shorter buffer size count. */
1073 wcscpy(testBuffer
, mixedString
);
1075 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
1076 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1077 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1078 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1080 /* Test uppercasing with a longer buffer size count. */
1081 wcscpy(testBuffer
, mixedString
);
1082 ret
= p_wcsupr_s(testBuffer
, sizeof(testBuffer
)/sizeof(WCHAR
));
1083 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1084 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1087 static void test__wcslwr_s(void)
1089 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1090 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1091 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1092 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1094 WCHAR buffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
1099 win_skip("_wcslwr_s not found\n");
1103 /* Test NULL input string and invalid size. */
1105 ret
= p_wcslwr_s(NULL
, 0);
1106 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1107 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1109 /* Test NULL input string and valid size. */
1111 ret
= p_wcslwr_s(NULL
, sizeof(buffer
)/sizeof(buffer
[0]));
1112 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1113 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1115 /* Test empty string with zero size. */
1118 ret
= p_wcslwr_s(buffer
, 0);
1119 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1120 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1121 ok(buffer
[0] == 0, "expected empty string\n");
1123 /* Test empty string with size of one. */
1125 ret
= p_wcslwr_s(buffer
, 1);
1126 ok(ret
== 0, "got %d\n", ret
);
1127 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1129 /* Test one-byte buffer with zero size. */
1132 ret
= p_wcslwr_s(buffer
, 0);
1133 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1134 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1135 ok(buffer
[0] == '\0', "expected empty string\n");
1137 /* Test one-byte buffer with size of one. */
1140 ret
= p_wcslwr_s(buffer
, 1);
1141 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1142 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1143 ok(buffer
[0] == '\0', "expected empty string\n");
1145 /* Test invalid size. */
1146 wcscpy(buffer
, mixedString
);
1148 ret
= p_wcslwr_s(buffer
, 0);
1149 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1150 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1151 ok(buffer
[0] == '\0', "expected empty string\n");
1153 /* Test normal string uppercasing. */
1154 wcscpy(buffer
, mixedString
);
1155 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
));
1156 ok(ret
== 0, "expected 0, got %d\n", ret
);
1157 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1159 /* Test uppercasing with a shorter buffer size count. */
1160 wcscpy(buffer
, mixedString
);
1162 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
1163 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1164 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1165 ok(buffer
[0] == '\0', "expected empty string\n");
1167 /* Test uppercasing with a longer buffer size count. */
1168 wcscpy(buffer
, mixedString
);
1169 ret
= p_wcslwr_s(buffer
, sizeof(buffer
)/sizeof(WCHAR
));
1170 ok(ret
== 0, "expected 0, got %d\n", ret
);
1171 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1174 static void test_mbcjisjms(void)
1176 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1177 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1178 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1179 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1180 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1181 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1183 int prev_cp
= _getmbcp();
1185 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1188 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1190 unsigned int ret
, exp
;
1191 ret
= _mbcjistojms(jisjms
[j
][0]);
1192 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1193 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1194 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1200 static void test_mbcjmsjis(void)
1202 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1203 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1204 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1205 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1206 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1207 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1208 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1209 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1211 int prev_cp
= _getmbcp();
1213 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1216 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1218 unsigned int ret
, exp
;
1219 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1220 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1221 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1222 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1228 static void test_mbctohira(void)
1230 static const unsigned int mbchira_932
[][2] = {
1231 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1232 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1233 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1234 {0x8396, 0x8396}, {0x8397, 0x8397},
1235 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1237 unsigned int prev_cp
= _getmbcp();
1239 _setmbcp(_MB_CP_SBCS
);
1240 for (i
= 0; i
< sizeof(mbchira_932
)/sizeof(mbchira_932
[0]); i
++)
1242 int ret
, exp
= mbchira_932
[i
][0];
1243 ret
= _mbctohira(mbchira_932
[i
][0]);
1244 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1248 for (i
= 0; i
< sizeof(mbchira_932
)/sizeof(mbchira_932
[0]); i
++)
1250 unsigned int ret
, exp
;
1251 ret
= _mbctohira(mbchira_932
[i
][0]);
1252 exp
= mbchira_932
[i
][1];
1253 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1258 static void test_mbctokata(void)
1260 static const unsigned int mbckata_932
[][2] = {
1261 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1262 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1263 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1264 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1266 unsigned int prev_cp
= _getmbcp();
1268 _setmbcp(_MB_CP_SBCS
);
1269 for (i
= 0; i
< sizeof(mbckata_932
)/sizeof(mbckata_932
[0]); i
++)
1271 int ret
, exp
= mbckata_932
[i
][0];
1272 ret
= _mbctokata(mbckata_932
[i
][0]);
1273 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1277 for (i
= 0; i
< sizeof(mbckata_932
)/sizeof(mbckata_932
[0]); i
++)
1279 unsigned int ret
, exp
;
1280 ret
= _mbctokata(mbckata_932
[i
][0]);
1281 exp
= mbckata_932
[i
][1];
1282 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1287 static void test_mbbtombc(void)
1289 static const unsigned int mbbmbc
[][2] = {
1290 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1291 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1292 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1293 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1294 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1296 int prev_cp
= _getmbcp();
1298 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1301 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1303 unsigned int exp
, ret
;
1304 ret
= _mbbtombc(mbbmbc
[j
][0]);
1305 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1306 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1307 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1313 static void test_mbctombb(void)
1315 static const unsigned int mbcmbb_932
[][2] = {
1316 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1317 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1318 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1319 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1320 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1321 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1322 unsigned int exp
, ret
, i
;
1323 unsigned int prev_cp
= _getmbcp();
1326 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1328 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1329 exp
= mbcmbb_932
[i
][1];
1330 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1335 static void test_ismbckata(void) {
1336 struct katakana_pair
{
1340 static const struct katakana_pair tests
[] = {
1341 {0x8152, FALSE
}, {0x8153, FALSE
}, {0x8154, FALSE
}, {0x8155, FALSE
},
1342 {0x82a0, FALSE
}, {0x833f, FALSE
}, {0x8340, TRUE
}, {0x837e, TRUE
},
1343 {0x837f, FALSE
}, {0x8380, TRUE
}, {0x8396, TRUE
}, {0x8397, FALSE
},
1344 {0xa5, FALSE
}, {0xb0, FALSE
}, {0xdd, FALSE
}
1346 unsigned int prev_cp
= _getmbcp();
1350 _setmbcp(_MB_CP_SBCS
);
1351 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++) {
1352 ret
= _ismbckata(tests
[i
].c
);
1353 ok(!ret
, "expected 0, got %d for %04x\n", ret
, tests
[i
].c
);
1357 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++) {
1358 ret
= _ismbckata(tests
[i
].c
);
1359 ok(!!ret
== tests
[i
].exp
, "expected %d, got %d for %04x\n",
1360 tests
[i
].exp
, !!ret
, tests
[i
].c
);
1366 static void test_ismbclegal(void) {
1367 unsigned int prev_cp
= _getmbcp();
1371 _setmbcp(932); /* Japanese */
1373 for(i
= 0; i
< 0x10000; i
++) {
1374 ret
= _ismbclegal(i
);
1375 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1376 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1377 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1378 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1384 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1385 _setmbcp(936); /* Chinese (GBK) */
1387 for(i
= 0; i
< 0x10000; i
++) {
1388 ret
= _ismbclegal(i
);
1389 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1390 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1396 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1397 _setmbcp(949); /* Korean */
1399 for(i
= 0; i
< 0x10000; i
++) {
1400 ret
= _ismbclegal(i
);
1401 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1402 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1408 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1409 _setmbcp(950); /* Chinese (Big5) */
1411 for(i
= 0; i
< 0x10000; i
++) {
1412 ret
= _ismbclegal(i
);
1413 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1414 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1415 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1421 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1422 _setmbcp(1361); /* Korean (Johab) */
1424 for(i
= 0; i
< 0x10000; i
++) {
1425 ret
= _ismbclegal(i
);
1426 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1427 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1428 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1429 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1436 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1441 static const struct {
1443 const char* delimiter
;
1444 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1446 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1448 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1450 } testcases_strtok
[] = {
1451 { "red cabernet", " ", 0, 4, -1 },
1452 { "sparkling white riesling", " ", 0, 10, 16 },
1453 { " pale cream sherry", "e ", 1, 6, 9 },
1458 static void test_strtok(void)
1463 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1464 strcpy( teststr
, testcases_strtok
[i
].string
);
1465 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1466 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1467 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1468 "string (%p) \'%s\' return %p\n",
1469 teststr
, testcases_strtok
[i
].string
, strret
);
1470 if( !strret
) continue;
1471 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1472 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1473 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1474 "second call string (%p) \'%s\' return %p\n",
1475 teststr
, testcases_strtok
[i
].string
, strret
);
1476 if( !strret
) continue;
1477 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1478 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1479 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1480 "third call string (%p) \'%s\' return %p\n",
1481 teststr
, testcases_strtok
[i
].string
, strret
);
1485 static void test_strtol(void)
1487 static char neg
[] = "-0x";
1493 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1494 /* errno is modified on W2K8+ */
1496 l
= strtol("-1234", &e
, 0);
1497 ok(l
==-1234, "wrong value %d\n", l
);
1498 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1500 ul
= strtoul("1234", &e
, 0);
1501 ok(ul
==1234, "wrong value %u\n", ul
);
1502 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1505 l
= strtol("2147483647L", &e
, 0);
1506 ok(l
==2147483647, "wrong value %d\n", l
);
1507 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1509 l
= strtol("-2147483648L", &e
, 0);
1510 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1511 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1513 ul
= strtoul("4294967295UL", &e
, 0);
1514 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1515 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1518 l
= strtol("9223372036854775807L", &e
, 0);
1519 ok(l
==2147483647, "wrong value %d\n", l
);
1520 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1522 ul
= strtoul("9223372036854775807L", &e
, 0);
1523 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1524 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1527 ul
= strtoul("-2", NULL
, 0);
1528 ok(ul
== -2, "wrong value %u\n", ul
);
1529 ok(errno
== 0, "wrong errno %d\n", errno
);
1532 ul
= strtoul("-4294967294", NULL
, 0);
1533 ok(ul
== 2, "wrong value %u\n", ul
);
1534 ok(errno
== 0, "wrong errno %d\n", errno
);
1537 ul
= strtoul("-4294967295", NULL
, 0);
1538 ok(ul
==1, "wrong value %u\n", ul
);
1539 ok(errno
== 0, "wrong errno %d\n", errno
);
1542 ul
= strtoul("-4294967296", NULL
, 0);
1543 ok(ul
== 1, "wrong value %u\n", ul
);
1544 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1547 l
= strtol(neg
, &e
, 0);
1548 ok(l
== 0, "wrong value %d\n", l
);
1549 ok(errno
== 0, "wrong errno %d\n", errno
);
1550 ok(e
== neg
, "e = %p, neg = %p\n", e
, neg
);
1553 static void test_strnlen(void)
1555 static const char str
[] = "string";
1559 win_skip("strnlen not found\n");
1563 res
= p_strnlen(str
, 20);
1564 ok(res
== 6, "Returned length = %d\n", (int)res
);
1566 res
= p_strnlen(str
, 3);
1567 ok(res
== 3, "Returned length = %d\n", (int)res
);
1569 res
= p_strnlen(NULL
, 0);
1570 ok(res
== 0, "Returned length = %d\n", (int)res
);
1573 static void test__strtoi64(void)
1575 static const char no1
[] = "31923";
1576 static const char no2
[] = "-213312";
1577 static const char no3
[] = "12aa";
1578 static const char no4
[] = "abc12";
1579 static const char overflow
[] = "99999999999999999999";
1580 static const char neg_overflow
[] = "-99999999999999999999";
1581 static const char hex
[] = "0x123";
1582 static const char oct
[] = "000123";
1583 static const char blanks
[] = " 12 212.31";
1586 unsigned __int64 ures
;
1589 if(!p_strtoi64
|| !p_strtoui64
) {
1590 win_skip("_strtoi64 or _strtoui64 not found\n");
1595 res
= p_strtoi64(no1
, NULL
, 10);
1596 ok(res
== 31923, "res != 31923\n");
1597 res
= p_strtoi64(no2
, NULL
, 10);
1598 ok(res
== -213312, "res != -213312\n");
1599 res
= p_strtoi64(no3
, NULL
, 10);
1600 ok(res
== 12, "res != 12\n");
1601 res
= p_strtoi64(no4
, &endpos
, 10);
1602 ok(res
== 0, "res != 0\n");
1603 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1604 res
= p_strtoi64(hex
, &endpos
, 10);
1605 ok(res
== 0, "res != 0\n");
1606 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1607 res
= p_strtoi64(oct
, &endpos
, 10);
1608 ok(res
== 123, "res != 123\n");
1609 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1610 res
= p_strtoi64(blanks
, &endpos
, 10);
1611 ok(res
== 12, "res != 12\n");
1612 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1613 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1616 res
= p_strtoi64(overflow
, &endpos
, 10);
1617 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1618 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1619 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1622 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1623 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1624 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1625 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1628 res
= p_strtoi64(no1
, &endpos
, 16);
1629 ok(res
== 203043, "res != 203043\n");
1630 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1631 res
= p_strtoi64(no2
, &endpos
, 16);
1632 ok(res
== -2175762, "res != -2175762\n");
1633 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1634 res
= p_strtoi64(no3
, &endpos
, 16);
1635 ok(res
== 4778, "res != 4778\n");
1636 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1637 res
= p_strtoi64(no4
, &endpos
, 16);
1638 ok(res
== 703506, "res != 703506\n");
1639 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1640 res
= p_strtoi64(hex
, &endpos
, 16);
1641 ok(res
== 291, "res != 291\n");
1642 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1643 res
= p_strtoi64(oct
, &endpos
, 16);
1644 ok(res
== 291, "res != 291\n");
1645 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1646 res
= p_strtoi64(blanks
, &endpos
, 16);
1647 ok(res
== 18, "res != 18\n");
1648 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1649 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1652 res
= p_strtoi64(hex
, &endpos
, 36);
1653 ok(res
== 1541019, "res != 1541019\n");
1654 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1655 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1658 res
= p_strtoi64(no1
, &endpos
, 0);
1659 ok(res
== 31923, "res != 31923\n");
1660 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1661 res
= p_strtoi64(no2
, &endpos
, 0);
1662 ok(res
== -213312, "res != -213312\n");
1663 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1664 res
= p_strtoi64(no3
, &endpos
, 10);
1665 ok(res
== 12, "res != 12\n");
1666 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1667 res
= p_strtoi64(no4
, &endpos
, 10);
1668 ok(res
== 0, "res != 0\n");
1669 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1670 res
= p_strtoi64(hex
, &endpos
, 10);
1671 ok(res
== 0, "res != 0\n");
1672 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1673 res
= p_strtoi64(oct
, &endpos
, 10);
1674 ok(res
== 123, "res != 123\n");
1675 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1676 res
= p_strtoi64(blanks
, &endpos
, 10);
1677 ok(res
== 12, "res != 12\n");
1678 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1679 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1682 ures
= p_strtoui64(no1
, &endpos
, 0);
1683 ok(ures
== 31923, "ures != 31923\n");
1684 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1685 ures
= p_strtoui64(no2
, &endpos
, 0);
1686 ok(ures
== -213312, "ures != -213312\n");
1687 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1688 ures
= p_strtoui64(no3
, &endpos
, 10);
1689 ok(ures
== 12, "ures != 12\n");
1690 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1691 ures
= p_strtoui64(no4
, &endpos
, 10);
1692 ok(ures
== 0, "ures != 0\n");
1693 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1694 ures
= p_strtoui64(hex
, &endpos
, 10);
1695 ok(ures
== 0, "ures != 0\n");
1696 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1697 ures
= p_strtoui64(oct
, &endpos
, 10);
1698 ok(ures
== 123, "ures != 123\n");
1699 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1700 ures
= p_strtoui64(blanks
, &endpos
, 10);
1701 ok(ures
== 12, "ures != 12\n");
1702 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1703 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1706 ures
= p_strtoui64(overflow
, &endpos
, 10);
1707 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1708 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1709 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1712 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1713 ok(ures
== 1, "ures != 1\n");
1714 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1715 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1718 static inline BOOL
almost_equal(double d1
, double d2
) {
1719 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1724 static void test__strtod(void)
1726 const char double1
[] = "12.1";
1727 const char double2
[] = "-13.721";
1728 const char double3
[] = "INF";
1729 const char double4
[] = ".21e12";
1730 const char double5
[] = "214353e-3";
1731 const char double6
[] = "NAN";
1732 const char overflow
[] = "1d9999999999999999999";
1733 const char white_chars
[] = " d10";
1738 d
= strtod(double1
, &end
);
1739 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1740 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1742 d
= strtod(double2
, &end
);
1743 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1744 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1746 d
= strtod(double3
, &end
);
1747 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1748 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1750 d
= strtod(double4
, &end
);
1751 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1752 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1754 d
= strtod(double5
, &end
);
1755 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1756 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1758 d
= strtod(double6
, &end
);
1759 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1760 ok(end
== double6
, "incorrect end (%d)\n", (int)(end
-double6
));
1762 d
= strtod("12.1d2", NULL
);
1763 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1765 d
= strtod(white_chars
, &end
);
1766 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1767 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1770 win_skip("_strtod_l not found\n");
1774 d
= strtod(NULL
, NULL
);
1775 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1776 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1779 end
= (char *)0xdeadbeef;
1780 d
= strtod(NULL
, &end
);
1781 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1782 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1783 ok(!end
, "incorrect end ptr %p\n", end
);
1786 d
= p__strtod_l(NULL
, NULL
, NULL
);
1787 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1788 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1791 /* Set locale with non '.' decimal point (',') */
1792 if(!setlocale(LC_ALL
, "Polish")) {
1793 win_skip("system with limited locales\n");
1797 d
= strtod("12.1", NULL
);
1798 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1800 d
= strtod("12,1", NULL
);
1801 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1803 setlocale(LC_ALL
, "C");
1805 /* Precision tests */
1806 d
= strtod("0.1", NULL
);
1807 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1808 d
= strtod("-0.1", NULL
);
1809 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1810 d
= strtod("0.1281832188491894198128921", NULL
);
1811 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1812 d
= strtod("0.82181281288121", NULL
);
1813 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1814 d
= strtod("21921922352523587651128218821", NULL
);
1815 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1816 d
= strtod("0.1d238", NULL
);
1817 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1818 d
= strtod("0.1D-4736", NULL
);
1819 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1822 strtod(overflow
, &end
);
1823 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1824 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1827 strtod("-1d309", NULL
);
1828 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1831 static void test_mbstowcs(void)
1833 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1834 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1835 static const char mSimple
[] = "text";
1836 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1838 const wchar_t *pwstr
;
1846 wOut
[4] = '!'; wOut
[5] = '\0';
1847 mOut
[4] = '!'; mOut
[5] = '\0';
1850 /* crashes on some systems */
1852 ret
= mbstowcs(wOut
, NULL
, 4);
1853 ok(ret
== -1, "mbstowcs did not return -1\n");
1854 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1857 ret
= mbstowcs(NULL
, mSimple
, 0);
1858 ok(ret
== 4, "mbstowcs did not return 4\n");
1860 ret
= mbstowcs(wOut
, mSimple
, 4);
1861 ok(ret
== 4, "mbstowcs did not return 4\n");
1862 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1863 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1865 ret
= wcstombs(NULL
, wSimple
, 0);
1866 ok(ret
== 4, "wcstombs did not return 4\n");
1868 ret
= wcstombs(mOut
, wSimple
, 6);
1869 ok(ret
== 4, "wcstombs did not return 4\n");
1870 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1872 ret
= wcstombs(mOut
, wSimple
, 2);
1873 ok(ret
== 2, "wcstombs did not return 2\n");
1874 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1876 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
1877 win_skip("Japanese_Japan.932 locale not available\n");
1881 ret
= mbstowcs(wOut
, mHiragana
, 6);
1882 ok(ret
== 2, "mbstowcs did not return 2\n");
1883 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1885 ret
= wcstombs(mOut
, wHiragana
, 6);
1886 ok(ret
== 4, "wcstombs did not return 4\n");
1887 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1889 if(!pmbstowcs_s
|| !pwcstombs_s
) {
1890 setlocale(LC_ALL
, "C");
1891 win_skip("mbstowcs_s or wcstombs_s not available\n");
1895 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
1896 ok(err
== 0, "err = %d\n", err
);
1897 ok(ret
== 5, "mbstowcs_s did not return 5\n");
1898 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1900 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
1901 ok(err
== 0, "err = %d\n", err
);
1902 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1903 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1905 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
1906 ok(err
== 0, "err = %d\n", err
);
1907 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1909 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
1910 ok(err
== 0, "err = %d\n", err
);
1911 ok(ret
== 5, "wcstombs_s did not return 5\n");
1912 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1914 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
1915 ok(err
== 0, "err = %d\n", err
);
1916 ok(ret
== 5, "wcstombs_s did not return 5\n");
1917 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1919 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
1920 ok(err
== 0, "err = %d\n", err
);
1921 ok(ret
== 5, "wcstombs_s did not return 5\n");
1924 setlocale(LC_ALL
, "C");
1925 win_skip("wcsrtombs not available\n");
1931 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
1932 ok(ret
== 4, "wcsrtombs did not return 4\n");
1933 ok(err
== 0, "err = %d\n", err
);
1934 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
1935 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
1938 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
1939 ok(ret
== 4, "wcsrtombs did not return 4\n");
1940 ok(pwstr
== NULL
, "pwstr != NULL\n");
1941 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1944 setlocale(LC_ALL
, "C");
1945 win_skip("mbsrtowcs not available\n");
1950 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
1951 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1952 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1953 ok(!pmbstr
, "pmbstr != NULL\n");
1955 state
= mHiragana
[0];
1956 pmbstr
= mHiragana
+1;
1957 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
1958 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1959 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
1960 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
1961 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
1962 ok(!pmbstr
, "pmbstr != NULL\n");
1965 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
1966 ok(ret
== -1, "mbsrtowcs did not return -1\n");
1967 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1969 setlocale(LC_ALL
, "C");
1972 static void test_gcvt(void)
1974 char buf
[1024], *res
;
1978 win_skip("Skipping _gcvt tests\n");
1983 res
= _gcvt(1.2, -1, buf
);
1984 ok(res
== NULL
, "res != NULL\n");
1985 ok(errno
== ERANGE
, "errno = %d\n", errno
);
1988 res
= _gcvt(1.2, 5, NULL
);
1989 ok(res
== NULL
, "res != NULL\n");
1990 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1992 res
= gcvt(1.2, 5, buf
);
1993 ok(res
== buf
, "res != buf\n");
1994 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
1997 err
= p_gcvt_s(buf
, 5, 1.2, 10);
1998 ok(err
== ERANGE
, "err = %d\n", err
);
1999 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2002 err
= p_gcvt_s(buf
, 4, 123456, 2);
2003 ok(err
== ERANGE
, "err = %d\n", err
);
2004 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2007 static void test__itoa_s(void)
2014 win_skip("Skipping _itoa_s tests\n");
2019 ret
= p_itoa_s(0, NULL
, 0, 0);
2020 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2021 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2023 memset(buffer
, 'X', sizeof(buffer
));
2025 ret
= p_itoa_s(0, buffer
, 0, 0);
2026 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2027 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2028 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2030 memset(buffer
, 'X', sizeof(buffer
));
2032 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
2033 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2034 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2035 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2037 memset(buffer
, 'X', sizeof(buffer
));
2039 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
2040 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2041 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2042 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2044 memset(buffer
, 'X', sizeof(buffer
));
2046 ret
= p_itoa_s(12345678, buffer
, 4, 10);
2047 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2048 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2049 ok(!memcmp(buffer
, "\000765", 4),
2050 "Expected the output buffer to be null terminated with truncated output\n");
2052 memset(buffer
, 'X', sizeof(buffer
));
2054 ret
= p_itoa_s(12345678, buffer
, 8, 10);
2055 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2056 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2057 ok(!memcmp(buffer
, "\0007654321", 8),
2058 "Expected the output buffer to be null terminated with truncated output\n");
2060 memset(buffer
, 'X', sizeof(buffer
));
2062 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
2063 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2064 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2065 ok(!memcmp(buffer
, "\00087654321", 9),
2066 "Expected the output buffer to be null terminated with truncated output\n");
2068 ret
= p_itoa_s(12345678, buffer
, 9, 10);
2069 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2070 ok(!strcmp(buffer
, "12345678"),
2071 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2074 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
2075 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2076 ok(!strcmp(buffer
, "1010101010101010"),
2077 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2080 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
2081 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2082 ok(!strcmp(buffer
, "nell"),
2083 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2086 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
2087 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2088 ok(!strcmp(buffer
, "hag"),
2089 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2092 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
2093 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2094 ok(!strcmp(buffer
, "-12345678"),
2095 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2098 itoa(100, buffer
, 100);
2099 ok(!strcmp(buffer
, "10"),
2100 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
2103 static void test__strlwr_s(void)
2110 win_skip("Skipping _strlwr_s tests\n");
2115 ret
= p_strlwr_s(NULL
, 0);
2116 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2117 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2120 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
2121 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2122 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2125 ret
= p_strlwr_s(buffer
, 0);
2126 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2127 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2129 strcpy(buffer
, "GoRrIsTeR");
2131 ret
= p_strlwr_s(buffer
, 5);
2132 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2133 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2134 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2135 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2137 strcpy(buffer
, "GoRrIsTeR");
2139 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
2140 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2141 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2142 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2143 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2145 strcpy(buffer
, "GoRrIsTeR");
2146 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
2147 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2148 ok(!strcmp(buffer
, "gorrister"),
2149 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2152 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2153 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
2154 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2155 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2156 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2160 static void test_wcsncat_s(void)
2162 static wchar_t abcW
[] = {'a','b','c',0};
2169 win_skip("skipping wcsncat_s tests\n");
2173 memcpy(src
, abcW
, sizeof(abcW
));
2175 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
2176 ok(ret
== EINVAL
, "err = %d\n", ret
);
2177 ret
= p_wcsncat_s(dst
, 0, src
, 4);
2178 ok(ret
== EINVAL
, "err = %d\n", ret
);
2179 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
2180 ok(ret
== EINVAL
, "err = %d\n", ret
);
2181 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
2182 ok(ret
== 0, "err = %d\n", ret
);
2185 ret
= p_wcsncat_s(dst
, 2, src
, 4);
2186 ok(ret
== ERANGE
, "err = %d\n", ret
);
2189 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
2190 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
2191 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2193 memcpy(dst
, abcW
, sizeof(abcW
));
2195 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2196 ok(ret
== EINVAL
, "err = %d\n", ret
);
2199 static void test__mbsnbcat_s(void)
2201 unsigned char dest
[16];
2202 const unsigned char first
[] = "dinosaur";
2203 const unsigned char second
[] = "duck";
2208 win_skip("Skipping _mbsnbcat_s tests\n");
2212 /* Test invalid arguments. */
2213 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2214 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2217 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2218 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2219 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2222 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2223 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2224 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2226 memset(dest
, 'X', sizeof(dest
));
2228 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2229 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2230 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2231 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2233 memset(dest
, 'X', sizeof(dest
));
2235 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2236 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2237 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2238 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2240 memset(dest
, 'X', sizeof(dest
));
2242 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2243 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2244 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2245 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2247 memset(dest
, 'X', sizeof(dest
));
2249 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2250 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2251 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2252 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2254 memset(dest
, 'X', sizeof(dest
));
2256 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2257 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2258 ok(!memcmp(dest
, second
, sizeof(second
)),
2259 "Expected the output buffer string to be \"duck\"\n");
2261 /* Test source truncation behavior. */
2262 memset(dest
, 'X', sizeof(dest
));
2263 memcpy(dest
, first
, sizeof(first
));
2264 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2265 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2266 ok(!memcmp(dest
, first
, sizeof(first
)),
2267 "Expected the output buffer string to be \"dinosaur\"\n");
2269 memset(dest
, 'X', sizeof(dest
));
2270 memcpy(dest
, first
, sizeof(first
));
2271 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2272 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2273 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2274 "Expected the output buffer string to be \"dinosaurduck\"\n");
2276 memset(dest
, 'X', sizeof(dest
));
2277 memcpy(dest
, first
, sizeof(first
));
2278 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2279 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2280 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2281 "Expected the output buffer string to be \"dinosaurduck\"\n");
2283 memset(dest
, 'X', sizeof(dest
));
2284 memcpy(dest
, first
, sizeof(first
));
2285 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2286 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2287 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2288 "Expected the output buffer string to be \"dinosaurduck\"\n");
2290 memset(dest
, 'X', sizeof(dest
));
2291 memcpy(dest
, first
, sizeof(first
));
2292 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2293 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2294 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2295 "Expected the output buffer string to be \"dinosaurduc\"\n");
2297 /* Test destination truncation behavior. */
2298 memset(dest
, 'X', sizeof(dest
));
2299 memcpy(dest
, first
, sizeof(first
));
2301 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2302 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2303 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2304 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2305 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2307 memset(dest
, 'X', sizeof(dest
));
2308 memcpy(dest
, first
, sizeof(first
));
2310 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2311 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2312 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2313 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2314 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2316 memset(dest
, 'X', sizeof(dest
));
2317 memcpy(dest
, first
, sizeof(first
));
2319 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2320 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2321 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2322 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2323 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2326 static void test__mbsupr_s(void)
2329 unsigned char buffer
[20];
2333 win_skip("Skipping _mbsupr_s tests\n");
2338 ret
= p_mbsupr_s(NULL
, 0);
2339 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2342 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2343 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2344 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2347 ret
= p_mbsupr_s(buffer
, 0);
2348 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2349 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2351 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2353 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2354 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2355 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2356 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2359 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2361 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2362 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2363 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2364 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2367 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2369 ret
= p_mbsupr_s(buffer
, 4);
2370 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2371 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2373 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2375 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2376 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2377 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2378 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2383 static void test__mbslwr_s(void)
2386 unsigned char buffer
[20];
2390 win_skip("Skipping _mbslwr_s tests\n");
2395 ret
= p_mbslwr_s(NULL
, 0);
2396 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2399 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2400 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2401 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2404 ret
= p_mbslwr_s(buffer
, 0);
2405 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2406 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2408 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2410 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2411 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2412 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2413 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2416 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2418 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2419 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2420 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2421 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2424 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2426 ret
= p_mbslwr_s(buffer
, 4);
2427 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2428 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2430 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2432 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2433 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2434 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2435 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2439 static void test__mbstok(void)
2441 const unsigned char delim
[] = "t";
2443 char str
[] = "!.!test";
2448 ret
= _mbstok(NULL
, delim
);
2449 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2450 ok(!ret
|| broken((char*)ret
==str
+4),
2451 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2453 ret
= _mbstok(NULL
, delim
);
2454 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2457 static void test__ultoa_s(void)
2464 win_skip("Skipping _ultoa_s tests\n");
2469 ret
= p_ultoa_s(0, NULL
, 0, 0);
2470 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2471 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2473 memset(buffer
, 'X', sizeof(buffer
));
2475 ret
= p_ultoa_s(0, buffer
, 0, 0);
2476 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2477 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2478 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2480 memset(buffer
, 'X', sizeof(buffer
));
2482 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2483 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2484 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2485 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2487 memset(buffer
, 'X', sizeof(buffer
));
2489 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2490 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2491 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2492 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2494 memset(buffer
, 'X', sizeof(buffer
));
2496 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2497 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2498 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2499 ok(!memcmp(buffer
, "\000765", 4),
2500 "Expected the output buffer to be null terminated with truncated output\n");
2502 memset(buffer
, 'X', sizeof(buffer
));
2504 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2505 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2506 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2507 ok(!memcmp(buffer
, "\0007654321", 8),
2508 "Expected the output buffer to be null terminated with truncated output\n");
2510 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2511 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2512 ok(!strcmp(buffer
, "12345678"),
2513 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2516 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2517 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2518 ok(!strcmp(buffer
, "1010101010101010"),
2519 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2522 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2523 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2524 ok(!strcmp(buffer
, "nell"),
2525 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2528 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2529 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2530 ok(!strcmp(buffer
, "hag"),
2531 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2535 static void test_wctob(void)
2539 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2540 win_skip("Skipping wctob tests\n");
2544 ret
= p_wctob(0x8141);
2545 ok(ret
== EOF
, "ret = %x\n", ret
);
2547 ret
= p_wctob(0x81);
2548 ok(ret
== EOF
, "ret = %x\n", ret
);
2550 ret
= p_wctob(0xe0);
2551 ok(ret
== 0x61, "ret = %x\n", ret
);
2554 ret
= p_wctob(0x81);
2555 ok(ret
== EOF
, "ret = %x\n", ret
);
2557 setlocale(LC_ALL
, "C");
2558 ret
= p_wctob(0x8141);
2559 ok(ret
== EOF
, "ret = %x\n", ret
);
2561 ret
= p_wctob(0x81);
2562 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2564 ret
= p_wctob(0x9f);
2565 ok(ret
== (int)(char)0x9f, "ret = %x\n", ret
);
2567 ret
= p_wctob(0xe0);
2568 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2570 static void test_wctomb(void)
2573 unsigned char dst
[10];
2576 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
2577 win_skip("wcrtomb tests\n");
2581 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
2582 ok(ret
== 2, "wcrtomb did not return 2\n");
2586 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
2587 ok(ret
== 2, "wcrtomb did not return 2\n");
2588 ok(state
== 0, "state != 0\n");
2589 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2590 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
2591 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
2593 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
2594 ok(ret
== 2, "wcrtomb did not return 2\n");
2595 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2596 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
2598 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
2599 ok(ret
== 1, "wcrtomb did not return 1\n");
2600 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
2602 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
2603 ok(ret
== -1, "wcrtomb did not return -1\n");
2604 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
2606 setlocale(LC_ALL
, "C");
2609 static void test_tolower(void)
2615 /* test C locale when locale was never changed */
2616 ret
= p_tolower(0x41);
2617 ok(ret
== 0x61, "ret = %x\n", ret
);
2619 ret
= p_tolower(0xF4);
2620 ok(ret
== 0xF4, "ret = %x\n", ret
);
2623 ret
= p_tolower((char)0xF4);
2624 todo_wine
ok(ret
== (char)0xF4, "ret = %x\n", ret
);
2625 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2628 ret
= p_tolower((char)0xD0);
2629 todo_wine
ok(ret
== (char)0xD0, "ret = %x\n", ret
);
2630 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2632 /* test C locale after setting locale */
2633 if(!setlocale(LC_ALL
, "us")) {
2634 win_skip("skipping tolower tests that depends on locale\n");
2637 setlocale(LC_ALL
, "C");
2641 ret
= p_tolower(ch
);
2642 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
2643 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
2644 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
2647 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2649 ok(ret
== ch
, "ret = %x\n", ret
);
2650 if(!len
|| ret
==(unsigned char)lch
)
2651 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2655 ret
= p_tolower(ch
);
2656 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
2657 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
2658 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
2661 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2663 ok(ret
== ch
, "ret = %x\n", ret
);
2664 if(!len
|| ret
==(unsigned char)lch
)
2665 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2667 ret
= p_tolower(0xD0);
2668 ok(ret
== 0xD0, "ret = %x\n", ret
);
2670 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
2672 ret
= p_tolower((char)0xD0);
2673 ok(ret
== 0xF0, "ret = %x\n", ret
);
2675 ret
= p_tolower(0xD0);
2676 ok(ret
== 0xF0, "ret = %x\n", ret
);
2678 setlocale(LC_ALL
, "C");
2681 static void test__atodbl(void)
2688 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2689 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2690 win_skip("_atodbl_l is not available\n");
2695 ret
= p__atodbl_l(&d
, num
, NULL
);
2696 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
2697 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2698 ret
= _atodbl(&d
, num
);
2699 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
2700 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2703 ret
= p__atodbl_l(&d
, num
, NULL
);
2704 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
2705 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2706 ret
= _atodbl(&d
, num
);
2707 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
2708 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2711 ret
= p__atodbl_l(&d
, num
, NULL
);
2712 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
2713 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2714 ret
= _atodbl(&d
, num
);
2715 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
2716 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2719 ret
= p__atodbl_l(&d
, num
, NULL
);
2720 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
2721 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2722 ret
= _atodbl(&d
, num
);
2723 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
2724 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2726 strcpy(num
, "1e-309");
2727 ret
= p__atodbl_l(&d
, num
, NULL
);
2728 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
2729 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2730 ret
= _atodbl(&d
, num
);
2731 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
2732 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2734 strcpy(num
, "1e309");
2735 ret
= p__atodbl_l(&d
, num
, NULL
);
2736 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
2737 ret
= _atodbl(&d
, num
);
2738 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
2741 static void test__stricmp(void)
2745 ret
= _stricmp("test", "test");
2746 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2747 ret
= _stricmp("a", "z");
2748 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2749 ret
= _stricmp("z", "a");
2750 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2751 ret
= _stricmp("\xa5", "\xb9");
2752 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2754 if(!setlocale(LC_ALL
, "polish")) {
2755 win_skip("stricmp tests\n");
2759 ret
= _stricmp("test", "test");
2760 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2761 ret
= _stricmp("a", "z");
2762 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2763 ret
= _stricmp("z", "a");
2764 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2765 ret
= _stricmp("\xa5", "\xb9");
2766 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2767 ret
= _stricmp("a", "\xb9");
2768 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2770 setlocale(LC_ALL
, "C");
2773 static void test__wcstoi64(void)
2775 static const WCHAR digit
[] = { '9', 0 };
2776 static const WCHAR stock
[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2777 static const WCHAR tamil
[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2778 static const WCHAR thai
[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2779 static const WCHAR fullwidth
[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2780 static const WCHAR hex
[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
2783 unsigned __int64 ures
;
2786 if (!p_wcstoi64
|| !p_wcstoui64
) {
2787 win_skip("_wcstoi64 or _wcstoui64 not found\n");
2791 res
= p_wcstoi64(digit
, NULL
, 10);
2792 ok(res
== 9, "res != 9\n");
2793 res
= p_wcstoi64(stock
, &endpos
, 10);
2794 ok(res
== 0, "res != 0\n");
2795 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2796 res
= p_wcstoi64(tamil
, &endpos
, 10);
2797 ok(res
== 0, "res != 0\n");
2798 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2799 res
= p_wcstoi64(thai
, NULL
, 10);
2800 todo_wine
ok(res
== 9, "res != 9\n");
2801 res
= p_wcstoi64(fullwidth
, NULL
, 10);
2802 todo_wine
ok(res
== 9, "res != 9\n");
2803 res
= p_wcstoi64(hex
, NULL
, 16);
2804 todo_wine
ok(res
== 0x9f9, "res != 0x9f9\n");
2806 ures
= p_wcstoui64(digit
, NULL
, 10);
2807 ok(ures
== 9, "ures != 9\n");
2808 ures
= p_wcstoui64(stock
, &endpos
, 10);
2809 ok(ures
== 0, "ures != 0\n");
2810 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2811 ures
= p_wcstoui64(tamil
, &endpos
, 10);
2812 ok(ures
== 0, "ures != 0\n");
2813 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2814 ures
= p_wcstoui64(thai
, NULL
, 10);
2815 todo_wine
ok(ures
== 9, "ures != 9\n");
2816 ures
= p_wcstoui64(fullwidth
, NULL
, 10);
2817 todo_wine
ok(ures
== 9, "ures != 9\n");
2818 ures
= p_wcstoui64(hex
, NULL
, 16);
2819 todo_wine
ok(ures
== 0x9f9, "ures != 0x9f9\n");
2824 static void test_atoi(void)
2829 ok(r
== 0, "atoi(0) = %d\n", r
);
2832 ok(r
== -1, "atoi(-1) = %d\n", r
);
2835 ok(r
== 1, "atoi(1) = %d\n", r
);
2837 r
= atoi("4294967296");
2838 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
2841 static void test_atof(void)
2846 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
2849 ok(almost_equal(d
, 1.0), "d = %lf\n", d
);
2852 ok(almost_equal(d
, -1.0), "d = %lf\n", d
);
2856 win_skip("_atof_l not found\n");
2862 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
2863 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2866 d
= p__atof_l(NULL
, NULL
);
2867 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
2868 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2871 static void test_strncpy(void)
2873 #define TEST_STRNCPY_LEN 10
2875 char dst
[TEST_STRNCPY_LEN
+ 1];
2876 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
2878 /* strlen(src) > TEST_STRNCPY_LEN */
2879 ret
= strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
2880 ok(ret
== dst
, "ret != dst\n");
2881 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2883 /* without null-terminated */
2884 ret
= strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
2885 ok(ret
== dst
, "ret != dst\n");
2886 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2888 /* strlen(src) < TEST_STRNCPY_LEN */
2889 strcpy(dst
, "0123456789");
2890 ret
= strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
2891 ok(ret
== dst
, "ret != dst\n");
2892 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
2893 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
2895 /* strlen(src) == TEST_STRNCPY_LEN */
2896 ret
= strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
2897 ok(ret
== dst
, "ret != dst\n");
2898 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2901 static void test_strxfrm(void)
2906 /* crashes on old version of msvcrt */
2909 ret
= strxfrm(NULL
, "src", 1);
2910 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
2911 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2914 ret
= strxfrm(dest
, NULL
, 100);
2915 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
2916 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2919 ret
= strxfrm(NULL
, "src", 0);
2920 ok(ret
== 3, "ret = %d\n", (int)ret
);
2922 ret
= strxfrm(dest
, "src", 0);
2923 ok(ret
== 3, "ret = %d\n", (int)ret
);
2924 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
2927 ret
= strxfrm(dest
, "src", 5);
2928 ok(ret
== 3, "ret = %d\n", (int)ret
);
2929 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
2933 ret
= strxfrm(dest
, "src", 1);
2934 ok(ret
== 3, "ret = %d\n", (int)ret
);
2935 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
2936 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
2937 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2939 ret
= strxfrm(dest
, "", 5);
2940 ok(ret
== 0, "ret = %d\n", (int)ret
);
2941 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
2943 if(!setlocale(LC_ALL
, "polish")) {
2944 win_skip("stxfrm tests\n");
2948 ret
= strxfrm(NULL
, "src", 0);
2949 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2951 ret
= strxfrm(dest
, "src", 0);
2952 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2953 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
2955 ret
= strxfrm(dest
, "src", ret
+1);
2956 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2957 ok(dest
[0], "dest[0] = 0\n");
2961 ret
= strxfrm(dest
, "src", 5);
2962 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2963 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
2965 setlocale(LC_ALL
, "C");
2968 static void test__strnset_s(void)
2974 win_skip("_strnset_s not available\n");
2978 r
= p__strnset_s(NULL
, 0, 'a', 0);
2979 ok(r
== 0, "r = %d\n", r
);
2981 buf
[0] = buf
[1] = buf
[2] = 'b';
2982 r
= p__strnset_s(buf
, sizeof(buf
), 'a', 2);
2983 ok(r
== 0, "r = %d\n", r
);
2984 ok(!strcmp(buf
, "aab"), "buf = %s\n", buf
);
2986 r
= p__strnset_s(buf
, 0, 'a', 0);
2987 ok(r
== EINVAL
, "r = %d\n", r
);
2989 r
= p__strnset_s(NULL
, 0, 'a', 1);
2990 ok(r
== EINVAL
, "r = %d\n", r
);
2993 r
= p__strnset_s(buf
, sizeof(buf
)-1, 'c', 2);
2994 ok(r
== EINVAL
, "r = %d\n", r
);
2995 ok(!buf
[0] && buf
[1]=='c' && buf
[2]=='b', "buf = %s\n", buf
);
2998 static void test__wcsset_s(void)
3004 win_skip("_wcsset_s not available\n");
3008 r
= p__wcsset_s(NULL
, 0, 'a');
3009 ok(r
== EINVAL
, "r = %d\n", r
);
3012 r
= p__wcsset_s(str
, 0, 'a');
3013 ok(r
== EINVAL
, "r = %d\n", r
);
3014 ok(str
[0] == 'a', "str[0] = %d\n", str
[0]);
3018 r
= p__wcsset_s(str
, 2, 'c');
3019 ok(r
== EINVAL
, "r = %d\n", r
);
3020 ok(!str
[0], "str[0] = %d\n", str
[0]);
3021 ok(str
[1] == 'b', "str[1] = %d\n", str
[1]);
3026 r
= p__wcsset_s(str
, 3, 'c');
3027 ok(str
[0] == 'c', "str[0] = %d\n", str
[0]);
3028 ok(str
[1] == 0, "str[1] = %d\n", str
[1]);
3029 ok(str
[2] == 'b', "str[2] = %d\n", str
[2]);
3032 static void test__mbscmp(void)
3034 static const unsigned char a
[] = {'a',0}, b
[] = {'b',0};
3039 win_skip("_mbscmp tests\n");
3043 ret
= _mbscmp(NULL
, NULL
);
3044 ok(ret
== INT_MAX
, "got %d\n", ret
);
3046 ret
= _mbscmp(a
, NULL
);
3047 ok(ret
== INT_MAX
, "got %d\n", ret
);
3049 ret
= _mbscmp(NULL
, a
);
3050 ok(ret
== INT_MAX
, "got %d\n", ret
);
3052 ret
= _mbscmp(a
, a
);
3053 ok(!ret
, "got %d\n", ret
);
3055 ret
= _mbscmp(a
, b
);
3056 ok(ret
== -1, "got %d\n", ret
);
3058 ret
= _mbscmp(b
, a
);
3059 ok(ret
== 1, "got %d\n", ret
);
3065 static const char xilstring
[]="c:/xilinx";
3068 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
3070 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
3071 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
3072 SET(pmemcpy
,"memcpy");
3073 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
3074 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
3075 SET(pmemcmp
,"memcmp");
3076 SET(p_mbctype
,"_mbctype");
3077 SET(p__mb_cur_max
,"__mb_cur_max");
3078 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
3079 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
3080 p_mbscat_s
= (void*)GetProcAddress( hMsvcrt
, "_mbscat_s" );
3081 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
3082 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
3083 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
3084 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
3085 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
3086 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
3087 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
3088 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
3089 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
3090 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
3091 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
3092 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
3093 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
3094 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
3095 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
3096 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
3097 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
3098 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
3099 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
3100 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
3101 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
3102 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
3103 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
3104 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
3105 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
3106 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
3107 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
3108 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
3109 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
3110 p__atof_l
= (void*)GetProcAddress(hMsvcrt
, "_atof_l");
3111 p__strtod_l
= (void*)GetProcAddress(hMsvcrt
, "_strtod_l");
3112 p__strnset_s
= (void*)GetProcAddress(hMsvcrt
, "_strnset_s");
3113 p__wcsset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsset_s");
3115 /* MSVCRT memcpy behaves like memmove for overlapping moves,
3116 MFC42 CString::Insert seems to rely on that behaviour */
3117 strcpy(mem
,xilstring
);
3118 nLen
=strlen(xilstring
);
3119 pmemcpy(mem
+5, mem
,nLen
+1);
3120 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
3121 "Got result %s\n",mem
+5);
3123 /* run tolower tests first */