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 *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_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
62 static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
63 static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
64 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
65 static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
66 static size_t (__cdecl *p_strnlen)(const char *, size_t);
67 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
68 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
69 static int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
70 static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
71 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
72 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
73 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
74 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
75 static int *p__mb_cur_max;
76 static unsigned char *p_mbctype;
77 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
79 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
80 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
82 static HMODULE hMsvcrt;
84 static void test_swab( void ) {
85 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
86 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
87 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
88 char expected3[] = "$";
95 /* Test 1 - normal even case */
96 memset(to,'$', sizeof(to));
97 memset(from,'@', sizeof(from));
99 memcpy(from, original, testsize);
100 _swab( from, to, testsize );
101 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
103 /* Test 2 - uneven case */
104 memset(to,'$', sizeof(to));
105 memset(from,'@', sizeof(from));
107 memcpy(from, original, testsize);
108 _swab( from, to, testsize );
109 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
111 /* Test 3 - from = to */
112 memset(to,'$', sizeof(to));
113 memset(from,'@', sizeof(from));
115 memcpy(to, original, testsize);
116 _swab( to, to, testsize );
117 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
119 /* Test 4 - 1 bytes */
120 memset(to,'$', sizeof(to));
121 memset(from,'@', sizeof(from));
123 memcpy(from, original, testsize);
124 _swab( from, to, testsize );
125 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
128 #if 0 /* use this to generate more tests */
130 static void test_codepage(int cp)
136 ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
139 printf("static int result_cp_%d_mbctype[] = { ", cp);
140 for (i = 1; i < 257; i++)
142 if (p_mbctype[i] != prev)
144 printf("0x%x,%d, ", prev, count);
151 printf("0x%x,%d };\n", prev, count);
156 /* RLE-encoded mbctype tables for given codepages */
157 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
158 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
159 static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
161 static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
163 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
164 0x0,2, 0x4,32, 0xc,94, 0,1 };
166 static void test_cp_table(int cp, int *result)
172 for (i = 0; i < 256; i++)
180 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);
185 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
189 static void test_mbcp(void)
191 int mb_orig_max = *p__mb_cur_max;
192 int curr_mbcp = _getmbcp();
193 unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
194 unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
195 unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
196 unsigned char buf[16];
202 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
203 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
204 * CP1252 (or the ACP?) so we test only a few ASCII characters */
206 expect_eq(p_mbctype[10], 0, char, "%x");
207 expect_eq(p_mbctype[50], 0, char, "%x");
208 expect_eq(p_mbctype[66], _SBUP, char, "%x");
209 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
210 expect_eq(p_mbctype[128], 0, char, "%x");
212 expect_eq(p_mbctype[10], 0, char, "%x");
213 expect_eq(p_mbctype[50], 0, char, "%x");
214 expect_eq(p_mbctype[66], _SBUP, char, "%x");
215 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
216 expect_eq(p_mbctype[128], 0, char, "%x");
218 /* double byte code pages */
225 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);
226 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
227 ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
228 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
229 ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
230 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
231 ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
234 expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
235 expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
236 expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
237 expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
238 expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
239 expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
240 expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
241 expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
242 expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
244 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
245 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
246 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
247 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
250 expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
251 expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
252 expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
253 expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
254 expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
255 expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
256 expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
257 expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
258 expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
260 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
261 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
262 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
263 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
264 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
265 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
268 expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
269 expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
270 expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
271 expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
272 expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
273 expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
274 expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
275 expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
276 expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
278 expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
279 expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
280 expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
281 expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
282 expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
283 expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
286 expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
287 expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
288 expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
290 /* _mbclen/_mbslen */
291 expect_eq(_mbclen(mbstring), 2, int, "%d");
292 expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
293 expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
294 expect_eq(_mbslen(mbstring2), 4, int, "%d");
295 expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
296 expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
298 /* _mbccpy/_mbsncpy */
299 memset(buf, 0xff, sizeof(buf));
300 _mbccpy(buf, mbstring);
301 expect_bin(buf, "\xb0\xb1\xff", 3);
303 memset(buf, 0xff, sizeof(buf));
304 _mbsncpy(buf, mbstring, 1);
305 expect_bin(buf, "\xb0\xb1\xff", 3);
306 memset(buf, 0xff, sizeof(buf));
307 _mbsncpy(buf, mbstring, 2);
308 expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
309 memset(buf, 0xff, sizeof(buf));
310 _mbsncpy(buf, mbstring, 3);
311 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
312 memset(buf, 0xff, sizeof(buf));
313 _mbsncpy(buf, mbstring, 4);
314 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
315 memset(buf, 0xff, sizeof(buf));
316 _mbsncpy(buf, mbstring, 5);
317 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
318 memset(buf, 0xff, sizeof(buf));
319 _mbsncpy(buf, mbsonlylead, 6);
320 expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
322 memset(buf, 0xff, sizeof(buf));
323 _mbsnbcpy(buf, mbstring2, 2);
324 expect_bin(buf, "\xb0\xb1\xff", 3);
325 _mbsnbcpy(buf, mbstring2, 3);
326 expect_bin(buf, "\xb0\xb1\0\xff", 4);
327 _mbsnbcpy(buf, mbstring2, 4);
328 expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
329 memset(buf, 0xff, sizeof(buf));
330 _mbsnbcpy(buf, mbsonlylead, 5);
331 expect_bin(buf, "\0\0\0\0\0\xff", 6);
334 step = _mbsinc(mbstring) - mbstring;
335 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
336 step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
337 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
339 step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
340 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
341 step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
342 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
343 step = _mbsninc(mbstring2, 0) - mbstring2;
344 ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
345 step = _mbsninc(mbstring2, 1) - mbstring2;
346 ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
347 step = _mbsninc(mbstring2, 2) - mbstring2;
348 ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
349 step = _mbsninc(mbstring2, 3) - mbstring2;
350 ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
351 step = _mbsninc(mbstring2, 4) - mbstring2;
352 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
353 step = _mbsninc(mbstring2, 5) - mbstring2;
354 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
355 step = _mbsninc(mbstring2, 17) - mbstring2;
356 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
358 /* functions that depend on locale codepage, not mbcp.
359 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
360 * (as of Wine 0.9.43)
362 GetCPInfo(GetACP(), &cp_info);
363 if (cp_info.MaxCharSize == 1)
365 expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
366 expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
369 skip("Current locale has double-byte charset - could lead to false positives\n");
372 expect_eq(_ismbblead(0x80), 0, int, "%d");
374 expect_eq(_ismbblead(0x81), 1, int, "%d");
375 expect_eq(_ismbblead(0x83), 1, int, "%d");
377 expect_eq(_ismbblead(0x84), 1, int, "%d");
378 expect_eq(_ismbblead(0xd3), 1, int, "%d");
379 expect_eq(_ismbblead(0xd7), 0, int, "%d");
381 expect_eq(_ismbblead(0xd8), 1, int, "%d");
383 expect_eq(_ismbblead(0xd9), 1, int, "%d");
385 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
386 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
387 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
388 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
389 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
390 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
391 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
392 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
397 static void test_mbsspn( void)
399 unsigned char str1[]="cabernet";
400 unsigned char str2[]="shiraz";
401 unsigned char set[]="abc";
402 unsigned char empty[]="";
404 ret=_mbsspn( str1, set);
405 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
406 ret=_mbsspn( str2, set);
407 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
408 ret=_mbsspn( str1, empty);
409 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
412 static void test_mbsspnp( void)
414 unsigned char str1[]="cabernet";
415 unsigned char str2[]="shiraz";
416 unsigned char set[]="abc";
417 unsigned char empty[]="";
418 unsigned char full[]="abcenrt";
420 ret=_mbsspnp( str1, set);
421 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
422 ret=_mbsspnp( str2, set);
423 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
424 ret=_mbsspnp( str1, empty);
425 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
426 ret=_mbsspnp( str1, full);
427 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
430 static void test_strdup(void)
434 ok( str == 0, "strdup returns %s should be 0\n", str);
438 static void test_strcpy_s(void)
441 const char *small = "small";
442 const char *big = "atoolongstringforthislittledestination";
447 skip("strcpy_s not found\n");
451 memset(dest, 'X', sizeof(dest));
452 ret = pstrcpy_s(dest, sizeof(dest), small);
453 ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
454 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
455 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
456 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
457 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
459 memset(dest, 'X', sizeof(dest));
460 ret = pstrcpy_s(dest, 0, big);
461 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
462 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
463 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
464 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
465 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
466 ret = pstrcpy_s(dest, 0, NULL);
467 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
468 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
469 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
470 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
471 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
473 memset(dest, 'X', sizeof(dest));
474 ret = pstrcpy_s(dest, sizeof(dest), big);
475 ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
476 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
477 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
478 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
479 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
481 memset(dest, 'X', sizeof(dest));
482 ret = pstrcpy_s(dest, sizeof(dest), NULL);
483 ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
484 ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
485 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
486 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
487 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
489 ret = pstrcpy_s(NULL, sizeof(dest), small);
490 ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
493 static void test_strcat_s(void)
496 const char *small = "sma";
501 skip("strcat_s not found\n");
505 memset(dest, 'X', sizeof(dest));
507 ret = pstrcat_s(dest, sizeof(dest), small);
508 ok(ret == 0, "strcat_s: 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] == '\0'&&
510 dest[4] == 'X' && dest[5] == 'X' && 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]);
513 ret = pstrcat_s(dest, sizeof(dest), small);
514 ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
515 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
516 dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
517 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
518 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
520 ret = pstrcat_s(dest, sizeof(dest), small);
521 ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
522 ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
523 dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
524 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
525 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
527 memset(dest, 'X', sizeof(dest));
531 ret = pstrcat_s(dest, 0, small);
532 ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
533 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
534 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
535 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
536 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
538 ret = pstrcat_s(dest, 0, NULL);
539 ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
540 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
541 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
542 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
543 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
545 ret = pstrcat_s(dest, sizeof(dest), NULL);
546 ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
547 ok(dest[0] == '\0'&& dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
548 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
549 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
550 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
552 ret = pstrcat_s(NULL, sizeof(dest), small);
553 ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
556 static void test__mbsnbcpy_s(void)
558 unsigned char dest[8];
559 const unsigned char big[] = "atoolongstringforthislittledestination";
560 const unsigned char small[] = "small";
565 skip("_mbsnbcpy_s not found\n");
569 memset(dest, 'X', sizeof(dest));
570 ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
571 ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
572 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
573 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
574 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
575 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
578 memset(dest, 'X', sizeof(dest));
579 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
580 ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
581 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
582 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
583 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
584 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
586 memset(dest, 'X', sizeof(dest));
587 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
588 ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
589 ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
590 dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
591 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
592 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
594 memset(dest, 'X', sizeof(dest));
595 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
596 ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
597 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
598 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
599 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
600 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
603 static void test_wcscpy_s(void)
605 static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
606 static WCHAR szDest[18];
607 static WCHAR szDestShort[8];
612 skip("wcscpy_s not found\n");
617 ret = p_wcscpy_s(NULL, 18, szLongText);
618 ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
620 /* Test NULL Source */
622 ret = p_wcscpy_s(szDest, 18, NULL);
623 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
624 ok(szDest[0] == 0, "szDest[0] not 0\n");
626 /* Test invalid size */
628 ret = p_wcscpy_s(szDest, 0, szLongText);
629 /* Later versions changed the return value for this case to EINVAL,
630 * and don't modify the result if the dest size is 0.
632 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
633 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
635 /* Copy same buffer size */
636 ret = p_wcscpy_s(szDest, 18, szLongText);
637 ok(ret == 0, "expected 0 got %d\n", ret);
638 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
640 /* Copy smaller buffer size */
642 ret = p_wcscpy_s(szDestShort, 8, szLongText);
643 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
644 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
647 static void test__wcsupr_s(void)
649 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
650 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
651 static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
652 'W', 'E', 'R', 'U', 'P', 'P', 'E',
654 WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
659 win_skip("_wcsupr_s not found\n");
663 /* Test NULL input string and invalid size. */
665 ret = p_wcsupr_s(NULL, 0);
666 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
667 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
669 /* Test NULL input string and valid size. */
671 ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
672 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
673 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
675 /* Test empty string with zero size. */
677 testBuffer[0] = '\0';
678 ret = p_wcsupr_s(testBuffer, 0);
679 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
680 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
681 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
683 /* Test empty string with size of one. */
684 testBuffer[0] = '\0';
685 ret = p_wcsupr_s(testBuffer, 1);
686 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
687 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
689 /* Test one-byte buffer with zero size. */
692 ret = p_wcsupr_s(testBuffer, 0);
693 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
694 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
695 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
697 /* Test one-byte buffer with size of one. */
700 ret = p_wcsupr_s(testBuffer, 1);
701 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
702 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
703 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
705 /* Test invalid size. */
706 wcscpy(testBuffer, mixedString);
708 ret = p_wcsupr_s(testBuffer, 0);
709 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
710 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
711 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
713 /* Test normal string uppercasing. */
714 wcscpy(testBuffer, mixedString);
715 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
716 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
717 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
719 /* Test uppercasing with a shorter buffer size count. */
720 wcscpy(testBuffer, mixedString);
722 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
723 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
724 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
725 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
727 /* Test uppercasing with a longer buffer size count. */
728 wcscpy(testBuffer, mixedString);
729 ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
730 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
731 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
734 static void test_mbcjisjms(void)
736 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
737 unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
738 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
739 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
740 unsigned int ret, exp, i;
745 ret = _mbcjistojms(jisjms[i][0]);
747 if(_getmbcp() == 932) /* Japanese codepage? */
750 exp = jisjms[i][0]; /* If not, no conversion */
752 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
753 } while(jisjms[i++][0] != 0);
756 static void test_mbctombb(void)
758 static const unsigned int mbcmbb_932[][2] = {
759 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
760 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
761 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
762 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
763 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
764 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
765 unsigned int exp, ret, i;
766 unsigned int prev_cp = _getmbcp();
769 for (i = 0; mbcmbb_932[i][0] != 0; i++)
771 ret = _mbctombb(mbcmbb_932[i][0]);
772 exp = mbcmbb_932[i][1];
773 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
778 static void test_ismbclegal(void) {
779 unsigned int prev_cp = _getmbcp();
783 _setmbcp(932); /* Japanese */
785 for(i = 0; i < 0x10000; i++) {
786 ret = _ismbclegal(i);
787 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
788 (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
789 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
790 (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
796 ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
797 _setmbcp(936); /* Chinese (GBK) */
799 for(i = 0; i < 0x10000; i++) {
800 ret = _ismbclegal(i);
801 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
802 LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
808 ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
809 _setmbcp(949); /* Korean */
811 for(i = 0; i < 0x10000; i++) {
812 ret = _ismbclegal(i);
813 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
814 LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
820 ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
821 _setmbcp(950); /* Chinese (Big5) */
823 for(i = 0; i < 0x10000; i++) {
824 ret = _ismbclegal(i);
825 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
826 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
827 (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
833 ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
834 _setmbcp(1361); /* Korean (Johab) */
836 for(i = 0; i < 0x10000; i++) {
837 ret = _ismbclegal(i);
838 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
839 (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
840 ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
841 (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
848 todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
853 static const struct {
855 const char* delimiter;
856 int exp_offsetret1; /* returned offset from string after first call to strtok()
858 int exp_offsetret2; /* returned offset from string after second call to strtok()
860 int exp_offsetret3; /* returned offset from string after third call to strtok()
862 } testcases_strtok[] = {
863 { "red cabernet", " ", 0, 4, -1 },
864 { "sparkling white riesling", " ", 0, 10, 16 },
865 { " pale cream sherry", "e ", 1, 6, 9 },
870 static void test_strtok(void)
875 for( i = 0; testcases_strtok[i].string; i++){
876 strcpy( teststr, testcases_strtok[i].string);
877 strret = strtok( teststr, testcases_strtok[i].delimiter);
878 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
879 (!strret && testcases_strtok[i].exp_offsetret1 == -1),
880 "string (%p) \'%s\' return %p\n",
881 teststr, testcases_strtok[i].string, strret);
882 if( !strret) continue;
883 strret = strtok( NULL, testcases_strtok[i].delimiter);
884 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
885 (!strret && testcases_strtok[i].exp_offsetret2 == -1),
886 "second call string (%p) \'%s\' return %p\n",
887 teststr, testcases_strtok[i].string, strret);
888 if( !strret) continue;
889 strret = strtok( NULL, testcases_strtok[i].delimiter);
890 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
891 (!strret && testcases_strtok[i].exp_offsetret3 == -1),
892 "third call string (%p) \'%s\' return %p\n",
893 teststr, testcases_strtok[i].string, strret);
897 static void test_strtol(void)
903 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
904 /* errno is modified on W2K8+ */
906 l = strtol("-1234", &e, 0);
907 ok(l==-1234, "wrong value %d\n", l);
908 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
910 ul = strtoul("1234", &e, 0);
911 ok(ul==1234, "wrong value %u\n", ul);
912 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
915 l = strtol("2147483647L", &e, 0);
916 ok(l==2147483647, "wrong value %d\n", l);
917 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
919 l = strtol("-2147483648L", &e, 0);
920 ok(l==-2147483647L - 1, "wrong value %d\n", l);
921 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
923 ul = strtoul("4294967295UL", &e, 0);
924 ok(ul==4294967295ul, "wrong value %u\n", ul);
925 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
928 l = strtol("9223372036854775807L", &e, 0);
929 ok(l==2147483647, "wrong value %d\n", l);
930 ok(errno == ERANGE, "wrong errno %d\n", errno);
932 ul = strtoul("9223372036854775807L", &e, 0);
933 ok(ul==4294967295ul, "wrong value %u\n", ul);
934 ok(errno == ERANGE, "wrong errno %d\n", errno);
937 static void test_strnlen(void)
939 static const char str[] = "string";
943 win_skip("strnlen not found\n");
947 res = p_strnlen(str, 20);
948 ok(res == 6, "Returned length = %d\n", (int)res);
950 res = p_strnlen(str, 3);
951 ok(res == 3, "Returned length = %d\n", (int)res);
953 res = p_strnlen(NULL, 0);
954 ok(res == 0, "Returned length = %d\n", (int)res);
957 static void test__strtoi64(void)
959 static const char no1[] = "31923";
960 static const char no2[] = "-213312";
961 static const char no3[] = "12aa";
962 static const char no4[] = "abc12";
963 static const char overflow[] = "99999999999999999999";
964 static const char neg_overflow[] = "-99999999999999999999";
965 static const char hex[] = "0x123";
966 static const char oct[] = "000123";
967 static const char blanks[] = " 12 212.31";
970 unsigned __int64 ures;
973 if(!p_strtoi64 || !p_strtoui64) {
974 win_skip("_strtoi64 or _strtoui64 not found\n");
979 res = p_strtoi64(no1, NULL, 10);
980 ok(res == 31923, "res != 31923\n");
981 res = p_strtoi64(no2, NULL, 10);
982 ok(res == -213312, "res != -213312\n");
983 res = p_strtoi64(no3, NULL, 10);
984 ok(res == 12, "res != 12\n");
985 res = p_strtoi64(no4, &endpos, 10);
986 ok(res == 0, "res != 0\n");
987 ok(endpos == no4, "Scanning was not stopped on first character\n");
988 res = p_strtoi64(hex, &endpos, 10);
989 ok(res == 0, "res != 0\n");
990 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
991 res = p_strtoi64(oct, &endpos, 10);
992 ok(res == 123, "res != 123\n");
993 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
994 res = p_strtoi64(blanks, &endpos, 10);
995 ok(res == 12, "res != 12\n");
996 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
997 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1000 res = p_strtoi64(overflow, &endpos, 10);
1001 ok(res == _I64_MAX, "res != _I64_MAX\n");
1002 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1003 ok(errno == ERANGE, "errno = %x\n", errno);
1006 res = p_strtoi64(neg_overflow, &endpos, 10);
1007 ok(res == _I64_MIN, "res != _I64_MIN\n");
1008 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1009 ok(errno == ERANGE, "errno = %x\n", errno);
1012 res = p_strtoi64(no1, &endpos, 16);
1013 ok(res == 203043, "res != 203043\n");
1014 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1015 res = p_strtoi64(no2, &endpos, 16);
1016 ok(res == -2175762, "res != -2175762\n");
1017 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1018 res = p_strtoi64(no3, &endpos, 16);
1019 ok(res == 4778, "res != 4778\n");
1020 ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
1021 res = p_strtoi64(no4, &endpos, 16);
1022 ok(res == 703506, "res != 703506\n");
1023 ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
1024 res = p_strtoi64(hex, &endpos, 16);
1025 ok(res == 291, "res != 291\n");
1026 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1027 res = p_strtoi64(oct, &endpos, 16);
1028 ok(res == 291, "res != 291\n");
1029 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1030 res = p_strtoi64(blanks, &endpos, 16);
1031 ok(res == 18, "res != 18\n");
1032 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1033 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1036 res = p_strtoi64(hex, &endpos, 36);
1037 ok(res == 1541019, "res != 1541019\n");
1038 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1039 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1042 res = p_strtoi64(no1, &endpos, 0);
1043 ok(res == 31923, "res != 31923\n");
1044 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1045 res = p_strtoi64(no2, &endpos, 0);
1046 ok(res == -213312, "res != -213312\n");
1047 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1048 res = p_strtoi64(no3, &endpos, 10);
1049 ok(res == 12, "res != 12\n");
1050 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1051 res = p_strtoi64(no4, &endpos, 10);
1052 ok(res == 0, "res != 0\n");
1053 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1054 res = p_strtoi64(hex, &endpos, 10);
1055 ok(res == 0, "res != 0\n");
1056 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1057 res = p_strtoi64(oct, &endpos, 10);
1058 ok(res == 123, "res != 123\n");
1059 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1060 res = p_strtoi64(blanks, &endpos, 10);
1061 ok(res == 12, "res != 12\n");
1062 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1063 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1066 ures = p_strtoui64(no1, &endpos, 0);
1067 ok(ures == 31923, "ures != 31923\n");
1068 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1069 ures = p_strtoui64(no2, &endpos, 0);
1070 ok(ures == -213312, "ures != -213312\n");
1071 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1072 ures = p_strtoui64(no3, &endpos, 10);
1073 ok(ures == 12, "ures != 12\n");
1074 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1075 ures = p_strtoui64(no4, &endpos, 10);
1076 ok(ures == 0, "ures != 0\n");
1077 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1078 ures = p_strtoui64(hex, &endpos, 10);
1079 ok(ures == 0, "ures != 0\n");
1080 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1081 ures = p_strtoui64(oct, &endpos, 10);
1082 ok(ures == 123, "ures != 123\n");
1083 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1084 ures = p_strtoui64(blanks, &endpos, 10);
1085 ok(ures == 12, "ures != 12\n");
1086 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1087 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1090 ures = p_strtoui64(overflow, &endpos, 10);
1091 ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
1092 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1093 ok(errno == ERANGE, "errno = %x\n", errno);
1096 ures = p_strtoui64(neg_overflow, &endpos, 10);
1097 ok(ures == 1, "ures != 1\n");
1098 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1099 ok(errno == ERANGE, "errno = %x\n", errno);
1102 static inline BOOL almost_equal(double d1, double d2) {
1103 if(d1-d2>-1e-30 && d1-d2<1e-30)
1108 static void test__strtod(void)
1110 const char double1[] = "12.1";
1111 const char double2[] = "-13.721";
1112 const char double3[] = "INF";
1113 const char double4[] = ".21e12";
1114 const char double5[] = "214353e-3";
1115 const char overflow[] = "1d9999999999999999999";
1116 const char white_chars[] = " d10";
1121 d = strtod(double1, &end);
1122 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1123 ok(end == double1+4, "incorrect end (%d)\n", (int)(end-double1));
1125 d = strtod(double2, &end);
1126 ok(almost_equal(d, -13.721), "d = %lf\n", d);
1127 ok(end == double2+7, "incorrect end (%d)\n", (int)(end-double2));
1129 d = strtod(double3, &end);
1130 ok(almost_equal(d, 0), "d = %lf\n", d);
1131 ok(end == double3, "incorrect end (%d)\n", (int)(end-double3));
1133 d = strtod(double4, &end);
1134 ok(almost_equal(d, 210000000000.0), "d = %lf\n", d);
1135 ok(end == double4+6, "incorrect end (%d)\n", (int)(end-double4));
1137 d = strtod(double5, &end);
1138 ok(almost_equal(d, 214.353), "d = %lf\n", d);
1139 ok(end == double5+9, "incorrect end (%d)\n", (int)(end-double5));
1141 d = strtod("12.1d2", NULL);
1142 ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
1144 d = strtod(white_chars, &end);
1145 ok(almost_equal(d, 0), "d = %lf\n", d);
1146 ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
1148 /* Set locale with non '.' decimal point (',') */
1149 if(!setlocale(LC_ALL, "Polish")) {
1150 win_skip("system with limited locales\n");
1154 d = strtod("12.1", NULL);
1155 ok(almost_equal(d, 12.0), "d = %lf\n", d);
1157 d = strtod("12,1", NULL);
1158 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1160 setlocale(LC_ALL, "C");
1162 /* Precision tests */
1163 d = strtod("0.1", NULL);
1164 ok(almost_equal(d, 0.1), "d = %lf\n", d);
1165 d = strtod("-0.1", NULL);
1166 ok(almost_equal(d, -0.1), "d = %lf\n", d);
1167 d = strtod("0.1281832188491894198128921", NULL);
1168 ok(almost_equal(d, 0.1281832188491894198128921), "d = %lf\n", d);
1169 d = strtod("0.82181281288121", NULL);
1170 ok(almost_equal(d, 0.82181281288121), "d = %lf\n", d);
1171 d = strtod("21921922352523587651128218821", NULL);
1172 ok(almost_equal(d, 21921922352523587651128218821.0), "d = %lf\n", d);
1173 d = strtod("0.1d238", NULL);
1174 ok(almost_equal(d, 0.1e238L), "d = %lf\n", d);
1175 d = strtod("0.1D-4736", NULL);
1176 ok(almost_equal(d, 0.1e-4736L), "d = %lf\n", d);
1179 d = strtod(overflow, &end);
1180 ok(errno == ERANGE, "errno = %x\n", errno);
1181 ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
1184 strtod("-1d309", NULL);
1185 ok(errno == ERANGE, "errno = %x\n", errno);
1188 static void test_mbstowcs(void)
1190 static const wchar_t wSimple[] = { 't','e','x','t',0 };
1191 static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
1192 static const char mSimple[] = "text";
1193 static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
1200 wOut[4] = '!'; wOut[5] = '\0';
1201 mOut[4] = '!'; mOut[5] = '\0';
1203 ret = mbstowcs(NULL, mSimple, 0);
1204 ok(ret == 4, "mbstowcs did not return 4\n");
1206 ret = mbstowcs(wOut, mSimple, 4);
1207 ok(ret == 4, "mbstowcs did not return 4\n");
1208 ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
1209 ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
1211 ret = wcstombs(NULL, wSimple, 0);
1212 ok(ret == 4, "wcstombs did not return 4\n");
1214 ret = wcstombs(mOut, wSimple, 6);
1215 ok(ret == 4, "wcstombs did not return 4\n");
1216 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1218 ret = wcstombs(mOut, wSimple, 2);
1219 ok(ret == 2, "wcstombs did not return 2\n");
1220 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1222 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
1223 win_skip("Japanese_Japan.932 locale not available\n");
1227 ret = mbstowcs(wOut, mHiragana, 6);
1228 ok(ret == 2, "mbstowcs did not return 2\n");
1229 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1231 ret = wcstombs(mOut, wHiragana, 6);
1232 ok(ret == 4, "wcstombs did not return 4\n");
1233 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1235 if(!pmbstowcs_s || !pwcstombs_s) {
1236 win_skip("mbstowcs_s or wcstombs_s not available\n");
1240 err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
1241 ok(err == 0, "err = %d\n", err);
1242 ok(ret == 5, "ret = %d\n", (int)ret);
1243 ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
1245 err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
1246 ok(err == 0, "err = %d\n", err);
1247 ok(ret == 3, "ret = %d\n", (int)ret);
1248 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1250 err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
1251 ok(err == 0, "err = %d\n", err);
1252 ok(ret == 5, "ret = %d\n", (int)ret);
1253 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1255 err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
1256 ok(err == 0, "err = %d\n", err);
1257 ok(ret == 5, "ret = %d\n", (int)ret);
1258 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1261 static void test_gcvt(void)
1263 char buf[1024], *res;
1267 win_skip("Skipping _gcvt tests\n");
1272 res = _gcvt(1.2, -1, buf);
1273 ok(res == NULL, "res != NULL\n");
1274 ok(errno == ERANGE, "errno = %d\n", errno);
1277 res = _gcvt(1.2, 5, NULL);
1278 ok(res == NULL, "res != NULL\n");
1279 ok(errno == EINVAL, "errno = %d\n", errno);
1281 res = gcvt(1.2, 5, buf);
1282 ok(res == buf, "res != buf\n");
1283 ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
1286 err = p_gcvt_s(buf, 5, 1.2, 10);
1287 ok(err == ERANGE, "err = %d\n", err);
1288 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1291 err = p_gcvt_s(buf, 4, 123456, 2);
1292 ok(err == ERANGE, "err = %d\n", err);
1293 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1296 static void test__itoa_s(void)
1303 win_skip("Skipping _itoa_s tests\n");
1307 if (p_set_invalid_parameter_handler)
1308 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1309 "Invalid parameter handler was already set\n");
1312 ret = p_itoa_s(0, NULL, 0, 0);
1313 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1314 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1316 memset(buffer, 'X', sizeof(buffer));
1318 ret = p_itoa_s(0, buffer, 0, 0);
1319 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1320 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1321 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1323 memset(buffer, 'X', sizeof(buffer));
1325 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
1326 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1327 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1328 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1330 memset(buffer, 'X', sizeof(buffer));
1332 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
1333 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1334 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1335 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1337 memset(buffer, 'X', sizeof(buffer));
1339 ret = p_itoa_s(12345678, buffer, 4, 10);
1340 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1341 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1342 ok(!memcmp(buffer, "\000765", 4),
1343 "Expected the output buffer to be null terminated with truncated output\n");
1345 memset(buffer, 'X', sizeof(buffer));
1347 ret = p_itoa_s(12345678, buffer, 8, 10);
1348 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1349 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1350 ok(!memcmp(buffer, "\0007654321", 8),
1351 "Expected the output buffer to be null terminated with truncated output\n");
1353 memset(buffer, 'X', sizeof(buffer));
1355 ret = p_itoa_s(-12345678, buffer, 9, 10);
1356 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1357 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1358 ok(!memcmp(buffer, "\00087654321", 9),
1359 "Expected the output buffer to be null terminated with truncated output\n");
1361 ret = p_itoa_s(12345678, buffer, 9, 10);
1362 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1363 ok(!strcmp(buffer, "12345678"),
1364 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1367 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
1368 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1369 ok(!strcmp(buffer, "1010101010101010"),
1370 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1373 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
1374 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1375 ok(!strcmp(buffer, "nell"),
1376 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1379 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
1380 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1381 ok(!strcmp(buffer, "hag"),
1382 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1385 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
1386 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1387 ok(!strcmp(buffer, "-12345678"),
1388 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1390 if (p_set_invalid_parameter_handler)
1391 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1392 "Cannot reset invalid parameter handler\n");
1395 static void test__strlwr_s(void)
1402 win_skip("Skipping _strlwr_s tests\n");
1407 ret = p_strlwr_s(NULL, 0);
1408 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1409 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1412 ret = p_strlwr_s(NULL, sizeof(buffer));
1413 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1414 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1417 ret = p_strlwr_s(buffer, 0);
1418 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1419 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1421 strcpy(buffer, "GoRrIsTeR");
1423 ret = p_strlwr_s(buffer, 5);
1424 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1425 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1426 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1427 "Expected the output buffer to be \"gorrIsTeR\"\n");
1429 strcpy(buffer, "GoRrIsTeR");
1431 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
1432 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1433 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1434 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1435 "Expected the output buffer to be \"gorrIsTeR\"\n");
1437 strcpy(buffer, "GoRrIsTeR");
1438 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
1439 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1440 ok(!strcmp(buffer, "gorrister"),
1441 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1444 memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1445 ret = p_strlwr_s(buffer, sizeof(buffer));
1446 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1447 ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1448 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1452 static void test_wcsncat_s(void)
1454 static wchar_t abcW[] = {'a','b','c',0};
1461 win_skip("skipping wcsncat_s tests\n");
1465 if (p_set_invalid_parameter_handler)
1466 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1467 "Invalid parameter handler was already set\n");
1469 memcpy(src, abcW, sizeof(abcW));
1471 ret = p_wcsncat_s(NULL, 4, src, 4);
1472 ok(ret == EINVAL, "err = %d\n", ret);
1473 ret = p_wcsncat_s(dst, 0, src, 4);
1474 ok(ret == EINVAL, "err = %d\n", ret);
1475 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
1476 ok(ret == EINVAL, "err = %d\n", ret);
1477 ret = p_wcsncat_s(dst, 4, NULL, 0);
1478 ok(ret == 0, "err = %d\n", ret);
1481 ret = p_wcsncat_s(dst, 2, src, 4);
1482 ok(ret == ERANGE, "err = %d\n", ret);
1485 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
1486 ok(ret == STRUNCATE, "err = %d\n", ret);
1487 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
1489 memcpy(dst, abcW, sizeof(abcW));
1491 ret = p_wcsncat_s(dst, 4, src, 4);
1492 ok(ret == EINVAL, "err = %d\n", ret);
1494 if (p_set_invalid_parameter_handler)
1495 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1496 "Cannot reset invalid parameter handler\n");
1499 static void test__mbsnbcat_s(void)
1501 unsigned char dest[16];
1502 const unsigned char first[] = "dinosaur";
1503 const unsigned char second[] = "duck";
1508 win_skip("Skipping _mbsnbcat_s tests\n");
1512 /* Test invalid arguments. */
1513 ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
1514 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1517 ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
1518 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1519 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1522 ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
1523 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1524 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1526 memset(dest, 'X', sizeof(dest));
1528 ret = p_mbsnbcat_s(dest, 0, NULL, 0);
1529 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1530 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1531 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1533 memset(dest, 'X', sizeof(dest));
1535 ret = p_mbsnbcat_s(dest, 0, second, 0);
1536 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1537 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1538 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1540 memset(dest, 'X', sizeof(dest));
1542 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
1543 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1544 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1545 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1547 memset(dest, 'X', sizeof(dest));
1549 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
1550 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1551 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1552 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1554 memset(dest, 'X', sizeof(dest));
1556 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1557 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1558 ok(!memcmp(dest, second, sizeof(second)),
1559 "Expected the output buffer string to be \"duck\"\n");
1561 /* Test source truncation behavior. */
1562 memset(dest, 'X', sizeof(dest));
1563 memcpy(dest, first, sizeof(first));
1564 ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
1565 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1566 ok(!memcmp(dest, first, sizeof(first)),
1567 "Expected the output buffer string to be \"dinosaur\"\n");
1569 memset(dest, 'X', sizeof(dest));
1570 memcpy(dest, first, sizeof(first));
1571 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1572 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1573 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1574 "Expected the output buffer string to be \"dinosaurduck\"\n");
1576 memset(dest, 'X', sizeof(dest));
1577 memcpy(dest, first, sizeof(first));
1578 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
1579 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1580 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1581 "Expected the output buffer string to be \"dinosaurduck\"\n");
1583 memset(dest, 'X', sizeof(dest));
1584 memcpy(dest, first, sizeof(first));
1585 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
1586 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1587 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1588 "Expected the output buffer string to be \"dinosaurduck\"\n");
1590 memset(dest, 'X', sizeof(dest));
1591 memcpy(dest, first, sizeof(first));
1592 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
1593 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1594 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
1595 "Expected the output buffer string to be \"dinosaurduc\"\n");
1597 /* Test destination truncation behavior. */
1598 memset(dest, 'X', sizeof(dest));
1599 memcpy(dest, first, sizeof(first));
1601 ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
1602 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1603 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1604 ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
1605 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
1607 memset(dest, 'X', sizeof(dest));
1608 memcpy(dest, first, sizeof(first));
1610 ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
1611 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1612 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1613 ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
1614 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
1616 memset(dest, 'X', sizeof(dest));
1617 memcpy(dest, first, sizeof(first));
1619 ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
1620 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1621 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1622 ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
1623 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
1626 static void test__ultoa_s(void)
1633 win_skip("Skipping _ultoa_s tests\n");
1638 ret = p_ultoa_s(0, NULL, 0, 0);
1639 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1640 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1642 memset(buffer, 'X', sizeof(buffer));
1644 ret = p_ultoa_s(0, buffer, 0, 0);
1645 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1646 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1647 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1649 memset(buffer, 'X', sizeof(buffer));
1651 ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
1652 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1653 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1654 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1656 memset(buffer, 'X', sizeof(buffer));
1658 ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
1659 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1660 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1661 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1663 memset(buffer, 'X', sizeof(buffer));
1665 ret = p_ultoa_s(12345678, buffer, 4, 10);
1666 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
1667 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1668 ok(!memcmp(buffer, "\000765", 4),
1669 "Expected the output buffer to be null terminated with truncated output\n");
1671 memset(buffer, 'X', sizeof(buffer));
1673 ret = p_ultoa_s(12345678, buffer, 8, 10);
1674 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
1675 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1676 ok(!memcmp(buffer, "\0007654321", 8),
1677 "Expected the output buffer to be null terminated with truncated output\n");
1679 ret = p_ultoa_s(12345678, buffer, 9, 10);
1680 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1681 ok(!strcmp(buffer, "12345678"),
1682 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1685 ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
1686 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1687 ok(!strcmp(buffer, "1010101010101010"),
1688 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1691 ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
1692 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1693 ok(!strcmp(buffer, "nell"),
1694 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1697 ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
1698 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1699 ok(!strcmp(buffer, "hag"),
1700 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1707 static const char xilstring[]="c:/xilinx";
1710 hMsvcrt = GetModuleHandleA("msvcrt.dll");
1712 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
1713 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
1714 SET(pmemcpy,"memcpy");
1715 SET(pmemcmp,"memcmp");
1716 SET(p_mbctype,"_mbctype");
1717 SET(p__mb_cur_max,"__mb_cur_max");
1718 pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
1719 pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
1720 p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
1721 p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
1722 p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
1723 p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
1724 p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
1725 p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
1726 p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
1727 p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
1728 pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
1729 pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
1730 p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
1731 p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
1732 p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
1733 p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
1734 p_set_invalid_parameter_handler = (void *) GetProcAddress(hMsvcrt, "_set_invalid_parameter_handler");
1736 /* MSVCRT memcpy behaves like memmove for overlapping moves,
1737 MFC42 CString::Insert seems to rely on that behaviour */
1738 strcpy(mem,xilstring);
1739 nLen=strlen(xilstring);
1740 pmemcpy(mem+5, mem,nLen+1);
1741 ok(pmemcmp(mem+5,xilstring, nLen) == 0,
1742 "Got result %s\n",mem+5);
1744 /* Test _swab function */