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 size_t (__cdecl *pwcsrtombs)(char*, const wchar_t**, size_t, int*);
72 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
73 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
74 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
75 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
76 static int *p__mb_cur_max;
77 static unsigned char *p_mbctype;
78 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
79 static int (__cdecl *p_wcslwr_s)(wchar_t*,size_t);
80 static errno_t (__cdecl *p_mbsupr_s)(unsigned char *str, size_t numberOfElements);
81 static errno_t (__cdecl *p_mbslwr_s)(unsigned char *str, size_t numberOfElements);
82 static int (__cdecl *p_wctob)(wint_t);
84 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
85 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
87 static HMODULE hMsvcrt;
89 static void test_swab( void ) {
90 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
91 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
92 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
93 char expected3[] = "$";
100 /* Test 1 - normal even case */
101 memset(to,'$', sizeof(to));
102 memset(from,'@', sizeof(from));
104 memcpy(from, original, testsize);
105 _swab( from, to, testsize );
106 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
108 /* Test 2 - uneven case */
109 memset(to,'$', sizeof(to));
110 memset(from,'@', sizeof(from));
112 memcpy(from, original, testsize);
113 _swab( from, to, testsize );
114 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
116 /* Test 3 - from = to */
117 memset(to,'$', sizeof(to));
118 memset(from,'@', sizeof(from));
120 memcpy(to, original, testsize);
121 _swab( to, to, testsize );
122 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
124 /* Test 4 - 1 bytes */
125 memset(to,'$', sizeof(to));
126 memset(from,'@', sizeof(from));
128 memcpy(from, original, testsize);
129 _swab( from, to, testsize );
130 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
133 #if 0 /* use this to generate more tests */
135 static void test_codepage(int cp)
141 ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
144 printf("static int result_cp_%d_mbctype[] = { ", cp);
145 for (i = 1; i < 257; i++)
147 if (p_mbctype[i] != prev)
149 printf("0x%x,%d, ", prev, count);
156 printf("0x%x,%d };\n", prev, count);
161 /* RLE-encoded mbctype tables for given codepages */
162 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
163 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
164 static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
166 static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
168 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
169 0x0,2, 0x4,32, 0xc,94, 0,1 };
171 static void test_cp_table(int cp, int *result)
177 for (i = 0; i < 256; i++)
185 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);
190 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
194 static void test_mbcp(void)
196 int mb_orig_max = *p__mb_cur_max;
197 int curr_mbcp = _getmbcp();
198 unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
199 unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
200 unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
201 unsigned char buf[16];
207 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
208 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
209 * CP1252 (or the ACP?) so we test only a few ASCII characters */
211 expect_eq(p_mbctype[10], 0, char, "%x");
212 expect_eq(p_mbctype[50], 0, char, "%x");
213 expect_eq(p_mbctype[66], _SBUP, char, "%x");
214 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
215 expect_eq(p_mbctype[128], 0, char, "%x");
217 expect_eq(p_mbctype[10], 0, char, "%x");
218 expect_eq(p_mbctype[50], 0, char, "%x");
219 expect_eq(p_mbctype[66], _SBUP, char, "%x");
220 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
221 expect_eq(p_mbctype[128], 0, char, "%x");
223 /* double byte code pages */
230 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);
231 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
232 ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
233 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
234 ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
235 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
236 ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
239 expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
240 expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
241 expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
242 expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
243 expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
244 expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
245 expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
246 expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
247 expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
249 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
250 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
251 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
252 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
255 expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
256 expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
257 expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
258 expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
259 expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
260 expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
261 expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
262 expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
263 expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
265 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
266 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
267 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
268 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
269 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
270 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
273 expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
274 expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
275 expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
276 expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
277 expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
278 expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
279 expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
280 expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
281 expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
283 expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
284 expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
285 expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
286 expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
287 expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
288 expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
291 expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
292 expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
293 expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
295 /* _mbclen/_mbslen */
296 expect_eq(_mbclen(mbstring), 2, int, "%d");
297 expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
298 expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
299 expect_eq(_mbslen(mbstring2), 4, int, "%d");
300 expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
301 expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
303 /* _mbccpy/_mbsncpy */
304 memset(buf, 0xff, sizeof(buf));
305 _mbccpy(buf, mbstring);
306 expect_bin(buf, "\xb0\xb1\xff", 3);
308 memset(buf, 0xff, sizeof(buf));
309 _mbsncpy(buf, mbstring, 1);
310 expect_bin(buf, "\xb0\xb1\xff", 3);
311 memset(buf, 0xff, sizeof(buf));
312 _mbsncpy(buf, mbstring, 2);
313 expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
314 memset(buf, 0xff, sizeof(buf));
315 _mbsncpy(buf, mbstring, 3);
316 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
317 memset(buf, 0xff, sizeof(buf));
318 _mbsncpy(buf, mbstring, 4);
319 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
320 memset(buf, 0xff, sizeof(buf));
321 _mbsncpy(buf, mbstring, 5);
322 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
323 memset(buf, 0xff, sizeof(buf));
324 _mbsncpy(buf, mbsonlylead, 6);
325 expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
327 memset(buf, 0xff, sizeof(buf));
328 _mbsnbcpy(buf, mbstring2, 2);
329 expect_bin(buf, "\xb0\xb1\xff", 3);
330 _mbsnbcpy(buf, mbstring2, 3);
331 expect_bin(buf, "\xb0\xb1\0\xff", 4);
332 _mbsnbcpy(buf, mbstring2, 4);
333 expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
334 memset(buf, 0xff, sizeof(buf));
335 _mbsnbcpy(buf, mbsonlylead, 5);
336 expect_bin(buf, "\0\0\0\0\0\xff", 6);
339 step = _mbsinc(mbstring) - mbstring;
340 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
341 step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
342 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
344 step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
345 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
346 step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
347 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
348 step = _mbsninc(mbstring2, 0) - mbstring2;
349 ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
350 step = _mbsninc(mbstring2, 1) - mbstring2;
351 ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
352 step = _mbsninc(mbstring2, 2) - mbstring2;
353 ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
354 step = _mbsninc(mbstring2, 3) - mbstring2;
355 ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
356 step = _mbsninc(mbstring2, 4) - mbstring2;
357 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
358 step = _mbsninc(mbstring2, 5) - mbstring2;
359 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
360 step = _mbsninc(mbstring2, 17) - mbstring2;
361 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
363 /* functions that depend on locale codepage, not mbcp.
364 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
365 * (as of Wine 0.9.43)
367 GetCPInfo(GetACP(), &cp_info);
368 if (cp_info.MaxCharSize == 1)
370 expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
371 expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
374 skip("Current locale has double-byte charset - could lead to false positives\n");
377 expect_eq(_ismbblead(0x80), 0, int, "%d");
379 expect_eq(_ismbblead(0x81), 1, int, "%d");
380 expect_eq(_ismbblead(0x83), 1, int, "%d");
382 expect_eq(_ismbblead(0x84), 1, int, "%d");
383 expect_eq(_ismbblead(0xd3), 1, int, "%d");
384 expect_eq(_ismbblead(0xd7), 0, int, "%d");
386 expect_eq(_ismbblead(0xd8), 1, int, "%d");
388 expect_eq(_ismbblead(0xd9), 1, int, "%d");
390 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
391 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
392 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
393 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
394 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
395 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
396 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
397 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
402 static void test_mbsspn( void)
404 unsigned char str1[]="cabernet";
405 unsigned char str2[]="shiraz";
406 unsigned char set[]="abc";
407 unsigned char empty[]="";
409 ret=_mbsspn( str1, set);
410 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
411 ret=_mbsspn( str2, set);
412 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
413 ret=_mbsspn( str1, empty);
414 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
417 static void test_mbsspnp( void)
419 unsigned char str1[]="cabernet";
420 unsigned char str2[]="shiraz";
421 unsigned char set[]="abc";
422 unsigned char empty[]="";
423 unsigned char full[]="abcenrt";
425 ret=_mbsspnp( str1, set);
426 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
427 ret=_mbsspnp( str2, set);
428 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
429 ret=_mbsspnp( str1, empty);
430 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
431 ret=_mbsspnp( str1, full);
432 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
435 static void test_strdup(void)
439 ok( str == 0, "strdup returns %s should be 0\n", str);
443 static void test_strcpy_s(void)
446 const char *small = "small";
447 const char *big = "atoolongstringforthislittledestination";
452 skip("strcpy_s not found\n");
456 memset(dest, 'X', sizeof(dest));
457 ret = pstrcpy_s(dest, sizeof(dest), small);
458 ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
459 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
460 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
461 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
462 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
464 memset(dest, 'X', sizeof(dest));
465 ret = pstrcpy_s(dest, 0, big);
466 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
467 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
468 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
469 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
470 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
471 ret = pstrcpy_s(dest, 0, NULL);
472 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
473 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
474 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
475 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
476 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
478 memset(dest, 'X', sizeof(dest));
479 ret = pstrcpy_s(dest, sizeof(dest), big);
480 ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
481 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
482 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
483 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
484 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
486 memset(dest, 'X', sizeof(dest));
487 ret = pstrcpy_s(dest, sizeof(dest), NULL);
488 ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
489 ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
490 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
491 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
492 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
494 ret = pstrcpy_s(NULL, sizeof(dest), small);
495 ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
498 static void test_strcat_s(void)
501 const char *small = "sma";
506 skip("strcat_s not found\n");
510 memset(dest, 'X', sizeof(dest));
512 ret = pstrcat_s(dest, sizeof(dest), small);
513 ok(ret == 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
514 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == '\0'&&
515 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
516 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
517 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
518 ret = pstrcat_s(dest, sizeof(dest), small);
519 ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
520 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
521 dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
522 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
523 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
525 ret = pstrcat_s(dest, sizeof(dest), small);
526 ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
527 ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
528 dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
529 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
530 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
532 memset(dest, 'X', sizeof(dest));
536 ret = pstrcat_s(dest, 0, small);
537 ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
538 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
539 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
540 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
541 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
543 ret = pstrcat_s(dest, 0, NULL);
544 ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
545 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
546 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
547 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
548 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
550 ret = pstrcat_s(dest, sizeof(dest), NULL);
551 ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
552 ok(dest[0] == '\0'&& dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
553 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
554 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
555 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
557 ret = pstrcat_s(NULL, sizeof(dest), small);
558 ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
561 static void test__mbsnbcpy_s(void)
563 unsigned char dest[8];
564 const unsigned char big[] = "atoolongstringforthislittledestination";
565 const unsigned char small[] = "small";
570 skip("_mbsnbcpy_s not found\n");
574 memset(dest, 'X', sizeof(dest));
575 ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
576 ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
577 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
578 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
579 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
580 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
583 memset(dest, 'X', sizeof(dest));
584 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
585 ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
586 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
587 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
588 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
589 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
591 memset(dest, 'X', sizeof(dest));
592 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
593 ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
594 ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
595 dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
596 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
597 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
599 memset(dest, 'X', sizeof(dest));
600 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
601 ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
602 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
603 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
604 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
605 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
608 static void test_wcscpy_s(void)
610 static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
611 static WCHAR szDest[18];
612 static WCHAR szDestShort[8];
617 skip("wcscpy_s not found\n");
622 ret = p_wcscpy_s(NULL, 18, szLongText);
623 ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
625 /* Test NULL Source */
627 ret = p_wcscpy_s(szDest, 18, NULL);
628 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
629 ok(szDest[0] == 0, "szDest[0] not 0\n");
631 /* Test invalid size */
633 ret = p_wcscpy_s(szDest, 0, szLongText);
634 /* Later versions changed the return value for this case to EINVAL,
635 * and don't modify the result if the dest size is 0.
637 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
638 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
640 /* Copy same buffer size */
641 ret = p_wcscpy_s(szDest, 18, szLongText);
642 ok(ret == 0, "expected 0 got %d\n", ret);
643 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
645 /* Copy smaller buffer size */
647 ret = p_wcscpy_s(szDestShort, 8, szLongText);
648 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
649 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
652 static void test__wcsupr_s(void)
654 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
655 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
656 static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
657 'W', 'E', 'R', 'U', 'P', 'P', 'E',
659 WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
664 win_skip("_wcsupr_s not found\n");
668 /* Test NULL input string and invalid size. */
670 ret = p_wcsupr_s(NULL, 0);
671 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
672 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
674 /* Test NULL input string and valid size. */
676 ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
677 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
678 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
680 /* Test empty string with zero size. */
682 testBuffer[0] = '\0';
683 ret = p_wcsupr_s(testBuffer, 0);
684 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
685 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
686 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
688 /* Test empty string with size of one. */
689 testBuffer[0] = '\0';
690 ret = p_wcsupr_s(testBuffer, 1);
691 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
692 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
694 /* Test one-byte buffer with zero size. */
697 ret = p_wcsupr_s(testBuffer, 0);
698 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
699 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
700 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
702 /* Test one-byte buffer with size of one. */
705 ret = p_wcsupr_s(testBuffer, 1);
706 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
707 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
708 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
710 /* Test invalid size. */
711 wcscpy(testBuffer, mixedString);
713 ret = p_wcsupr_s(testBuffer, 0);
714 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
715 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
716 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
718 /* Test normal string uppercasing. */
719 wcscpy(testBuffer, mixedString);
720 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
721 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
722 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
724 /* Test uppercasing with a shorter buffer size count. */
725 wcscpy(testBuffer, mixedString);
727 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
728 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
729 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
730 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
732 /* Test uppercasing with a longer buffer size count. */
733 wcscpy(testBuffer, mixedString);
734 ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
735 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
736 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
739 static void test__wcslwr_s(void)
741 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
742 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
743 static const WCHAR expectedString[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
744 'w', 'e', 'r', 'u', 'p', 'p', 'e',
746 WCHAR buffer[2*sizeof(mixedString)/sizeof(WCHAR)];
751 win_skip("_wcslwr_s not found\n");
755 /* Test NULL input string and invalid size. */
757 ret = p_wcslwr_s(NULL, 0);
758 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
759 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
761 /* Test NULL input string and valid size. */
763 ret = p_wcslwr_s(NULL, sizeof(buffer)/sizeof(wchar_t));
764 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
765 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
767 /* Test empty string with zero size. */
770 ret = p_wcslwr_s(buffer, 0);
771 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
772 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
773 ok(buffer[0] == 0, "expected empty string\n");
775 /* Test empty string with size of one. */
777 ret = p_wcslwr_s(buffer, 1);
778 ok(ret == 0, "got %d\n", ret);
779 ok(buffer[0] == 0, "expected buffer to be unchanged\n");
781 /* Test one-byte buffer with zero size. */
784 ret = p_wcslwr_s(buffer, 0);
785 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
786 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
787 ok(buffer[0] == '\0', "expected empty string\n");
789 /* Test one-byte buffer with size of one. */
792 ret = p_wcslwr_s(buffer, 1);
793 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
794 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
795 ok(buffer[0] == '\0', "expected empty string\n");
797 /* Test invalid size. */
798 wcscpy(buffer, mixedString);
800 ret = p_wcslwr_s(buffer, 0);
801 ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
802 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
803 ok(buffer[0] == '\0', "expected empty string\n");
805 /* Test normal string uppercasing. */
806 wcscpy(buffer, mixedString);
807 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR));
808 ok(ret == 0, "expected 0, got %d\n", ret);
809 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
811 /* Test uppercasing with a shorter buffer size count. */
812 wcscpy(buffer, mixedString);
814 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
815 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
816 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
817 ok(buffer[0] == '\0', "expected empty string\n");
819 /* Test uppercasing with a longer buffer size count. */
820 wcscpy(buffer, mixedString);
821 ret = p_wcslwr_s(buffer, sizeof(buffer)/sizeof(WCHAR));
822 ok(ret == 0, "expected 0, got %d\n", ret);
823 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
826 static void test_mbcjisjms(void)
828 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
829 unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
830 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
831 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
832 unsigned int ret, exp, i;
837 ret = _mbcjistojms(jisjms[i][0]);
839 if(_getmbcp() == 932) /* Japanese codepage? */
842 exp = jisjms[i][0]; /* If not, no conversion */
844 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
845 } while(jisjms[i++][0] != 0);
848 static void test_mbctombb(void)
850 static const unsigned int mbcmbb_932[][2] = {
851 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
852 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
853 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
854 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
855 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
856 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
857 unsigned int exp, ret, i;
858 unsigned int prev_cp = _getmbcp();
861 for (i = 0; mbcmbb_932[i][0] != 0; i++)
863 ret = _mbctombb(mbcmbb_932[i][0]);
864 exp = mbcmbb_932[i][1];
865 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
870 static void test_ismbclegal(void) {
871 unsigned int prev_cp = _getmbcp();
875 _setmbcp(932); /* Japanese */
877 for(i = 0; i < 0x10000; i++) {
878 ret = _ismbclegal(i);
879 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
880 (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
881 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
882 (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
888 ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
889 _setmbcp(936); /* Chinese (GBK) */
891 for(i = 0; i < 0x10000; i++) {
892 ret = _ismbclegal(i);
893 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
894 LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
900 ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
901 _setmbcp(949); /* Korean */
903 for(i = 0; i < 0x10000; i++) {
904 ret = _ismbclegal(i);
905 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
906 LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
912 ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
913 _setmbcp(950); /* Chinese (Big5) */
915 for(i = 0; i < 0x10000; i++) {
916 ret = _ismbclegal(i);
917 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
918 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
919 (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
925 ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
926 _setmbcp(1361); /* Korean (Johab) */
928 for(i = 0; i < 0x10000; i++) {
929 ret = _ismbclegal(i);
930 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
931 (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
932 ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
933 (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
940 todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
945 static const struct {
947 const char* delimiter;
948 int exp_offsetret1; /* returned offset from string after first call to strtok()
950 int exp_offsetret2; /* returned offset from string after second call to strtok()
952 int exp_offsetret3; /* returned offset from string after third call to strtok()
954 } testcases_strtok[] = {
955 { "red cabernet", " ", 0, 4, -1 },
956 { "sparkling white riesling", " ", 0, 10, 16 },
957 { " pale cream sherry", "e ", 1, 6, 9 },
962 static void test_strtok(void)
967 for( i = 0; testcases_strtok[i].string; i++){
968 strcpy( teststr, testcases_strtok[i].string);
969 strret = strtok( teststr, testcases_strtok[i].delimiter);
970 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
971 (!strret && testcases_strtok[i].exp_offsetret1 == -1),
972 "string (%p) \'%s\' return %p\n",
973 teststr, testcases_strtok[i].string, strret);
974 if( !strret) continue;
975 strret = strtok( NULL, testcases_strtok[i].delimiter);
976 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
977 (!strret && testcases_strtok[i].exp_offsetret2 == -1),
978 "second call string (%p) \'%s\' return %p\n",
979 teststr, testcases_strtok[i].string, strret);
980 if( !strret) continue;
981 strret = strtok( NULL, testcases_strtok[i].delimiter);
982 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
983 (!strret && testcases_strtok[i].exp_offsetret3 == -1),
984 "third call string (%p) \'%s\' return %p\n",
985 teststr, testcases_strtok[i].string, strret);
989 static void test_strtol(void)
995 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
996 /* errno is modified on W2K8+ */
998 l = strtol("-1234", &e, 0);
999 ok(l==-1234, "wrong value %d\n", l);
1000 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1002 ul = strtoul("1234", &e, 0);
1003 ok(ul==1234, "wrong value %u\n", ul);
1004 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1007 l = strtol("2147483647L", &e, 0);
1008 ok(l==2147483647, "wrong value %d\n", l);
1009 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1011 l = strtol("-2147483648L", &e, 0);
1012 ok(l==-2147483647L - 1, "wrong value %d\n", l);
1013 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1015 ul = strtoul("4294967295UL", &e, 0);
1016 ok(ul==4294967295ul, "wrong value %u\n", ul);
1017 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1020 l = strtol("9223372036854775807L", &e, 0);
1021 ok(l==2147483647, "wrong value %d\n", l);
1022 ok(errno == ERANGE, "wrong errno %d\n", errno);
1024 ul = strtoul("9223372036854775807L", &e, 0);
1025 ok(ul==4294967295ul, "wrong value %u\n", ul);
1026 ok(errno == ERANGE, "wrong errno %d\n", errno);
1029 static void test_strnlen(void)
1031 static const char str[] = "string";
1035 win_skip("strnlen not found\n");
1039 res = p_strnlen(str, 20);
1040 ok(res == 6, "Returned length = %d\n", (int)res);
1042 res = p_strnlen(str, 3);
1043 ok(res == 3, "Returned length = %d\n", (int)res);
1045 res = p_strnlen(NULL, 0);
1046 ok(res == 0, "Returned length = %d\n", (int)res);
1049 static void test__strtoi64(void)
1051 static const char no1[] = "31923";
1052 static const char no2[] = "-213312";
1053 static const char no3[] = "12aa";
1054 static const char no4[] = "abc12";
1055 static const char overflow[] = "99999999999999999999";
1056 static const char neg_overflow[] = "-99999999999999999999";
1057 static const char hex[] = "0x123";
1058 static const char oct[] = "000123";
1059 static const char blanks[] = " 12 212.31";
1062 unsigned __int64 ures;
1065 if(!p_strtoi64 || !p_strtoui64) {
1066 win_skip("_strtoi64 or _strtoui64 not found\n");
1071 res = p_strtoi64(no1, NULL, 10);
1072 ok(res == 31923, "res != 31923\n");
1073 res = p_strtoi64(no2, NULL, 10);
1074 ok(res == -213312, "res != -213312\n");
1075 res = p_strtoi64(no3, NULL, 10);
1076 ok(res == 12, "res != 12\n");
1077 res = p_strtoi64(no4, &endpos, 10);
1078 ok(res == 0, "res != 0\n");
1079 ok(endpos == no4, "Scanning was not stopped on first character\n");
1080 res = p_strtoi64(hex, &endpos, 10);
1081 ok(res == 0, "res != 0\n");
1082 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1083 res = p_strtoi64(oct, &endpos, 10);
1084 ok(res == 123, "res != 123\n");
1085 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1086 res = p_strtoi64(blanks, &endpos, 10);
1087 ok(res == 12, "res != 12\n");
1088 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1089 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1092 res = p_strtoi64(overflow, &endpos, 10);
1093 ok(res == _I64_MAX, "res != _I64_MAX\n");
1094 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1095 ok(errno == ERANGE, "errno = %x\n", errno);
1098 res = p_strtoi64(neg_overflow, &endpos, 10);
1099 ok(res == _I64_MIN, "res != _I64_MIN\n");
1100 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1101 ok(errno == ERANGE, "errno = %x\n", errno);
1104 res = p_strtoi64(no1, &endpos, 16);
1105 ok(res == 203043, "res != 203043\n");
1106 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1107 res = p_strtoi64(no2, &endpos, 16);
1108 ok(res == -2175762, "res != -2175762\n");
1109 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1110 res = p_strtoi64(no3, &endpos, 16);
1111 ok(res == 4778, "res != 4778\n");
1112 ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
1113 res = p_strtoi64(no4, &endpos, 16);
1114 ok(res == 703506, "res != 703506\n");
1115 ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
1116 res = p_strtoi64(hex, &endpos, 16);
1117 ok(res == 291, "res != 291\n");
1118 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1119 res = p_strtoi64(oct, &endpos, 16);
1120 ok(res == 291, "res != 291\n");
1121 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1122 res = p_strtoi64(blanks, &endpos, 16);
1123 ok(res == 18, "res != 18\n");
1124 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1125 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1128 res = p_strtoi64(hex, &endpos, 36);
1129 ok(res == 1541019, "res != 1541019\n");
1130 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1131 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1134 res = p_strtoi64(no1, &endpos, 0);
1135 ok(res == 31923, "res != 31923\n");
1136 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1137 res = p_strtoi64(no2, &endpos, 0);
1138 ok(res == -213312, "res != -213312\n");
1139 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1140 res = p_strtoi64(no3, &endpos, 10);
1141 ok(res == 12, "res != 12\n");
1142 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1143 res = p_strtoi64(no4, &endpos, 10);
1144 ok(res == 0, "res != 0\n");
1145 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1146 res = p_strtoi64(hex, &endpos, 10);
1147 ok(res == 0, "res != 0\n");
1148 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1149 res = p_strtoi64(oct, &endpos, 10);
1150 ok(res == 123, "res != 123\n");
1151 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1152 res = p_strtoi64(blanks, &endpos, 10);
1153 ok(res == 12, "res != 12\n");
1154 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1155 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1158 ures = p_strtoui64(no1, &endpos, 0);
1159 ok(ures == 31923, "ures != 31923\n");
1160 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1161 ures = p_strtoui64(no2, &endpos, 0);
1162 ok(ures == -213312, "ures != -213312\n");
1163 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1164 ures = p_strtoui64(no3, &endpos, 10);
1165 ok(ures == 12, "ures != 12\n");
1166 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1167 ures = p_strtoui64(no4, &endpos, 10);
1168 ok(ures == 0, "ures != 0\n");
1169 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1170 ures = p_strtoui64(hex, &endpos, 10);
1171 ok(ures == 0, "ures != 0\n");
1172 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1173 ures = p_strtoui64(oct, &endpos, 10);
1174 ok(ures == 123, "ures != 123\n");
1175 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1176 ures = p_strtoui64(blanks, &endpos, 10);
1177 ok(ures == 12, "ures != 12\n");
1178 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1179 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1182 ures = p_strtoui64(overflow, &endpos, 10);
1183 ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
1184 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1185 ok(errno == ERANGE, "errno = %x\n", errno);
1188 ures = p_strtoui64(neg_overflow, &endpos, 10);
1189 ok(ures == 1, "ures != 1\n");
1190 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1191 ok(errno == ERANGE, "errno = %x\n", errno);
1194 static inline BOOL almost_equal(double d1, double d2) {
1195 if(d1-d2>-1e-30 && d1-d2<1e-30)
1200 static void test__strtod(void)
1202 const char double1[] = "12.1";
1203 const char double2[] = "-13.721";
1204 const char double3[] = "INF";
1205 const char double4[] = ".21e12";
1206 const char double5[] = "214353e-3";
1207 const char overflow[] = "1d9999999999999999999";
1208 const char white_chars[] = " d10";
1213 d = strtod(double1, &end);
1214 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1215 ok(end == double1+4, "incorrect end (%d)\n", (int)(end-double1));
1217 d = strtod(double2, &end);
1218 ok(almost_equal(d, -13.721), "d = %lf\n", d);
1219 ok(end == double2+7, "incorrect end (%d)\n", (int)(end-double2));
1221 d = strtod(double3, &end);
1222 ok(almost_equal(d, 0), "d = %lf\n", d);
1223 ok(end == double3, "incorrect end (%d)\n", (int)(end-double3));
1225 d = strtod(double4, &end);
1226 ok(almost_equal(d, 210000000000.0), "d = %lf\n", d);
1227 ok(end == double4+6, "incorrect end (%d)\n", (int)(end-double4));
1229 d = strtod(double5, &end);
1230 ok(almost_equal(d, 214.353), "d = %lf\n", d);
1231 ok(end == double5+9, "incorrect end (%d)\n", (int)(end-double5));
1233 d = strtod("12.1d2", NULL);
1234 ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
1236 d = strtod(white_chars, &end);
1237 ok(almost_equal(d, 0), "d = %lf\n", d);
1238 ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
1240 /* Set locale with non '.' decimal point (',') */
1241 if(!setlocale(LC_ALL, "Polish")) {
1242 win_skip("system with limited locales\n");
1246 d = strtod("12.1", NULL);
1247 ok(almost_equal(d, 12.0), "d = %lf\n", d);
1249 d = strtod("12,1", NULL);
1250 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1252 setlocale(LC_ALL, "C");
1254 /* Precision tests */
1255 d = strtod("0.1", NULL);
1256 ok(almost_equal(d, 0.1), "d = %lf\n", d);
1257 d = strtod("-0.1", NULL);
1258 ok(almost_equal(d, -0.1), "d = %lf\n", d);
1259 d = strtod("0.1281832188491894198128921", NULL);
1260 ok(almost_equal(d, 0.1281832188491894198128921), "d = %lf\n", d);
1261 d = strtod("0.82181281288121", NULL);
1262 ok(almost_equal(d, 0.82181281288121), "d = %lf\n", d);
1263 d = strtod("21921922352523587651128218821", NULL);
1264 ok(almost_equal(d, 21921922352523587651128218821.0), "d = %lf\n", d);
1265 d = strtod("0.1d238", NULL);
1266 ok(almost_equal(d, 0.1e238L), "d = %lf\n", d);
1267 d = strtod("0.1D-4736", NULL);
1268 ok(almost_equal(d, 0.1e-4736L), "d = %lf\n", d);
1271 strtod(overflow, &end);
1272 ok(errno == ERANGE, "errno = %x\n", errno);
1273 ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
1276 strtod("-1d309", NULL);
1277 ok(errno == ERANGE, "errno = %x\n", errno);
1280 static void test_mbstowcs(void)
1282 static const wchar_t wSimple[] = { 't','e','x','t',0 };
1283 static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
1284 static const char mSimple[] = "text";
1285 static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
1287 const wchar_t *pwstr;
1293 wOut[4] = '!'; wOut[5] = '\0';
1294 mOut[4] = '!'; mOut[5] = '\0';
1296 ret = mbstowcs(NULL, mSimple, 0);
1297 ok(ret == 4, "mbstowcs did not return 4\n");
1299 ret = mbstowcs(wOut, mSimple, 4);
1300 ok(ret == 4, "mbstowcs did not return 4\n");
1301 ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
1302 ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
1304 ret = wcstombs(NULL, wSimple, 0);
1305 ok(ret == 4, "wcstombs did not return 4\n");
1307 ret = wcstombs(mOut, wSimple, 6);
1308 ok(ret == 4, "wcstombs did not return 4\n");
1309 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1311 ret = wcstombs(mOut, wSimple, 2);
1312 ok(ret == 2, "wcstombs did not return 2\n");
1313 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1315 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
1316 win_skip("Japanese_Japan.932 locale not available\n");
1320 ret = mbstowcs(wOut, mHiragana, 6);
1321 ok(ret == 2, "mbstowcs did not return 2\n");
1322 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1324 ret = wcstombs(mOut, wHiragana, 6);
1325 ok(ret == 4, "wcstombs did not return 4\n");
1326 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1328 if(!pmbstowcs_s || !pwcstombs_s) {
1329 win_skip("mbstowcs_s or wcstombs_s not available\n");
1333 err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
1334 ok(err == 0, "err = %d\n", err);
1335 ok(ret == 5, "mbstowcs_s did not return 5\n");
1336 ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
1338 err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
1339 ok(err == 0, "err = %d\n", err);
1340 ok(ret == 3, "mbstowcs_s did not return 3\n");
1341 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1343 err = pmbstowcs_s(&ret, NULL, 0, mHiragana, 1);
1344 ok(err == 0, "err = %d\n", err);
1345 ok(ret == 3, "mbstowcs_s did not return 3\n");
1347 err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
1348 ok(err == 0, "err = %d\n", err);
1349 ok(ret == 5, "wcstombs_s did not return 5\n");
1350 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1352 err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
1353 ok(err == 0, "err = %d\n", err);
1354 ok(ret == 5, "wcstombs_s did not return 5\n");
1355 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1357 err = pwcstombs_s(&ret, NULL, 0, wHiragana, 1);
1358 ok(err == 0, "err = %d\n", err);
1359 ok(ret == 5, "wcstombs_s did not return 5\n");
1362 win_skip("wcsrtombs not available\n");
1368 ret = pwcsrtombs(mOut, &pwstr, 4, &err);
1369 ok(ret == 4, "wcsrtombs did not return 4\n");
1370 ok(err == 0, "err = %d\n", err);
1371 ok(pwstr == wSimple+4, "pwstr = %p (wszSimple = %p)\n", pwstr, wSimple);
1372 ok(!memcmp(mOut, mSimple, ret), "mOut = %s\n", mOut);
1375 ret = pwcsrtombs(mOut, &pwstr, 5, NULL);
1376 ok(ret == 4, "wcsrtombs did not return 4\n");
1377 ok(pwstr == NULL, "pwstr != NULL\n");
1378 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1381 static void test_gcvt(void)
1383 char buf[1024], *res;
1387 win_skip("Skipping _gcvt tests\n");
1392 res = _gcvt(1.2, -1, buf);
1393 ok(res == NULL, "res != NULL\n");
1394 ok(errno == ERANGE, "errno = %d\n", errno);
1397 res = _gcvt(1.2, 5, NULL);
1398 ok(res == NULL, "res != NULL\n");
1399 ok(errno == EINVAL, "errno = %d\n", errno);
1401 res = gcvt(1.2, 5, buf);
1402 ok(res == buf, "res != buf\n");
1403 ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
1406 err = p_gcvt_s(buf, 5, 1.2, 10);
1407 ok(err == ERANGE, "err = %d\n", err);
1408 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1411 err = p_gcvt_s(buf, 4, 123456, 2);
1412 ok(err == ERANGE, "err = %d\n", err);
1413 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1416 static void test__itoa_s(void)
1423 win_skip("Skipping _itoa_s tests\n");
1427 if (p_set_invalid_parameter_handler)
1428 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1429 "Invalid parameter handler was already set\n");
1432 ret = p_itoa_s(0, NULL, 0, 0);
1433 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1434 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1436 memset(buffer, 'X', sizeof(buffer));
1438 ret = p_itoa_s(0, buffer, 0, 0);
1439 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1440 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1441 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1443 memset(buffer, 'X', sizeof(buffer));
1445 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
1446 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1447 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1448 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1450 memset(buffer, 'X', sizeof(buffer));
1452 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
1453 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1454 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1455 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1457 memset(buffer, 'X', sizeof(buffer));
1459 ret = p_itoa_s(12345678, buffer, 4, 10);
1460 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1461 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1462 ok(!memcmp(buffer, "\000765", 4),
1463 "Expected the output buffer to be null terminated with truncated output\n");
1465 memset(buffer, 'X', sizeof(buffer));
1467 ret = p_itoa_s(12345678, buffer, 8, 10);
1468 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1469 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1470 ok(!memcmp(buffer, "\0007654321", 8),
1471 "Expected the output buffer to be null terminated with truncated output\n");
1473 memset(buffer, 'X', sizeof(buffer));
1475 ret = p_itoa_s(-12345678, buffer, 9, 10);
1476 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1477 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1478 ok(!memcmp(buffer, "\00087654321", 9),
1479 "Expected the output buffer to be null terminated with truncated output\n");
1481 ret = p_itoa_s(12345678, buffer, 9, 10);
1482 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1483 ok(!strcmp(buffer, "12345678"),
1484 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1487 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
1488 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1489 ok(!strcmp(buffer, "1010101010101010"),
1490 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1493 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
1494 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1495 ok(!strcmp(buffer, "nell"),
1496 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1499 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
1500 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1501 ok(!strcmp(buffer, "hag"),
1502 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1505 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
1506 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1507 ok(!strcmp(buffer, "-12345678"),
1508 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1510 if (p_set_invalid_parameter_handler)
1511 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1512 "Cannot reset invalid parameter handler\n");
1515 static void test__strlwr_s(void)
1522 win_skip("Skipping _strlwr_s tests\n");
1527 ret = p_strlwr_s(NULL, 0);
1528 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1529 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1532 ret = p_strlwr_s(NULL, sizeof(buffer));
1533 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1534 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1537 ret = p_strlwr_s(buffer, 0);
1538 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1539 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1541 strcpy(buffer, "GoRrIsTeR");
1543 ret = p_strlwr_s(buffer, 5);
1544 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1545 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1546 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1547 "Expected the output buffer to be \"gorrIsTeR\"\n");
1549 strcpy(buffer, "GoRrIsTeR");
1551 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
1552 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1553 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1554 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1555 "Expected the output buffer to be \"gorrIsTeR\"\n");
1557 strcpy(buffer, "GoRrIsTeR");
1558 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
1559 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1560 ok(!strcmp(buffer, "gorrister"),
1561 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1564 memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1565 ret = p_strlwr_s(buffer, sizeof(buffer));
1566 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1567 ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1568 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1572 static void test_wcsncat_s(void)
1574 static wchar_t abcW[] = {'a','b','c',0};
1581 win_skip("skipping wcsncat_s tests\n");
1585 if (p_set_invalid_parameter_handler)
1586 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1587 "Invalid parameter handler was already set\n");
1589 memcpy(src, abcW, sizeof(abcW));
1591 ret = p_wcsncat_s(NULL, 4, src, 4);
1592 ok(ret == EINVAL, "err = %d\n", ret);
1593 ret = p_wcsncat_s(dst, 0, src, 4);
1594 ok(ret == EINVAL, "err = %d\n", ret);
1595 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
1596 ok(ret == EINVAL, "err = %d\n", ret);
1597 ret = p_wcsncat_s(dst, 4, NULL, 0);
1598 ok(ret == 0, "err = %d\n", ret);
1601 ret = p_wcsncat_s(dst, 2, src, 4);
1602 ok(ret == ERANGE, "err = %d\n", ret);
1605 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
1606 ok(ret == STRUNCATE, "err = %d\n", ret);
1607 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
1609 memcpy(dst, abcW, sizeof(abcW));
1611 ret = p_wcsncat_s(dst, 4, src, 4);
1612 ok(ret == EINVAL, "err = %d\n", ret);
1614 if (p_set_invalid_parameter_handler)
1615 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1616 "Cannot reset invalid parameter handler\n");
1619 static void test__mbsnbcat_s(void)
1621 unsigned char dest[16];
1622 const unsigned char first[] = "dinosaur";
1623 const unsigned char second[] = "duck";
1628 win_skip("Skipping _mbsnbcat_s tests\n");
1632 /* Test invalid arguments. */
1633 ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
1634 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1637 ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
1638 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1639 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1642 ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
1643 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1644 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1646 memset(dest, 'X', sizeof(dest));
1648 ret = p_mbsnbcat_s(dest, 0, NULL, 0);
1649 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1650 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1651 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1653 memset(dest, 'X', sizeof(dest));
1655 ret = p_mbsnbcat_s(dest, 0, second, 0);
1656 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1657 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1658 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1660 memset(dest, 'X', sizeof(dest));
1662 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
1663 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1664 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1665 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1667 memset(dest, 'X', sizeof(dest));
1669 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
1670 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1671 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1672 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1674 memset(dest, 'X', sizeof(dest));
1676 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1677 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1678 ok(!memcmp(dest, second, sizeof(second)),
1679 "Expected the output buffer string to be \"duck\"\n");
1681 /* Test source truncation behavior. */
1682 memset(dest, 'X', sizeof(dest));
1683 memcpy(dest, first, sizeof(first));
1684 ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
1685 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1686 ok(!memcmp(dest, first, sizeof(first)),
1687 "Expected the output buffer string to be \"dinosaur\"\n");
1689 memset(dest, 'X', sizeof(dest));
1690 memcpy(dest, first, sizeof(first));
1691 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1692 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1693 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1694 "Expected the output buffer string to be \"dinosaurduck\"\n");
1696 memset(dest, 'X', sizeof(dest));
1697 memcpy(dest, first, sizeof(first));
1698 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
1699 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1700 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1701 "Expected the output buffer string to be \"dinosaurduck\"\n");
1703 memset(dest, 'X', sizeof(dest));
1704 memcpy(dest, first, sizeof(first));
1705 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
1706 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1707 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1708 "Expected the output buffer string to be \"dinosaurduck\"\n");
1710 memset(dest, 'X', sizeof(dest));
1711 memcpy(dest, first, sizeof(first));
1712 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
1713 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1714 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
1715 "Expected the output buffer string to be \"dinosaurduc\"\n");
1717 /* Test destination truncation behavior. */
1718 memset(dest, 'X', sizeof(dest));
1719 memcpy(dest, first, sizeof(first));
1721 ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
1722 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1723 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1724 ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
1725 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
1727 memset(dest, 'X', sizeof(dest));
1728 memcpy(dest, first, sizeof(first));
1730 ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
1731 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1732 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1733 ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
1734 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
1736 memset(dest, 'X', sizeof(dest));
1737 memcpy(dest, first, sizeof(first));
1739 ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
1740 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1741 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1742 ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
1743 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
1746 static void test__mbsupr_s(void)
1749 unsigned char buffer[20];
1753 win_skip("Skipping _mbsupr_s tests\n");
1758 ret = p_mbsupr_s(NULL, 0);
1759 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
1762 ret = p_mbsupr_s(NULL, sizeof(buffer));
1763 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
1764 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1767 ret = p_mbsupr_s(buffer, 0);
1768 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
1769 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1771 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
1773 ret = p_mbsupr_s(buffer, sizeof("abcdefgh"));
1774 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
1775 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
1776 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
1779 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
1781 ret = p_mbsupr_s(buffer, sizeof(buffer));
1782 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
1783 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
1784 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
1787 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
1789 ret = p_mbsupr_s(buffer, 4);
1790 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
1791 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1793 memcpy(buffer, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
1795 ret = p_mbsupr_s(buffer, sizeof(buffer));
1796 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
1797 ok(!memcmp(buffer, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
1798 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
1803 static void test__mbslwr_s(void)
1806 unsigned char buffer[20];
1810 win_skip("Skipping _mbslwr_s tests\n");
1815 ret = p_mbslwr_s(NULL, 0);
1816 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
1819 ret = p_mbslwr_s(NULL, sizeof(buffer));
1820 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
1821 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1824 ret = p_mbslwr_s(buffer, 0);
1825 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
1826 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1828 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
1830 ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH"));
1831 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
1832 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
1833 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
1836 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
1838 ret = p_mbslwr_s(buffer, sizeof(buffer));
1839 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
1840 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
1841 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
1844 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
1846 ret = p_mbslwr_s(buffer, 4);
1847 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
1848 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1850 memcpy(buffer, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
1852 ret = p_mbslwr_s(buffer, sizeof(buffer));
1853 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
1854 ok(!memcmp(buffer, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
1855 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
1860 static void test__ultoa_s(void)
1867 win_skip("Skipping _ultoa_s tests\n");
1872 ret = p_ultoa_s(0, NULL, 0, 0);
1873 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1874 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1876 memset(buffer, 'X', sizeof(buffer));
1878 ret = p_ultoa_s(0, buffer, 0, 0);
1879 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1880 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1881 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1883 memset(buffer, 'X', sizeof(buffer));
1885 ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
1886 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1887 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1888 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1890 memset(buffer, 'X', sizeof(buffer));
1892 ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
1893 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
1894 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1895 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1897 memset(buffer, 'X', sizeof(buffer));
1899 ret = p_ultoa_s(12345678, buffer, 4, 10);
1900 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
1901 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1902 ok(!memcmp(buffer, "\000765", 4),
1903 "Expected the output buffer to be null terminated with truncated output\n");
1905 memset(buffer, 'X', sizeof(buffer));
1907 ret = p_ultoa_s(12345678, buffer, 8, 10);
1908 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
1909 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1910 ok(!memcmp(buffer, "\0007654321", 8),
1911 "Expected the output buffer to be null terminated with truncated output\n");
1913 ret = p_ultoa_s(12345678, buffer, 9, 10);
1914 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1915 ok(!strcmp(buffer, "12345678"),
1916 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1919 ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
1920 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1921 ok(!strcmp(buffer, "1010101010101010"),
1922 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1925 ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
1926 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1927 ok(!strcmp(buffer, "nell"),
1928 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1931 ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
1932 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
1933 ok(!strcmp(buffer, "hag"),
1934 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1938 static void test_wctob(void)
1942 if(!p_wctob || !setlocale(LC_ALL, "chinese-traditional")) {
1943 win_skip("Skipping wctob tests\n");
1947 ret = p_wctob(0x8141);
1948 ok(ret == EOF, "ret = %x\n", ret);
1950 ret = p_wctob(0x81);
1951 ok(ret == EOF, "ret = %x\n", ret);
1953 ret = p_wctob(0xe0);
1954 ok(ret == 0x61, "ret = %x\n", ret);
1957 ret = p_wctob(0x81);
1958 /* wctob should not be affected by _setmbcp */
1959 todo_wine ok(ret == EOF, "ret = %x\n", ret);
1961 setlocale(LC_ALL, "C");
1962 ret = p_wctob(0x8141);
1963 ok(ret == EOF, "ret = %x\n", ret);
1965 ret = p_wctob(0x81);
1966 ok(ret == (int)(char)0x81, "ret = %x\n", ret);
1968 ret = p_wctob(0xe0);
1969 ok(ret == (int)(char)0xe0, "ret = %x\n", ret);
1975 static const char xilstring[]="c:/xilinx";
1978 hMsvcrt = GetModuleHandleA("msvcrt.dll");
1980 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
1981 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
1982 SET(pmemcpy,"memcpy");
1983 SET(pmemcmp,"memcmp");
1984 SET(p_mbctype,"_mbctype");
1985 SET(p__mb_cur_max,"__mb_cur_max");
1986 pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
1987 pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
1988 p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
1989 p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
1990 p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
1991 p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
1992 p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
1993 p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
1994 p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
1995 p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
1996 pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
1997 pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
1998 pwcsrtombs = (void *)GetProcAddress(hMsvcrt, "wcsrtombs");
1999 p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
2000 p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
2001 p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
2002 p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
2003 p_set_invalid_parameter_handler = (void *) GetProcAddress(hMsvcrt, "_set_invalid_parameter_handler");
2004 p_wcslwr_s = (void*)GetProcAddress(hMsvcrt, "_wcslwr_s");
2005 p_mbsupr_s = (void*)GetProcAddress(hMsvcrt, "_mbsupr_s");
2006 p_mbslwr_s = (void*)GetProcAddress(hMsvcrt, "_mbslwr_s");
2007 p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob");
2009 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2010 MFC42 CString::Insert seems to rely on that behaviour */
2011 strcpy(mem,xilstring);
2012 nLen=strlen(xilstring);
2013 pmemcpy(mem+5, mem,nLen+1);
2014 ok(pmemcmp(mem+5,xilstring, nLen) == 0,
2015 "Got result %s\n",mem+5);
2017 /* Test _swab function */
2051 /* This test is changing locale */