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_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
65 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
66 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
67 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
68 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
69 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
70 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
71 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
72 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
73 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
74 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
75 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
76 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
77 static int *p__mb_cur_max
;
78 static unsigned char *p_mbctype
;
79 static _invalid_parameter_handler (__cdecl
*p_set_invalid_parameter_handler
)(_invalid_parameter_handler
);
80 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
81 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
82 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
83 static int (__cdecl
*p_wctob
)(wint_t);
84 static int (__cdecl
*p_tolower
)(int);
86 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
87 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
89 static HMODULE hMsvcrt
;
91 static void test_swab( void ) {
92 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
93 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
94 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
95 char expected3
[] = "$";
102 /* Test 1 - normal even case */
103 memset(to
,'$', sizeof(to
));
104 memset(from
,'@', sizeof(from
));
106 memcpy(from
, original
, testsize
);
107 _swab( from
, to
, testsize
);
108 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
110 /* Test 2 - uneven case */
111 memset(to
,'$', sizeof(to
));
112 memset(from
,'@', sizeof(from
));
114 memcpy(from
, original
, testsize
);
115 _swab( from
, to
, testsize
);
116 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
118 /* Test 3 - from = to */
119 memset(to
,'$', sizeof(to
));
120 memset(from
,'@', sizeof(from
));
122 memcpy(to
, original
, testsize
);
123 _swab( to
, to
, testsize
);
124 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
126 /* Test 4 - 1 bytes */
127 memset(to
,'$', sizeof(to
));
128 memset(from
,'@', sizeof(from
));
130 memcpy(from
, original
, testsize
);
131 _swab( from
, to
, testsize
);
132 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
135 #if 0 /* use this to generate more tests */
137 static void test_codepage(int cp
)
143 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
146 printf("static int result_cp_%d_mbctype[] = { ", cp
);
147 for (i
= 1; i
< 257; i
++)
149 if (p_mbctype
[i
] != prev
)
151 printf("0x%x,%d, ", prev
, count
);
158 printf("0x%x,%d };\n", prev
, count
);
163 /* RLE-encoded mbctype tables for given codepages */
164 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
165 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
166 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
168 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
170 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
171 0x0,2, 0x4,32, 0xc,94, 0,1 };
173 static void test_cp_table(int cp
, int *result
)
179 for (i
= 0; i
< 256; i
++)
187 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
);
192 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
196 static void test_mbcp(void)
198 int mb_orig_max
= *p__mb_cur_max
;
199 int curr_mbcp
= _getmbcp();
200 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
201 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
202 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
203 unsigned char buf
[16];
209 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
210 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
211 * CP1252 (or the ACP?) so we test only a few ASCII characters */
213 expect_eq(p_mbctype
[10], 0, char, "%x");
214 expect_eq(p_mbctype
[50], 0, char, "%x");
215 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
216 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
217 expect_eq(p_mbctype
[128], 0, char, "%x");
219 expect_eq(p_mbctype
[10], 0, char, "%x");
220 expect_eq(p_mbctype
[50], 0, char, "%x");
221 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
222 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
223 expect_eq(p_mbctype
[128], 0, char, "%x");
225 /* double byte code pages */
232 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
);
233 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
234 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
235 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
236 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
237 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
238 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
241 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
242 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
243 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
244 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
245 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
246 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
247 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
248 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
249 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
251 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
252 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
253 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
254 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
257 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
258 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
259 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
260 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
261 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
262 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
263 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
264 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
265 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
267 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
268 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
269 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
270 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
271 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
272 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
275 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
276 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
277 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
278 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
279 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
280 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
281 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
282 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
283 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
285 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
286 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
287 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
288 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
289 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
290 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
293 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
294 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
295 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
297 /* _mbclen/_mbslen */
298 expect_eq(_mbclen(mbstring
), 2, int, "%d");
299 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
300 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
301 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
302 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
303 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
305 /* _mbccpy/_mbsncpy */
306 memset(buf
, 0xff, sizeof(buf
));
307 _mbccpy(buf
, mbstring
);
308 expect_bin(buf
, "\xb0\xb1\xff", 3);
310 memset(buf
, 0xff, sizeof(buf
));
311 _mbsncpy(buf
, mbstring
, 1);
312 expect_bin(buf
, "\xb0\xb1\xff", 3);
313 memset(buf
, 0xff, sizeof(buf
));
314 _mbsncpy(buf
, mbstring
, 2);
315 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
316 memset(buf
, 0xff, sizeof(buf
));
317 _mbsncpy(buf
, mbstring
, 3);
318 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
319 memset(buf
, 0xff, sizeof(buf
));
320 _mbsncpy(buf
, mbstring
, 4);
321 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
322 memset(buf
, 0xff, sizeof(buf
));
323 _mbsncpy(buf
, mbstring
, 5);
324 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
325 memset(buf
, 0xff, sizeof(buf
));
326 _mbsncpy(buf
, mbsonlylead
, 6);
327 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
329 memset(buf
, 0xff, sizeof(buf
));
330 _mbsnbcpy(buf
, mbstring2
, 2);
331 expect_bin(buf
, "\xb0\xb1\xff", 3);
332 _mbsnbcpy(buf
, mbstring2
, 3);
333 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
334 _mbsnbcpy(buf
, mbstring2
, 4);
335 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
336 memset(buf
, 0xff, sizeof(buf
));
337 _mbsnbcpy(buf
, mbsonlylead
, 5);
338 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
341 step
= _mbsinc(mbstring
) - mbstring
;
342 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
343 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
344 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
346 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
347 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
348 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
349 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
350 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
351 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
352 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
353 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
354 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
355 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
356 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
357 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
358 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
359 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
360 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
361 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
362 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
363 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
365 /* functions that depend on locale codepage, not mbcp.
366 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
367 * (as of Wine 0.9.43)
369 GetCPInfo(GetACP(), &cp_info
);
370 if (cp_info
.MaxCharSize
== 1)
372 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
373 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
376 skip("Current locale has double-byte charset - could lead to false positives\n");
379 expect_eq(_ismbblead(0x80), 0, int, "%d");
381 expect_eq(_ismbblead(0x81), 1, int, "%d");
382 expect_eq(_ismbblead(0x83), 1, int, "%d");
384 expect_eq(_ismbblead(0x84), 1, int, "%d");
385 expect_eq(_ismbblead(0xd3), 1, int, "%d");
386 expect_eq(_ismbblead(0xd7), 0, int, "%d");
388 expect_eq(_ismbblead(0xd8), 1, int, "%d");
390 expect_eq(_ismbblead(0xd9), 1, int, "%d");
392 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
393 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
394 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
395 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
396 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
397 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
398 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
399 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
404 static void test_mbsspn( void)
406 unsigned char str1
[]="cabernet";
407 unsigned char str2
[]="shiraz";
408 unsigned char set
[]="abc";
409 unsigned char empty
[]="";
411 ret
=_mbsspn( str1
, set
);
412 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
413 ret
=_mbsspn( str2
, set
);
414 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
415 ret
=_mbsspn( str1
, empty
);
416 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
419 static void test_mbsspnp( void)
421 unsigned char str1
[]="cabernet";
422 unsigned char str2
[]="shiraz";
423 unsigned char set
[]="abc";
424 unsigned char empty
[]="";
425 unsigned char full
[]="abcenrt";
427 ret
=_mbsspnp( str1
, set
);
428 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
429 ret
=_mbsspnp( str2
, set
);
430 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
431 ret
=_mbsspnp( str1
, empty
);
432 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
433 ret
=_mbsspnp( str1
, full
);
434 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
437 static void test_strdup(void)
441 ok( str
== 0, "strdup returns %s should be 0\n", str
);
445 static void test_strcpy_s(void)
448 const char *small
= "small";
449 const char *big
= "atoolongstringforthislittledestination";
454 skip("strcpy_s not found\n");
458 memset(dest
, 'X', sizeof(dest
));
459 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
460 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
461 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
462 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
463 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
464 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
466 memset(dest
, 'X', sizeof(dest
));
467 ret
= pstrcpy_s(dest
, 0, big
);
468 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
469 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
470 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
471 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
472 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
473 ret
= pstrcpy_s(dest
, 0, NULL
);
474 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
475 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
476 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
477 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
478 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
480 memset(dest
, 'X', sizeof(dest
));
481 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
482 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
483 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
484 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
485 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
486 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
488 memset(dest
, 'X', sizeof(dest
));
489 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
490 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
491 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
492 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
493 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
494 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
496 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
497 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
500 static void test_strcat_s(void)
503 const char *small
= "sma";
508 skip("strcat_s not found\n");
512 memset(dest
, 'X', sizeof(dest
));
514 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
515 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
516 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
517 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
518 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
519 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
520 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
521 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
522 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
523 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
524 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
525 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
527 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
528 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
529 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
530 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
531 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
532 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
534 memset(dest
, 'X', sizeof(dest
));
538 ret
= pstrcat_s(dest
, 0, small
);
539 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
540 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
541 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
542 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
543 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
545 ret
= pstrcat_s(dest
, 0, NULL
);
546 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
547 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
548 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
549 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
550 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
552 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
553 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
554 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
555 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
556 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
557 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
559 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
560 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
563 static void test__mbsnbcpy_s(void)
565 unsigned char dest
[8];
566 const unsigned char big
[] = "atoolongstringforthislittledestination";
567 const unsigned char small
[] = "small";
572 skip("_mbsnbcpy_s not found\n");
576 memset(dest
, 'X', sizeof(dest
));
577 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
578 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
579 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
580 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
581 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
582 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
585 memset(dest
, 'X', sizeof(dest
));
586 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
587 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
588 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
589 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
590 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
591 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
593 memset(dest
, 'X', sizeof(dest
));
594 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
595 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
596 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
597 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
598 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
599 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
601 memset(dest
, 'X', sizeof(dest
));
602 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
603 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
604 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
605 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
606 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
607 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
610 static void test_wcscpy_s(void)
612 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
613 static WCHAR szDest
[18];
614 static WCHAR szDestShort
[8];
619 win_skip("wcscpy_s not found\n");
624 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
625 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
627 /* Test NULL Source */
629 ret
= p_wcscpy_s(szDest
, 18, NULL
);
630 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
631 ok(szDest
[0] == 0, "szDest[0] not 0\n");
633 /* Test invalid size */
635 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
636 /* Later versions changed the return value for this case to EINVAL,
637 * and don't modify the result if the dest size is 0.
639 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
640 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
642 /* Copy same buffer size */
643 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
644 ok(ret
== 0, "expected 0 got %d\n", ret
);
645 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
647 /* Copy smaller buffer size */
649 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
650 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
651 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
655 win_skip("wcsncpy_s not found\n");
659 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
660 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
663 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
664 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
665 ok(szDest
[0] == 0, "szDest[0] not 0\n");
668 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
669 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
670 ok(szDest
[0] == 0, "szDest[0] not 0\n");
673 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
674 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
675 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
677 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
678 ok(ret
== 0, "expected 0 got %d\n", ret
);
679 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
682 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
683 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
684 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
687 static void test__wcsupr_s(void)
689 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
690 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
691 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
692 'W', 'E', 'R', 'U', 'P', 'P', 'E',
694 WCHAR testBuffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
699 win_skip("_wcsupr_s not found\n");
703 /* Test NULL input string and invalid size. */
705 ret
= p_wcsupr_s(NULL
, 0);
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
);
709 /* Test NULL input string and valid size. */
711 ret
= p_wcsupr_s(NULL
, sizeof(testBuffer
)/sizeof(WCHAR
));
712 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
713 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
715 /* Test empty string with zero size. */
717 testBuffer
[0] = '\0';
718 ret
= p_wcsupr_s(testBuffer
, 0);
719 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
720 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
721 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
723 /* Test empty string with size of one. */
724 testBuffer
[0] = '\0';
725 ret
= p_wcsupr_s(testBuffer
, 1);
726 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
727 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
729 /* Test one-byte buffer with zero size. */
732 ret
= p_wcsupr_s(testBuffer
, 0);
733 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
734 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
735 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
737 /* Test one-byte buffer with size of one. */
740 ret
= p_wcsupr_s(testBuffer
, 1);
741 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
742 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
743 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
745 /* Test invalid size. */
746 wcscpy(testBuffer
, mixedString
);
748 ret
= p_wcsupr_s(testBuffer
, 0);
749 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
750 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
751 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
753 /* Test normal string uppercasing. */
754 wcscpy(testBuffer
, mixedString
);
755 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
));
756 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
757 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
759 /* Test uppercasing with a shorter buffer size count. */
760 wcscpy(testBuffer
, mixedString
);
762 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
763 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
764 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
765 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
767 /* Test uppercasing with a longer buffer size count. */
768 wcscpy(testBuffer
, mixedString
);
769 ret
= p_wcsupr_s(testBuffer
, sizeof(testBuffer
)/sizeof(WCHAR
));
770 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
771 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
774 static void test__wcslwr_s(void)
776 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
777 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
778 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
779 'w', 'e', 'r', 'u', 'p', 'p', 'e',
781 WCHAR buffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
786 win_skip("_wcslwr_s not found\n");
790 /* Test NULL input string and invalid size. */
792 ret
= p_wcslwr_s(NULL
, 0);
793 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
794 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
796 /* Test NULL input string and valid size. */
798 ret
= p_wcslwr_s(NULL
, sizeof(buffer
)/sizeof(wchar_t));
799 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
800 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
802 /* Test empty string with zero size. */
805 ret
= p_wcslwr_s(buffer
, 0);
806 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
807 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
808 ok(buffer
[0] == 0, "expected empty string\n");
810 /* Test empty string with size of one. */
812 ret
= p_wcslwr_s(buffer
, 1);
813 ok(ret
== 0, "got %d\n", ret
);
814 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
816 /* Test one-byte buffer with zero size. */
819 ret
= p_wcslwr_s(buffer
, 0);
820 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
821 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
822 ok(buffer
[0] == '\0', "expected empty string\n");
824 /* Test one-byte buffer with size of one. */
827 ret
= p_wcslwr_s(buffer
, 1);
828 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
829 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
830 ok(buffer
[0] == '\0', "expected empty string\n");
832 /* Test invalid size. */
833 wcscpy(buffer
, mixedString
);
835 ret
= p_wcslwr_s(buffer
, 0);
836 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
837 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
838 ok(buffer
[0] == '\0', "expected empty string\n");
840 /* Test normal string uppercasing. */
841 wcscpy(buffer
, mixedString
);
842 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
));
843 ok(ret
== 0, "expected 0, got %d\n", ret
);
844 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
846 /* Test uppercasing with a shorter buffer size count. */
847 wcscpy(buffer
, mixedString
);
849 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
850 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
851 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
852 ok(buffer
[0] == '\0', "expected empty string\n");
854 /* Test uppercasing with a longer buffer size count. */
855 wcscpy(buffer
, mixedString
);
856 ret
= p_wcslwr_s(buffer
, sizeof(buffer
)/sizeof(WCHAR
));
857 ok(ret
== 0, "expected 0, got %d\n", ret
);
858 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
861 static void test_mbcjisjms(void)
863 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
864 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
865 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
866 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
867 unsigned int ret
, exp
, i
;
872 ret
= _mbcjistojms(jisjms
[i
][0]);
874 if(_getmbcp() == 932) /* Japanese codepage? */
877 exp
= jisjms
[i
][0]; /* If not, no conversion */
879 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
880 } while(jisjms
[i
++][0] != 0);
883 static void test_mbctombb(void)
885 static const unsigned int mbcmbb_932
[][2] = {
886 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
887 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
888 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
889 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
890 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
891 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
892 unsigned int exp
, ret
, i
;
893 unsigned int prev_cp
= _getmbcp();
896 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
898 ret
= _mbctombb(mbcmbb_932
[i
][0]);
899 exp
= mbcmbb_932
[i
][1];
900 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
905 static void test_ismbclegal(void) {
906 unsigned int prev_cp
= _getmbcp();
910 _setmbcp(932); /* Japanese */
912 for(i
= 0; i
< 0x10000; i
++) {
913 ret
= _ismbclegal(i
);
914 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
915 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
916 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
917 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
923 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
924 _setmbcp(936); /* Chinese (GBK) */
926 for(i
= 0; i
< 0x10000; i
++) {
927 ret
= _ismbclegal(i
);
928 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
929 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
935 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
936 _setmbcp(949); /* Korean */
938 for(i
= 0; i
< 0x10000; i
++) {
939 ret
= _ismbclegal(i
);
940 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
941 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
947 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
948 _setmbcp(950); /* Chinese (Big5) */
950 for(i
= 0; i
< 0x10000; i
++) {
951 ret
= _ismbclegal(i
);
952 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
953 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
954 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
960 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
961 _setmbcp(1361); /* Korean (Johab) */
963 for(i
= 0; i
< 0x10000; i
++) {
964 ret
= _ismbclegal(i
);
965 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
966 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
967 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
968 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
975 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
980 static const struct {
982 const char* delimiter
;
983 int exp_offsetret1
; /* returned offset from string after first call to strtok()
985 int exp_offsetret2
; /* returned offset from string after second call to strtok()
987 int exp_offsetret3
; /* returned offset from string after third call to strtok()
989 } testcases_strtok
[] = {
990 { "red cabernet", " ", 0, 4, -1 },
991 { "sparkling white riesling", " ", 0, 10, 16 },
992 { " pale cream sherry", "e ", 1, 6, 9 },
997 static void test_strtok(void)
1002 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1003 strcpy( teststr
, testcases_strtok
[i
].string
);
1004 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1005 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1006 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1007 "string (%p) \'%s\' return %p\n",
1008 teststr
, testcases_strtok
[i
].string
, strret
);
1009 if( !strret
) continue;
1010 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1011 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1012 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1013 "second call string (%p) \'%s\' return %p\n",
1014 teststr
, testcases_strtok
[i
].string
, strret
);
1015 if( !strret
) continue;
1016 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1017 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1018 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1019 "third call string (%p) \'%s\' return %p\n",
1020 teststr
, testcases_strtok
[i
].string
, strret
);
1024 static void test_strtol(void)
1030 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1031 /* errno is modified on W2K8+ */
1033 l
= strtol("-1234", &e
, 0);
1034 ok(l
==-1234, "wrong value %d\n", l
);
1035 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1037 ul
= strtoul("1234", &e
, 0);
1038 ok(ul
==1234, "wrong value %u\n", ul
);
1039 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1042 l
= strtol("2147483647L", &e
, 0);
1043 ok(l
==2147483647, "wrong value %d\n", l
);
1044 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1046 l
= strtol("-2147483648L", &e
, 0);
1047 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1048 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1050 ul
= strtoul("4294967295UL", &e
, 0);
1051 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1052 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1055 l
= strtol("9223372036854775807L", &e
, 0);
1056 ok(l
==2147483647, "wrong value %d\n", l
);
1057 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1059 ul
= strtoul("9223372036854775807L", &e
, 0);
1060 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1061 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1064 static void test_strnlen(void)
1066 static const char str
[] = "string";
1070 win_skip("strnlen not found\n");
1074 res
= p_strnlen(str
, 20);
1075 ok(res
== 6, "Returned length = %d\n", (int)res
);
1077 res
= p_strnlen(str
, 3);
1078 ok(res
== 3, "Returned length = %d\n", (int)res
);
1080 res
= p_strnlen(NULL
, 0);
1081 ok(res
== 0, "Returned length = %d\n", (int)res
);
1084 static void test__strtoi64(void)
1086 static const char no1
[] = "31923";
1087 static const char no2
[] = "-213312";
1088 static const char no3
[] = "12aa";
1089 static const char no4
[] = "abc12";
1090 static const char overflow
[] = "99999999999999999999";
1091 static const char neg_overflow
[] = "-99999999999999999999";
1092 static const char hex
[] = "0x123";
1093 static const char oct
[] = "000123";
1094 static const char blanks
[] = " 12 212.31";
1097 unsigned __int64 ures
;
1100 if(!p_strtoi64
|| !p_strtoui64
) {
1101 win_skip("_strtoi64 or _strtoui64 not found\n");
1106 res
= p_strtoi64(no1
, NULL
, 10);
1107 ok(res
== 31923, "res != 31923\n");
1108 res
= p_strtoi64(no2
, NULL
, 10);
1109 ok(res
== -213312, "res != -213312\n");
1110 res
= p_strtoi64(no3
, NULL
, 10);
1111 ok(res
== 12, "res != 12\n");
1112 res
= p_strtoi64(no4
, &endpos
, 10);
1113 ok(res
== 0, "res != 0\n");
1114 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1115 res
= p_strtoi64(hex
, &endpos
, 10);
1116 ok(res
== 0, "res != 0\n");
1117 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1118 res
= p_strtoi64(oct
, &endpos
, 10);
1119 ok(res
== 123, "res != 123\n");
1120 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1121 res
= p_strtoi64(blanks
, &endpos
, 10);
1122 ok(res
== 12, "res != 12\n");
1123 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1124 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1127 res
= p_strtoi64(overflow
, &endpos
, 10);
1128 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1129 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1130 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1133 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1134 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1135 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1136 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1139 res
= p_strtoi64(no1
, &endpos
, 16);
1140 ok(res
== 203043, "res != 203043\n");
1141 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1142 res
= p_strtoi64(no2
, &endpos
, 16);
1143 ok(res
== -2175762, "res != -2175762\n");
1144 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1145 res
= p_strtoi64(no3
, &endpos
, 16);
1146 ok(res
== 4778, "res != 4778\n");
1147 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1148 res
= p_strtoi64(no4
, &endpos
, 16);
1149 ok(res
== 703506, "res != 703506\n");
1150 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1151 res
= p_strtoi64(hex
, &endpos
, 16);
1152 ok(res
== 291, "res != 291\n");
1153 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1154 res
= p_strtoi64(oct
, &endpos
, 16);
1155 ok(res
== 291, "res != 291\n");
1156 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1157 res
= p_strtoi64(blanks
, &endpos
, 16);
1158 ok(res
== 18, "res != 18\n");
1159 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1160 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1163 res
= p_strtoi64(hex
, &endpos
, 36);
1164 ok(res
== 1541019, "res != 1541019\n");
1165 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1166 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1169 res
= p_strtoi64(no1
, &endpos
, 0);
1170 ok(res
== 31923, "res != 31923\n");
1171 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1172 res
= p_strtoi64(no2
, &endpos
, 0);
1173 ok(res
== -213312, "res != -213312\n");
1174 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1175 res
= p_strtoi64(no3
, &endpos
, 10);
1176 ok(res
== 12, "res != 12\n");
1177 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1178 res
= p_strtoi64(no4
, &endpos
, 10);
1179 ok(res
== 0, "res != 0\n");
1180 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1181 res
= p_strtoi64(hex
, &endpos
, 10);
1182 ok(res
== 0, "res != 0\n");
1183 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1184 res
= p_strtoi64(oct
, &endpos
, 10);
1185 ok(res
== 123, "res != 123\n");
1186 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1187 res
= p_strtoi64(blanks
, &endpos
, 10);
1188 ok(res
== 12, "res != 12\n");
1189 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1190 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1193 ures
= p_strtoui64(no1
, &endpos
, 0);
1194 ok(ures
== 31923, "ures != 31923\n");
1195 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1196 ures
= p_strtoui64(no2
, &endpos
, 0);
1197 ok(ures
== -213312, "ures != -213312\n");
1198 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1199 ures
= p_strtoui64(no3
, &endpos
, 10);
1200 ok(ures
== 12, "ures != 12\n");
1201 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1202 ures
= p_strtoui64(no4
, &endpos
, 10);
1203 ok(ures
== 0, "ures != 0\n");
1204 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1205 ures
= p_strtoui64(hex
, &endpos
, 10);
1206 ok(ures
== 0, "ures != 0\n");
1207 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1208 ures
= p_strtoui64(oct
, &endpos
, 10);
1209 ok(ures
== 123, "ures != 123\n");
1210 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1211 ures
= p_strtoui64(blanks
, &endpos
, 10);
1212 ok(ures
== 12, "ures != 12\n");
1213 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1214 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1217 ures
= p_strtoui64(overflow
, &endpos
, 10);
1218 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1219 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1220 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1223 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1224 ok(ures
== 1, "ures != 1\n");
1225 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1226 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1229 static inline BOOL
almost_equal(double d1
, double d2
) {
1230 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1235 static void test__strtod(void)
1237 const char double1
[] = "12.1";
1238 const char double2
[] = "-13.721";
1239 const char double3
[] = "INF";
1240 const char double4
[] = ".21e12";
1241 const char double5
[] = "214353e-3";
1242 const char overflow
[] = "1d9999999999999999999";
1243 const char white_chars
[] = " d10";
1248 d
= strtod(double1
, &end
);
1249 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1250 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1252 d
= strtod(double2
, &end
);
1253 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1254 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1256 d
= strtod(double3
, &end
);
1257 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1258 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1260 d
= strtod(double4
, &end
);
1261 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1262 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1264 d
= strtod(double5
, &end
);
1265 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1266 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1268 d
= strtod("12.1d2", NULL
);
1269 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1271 d
= strtod(white_chars
, &end
);
1272 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1273 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1275 /* Set locale with non '.' decimal point (',') */
1276 if(!setlocale(LC_ALL
, "Polish")) {
1277 win_skip("system with limited locales\n");
1281 d
= strtod("12.1", NULL
);
1282 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1284 d
= strtod("12,1", NULL
);
1285 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1287 setlocale(LC_ALL
, "C");
1289 /* Precision tests */
1290 d
= strtod("0.1", NULL
);
1291 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1292 d
= strtod("-0.1", NULL
);
1293 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1294 d
= strtod("0.1281832188491894198128921", NULL
);
1295 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1296 d
= strtod("0.82181281288121", NULL
);
1297 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1298 d
= strtod("21921922352523587651128218821", NULL
);
1299 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1300 d
= strtod("0.1d238", NULL
);
1301 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1302 d
= strtod("0.1D-4736", NULL
);
1303 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1306 strtod(overflow
, &end
);
1307 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1308 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1311 strtod("-1d309", NULL
);
1312 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1315 static void test_mbstowcs(void)
1317 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1318 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1319 static const char mSimple
[] = "text";
1320 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1322 const wchar_t *pwstr
;
1328 wOut
[4] = '!'; wOut
[5] = '\0';
1329 mOut
[4] = '!'; mOut
[5] = '\0';
1331 ret
= mbstowcs(NULL
, mSimple
, 0);
1332 ok(ret
== 4, "mbstowcs did not return 4\n");
1334 ret
= mbstowcs(wOut
, mSimple
, 4);
1335 ok(ret
== 4, "mbstowcs did not return 4\n");
1336 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1337 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1339 ret
= wcstombs(NULL
, wSimple
, 0);
1340 ok(ret
== 4, "wcstombs did not return 4\n");
1342 ret
= wcstombs(mOut
, wSimple
, 6);
1343 ok(ret
== 4, "wcstombs did not return 4\n");
1344 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1346 ret
= wcstombs(mOut
, wSimple
, 2);
1347 ok(ret
== 2, "wcstombs did not return 2\n");
1348 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1350 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
1351 win_skip("Japanese_Japan.932 locale not available\n");
1355 ret
= mbstowcs(wOut
, mHiragana
, 6);
1356 ok(ret
== 2, "mbstowcs did not return 2\n");
1357 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1359 ret
= wcstombs(mOut
, wHiragana
, 6);
1360 ok(ret
== 4, "wcstombs did not return 4\n");
1361 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1363 if(!pmbstowcs_s
|| !pwcstombs_s
) {
1364 setlocale(LC_ALL
, "C");
1365 win_skip("mbstowcs_s or wcstombs_s not available\n");
1369 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
1370 ok(err
== 0, "err = %d\n", err
);
1371 ok(ret
== 5, "mbstowcs_s did not return 5\n");
1372 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1374 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
1375 ok(err
== 0, "err = %d\n", err
);
1376 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1377 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1379 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
1380 ok(err
== 0, "err = %d\n", err
);
1381 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1383 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
1384 ok(err
== 0, "err = %d\n", err
);
1385 ok(ret
== 5, "wcstombs_s did not return 5\n");
1386 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1388 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
1389 ok(err
== 0, "err = %d\n", err
);
1390 ok(ret
== 5, "wcstombs_s did not return 5\n");
1391 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1393 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
1394 ok(err
== 0, "err = %d\n", err
);
1395 ok(ret
== 5, "wcstombs_s did not return 5\n");
1398 setlocale(LC_ALL
, "C");
1399 win_skip("wcsrtombs not available\n");
1405 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
1406 ok(ret
== 4, "wcsrtombs did not return 4\n");
1407 ok(err
== 0, "err = %d\n", err
);
1408 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
1409 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
1412 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
1413 ok(ret
== 4, "wcsrtombs did not return 4\n");
1414 ok(pwstr
== NULL
, "pwstr != NULL\n");
1415 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1417 setlocale(LC_ALL
, "C");
1420 static void test_gcvt(void)
1422 char buf
[1024], *res
;
1426 win_skip("Skipping _gcvt tests\n");
1431 res
= _gcvt(1.2, -1, buf
);
1432 ok(res
== NULL
, "res != NULL\n");
1433 ok(errno
== ERANGE
, "errno = %d\n", errno
);
1436 res
= _gcvt(1.2, 5, NULL
);
1437 ok(res
== NULL
, "res != NULL\n");
1438 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1440 res
= gcvt(1.2, 5, buf
);
1441 ok(res
== buf
, "res != buf\n");
1442 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
1445 err
= p_gcvt_s(buf
, 5, 1.2, 10);
1446 ok(err
== ERANGE
, "err = %d\n", err
);
1447 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1450 err
= p_gcvt_s(buf
, 4, 123456, 2);
1451 ok(err
== ERANGE
, "err = %d\n", err
);
1452 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1455 static void test__itoa_s(void)
1462 win_skip("Skipping _itoa_s tests\n");
1466 if (p_set_invalid_parameter_handler
)
1467 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1468 "Invalid parameter handler was already set\n");
1471 ret
= p_itoa_s(0, NULL
, 0, 0);
1472 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1473 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1475 memset(buffer
, 'X', sizeof(buffer
));
1477 ret
= p_itoa_s(0, buffer
, 0, 0);
1478 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1479 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1480 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
1482 memset(buffer
, 'X', sizeof(buffer
));
1484 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
1485 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1486 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1487 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1489 memset(buffer
, 'X', sizeof(buffer
));
1491 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
1492 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1493 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1494 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1496 memset(buffer
, 'X', sizeof(buffer
));
1498 ret
= p_itoa_s(12345678, buffer
, 4, 10);
1499 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1500 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1501 ok(!memcmp(buffer
, "\000765", 4),
1502 "Expected the output buffer to be null terminated with truncated output\n");
1504 memset(buffer
, 'X', sizeof(buffer
));
1506 ret
= p_itoa_s(12345678, buffer
, 8, 10);
1507 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1508 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1509 ok(!memcmp(buffer
, "\0007654321", 8),
1510 "Expected the output buffer to be null terminated with truncated output\n");
1512 memset(buffer
, 'X', sizeof(buffer
));
1514 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
1515 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1516 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1517 ok(!memcmp(buffer
, "\00087654321", 9),
1518 "Expected the output buffer to be null terminated with truncated output\n");
1520 ret
= p_itoa_s(12345678, buffer
, 9, 10);
1521 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1522 ok(!strcmp(buffer
, "12345678"),
1523 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1526 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
1527 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1528 ok(!strcmp(buffer
, "1010101010101010"),
1529 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1532 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
1533 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1534 ok(!strcmp(buffer
, "nell"),
1535 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1538 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
1539 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1540 ok(!strcmp(buffer
, "hag"),
1541 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1544 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
1545 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1546 ok(!strcmp(buffer
, "-12345678"),
1547 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1549 if (p_set_invalid_parameter_handler
)
1550 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
1551 "Cannot reset invalid parameter handler\n");
1554 static void test__strlwr_s(void)
1561 win_skip("Skipping _strlwr_s tests\n");
1566 ret
= p_strlwr_s(NULL
, 0);
1567 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1568 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1571 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
1572 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1573 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1576 ret
= p_strlwr_s(buffer
, 0);
1577 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1578 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1580 strcpy(buffer
, "GoRrIsTeR");
1582 ret
= p_strlwr_s(buffer
, 5);
1583 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1584 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1585 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1586 "Expected the output buffer to be \"gorrIsTeR\"\n");
1588 strcpy(buffer
, "GoRrIsTeR");
1590 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
1591 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1592 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1593 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1594 "Expected the output buffer to be \"gorrIsTeR\"\n");
1596 strcpy(buffer
, "GoRrIsTeR");
1597 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
1598 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1599 ok(!strcmp(buffer
, "gorrister"),
1600 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1603 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1604 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
1605 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1606 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1607 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1611 static void test_wcsncat_s(void)
1613 static wchar_t abcW
[] = {'a','b','c',0};
1620 win_skip("skipping wcsncat_s tests\n");
1624 if (p_set_invalid_parameter_handler
)
1625 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1626 "Invalid parameter handler was already set\n");
1628 memcpy(src
, abcW
, sizeof(abcW
));
1630 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
1631 ok(ret
== EINVAL
, "err = %d\n", ret
);
1632 ret
= p_wcsncat_s(dst
, 0, src
, 4);
1633 ok(ret
== EINVAL
, "err = %d\n", ret
);
1634 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
1635 ok(ret
== EINVAL
, "err = %d\n", ret
);
1636 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
1637 ok(ret
== 0, "err = %d\n", ret
);
1640 ret
= p_wcsncat_s(dst
, 2, src
, 4);
1641 ok(ret
== ERANGE
, "err = %d\n", ret
);
1644 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
1645 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
1646 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
1648 memcpy(dst
, abcW
, sizeof(abcW
));
1650 ret
= p_wcsncat_s(dst
, 4, src
, 4);
1651 ok(ret
== EINVAL
, "err = %d\n", ret
);
1653 if (p_set_invalid_parameter_handler
)
1654 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
1655 "Cannot reset invalid parameter handler\n");
1658 static void test__mbsnbcat_s(void)
1660 unsigned char dest
[16];
1661 const unsigned char first
[] = "dinosaur";
1662 const unsigned char second
[] = "duck";
1667 win_skip("Skipping _mbsnbcat_s tests\n");
1671 /* Test invalid arguments. */
1672 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
1673 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1676 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
1677 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1678 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1681 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
1682 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1683 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1685 memset(dest
, 'X', sizeof(dest
));
1687 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
1688 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1689 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1690 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
1692 memset(dest
, 'X', sizeof(dest
));
1694 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
1695 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1696 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1697 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
1699 memset(dest
, 'X', sizeof(dest
));
1701 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
1702 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1703 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1704 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
1706 memset(dest
, 'X', sizeof(dest
));
1708 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
1709 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1710 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1711 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
1713 memset(dest
, 'X', sizeof(dest
));
1715 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
1716 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1717 ok(!memcmp(dest
, second
, sizeof(second
)),
1718 "Expected the output buffer string to be \"duck\"\n");
1720 /* Test source truncation behavior. */
1721 memset(dest
, 'X', sizeof(dest
));
1722 memcpy(dest
, first
, sizeof(first
));
1723 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
1724 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1725 ok(!memcmp(dest
, first
, sizeof(first
)),
1726 "Expected the output buffer string to be \"dinosaur\"\n");
1728 memset(dest
, 'X', sizeof(dest
));
1729 memcpy(dest
, first
, sizeof(first
));
1730 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
1731 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1732 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
1733 "Expected the output buffer string to be \"dinosaurduck\"\n");
1735 memset(dest
, 'X', sizeof(dest
));
1736 memcpy(dest
, first
, sizeof(first
));
1737 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
1738 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1739 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
1740 "Expected the output buffer string to be \"dinosaurduck\"\n");
1742 memset(dest
, 'X', sizeof(dest
));
1743 memcpy(dest
, first
, sizeof(first
));
1744 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
1745 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1746 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
1747 "Expected the output buffer string to be \"dinosaurduck\"\n");
1749 memset(dest
, 'X', sizeof(dest
));
1750 memcpy(dest
, first
, sizeof(first
));
1751 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
1752 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
1753 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
1754 "Expected the output buffer string to be \"dinosaurduc\"\n");
1756 /* Test destination truncation behavior. */
1757 memset(dest
, 'X', sizeof(dest
));
1758 memcpy(dest
, first
, sizeof(first
));
1760 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
1761 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
1762 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1763 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
1764 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
1766 memset(dest
, 'X', sizeof(dest
));
1767 memcpy(dest
, first
, sizeof(first
));
1769 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
1770 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
1771 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1772 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
1773 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
1775 memset(dest
, 'X', sizeof(dest
));
1776 memcpy(dest
, first
, sizeof(first
));
1778 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
1779 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
1780 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1781 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
1782 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
1785 static void test__mbsupr_s(void)
1788 unsigned char buffer
[20];
1792 win_skip("Skipping _mbsupr_s tests\n");
1797 ret
= p_mbsupr_s(NULL
, 0);
1798 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1801 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
1802 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
1803 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1806 ret
= p_mbsupr_s(buffer
, 0);
1807 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
1808 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1810 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
1812 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
1813 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1814 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
1815 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
1818 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
1820 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
1821 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1822 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
1823 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
1826 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
1828 ret
= p_mbsupr_s(buffer
, 4);
1829 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
1830 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1832 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
1834 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
1835 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
1836 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
1837 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
1842 static void test__mbslwr_s(void)
1845 unsigned char buffer
[20];
1849 win_skip("Skipping _mbslwr_s tests\n");
1854 ret
= p_mbslwr_s(NULL
, 0);
1855 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1858 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
1859 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
1860 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1863 ret
= p_mbslwr_s(buffer
, 0);
1864 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
1865 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1867 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
1869 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
1870 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1871 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
1872 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
1875 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
1877 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
1878 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1879 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
1880 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
1883 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
1885 ret
= p_mbslwr_s(buffer
, 4);
1886 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
1887 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1889 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
1891 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
1892 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
1893 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
1894 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
1898 static void test__ultoa_s(void)
1905 win_skip("Skipping _ultoa_s tests\n");
1910 ret
= p_ultoa_s(0, NULL
, 0, 0);
1911 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1912 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1914 memset(buffer
, 'X', sizeof(buffer
));
1916 ret
= p_ultoa_s(0, buffer
, 0, 0);
1917 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1918 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1919 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
1921 memset(buffer
, 'X', sizeof(buffer
));
1923 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
1924 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1925 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1926 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1928 memset(buffer
, 'X', sizeof(buffer
));
1930 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
1931 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
1932 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1933 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1935 memset(buffer
, 'X', sizeof(buffer
));
1937 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
1938 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
1939 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1940 ok(!memcmp(buffer
, "\000765", 4),
1941 "Expected the output buffer to be null terminated with truncated output\n");
1943 memset(buffer
, 'X', sizeof(buffer
));
1945 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
1946 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
1947 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1948 ok(!memcmp(buffer
, "\0007654321", 8),
1949 "Expected the output buffer to be null terminated with truncated output\n");
1951 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
1952 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1953 ok(!strcmp(buffer
, "12345678"),
1954 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1957 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
1958 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1959 ok(!strcmp(buffer
, "1010101010101010"),
1960 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1963 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
1964 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1965 ok(!strcmp(buffer
, "nell"),
1966 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1969 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
1970 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
1971 ok(!strcmp(buffer
, "hag"),
1972 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1976 static void test_wctob(void)
1980 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
1981 win_skip("Skipping wctob tests\n");
1985 ret
= p_wctob(0x8141);
1986 ok(ret
== EOF
, "ret = %x\n", ret
);
1988 ret
= p_wctob(0x81);
1989 ok(ret
== EOF
, "ret = %x\n", ret
);
1991 ret
= p_wctob(0xe0);
1992 ok(ret
== 0x61, "ret = %x\n", ret
);
1995 ret
= p_wctob(0x81);
1996 ok(ret
== EOF
, "ret = %x\n", ret
);
1998 setlocale(LC_ALL
, "C");
1999 ret
= p_wctob(0x8141);
2000 ok(ret
== EOF
, "ret = %x\n", ret
);
2002 ret
= p_wctob(0x81);
2003 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2005 ret
= p_wctob(0xe0);
2006 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2009 static void test_tolower(void)
2013 ret
= p_tolower(0x41);
2014 ok(ret
== 0x61, "ret = %x\n", ret
);
2016 ret
= p_tolower(0xF4);
2017 ok(ret
== 0xF4, "ret = %x\n", ret
);
2019 ret
= p_tolower((char)0xF4);
2020 ok(ret
==0xF4/*Vista+*/ || ret
==(char)0xF4, "ret = %x\n", ret
);
2022 /* is it using different locale (CP_ACP) for negative values?? */
2023 /* current implementation matches msvcr90 behaviour */
2024 ret
= p_tolower((char)0xD0);
2025 todo_wine
ok(ret
==0xF0/*Vista+*/ || ret
==(char)0xD0, "ret = %x\n", ret
);
2027 ret
= p_tolower(0xD0);
2028 ok(ret
== 0xD0, "ret = %x\n", ret
);
2030 if(!setlocale(LC_ALL
, "us")) {
2031 win_skip("skipping tolower tests that depends on locale\n");
2035 ret
= p_tolower((char)0xD0);
2036 ok(ret
== 0xF0, "ret = %x\n", ret
);
2038 ret
= p_tolower(0xD0);
2039 ok(ret
== 0xF0, "ret = %x\n", ret
);
2041 setlocale(LC_ALL
, "C");
2047 static const char xilstring
[]="c:/xilinx";
2050 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
2052 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
2053 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
2054 SET(pmemcpy
,"memcpy");
2055 SET(pmemcmp
,"memcmp");
2056 SET(p_mbctype
,"_mbctype");
2057 SET(p__mb_cur_max
,"__mb_cur_max");
2058 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
2059 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
2060 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
2061 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
2062 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
2063 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
2064 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
2065 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
2066 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
2067 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
2068 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
2069 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
2070 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
2071 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
2072 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
2073 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
2074 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
2075 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
2076 p_set_invalid_parameter_handler
= (void *) GetProcAddress(hMsvcrt
, "_set_invalid_parameter_handler");
2077 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
2078 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
2079 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
2080 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
2081 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
2083 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2084 MFC42 CString::Insert seems to rely on that behaviour */
2085 strcpy(mem
,xilstring
);
2086 nLen
=strlen(xilstring
);
2087 pmemcpy(mem
+5, mem
,nLen
+1);
2088 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
2089 "Got result %s\n",mem
+5);
2091 /* Test _swab function */