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 static char *buf_to_string(const unsigned char *bin, int len, int nr)
35 static char buf[2][1024];
39 for (i = 0; i < len; i++)
41 sprintf(w, "%02x ", (unsigned char)bin[i]);
47 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
48 const wchar_t *function, const wchar_t *file,
49 unsigned line, uintptr_t arg)
51 /* we just ignore handler calls */
54 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
55 #define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); }
57 static void* (__cdecl *pmemcpy)(void *, const void *, size_t n);
58 static int (__cdecl *p_memcpy_s)(void *, size_t, const void *, size_t);
59 static int (__cdecl *p_memmove_s)(void *, size_t, const void *, size_t);
60 static int* (__cdecl *pmemcmp)(void *, const void *, size_t n);
61 static int (__cdecl *pstrcpy_s)(char *dst, size_t len, const char *src);
62 static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
63 static int (__cdecl *p_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
64 static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
65 static int (__cdecl *p_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 int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
73 static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
74 static size_t (__cdecl *pwcsrtombs)(char*, const wchar_t**, size_t, int*);
75 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
76 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
77 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
78 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
79 static int *p__mb_cur_max;
80 static unsigned char *p_mbctype;
81 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
82 static int (__cdecl *p_wcslwr_s)(wchar_t*,size_t);
83 static errno_t (__cdecl *p_mbsupr_s)(unsigned char *str, size_t numberOfElements);
84 static errno_t (__cdecl *p_mbslwr_s)(unsigned char *str, size_t numberOfElements);
85 static int (__cdecl *p_wctob)(wint_t);
86 static int (__cdecl *p_tolower)(int);
88 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
89 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
91 static HMODULE hMsvcrt;
93 static void test_swab( void ) {
94 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
95 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
96 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
97 char expected3[] = "$";
104 /* Test 1 - normal even case */
105 memset(to,'$', sizeof(to));
106 memset(from,'@', sizeof(from));
108 memcpy(from, original, testsize);
109 _swab( from, to, testsize );
110 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
112 /* Test 2 - uneven case */
113 memset(to,'$', sizeof(to));
114 memset(from,'@', sizeof(from));
116 memcpy(from, original, testsize);
117 _swab( from, to, testsize );
118 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
120 /* Test 3 - from = to */
121 memset(to,'$', sizeof(to));
122 memset(from,'@', sizeof(from));
124 memcpy(to, original, testsize);
125 _swab( to, to, testsize );
126 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
128 /* Test 4 - 1 bytes */
129 memset(to,'$', sizeof(to));
130 memset(from,'@', sizeof(from));
132 memcpy(from, original, testsize);
133 _swab( from, to, testsize );
134 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
137 #if 0 /* use this to generate more tests */
139 static void test_codepage(int cp)
145 ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
148 printf("static int result_cp_%d_mbctype[] = { ", cp);
149 for (i = 1; i < 257; i++)
151 if (p_mbctype[i] != prev)
153 printf("0x%x,%d, ", prev, count);
160 printf("0x%x,%d };\n", prev, count);
165 /* RLE-encoded mbctype tables for given codepages */
166 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
167 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
168 static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
170 static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
172 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
173 0x0,2, 0x4,32, 0xc,94, 0,1 };
175 static void test_cp_table(int cp, int *result)
181 for (i = 0; i < 256; i++)
189 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);
194 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
198 static void test_mbcp(void)
200 int mb_orig_max = *p__mb_cur_max;
201 int curr_mbcp = _getmbcp();
202 unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
203 unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
204 unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
205 unsigned char buf[16];
211 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
212 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
213 * CP1252 (or the ACP?) so we test only a few ASCII characters */
215 expect_eq(p_mbctype[10], 0, char, "%x");
216 expect_eq(p_mbctype[50], 0, char, "%x");
217 expect_eq(p_mbctype[66], _SBUP, char, "%x");
218 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
219 expect_eq(p_mbctype[128], 0, char, "%x");
221 expect_eq(p_mbctype[10], 0, char, "%x");
222 expect_eq(p_mbctype[50], 0, char, "%x");
223 expect_eq(p_mbctype[66], _SBUP, char, "%x");
224 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
225 expect_eq(p_mbctype[128], 0, char, "%x");
227 /* double byte code pages */
234 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);
235 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
236 ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
237 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
238 ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
239 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
240 ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
243 expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
244 expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
245 expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
246 expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
247 expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
248 expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
249 expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
250 expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
251 expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
253 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
254 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
255 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
256 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
259 expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
260 expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
261 expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
262 expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
263 expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
264 expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
265 expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
266 expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
267 expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
269 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
270 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
271 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
272 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
273 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
274 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
277 expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
278 expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
279 expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
280 expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
281 expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
282 expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
283 expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
284 expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
285 expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
287 expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
288 expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
289 expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
290 expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
291 expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
292 expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
295 expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
296 expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
297 expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
299 /* _mbclen/_mbslen */
300 expect_eq(_mbclen(mbstring), 2, int, "%d");
301 expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
302 expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
303 expect_eq(_mbslen(mbstring2), 4, int, "%d");
304 expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
305 expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
307 /* _mbccpy/_mbsncpy */
308 memset(buf, 0xff, sizeof(buf));
309 _mbccpy(buf, mbstring);
310 expect_bin(buf, "\xb0\xb1\xff", 3);
312 memset(buf, 0xff, sizeof(buf));
313 _mbsncpy(buf, mbstring, 1);
314 expect_bin(buf, "\xb0\xb1\xff", 3);
315 memset(buf, 0xff, sizeof(buf));
316 _mbsncpy(buf, mbstring, 2);
317 expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
318 memset(buf, 0xff, sizeof(buf));
319 _mbsncpy(buf, mbstring, 3);
320 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
321 memset(buf, 0xff, sizeof(buf));
322 _mbsncpy(buf, mbstring, 4);
323 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
324 memset(buf, 0xff, sizeof(buf));
325 _mbsncpy(buf, mbstring, 5);
326 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
327 memset(buf, 0xff, sizeof(buf));
328 _mbsncpy(buf, mbsonlylead, 6);
329 expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
331 memset(buf, 0xff, sizeof(buf));
332 _mbsnbcpy(buf, mbstring2, 2);
333 expect_bin(buf, "\xb0\xb1\xff", 3);
334 _mbsnbcpy(buf, mbstring2, 3);
335 expect_bin(buf, "\xb0\xb1\0\xff", 4);
336 _mbsnbcpy(buf, mbstring2, 4);
337 expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
338 memset(buf, 0xff, sizeof(buf));
339 _mbsnbcpy(buf, mbsonlylead, 5);
340 expect_bin(buf, "\0\0\0\0\0\xff", 6);
343 step = _mbsinc(mbstring) - mbstring;
344 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
345 step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
346 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
348 step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
349 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
350 step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
351 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
352 step = _mbsninc(mbstring2, 0) - mbstring2;
353 ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
354 step = _mbsninc(mbstring2, 1) - mbstring2;
355 ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
356 step = _mbsninc(mbstring2, 2) - mbstring2;
357 ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
358 step = _mbsninc(mbstring2, 3) - mbstring2;
359 ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
360 step = _mbsninc(mbstring2, 4) - mbstring2;
361 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
362 step = _mbsninc(mbstring2, 5) - mbstring2;
363 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
364 step = _mbsninc(mbstring2, 17) - mbstring2;
365 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
367 /* functions that depend on locale codepage, not mbcp.
368 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
369 * (as of Wine 0.9.43)
371 GetCPInfo(GetACP(), &cp_info);
372 if (cp_info.MaxCharSize == 1)
374 expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
375 expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
378 skip("Current locale has double-byte charset - could lead to false positives\n");
381 expect_eq(_ismbblead(0x80), 0, int, "%d");
383 expect_eq(_ismbblead(0x81), 1, int, "%d");
384 expect_eq(_ismbblead(0x83), 1, int, "%d");
386 expect_eq(_ismbblead(0x84), 1, int, "%d");
387 expect_eq(_ismbblead(0xd3), 1, int, "%d");
388 expect_eq(_ismbblead(0xd7), 0, int, "%d");
390 expect_eq(_ismbblead(0xd8), 1, int, "%d");
392 expect_eq(_ismbblead(0xd9), 1, int, "%d");
394 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
395 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
396 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
397 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
398 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
399 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
400 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
401 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
406 static void test_mbsspn( void)
408 unsigned char str1[]="cabernet";
409 unsigned char str2[]="shiraz";
410 unsigned char set[]="abc";
411 unsigned char empty[]="";
413 ret=_mbsspn( str1, set);
414 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
415 ret=_mbsspn( str2, set);
416 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
417 ret=_mbsspn( str1, empty);
418 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
421 static void test_mbsspnp( void)
423 unsigned char str1[]="cabernet";
424 unsigned char str2[]="shiraz";
425 unsigned char set[]="abc";
426 unsigned char empty[]="";
427 unsigned char full[]="abcenrt";
429 ret=_mbsspnp( str1, set);
430 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
431 ret=_mbsspnp( str2, set);
432 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
433 ret=_mbsspnp( str1, empty);
434 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
435 ret=_mbsspnp( str1, full);
436 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
439 static void test_strdup(void)
443 ok( str == 0, "strdup returns %s should be 0\n", str);
447 static void test_strcpy_s(void)
450 const char *small = "small";
451 const char *big = "atoolongstringforthislittledestination";
456 skip("strcpy_s not found\n");
460 memset(dest, 'X', sizeof(dest));
461 ret = pstrcpy_s(dest, sizeof(dest), small);
462 ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
463 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
464 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
465 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
466 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
468 memset(dest, 'X', sizeof(dest));
469 ret = pstrcpy_s(dest, 0, big);
470 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
471 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
472 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
473 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
474 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
475 ret = pstrcpy_s(dest, 0, NULL);
476 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
477 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
478 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
479 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
480 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
482 memset(dest, 'X', sizeof(dest));
483 ret = pstrcpy_s(dest, sizeof(dest), big);
484 ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
485 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
486 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
487 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
488 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
490 memset(dest, 'X', sizeof(dest));
491 ret = pstrcpy_s(dest, sizeof(dest), NULL);
492 ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
493 ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
494 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
495 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
496 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
498 ret = pstrcpy_s(NULL, sizeof(dest), small);
499 ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
502 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
504 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
505 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
506 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
507 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
508 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
510 static void test_memcpy_s(void)
513 static const char tiny[] = {'T',0,'I','N','Y',0};
514 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
517 skip("memcpy_s not found\n");
521 if (p_set_invalid_parameter_handler)
522 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
523 "Invalid parameter handler was already set\n");
526 memset(dest, 'X', sizeof(dest));
527 ret = p_memcpy_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
528 ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret);
529 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
531 /* Vary source size */
533 memset(dest, 'X', sizeof(dest));
534 ret = p_memcpy_s(dest, NUMELMS(dest), big, NUMELMS(big));
535 ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret);
536 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
537 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
539 /* Replace source with NULL */
541 memset(dest, 'X', sizeof(dest));
542 ret = p_memcpy_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
543 ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret);
544 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
545 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
549 memset(dest, 'X', sizeof(dest));
550 ret = p_memcpy_s(dest, 0, tiny, NUMELMS(tiny));
551 ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret);
552 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
553 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
555 /* Replace dest with NULL */
557 ret = p_memcpy_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
558 ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
559 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
563 memset(dest, 'X', sizeof(dest));
564 ret = p_memcpy_s(dest, 0, NULL, NUMELMS(tiny));
565 ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
566 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
567 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
569 if (p_set_invalid_parameter_handler)
570 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
571 "Cannot reset invalid parameter handler\n");
574 static void test_memmove_s(void)
577 static const char tiny[] = {'T',0,'I','N','Y',0};
578 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
581 skip("memmove_s not found\n");
585 if (p_set_invalid_parameter_handler)
586 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
587 "Invalid parameter handler was already set\n");
590 memset(dest, 'X', sizeof(dest));
591 ret = p_memmove_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
592 ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret);
593 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
596 memcpy(dest, big, sizeof(dest));
597 ret = p_memmove_s(dest+1, NUMELMS(dest)-1, dest, NUMELMS(dest)-1);
598 ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret);
599 okchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]);
601 /* Vary source size */
603 memset(dest, 'X', sizeof(dest));
604 ret = p_memmove_s(dest, NUMELMS(dest), big, NUMELMS(big));
605 ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret);
606 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
607 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
609 /* Replace source with NULL */
611 memset(dest, 'X', sizeof(dest));
612 ret = p_memmove_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
613 ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret);
614 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
615 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
619 memset(dest, 'X', sizeof(dest));
620 ret = p_memmove_s(dest, 0, tiny, NUMELMS(tiny));
621 ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret);
622 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
623 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
625 /* Replace dest with NULL */
627 ret = p_memmove_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
628 ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
629 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
633 memset(dest, 'X', sizeof(dest));
634 ret = p_memmove_s(dest, 0, NULL, NUMELMS(tiny));
635 ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
636 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
637 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
639 if (p_set_invalid_parameter_handler)
640 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
641 "Cannot reset invalid parameter handler\n");
644 static void test_strcat_s(void)
647 const char *small = "sma";
652 skip("strcat_s not found\n");
656 memset(dest, 'X', sizeof(dest));
658 ret = pstrcat_s(dest, sizeof(dest), small);
659 ok(ret == 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
660 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == '\0'&&
661 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
662 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
663 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
664 ret = pstrcat_s(dest, sizeof(dest), small);
665 ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
666 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
667 dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
668 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
669 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
671 ret = pstrcat_s(dest, sizeof(dest), small);
672 ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
673 ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
674 dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
675 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
676 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
678 memset(dest, 'X', sizeof(dest));
682 ret = pstrcat_s(dest, 0, small);
683 ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
684 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
685 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
686 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
687 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
689 ret = pstrcat_s(dest, 0, NULL);
690 ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
691 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
692 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
693 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
694 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
696 ret = pstrcat_s(dest, sizeof(dest), NULL);
697 ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
698 ok(dest[0] == '\0'&& dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
699 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
700 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
701 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
703 ret = pstrcat_s(NULL, sizeof(dest), small);
704 ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
707 static void test__mbsnbcpy_s(void)
709 unsigned char dest[8];
710 const unsigned char big[] = "atoolongstringforthislittledestination";
711 const unsigned char small[] = "small";
716 skip("_mbsnbcpy_s not found\n");
720 memset(dest, 'X', sizeof(dest));
721 ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
722 ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
723 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
724 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
725 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
726 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
729 memset(dest, 'X', sizeof(dest));
730 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
731 ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
732 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
733 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
734 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
735 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
737 memset(dest, 'X', sizeof(dest));
738 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
739 ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
740 ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
741 dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
742 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
743 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
745 memset(dest, 'X', sizeof(dest));
746 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
747 ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
748 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
749 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
750 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
751 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
754 static void test_wcscpy_s(void)
756 static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
757 static WCHAR szDest[18];
758 static WCHAR szDestShort[8];
763 win_skip("wcscpy_s not found\n");
768 ret = p_wcscpy_s(NULL, 18, szLongText);
769 ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
771 /* Test NULL Source */
773 ret = p_wcscpy_s(szDest, 18, NULL);
774 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
775 ok(szDest[0] == 0, "szDest[0] not 0\n");
777 /* Test invalid size */
779 ret = p_wcscpy_s(szDest, 0, szLongText);
780 /* Later versions changed the return value for this case to EINVAL,
781 * and don't modify the result if the dest size is 0.
783 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
784 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
786 /* Copy same buffer size */
787 ret = p_wcscpy_s(szDest, 18, szLongText);
788 ok(ret == 0, "expected 0 got %d\n", ret);
789 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
791 /* Copy smaller buffer size */
793 ret = p_wcscpy_s(szDestShort, 8, szLongText);
794 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
795 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
799 win_skip("wcsncpy_s not found\n");
803 ret = p_wcsncpy_s(NULL, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
804 ok(ret == EINVAL, "p_wcsncpy_s expect EINVAL got %d\n", ret);
807 ret = p_wcsncpy_s(szDest, 18, NULL, 1);
808 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
809 ok(szDest[0] == 0, "szDest[0] not 0\n");
812 ret = p_wcsncpy_s(szDest, 18, NULL, 0);
813 ok(ret == 0, "expected ERROR_SUCCESS got %d\n", ret);
814 ok(szDest[0] == 0, "szDest[0] not 0\n");
817 ret = p_wcsncpy_s(szDest, 0, szLongText, sizeof(szLongText)/sizeof(WCHAR));
818 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
819 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
821 ret = p_wcsncpy_s(szDest, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
822 ok(ret == 0, "expected 0 got %d\n", ret);
823 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
826 ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR));
827 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
828 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
831 ret = p_wcsncpy_s(szDest, 5, szLongText, -1);
832 ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret);
833 ok(szDest[4] == 0, "szDest[4] not 0\n");
834 ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest));
836 ret = p_wcsncpy_s(NULL, 0, (void*)0xdeadbeef, 0);
837 ok(ret == 0, "ret = %d\n", ret);
839 szDestShort[0] = '1';
841 ret = p_wcsncpy_s(szDestShort+1, 4, szDestShort, -1);
842 ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret);
843 ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1',
844 "szDestShort = %s\n", wine_dbgstr_w(szDestShort));
847 static void test__wcsupr_s(void)
849 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
850 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
851 static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
852 'W', 'E', 'R', 'U', 'P', 'P', 'E',
854 WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
859 win_skip("_wcsupr_s not found\n");
863 /* Test NULL input string and invalid size. */
865 ret = p_wcsupr_s(NULL, 0);
866 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
867 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
869 /* Test NULL input string and valid size. */
871 ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
872 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
873 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
875 /* Test empty string with zero size. */
877 testBuffer[0] = '\0';
878 ret = p_wcsupr_s(testBuffer, 0);
879 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
880 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
881 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
883 /* Test empty string with size of one. */
884 testBuffer[0] = '\0';
885 ret = p_wcsupr_s(testBuffer, 1);
886 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
887 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
889 /* Test one-byte buffer with zero size. */
892 ret = p_wcsupr_s(testBuffer, 0);
893 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
894 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
895 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
897 /* Test one-byte buffer with size of one. */
900 ret = p_wcsupr_s(testBuffer, 1);
901 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
902 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
903 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
905 /* Test invalid size. */
906 wcscpy(testBuffer, mixedString);
908 ret = p_wcsupr_s(testBuffer, 0);
909 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
910 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
911 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
913 /* Test normal string uppercasing. */
914 wcscpy(testBuffer, mixedString);
915 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
916 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
917 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
919 /* Test uppercasing with a shorter buffer size count. */
920 wcscpy(testBuffer, mixedString);
922 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
923 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
924 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
925 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
927 /* Test uppercasing with a longer buffer size count. */
928 wcscpy(testBuffer, mixedString);
929 ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
930 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
931 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
934 static void test__wcslwr_s(void)
936 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
937 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
938 static const WCHAR expectedString[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
939 'w', 'e', 'r', 'u', 'p', 'p', 'e',
941 WCHAR buffer[2*sizeof(mixedString)/sizeof(WCHAR)];
946 win_skip("_wcslwr_s not found\n");
950 /* Test NULL input string and invalid size. */
952 ret = p_wcslwr_s(NULL, 0);
953 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
954 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
956 /* Test NULL input string and valid size. */
958 ret = p_wcslwr_s(NULL, sizeof(buffer)/sizeof(wchar_t));
959 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
960 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
962 /* Test empty string with zero size. */
965 ret = p_wcslwr_s(buffer, 0);
966 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
967 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
968 ok(buffer[0] == 0, "expected empty string\n");
970 /* Test empty string with size of one. */
972 ret = p_wcslwr_s(buffer, 1);
973 ok(ret == 0, "got %d\n", ret);
974 ok(buffer[0] == 0, "expected buffer to be unchanged\n");
976 /* Test one-byte buffer with zero size. */
979 ret = p_wcslwr_s(buffer, 0);
980 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
981 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
982 ok(buffer[0] == '\0', "expected empty string\n");
984 /* Test one-byte buffer with size of one. */
987 ret = p_wcslwr_s(buffer, 1);
988 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
989 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
990 ok(buffer[0] == '\0', "expected empty string\n");
992 /* Test invalid size. */
993 wcscpy(buffer, mixedString);
995 ret = p_wcslwr_s(buffer, 0);
996 ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
997 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
998 ok(buffer[0] == '\0', "expected empty string\n");
1000 /* Test normal string uppercasing. */
1001 wcscpy(buffer, mixedString);
1002 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR));
1003 ok(ret == 0, "expected 0, got %d\n", ret);
1004 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1006 /* Test uppercasing with a shorter buffer size count. */
1007 wcscpy(buffer, mixedString);
1009 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
1010 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1011 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1012 ok(buffer[0] == '\0', "expected empty string\n");
1014 /* Test uppercasing with a longer buffer size count. */
1015 wcscpy(buffer, mixedString);
1016 ret = p_wcslwr_s(buffer, sizeof(buffer)/sizeof(WCHAR));
1017 ok(ret == 0, "expected 0, got %d\n", ret);
1018 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1021 static void test_mbcjisjms(void)
1023 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1024 unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1025 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1026 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1027 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1028 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1030 int prev_cp = _getmbcp();
1032 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1035 for (j = 0; jisjms[j][0] != 0; j++)
1037 unsigned int ret, exp;
1038 ret = _mbcjistojms(jisjms[j][0]);
1039 exp = (cp[i] == 932) ? jisjms[j][1] : jisjms[j][0];
1040 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1041 exp, ret, jisjms[j][0], cp[i]);
1047 static void test_mbcjmsjis(void)
1049 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1050 unsigned int jmsjis[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1051 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1052 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1053 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1054 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1055 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1056 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1058 int prev_cp = _getmbcp();
1060 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1063 for (j = 0; jmsjis[j][0] != 0; j++)
1065 unsigned int ret, exp;
1066 ret = _mbcjmstojis(jmsjis[j][0]);
1067 exp = (cp[i] == 932) ? jmsjis[j][1] : jmsjis[j][0];
1068 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1069 exp, ret, jmsjis[j][0], cp[i]);
1075 static void test_mbbtombc(void)
1077 static const unsigned int mbbmbc[][2] = {
1078 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1079 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1080 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1081 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1082 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1084 int prev_cp = _getmbcp();
1086 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1089 for (j = 0; mbbmbc[j][0] != 0; j++)
1091 unsigned int exp, ret;
1092 ret = _mbbtombc(mbbmbc[j][0]);
1093 exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0];
1094 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1095 exp, ret, mbbmbc[j][0], cp[i]);
1101 static void test_mbctombb(void)
1103 static const unsigned int mbcmbb_932[][2] = {
1104 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1105 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1106 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1107 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1108 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1109 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1110 unsigned int exp, ret, i;
1111 unsigned int prev_cp = _getmbcp();
1114 for (i = 0; mbcmbb_932[i][0] != 0; i++)
1116 ret = _mbctombb(mbcmbb_932[i][0]);
1117 exp = mbcmbb_932[i][1];
1118 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1123 static void test_ismbclegal(void) {
1124 unsigned int prev_cp = _getmbcp();
1128 _setmbcp(932); /* Japanese */
1130 for(i = 0; i < 0x10000; i++) {
1131 ret = _ismbclegal(i);
1132 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
1133 (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
1134 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1135 (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
1141 ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1142 _setmbcp(936); /* Chinese (GBK) */
1144 for(i = 0; i < 0x10000; i++) {
1145 ret = _ismbclegal(i);
1146 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1147 LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
1153 ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1154 _setmbcp(949); /* Korean */
1156 for(i = 0; i < 0x10000; i++) {
1157 ret = _ismbclegal(i);
1158 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1159 LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
1165 ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1166 _setmbcp(950); /* Chinese (Big5) */
1168 for(i = 0; i < 0x10000; i++) {
1169 ret = _ismbclegal(i);
1170 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1171 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1172 (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
1178 ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1179 _setmbcp(1361); /* Korean (Johab) */
1181 for(i = 0; i < 0x10000; i++) {
1182 ret = _ismbclegal(i);
1183 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
1184 (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
1185 ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
1186 (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
1193 todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1198 static const struct {
1200 const char* delimiter;
1201 int exp_offsetret1; /* returned offset from string after first call to strtok()
1203 int exp_offsetret2; /* returned offset from string after second call to strtok()
1205 int exp_offsetret3; /* returned offset from string after third call to strtok()
1207 } testcases_strtok[] = {
1208 { "red cabernet", " ", 0, 4, -1 },
1209 { "sparkling white riesling", " ", 0, 10, 16 },
1210 { " pale cream sherry", "e ", 1, 6, 9 },
1215 static void test_strtok(void)
1220 for( i = 0; testcases_strtok[i].string; i++){
1221 strcpy( teststr, testcases_strtok[i].string);
1222 strret = strtok( teststr, testcases_strtok[i].delimiter);
1223 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
1224 (!strret && testcases_strtok[i].exp_offsetret1 == -1),
1225 "string (%p) \'%s\' return %p\n",
1226 teststr, testcases_strtok[i].string, strret);
1227 if( !strret) continue;
1228 strret = strtok( NULL, testcases_strtok[i].delimiter);
1229 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
1230 (!strret && testcases_strtok[i].exp_offsetret2 == -1),
1231 "second call string (%p) \'%s\' return %p\n",
1232 teststr, testcases_strtok[i].string, strret);
1233 if( !strret) continue;
1234 strret = strtok( NULL, testcases_strtok[i].delimiter);
1235 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
1236 (!strret && testcases_strtok[i].exp_offsetret3 == -1),
1237 "third call string (%p) \'%s\' return %p\n",
1238 teststr, testcases_strtok[i].string, strret);
1242 static void test_strtol(void)
1248 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1249 /* errno is modified on W2K8+ */
1251 l = strtol("-1234", &e, 0);
1252 ok(l==-1234, "wrong value %d\n", l);
1253 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1255 ul = strtoul("1234", &e, 0);
1256 ok(ul==1234, "wrong value %u\n", ul);
1257 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1260 l = strtol("2147483647L", &e, 0);
1261 ok(l==2147483647, "wrong value %d\n", l);
1262 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1264 l = strtol("-2147483648L", &e, 0);
1265 ok(l==-2147483647L - 1, "wrong value %d\n", l);
1266 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1268 ul = strtoul("4294967295UL", &e, 0);
1269 ok(ul==4294967295ul, "wrong value %u\n", ul);
1270 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1273 l = strtol("9223372036854775807L", &e, 0);
1274 ok(l==2147483647, "wrong value %d\n", l);
1275 ok(errno == ERANGE, "wrong errno %d\n", errno);
1277 ul = strtoul("9223372036854775807L", &e, 0);
1278 ok(ul==4294967295ul, "wrong value %u\n", ul);
1279 ok(errno == ERANGE, "wrong errno %d\n", errno);
1282 static void test_strnlen(void)
1284 static const char str[] = "string";
1288 win_skip("strnlen not found\n");
1292 res = p_strnlen(str, 20);
1293 ok(res == 6, "Returned length = %d\n", (int)res);
1295 res = p_strnlen(str, 3);
1296 ok(res == 3, "Returned length = %d\n", (int)res);
1298 res = p_strnlen(NULL, 0);
1299 ok(res == 0, "Returned length = %d\n", (int)res);
1302 static void test__strtoi64(void)
1304 static const char no1[] = "31923";
1305 static const char no2[] = "-213312";
1306 static const char no3[] = "12aa";
1307 static const char no4[] = "abc12";
1308 static const char overflow[] = "99999999999999999999";
1309 static const char neg_overflow[] = "-99999999999999999999";
1310 static const char hex[] = "0x123";
1311 static const char oct[] = "000123";
1312 static const char blanks[] = " 12 212.31";
1315 unsigned __int64 ures;
1318 if(!p_strtoi64 || !p_strtoui64) {
1319 win_skip("_strtoi64 or _strtoui64 not found\n");
1324 res = p_strtoi64(no1, NULL, 10);
1325 ok(res == 31923, "res != 31923\n");
1326 res = p_strtoi64(no2, NULL, 10);
1327 ok(res == -213312, "res != -213312\n");
1328 res = p_strtoi64(no3, NULL, 10);
1329 ok(res == 12, "res != 12\n");
1330 res = p_strtoi64(no4, &endpos, 10);
1331 ok(res == 0, "res != 0\n");
1332 ok(endpos == no4, "Scanning was not stopped on first character\n");
1333 res = p_strtoi64(hex, &endpos, 10);
1334 ok(res == 0, "res != 0\n");
1335 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1336 res = p_strtoi64(oct, &endpos, 10);
1337 ok(res == 123, "res != 123\n");
1338 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1339 res = p_strtoi64(blanks, &endpos, 10);
1340 ok(res == 12, "res != 12\n");
1341 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1342 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1345 res = p_strtoi64(overflow, &endpos, 10);
1346 ok(res == _I64_MAX, "res != _I64_MAX\n");
1347 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1348 ok(errno == ERANGE, "errno = %x\n", errno);
1351 res = p_strtoi64(neg_overflow, &endpos, 10);
1352 ok(res == _I64_MIN, "res != _I64_MIN\n");
1353 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1354 ok(errno == ERANGE, "errno = %x\n", errno);
1357 res = p_strtoi64(no1, &endpos, 16);
1358 ok(res == 203043, "res != 203043\n");
1359 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1360 res = p_strtoi64(no2, &endpos, 16);
1361 ok(res == -2175762, "res != -2175762\n");
1362 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1363 res = p_strtoi64(no3, &endpos, 16);
1364 ok(res == 4778, "res != 4778\n");
1365 ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
1366 res = p_strtoi64(no4, &endpos, 16);
1367 ok(res == 703506, "res != 703506\n");
1368 ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
1369 res = p_strtoi64(hex, &endpos, 16);
1370 ok(res == 291, "res != 291\n");
1371 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1372 res = p_strtoi64(oct, &endpos, 16);
1373 ok(res == 291, "res != 291\n");
1374 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1375 res = p_strtoi64(blanks, &endpos, 16);
1376 ok(res == 18, "res != 18\n");
1377 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1378 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1381 res = p_strtoi64(hex, &endpos, 36);
1382 ok(res == 1541019, "res != 1541019\n");
1383 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1384 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1387 res = p_strtoi64(no1, &endpos, 0);
1388 ok(res == 31923, "res != 31923\n");
1389 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1390 res = p_strtoi64(no2, &endpos, 0);
1391 ok(res == -213312, "res != -213312\n");
1392 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1393 res = p_strtoi64(no3, &endpos, 10);
1394 ok(res == 12, "res != 12\n");
1395 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1396 res = p_strtoi64(no4, &endpos, 10);
1397 ok(res == 0, "res != 0\n");
1398 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1399 res = p_strtoi64(hex, &endpos, 10);
1400 ok(res == 0, "res != 0\n");
1401 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1402 res = p_strtoi64(oct, &endpos, 10);
1403 ok(res == 123, "res != 123\n");
1404 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1405 res = p_strtoi64(blanks, &endpos, 10);
1406 ok(res == 12, "res != 12\n");
1407 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1408 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1411 ures = p_strtoui64(no1, &endpos, 0);
1412 ok(ures == 31923, "ures != 31923\n");
1413 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1414 ures = p_strtoui64(no2, &endpos, 0);
1415 ok(ures == -213312, "ures != -213312\n");
1416 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1417 ures = p_strtoui64(no3, &endpos, 10);
1418 ok(ures == 12, "ures != 12\n");
1419 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1420 ures = p_strtoui64(no4, &endpos, 10);
1421 ok(ures == 0, "ures != 0\n");
1422 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1423 ures = p_strtoui64(hex, &endpos, 10);
1424 ok(ures == 0, "ures != 0\n");
1425 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1426 ures = p_strtoui64(oct, &endpos, 10);
1427 ok(ures == 123, "ures != 123\n");
1428 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1429 ures = p_strtoui64(blanks, &endpos, 10);
1430 ok(ures == 12, "ures != 12\n");
1431 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1432 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1435 ures = p_strtoui64(overflow, &endpos, 10);
1436 ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
1437 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1438 ok(errno == ERANGE, "errno = %x\n", errno);
1441 ures = p_strtoui64(neg_overflow, &endpos, 10);
1442 ok(ures == 1, "ures != 1\n");
1443 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1444 ok(errno == ERANGE, "errno = %x\n", errno);
1447 static inline BOOL almost_equal(double d1, double d2) {
1448 if(d1-d2>-1e-30 && d1-d2<1e-30)
1453 static void test__strtod(void)
1455 const char double1[] = "12.1";
1456 const char double2[] = "-13.721";
1457 const char double3[] = "INF";
1458 const char double4[] = ".21e12";
1459 const char double5[] = "214353e-3";
1460 const char overflow[] = "1d9999999999999999999";
1461 const char white_chars[] = " d10";
1466 d = strtod(double1, &end);
1467 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1468 ok(end == double1+4, "incorrect end (%d)\n", (int)(end-double1));
1470 d = strtod(double2, &end);
1471 ok(almost_equal(d, -13.721), "d = %lf\n", d);
1472 ok(end == double2+7, "incorrect end (%d)\n", (int)(end-double2));
1474 d = strtod(double3, &end);
1475 ok(almost_equal(d, 0), "d = %lf\n", d);
1476 ok(end == double3, "incorrect end (%d)\n", (int)(end-double3));
1478 d = strtod(double4, &end);
1479 ok(almost_equal(d, 210000000000.0), "d = %lf\n", d);
1480 ok(end == double4+6, "incorrect end (%d)\n", (int)(end-double4));
1482 d = strtod(double5, &end);
1483 ok(almost_equal(d, 214.353), "d = %lf\n", d);
1484 ok(end == double5+9, "incorrect end (%d)\n", (int)(end-double5));
1486 d = strtod("12.1d2", NULL);
1487 ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
1489 d = strtod(white_chars, &end);
1490 ok(almost_equal(d, 0), "d = %lf\n", d);
1491 ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
1493 /* Set locale with non '.' decimal point (',') */
1494 if(!setlocale(LC_ALL, "Polish")) {
1495 win_skip("system with limited locales\n");
1499 d = strtod("12.1", NULL);
1500 ok(almost_equal(d, 12.0), "d = %lf\n", d);
1502 d = strtod("12,1", NULL);
1503 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1505 setlocale(LC_ALL, "C");
1507 /* Precision tests */
1508 d = strtod("0.1", NULL);
1509 ok(almost_equal(d, 0.1), "d = %lf\n", d);
1510 d = strtod("-0.1", NULL);
1511 ok(almost_equal(d, -0.1), "d = %lf\n", d);
1512 d = strtod("0.1281832188491894198128921", NULL);
1513 ok(almost_equal(d, 0.1281832188491894198128921), "d = %lf\n", d);
1514 d = strtod("0.82181281288121", NULL);
1515 ok(almost_equal(d, 0.82181281288121), "d = %lf\n", d);
1516 d = strtod("21921922352523587651128218821", NULL);
1517 ok(almost_equal(d, 21921922352523587651128218821.0), "d = %lf\n", d);
1518 d = strtod("0.1d238", NULL);
1519 ok(almost_equal(d, 0.1e238L), "d = %lf\n", d);
1520 d = strtod("0.1D-4736", NULL);
1521 ok(almost_equal(d, 0.1e-4736L), "d = %lf\n", d);
1524 strtod(overflow, &end);
1525 ok(errno == ERANGE, "errno = %x\n", errno);
1526 ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
1529 strtod("-1d309", NULL);
1530 ok(errno == ERANGE, "errno = %x\n", errno);
1533 static void test_mbstowcs(void)
1535 static const wchar_t wSimple[] = { 't','e','x','t',0 };
1536 static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
1537 static const char mSimple[] = "text";
1538 static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
1540 const wchar_t *pwstr;
1546 wOut[4] = '!'; wOut[5] = '\0';
1547 mOut[4] = '!'; mOut[5] = '\0';
1549 ret = mbstowcs(NULL, mSimple, 0);
1550 ok(ret == 4, "mbstowcs did not return 4\n");
1552 ret = mbstowcs(wOut, mSimple, 4);
1553 ok(ret == 4, "mbstowcs did not return 4\n");
1554 ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
1555 ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
1557 ret = wcstombs(NULL, wSimple, 0);
1558 ok(ret == 4, "wcstombs did not return 4\n");
1560 ret = wcstombs(mOut, wSimple, 6);
1561 ok(ret == 4, "wcstombs did not return 4\n");
1562 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1564 ret = wcstombs(mOut, wSimple, 2);
1565 ok(ret == 2, "wcstombs did not return 2\n");
1566 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1568 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
1569 win_skip("Japanese_Japan.932 locale not available\n");
1573 ret = mbstowcs(wOut, mHiragana, 6);
1574 ok(ret == 2, "mbstowcs did not return 2\n");
1575 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1577 ret = wcstombs(mOut, wHiragana, 6);
1578 ok(ret == 4, "wcstombs did not return 4\n");
1579 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1581 if(!pmbstowcs_s || !pwcstombs_s) {
1582 setlocale(LC_ALL, "C");
1583 win_skip("mbstowcs_s or wcstombs_s not available\n");
1587 err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
1588 ok(err == 0, "err = %d\n", err);
1589 ok(ret == 5, "mbstowcs_s did not return 5\n");
1590 ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
1592 err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
1593 ok(err == 0, "err = %d\n", err);
1594 ok(ret == 3, "mbstowcs_s did not return 3\n");
1595 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1597 err = pmbstowcs_s(&ret, NULL, 0, mHiragana, 1);
1598 ok(err == 0, "err = %d\n", err);
1599 ok(ret == 3, "mbstowcs_s did not return 3\n");
1601 err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
1602 ok(err == 0, "err = %d\n", err);
1603 ok(ret == 5, "wcstombs_s did not return 5\n");
1604 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1606 err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
1607 ok(err == 0, "err = %d\n", err);
1608 ok(ret == 5, "wcstombs_s did not return 5\n");
1609 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1611 err = pwcstombs_s(&ret, NULL, 0, wHiragana, 1);
1612 ok(err == 0, "err = %d\n", err);
1613 ok(ret == 5, "wcstombs_s did not return 5\n");
1616 setlocale(LC_ALL, "C");
1617 win_skip("wcsrtombs not available\n");
1623 ret = pwcsrtombs(mOut, &pwstr, 4, &err);
1624 ok(ret == 4, "wcsrtombs did not return 4\n");
1625 ok(err == 0, "err = %d\n", err);
1626 ok(pwstr == wSimple+4, "pwstr = %p (wszSimple = %p)\n", pwstr, wSimple);
1627 ok(!memcmp(mOut, mSimple, ret), "mOut = %s\n", mOut);
1630 ret = pwcsrtombs(mOut, &pwstr, 5, NULL);
1631 ok(ret == 4, "wcsrtombs did not return 4\n");
1632 ok(pwstr == NULL, "pwstr != NULL\n");
1633 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1635 setlocale(LC_ALL, "C");
1638 static void test_gcvt(void)
1640 char buf[1024], *res;
1644 win_skip("Skipping _gcvt tests\n");
1649 res = _gcvt(1.2, -1, buf);
1650 ok(res == NULL, "res != NULL\n");
1651 ok(errno == ERANGE, "errno = %d\n", errno);
1654 res = _gcvt(1.2, 5, NULL);
1655 ok(res == NULL, "res != NULL\n");
1656 ok(errno == EINVAL, "errno = %d\n", errno);
1658 res = gcvt(1.2, 5, buf);
1659 ok(res == buf, "res != buf\n");
1660 ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
1663 err = p_gcvt_s(buf, 5, 1.2, 10);
1664 ok(err == ERANGE, "err = %d\n", err);
1665 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1668 err = p_gcvt_s(buf, 4, 123456, 2);
1669 ok(err == ERANGE, "err = %d\n", err);
1670 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1673 static void test__itoa_s(void)
1680 win_skip("Skipping _itoa_s tests\n");
1684 if (p_set_invalid_parameter_handler)
1685 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1686 "Invalid parameter handler was already set\n");
1689 ret = p_itoa_s(0, NULL, 0, 0);
1690 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1691 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1693 memset(buffer, 'X', sizeof(buffer));
1695 ret = p_itoa_s(0, buffer, 0, 0);
1696 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1697 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1698 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1700 memset(buffer, 'X', sizeof(buffer));
1702 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
1703 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1704 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1705 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1707 memset(buffer, 'X', sizeof(buffer));
1709 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
1710 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1711 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1712 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1714 memset(buffer, 'X', sizeof(buffer));
1716 ret = p_itoa_s(12345678, buffer, 4, 10);
1717 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1718 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1719 ok(!memcmp(buffer, "\000765", 4),
1720 "Expected the output buffer to be null terminated with truncated output\n");
1722 memset(buffer, 'X', sizeof(buffer));
1724 ret = p_itoa_s(12345678, buffer, 8, 10);
1725 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1726 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1727 ok(!memcmp(buffer, "\0007654321", 8),
1728 "Expected the output buffer to be null terminated with truncated output\n");
1730 memset(buffer, 'X', sizeof(buffer));
1732 ret = p_itoa_s(-12345678, buffer, 9, 10);
1733 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1734 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1735 ok(!memcmp(buffer, "\00087654321", 9),
1736 "Expected the output buffer to be null terminated with truncated output\n");
1738 ret = p_itoa_s(12345678, buffer, 9, 10);
1739 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1740 ok(!strcmp(buffer, "12345678"),
1741 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1744 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
1745 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1746 ok(!strcmp(buffer, "1010101010101010"),
1747 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1750 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
1751 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1752 ok(!strcmp(buffer, "nell"),
1753 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1756 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
1757 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1758 ok(!strcmp(buffer, "hag"),
1759 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1762 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
1763 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1764 ok(!strcmp(buffer, "-12345678"),
1765 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1767 if (p_set_invalid_parameter_handler)
1768 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1769 "Cannot reset invalid parameter handler\n");
1772 static void test__strlwr_s(void)
1779 win_skip("Skipping _strlwr_s tests\n");
1784 ret = p_strlwr_s(NULL, 0);
1785 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1786 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1789 ret = p_strlwr_s(NULL, sizeof(buffer));
1790 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1791 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1794 ret = p_strlwr_s(buffer, 0);
1795 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1796 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1798 strcpy(buffer, "GoRrIsTeR");
1800 ret = p_strlwr_s(buffer, 5);
1801 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1802 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1803 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1804 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1806 strcpy(buffer, "GoRrIsTeR");
1808 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
1809 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1810 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1811 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1812 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1814 strcpy(buffer, "GoRrIsTeR");
1815 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
1816 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1817 ok(!strcmp(buffer, "gorrister"),
1818 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1821 memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1822 ret = p_strlwr_s(buffer, sizeof(buffer));
1823 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1824 ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1825 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1829 static void test_wcsncat_s(void)
1831 static wchar_t abcW[] = {'a','b','c',0};
1838 win_skip("skipping wcsncat_s tests\n");
1842 if (p_set_invalid_parameter_handler)
1843 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1844 "Invalid parameter handler was already set\n");
1846 memcpy(src, abcW, sizeof(abcW));
1848 ret = p_wcsncat_s(NULL, 4, src, 4);
1849 ok(ret == EINVAL, "err = %d\n", ret);
1850 ret = p_wcsncat_s(dst, 0, src, 4);
1851 ok(ret == EINVAL, "err = %d\n", ret);
1852 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
1853 ok(ret == EINVAL, "err = %d\n", ret);
1854 ret = p_wcsncat_s(dst, 4, NULL, 0);
1855 ok(ret == 0, "err = %d\n", ret);
1858 ret = p_wcsncat_s(dst, 2, src, 4);
1859 ok(ret == ERANGE, "err = %d\n", ret);
1862 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
1863 ok(ret == STRUNCATE, "err = %d\n", ret);
1864 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
1866 memcpy(dst, abcW, sizeof(abcW));
1868 ret = p_wcsncat_s(dst, 4, src, 4);
1869 ok(ret == EINVAL, "err = %d\n", ret);
1871 if (p_set_invalid_parameter_handler)
1872 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1873 "Cannot reset invalid parameter handler\n");
1876 static void test__mbsnbcat_s(void)
1878 unsigned char dest[16];
1879 const unsigned char first[] = "dinosaur";
1880 const unsigned char second[] = "duck";
1885 win_skip("Skipping _mbsnbcat_s tests\n");
1889 /* Test invalid arguments. */
1890 ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
1891 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1894 ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
1895 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1896 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1899 ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
1900 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1901 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1903 memset(dest, 'X', sizeof(dest));
1905 ret = p_mbsnbcat_s(dest, 0, NULL, 0);
1906 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1907 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1908 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1910 memset(dest, 'X', sizeof(dest));
1912 ret = p_mbsnbcat_s(dest, 0, second, 0);
1913 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1914 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1915 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1917 memset(dest, 'X', sizeof(dest));
1919 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
1920 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1921 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1922 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1924 memset(dest, 'X', sizeof(dest));
1926 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
1927 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1928 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1929 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1931 memset(dest, 'X', sizeof(dest));
1933 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1934 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1935 ok(!memcmp(dest, second, sizeof(second)),
1936 "Expected the output buffer string to be \"duck\"\n");
1938 /* Test source truncation behavior. */
1939 memset(dest, 'X', sizeof(dest));
1940 memcpy(dest, first, sizeof(first));
1941 ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
1942 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1943 ok(!memcmp(dest, first, sizeof(first)),
1944 "Expected the output buffer string to be \"dinosaur\"\n");
1946 memset(dest, 'X', sizeof(dest));
1947 memcpy(dest, first, sizeof(first));
1948 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1949 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1950 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1951 "Expected the output buffer string to be \"dinosaurduck\"\n");
1953 memset(dest, 'X', sizeof(dest));
1954 memcpy(dest, first, sizeof(first));
1955 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
1956 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1957 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1958 "Expected the output buffer string to be \"dinosaurduck\"\n");
1960 memset(dest, 'X', sizeof(dest));
1961 memcpy(dest, first, sizeof(first));
1962 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
1963 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1964 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1965 "Expected the output buffer string to be \"dinosaurduck\"\n");
1967 memset(dest, 'X', sizeof(dest));
1968 memcpy(dest, first, sizeof(first));
1969 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
1970 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1971 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
1972 "Expected the output buffer string to be \"dinosaurduc\"\n");
1974 /* Test destination truncation behavior. */
1975 memset(dest, 'X', sizeof(dest));
1976 memcpy(dest, first, sizeof(first));
1978 ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
1979 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1980 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1981 ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
1982 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
1984 memset(dest, 'X', sizeof(dest));
1985 memcpy(dest, first, sizeof(first));
1987 ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
1988 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1989 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1990 ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
1991 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
1993 memset(dest, 'X', sizeof(dest));
1994 memcpy(dest, first, sizeof(first));
1996 ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
1997 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1998 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1999 ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2000 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2003 static void test__mbsupr_s(void)
2006 unsigned char buffer[20];
2010 win_skip("Skipping _mbsupr_s tests\n");
2015 ret = p_mbsupr_s(NULL, 0);
2016 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2019 ret = p_mbsupr_s(NULL, sizeof(buffer));
2020 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2021 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2024 ret = p_mbsupr_s(buffer, 0);
2025 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2026 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2028 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2030 ret = p_mbsupr_s(buffer, sizeof("abcdefgh"));
2031 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2032 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2033 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2036 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2038 ret = p_mbsupr_s(buffer, sizeof(buffer));
2039 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2040 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2041 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2044 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2046 ret = p_mbsupr_s(buffer, 4);
2047 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2048 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2050 memcpy(buffer, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2052 ret = p_mbsupr_s(buffer, sizeof(buffer));
2053 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2054 ok(!memcmp(buffer, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2055 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2060 static void test__mbslwr_s(void)
2063 unsigned char buffer[20];
2067 win_skip("Skipping _mbslwr_s tests\n");
2072 ret = p_mbslwr_s(NULL, 0);
2073 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2076 ret = p_mbslwr_s(NULL, sizeof(buffer));
2077 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2078 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2081 ret = p_mbslwr_s(buffer, 0);
2082 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2083 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2085 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2087 ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH"));
2088 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2089 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2090 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2093 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2095 ret = p_mbslwr_s(buffer, sizeof(buffer));
2096 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2097 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2098 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2101 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2103 ret = p_mbslwr_s(buffer, 4);
2104 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2105 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2107 memcpy(buffer, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2109 ret = p_mbslwr_s(buffer, sizeof(buffer));
2110 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2111 ok(!memcmp(buffer, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2112 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2116 static void test__ultoa_s(void)
2123 win_skip("Skipping _ultoa_s tests\n");
2128 ret = p_ultoa_s(0, NULL, 0, 0);
2129 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2130 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2132 memset(buffer, 'X', sizeof(buffer));
2134 ret = p_ultoa_s(0, buffer, 0, 0);
2135 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2136 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2137 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
2139 memset(buffer, 'X', sizeof(buffer));
2141 ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
2142 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2143 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2144 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2146 memset(buffer, 'X', sizeof(buffer));
2148 ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
2149 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2150 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2151 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2153 memset(buffer, 'X', sizeof(buffer));
2155 ret = p_ultoa_s(12345678, buffer, 4, 10);
2156 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2157 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2158 ok(!memcmp(buffer, "\000765", 4),
2159 "Expected the output buffer to be null terminated with truncated output\n");
2161 memset(buffer, 'X', sizeof(buffer));
2163 ret = p_ultoa_s(12345678, buffer, 8, 10);
2164 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2165 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2166 ok(!memcmp(buffer, "\0007654321", 8),
2167 "Expected the output buffer to be null terminated with truncated output\n");
2169 ret = p_ultoa_s(12345678, buffer, 9, 10);
2170 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2171 ok(!strcmp(buffer, "12345678"),
2172 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2175 ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
2176 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2177 ok(!strcmp(buffer, "1010101010101010"),
2178 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2181 ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
2182 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2183 ok(!strcmp(buffer, "nell"),
2184 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2187 ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
2188 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2189 ok(!strcmp(buffer, "hag"),
2190 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2194 static void test_wctob(void)
2198 if(!p_wctob || !setlocale(LC_ALL, "chinese-traditional")) {
2199 win_skip("Skipping wctob tests\n");
2203 ret = p_wctob(0x8141);
2204 ok(ret == EOF, "ret = %x\n", ret);
2206 ret = p_wctob(0x81);
2207 ok(ret == EOF, "ret = %x\n", ret);
2209 ret = p_wctob(0xe0);
2210 ok(ret == 0x61, "ret = %x\n", ret);
2213 ret = p_wctob(0x81);
2214 ok(ret == EOF, "ret = %x\n", ret);
2216 setlocale(LC_ALL, "C");
2217 ret = p_wctob(0x8141);
2218 ok(ret == EOF, "ret = %x\n", ret);
2220 ret = p_wctob(0x81);
2221 ok(ret == (int)(char)0x81, "ret = %x\n", ret);
2223 ret = p_wctob(0x9f);
2224 ok(ret == (int)(char)0x9f, "ret = %x\n", ret);
2226 ret = p_wctob(0xe0);
2227 ok(ret == (int)(char)0xe0, "ret = %x\n", ret);
2230 static void test_tolower(void)
2234 ret = p_tolower(0x41);
2235 ok(ret == 0x61, "ret = %x\n", ret);
2237 ret = p_tolower(0xF4);
2238 ok(ret == 0xF4, "ret = %x\n", ret);
2240 ret = p_tolower((char)0xF4);
2241 ok(ret==0xF4/*Vista+*/ || ret==(char)0xF4, "ret = %x\n", ret);
2243 /* is it using different locale (CP_ACP) for negative values?? */
2244 /* current implementation matches msvcr90 behaviour */
2245 ret = p_tolower((char)0xD0);
2246 todo_wine ok(ret==0xF0/*Vista+*/ || ret==(char)0xD0, "ret = %x\n", ret);
2248 ret = p_tolower(0xD0);
2249 ok(ret == 0xD0, "ret = %x\n", ret);
2251 if(!setlocale(LC_ALL, "us")) {
2252 win_skip("skipping tolower tests that depends on locale\n");
2256 ret = p_tolower((char)0xD0);
2257 ok(ret == 0xF0, "ret = %x\n", ret);
2259 ret = p_tolower(0xD0);
2260 ok(ret == 0xF0, "ret = %x\n", ret);
2262 setlocale(LC_ALL, "C");
2268 static const char xilstring[]="c:/xilinx";
2271 hMsvcrt = GetModuleHandleA("msvcrt.dll");
2273 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
2274 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
2275 SET(pmemcpy,"memcpy");
2276 p_memcpy_s = (void*)GetProcAddress( hMsvcrt, "memcpy_s" );
2277 p_memmove_s = (void*)GetProcAddress( hMsvcrt, "memmove_s" );
2278 SET(pmemcmp,"memcmp");
2279 SET(p_mbctype,"_mbctype");
2280 SET(p__mb_cur_max,"__mb_cur_max");
2281 pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
2282 pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
2283 p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
2284 p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
2285 p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
2286 p_wcsncpy_s = (void *)GetProcAddress( hMsvcrt,"wcsncpy_s" );
2287 p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
2288 p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
2289 p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
2290 p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
2291 p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
2292 pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
2293 pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
2294 pwcsrtombs = (void *)GetProcAddress(hMsvcrt, "wcsrtombs");
2295 p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
2296 p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
2297 p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
2298 p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
2299 p_set_invalid_parameter_handler = (void *) GetProcAddress(hMsvcrt, "_set_invalid_parameter_handler");
2300 p_wcslwr_s = (void*)GetProcAddress(hMsvcrt, "_wcslwr_s");
2301 p_mbsupr_s = (void*)GetProcAddress(hMsvcrt, "_mbsupr_s");
2302 p_mbslwr_s = (void*)GetProcAddress(hMsvcrt, "_mbslwr_s");
2303 p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob");
2304 p_tolower = (void*)GetProcAddress(hMsvcrt, "tolower");
2306 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2307 MFC42 CString::Insert seems to rely on that behaviour */
2308 strcpy(mem,xilstring);
2309 nLen=strlen(xilstring);
2310 pmemcpy(mem+5, mem,nLen+1);
2311 ok(pmemcmp(mem+5,xilstring, nLen) == 0,
2312 "Got result %s\n",mem+5);
2314 /* Test _swab function */