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 int (__cdecl
*p_mbsrtowcs_s
)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
78 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
79 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
80 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
81 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
82 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
83 static int *p__mb_cur_max
;
84 static unsigned char *p_mbctype
;
85 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
86 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
87 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
88 static int (__cdecl
*p_wctob
)(wint_t);
89 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
90 static int (__cdecl
*p_tolower
)(int);
91 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
92 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
93 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
94 static double (__cdecl
*p__atof_l
)(const char*,_locale_t
);
95 static double (__cdecl
*p__strtod_l
)(const char *,char**,_locale_t
);
96 static int (__cdecl
*p__strnset_s
)(char*,size_t,int,size_t);
97 static int (__cdecl
*p__wcsset_s
)(wchar_t*,size_t,wchar_t);
99 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
100 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
102 static HMODULE hMsvcrt
;
104 static void test_swab( void ) {
105 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
106 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
107 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
108 char expected3
[] = "$";
115 /* Test 1 - normal even case */
116 memset(to
,'$', sizeof(to
));
117 memset(from
,'@', sizeof(from
));
119 memcpy(from
, original
, testsize
);
120 _swab( from
, to
, testsize
);
121 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
123 /* Test 2 - uneven case */
124 memset(to
,'$', sizeof(to
));
125 memset(from
,'@', sizeof(from
));
127 memcpy(from
, original
, testsize
);
128 _swab( from
, to
, testsize
);
129 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
131 /* Test 3 - from = to */
132 memset(to
,'$', sizeof(to
));
133 memset(from
,'@', sizeof(from
));
135 memcpy(to
, original
, testsize
);
136 _swab( to
, to
, testsize
);
137 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
139 /* Test 4 - 1 bytes */
140 memset(to
,'$', sizeof(to
));
141 memset(from
,'@', sizeof(from
));
143 memcpy(from
, original
, testsize
);
144 _swab( from
, to
, testsize
);
145 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
148 #if 0 /* use this to generate more tests */
150 static void test_codepage(int cp
)
156 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
159 printf("static int result_cp_%d_mbctype[] = { ", cp
);
160 for (i
= 1; i
< 257; i
++)
162 if (p_mbctype
[i
] != prev
)
164 printf("0x%x,%d, ", prev
, count
);
171 printf("0x%x,%d };\n", prev
, count
);
176 /* RLE-encoded mbctype tables for given codepages */
177 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
178 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
179 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
181 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
183 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
184 0x0,2, 0x4,32, 0xc,94, 0,1 };
186 static void test_cp_table(int cp
, int *result
)
192 for (i
= 0; i
< 256; i
++)
200 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
);
205 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
209 static void test_mbcp(void)
211 int mb_orig_max
= *p__mb_cur_max
;
212 int curr_mbcp
= _getmbcp();
213 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
214 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
215 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
216 unsigned char buf
[16];
222 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
223 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
224 * CP1252 (or the ACP?) so we test only a few ASCII characters */
226 expect_eq(p_mbctype
[10], 0, char, "%x");
227 expect_eq(p_mbctype
[50], 0, char, "%x");
228 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
229 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
230 expect_eq(p_mbctype
[128], 0, char, "%x");
232 expect_eq(p_mbctype
[10], 0, char, "%x");
233 expect_eq(p_mbctype
[50], 0, char, "%x");
234 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
235 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
236 expect_eq(p_mbctype
[128], 0, char, "%x");
238 /* double byte code pages */
245 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
);
246 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
247 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
248 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
249 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
250 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
251 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
254 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
255 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
256 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
257 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
258 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
259 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
260 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
261 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
262 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
264 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
265 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
266 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
267 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
270 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
271 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
272 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
273 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
274 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
275 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
276 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
277 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
278 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
280 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
281 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
282 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
283 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
284 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
285 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
288 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
289 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
290 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
291 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
292 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
293 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
294 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
295 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
296 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
298 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
299 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
300 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
301 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
302 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
303 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
306 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
307 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
308 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
310 /* _mbclen/_mbslen */
311 expect_eq(_mbclen(mbstring
), 2, int, "%d");
312 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
313 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
314 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
315 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
316 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
319 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
320 win_skip("mbrlen tests\n");
323 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
324 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
325 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
326 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
327 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
328 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
329 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
333 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
334 win_skip("mbrtowc tests\n");
338 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
339 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
340 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
341 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
342 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
343 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
344 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
345 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
346 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
347 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
348 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
349 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
350 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
351 ok(state
== 0, "incorrect state value (%x)\n", state
);
353 setlocale(LC_ALL
, "C");
355 /* _mbccpy/_mbsncpy */
356 memset(buf
, 0xff, sizeof(buf
));
357 _mbccpy(buf
, mbstring
);
358 expect_bin(buf
, "\xb0\xb1\xff", 3);
360 memset(buf
, 0xff, sizeof(buf
));
361 _mbsncpy(buf
, mbstring
, 1);
362 expect_bin(buf
, "\xb0\xb1\xff", 3);
363 memset(buf
, 0xff, sizeof(buf
));
364 _mbsncpy(buf
, mbstring
, 2);
365 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
366 memset(buf
, 0xff, sizeof(buf
));
367 _mbsncpy(buf
, mbstring
, 3);
368 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
369 memset(buf
, 0xff, sizeof(buf
));
370 _mbsncpy(buf
, mbstring
, 4);
371 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
372 memset(buf
, 0xff, sizeof(buf
));
373 _mbsncpy(buf
, mbstring
, 5);
374 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
375 memset(buf
, 0xff, sizeof(buf
));
376 _mbsncpy(buf
, mbsonlylead
, 6);
377 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
379 memset(buf
, 0xff, sizeof(buf
));
380 _mbsnbcpy(buf
, mbstring2
, 2);
381 expect_bin(buf
, "\xb0\xb1\xff", 3);
382 _mbsnbcpy(buf
, mbstring2
, 3);
383 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
384 _mbsnbcpy(buf
, mbstring2
, 4);
385 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
386 memset(buf
, 0xff, sizeof(buf
));
387 _mbsnbcpy(buf
, mbsonlylead
, 5);
388 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
391 step
= _mbsinc(mbstring
) - mbstring
;
392 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
393 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
394 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
396 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
397 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
398 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
399 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
400 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
401 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
402 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
403 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
404 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
405 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
406 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
407 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
408 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
409 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
410 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
411 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
412 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
413 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
415 /* functions that depend on locale codepage, not mbcp.
416 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
417 * (as of Wine 0.9.43)
419 GetCPInfo(GetACP(), &cp_info
);
420 if (cp_info
.MaxCharSize
== 1)
422 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
423 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
426 skip("Current locale has double-byte charset - could lead to false positives\n");
429 expect_eq(_ismbblead(0x80), 0, int, "%d");
431 expect_eq(_ismbblead(0x81), 1, int, "%d");
432 expect_eq(_ismbblead(0x83), 1, int, "%d");
434 expect_eq(_ismbblead(0x84), 1, int, "%d");
435 expect_eq(_ismbblead(0xd3), 1, int, "%d");
436 expect_eq(_ismbblead(0xd7), 0, int, "%d");
437 expect_eq(_ismbblead(0xd8), 1, int, "%d");
438 expect_eq(_ismbblead(0xd9), 1, int, "%d");
440 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
441 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
442 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
443 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
444 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
445 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
446 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
447 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
452 static void test_mbsspn( void)
454 unsigned char str1
[]="cabernet";
455 unsigned char str2
[]="shiraz";
456 unsigned char set
[]="abc";
457 unsigned char empty
[]="";
459 ret
=_mbsspn( str1
, set
);
460 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
461 ret
=_mbsspn( str2
, set
);
462 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
463 ret
=_mbsspn( str1
, empty
);
464 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
467 static void test_mbsspnp( void)
469 unsigned char str1
[]="cabernet";
470 unsigned char str2
[]="shiraz";
471 unsigned char set
[]="abc";
472 unsigned char empty
[]="";
473 unsigned char full
[]="abcenrt";
475 ret
=_mbsspnp( str1
, set
);
476 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
477 ret
=_mbsspnp( str2
, set
);
478 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
479 ret
=_mbsspnp( str1
, empty
);
480 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
481 ret
=_mbsspnp( str1
, full
);
482 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
485 static void test_strdup(void)
489 ok( str
== 0, "strdup returns %s should be 0\n", str
);
493 static void test_strcpy_s(void)
496 const char *small
= "small";
497 const char *big
= "atoolongstringforthislittledestination";
502 win_skip("strcpy_s not found\n");
506 memset(dest
, 'X', sizeof(dest
));
507 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
508 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
509 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
510 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
511 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
512 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
514 memset(dest
, 'X', sizeof(dest
));
515 ret
= pstrcpy_s(dest
, 0, big
);
516 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
517 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
518 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
519 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
520 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
521 ret
= pstrcpy_s(dest
, 0, NULL
);
522 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
523 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
524 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
525 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
526 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
528 memset(dest
, 'X', sizeof(dest
));
529 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
530 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
531 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
532 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
533 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
534 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
536 memset(dest
, 'X', sizeof(dest
));
537 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
538 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
539 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
540 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
541 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
542 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
544 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
545 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
548 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
550 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
551 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
552 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
553 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
554 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
556 static void test_memcpy_s(void)
559 static const char tiny
[] = {'T',0,'I','N','Y',0};
560 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
563 win_skip("memcpy_s not found\n");
568 memset(dest
, 'X', sizeof(dest
));
569 ret
= p_memcpy_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
570 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
571 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
573 /* Vary source size */
575 memset(dest
, 'X', sizeof(dest
));
576 ret
= p_memcpy_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
577 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
578 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
579 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
581 /* Replace source with NULL */
583 memset(dest
, 'X', sizeof(dest
));
584 ret
= p_memcpy_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
585 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
586 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
587 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
591 memset(dest
, 'X', sizeof(dest
));
592 ret
= p_memcpy_s(dest
, 0, tiny
, NUMELMS(tiny
));
593 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
594 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
595 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
597 /* Replace dest with NULL */
599 ret
= p_memcpy_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
600 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
601 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
605 memset(dest
, 'X', sizeof(dest
));
606 ret
= p_memcpy_s(dest
, 0, NULL
, NUMELMS(tiny
));
607 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
608 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
609 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
612 static void test_memmove_s(void)
615 static const char tiny
[] = {'T',0,'I','N','Y',0};
616 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
619 win_skip("memmove_s not found\n");
624 memset(dest
, 'X', sizeof(dest
));
625 ret
= p_memmove_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
626 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
627 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
630 memcpy(dest
, big
, sizeof(dest
));
631 ret
= p_memmove_s(dest
+1, NUMELMS(dest
)-1, dest
, NUMELMS(dest
)-1);
632 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
633 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
635 /* Vary source size */
637 memset(dest
, 'X', sizeof(dest
));
638 ret
= p_memmove_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
639 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
640 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
641 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
643 /* Replace source with NULL */
645 memset(dest
, 'X', sizeof(dest
));
646 ret
= p_memmove_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
647 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
648 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
649 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
653 memset(dest
, 'X', sizeof(dest
));
654 ret
= p_memmove_s(dest
, 0, tiny
, NUMELMS(tiny
));
655 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
656 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
657 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
659 /* Replace dest with NULL */
661 ret
= p_memmove_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
662 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
663 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
667 memset(dest
, 'X', sizeof(dest
));
668 ret
= p_memmove_s(dest
, 0, NULL
, NUMELMS(tiny
));
669 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
670 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
671 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
674 static void test_strcat_s(void)
677 const char *small
= "sma";
682 win_skip("strcat_s not found\n");
686 memset(dest
, 'X', sizeof(dest
));
688 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
689 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
690 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
691 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
692 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
693 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
694 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
695 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
696 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
697 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
698 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
699 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
701 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
702 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
703 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
704 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
705 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
706 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
708 memset(dest
, 'X', sizeof(dest
));
712 ret
= pstrcat_s(dest
, 0, small
);
713 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
714 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
715 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
716 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
717 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
719 ret
= pstrcat_s(dest
, 0, NULL
);
720 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
721 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
722 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
723 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
724 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
726 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
727 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
728 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
729 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
730 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
731 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
733 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
734 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
737 static void test__mbscat_s(void)
739 unsigned char dst
[8], src
[4];
741 int prev_cp
= _getmbcp();
745 win_skip("_mbscat_s not found\n");
751 err
= p_mbscat_s(NULL
, sizeof(dst
), src
);
752 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
754 err
= p_mbscat_s(dst
, sizeof(dst
), NULL
);
755 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
758 err
= p_mbscat_s(dst
, 1, src
);
759 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
761 memset(dst
, 'a', sizeof(dst
));
766 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
767 ok(err
== 0, "_mbscat_s returned %d\n", err
);
768 ok(!memcmp(dst
, "aaaaaab", 8), "dst = %s\n", dst
);
770 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
771 ok(err
== ERANGE
, "_mbscat_s returned %d\n", err
);
772 ok(!dst
[0], "dst[0] = %c\n", dst
[0]);
773 ok(dst
[1] == 'a', "dst[1] = %c\n", dst
[1]);
776 /* test invalid str in dst */
783 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
784 ok(err
== 0, "_mbscat_s returned %d\n", err
);
786 /* test invalid str in src */
792 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
793 ok(err
== 0, "_mbscat_s returned %d\n", err
);
795 /* test dst with leading byte on the end of buffer */
801 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
802 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
803 ok(!memcmp(dst
, "aR", 3), "dst = %s\n", dst
);
805 /* test src with leading byte on the end of buffer */
811 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
812 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
813 ok(!memcmp(dst
, "ab", 3), "dst = %s\n", dst
);
817 static void test__mbsnbcpy_s(void)
819 unsigned char dest
[8];
820 const unsigned char big
[] = "atoolongstringforthislittledestination";
821 const unsigned char small
[] = "small";
826 win_skip("_mbsnbcpy_s not found\n");
830 memset(dest
, 'X', sizeof(dest
));
831 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
832 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
833 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
834 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
835 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
836 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
839 memset(dest
, 'X', sizeof(dest
));
840 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
841 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
842 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
843 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
844 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
845 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
847 memset(dest
, 'X', sizeof(dest
));
848 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
849 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
850 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
851 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
852 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
853 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
855 memset(dest
, 'X', sizeof(dest
));
856 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
857 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
858 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
859 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
860 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
861 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
864 static void test__mbscpy_s(void)
866 const unsigned char src
[] = "source string";
867 unsigned char dest
[16];
872 win_skip("_mbscpy_s not found\n");
876 ret
= p__mbscpy_s(NULL
, 0, src
);
877 ok(ret
== EINVAL
, "got %d\n", ret
);
878 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
879 ok(ret
== EINVAL
, "got %d\n", ret
);
880 ret
= p__mbscpy_s(dest
, 0, src
);
881 ok(ret
== EINVAL
, "got %d\n", ret
);
883 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
884 ok(ret
== EINVAL
, "got %d\n", ret
);
885 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
887 memset(dest
, 'X', sizeof(dest
));
888 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
889 ok(!ret
, "got %d\n", ret
);
890 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
891 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
893 memset(dest
, 'X', sizeof(dest
));
894 ret
= p__mbscpy_s(dest
, 4, src
);
895 ok(ret
== ERANGE
, "got %d\n", ret
);
896 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
897 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
900 static void test_wcscpy_s(void)
902 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
903 static WCHAR szDest
[18];
904 static WCHAR szDestShort
[8];
909 win_skip("wcscpy_s not found\n");
915 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
916 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
917 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
919 /* Test NULL Source */
922 ret
= p_wcscpy_s(szDest
, 18, NULL
);
923 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
924 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
925 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
927 /* Test invalid size */
930 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
931 /* Later versions changed the return value for this case to EINVAL,
932 * and don't modify the result if the dest size is 0.
934 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
935 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
936 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
938 /* Copy same buffer size */
939 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
940 ok(ret
== 0, "expected 0 got %d\n", ret
);
941 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
943 /* Copy smaller buffer size */
946 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
947 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
948 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
949 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
953 win_skip("wcsncpy_s not found\n");
957 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
958 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
961 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
962 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
963 ok(szDest
[0] == 0, "szDest[0] not 0\n");
966 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
967 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
968 ok(szDest
[0] == 0, "szDest[0] not 0\n");
971 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
972 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
973 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
975 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
976 ok(ret
== 0, "expected 0 got %d\n", ret
);
977 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
980 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
981 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
982 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
985 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
986 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
987 ok(szDest
[4] == 0, "szDest[4] not 0\n");
988 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
990 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
991 ok(ret
== 0, "ret = %d\n", ret
);
993 szDestShort
[0] = '1';
995 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
996 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
997 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
998 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
1001 static void test__wcsupr_s(void)
1003 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1004 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1005 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
1006 'W', 'E', 'R', 'U', 'P', 'P', 'E',
1008 WCHAR testBuffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
1013 win_skip("_wcsupr_s not found\n");
1017 /* Test NULL input string and invalid size. */
1019 ret
= p_wcsupr_s(NULL
, 0);
1020 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1021 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1023 /* Test NULL input string and valid size. */
1025 ret
= p_wcsupr_s(NULL
, sizeof(testBuffer
)/sizeof(WCHAR
));
1026 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1027 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1029 /* Test empty string with zero size. */
1031 testBuffer
[0] = '\0';
1032 ret
= p_wcsupr_s(testBuffer
, 0);
1033 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1034 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1035 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1037 /* Test empty string with size of one. */
1038 testBuffer
[0] = '\0';
1039 ret
= p_wcsupr_s(testBuffer
, 1);
1040 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1041 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1043 /* Test one-byte buffer with zero size. */
1045 testBuffer
[0] = 'x';
1046 ret
= p_wcsupr_s(testBuffer
, 0);
1047 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1048 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1049 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1051 /* Test one-byte buffer with size of one. */
1053 testBuffer
[0] = 'x';
1054 ret
= p_wcsupr_s(testBuffer
, 1);
1055 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1056 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1057 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1059 /* Test invalid size. */
1060 wcscpy(testBuffer
, mixedString
);
1062 ret
= p_wcsupr_s(testBuffer
, 0);
1063 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1064 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1065 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1067 /* Test normal string uppercasing. */
1068 wcscpy(testBuffer
, mixedString
);
1069 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
));
1070 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1071 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1073 /* Test uppercasing with a shorter buffer size count. */
1074 wcscpy(testBuffer
, mixedString
);
1076 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
1077 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1078 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1079 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1081 /* Test uppercasing with a longer buffer size count. */
1082 wcscpy(testBuffer
, mixedString
);
1083 ret
= p_wcsupr_s(testBuffer
, sizeof(testBuffer
)/sizeof(WCHAR
));
1084 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1085 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1088 static void test__wcslwr_s(void)
1090 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1091 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1092 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1093 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1095 WCHAR buffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
1100 win_skip("_wcslwr_s not found\n");
1104 /* Test NULL input string and invalid size. */
1106 ret
= p_wcslwr_s(NULL
, 0);
1107 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1108 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1110 /* Test NULL input string and valid size. */
1112 ret
= p_wcslwr_s(NULL
, sizeof(buffer
)/sizeof(buffer
[0]));
1113 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1114 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1116 /* Test empty string with zero size. */
1119 ret
= p_wcslwr_s(buffer
, 0);
1120 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1121 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1122 ok(buffer
[0] == 0, "expected empty string\n");
1124 /* Test empty string with size of one. */
1126 ret
= p_wcslwr_s(buffer
, 1);
1127 ok(ret
== 0, "got %d\n", ret
);
1128 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1130 /* Test one-byte buffer with zero size. */
1133 ret
= p_wcslwr_s(buffer
, 0);
1134 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1135 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1136 ok(buffer
[0] == '\0', "expected empty string\n");
1138 /* Test one-byte buffer with size of one. */
1141 ret
= p_wcslwr_s(buffer
, 1);
1142 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1143 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1144 ok(buffer
[0] == '\0', "expected empty string\n");
1146 /* Test invalid size. */
1147 wcscpy(buffer
, mixedString
);
1149 ret
= p_wcslwr_s(buffer
, 0);
1150 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1151 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1152 ok(buffer
[0] == '\0', "expected empty string\n");
1154 /* Test normal string uppercasing. */
1155 wcscpy(buffer
, mixedString
);
1156 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
));
1157 ok(ret
== 0, "expected 0, got %d\n", ret
);
1158 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1160 /* Test uppercasing with a shorter buffer size count. */
1161 wcscpy(buffer
, mixedString
);
1163 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
1164 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1165 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1166 ok(buffer
[0] == '\0', "expected empty string\n");
1168 /* Test uppercasing with a longer buffer size count. */
1169 wcscpy(buffer
, mixedString
);
1170 ret
= p_wcslwr_s(buffer
, sizeof(buffer
)/sizeof(WCHAR
));
1171 ok(ret
== 0, "expected 0, got %d\n", ret
);
1172 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1175 static void test_mbcjisjms(void)
1177 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1178 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1179 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1180 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1181 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1182 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1184 int prev_cp
= _getmbcp();
1186 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1189 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1191 unsigned int ret
, exp
;
1192 ret
= _mbcjistojms(jisjms
[j
][0]);
1193 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1194 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1195 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1201 static void test_mbcjmsjis(void)
1203 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1204 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1205 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1206 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1207 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1208 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1209 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1210 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1212 int prev_cp
= _getmbcp();
1214 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1217 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1219 unsigned int ret
, exp
;
1220 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1221 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1222 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1223 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1229 static void test_mbctohira(void)
1231 static const unsigned int mbchira_932
[][2] = {
1232 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1233 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1234 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1235 {0x8396, 0x8396}, {0x8397, 0x8397},
1236 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1238 unsigned int prev_cp
= _getmbcp();
1240 _setmbcp(_MB_CP_SBCS
);
1241 for (i
= 0; i
< sizeof(mbchira_932
)/sizeof(mbchira_932
[0]); i
++)
1243 int ret
, exp
= mbchira_932
[i
][0];
1244 ret
= _mbctohira(mbchira_932
[i
][0]);
1245 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1249 for (i
= 0; i
< sizeof(mbchira_932
)/sizeof(mbchira_932
[0]); i
++)
1251 unsigned int ret
, exp
;
1252 ret
= _mbctohira(mbchira_932
[i
][0]);
1253 exp
= mbchira_932
[i
][1];
1254 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1259 static void test_mbctokata(void)
1261 static const unsigned int mbckata_932
[][2] = {
1262 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1263 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1264 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1265 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1267 unsigned int prev_cp
= _getmbcp();
1269 _setmbcp(_MB_CP_SBCS
);
1270 for (i
= 0; i
< sizeof(mbckata_932
)/sizeof(mbckata_932
[0]); i
++)
1272 int ret
, exp
= mbckata_932
[i
][0];
1273 ret
= _mbctokata(mbckata_932
[i
][0]);
1274 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1278 for (i
= 0; i
< sizeof(mbckata_932
)/sizeof(mbckata_932
[0]); i
++)
1280 unsigned int ret
, exp
;
1281 ret
= _mbctokata(mbckata_932
[i
][0]);
1282 exp
= mbckata_932
[i
][1];
1283 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1288 static void test_mbbtombc(void)
1290 static const unsigned int mbbmbc
[][2] = {
1291 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1292 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1293 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1294 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1295 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1297 int prev_cp
= _getmbcp();
1299 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1302 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1304 unsigned int exp
, ret
;
1305 ret
= _mbbtombc(mbbmbc
[j
][0]);
1306 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1307 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1308 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1314 static void test_mbctombb(void)
1316 static const unsigned int mbcmbb_932
[][2] = {
1317 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1318 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1319 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1320 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1321 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1322 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1323 unsigned int exp
, ret
, i
;
1324 unsigned int prev_cp
= _getmbcp();
1327 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1329 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1330 exp
= mbcmbb_932
[i
][1];
1331 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1336 static void test_ismbckata(void) {
1337 struct katakana_pair
{
1341 static const struct katakana_pair tests
[] = {
1342 {0x8152, FALSE
}, {0x8153, FALSE
}, {0x8154, FALSE
}, {0x8155, FALSE
},
1343 {0x82a0, FALSE
}, {0x833f, FALSE
}, {0x8340, TRUE
}, {0x837e, TRUE
},
1344 {0x837f, FALSE
}, {0x8380, TRUE
}, {0x8396, TRUE
}, {0x8397, FALSE
},
1345 {0xa5, FALSE
}, {0xb0, FALSE
}, {0xdd, FALSE
}
1347 unsigned int prev_cp
= _getmbcp();
1351 _setmbcp(_MB_CP_SBCS
);
1352 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++) {
1353 ret
= _ismbckata(tests
[i
].c
);
1354 ok(!ret
, "expected 0, got %d for %04x\n", ret
, tests
[i
].c
);
1358 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++) {
1359 ret
= _ismbckata(tests
[i
].c
);
1360 ok(!!ret
== tests
[i
].exp
, "expected %d, got %d for %04x\n",
1361 tests
[i
].exp
, !!ret
, tests
[i
].c
);
1367 static void test_ismbclegal(void) {
1368 unsigned int prev_cp
= _getmbcp();
1372 _setmbcp(932); /* Japanese */
1374 for(i
= 0; i
< 0x10000; i
++) {
1375 ret
= _ismbclegal(i
);
1376 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1377 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1378 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1379 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1385 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1386 _setmbcp(936); /* Chinese (GBK) */
1388 for(i
= 0; i
< 0x10000; i
++) {
1389 ret
= _ismbclegal(i
);
1390 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1391 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1397 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1398 _setmbcp(949); /* Korean */
1400 for(i
= 0; i
< 0x10000; i
++) {
1401 ret
= _ismbclegal(i
);
1402 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1403 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1409 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1410 _setmbcp(950); /* Chinese (Big5) */
1412 for(i
= 0; i
< 0x10000; i
++) {
1413 ret
= _ismbclegal(i
);
1414 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1415 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1416 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1422 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1423 _setmbcp(1361); /* Korean (Johab) */
1425 for(i
= 0; i
< 0x10000; i
++) {
1426 ret
= _ismbclegal(i
);
1427 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1428 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1429 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1430 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1437 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1442 static const struct {
1444 const char* delimiter
;
1445 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1447 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1449 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1451 } testcases_strtok
[] = {
1452 { "red cabernet", " ", 0, 4, -1 },
1453 { "sparkling white riesling", " ", 0, 10, 16 },
1454 { " pale cream sherry", "e ", 1, 6, 9 },
1459 static void test_strtok(void)
1464 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1465 strcpy( teststr
, testcases_strtok
[i
].string
);
1466 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1467 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1468 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1469 "string (%p) \'%s\' return %p\n",
1470 teststr
, testcases_strtok
[i
].string
, strret
);
1471 if( !strret
) continue;
1472 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1473 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1474 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1475 "second call string (%p) \'%s\' return %p\n",
1476 teststr
, testcases_strtok
[i
].string
, strret
);
1477 if( !strret
) continue;
1478 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1479 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1480 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1481 "third call string (%p) \'%s\' return %p\n",
1482 teststr
, testcases_strtok
[i
].string
, strret
);
1486 static void test_strtol(void)
1488 static char neg
[] = "-0x";
1494 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1495 /* errno is modified on W2K8+ */
1497 l
= strtol("-1234", &e
, 0);
1498 ok(l
==-1234, "wrong value %d\n", l
);
1499 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1501 ul
= strtoul("1234", &e
, 0);
1502 ok(ul
==1234, "wrong value %u\n", ul
);
1503 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1506 l
= strtol("2147483647L", &e
, 0);
1507 ok(l
==2147483647, "wrong value %d\n", l
);
1508 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1510 l
= strtol("-2147483648L", &e
, 0);
1511 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1512 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1514 ul
= strtoul("4294967295UL", &e
, 0);
1515 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1516 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1519 l
= strtol("9223372036854775807L", &e
, 0);
1520 ok(l
==2147483647, "wrong value %d\n", l
);
1521 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1523 ul
= strtoul("9223372036854775807L", &e
, 0);
1524 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1525 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1528 ul
= strtoul("-2", NULL
, 0);
1529 ok(ul
== -2, "wrong value %u\n", ul
);
1530 ok(errno
== 0, "wrong errno %d\n", errno
);
1533 ul
= strtoul("-4294967294", NULL
, 0);
1534 ok(ul
== 2, "wrong value %u\n", ul
);
1535 ok(errno
== 0, "wrong errno %d\n", errno
);
1538 ul
= strtoul("-4294967295", NULL
, 0);
1539 ok(ul
==1, "wrong value %u\n", ul
);
1540 ok(errno
== 0, "wrong errno %d\n", errno
);
1543 ul
= strtoul("-4294967296", NULL
, 0);
1544 ok(ul
== 1, "wrong value %u\n", ul
);
1545 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1548 l
= strtol(neg
, &e
, 0);
1549 ok(l
== 0, "wrong value %d\n", l
);
1550 ok(errno
== 0, "wrong errno %d\n", errno
);
1551 ok(e
== neg
, "e = %p, neg = %p\n", e
, neg
);
1554 static void test_strnlen(void)
1556 static const char str
[] = "string";
1560 win_skip("strnlen not found\n");
1564 res
= p_strnlen(str
, 20);
1565 ok(res
== 6, "Returned length = %d\n", (int)res
);
1567 res
= p_strnlen(str
, 3);
1568 ok(res
== 3, "Returned length = %d\n", (int)res
);
1570 res
= p_strnlen(NULL
, 0);
1571 ok(res
== 0, "Returned length = %d\n", (int)res
);
1574 static void test__strtoi64(void)
1576 static const char no1
[] = "31923";
1577 static const char no2
[] = "-213312";
1578 static const char no3
[] = "12aa";
1579 static const char no4
[] = "abc12";
1580 static const char overflow
[] = "99999999999999999999";
1581 static const char neg_overflow
[] = "-99999999999999999999";
1582 static const char hex
[] = "0x123";
1583 static const char oct
[] = "000123";
1584 static const char blanks
[] = " 12 212.31";
1587 unsigned __int64 ures
;
1590 if(!p_strtoi64
|| !p_strtoui64
) {
1591 win_skip("_strtoi64 or _strtoui64 not found\n");
1596 res
= p_strtoi64(no1
, NULL
, 10);
1597 ok(res
== 31923, "res != 31923\n");
1598 res
= p_strtoi64(no2
, NULL
, 10);
1599 ok(res
== -213312, "res != -213312\n");
1600 res
= p_strtoi64(no3
, NULL
, 10);
1601 ok(res
== 12, "res != 12\n");
1602 res
= p_strtoi64(no4
, &endpos
, 10);
1603 ok(res
== 0, "res != 0\n");
1604 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1605 res
= p_strtoi64(hex
, &endpos
, 10);
1606 ok(res
== 0, "res != 0\n");
1607 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1608 res
= p_strtoi64(oct
, &endpos
, 10);
1609 ok(res
== 123, "res != 123\n");
1610 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1611 res
= p_strtoi64(blanks
, &endpos
, 10);
1612 ok(res
== 12, "res != 12\n");
1613 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1614 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1617 res
= p_strtoi64(overflow
, &endpos
, 10);
1618 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1619 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1620 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1623 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1624 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1625 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1626 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1629 res
= p_strtoi64(no1
, &endpos
, 16);
1630 ok(res
== 203043, "res != 203043\n");
1631 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1632 res
= p_strtoi64(no2
, &endpos
, 16);
1633 ok(res
== -2175762, "res != -2175762\n");
1634 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1635 res
= p_strtoi64(no3
, &endpos
, 16);
1636 ok(res
== 4778, "res != 4778\n");
1637 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1638 res
= p_strtoi64(no4
, &endpos
, 16);
1639 ok(res
== 703506, "res != 703506\n");
1640 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1641 res
= p_strtoi64(hex
, &endpos
, 16);
1642 ok(res
== 291, "res != 291\n");
1643 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1644 res
= p_strtoi64(oct
, &endpos
, 16);
1645 ok(res
== 291, "res != 291\n");
1646 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1647 res
= p_strtoi64(blanks
, &endpos
, 16);
1648 ok(res
== 18, "res != 18\n");
1649 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1650 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1653 res
= p_strtoi64(hex
, &endpos
, 36);
1654 ok(res
== 1541019, "res != 1541019\n");
1655 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1656 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1659 res
= p_strtoi64(no1
, &endpos
, 0);
1660 ok(res
== 31923, "res != 31923\n");
1661 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1662 res
= p_strtoi64(no2
, &endpos
, 0);
1663 ok(res
== -213312, "res != -213312\n");
1664 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1665 res
= p_strtoi64(no3
, &endpos
, 10);
1666 ok(res
== 12, "res != 12\n");
1667 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1668 res
= p_strtoi64(no4
, &endpos
, 10);
1669 ok(res
== 0, "res != 0\n");
1670 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1671 res
= p_strtoi64(hex
, &endpos
, 10);
1672 ok(res
== 0, "res != 0\n");
1673 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1674 res
= p_strtoi64(oct
, &endpos
, 10);
1675 ok(res
== 123, "res != 123\n");
1676 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1677 res
= p_strtoi64(blanks
, &endpos
, 10);
1678 ok(res
== 12, "res != 12\n");
1679 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1680 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1683 ures
= p_strtoui64(no1
, &endpos
, 0);
1684 ok(ures
== 31923, "ures != 31923\n");
1685 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1686 ures
= p_strtoui64(no2
, &endpos
, 0);
1687 ok(ures
== -213312, "ures != -213312\n");
1688 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1689 ures
= p_strtoui64(no3
, &endpos
, 10);
1690 ok(ures
== 12, "ures != 12\n");
1691 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1692 ures
= p_strtoui64(no4
, &endpos
, 10);
1693 ok(ures
== 0, "ures != 0\n");
1694 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1695 ures
= p_strtoui64(hex
, &endpos
, 10);
1696 ok(ures
== 0, "ures != 0\n");
1697 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1698 ures
= p_strtoui64(oct
, &endpos
, 10);
1699 ok(ures
== 123, "ures != 123\n");
1700 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1701 ures
= p_strtoui64(blanks
, &endpos
, 10);
1702 ok(ures
== 12, "ures != 12\n");
1703 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1704 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1707 ures
= p_strtoui64(overflow
, &endpos
, 10);
1708 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1709 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1710 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1713 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1714 ok(ures
== 1, "ures != 1\n");
1715 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1716 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1719 static inline BOOL
almost_equal(double d1
, double d2
) {
1720 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1725 static void test__strtod(void)
1727 const char double1
[] = "12.1";
1728 const char double2
[] = "-13.721";
1729 const char double3
[] = "INF";
1730 const char double4
[] = ".21e12";
1731 const char double5
[] = "214353e-3";
1732 const char double6
[] = "NAN";
1733 const char overflow
[] = "1d9999999999999999999";
1734 const char white_chars
[] = " d10";
1739 d
= strtod(double1
, &end
);
1740 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1741 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1743 d
= strtod(double2
, &end
);
1744 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1745 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1747 d
= strtod(double3
, &end
);
1748 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1749 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1751 d
= strtod(double4
, &end
);
1752 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1753 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1755 d
= strtod(double5
, &end
);
1756 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1757 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1759 d
= strtod(double6
, &end
);
1760 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1761 ok(end
== double6
, "incorrect end (%d)\n", (int)(end
-double6
));
1763 d
= strtod("12.1d2", NULL
);
1764 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1766 d
= strtod(white_chars
, &end
);
1767 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1768 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1771 win_skip("_strtod_l not found\n");
1775 d
= strtod(NULL
, NULL
);
1776 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1777 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1780 end
= (char *)0xdeadbeef;
1781 d
= strtod(NULL
, &end
);
1782 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1783 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1784 ok(!end
, "incorrect end ptr %p\n", end
);
1787 d
= p__strtod_l(NULL
, NULL
, NULL
);
1788 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
1789 ok(errno
== EINVAL
, "errno = %x\n", errno
);
1792 /* Set locale with non '.' decimal point (',') */
1793 if(!setlocale(LC_ALL
, "Polish")) {
1794 win_skip("system with limited locales\n");
1798 d
= strtod("12.1", NULL
);
1799 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1801 d
= strtod("12,1", NULL
);
1802 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1804 setlocale(LC_ALL
, "C");
1806 /* Precision tests */
1807 d
= strtod("0.1", NULL
);
1808 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1809 d
= strtod("-0.1", NULL
);
1810 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1811 d
= strtod("0.1281832188491894198128921", NULL
);
1812 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1813 d
= strtod("0.82181281288121", NULL
);
1814 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1815 d
= strtod("21921922352523587651128218821", NULL
);
1816 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1817 d
= strtod("0.1d238", NULL
);
1818 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1819 d
= strtod("0.1D-4736", NULL
);
1820 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1823 strtod(overflow
, &end
);
1824 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1825 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1828 strtod("-1d309", NULL
);
1829 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1832 static void test_mbstowcs(void)
1834 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1835 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1836 static const char mSimple
[] = "text";
1837 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1839 const wchar_t *pwstr
;
1847 wOut
[4] = '!'; wOut
[5] = '\0';
1848 mOut
[4] = '!'; mOut
[5] = '\0';
1851 /* crashes on some systems */
1853 ret
= mbstowcs(wOut
, NULL
, 4);
1854 ok(ret
== -1, "mbstowcs did not return -1\n");
1855 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1858 ret
= mbstowcs(NULL
, mSimple
, 0);
1859 ok(ret
== 4, "mbstowcs did not return 4\n");
1861 ret
= mbstowcs(wOut
, mSimple
, 4);
1862 ok(ret
== 4, "mbstowcs did not return 4\n");
1863 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1864 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1866 ret
= wcstombs(NULL
, wSimple
, 0);
1867 ok(ret
== 4, "wcstombs did not return 4\n");
1869 ret
= wcstombs(mOut
, wSimple
, 6);
1870 ok(ret
== 4, "wcstombs did not return 4\n");
1871 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1873 ret
= wcstombs(mOut
, wSimple
, 2);
1874 ok(ret
== 2, "wcstombs did not return 2\n");
1875 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1877 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
1878 win_skip("Japanese_Japan.932 locale not available\n");
1882 ret
= mbstowcs(wOut
, mHiragana
, 6);
1883 ok(ret
== 2, "mbstowcs did not return 2\n");
1884 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1886 ret
= wcstombs(mOut
, wHiragana
, 6);
1887 ok(ret
== 4, "wcstombs did not return 4\n");
1888 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1890 if(!pmbstowcs_s
|| !pwcstombs_s
) {
1891 setlocale(LC_ALL
, "C");
1892 win_skip("mbstowcs_s or wcstombs_s not available\n");
1896 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
1897 ok(err
== 0, "err = %d\n", err
);
1898 ok(ret
== 5, "mbstowcs_s did not return 5\n");
1899 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1901 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
1902 ok(err
== 0, "err = %d\n", err
);
1903 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1904 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1906 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
1907 ok(err
== 0, "err = %d\n", err
);
1908 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1910 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
1911 ok(err
== 0, "err = %d\n", err
);
1912 ok(ret
== 5, "wcstombs_s did not return 5\n");
1913 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1915 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
1916 ok(err
== 0, "err = %d\n", err
);
1917 ok(ret
== 5, "wcstombs_s did not return 5\n");
1918 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1920 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
1921 ok(err
== 0, "err = %d\n", err
);
1922 ok(ret
== 5, "wcstombs_s did not return 5\n");
1925 setlocale(LC_ALL
, "C");
1926 win_skip("wcsrtombs not available\n");
1932 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
1933 ok(ret
== 4, "wcsrtombs did not return 4\n");
1934 ok(err
== 0, "err = %d\n", err
);
1935 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
1936 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
1939 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
1940 ok(ret
== 4, "wcsrtombs did not return 4\n");
1941 ok(pwstr
== NULL
, "pwstr != NULL\n");
1942 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1945 setlocale(LC_ALL
, "C");
1946 win_skip("mbsrtowcs not available\n");
1951 ret
= p_mbsrtowcs(NULL
, &pmbstr
, 6, NULL
);
1952 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1953 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
1956 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
1957 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1958 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1959 ok(!pmbstr
, "pmbstr != NULL\n");
1961 state
= mHiragana
[0];
1962 pmbstr
= mHiragana
+1;
1963 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
1964 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1965 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
1966 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
1967 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
1968 ok(!pmbstr
, "pmbstr != NULL\n");
1971 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
1972 ok(ret
== -1, "mbsrtowcs did not return -1\n");
1973 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1975 if(!p_mbsrtowcs_s
) {
1976 setlocale(LC_ALL
, "C");
1977 win_skip("mbsrtowcs_s not available\n");
1982 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, NULL
, 6, NULL
);
1983 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
1984 ok(err
== EINVAL
, "err = %d\n", err
);
1985 err
= p_mbsrtowcs_s(&ret
, NULL
, 1, &pmbstr
, 6, NULL
);
1986 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
1987 ok(err
== EINVAL
, "err = %d\n", err
);
1988 err
= p_mbsrtowcs_s(&ret
, wOut
, 0, &pmbstr
, 6, NULL
);
1989 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
1990 ok(err
== EINVAL
, "err = %d\n", err
);
1994 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, &pmbstr
, 6, NULL
);
1995 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
1996 ok(err
== 0, "err = %d\n", err
);
1997 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
1998 ok(errno
== 0, "errno = %d\n", errno
);
2001 err
= p_mbsrtowcs_s(&ret
, wOut
, 1, &pmbstr
, 6, NULL
);
2002 ok(ret
== 2, "mbsrtowcs_s did not return 2\n");
2003 ok(err
== 0, "err = %d\n", err
);
2004 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2005 ok(pmbstr
== mHiragana
+2, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+2);
2006 ok(errno
== 0, "errno = %d\n", errno
);
2009 err
= p_mbsrtowcs_s(&ret
, wOut
, 2, &pmbstr
, 6, NULL
);
2010 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2011 ok(err
== 0, "err = %d\n", err
);
2012 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2013 ok(pmbstr
== mHiragana
+4, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+4);
2014 ok(errno
== 0, "errno = %d\n", errno
);
2017 err
= p_mbsrtowcs_s(&ret
, wOut
, 3, &pmbstr
, 6, NULL
);
2018 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2019 ok(err
== 0, "err = %d\n", err
);
2020 ok(!pmbstr
, "pmbstr != NULL\n");
2021 ok(errno
== 0, "errno = %d\n", errno
);
2023 setlocale(LC_ALL
, "C");
2026 static void test_gcvt(void)
2028 char buf
[1024], *res
;
2032 win_skip("Skipping _gcvt tests\n");
2037 res
= _gcvt(1.2, -1, buf
);
2038 ok(res
== NULL
, "res != NULL\n");
2039 ok(errno
== ERANGE
, "errno = %d\n", errno
);
2042 res
= _gcvt(1.2, 5, NULL
);
2043 ok(res
== NULL
, "res != NULL\n");
2044 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2046 res
= gcvt(1.2, 5, buf
);
2047 ok(res
== buf
, "res != buf\n");
2048 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
2051 err
= p_gcvt_s(buf
, 5, 1.2, 10);
2052 ok(err
== ERANGE
, "err = %d\n", err
);
2053 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2056 err
= p_gcvt_s(buf
, 4, 123456, 2);
2057 ok(err
== ERANGE
, "err = %d\n", err
);
2058 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2061 static void test__itoa_s(void)
2068 win_skip("Skipping _itoa_s tests\n");
2073 ret
= p_itoa_s(0, NULL
, 0, 0);
2074 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2075 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2077 memset(buffer
, 'X', sizeof(buffer
));
2079 ret
= p_itoa_s(0, buffer
, 0, 0);
2080 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2081 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2082 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2084 memset(buffer
, 'X', sizeof(buffer
));
2086 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
2087 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2088 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2089 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2091 memset(buffer
, 'X', sizeof(buffer
));
2093 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
2094 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2095 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2096 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2098 memset(buffer
, 'X', sizeof(buffer
));
2100 ret
= p_itoa_s(12345678, buffer
, 4, 10);
2101 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2102 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2103 ok(!memcmp(buffer
, "\000765", 4),
2104 "Expected the output buffer to be null terminated with truncated output\n");
2106 memset(buffer
, 'X', sizeof(buffer
));
2108 ret
= p_itoa_s(12345678, buffer
, 8, 10);
2109 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2110 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2111 ok(!memcmp(buffer
, "\0007654321", 8),
2112 "Expected the output buffer to be null terminated with truncated output\n");
2114 memset(buffer
, 'X', sizeof(buffer
));
2116 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
2117 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2118 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2119 ok(!memcmp(buffer
, "\00087654321", 9),
2120 "Expected the output buffer to be null terminated with truncated output\n");
2122 ret
= p_itoa_s(12345678, buffer
, 9, 10);
2123 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2124 ok(!strcmp(buffer
, "12345678"),
2125 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2128 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
2129 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2130 ok(!strcmp(buffer
, "1010101010101010"),
2131 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2134 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
2135 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2136 ok(!strcmp(buffer
, "nell"),
2137 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2140 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
2141 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2142 ok(!strcmp(buffer
, "hag"),
2143 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2146 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
2147 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2148 ok(!strcmp(buffer
, "-12345678"),
2149 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2152 itoa(100, buffer
, 100);
2153 ok(!strcmp(buffer
, "10"),
2154 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
2157 static void test__strlwr_s(void)
2164 win_skip("Skipping _strlwr_s tests\n");
2169 ret
= p_strlwr_s(NULL
, 0);
2170 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2171 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2174 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
2175 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2176 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2179 ret
= p_strlwr_s(buffer
, 0);
2180 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2181 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2183 strcpy(buffer
, "GoRrIsTeR");
2185 ret
= p_strlwr_s(buffer
, 5);
2186 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2187 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2188 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2189 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2191 strcpy(buffer
, "GoRrIsTeR");
2193 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
2194 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2195 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2196 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2197 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2199 strcpy(buffer
, "GoRrIsTeR");
2200 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
2201 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2202 ok(!strcmp(buffer
, "gorrister"),
2203 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2206 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2207 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
2208 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2209 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2210 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2214 static void test_wcsncat_s(void)
2216 static wchar_t abcW
[] = {'a','b','c',0};
2223 win_skip("skipping wcsncat_s tests\n");
2227 memcpy(src
, abcW
, sizeof(abcW
));
2229 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
2230 ok(ret
== EINVAL
, "err = %d\n", ret
);
2231 ret
= p_wcsncat_s(dst
, 0, src
, 4);
2232 ok(ret
== EINVAL
, "err = %d\n", ret
);
2233 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
2234 ok(ret
== EINVAL
, "err = %d\n", ret
);
2235 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
2236 ok(ret
== 0, "err = %d\n", ret
);
2239 ret
= p_wcsncat_s(dst
, 2, src
, 4);
2240 ok(ret
== ERANGE
, "err = %d\n", ret
);
2243 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
2244 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
2245 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2247 memcpy(dst
, abcW
, sizeof(abcW
));
2249 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2250 ok(ret
== EINVAL
, "err = %d\n", ret
);
2253 static void test__mbsnbcat_s(void)
2255 unsigned char dest
[16];
2256 const unsigned char first
[] = "dinosaur";
2257 const unsigned char second
[] = "duck";
2262 win_skip("Skipping _mbsnbcat_s tests\n");
2266 /* Test invalid arguments. */
2267 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2268 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2271 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2272 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2273 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2276 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2277 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2278 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2280 memset(dest
, 'X', sizeof(dest
));
2282 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2283 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2284 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2285 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2287 memset(dest
, 'X', sizeof(dest
));
2289 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2290 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2291 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2292 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2294 memset(dest
, 'X', sizeof(dest
));
2296 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2297 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2298 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2299 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2301 memset(dest
, 'X', sizeof(dest
));
2303 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2304 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2305 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2306 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2308 memset(dest
, 'X', sizeof(dest
));
2310 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2311 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2312 ok(!memcmp(dest
, second
, sizeof(second
)),
2313 "Expected the output buffer string to be \"duck\"\n");
2315 /* Test source truncation behavior. */
2316 memset(dest
, 'X', sizeof(dest
));
2317 memcpy(dest
, first
, sizeof(first
));
2318 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2319 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2320 ok(!memcmp(dest
, first
, sizeof(first
)),
2321 "Expected the output buffer string to be \"dinosaur\"\n");
2323 memset(dest
, 'X', sizeof(dest
));
2324 memcpy(dest
, first
, sizeof(first
));
2325 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2326 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2327 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2328 "Expected the output buffer string to be \"dinosaurduck\"\n");
2330 memset(dest
, 'X', sizeof(dest
));
2331 memcpy(dest
, first
, sizeof(first
));
2332 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2333 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2334 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2335 "Expected the output buffer string to be \"dinosaurduck\"\n");
2337 memset(dest
, 'X', sizeof(dest
));
2338 memcpy(dest
, first
, sizeof(first
));
2339 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2340 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2341 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2342 "Expected the output buffer string to be \"dinosaurduck\"\n");
2344 memset(dest
, 'X', sizeof(dest
));
2345 memcpy(dest
, first
, sizeof(first
));
2346 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2347 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2348 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2349 "Expected the output buffer string to be \"dinosaurduc\"\n");
2351 /* Test destination truncation behavior. */
2352 memset(dest
, 'X', sizeof(dest
));
2353 memcpy(dest
, first
, sizeof(first
));
2355 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2356 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2357 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2358 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2359 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2361 memset(dest
, 'X', sizeof(dest
));
2362 memcpy(dest
, first
, sizeof(first
));
2364 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2365 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2366 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2367 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2368 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2370 memset(dest
, 'X', sizeof(dest
));
2371 memcpy(dest
, first
, sizeof(first
));
2373 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2374 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2375 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2376 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2377 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2380 static void test__mbsupr_s(void)
2383 unsigned char buffer
[20];
2387 win_skip("Skipping _mbsupr_s tests\n");
2392 ret
= p_mbsupr_s(NULL
, 0);
2393 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2396 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2397 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2398 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2401 ret
= p_mbsupr_s(buffer
, 0);
2402 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2403 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2405 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2407 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2408 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2409 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2410 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2413 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2415 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2416 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2417 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2418 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2421 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2423 ret
= p_mbsupr_s(buffer
, 4);
2424 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2425 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2427 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2429 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2430 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2431 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2432 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2437 static void test__mbslwr_s(void)
2440 unsigned char buffer
[20];
2444 win_skip("Skipping _mbslwr_s tests\n");
2449 ret
= p_mbslwr_s(NULL
, 0);
2450 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2453 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2454 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2455 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2458 ret
= p_mbslwr_s(buffer
, 0);
2459 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2460 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2462 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2464 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2465 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2466 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2467 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2470 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2472 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2473 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2474 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2475 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2478 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2480 ret
= p_mbslwr_s(buffer
, 4);
2481 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2482 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2484 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2486 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2487 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2488 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2489 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2493 static void test__mbstok(void)
2495 const unsigned char delim
[] = "t";
2497 char str
[] = "!.!test";
2502 ret
= _mbstok(NULL
, delim
);
2503 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2504 ok(!ret
|| broken((char*)ret
==str
+4),
2505 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2507 ret
= _mbstok(NULL
, delim
);
2508 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2511 static void test__ultoa_s(void)
2518 win_skip("Skipping _ultoa_s tests\n");
2523 ret
= p_ultoa_s(0, NULL
, 0, 0);
2524 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2525 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2527 memset(buffer
, 'X', sizeof(buffer
));
2529 ret
= p_ultoa_s(0, buffer
, 0, 0);
2530 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2531 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2532 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2534 memset(buffer
, 'X', sizeof(buffer
));
2536 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2537 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2538 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2539 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2541 memset(buffer
, 'X', sizeof(buffer
));
2543 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2544 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2545 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2546 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2548 memset(buffer
, 'X', sizeof(buffer
));
2550 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2551 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2552 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2553 ok(!memcmp(buffer
, "\000765", 4),
2554 "Expected the output buffer to be null terminated with truncated output\n");
2556 memset(buffer
, 'X', sizeof(buffer
));
2558 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2559 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2560 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2561 ok(!memcmp(buffer
, "\0007654321", 8),
2562 "Expected the output buffer to be null terminated with truncated output\n");
2564 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2565 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2566 ok(!strcmp(buffer
, "12345678"),
2567 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2570 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2571 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2572 ok(!strcmp(buffer
, "1010101010101010"),
2573 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2576 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2577 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2578 ok(!strcmp(buffer
, "nell"),
2579 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2582 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2583 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2584 ok(!strcmp(buffer
, "hag"),
2585 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2589 static void test_wctob(void)
2593 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2594 win_skip("Skipping wctob tests\n");
2598 ret
= p_wctob(0x8141);
2599 ok(ret
== EOF
, "ret = %x\n", ret
);
2601 ret
= p_wctob(0x81);
2602 ok(ret
== EOF
, "ret = %x\n", ret
);
2604 ret
= p_wctob(0xe0);
2605 ok(ret
== 0x61, "ret = %x\n", ret
);
2608 ret
= p_wctob(0x81);
2609 ok(ret
== EOF
, "ret = %x\n", ret
);
2611 setlocale(LC_ALL
, "C");
2612 ret
= p_wctob(0x8141);
2613 ok(ret
== EOF
, "ret = %x\n", ret
);
2615 ret
= p_wctob(0x81);
2616 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2618 ret
= p_wctob(0x9f);
2619 ok(ret
== (int)(char)0x9f, "ret = %x\n", ret
);
2621 ret
= p_wctob(0xe0);
2622 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2624 static void test_wctomb(void)
2627 unsigned char dst
[10];
2630 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
2631 win_skip("wcrtomb tests\n");
2635 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
2636 ok(ret
== 2, "wcrtomb did not return 2\n");
2640 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
2641 ok(ret
== 2, "wcrtomb did not return 2\n");
2642 ok(state
== 0, "state != 0\n");
2643 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2644 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
2645 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
2647 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
2648 ok(ret
== 2, "wcrtomb did not return 2\n");
2649 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2650 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
2652 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
2653 ok(ret
== 1, "wcrtomb did not return 1\n");
2654 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
2656 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
2657 ok(ret
== -1, "wcrtomb did not return -1\n");
2658 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
2660 setlocale(LC_ALL
, "C");
2663 static void test_tolower(void)
2669 /* test C locale when locale was never changed */
2670 ret
= p_tolower(0x41);
2671 ok(ret
== 0x61, "ret = %x\n", ret
);
2673 ret
= p_tolower(0xF4);
2674 ok(ret
== 0xF4, "ret = %x\n", ret
);
2677 ret
= p_tolower((char)0xF4);
2678 todo_wine
ok(ret
== (char)0xF4, "ret = %x\n", ret
);
2679 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2682 ret
= p_tolower((char)0xD0);
2683 todo_wine
ok(ret
== (char)0xD0, "ret = %x\n", ret
);
2684 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2686 /* test C locale after setting locale */
2687 if(!setlocale(LC_ALL
, "us")) {
2688 win_skip("skipping tolower tests that depends on locale\n");
2691 setlocale(LC_ALL
, "C");
2695 ret
= p_tolower(ch
);
2696 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
2697 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
2698 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
2701 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2703 ok(ret
== ch
, "ret = %x\n", ret
);
2704 if(!len
|| ret
==(unsigned char)lch
)
2705 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2709 ret
= p_tolower(ch
);
2710 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
2711 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
2712 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
2715 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2717 ok(ret
== ch
, "ret = %x\n", ret
);
2718 if(!len
|| ret
==(unsigned char)lch
)
2719 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2721 ret
= p_tolower(0xD0);
2722 ok(ret
== 0xD0, "ret = %x\n", ret
);
2724 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
2726 ret
= p_tolower((char)0xD0);
2727 ok(ret
== 0xF0, "ret = %x\n", ret
);
2729 ret
= p_tolower(0xD0);
2730 ok(ret
== 0xF0, "ret = %x\n", ret
);
2732 setlocale(LC_ALL
, "C");
2735 static void test__atodbl(void)
2742 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2743 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2744 win_skip("_atodbl_l is not available\n");
2749 ret
= p__atodbl_l(&d
, num
, NULL
);
2750 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
2751 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2752 ret
= _atodbl(&d
, num
);
2753 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
2754 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2757 ret
= p__atodbl_l(&d
, num
, NULL
);
2758 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
2759 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2760 ret
= _atodbl(&d
, num
);
2761 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
2762 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2765 ret
= p__atodbl_l(&d
, num
, NULL
);
2766 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
2767 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2768 ret
= _atodbl(&d
, num
);
2769 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
2770 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2773 ret
= p__atodbl_l(&d
, num
, NULL
);
2774 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
2775 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2776 ret
= _atodbl(&d
, num
);
2777 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
2778 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2780 strcpy(num
, "1e-309");
2781 ret
= p__atodbl_l(&d
, num
, NULL
);
2782 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
2783 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2784 ret
= _atodbl(&d
, num
);
2785 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
2786 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2788 strcpy(num
, "1e309");
2789 ret
= p__atodbl_l(&d
, num
, NULL
);
2790 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
2791 ret
= _atodbl(&d
, num
);
2792 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
2795 static void test__stricmp(void)
2799 ret
= _stricmp("test", "test");
2800 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2801 ret
= _stricmp("a", "z");
2802 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2803 ret
= _stricmp("z", "a");
2804 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2805 ret
= _stricmp("\xa5", "\xb9");
2806 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2808 if(!setlocale(LC_ALL
, "polish")) {
2809 win_skip("stricmp tests\n");
2813 ret
= _stricmp("test", "test");
2814 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2815 ret
= _stricmp("a", "z");
2816 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2817 ret
= _stricmp("z", "a");
2818 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2819 ret
= _stricmp("\xa5", "\xb9");
2820 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2821 ret
= _stricmp("a", "\xb9");
2822 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2824 setlocale(LC_ALL
, "C");
2827 static void test__wcstoi64(void)
2829 static const WCHAR digit
[] = { '9', 0 };
2830 static const WCHAR space
[] = { ' ', 0 };
2831 static const WCHAR stock
[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2832 static const WCHAR cjk_1
[] = { 0x4e00, 0 }; /* CJK Ideograph, First */
2833 static const WCHAR tamil
[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2834 static const WCHAR thai
[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2835 static const WCHAR fullwidth
[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2836 static const WCHAR superscript1
[] = { 0xb9, 0 }; /* SUPERSCRIPT ONE */
2837 static const WCHAR minus_0x91
[] = { '-', 0x0e50, 'x', 0xff19, '1', 0 };
2838 static const WCHAR plus_071
[] = { '+', 0x0e50, 0xff17, '1', 0 };
2839 static const WCHAR hex
[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
2840 static const WCHAR zeros
[] = {
2841 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
2842 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
2847 unsigned __int64 ures
;
2850 if (!p_wcstoi64
|| !p_wcstoui64
) {
2851 win_skip("_wcstoi64 or _wcstoui64 not found\n");
2855 res
= p_wcstoi64(digit
, NULL
, 10);
2856 ok(res
== 9, "res != 9\n");
2857 res
= p_wcstoi64(space
, &endpos
, 0);
2858 ok(endpos
== space
, "endpos != space\n");
2859 res
= p_wcstoi64(stock
, &endpos
, 10);
2860 ok(res
== 0, "res != 0\n");
2861 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2862 res
= p_wcstoi64(cjk_1
, NULL
, 0);
2863 ok(res
== 0, "res != 0\n");
2864 res
= p_wcstoi64(tamil
, &endpos
, 10);
2865 ok(res
== 0, "res != 0\n");
2866 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2867 res
= p_wcstoi64(thai
, NULL
, 10);
2868 ok(res
== 9, "res != 9\n");
2869 res
= p_wcstoi64(fullwidth
, NULL
, 10);
2870 ok(res
== 9, "res != 9\n");
2871 res
= p_wcstoi64(superscript1
, NULL
, 10);
2872 ok(res
== 0, "res != 0\n");
2873 res
= p_wcstoi64(hex
, NULL
, 16);
2874 ok(res
== 0x9f9, "res != 0x9f9\n");
2875 res
= p_wcstoi64(minus_0x91
, NULL
, 0);
2876 ok(res
== -0x91, "res != -0x91\n");
2877 res
= p_wcstoi64(plus_071
, NULL
, 0);
2878 ok(res
== 071, "res != 071\n");
2880 ures
= p_wcstoui64(digit
, NULL
, 10);
2881 ok(ures
== 9, "ures != 9\n");
2882 ures
= p_wcstoui64(space
, &endpos
, 0);
2883 ok(endpos
== space
, "endpos != space\n");
2884 ures
= p_wcstoui64(stock
, &endpos
, 10);
2885 ok(ures
== 0, "ures != 0\n");
2886 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2887 ures
= p_wcstoui64(tamil
, &endpos
, 10);
2888 ok(ures
== 0, "ures != 0\n");
2889 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2890 ures
= p_wcstoui64(thai
, NULL
, 10);
2891 ok(ures
== 9, "ures != 9\n");
2892 ures
= p_wcstoui64(fullwidth
, NULL
, 10);
2893 ok(ures
== 9, "ures != 9\n");
2894 ures
= p_wcstoui64(superscript1
, NULL
, 10);
2895 ok(ures
== 0, "ures != 0\n");
2896 ures
= p_wcstoui64(hex
, NULL
, 16);
2897 ok(ures
== 0x9f9, "ures != 0x9f9\n");
2898 ures
= p_wcstoui64(plus_071
, NULL
, 0);
2899 ok(ures
== 071, "ures != 071\n");
2901 /* Test various unicode digits */
2902 for (i
= 0; i
< sizeof(zeros
) / sizeof(zeros
[0]); ++i
) {
2903 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
2904 res
= p_wcstoi64(tmp
, NULL
, 0);
2905 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
2906 tmp
[1] = zeros
[i
] + 10;
2907 res
= p_wcstoi64(tmp
, NULL
, 16);
2908 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
2914 static void test_atoi(void)
2919 ok(r
== 0, "atoi(0) = %d\n", r
);
2922 ok(r
== -1, "atoi(-1) = %d\n", r
);
2925 ok(r
== 1, "atoi(1) = %d\n", r
);
2927 r
= atoi("4294967296");
2928 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
2931 static void test_atof(void)
2936 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
2939 ok(almost_equal(d
, 1.0), "d = %lf\n", d
);
2942 ok(almost_equal(d
, -1.0), "d = %lf\n", d
);
2946 win_skip("_atof_l not found\n");
2952 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
2953 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2956 d
= p__atof_l(NULL
, NULL
);
2957 ok(almost_equal(d
, 0.0), "d = %lf\n", d
);
2958 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2961 static void test_strncpy(void)
2963 #define TEST_STRNCPY_LEN 10
2965 char dst
[TEST_STRNCPY_LEN
+ 1];
2966 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
2968 /* strlen(src) > TEST_STRNCPY_LEN */
2969 ret
= strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
2970 ok(ret
== dst
, "ret != dst\n");
2971 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2973 /* without null-terminated */
2974 ret
= strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
2975 ok(ret
== dst
, "ret != dst\n");
2976 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2978 /* strlen(src) < TEST_STRNCPY_LEN */
2979 strcpy(dst
, "0123456789");
2980 ret
= strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
2981 ok(ret
== dst
, "ret != dst\n");
2982 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
2983 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
2985 /* strlen(src) == TEST_STRNCPY_LEN */
2986 ret
= strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
2987 ok(ret
== dst
, "ret != dst\n");
2988 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2991 static void test_strxfrm(void)
2996 /* crashes on old version of msvcrt */
2999 ret
= strxfrm(NULL
, "src", 1);
3000 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3001 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3004 ret
= strxfrm(dest
, NULL
, 100);
3005 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3006 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3009 ret
= strxfrm(NULL
, "src", 0);
3010 ok(ret
== 3, "ret = %d\n", (int)ret
);
3012 ret
= strxfrm(dest
, "src", 0);
3013 ok(ret
== 3, "ret = %d\n", (int)ret
);
3014 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3017 ret
= strxfrm(dest
, "src", 5);
3018 ok(ret
== 3, "ret = %d\n", (int)ret
);
3019 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
3023 ret
= strxfrm(dest
, "src", 1);
3024 ok(ret
== 3, "ret = %d\n", (int)ret
);
3025 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
3026 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
3027 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3029 ret
= strxfrm(dest
, "", 5);
3030 ok(ret
== 0, "ret = %d\n", (int)ret
);
3031 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
3033 if(!setlocale(LC_ALL
, "polish")) {
3034 win_skip("stxfrm tests\n");
3038 ret
= strxfrm(NULL
, "src", 0);
3039 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3041 ret
= strxfrm(dest
, "src", 0);
3042 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3043 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3045 ret
= strxfrm(dest
, "src", ret
+1);
3046 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3047 ok(dest
[0], "dest[0] = 0\n");
3051 ret
= strxfrm(dest
, "src", 5);
3052 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3053 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
3055 setlocale(LC_ALL
, "C");
3058 static void test__strnset_s(void)
3064 win_skip("_strnset_s not available\n");
3068 r
= p__strnset_s(NULL
, 0, 'a', 0);
3069 ok(r
== 0, "r = %d\n", r
);
3071 buf
[0] = buf
[1] = buf
[2] = 'b';
3072 r
= p__strnset_s(buf
, sizeof(buf
), 'a', 2);
3073 ok(r
== 0, "r = %d\n", r
);
3074 ok(!strcmp(buf
, "aab"), "buf = %s\n", buf
);
3076 r
= p__strnset_s(buf
, 0, 'a', 0);
3077 ok(r
== EINVAL
, "r = %d\n", r
);
3079 r
= p__strnset_s(NULL
, 0, 'a', 1);
3080 ok(r
== EINVAL
, "r = %d\n", r
);
3083 r
= p__strnset_s(buf
, sizeof(buf
)-1, 'c', 2);
3084 ok(r
== EINVAL
, "r = %d\n", r
);
3085 ok(!buf
[0] && buf
[1]=='c' && buf
[2]=='b', "buf = %s\n", buf
);
3088 static void test__wcsset_s(void)
3094 win_skip("_wcsset_s not available\n");
3098 r
= p__wcsset_s(NULL
, 0, 'a');
3099 ok(r
== EINVAL
, "r = %d\n", r
);
3102 r
= p__wcsset_s(str
, 0, 'a');
3103 ok(r
== EINVAL
, "r = %d\n", r
);
3104 ok(str
[0] == 'a', "str[0] = %d\n", str
[0]);
3108 r
= p__wcsset_s(str
, 2, 'c');
3109 ok(r
== EINVAL
, "r = %d\n", r
);
3110 ok(!str
[0], "str[0] = %d\n", str
[0]);
3111 ok(str
[1] == 'b', "str[1] = %d\n", str
[1]);
3116 r
= p__wcsset_s(str
, 3, 'c');
3117 ok(str
[0] == 'c', "str[0] = %d\n", str
[0]);
3118 ok(str
[1] == 0, "str[1] = %d\n", str
[1]);
3119 ok(str
[2] == 'b', "str[2] = %d\n", str
[2]);
3122 static void test__mbscmp(void)
3124 static const unsigned char a
[] = {'a',0}, b
[] = {'b',0};
3129 win_skip("_mbscmp tests\n");
3133 ret
= _mbscmp(NULL
, NULL
);
3134 ok(ret
== INT_MAX
, "got %d\n", ret
);
3136 ret
= _mbscmp(a
, NULL
);
3137 ok(ret
== INT_MAX
, "got %d\n", ret
);
3139 ret
= _mbscmp(NULL
, a
);
3140 ok(ret
== INT_MAX
, "got %d\n", ret
);
3142 ret
= _mbscmp(a
, a
);
3143 ok(!ret
, "got %d\n", ret
);
3145 ret
= _mbscmp(a
, b
);
3146 ok(ret
== -1, "got %d\n", ret
);
3148 ret
= _mbscmp(b
, a
);
3149 ok(ret
== 1, "got %d\n", ret
);
3155 static const char xilstring
[]="c:/xilinx";
3158 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
3160 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
3161 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
3162 SET(pmemcpy
,"memcpy");
3163 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
3164 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
3165 SET(pmemcmp
,"memcmp");
3166 SET(p_mbctype
,"_mbctype");
3167 SET(p__mb_cur_max
,"__mb_cur_max");
3168 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
3169 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
3170 p_mbscat_s
= (void*)GetProcAddress( hMsvcrt
, "_mbscat_s" );
3171 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
3172 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
3173 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
3174 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
3175 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
3176 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
3177 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
3178 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
3179 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
3180 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
3181 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
3182 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
3183 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
3184 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
3185 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
3186 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
3187 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
3188 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
3189 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
3190 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
3191 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
3192 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
3193 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
3194 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
3195 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
3196 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
3197 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
3198 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
3199 p_mbsrtowcs_s
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs_s");
3200 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
3201 p__atof_l
= (void*)GetProcAddress(hMsvcrt
, "_atof_l");
3202 p__strtod_l
= (void*)GetProcAddress(hMsvcrt
, "_strtod_l");
3203 p__strnset_s
= (void*)GetProcAddress(hMsvcrt
, "_strnset_s");
3204 p__wcsset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsset_s");
3206 /* MSVCRT memcpy behaves like memmove for overlapping moves,
3207 MFC42 CString::Insert seems to rely on that behaviour */
3208 strcpy(mem
,xilstring
);
3209 nLen
=strlen(xilstring
);
3210 pmemcpy(mem
+5, mem
,nLen
+1);
3211 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
3212 "Got result %s\n",mem
+5);
3214 /* run tolower tests first */