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"
34 typedef unsigned int __msvcrt_ulong
;
36 static char *buf_to_string(const unsigned char *bin
, int len
, int nr
)
38 static char buf
[2][1024];
42 for (i
= 0; i
< len
; i
++)
44 sprintf(w
, "%02x ", (unsigned char)bin
[i
]);
50 static void __cdecl
test_invalid_parameter_handler(const wchar_t *expression
,
51 const wchar_t *function
, const wchar_t *file
,
52 unsigned line
, uintptr_t arg
)
54 /* we just ignore handler calls */
57 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
58 #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)); }
60 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
61 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
62 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
63 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
64 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
65 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
66 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
67 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
68 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
69 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
70 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
71 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
72 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
73 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
74 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
75 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
76 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
77 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
78 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
79 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
80 static int *p__mb_cur_max
;
81 static unsigned char *p_mbctype
;
82 static _invalid_parameter_handler (__cdecl
*p_set_invalid_parameter_handler
)(_invalid_parameter_handler
);
83 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
84 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
85 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
86 static int (__cdecl
*p_wctob
)(wint_t);
87 static int (__cdecl
*p_tolower
)(int);
89 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
90 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
92 static HMODULE hMsvcrt
;
94 static void test_swab( void ) {
95 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
96 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
97 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
98 char expected3
[] = "$";
105 /* Test 1 - normal even case */
106 memset(to
,'$', sizeof(to
));
107 memset(from
,'@', sizeof(from
));
109 memcpy(from
, original
, testsize
);
110 _swab( from
, to
, testsize
);
111 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
113 /* Test 2 - uneven case */
114 memset(to
,'$', sizeof(to
));
115 memset(from
,'@', sizeof(from
));
117 memcpy(from
, original
, testsize
);
118 _swab( from
, to
, testsize
);
119 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
121 /* Test 3 - from = to */
122 memset(to
,'$', sizeof(to
));
123 memset(from
,'@', sizeof(from
));
125 memcpy(to
, original
, testsize
);
126 _swab( to
, to
, testsize
);
127 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
129 /* Test 4 - 1 bytes */
130 memset(to
,'$', sizeof(to
));
131 memset(from
,'@', sizeof(from
));
133 memcpy(from
, original
, testsize
);
134 _swab( from
, to
, testsize
);
135 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
138 #if 0 /* use this to generate more tests */
140 static void test_codepage(int cp
)
146 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
149 printf("static int result_cp_%d_mbctype[] = { ", cp
);
150 for (i
= 1; i
< 257; i
++)
152 if (p_mbctype
[i
] != prev
)
154 printf("0x%x,%d, ", prev
, count
);
161 printf("0x%x,%d };\n", prev
, count
);
166 /* RLE-encoded mbctype tables for given codepages */
167 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
168 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
169 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
171 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
173 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
174 0x0,2, 0x4,32, 0xc,94, 0,1 };
176 static void test_cp_table(int cp
, int *result
)
182 for (i
= 0; i
< 256; i
++)
190 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
);
195 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
199 static void test_mbcp(void)
201 int mb_orig_max
= *p__mb_cur_max
;
202 int curr_mbcp
= _getmbcp();
203 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
204 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
205 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
206 unsigned char buf
[16];
212 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
213 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
214 * CP1252 (or the ACP?) so we test only a few ASCII characters */
216 expect_eq(p_mbctype
[10], 0, char, "%x");
217 expect_eq(p_mbctype
[50], 0, char, "%x");
218 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
219 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
220 expect_eq(p_mbctype
[128], 0, char, "%x");
222 expect_eq(p_mbctype
[10], 0, char, "%x");
223 expect_eq(p_mbctype
[50], 0, char, "%x");
224 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
225 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
226 expect_eq(p_mbctype
[128], 0, char, "%x");
228 /* double byte code pages */
235 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
);
236 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
237 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
238 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
239 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
240 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
241 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
244 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
245 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
246 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
247 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
248 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
249 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
250 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
251 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
252 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
254 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
255 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
256 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
257 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
260 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
261 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
262 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
263 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
264 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
265 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
266 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
267 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
268 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
270 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
271 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
272 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
273 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
274 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
275 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
278 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
279 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
280 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
281 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
282 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
283 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
284 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
285 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
286 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
288 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
289 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
290 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
291 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
292 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
293 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
296 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
297 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
298 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
300 /* _mbclen/_mbslen */
301 expect_eq(_mbclen(mbstring
), 2, int, "%d");
302 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
303 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
304 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
305 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
306 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
308 /* _mbccpy/_mbsncpy */
309 memset(buf
, 0xff, sizeof(buf
));
310 _mbccpy(buf
, mbstring
);
311 expect_bin(buf
, "\xb0\xb1\xff", 3);
313 memset(buf
, 0xff, sizeof(buf
));
314 _mbsncpy(buf
, mbstring
, 1);
315 expect_bin(buf
, "\xb0\xb1\xff", 3);
316 memset(buf
, 0xff, sizeof(buf
));
317 _mbsncpy(buf
, mbstring
, 2);
318 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
319 memset(buf
, 0xff, sizeof(buf
));
320 _mbsncpy(buf
, mbstring
, 3);
321 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
322 memset(buf
, 0xff, sizeof(buf
));
323 _mbsncpy(buf
, mbstring
, 4);
324 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
325 memset(buf
, 0xff, sizeof(buf
));
326 _mbsncpy(buf
, mbstring
, 5);
327 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
328 memset(buf
, 0xff, sizeof(buf
));
329 _mbsncpy(buf
, mbsonlylead
, 6);
330 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
332 memset(buf
, 0xff, sizeof(buf
));
333 _mbsnbcpy(buf
, mbstring2
, 2);
334 expect_bin(buf
, "\xb0\xb1\xff", 3);
335 _mbsnbcpy(buf
, mbstring2
, 3);
336 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
337 _mbsnbcpy(buf
, mbstring2
, 4);
338 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
339 memset(buf
, 0xff, sizeof(buf
));
340 _mbsnbcpy(buf
, mbsonlylead
, 5);
341 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
344 step
= _mbsinc(mbstring
) - mbstring
;
345 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
346 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
347 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
349 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
350 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
351 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
352 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
353 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
354 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
355 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
356 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
357 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
358 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
359 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
360 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
361 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
362 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
363 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
364 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
365 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
366 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
368 /* functions that depend on locale codepage, not mbcp.
369 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
370 * (as of Wine 0.9.43)
372 GetCPInfo(GetACP(), &cp_info
);
373 if (cp_info
.MaxCharSize
== 1)
375 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
376 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
379 skip("Current locale has double-byte charset - could lead to false positives\n");
382 expect_eq(_ismbblead(0x80), 0, int, "%d");
384 expect_eq(_ismbblead(0x81), 1, int, "%d");
385 expect_eq(_ismbblead(0x83), 1, int, "%d");
387 expect_eq(_ismbblead(0x84), 1, int, "%d");
388 expect_eq(_ismbblead(0xd3), 1, int, "%d");
389 expect_eq(_ismbblead(0xd7), 0, int, "%d");
391 expect_eq(_ismbblead(0xd8), 1, int, "%d");
393 expect_eq(_ismbblead(0xd9), 1, int, "%d");
395 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
396 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
397 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
398 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
399 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
400 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
401 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
402 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
407 static void test_mbsspn( void)
409 unsigned char str1
[]="cabernet";
410 unsigned char str2
[]="shiraz";
411 unsigned char set
[]="abc";
412 unsigned char empty
[]="";
414 ret
=_mbsspn( str1
, set
);
415 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
416 ret
=_mbsspn( str2
, set
);
417 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
418 ret
=_mbsspn( str1
, empty
);
419 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
422 static void test_mbsspnp( void)
424 unsigned char str1
[]="cabernet";
425 unsigned char str2
[]="shiraz";
426 unsigned char set
[]="abc";
427 unsigned char empty
[]="";
428 unsigned char full
[]="abcenrt";
430 ret
=_mbsspnp( str1
, set
);
431 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
432 ret
=_mbsspnp( str2
, set
);
433 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
434 ret
=_mbsspnp( str1
, empty
);
435 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
436 ret
=_mbsspnp( str1
, full
);
437 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
440 static void test_strdup(void)
444 ok( str
== 0, "strdup returns %s should be 0\n", str
);
448 static void test_strcpy_s(void)
451 const char *small
= "small";
452 const char *big
= "atoolongstringforthislittledestination";
457 skip("strcpy_s not found\n");
461 memset(dest
, 'X', sizeof(dest
));
462 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
463 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
464 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
465 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
466 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
467 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
469 memset(dest
, 'X', sizeof(dest
));
470 ret
= pstrcpy_s(dest
, 0, big
);
471 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
472 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
473 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
474 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
475 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
476 ret
= pstrcpy_s(dest
, 0, NULL
);
477 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
478 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
479 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
480 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
481 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
483 memset(dest
, 'X', sizeof(dest
));
484 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
485 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
486 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
487 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
488 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
489 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
491 memset(dest
, 'X', sizeof(dest
));
492 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
493 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
494 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
495 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
496 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
497 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
499 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
500 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
503 static void test_strcat_s(void)
506 const char *small
= "sma";
511 skip("strcat_s not found\n");
515 memset(dest
, 'X', sizeof(dest
));
517 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
518 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
519 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
520 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
521 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
522 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
523 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
524 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
525 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
526 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
527 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
528 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
530 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
531 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
532 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
533 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
534 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
535 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
537 memset(dest
, 'X', sizeof(dest
));
541 ret
= pstrcat_s(dest
, 0, small
);
542 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
543 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
544 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
545 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
546 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
548 ret
= pstrcat_s(dest
, 0, NULL
);
549 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
550 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
551 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
552 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
553 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
555 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
556 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
557 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
558 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
559 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
560 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
562 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
563 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
566 static void test__mbsnbcpy_s(void)
568 unsigned char dest
[8];
569 const unsigned char big
[] = "atoolongstringforthislittledestination";
570 const unsigned char small
[] = "small";
575 skip("_mbsnbcpy_s not found\n");
579 memset(dest
, 'X', sizeof(dest
));
580 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
581 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
582 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
583 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
584 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
585 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
588 memset(dest
, 'X', sizeof(dest
));
589 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
590 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
591 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
592 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
593 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
594 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
596 memset(dest
, 'X', sizeof(dest
));
597 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
598 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
599 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
600 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
601 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
602 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
604 memset(dest
, 'X', sizeof(dest
));
605 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
606 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
607 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
608 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
609 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
610 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
613 static void test_wcscpy_s(void)
615 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
616 static WCHAR szDest
[18];
617 static WCHAR szDestShort
[8];
622 win_skip("wcscpy_s not found\n");
627 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
628 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
630 /* Test NULL Source */
632 ret
= p_wcscpy_s(szDest
, 18, NULL
);
633 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
634 ok(szDest
[0] == 0, "szDest[0] not 0\n");
636 /* Test invalid size */
638 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
639 /* Later versions changed the return value for this case to EINVAL,
640 * and don't modify the result if the dest size is 0.
642 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
643 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
645 /* Copy same buffer size */
646 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
647 ok(ret
== 0, "expected 0 got %d\n", ret
);
648 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
650 /* Copy smaller buffer size */
652 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
653 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
654 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
658 win_skip("wcsncpy_s not found\n");
662 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
663 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
666 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
667 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
668 ok(szDest
[0] == 0, "szDest[0] not 0\n");
671 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
672 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
673 ok(szDest
[0] == 0, "szDest[0] not 0\n");
676 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
677 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
678 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
680 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
681 ok(ret
== 0, "expected 0 got %d\n", ret
);
682 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
685 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
686 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
687 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
690 static void test__wcsupr_s(void)
692 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
693 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
694 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
695 'W', 'E', 'R', 'U', 'P', 'P', 'E',
697 WCHAR testBuffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
702 win_skip("_wcsupr_s not found\n");
706 /* Test NULL input string and invalid size. */
708 ret
= p_wcsupr_s(NULL
, 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
);
712 /* Test NULL input string and valid size. */
714 ret
= p_wcsupr_s(NULL
, sizeof(testBuffer
)/sizeof(WCHAR
));
715 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
716 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
718 /* Test empty string with zero size. */
720 testBuffer
[0] = '\0';
721 ret
= p_wcsupr_s(testBuffer
, 0);
722 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
723 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
724 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
726 /* Test empty string with size of one. */
727 testBuffer
[0] = '\0';
728 ret
= p_wcsupr_s(testBuffer
, 1);
729 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
730 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
732 /* Test one-byte buffer with zero size. */
735 ret
= p_wcsupr_s(testBuffer
, 0);
736 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
737 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
738 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
740 /* Test one-byte buffer with size of one. */
743 ret
= p_wcsupr_s(testBuffer
, 1);
744 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
745 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
746 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
748 /* Test invalid size. */
749 wcscpy(testBuffer
, mixedString
);
751 ret
= p_wcsupr_s(testBuffer
, 0);
752 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
753 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
754 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
756 /* Test normal string uppercasing. */
757 wcscpy(testBuffer
, mixedString
);
758 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
));
759 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
760 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
762 /* Test uppercasing with a shorter buffer size count. */
763 wcscpy(testBuffer
, mixedString
);
765 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
766 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
767 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
768 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
770 /* Test uppercasing with a longer buffer size count. */
771 wcscpy(testBuffer
, mixedString
);
772 ret
= p_wcsupr_s(testBuffer
, sizeof(testBuffer
)/sizeof(WCHAR
));
773 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
774 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
777 static void test__wcslwr_s(void)
779 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
780 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
781 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
782 'w', 'e', 'r', 'u', 'p', 'p', 'e',
784 WCHAR buffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
789 win_skip("_wcslwr_s not found\n");
793 /* Test NULL input string and invalid size. */
795 ret
= p_wcslwr_s(NULL
, 0);
796 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
797 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
799 /* Test NULL input string and valid size. */
801 ret
= p_wcslwr_s(NULL
, sizeof(buffer
)/sizeof(wchar_t));
802 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
803 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
805 /* Test empty string with zero size. */
808 ret
= p_wcslwr_s(buffer
, 0);
809 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
810 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
811 ok(buffer
[0] == 0, "expected empty string\n");
813 /* Test empty string with size of one. */
815 ret
= p_wcslwr_s(buffer
, 1);
816 ok(ret
== 0, "got %d\n", ret
);
817 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
819 /* Test one-byte buffer with zero size. */
822 ret
= p_wcslwr_s(buffer
, 0);
823 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
824 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
825 ok(buffer
[0] == '\0', "expected empty string\n");
827 /* Test one-byte buffer with size of one. */
830 ret
= p_wcslwr_s(buffer
, 1);
831 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
832 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
833 ok(buffer
[0] == '\0', "expected empty string\n");
835 /* Test invalid size. */
836 wcscpy(buffer
, mixedString
);
838 ret
= p_wcslwr_s(buffer
, 0);
839 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
840 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
841 ok(buffer
[0] == '\0', "expected empty string\n");
843 /* Test normal string uppercasing. */
844 wcscpy(buffer
, mixedString
);
845 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
));
846 ok(ret
== 0, "expected 0, got %d\n", ret
);
847 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
849 /* Test uppercasing with a shorter buffer size count. */
850 wcscpy(buffer
, mixedString
);
852 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
853 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
854 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
855 ok(buffer
[0] == '\0', "expected empty string\n");
857 /* Test uppercasing with a longer buffer size count. */
858 wcscpy(buffer
, mixedString
);
859 ret
= p_wcslwr_s(buffer
, sizeof(buffer
)/sizeof(WCHAR
));
860 ok(ret
== 0, "expected 0, got %d\n", ret
);
861 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
864 static void test_mbcjisjms(void)
866 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
867 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
868 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
869 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
870 unsigned int ret
, exp
, i
;
875 ret
= _mbcjistojms(jisjms
[i
][0]);
877 if(_getmbcp() == 932) /* Japanese codepage? */
880 exp
= jisjms
[i
][0]; /* If not, no conversion */
882 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
883 } while(jisjms
[i
++][0] != 0);
886 static void test_mbctombb(void)
888 static const unsigned int mbcmbb_932
[][2] = {
889 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
890 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
891 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
892 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
893 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
894 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
895 unsigned int exp
, ret
, i
;
896 unsigned int prev_cp
= _getmbcp();
899 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
901 ret
= _mbctombb(mbcmbb_932
[i
][0]);
902 exp
= mbcmbb_932
[i
][1];
903 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
908 static void test_ismbclegal(void) {
909 unsigned int prev_cp
= _getmbcp();
913 _setmbcp(932); /* Japanese */
915 for(i
= 0; i
< 0x10000; i
++) {
916 ret
= _ismbclegal(i
);
917 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
918 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
919 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
920 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
926 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
927 _setmbcp(936); /* Chinese (GBK) */
929 for(i
= 0; i
< 0x10000; i
++) {
930 ret
= _ismbclegal(i
);
931 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
932 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
938 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
939 _setmbcp(949); /* Korean */
941 for(i
= 0; i
< 0x10000; i
++) {
942 ret
= _ismbclegal(i
);
943 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
944 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
950 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
951 _setmbcp(950); /* Chinese (Big5) */
953 for(i
= 0; i
< 0x10000; i
++) {
954 ret
= _ismbclegal(i
);
955 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
956 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
957 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
963 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
964 _setmbcp(1361); /* Korean (Johab) */
966 for(i
= 0; i
< 0x10000; i
++) {
967 ret
= _ismbclegal(i
);
968 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
969 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
970 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
971 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
978 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
983 static const struct {
985 const char* delimiter
;
986 int exp_offsetret1
; /* returned offset from string after first call to strtok()
988 int exp_offsetret2
; /* returned offset from string after second call to strtok()
990 int exp_offsetret3
; /* returned offset from string after third call to strtok()
992 } testcases_strtok
[] = {
993 { "red cabernet", " ", 0, 4, -1 },
994 { "sparkling white riesling", " ", 0, 10, 16 },
995 { " pale cream sherry", "e ", 1, 6, 9 },
1000 static void test_strtok(void)
1005 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1006 strcpy( teststr
, testcases_strtok
[i
].string
);
1007 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1008 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1009 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1010 "string (%p) \'%s\' return %p\n",
1011 teststr
, testcases_strtok
[i
].string
, strret
);
1012 if( !strret
) continue;
1013 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1014 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1015 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1016 "second call string (%p) \'%s\' return %p\n",
1017 teststr
, testcases_strtok
[i
].string
, strret
);
1018 if( !strret
) continue;
1019 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1020 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1021 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1022 "third call string (%p) \'%s\' return %p\n",
1023 teststr
, testcases_strtok
[i
].string
, strret
);
1027 static void test_strtol(void)
1033 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1034 /* errno is modified on W2K8+ */
1036 l
= strtol("-1234", &e
, 0);
1037 ok(l
==-1234, "wrong value %d\n", l
);
1038 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1040 ul
= strtoul("1234", &e
, 0);
1041 ok(ul
==1234, "wrong value %u\n", ul
);
1042 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1045 l
= strtol("2147483647L", &e
, 0);
1046 ok(l
==2147483647, "wrong value %d\n", l
);
1047 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1049 l
= strtol("-2147483648L", &e
, 0);
1050 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1051 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1053 ul
= strtoul("4294967295UL", &e
, 0);
1054 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1055 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1058 l
= strtol("9223372036854775807L", &e
, 0);
1059 ok(l
==2147483647, "wrong value %d\n", l
);
1060 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1062 ul
= strtoul("9223372036854775807L", &e
, 0);
1063 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1064 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1067 static void test_strnlen(void)
1069 static const char str
[] = "string";
1073 win_skip("strnlen not found\n");
1077 res
= p_strnlen(str
, 20);
1078 ok(res
== 6, "Returned length = %d\n", (int)res
);
1080 res
= p_strnlen(str
, 3);
1081 ok(res
== 3, "Returned length = %d\n", (int)res
);
1083 res
= p_strnlen(NULL
, 0);
1084 ok(res
== 0, "Returned length = %d\n", (int)res
);
1087 static void test__strtoi64(void)
1089 static const char no1
[] = "31923";
1090 static const char no2
[] = "-213312";
1091 static const char no3
[] = "12aa";
1092 static const char no4
[] = "abc12";
1093 static const char overflow
[] = "99999999999999999999";
1094 static const char neg_overflow
[] = "-99999999999999999999";
1095 static const char hex
[] = "0x123";
1096 static const char oct
[] = "000123";
1097 static const char blanks
[] = " 12 212.31";
1100 unsigned __int64 ures
;
1103 if(!p_strtoi64
|| !p_strtoui64
) {
1104 win_skip("_strtoi64 or _strtoui64 not found\n");
1109 res
= p_strtoi64(no1
, NULL
, 10);
1110 ok(res
== 31923, "res != 31923\n");
1111 res
= p_strtoi64(no2
, NULL
, 10);
1112 ok(res
== -213312, "res != -213312\n");
1113 res
= p_strtoi64(no3
, NULL
, 10);
1114 ok(res
== 12, "res != 12\n");
1115 res
= p_strtoi64(no4
, &endpos
, 10);
1116 ok(res
== 0, "res != 0\n");
1117 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1118 res
= p_strtoi64(hex
, &endpos
, 10);
1119 ok(res
== 0, "res != 0\n");
1120 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1121 res
= p_strtoi64(oct
, &endpos
, 10);
1122 ok(res
== 123, "res != 123\n");
1123 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1124 res
= p_strtoi64(blanks
, &endpos
, 10);
1125 ok(res
== 12, "res != 12\n");
1126 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1127 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1130 res
= p_strtoi64(overflow
, &endpos
, 10);
1131 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1132 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1133 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1136 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1137 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1138 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1139 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1142 res
= p_strtoi64(no1
, &endpos
, 16);
1143 ok(res
== 203043, "res != 203043\n");
1144 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1145 res
= p_strtoi64(no2
, &endpos
, 16);
1146 ok(res
== -2175762, "res != -2175762\n");
1147 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1148 res
= p_strtoi64(no3
, &endpos
, 16);
1149 ok(res
== 4778, "res != 4778\n");
1150 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1151 res
= p_strtoi64(no4
, &endpos
, 16);
1152 ok(res
== 703506, "res != 703506\n");
1153 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1154 res
= p_strtoi64(hex
, &endpos
, 16);
1155 ok(res
== 291, "res != 291\n");
1156 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1157 res
= p_strtoi64(oct
, &endpos
, 16);
1158 ok(res
== 291, "res != 291\n");
1159 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1160 res
= p_strtoi64(blanks
, &endpos
, 16);
1161 ok(res
== 18, "res != 18\n");
1162 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1163 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1166 res
= p_strtoi64(hex
, &endpos
, 36);
1167 ok(res
== 1541019, "res != 1541019\n");
1168 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1169 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1172 res
= p_strtoi64(no1
, &endpos
, 0);
1173 ok(res
== 31923, "res != 31923\n");
1174 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1175 res
= p_strtoi64(no2
, &endpos
, 0);
1176 ok(res
== -213312, "res != -213312\n");
1177 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1178 res
= p_strtoi64(no3
, &endpos
, 10);
1179 ok(res
== 12, "res != 12\n");
1180 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1181 res
= p_strtoi64(no4
, &endpos
, 10);
1182 ok(res
== 0, "res != 0\n");
1183 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1184 res
= p_strtoi64(hex
, &endpos
, 10);
1185 ok(res
== 0, "res != 0\n");
1186 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1187 res
= p_strtoi64(oct
, &endpos
, 10);
1188 ok(res
== 123, "res != 123\n");
1189 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1190 res
= p_strtoi64(blanks
, &endpos
, 10);
1191 ok(res
== 12, "res != 12\n");
1192 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1193 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1196 ures
= p_strtoui64(no1
, &endpos
, 0);
1197 ok(ures
== 31923, "ures != 31923\n");
1198 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1199 ures
= p_strtoui64(no2
, &endpos
, 0);
1200 ok(ures
== -213312, "ures != -213312\n");
1201 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1202 ures
= p_strtoui64(no3
, &endpos
, 10);
1203 ok(ures
== 12, "ures != 12\n");
1204 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1205 ures
= p_strtoui64(no4
, &endpos
, 10);
1206 ok(ures
== 0, "ures != 0\n");
1207 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1208 ures
= p_strtoui64(hex
, &endpos
, 10);
1209 ok(ures
== 0, "ures != 0\n");
1210 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1211 ures
= p_strtoui64(oct
, &endpos
, 10);
1212 ok(ures
== 123, "ures != 123\n");
1213 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1214 ures
= p_strtoui64(blanks
, &endpos
, 10);
1215 ok(ures
== 12, "ures != 12\n");
1216 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1217 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1220 ures
= p_strtoui64(overflow
, &endpos
, 10);
1221 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1222 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1223 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1226 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1227 ok(ures
== 1, "ures != 1\n");
1228 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1229 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1232 static inline BOOL
almost_equal(double d1
, double d2
) {
1233 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1238 static void test__strtod(void)
1240 const char double1
[] = "12.1";
1241 const char double2
[] = "-13.721";
1242 const char double3
[] = "INF";
1243 const char double4
[] = ".21e12";
1244 const char double5
[] = "214353e-3";
1245 const char overflow
[] = "1d9999999999999999999";
1246 const char white_chars
[] = " d10";
1251 d
= strtod(double1
, &end
);
1252 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1253 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1255 d
= strtod(double2
, &end
);
1256 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1257 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1259 d
= strtod(double3
, &end
);
1260 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1261 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1263 d
= strtod(double4
, &end
);
1264 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1265 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1267 d
= strtod(double5
, &end
);
1268 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1269 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1271 d
= strtod("12.1d2", NULL
);
1272 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1274 d
= strtod(white_chars
, &end
);
1275 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1276 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1278 /* Set locale with non '.' decimal point (',') */
1279 if(!setlocale(LC_ALL
, "Polish")) {
1280 win_skip("system with limited locales\n");
1284 d
= strtod("12.1", NULL
);
1285 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1287 d
= strtod("12,1", NULL
);
1288 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1290 setlocale(LC_ALL
, "C");
1292 /* Precision tests */
1293 d
= strtod("0.1", NULL
);
1294 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1295 d
= strtod("-0.1", NULL
);
1296 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1297 d
= strtod("0.1281832188491894198128921", NULL
);
1298 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1299 d
= strtod("0.82181281288121", NULL
);
1300 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1301 d
= strtod("21921922352523587651128218821", NULL
);
1302 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1303 d
= strtod("0.1d238", NULL
);
1304 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1305 d
= strtod("0.1D-4736", NULL
);
1306 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1309 strtod(overflow
, &end
);
1310 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1311 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1314 strtod("-1d309", NULL
);
1315 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1318 static void test_mbstowcs(void)
1320 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1321 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1322 static const char mSimple
[] = "text";
1323 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1325 const wchar_t *pwstr
;
1331 wOut
[4] = '!'; wOut
[5] = '\0';
1332 mOut
[4] = '!'; mOut
[5] = '\0';
1334 ret
= mbstowcs(NULL
, mSimple
, 0);
1335 ok(ret
== 4, "mbstowcs did not return 4\n");
1337 ret
= mbstowcs(wOut
, mSimple
, 4);
1338 ok(ret
== 4, "mbstowcs did not return 4\n");
1339 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1340 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1342 ret
= wcstombs(NULL
, wSimple
, 0);
1343 ok(ret
== 4, "wcstombs did not return 4\n");
1345 ret
= wcstombs(mOut
, wSimple
, 6);
1346 ok(ret
== 4, "wcstombs did not return 4\n");
1347 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1349 ret
= wcstombs(mOut
, wSimple
, 2);
1350 ok(ret
== 2, "wcstombs did not return 2\n");
1351 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1353 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
1354 win_skip("Japanese_Japan.932 locale not available\n");
1358 ret
= mbstowcs(wOut
, mHiragana
, 6);
1359 ok(ret
== 2, "mbstowcs did not return 2\n");
1360 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1362 ret
= wcstombs(mOut
, wHiragana
, 6);
1363 ok(ret
== 4, "wcstombs did not return 4\n");
1364 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1366 if(!pmbstowcs_s
|| !pwcstombs_s
) {
1367 setlocale(LC_ALL
, "C");
1368 win_skip("mbstowcs_s or wcstombs_s not available\n");
1372 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
1373 ok(err
== 0, "err = %d\n", err
);
1374 ok(ret
== 5, "mbstowcs_s did not return 5\n");
1375 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1377 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
1378 ok(err
== 0, "err = %d\n", err
);
1379 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1380 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1382 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
1383 ok(err
== 0, "err = %d\n", err
);
1384 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1386 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
1387 ok(err
== 0, "err = %d\n", err
);
1388 ok(ret
== 5, "wcstombs_s did not return 5\n");
1389 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1391 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
1392 ok(err
== 0, "err = %d\n", err
);
1393 ok(ret
== 5, "wcstombs_s did not return 5\n");
1394 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1396 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
1397 ok(err
== 0, "err = %d\n", err
);
1398 ok(ret
== 5, "wcstombs_s did not return 5\n");
1401 setlocale(LC_ALL
, "C");
1402 win_skip("wcsrtombs not available\n");
1408 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
1409 ok(ret
== 4, "wcsrtombs did not return 4\n");
1410 ok(err
== 0, "err = %d\n", err
);
1411 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
1412 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
1415 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
1416 ok(ret
== 4, "wcsrtombs did not return 4\n");
1417 ok(pwstr
== NULL
, "pwstr != NULL\n");
1418 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1420 setlocale(LC_ALL
, "C");
1423 static void test_gcvt(void)
1425 char buf
[1024], *res
;
1429 win_skip("Skipping _gcvt tests\n");
1434 res
= _gcvt(1.2, -1, buf
);
1435 ok(res
== NULL
, "res != NULL\n");
1436 ok(errno
== ERANGE
, "errno = %d\n", errno
);
1439 res
= _gcvt(1.2, 5, NULL
);
1440 ok(res
== NULL
, "res != NULL\n");
1441 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1443 res
= gcvt(1.2, 5, buf
);
1444 ok(res
== buf
, "res != buf\n");
1445 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
1448 err
= p_gcvt_s(buf
, 5, 1.2, 10);
1449 ok(err
== ERANGE
, "err = %d\n", err
);
1450 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1453 err
= p_gcvt_s(buf
, 4, 123456, 2);
1454 ok(err
== ERANGE
, "err = %d\n", err
);
1455 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1458 static void test__itoa_s(void)
1465 win_skip("Skipping _itoa_s tests\n");
1469 if (p_set_invalid_parameter_handler
)
1470 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1471 "Invalid parameter handler was already set\n");
1474 ret
= p_itoa_s(0, NULL
, 0, 0);
1475 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1476 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1478 memset(buffer
, 'X', sizeof(buffer
));
1480 ret
= p_itoa_s(0, buffer
, 0, 0);
1481 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1482 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1483 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
1485 memset(buffer
, 'X', sizeof(buffer
));
1487 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
1488 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1489 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1490 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1492 memset(buffer
, 'X', sizeof(buffer
));
1494 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
1495 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1496 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1497 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1499 memset(buffer
, 'X', sizeof(buffer
));
1501 ret
= p_itoa_s(12345678, buffer
, 4, 10);
1502 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1503 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1504 ok(!memcmp(buffer
, "\000765", 4),
1505 "Expected the output buffer to be null terminated with truncated output\n");
1507 memset(buffer
, 'X', sizeof(buffer
));
1509 ret
= p_itoa_s(12345678, buffer
, 8, 10);
1510 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1511 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1512 ok(!memcmp(buffer
, "\0007654321", 8),
1513 "Expected the output buffer to be null terminated with truncated output\n");
1515 memset(buffer
, 'X', sizeof(buffer
));
1517 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
1518 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1519 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1520 ok(!memcmp(buffer
, "\00087654321", 9),
1521 "Expected the output buffer to be null terminated with truncated output\n");
1523 ret
= p_itoa_s(12345678, buffer
, 9, 10);
1524 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1525 ok(!strcmp(buffer
, "12345678"),
1526 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1529 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
1530 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1531 ok(!strcmp(buffer
, "1010101010101010"),
1532 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1535 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
1536 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1537 ok(!strcmp(buffer
, "nell"),
1538 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1541 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
1542 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1543 ok(!strcmp(buffer
, "hag"),
1544 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1547 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
1548 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1549 ok(!strcmp(buffer
, "-12345678"),
1550 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1552 if (p_set_invalid_parameter_handler
)
1553 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
1554 "Cannot reset invalid parameter handler\n");
1557 static void test__strlwr_s(void)
1564 win_skip("Skipping _strlwr_s tests\n");
1569 ret
= p_strlwr_s(NULL
, 0);
1570 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1571 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1574 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
1575 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1576 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1579 ret
= p_strlwr_s(buffer
, 0);
1580 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1581 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1583 strcpy(buffer
, "GoRrIsTeR");
1585 ret
= p_strlwr_s(buffer
, 5);
1586 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1587 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1588 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1589 "Expected the output buffer to be \"gorrIsTeR\"\n");
1591 strcpy(buffer
, "GoRrIsTeR");
1593 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
1594 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1595 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1596 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1597 "Expected the output buffer to be \"gorrIsTeR\"\n");
1599 strcpy(buffer
, "GoRrIsTeR");
1600 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
1601 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1602 ok(!strcmp(buffer
, "gorrister"),
1603 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1606 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1607 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
1608 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1609 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1610 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1614 static void test_wcsncat_s(void)
1616 static wchar_t abcW
[] = {'a','b','c',0};
1623 win_skip("skipping wcsncat_s tests\n");
1627 if (p_set_invalid_parameter_handler
)
1628 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1629 "Invalid parameter handler was already set\n");
1631 memcpy(src
, abcW
, sizeof(abcW
));
1633 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
1634 ok(ret
== EINVAL
, "err = %d\n", ret
);
1635 ret
= p_wcsncat_s(dst
, 0, src
, 4);
1636 ok(ret
== EINVAL
, "err = %d\n", ret
);
1637 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
1638 ok(ret
== EINVAL
, "err = %d\n", ret
);
1639 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
1640 ok(ret
== 0, "err = %d\n", ret
);
1643 ret
= p_wcsncat_s(dst
, 2, src
, 4);
1644 ok(ret
== ERANGE
, "err = %d\n", ret
);
1647 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
1648 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
1649 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
1651 memcpy(dst
, abcW
, sizeof(abcW
));
1653 ret
= p_wcsncat_s(dst
, 4, src
, 4);
1654 ok(ret
== EINVAL
, "err = %d\n", ret
);
1656 if (p_set_invalid_parameter_handler
)
1657 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
1658 "Cannot reset invalid parameter handler\n");
1661 static void test__mbsnbcat_s(void)
1663 unsigned char dest
[16];
1664 const unsigned char first
[] = "dinosaur";
1665 const unsigned char second
[] = "duck";
1670 win_skip("Skipping _mbsnbcat_s tests\n");
1674 /* Test invalid arguments. */
1675 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
1676 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1679 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
1680 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1681 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1684 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
1685 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1686 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1688 memset(dest
, 'X', sizeof(dest
));
1690 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
1691 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1692 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1693 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
1695 memset(dest
, 'X', sizeof(dest
));
1697 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
1698 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1699 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1700 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
1702 memset(dest
, 'X', sizeof(dest
));
1704 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
1705 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1706 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1707 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
1709 memset(dest
, 'X', sizeof(dest
));
1711 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
1712 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1713 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1714 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
1716 memset(dest
, 'X', sizeof(dest
));
1718 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
1719 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1720 ok(!memcmp(dest
, second
, sizeof(second
)),
1721 "Expected the output buffer string to be \"duck\"\n");
1723 /* Test source truncation behavior. */
1724 memset(dest
, 'X', sizeof(dest
));
1725 memcpy(dest
, first
, sizeof(first
));
1726 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
1727 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1728 ok(!memcmp(dest
, first
, sizeof(first
)),
1729 "Expected the output buffer string to be \"dinosaur\"\n");
1731 memset(dest
, 'X', sizeof(dest
));
1732 memcpy(dest
, first
, sizeof(first
));
1733 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
1734 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1735 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
1736 "Expected the output buffer string to be \"dinosaurduck\"\n");
1738 memset(dest
, 'X', sizeof(dest
));
1739 memcpy(dest
, first
, sizeof(first
));
1740 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
1741 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1742 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
1743 "Expected the output buffer string to be \"dinosaurduck\"\n");
1745 memset(dest
, 'X', sizeof(dest
));
1746 memcpy(dest
, first
, sizeof(first
));
1747 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
1748 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1749 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
1750 "Expected the output buffer string to be \"dinosaurduck\"\n");
1752 memset(dest
, 'X', sizeof(dest
));
1753 memcpy(dest
, first
, sizeof(first
));
1754 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
1755 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1756 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
1757 "Expected the output buffer string to be \"dinosaurduc\"\n");
1759 /* Test destination truncation behavior. */
1760 memset(dest
, 'X', sizeof(dest
));
1761 memcpy(dest
, first
, sizeof(first
));
1763 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
1764 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1765 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1766 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
1767 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
1769 memset(dest
, 'X', sizeof(dest
));
1770 memcpy(dest
, first
, sizeof(first
));
1772 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
1773 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
1774 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1775 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
1776 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
1778 memset(dest
, 'X', sizeof(dest
));
1779 memcpy(dest
, first
, sizeof(first
));
1781 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
1782 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
1783 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1784 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
1785 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
1788 static void test__mbsupr_s(void)
1791 unsigned char buffer
[20];
1795 win_skip("Skipping _mbsupr_s tests\n");
1800 ret
= p_mbsupr_s(NULL
, 0);
1801 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1804 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
1805 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
1806 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1809 ret
= p_mbsupr_s(buffer
, 0);
1810 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
1811 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1813 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
1815 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
1816 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1817 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
1818 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
1821 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
1823 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
1824 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1825 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
1826 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
1829 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
1831 ret
= p_mbsupr_s(buffer
, 4);
1832 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
1833 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1835 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
1837 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
1838 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1839 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
1840 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
1845 static void test__mbslwr_s(void)
1848 unsigned char buffer
[20];
1852 win_skip("Skipping _mbslwr_s tests\n");
1857 ret
= p_mbslwr_s(NULL
, 0);
1858 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1861 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
1862 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
1863 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1866 ret
= p_mbslwr_s(buffer
, 0);
1867 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
1868 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1870 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
1872 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
1873 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1874 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
1875 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
1878 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
1880 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
1881 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1882 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
1883 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
1886 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
1888 ret
= p_mbslwr_s(buffer
, 4);
1889 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
1890 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1892 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
1894 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
1895 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1896 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
1897 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
1901 static void test__ultoa_s(void)
1908 win_skip("Skipping _ultoa_s tests\n");
1913 ret
= p_ultoa_s(0, NULL
, 0, 0);
1914 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1915 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1917 memset(buffer
, 'X', sizeof(buffer
));
1919 ret
= p_ultoa_s(0, buffer
, 0, 0);
1920 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1921 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1922 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
1924 memset(buffer
, 'X', sizeof(buffer
));
1926 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
1927 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1928 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1929 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1931 memset(buffer
, 'X', sizeof(buffer
));
1933 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
1934 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1935 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1936 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1938 memset(buffer
, 'X', sizeof(buffer
));
1940 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
1941 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
1942 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1943 ok(!memcmp(buffer
, "\000765", 4),
1944 "Expected the output buffer to be null terminated with truncated output\n");
1946 memset(buffer
, 'X', sizeof(buffer
));
1948 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
1949 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
1950 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1951 ok(!memcmp(buffer
, "\0007654321", 8),
1952 "Expected the output buffer to be null terminated with truncated output\n");
1954 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
1955 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1956 ok(!strcmp(buffer
, "12345678"),
1957 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1960 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
1961 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1962 ok(!strcmp(buffer
, "1010101010101010"),
1963 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1966 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
1967 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1968 ok(!strcmp(buffer
, "nell"),
1969 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1972 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
1973 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1974 ok(!strcmp(buffer
, "hag"),
1975 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1979 static void test_wctob(void)
1983 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
1984 win_skip("Skipping wctob tests\n");
1988 ret
= p_wctob(0x8141);
1989 ok(ret
== EOF
, "ret = %x\n", ret
);
1991 ret
= p_wctob(0x81);
1992 ok(ret
== EOF
, "ret = %x\n", ret
);
1994 ret
= p_wctob(0xe0);
1995 ok(ret
== 0x61, "ret = %x\n", ret
);
1998 ret
= p_wctob(0x81);
1999 ok(ret
== EOF
, "ret = %x\n", ret
);
2001 setlocale(LC_ALL
, "C");
2002 ret
= p_wctob(0x8141);
2003 ok(ret
== EOF
, "ret = %x\n", ret
);
2005 ret
= p_wctob(0x81);
2006 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2008 ret
= p_wctob(0xe0);
2009 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2012 static void test_tolower(void)
2016 ret
= p_tolower(0x41);
2017 ok(ret
== 0x61, "ret = %x\n", ret
);
2019 ret
= p_tolower(0xF4);
2020 ok(ret
== 0xF4, "ret = %x\n", ret
);
2022 ret
= p_tolower((char)0xF4);
2023 ok(ret
==0xF4/*Vista+*/ || ret
==(char)0xF4, "ret = %x\n", ret
);
2025 /* is it using different locale (CP_ACP) for negative values?? */
2026 /* current implementation matches msvcr90 behaviour */
2027 ret
= p_tolower((char)0xD0);
2028 todo_wine
ok(ret
==0xF0/*Vista+*/ || ret
==(char)0xD0, "ret = %x\n", ret
);
2030 ret
= p_tolower(0xD0);
2031 ok(ret
== 0xD0, "ret = %x\n", ret
);
2033 if(!setlocale(LC_ALL
, "us")) {
2034 win_skip("skipping tolower tests that depends on locale\n");
2038 ret
= p_tolower((char)0xD0);
2039 ok(ret
== 0xF0, "ret = %x\n", ret
);
2041 ret
= p_tolower(0xD0);
2042 ok(ret
== 0xF0, "ret = %x\n", ret
);
2044 setlocale(LC_ALL
, "C");
2050 static const char xilstring
[]="c:/xilinx";
2053 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
2055 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
2056 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
2057 SET(pmemcpy
,"memcpy");
2058 SET(pmemcmp
,"memcmp");
2059 SET(p_mbctype
,"_mbctype");
2060 SET(p__mb_cur_max
,"__mb_cur_max");
2061 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
2062 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
2063 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
2064 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
2065 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
2066 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
2067 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
2068 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
2069 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
2070 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
2071 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
2072 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
2073 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
2074 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
2075 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
2076 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
2077 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
2078 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
2079 p_set_invalid_parameter_handler
= (void *) GetProcAddress(hMsvcrt
, "_set_invalid_parameter_handler");
2080 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
2081 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
2082 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
2083 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
2084 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
2086 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2087 MFC42 CString::Insert seems to rely on that behaviour */
2088 strcpy(mem
,xilstring
);
2089 nLen
=strlen(xilstring
);
2090 pmemcpy(mem
+5, mem
,nLen
+1);
2091 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
2092 "Got result %s\n",mem
+5);
2094 /* Test _swab function */