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 /* make it use a definition from string.h */
38 static char *buf_to_string(const unsigned char *bin
, int len
, int nr
)
40 static char buf
[2][1024];
44 for (i
= 0; i
< len
; i
++)
46 sprintf(w
, "%02x ", (unsigned char)bin
[i
]);
52 static void __cdecl
test_invalid_parameter_handler(const wchar_t *expression
,
53 const wchar_t *function
, const wchar_t *file
,
54 unsigned line
, uintptr_t arg
)
56 /* we just ignore handler calls */
59 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
60 #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)); }
62 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
63 static int (__cdecl
*p_memcpy_s
)(void *, size_t, const void *, size_t);
64 static int (__cdecl
*p_memmove_s
)(void *, size_t, const void *, size_t);
65 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
66 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
67 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
68 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
69 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
70 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
71 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
72 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
73 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
74 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
75 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
76 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
77 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
78 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
79 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
80 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
81 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
82 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
83 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
84 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
85 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
86 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
87 static int *p__mb_cur_max
;
88 static unsigned char *p_mbctype
;
89 static _invalid_parameter_handler (__cdecl
*p_set_invalid_parameter_handler
)(_invalid_parameter_handler
);
90 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
91 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
92 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
93 static int (__cdecl
*p_wctob
)(wint_t);
94 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
95 static int (__cdecl
*p_tolower
)(int);
96 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
97 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
98 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
100 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
101 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
103 static HMODULE hMsvcrt
;
105 static void test_swab( void ) {
106 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
107 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
108 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
109 char expected3
[] = "$";
116 /* Test 1 - normal even case */
117 memset(to
,'$', sizeof(to
));
118 memset(from
,'@', sizeof(from
));
120 memcpy(from
, original
, testsize
);
121 _swab( from
, to
, testsize
);
122 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
124 /* Test 2 - uneven case */
125 memset(to
,'$', sizeof(to
));
126 memset(from
,'@', sizeof(from
));
128 memcpy(from
, original
, testsize
);
129 _swab( from
, to
, testsize
);
130 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
132 /* Test 3 - from = to */
133 memset(to
,'$', sizeof(to
));
134 memset(from
,'@', sizeof(from
));
136 memcpy(to
, original
, testsize
);
137 _swab( to
, to
, testsize
);
138 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
140 /* Test 4 - 1 bytes */
141 memset(to
,'$', sizeof(to
));
142 memset(from
,'@', sizeof(from
));
144 memcpy(from
, original
, testsize
);
145 _swab( from
, to
, testsize
);
146 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
149 #if 0 /* use this to generate more tests */
151 static void test_codepage(int cp
)
157 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
160 printf("static int result_cp_%d_mbctype[] = { ", cp
);
161 for (i
= 1; i
< 257; i
++)
163 if (p_mbctype
[i
] != prev
)
165 printf("0x%x,%d, ", prev
, count
);
172 printf("0x%x,%d };\n", prev
, count
);
177 /* RLE-encoded mbctype tables for given codepages */
178 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
179 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
180 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
182 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
184 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
185 0x0,2, 0x4,32, 0xc,94, 0,1 };
187 static void test_cp_table(int cp
, int *result
)
193 for (i
= 0; i
< 256; i
++)
201 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
);
206 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
210 static void test_mbcp(void)
212 int mb_orig_max
= *p__mb_cur_max
;
213 int curr_mbcp
= _getmbcp();
214 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
215 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
216 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
217 unsigned char buf
[16];
223 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
224 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
225 * CP1252 (or the ACP?) so we test only a few ASCII characters */
227 expect_eq(p_mbctype
[10], 0, char, "%x");
228 expect_eq(p_mbctype
[50], 0, char, "%x");
229 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
230 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
231 expect_eq(p_mbctype
[128], 0, char, "%x");
233 expect_eq(p_mbctype
[10], 0, char, "%x");
234 expect_eq(p_mbctype
[50], 0, char, "%x");
235 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
236 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
237 expect_eq(p_mbctype
[128], 0, char, "%x");
239 /* double byte code pages */
246 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
);
247 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
248 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
249 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
250 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
251 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
252 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
255 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
256 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
257 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
258 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
259 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
260 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
261 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
262 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
263 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
265 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
266 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
267 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
268 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
271 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
272 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
273 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
274 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
275 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
276 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
277 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
278 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
279 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
281 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
282 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
283 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
284 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
285 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
286 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
289 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
290 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
291 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
292 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
293 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
294 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
295 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
296 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
297 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
299 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
300 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
301 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
302 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
303 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
304 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
307 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
308 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
309 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
311 /* _mbclen/_mbslen */
312 expect_eq(_mbclen(mbstring
), 2, int, "%d");
313 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
314 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
315 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
316 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
317 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
320 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
321 win_skip("mbrlen tests\n");
324 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
325 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
326 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
327 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
328 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
329 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
330 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
334 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
335 win_skip("mbrtowc tests\n");
339 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
340 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
341 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
342 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
343 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
344 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
345 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
346 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
347 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
348 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
349 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
350 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
351 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
352 ok(state
== 0, "incorrect state value (%x)\n", state
);
354 setlocale(LC_ALL
, "C");
356 /* _mbccpy/_mbsncpy */
357 memset(buf
, 0xff, sizeof(buf
));
358 _mbccpy(buf
, mbstring
);
359 expect_bin(buf
, "\xb0\xb1\xff", 3);
361 memset(buf
, 0xff, sizeof(buf
));
362 _mbsncpy(buf
, mbstring
, 1);
363 expect_bin(buf
, "\xb0\xb1\xff", 3);
364 memset(buf
, 0xff, sizeof(buf
));
365 _mbsncpy(buf
, mbstring
, 2);
366 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
367 memset(buf
, 0xff, sizeof(buf
));
368 _mbsncpy(buf
, mbstring
, 3);
369 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
370 memset(buf
, 0xff, sizeof(buf
));
371 _mbsncpy(buf
, mbstring
, 4);
372 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
373 memset(buf
, 0xff, sizeof(buf
));
374 _mbsncpy(buf
, mbstring
, 5);
375 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
376 memset(buf
, 0xff, sizeof(buf
));
377 _mbsncpy(buf
, mbsonlylead
, 6);
378 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
380 memset(buf
, 0xff, sizeof(buf
));
381 _mbsnbcpy(buf
, mbstring2
, 2);
382 expect_bin(buf
, "\xb0\xb1\xff", 3);
383 _mbsnbcpy(buf
, mbstring2
, 3);
384 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
385 _mbsnbcpy(buf
, mbstring2
, 4);
386 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
387 memset(buf
, 0xff, sizeof(buf
));
388 _mbsnbcpy(buf
, mbsonlylead
, 5);
389 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
392 step
= _mbsinc(mbstring
) - mbstring
;
393 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
394 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
395 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
397 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
398 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
399 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
400 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
401 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
402 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
403 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
404 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
405 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
406 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
407 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
408 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
409 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
410 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
411 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
412 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
413 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
414 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
416 /* functions that depend on locale codepage, not mbcp.
417 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
418 * (as of Wine 0.9.43)
420 GetCPInfo(GetACP(), &cp_info
);
421 if (cp_info
.MaxCharSize
== 1)
423 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
424 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
427 skip("Current locale has double-byte charset - could lead to false positives\n");
430 expect_eq(_ismbblead(0x80), 0, int, "%d");
432 expect_eq(_ismbblead(0x81), 1, int, "%d");
433 expect_eq(_ismbblead(0x83), 1, int, "%d");
435 expect_eq(_ismbblead(0x84), 1, int, "%d");
436 expect_eq(_ismbblead(0xd3), 1, int, "%d");
437 expect_eq(_ismbblead(0xd7), 0, int, "%d");
438 expect_eq(_ismbblead(0xd8), 1, int, "%d");
439 expect_eq(_ismbblead(0xd9), 1, int, "%d");
441 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
442 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
443 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
444 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
445 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
446 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
447 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
448 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
453 static void test_mbsspn( void)
455 unsigned char str1
[]="cabernet";
456 unsigned char str2
[]="shiraz";
457 unsigned char set
[]="abc";
458 unsigned char empty
[]="";
460 ret
=_mbsspn( str1
, set
);
461 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
462 ret
=_mbsspn( str2
, set
);
463 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
464 ret
=_mbsspn( str1
, empty
);
465 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
468 static void test_mbsspnp( void)
470 unsigned char str1
[]="cabernet";
471 unsigned char str2
[]="shiraz";
472 unsigned char set
[]="abc";
473 unsigned char empty
[]="";
474 unsigned char full
[]="abcenrt";
476 ret
=_mbsspnp( str1
, set
);
477 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
478 ret
=_mbsspnp( str2
, set
);
479 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
480 ret
=_mbsspnp( str1
, empty
);
481 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
482 ret
=_mbsspnp( str1
, full
);
483 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
486 static void test_strdup(void)
490 ok( str
== 0, "strdup returns %s should be 0\n", str
);
494 static void test_strcpy_s(void)
497 const char *small
= "small";
498 const char *big
= "atoolongstringforthislittledestination";
503 skip("strcpy_s not found\n");
507 memset(dest
, 'X', sizeof(dest
));
508 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
509 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
510 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
511 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
512 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
513 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
515 memset(dest
, 'X', sizeof(dest
));
516 ret
= pstrcpy_s(dest
, 0, big
);
517 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
518 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
519 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
520 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
521 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
522 ret
= pstrcpy_s(dest
, 0, NULL
);
523 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
524 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
525 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
526 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
527 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
529 memset(dest
, 'X', sizeof(dest
));
530 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
531 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
532 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
533 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
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
));
538 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
539 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
540 ok(dest
[0] == '\0'&& dest
[1] == 'X' && 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
= pstrcpy_s(NULL
, sizeof(dest
), small
);
546 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
549 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
551 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
552 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
553 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
554 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
555 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
557 static void test_memcpy_s(void)
560 static const char tiny
[] = {'T',0,'I','N','Y',0};
561 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
564 skip("memcpy_s not found\n");
568 if (p_set_invalid_parameter_handler
)
569 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
570 "Invalid parameter handler was already set\n");
573 memset(dest
, 'X', sizeof(dest
));
574 ret
= p_memcpy_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
575 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
576 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
578 /* Vary source size */
580 memset(dest
, 'X', sizeof(dest
));
581 ret
= p_memcpy_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
582 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
583 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
584 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
586 /* Replace source with NULL */
588 memset(dest
, 'X', sizeof(dest
));
589 ret
= p_memcpy_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
590 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
591 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
592 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
596 memset(dest
, 'X', sizeof(dest
));
597 ret
= p_memcpy_s(dest
, 0, tiny
, NUMELMS(tiny
));
598 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
599 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
600 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
602 /* Replace dest with NULL */
604 ret
= p_memcpy_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
605 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
606 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
610 memset(dest
, 'X', sizeof(dest
));
611 ret
= p_memcpy_s(dest
, 0, NULL
, NUMELMS(tiny
));
612 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
613 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
614 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
616 if (p_set_invalid_parameter_handler
)
617 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
618 "Cannot reset invalid parameter handler\n");
621 static void test_memmove_s(void)
624 static const char tiny
[] = {'T',0,'I','N','Y',0};
625 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
628 skip("memmove_s not found\n");
632 if (p_set_invalid_parameter_handler
)
633 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
634 "Invalid parameter handler was already set\n");
637 memset(dest
, 'X', sizeof(dest
));
638 ret
= p_memmove_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
639 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
640 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
643 memcpy(dest
, big
, sizeof(dest
));
644 ret
= p_memmove_s(dest
+1, NUMELMS(dest
)-1, dest
, NUMELMS(dest
)-1);
645 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
646 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
648 /* Vary source size */
650 memset(dest
, 'X', sizeof(dest
));
651 ret
= p_memmove_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
652 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
653 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
654 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
656 /* Replace source with NULL */
658 memset(dest
, 'X', sizeof(dest
));
659 ret
= p_memmove_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
660 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
661 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
662 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
666 memset(dest
, 'X', sizeof(dest
));
667 ret
= p_memmove_s(dest
, 0, tiny
, NUMELMS(tiny
));
668 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
669 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
670 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
672 /* Replace dest with NULL */
674 ret
= p_memmove_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
675 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
676 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
680 memset(dest
, 'X', sizeof(dest
));
681 ret
= p_memmove_s(dest
, 0, NULL
, NUMELMS(tiny
));
682 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
683 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
684 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
686 if (p_set_invalid_parameter_handler
)
687 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
688 "Cannot reset invalid parameter handler\n");
691 static void test_strcat_s(void)
694 const char *small
= "sma";
699 skip("strcat_s not found\n");
703 memset(dest
, 'X', sizeof(dest
));
705 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
706 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
707 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
708 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
709 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
710 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
711 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
712 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
713 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
714 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
715 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
716 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
718 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
719 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
720 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
721 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
722 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
723 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
725 memset(dest
, 'X', sizeof(dest
));
729 ret
= pstrcat_s(dest
, 0, small
);
730 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
731 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
732 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
733 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
734 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
736 ret
= pstrcat_s(dest
, 0, NULL
);
737 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
738 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
739 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
740 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
741 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
743 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
744 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
745 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
746 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
747 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
748 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
750 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
751 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
754 static void test__mbsnbcpy_s(void)
756 unsigned char dest
[8];
757 const unsigned char big
[] = "atoolongstringforthislittledestination";
758 const unsigned char small
[] = "small";
763 skip("_mbsnbcpy_s not found\n");
767 memset(dest
, 'X', sizeof(dest
));
768 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
769 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
770 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
771 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
772 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
773 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
776 memset(dest
, 'X', sizeof(dest
));
777 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
778 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
779 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
780 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
781 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
782 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
784 memset(dest
, 'X', sizeof(dest
));
785 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
786 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
787 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
788 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
789 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
790 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
792 memset(dest
, 'X', sizeof(dest
));
793 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
794 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
795 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
796 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
797 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
798 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
801 static void test_wcscpy_s(void)
803 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
804 static WCHAR szDest
[18];
805 static WCHAR szDestShort
[8];
810 win_skip("wcscpy_s not found\n");
814 if (p_set_invalid_parameter_handler
)
815 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
816 "Invalid parameter handler was already set\n");
820 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
821 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
822 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
824 /* Test NULL Source */
827 ret
= p_wcscpy_s(szDest
, 18, NULL
);
828 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
829 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
830 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
832 /* Test invalid size */
835 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
836 /* Later versions changed the return value for this case to EINVAL,
837 * and don't modify the result if the dest size is 0.
839 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
840 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
841 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
843 /* Copy same buffer size */
844 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
845 ok(ret
== 0, "expected 0 got %d\n", ret
);
846 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
848 /* Copy smaller buffer size */
851 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
852 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
853 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
854 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
858 win_skip("wcsncpy_s not found\n");
860 if (p_set_invalid_parameter_handler
)
861 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
862 "Cannot reset invalid parameter handler\n");
866 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
867 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
870 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
871 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
872 ok(szDest
[0] == 0, "szDest[0] not 0\n");
875 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
876 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
877 ok(szDest
[0] == 0, "szDest[0] not 0\n");
880 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
881 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
882 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
884 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
885 ok(ret
== 0, "expected 0 got %d\n", ret
);
886 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
889 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
890 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
891 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
894 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
895 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
896 ok(szDest
[4] == 0, "szDest[4] not 0\n");
897 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
899 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
900 ok(ret
== 0, "ret = %d\n", ret
);
902 szDestShort
[0] = '1';
904 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
905 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
906 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
907 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
909 if (p_set_invalid_parameter_handler
)
910 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
911 "Cannot reset invalid parameter handler\n");
914 static void test__wcsupr_s(void)
916 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
917 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
918 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
919 'W', 'E', 'R', 'U', 'P', 'P', 'E',
921 WCHAR testBuffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
926 win_skip("_wcsupr_s not found\n");
930 /* Test NULL input string and invalid size. */
932 ret
= p_wcsupr_s(NULL
, 0);
933 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
934 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
936 /* Test NULL input string and valid size. */
938 ret
= p_wcsupr_s(NULL
, sizeof(testBuffer
)/sizeof(WCHAR
));
939 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
940 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
942 /* Test empty string with zero size. */
944 testBuffer
[0] = '\0';
945 ret
= p_wcsupr_s(testBuffer
, 0);
946 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
947 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
948 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
950 /* Test empty string with size of one. */
951 testBuffer
[0] = '\0';
952 ret
= p_wcsupr_s(testBuffer
, 1);
953 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
954 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
956 /* Test one-byte buffer with zero size. */
959 ret
= p_wcsupr_s(testBuffer
, 0);
960 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
961 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
962 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
964 /* Test one-byte buffer with size of one. */
967 ret
= p_wcsupr_s(testBuffer
, 1);
968 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
969 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
970 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
972 /* Test invalid size. */
973 wcscpy(testBuffer
, mixedString
);
975 ret
= p_wcsupr_s(testBuffer
, 0);
976 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
977 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
978 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
980 /* Test normal string uppercasing. */
981 wcscpy(testBuffer
, mixedString
);
982 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
));
983 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
984 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
986 /* Test uppercasing with a shorter buffer size count. */
987 wcscpy(testBuffer
, mixedString
);
989 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
990 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
991 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
992 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
994 /* Test uppercasing with a longer buffer size count. */
995 wcscpy(testBuffer
, mixedString
);
996 ret
= p_wcsupr_s(testBuffer
, sizeof(testBuffer
)/sizeof(WCHAR
));
997 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
998 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1001 static void test__wcslwr_s(void)
1003 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1004 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1005 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1006 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1008 WCHAR buffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
1013 win_skip("_wcslwr_s not found\n");
1017 /* Test NULL input string and invalid size. */
1019 ret
= p_wcslwr_s(NULL
, 0);
1020 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1021 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1023 /* Test NULL input string and valid size. */
1025 ret
= p_wcslwr_s(NULL
, sizeof(buffer
)/sizeof(wchar_t));
1026 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1027 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1029 /* Test empty string with zero size. */
1032 ret
= p_wcslwr_s(buffer
, 0);
1033 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1034 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1035 ok(buffer
[0] == 0, "expected empty string\n");
1037 /* Test empty string with size of one. */
1039 ret
= p_wcslwr_s(buffer
, 1);
1040 ok(ret
== 0, "got %d\n", ret
);
1041 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1043 /* Test one-byte buffer with zero size. */
1046 ret
= p_wcslwr_s(buffer
, 0);
1047 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1048 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1049 ok(buffer
[0] == '\0', "expected empty string\n");
1051 /* Test one-byte buffer with size of one. */
1054 ret
= p_wcslwr_s(buffer
, 1);
1055 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1056 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1057 ok(buffer
[0] == '\0', "expected empty string\n");
1059 /* Test invalid size. */
1060 wcscpy(buffer
, mixedString
);
1062 ret
= p_wcslwr_s(buffer
, 0);
1063 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1064 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1065 ok(buffer
[0] == '\0', "expected empty string\n");
1067 /* Test normal string uppercasing. */
1068 wcscpy(buffer
, mixedString
);
1069 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
));
1070 ok(ret
== 0, "expected 0, got %d\n", ret
);
1071 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1073 /* Test uppercasing with a shorter buffer size count. */
1074 wcscpy(buffer
, mixedString
);
1076 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
1077 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1078 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1079 ok(buffer
[0] == '\0', "expected empty string\n");
1081 /* Test uppercasing with a longer buffer size count. */
1082 wcscpy(buffer
, mixedString
);
1083 ret
= p_wcslwr_s(buffer
, sizeof(buffer
)/sizeof(WCHAR
));
1084 ok(ret
== 0, "expected 0, got %d\n", ret
);
1085 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1088 static void test_mbcjisjms(void)
1090 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1091 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1092 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1093 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1094 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1095 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1097 int prev_cp
= _getmbcp();
1099 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1102 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1104 unsigned int ret
, exp
;
1105 ret
= _mbcjistojms(jisjms
[j
][0]);
1106 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1107 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1108 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1114 static void test_mbcjmsjis(void)
1116 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1117 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1118 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1119 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1120 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1121 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1122 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1123 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1125 int prev_cp
= _getmbcp();
1127 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1130 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1132 unsigned int ret
, exp
;
1133 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1134 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1135 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1136 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1142 static void test_mbbtombc(void)
1144 static const unsigned int mbbmbc
[][2] = {
1145 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1146 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1147 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1148 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1149 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1151 int prev_cp
= _getmbcp();
1153 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1156 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1158 unsigned int exp
, ret
;
1159 ret
= _mbbtombc(mbbmbc
[j
][0]);
1160 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1161 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1162 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1168 static void test_mbctombb(void)
1170 static const unsigned int mbcmbb_932
[][2] = {
1171 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1172 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1173 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1174 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1175 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1176 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1177 unsigned int exp
, ret
, i
;
1178 unsigned int prev_cp
= _getmbcp();
1181 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1183 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1184 exp
= mbcmbb_932
[i
][1];
1185 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1190 static void test_ismbclegal(void) {
1191 unsigned int prev_cp
= _getmbcp();
1195 _setmbcp(932); /* Japanese */
1197 for(i
= 0; i
< 0x10000; i
++) {
1198 ret
= _ismbclegal(i
);
1199 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1200 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1201 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1202 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1208 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1209 _setmbcp(936); /* Chinese (GBK) */
1211 for(i
= 0; i
< 0x10000; i
++) {
1212 ret
= _ismbclegal(i
);
1213 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1214 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1220 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1221 _setmbcp(949); /* Korean */
1223 for(i
= 0; i
< 0x10000; i
++) {
1224 ret
= _ismbclegal(i
);
1225 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1226 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1232 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1233 _setmbcp(950); /* Chinese (Big5) */
1235 for(i
= 0; i
< 0x10000; i
++) {
1236 ret
= _ismbclegal(i
);
1237 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1238 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1239 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1245 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1246 _setmbcp(1361); /* Korean (Johab) */
1248 for(i
= 0; i
< 0x10000; i
++) {
1249 ret
= _ismbclegal(i
);
1250 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1251 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1252 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1253 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1260 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1265 static const struct {
1267 const char* delimiter
;
1268 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1270 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1272 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1274 } testcases_strtok
[] = {
1275 { "red cabernet", " ", 0, 4, -1 },
1276 { "sparkling white riesling", " ", 0, 10, 16 },
1277 { " pale cream sherry", "e ", 1, 6, 9 },
1282 static void test_strtok(void)
1287 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1288 strcpy( teststr
, testcases_strtok
[i
].string
);
1289 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1290 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1291 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1292 "string (%p) \'%s\' return %p\n",
1293 teststr
, testcases_strtok
[i
].string
, strret
);
1294 if( !strret
) continue;
1295 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1296 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1297 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1298 "second call string (%p) \'%s\' return %p\n",
1299 teststr
, testcases_strtok
[i
].string
, strret
);
1300 if( !strret
) continue;
1301 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1302 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1303 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1304 "third call string (%p) \'%s\' return %p\n",
1305 teststr
, testcases_strtok
[i
].string
, strret
);
1309 static void test_strtol(void)
1315 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1316 /* errno is modified on W2K8+ */
1318 l
= strtol("-1234", &e
, 0);
1319 ok(l
==-1234, "wrong value %d\n", l
);
1320 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1322 ul
= strtoul("1234", &e
, 0);
1323 ok(ul
==1234, "wrong value %u\n", ul
);
1324 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1327 l
= strtol("2147483647L", &e
, 0);
1328 ok(l
==2147483647, "wrong value %d\n", l
);
1329 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1331 l
= strtol("-2147483648L", &e
, 0);
1332 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1333 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1335 ul
= strtoul("4294967295UL", &e
, 0);
1336 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1337 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1340 l
= strtol("9223372036854775807L", &e
, 0);
1341 ok(l
==2147483647, "wrong value %d\n", l
);
1342 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1344 ul
= strtoul("9223372036854775807L", &e
, 0);
1345 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1346 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1349 ul
= strtoul("-2", NULL
, 0);
1350 ok(ul
== -2, "wrong value %u\n", ul
);
1351 ok(errno
== 0, "wrong errno %d\n", errno
);
1354 ul
= strtoul("-4294967294", NULL
, 0);
1355 ok(ul
== 2, "wrong value %u\n", ul
);
1356 ok(errno
== 0, "wrong errno %d\n", errno
);
1359 ul
= strtoul("-4294967295", NULL
, 0);
1360 ok(ul
==1, "wrong value %u\n", ul
);
1361 ok(errno
== 0, "wrong errno %d\n", errno
);
1364 ul
= strtoul("-4294967296", NULL
, 0);
1365 ok(ul
== 1, "wrong value %u\n", ul
);
1366 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1369 static void test_strnlen(void)
1371 static const char str
[] = "string";
1375 win_skip("strnlen not found\n");
1379 res
= p_strnlen(str
, 20);
1380 ok(res
== 6, "Returned length = %d\n", (int)res
);
1382 res
= p_strnlen(str
, 3);
1383 ok(res
== 3, "Returned length = %d\n", (int)res
);
1385 res
= p_strnlen(NULL
, 0);
1386 ok(res
== 0, "Returned length = %d\n", (int)res
);
1389 static void test__strtoi64(void)
1391 static const char no1
[] = "31923";
1392 static const char no2
[] = "-213312";
1393 static const char no3
[] = "12aa";
1394 static const char no4
[] = "abc12";
1395 static const char overflow
[] = "99999999999999999999";
1396 static const char neg_overflow
[] = "-99999999999999999999";
1397 static const char hex
[] = "0x123";
1398 static const char oct
[] = "000123";
1399 static const char blanks
[] = " 12 212.31";
1402 unsigned __int64 ures
;
1405 if(!p_strtoi64
|| !p_strtoui64
) {
1406 win_skip("_strtoi64 or _strtoui64 not found\n");
1411 res
= p_strtoi64(no1
, NULL
, 10);
1412 ok(res
== 31923, "res != 31923\n");
1413 res
= p_strtoi64(no2
, NULL
, 10);
1414 ok(res
== -213312, "res != -213312\n");
1415 res
= p_strtoi64(no3
, NULL
, 10);
1416 ok(res
== 12, "res != 12\n");
1417 res
= p_strtoi64(no4
, &endpos
, 10);
1418 ok(res
== 0, "res != 0\n");
1419 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1420 res
= p_strtoi64(hex
, &endpos
, 10);
1421 ok(res
== 0, "res != 0\n");
1422 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1423 res
= p_strtoi64(oct
, &endpos
, 10);
1424 ok(res
== 123, "res != 123\n");
1425 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1426 res
= p_strtoi64(blanks
, &endpos
, 10);
1427 ok(res
== 12, "res != 12\n");
1428 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1429 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1432 res
= p_strtoi64(overflow
, &endpos
, 10);
1433 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1434 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1435 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1438 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1439 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1440 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1441 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1444 res
= p_strtoi64(no1
, &endpos
, 16);
1445 ok(res
== 203043, "res != 203043\n");
1446 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1447 res
= p_strtoi64(no2
, &endpos
, 16);
1448 ok(res
== -2175762, "res != -2175762\n");
1449 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1450 res
= p_strtoi64(no3
, &endpos
, 16);
1451 ok(res
== 4778, "res != 4778\n");
1452 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1453 res
= p_strtoi64(no4
, &endpos
, 16);
1454 ok(res
== 703506, "res != 703506\n");
1455 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1456 res
= p_strtoi64(hex
, &endpos
, 16);
1457 ok(res
== 291, "res != 291\n");
1458 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1459 res
= p_strtoi64(oct
, &endpos
, 16);
1460 ok(res
== 291, "res != 291\n");
1461 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1462 res
= p_strtoi64(blanks
, &endpos
, 16);
1463 ok(res
== 18, "res != 18\n");
1464 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1465 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1468 res
= p_strtoi64(hex
, &endpos
, 36);
1469 ok(res
== 1541019, "res != 1541019\n");
1470 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1471 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1474 res
= p_strtoi64(no1
, &endpos
, 0);
1475 ok(res
== 31923, "res != 31923\n");
1476 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1477 res
= p_strtoi64(no2
, &endpos
, 0);
1478 ok(res
== -213312, "res != -213312\n");
1479 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1480 res
= p_strtoi64(no3
, &endpos
, 10);
1481 ok(res
== 12, "res != 12\n");
1482 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1483 res
= p_strtoi64(no4
, &endpos
, 10);
1484 ok(res
== 0, "res != 0\n");
1485 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1486 res
= p_strtoi64(hex
, &endpos
, 10);
1487 ok(res
== 0, "res != 0\n");
1488 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1489 res
= p_strtoi64(oct
, &endpos
, 10);
1490 ok(res
== 123, "res != 123\n");
1491 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1492 res
= p_strtoi64(blanks
, &endpos
, 10);
1493 ok(res
== 12, "res != 12\n");
1494 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1495 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1498 ures
= p_strtoui64(no1
, &endpos
, 0);
1499 ok(ures
== 31923, "ures != 31923\n");
1500 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1501 ures
= p_strtoui64(no2
, &endpos
, 0);
1502 ok(ures
== -213312, "ures != -213312\n");
1503 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1504 ures
= p_strtoui64(no3
, &endpos
, 10);
1505 ok(ures
== 12, "ures != 12\n");
1506 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1507 ures
= p_strtoui64(no4
, &endpos
, 10);
1508 ok(ures
== 0, "ures != 0\n");
1509 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1510 ures
= p_strtoui64(hex
, &endpos
, 10);
1511 ok(ures
== 0, "ures != 0\n");
1512 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1513 ures
= p_strtoui64(oct
, &endpos
, 10);
1514 ok(ures
== 123, "ures != 123\n");
1515 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1516 ures
= p_strtoui64(blanks
, &endpos
, 10);
1517 ok(ures
== 12, "ures != 12\n");
1518 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1519 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1522 ures
= p_strtoui64(overflow
, &endpos
, 10);
1523 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1524 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1525 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1528 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1529 ok(ures
== 1, "ures != 1\n");
1530 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1531 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1534 static inline BOOL
almost_equal(double d1
, double d2
) {
1535 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1540 static void test__strtod(void)
1542 const char double1
[] = "12.1";
1543 const char double2
[] = "-13.721";
1544 const char double3
[] = "INF";
1545 const char double4
[] = ".21e12";
1546 const char double5
[] = "214353e-3";
1547 const char overflow
[] = "1d9999999999999999999";
1548 const char white_chars
[] = " d10";
1553 d
= strtod(double1
, &end
);
1554 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1555 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1557 d
= strtod(double2
, &end
);
1558 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1559 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1561 d
= strtod(double3
, &end
);
1562 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1563 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1565 d
= strtod(double4
, &end
);
1566 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1567 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1569 d
= strtod(double5
, &end
);
1570 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1571 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1573 d
= strtod("12.1d2", NULL
);
1574 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1576 d
= strtod(white_chars
, &end
);
1577 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1578 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1580 /* Set locale with non '.' decimal point (',') */
1581 if(!setlocale(LC_ALL
, "Polish")) {
1582 win_skip("system with limited locales\n");
1586 d
= strtod("12.1", NULL
);
1587 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1589 d
= strtod("12,1", NULL
);
1590 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1592 setlocale(LC_ALL
, "C");
1594 /* Precision tests */
1595 d
= strtod("0.1", NULL
);
1596 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1597 d
= strtod("-0.1", NULL
);
1598 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1599 d
= strtod("0.1281832188491894198128921", NULL
);
1600 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1601 d
= strtod("0.82181281288121", NULL
);
1602 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1603 d
= strtod("21921922352523587651128218821", NULL
);
1604 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1605 d
= strtod("0.1d238", NULL
);
1606 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1607 d
= strtod("0.1D-4736", NULL
);
1608 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1611 strtod(overflow
, &end
);
1612 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1613 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1616 strtod("-1d309", NULL
);
1617 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1620 static void test_mbstowcs(void)
1622 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1623 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1624 static const char mSimple
[] = "text";
1625 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1627 const wchar_t *pwstr
;
1635 wOut
[4] = '!'; wOut
[5] = '\0';
1636 mOut
[4] = '!'; mOut
[5] = '\0';
1639 /* crashes on some systems */
1641 ret
= mbstowcs(wOut
, NULL
, 4);
1642 ok(ret
== -1, "mbstowcs did not return -1\n");
1643 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1646 ret
= mbstowcs(NULL
, mSimple
, 0);
1647 ok(ret
== 4, "mbstowcs did not return 4\n");
1649 ret
= mbstowcs(wOut
, mSimple
, 4);
1650 ok(ret
== 4, "mbstowcs did not return 4\n");
1651 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1652 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1654 ret
= wcstombs(NULL
, wSimple
, 0);
1655 ok(ret
== 4, "wcstombs did not return 4\n");
1657 ret
= wcstombs(mOut
, wSimple
, 6);
1658 ok(ret
== 4, "wcstombs did not return 4\n");
1659 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1661 ret
= wcstombs(mOut
, wSimple
, 2);
1662 ok(ret
== 2, "wcstombs did not return 2\n");
1663 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1665 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
1666 win_skip("Japanese_Japan.932 locale not available\n");
1670 ret
= mbstowcs(wOut
, mHiragana
, 6);
1671 ok(ret
== 2, "mbstowcs did not return 2\n");
1672 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1674 ret
= wcstombs(mOut
, wHiragana
, 6);
1675 ok(ret
== 4, "wcstombs did not return 4\n");
1676 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1678 if(!pmbstowcs_s
|| !pwcstombs_s
) {
1679 setlocale(LC_ALL
, "C");
1680 win_skip("mbstowcs_s or wcstombs_s not available\n");
1684 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
1685 ok(err
== 0, "err = %d\n", err
);
1686 ok(ret
== 5, "mbstowcs_s did not return 5\n");
1687 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1689 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
1690 ok(err
== 0, "err = %d\n", err
);
1691 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1692 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1694 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
1695 ok(err
== 0, "err = %d\n", err
);
1696 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1698 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
1699 ok(err
== 0, "err = %d\n", err
);
1700 ok(ret
== 5, "wcstombs_s did not return 5\n");
1701 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1703 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
1704 ok(err
== 0, "err = %d\n", err
);
1705 ok(ret
== 5, "wcstombs_s did not return 5\n");
1706 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1708 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
1709 ok(err
== 0, "err = %d\n", err
);
1710 ok(ret
== 5, "wcstombs_s did not return 5\n");
1713 setlocale(LC_ALL
, "C");
1714 win_skip("wcsrtombs not available\n");
1720 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
1721 ok(ret
== 4, "wcsrtombs did not return 4\n");
1722 ok(err
== 0, "err = %d\n", err
);
1723 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
1724 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
1727 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
1728 ok(ret
== 4, "wcsrtombs did not return 4\n");
1729 ok(pwstr
== NULL
, "pwstr != NULL\n");
1730 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1733 setlocale(LC_ALL
, "C");
1734 win_skip("mbsrtowcs not available\n");
1739 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
1740 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1741 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1742 ok(!pmbstr
, "pmbstr != NULL\n");
1744 state
= mHiragana
[0];
1745 pmbstr
= mHiragana
+1;
1746 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
1747 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1748 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
1749 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
1750 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
1751 ok(!pmbstr
, "pmbstr != NULL\n");
1753 if (p_set_invalid_parameter_handler
)
1754 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1755 "Invalid parameter handler was already set\n");
1757 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
1758 ok(ret
== -1, "mbsrtowcs did not return -1\n");
1759 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1760 if (p_set_invalid_parameter_handler
)
1761 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
1762 "Cannot reset invalid parameter handler\n");
1764 setlocale(LC_ALL
, "C");
1767 static void test_gcvt(void)
1769 char buf
[1024], *res
;
1773 win_skip("Skipping _gcvt tests\n");
1778 res
= _gcvt(1.2, -1, buf
);
1779 ok(res
== NULL
, "res != NULL\n");
1780 ok(errno
== ERANGE
, "errno = %d\n", errno
);
1783 res
= _gcvt(1.2, 5, NULL
);
1784 ok(res
== NULL
, "res != NULL\n");
1785 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1787 res
= gcvt(1.2, 5, buf
);
1788 ok(res
== buf
, "res != buf\n");
1789 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
1792 err
= p_gcvt_s(buf
, 5, 1.2, 10);
1793 ok(err
== ERANGE
, "err = %d\n", err
);
1794 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1797 err
= p_gcvt_s(buf
, 4, 123456, 2);
1798 ok(err
== ERANGE
, "err = %d\n", err
);
1799 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1802 static void test__itoa_s(void)
1809 win_skip("Skipping _itoa_s tests\n");
1813 if (p_set_invalid_parameter_handler
)
1814 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1815 "Invalid parameter handler was already set\n");
1818 ret
= p_itoa_s(0, NULL
, 0, 0);
1819 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1820 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1822 memset(buffer
, 'X', sizeof(buffer
));
1824 ret
= p_itoa_s(0, buffer
, 0, 0);
1825 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1826 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1827 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
1829 memset(buffer
, 'X', sizeof(buffer
));
1831 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
1832 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1833 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1834 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1836 memset(buffer
, 'X', sizeof(buffer
));
1838 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
1839 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1840 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1841 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1843 memset(buffer
, 'X', sizeof(buffer
));
1845 ret
= p_itoa_s(12345678, buffer
, 4, 10);
1846 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1847 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1848 ok(!memcmp(buffer
, "\000765", 4),
1849 "Expected the output buffer to be null terminated with truncated output\n");
1851 memset(buffer
, 'X', sizeof(buffer
));
1853 ret
= p_itoa_s(12345678, buffer
, 8, 10);
1854 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1855 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1856 ok(!memcmp(buffer
, "\0007654321", 8),
1857 "Expected the output buffer to be null terminated with truncated output\n");
1859 memset(buffer
, 'X', sizeof(buffer
));
1861 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
1862 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1863 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1864 ok(!memcmp(buffer
, "\00087654321", 9),
1865 "Expected the output buffer to be null terminated with truncated output\n");
1867 ret
= p_itoa_s(12345678, buffer
, 9, 10);
1868 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1869 ok(!strcmp(buffer
, "12345678"),
1870 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1873 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
1874 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1875 ok(!strcmp(buffer
, "1010101010101010"),
1876 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1879 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
1880 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1881 ok(!strcmp(buffer
, "nell"),
1882 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1885 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
1886 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1887 ok(!strcmp(buffer
, "hag"),
1888 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1891 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
1892 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1893 ok(!strcmp(buffer
, "-12345678"),
1894 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1897 itoa(100, buffer
, 100);
1898 ok(!strcmp(buffer
, "10"),
1899 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
1901 if (p_set_invalid_parameter_handler
)
1902 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
1903 "Cannot reset invalid parameter handler\n");
1906 static void test__strlwr_s(void)
1913 win_skip("Skipping _strlwr_s tests\n");
1918 ret
= p_strlwr_s(NULL
, 0);
1919 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1920 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1923 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
1924 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1925 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1928 ret
= p_strlwr_s(buffer
, 0);
1929 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1930 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1932 strcpy(buffer
, "GoRrIsTeR");
1934 ret
= p_strlwr_s(buffer
, 5);
1935 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1936 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1937 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1938 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1940 strcpy(buffer
, "GoRrIsTeR");
1942 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
1943 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1944 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1945 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1946 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1948 strcpy(buffer
, "GoRrIsTeR");
1949 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
1950 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1951 ok(!strcmp(buffer
, "gorrister"),
1952 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1955 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1956 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
1957 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1958 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1959 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1963 static void test_wcsncat_s(void)
1965 static wchar_t abcW
[] = {'a','b','c',0};
1972 win_skip("skipping wcsncat_s tests\n");
1976 if (p_set_invalid_parameter_handler
)
1977 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler
) == NULL
,
1978 "Invalid parameter handler was already set\n");
1980 memcpy(src
, abcW
, sizeof(abcW
));
1982 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
1983 ok(ret
== EINVAL
, "err = %d\n", ret
);
1984 ret
= p_wcsncat_s(dst
, 0, src
, 4);
1985 ok(ret
== EINVAL
, "err = %d\n", ret
);
1986 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
1987 ok(ret
== EINVAL
, "err = %d\n", ret
);
1988 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
1989 ok(ret
== 0, "err = %d\n", ret
);
1992 ret
= p_wcsncat_s(dst
, 2, src
, 4);
1993 ok(ret
== ERANGE
, "err = %d\n", ret
);
1996 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
1997 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
1998 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2000 memcpy(dst
, abcW
, sizeof(abcW
));
2002 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2003 ok(ret
== EINVAL
, "err = %d\n", ret
);
2005 if (p_set_invalid_parameter_handler
)
2006 ok(p_set_invalid_parameter_handler(NULL
) == test_invalid_parameter_handler
,
2007 "Cannot reset invalid parameter handler\n");
2010 static void test__mbsnbcat_s(void)
2012 unsigned char dest
[16];
2013 const unsigned char first
[] = "dinosaur";
2014 const unsigned char second
[] = "duck";
2019 win_skip("Skipping _mbsnbcat_s tests\n");
2023 /* Test invalid arguments. */
2024 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2025 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2028 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2029 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2030 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2033 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2034 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2035 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2037 memset(dest
, 'X', sizeof(dest
));
2039 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2040 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2041 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2042 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2044 memset(dest
, 'X', sizeof(dest
));
2046 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2047 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2048 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2049 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2051 memset(dest
, 'X', sizeof(dest
));
2053 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2054 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2055 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2056 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2058 memset(dest
, 'X', sizeof(dest
));
2060 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2061 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2062 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2063 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2065 memset(dest
, 'X', sizeof(dest
));
2067 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2068 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2069 ok(!memcmp(dest
, second
, sizeof(second
)),
2070 "Expected the output buffer string to be \"duck\"\n");
2072 /* Test source truncation behavior. */
2073 memset(dest
, 'X', sizeof(dest
));
2074 memcpy(dest
, first
, sizeof(first
));
2075 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2076 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2077 ok(!memcmp(dest
, first
, sizeof(first
)),
2078 "Expected the output buffer string to be \"dinosaur\"\n");
2080 memset(dest
, 'X', sizeof(dest
));
2081 memcpy(dest
, first
, sizeof(first
));
2082 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2083 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2084 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2085 "Expected the output buffer string to be \"dinosaurduck\"\n");
2087 memset(dest
, 'X', sizeof(dest
));
2088 memcpy(dest
, first
, sizeof(first
));
2089 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2090 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2091 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2092 "Expected the output buffer string to be \"dinosaurduck\"\n");
2094 memset(dest
, 'X', sizeof(dest
));
2095 memcpy(dest
, first
, sizeof(first
));
2096 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2097 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2098 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2099 "Expected the output buffer string to be \"dinosaurduck\"\n");
2101 memset(dest
, 'X', sizeof(dest
));
2102 memcpy(dest
, first
, sizeof(first
));
2103 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2104 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2105 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2106 "Expected the output buffer string to be \"dinosaurduc\"\n");
2108 /* Test destination truncation behavior. */
2109 memset(dest
, 'X', sizeof(dest
));
2110 memcpy(dest
, first
, sizeof(first
));
2112 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2113 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2114 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2115 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2116 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2118 memset(dest
, 'X', sizeof(dest
));
2119 memcpy(dest
, first
, sizeof(first
));
2121 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2122 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2123 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2124 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2125 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2127 memset(dest
, 'X', sizeof(dest
));
2128 memcpy(dest
, first
, sizeof(first
));
2130 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2131 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2132 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2133 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2134 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2137 static void test__mbsupr_s(void)
2140 unsigned char buffer
[20];
2144 win_skip("Skipping _mbsupr_s tests\n");
2149 ret
= p_mbsupr_s(NULL
, 0);
2150 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2153 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2154 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2155 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2158 ret
= p_mbsupr_s(buffer
, 0);
2159 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2160 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2162 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2164 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2165 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2166 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2167 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2170 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2172 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2173 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2174 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2175 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2178 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2180 ret
= p_mbsupr_s(buffer
, 4);
2181 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2182 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2184 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2186 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2187 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2188 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2189 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2194 static void test__mbslwr_s(void)
2197 unsigned char buffer
[20];
2201 win_skip("Skipping _mbslwr_s tests\n");
2206 ret
= p_mbslwr_s(NULL
, 0);
2207 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2210 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2211 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2212 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2215 ret
= p_mbslwr_s(buffer
, 0);
2216 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2217 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2219 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2221 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2222 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2223 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2224 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2227 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2229 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2230 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2231 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2232 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2235 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2237 ret
= p_mbslwr_s(buffer
, 4);
2238 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2239 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2241 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2243 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2244 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2245 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2246 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2250 static void test__mbstok(void)
2252 const unsigned char delim
[] = "t";
2254 char str
[] = "!.!test";
2259 ret
= _mbstok(NULL
, delim
);
2260 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2261 ok(!ret
|| broken((char*)ret
==str
+4),
2262 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2264 ret
= _mbstok(NULL
, delim
);
2265 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2268 static void test__ultoa_s(void)
2275 win_skip("Skipping _ultoa_s tests\n");
2280 ret
= p_ultoa_s(0, NULL
, 0, 0);
2281 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2282 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2284 memset(buffer
, 'X', sizeof(buffer
));
2286 ret
= p_ultoa_s(0, buffer
, 0, 0);
2287 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2288 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2289 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2291 memset(buffer
, 'X', sizeof(buffer
));
2293 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2294 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2295 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2296 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2298 memset(buffer
, 'X', sizeof(buffer
));
2300 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2301 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2302 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2303 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2305 memset(buffer
, 'X', sizeof(buffer
));
2307 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2308 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2309 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2310 ok(!memcmp(buffer
, "\000765", 4),
2311 "Expected the output buffer to be null terminated with truncated output\n");
2313 memset(buffer
, 'X', sizeof(buffer
));
2315 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2316 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2317 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2318 ok(!memcmp(buffer
, "\0007654321", 8),
2319 "Expected the output buffer to be null terminated with truncated output\n");
2321 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2322 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2323 ok(!strcmp(buffer
, "12345678"),
2324 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2327 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2328 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2329 ok(!strcmp(buffer
, "1010101010101010"),
2330 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2333 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2334 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2335 ok(!strcmp(buffer
, "nell"),
2336 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2339 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2340 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2341 ok(!strcmp(buffer
, "hag"),
2342 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2346 static void test_wctob(void)
2350 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2351 win_skip("Skipping wctob tests\n");
2355 ret
= p_wctob(0x8141);
2356 ok(ret
== EOF
, "ret = %x\n", ret
);
2358 ret
= p_wctob(0x81);
2359 ok(ret
== EOF
, "ret = %x\n", ret
);
2361 ret
= p_wctob(0xe0);
2362 ok(ret
== 0x61, "ret = %x\n", ret
);
2365 ret
= p_wctob(0x81);
2366 ok(ret
== EOF
, "ret = %x\n", ret
);
2368 setlocale(LC_ALL
, "C");
2369 ret
= p_wctob(0x8141);
2370 ok(ret
== EOF
, "ret = %x\n", ret
);
2372 ret
= p_wctob(0x81);
2373 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2375 ret
= p_wctob(0x9f);
2376 ok(ret
== (int)(char)0x9f, "ret = %x\n", ret
);
2378 ret
= p_wctob(0xe0);
2379 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2381 static void test_wctomb(void)
2384 unsigned char dst
[10];
2387 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
2388 win_skip("wcrtomb tests\n");
2392 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
2393 ok(ret
== 2, "wcrtomb did not return 2\n");
2397 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
2398 ok(ret
== 2, "wcrtomb did not return 2\n");
2399 ok(state
== 0, "state != 0\n");
2400 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2401 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
2402 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
2404 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
2405 ok(ret
== 2, "wcrtomb did not return 2\n");
2406 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2407 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
2409 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
2410 ok(ret
== 1, "wcrtomb did not return 1\n");
2411 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
2413 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
2414 ok(ret
== -1, "wcrtomb did not return -1\n");
2415 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
2417 setlocale(LC_ALL
, "C");
2420 static void test_tolower(void)
2425 /* test C locale when locale was never changed */
2426 ret
= p_tolower(0x41);
2427 ok(ret
== 0x61, "ret = %x\n", ret
);
2429 ret
= p_tolower(0xF4);
2430 ok(ret
== 0xF4, "ret = %x\n", ret
);
2433 ret
= p_tolower((char)0xF4);
2434 todo_wine
ok(ret
== (char)0xF4, "ret = %x\n", ret
);
2435 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2438 ret
= p_tolower((char)0xD0);
2439 todo_wine
ok(ret
== (char)0xD0, "ret = %x\n", ret
);
2440 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2442 /* test C locale after setting locale */
2443 if(!setlocale(LC_ALL
, "us")) {
2444 win_skip("skipping tolower tests that depends on locale\n");
2447 setlocale(LC_ALL
, "C");
2451 ret
= p_tolower(ch
);
2452 len
= LCMapStringA(0, LCMAP_LOWERCASE
, &ch
, 1, &lch
, 1);
2454 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2456 ok(ret
== ch
, "ret = %x\n", ret
);
2457 if(!len
|| ret
==(unsigned char)lch
)
2458 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2462 ret
= p_tolower(ch
);
2463 len
= LCMapStringA(0, LCMAP_LOWERCASE
, &ch
, 1, &lch
, 1);
2465 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2467 ok(ret
== ch
, "ret = %x\n", ret
);
2468 if(!len
|| ret
==(unsigned char)lch
)
2469 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2471 ret
= p_tolower(0xD0);
2472 ok(ret
== 0xD0, "ret = %x\n", ret
);
2474 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
2476 ret
= p_tolower((char)0xD0);
2477 ok(ret
== 0xF0, "ret = %x\n", ret
);
2479 ret
= p_tolower(0xD0);
2480 ok(ret
== 0xF0, "ret = %x\n", ret
);
2482 setlocale(LC_ALL
, "C");
2485 static void test__atodbl(void)
2492 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2493 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2494 win_skip("_atodbl_l is not available\n");
2499 ret
= p__atodbl_l(&d
, num
, NULL
);
2500 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
2501 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2502 ret
= _atodbl(&d
, num
);
2503 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
2504 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2507 ret
= p__atodbl_l(&d
, num
, NULL
);
2508 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
2509 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2510 ret
= _atodbl(&d
, num
);
2511 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
2512 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2515 ret
= p__atodbl_l(&d
, num
, NULL
);
2516 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
2517 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2518 ret
= _atodbl(&d
, num
);
2519 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
2520 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2523 ret
= p__atodbl_l(&d
, num
, NULL
);
2524 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
2525 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2526 ret
= _atodbl(&d
, num
);
2527 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
2528 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2530 strcpy(num
, "1e-309");
2531 ret
= p__atodbl_l(&d
, num
, NULL
);
2532 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
2533 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2534 ret
= _atodbl(&d
, num
);
2535 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
2536 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2538 strcpy(num
, "1e309");
2539 ret
= p__atodbl_l(&d
, num
, NULL
);
2540 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
2541 ret
= _atodbl(&d
, num
);
2542 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
2545 static void test__stricmp(void)
2549 ret
= _stricmp("test", "test");
2550 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2551 ret
= _stricmp("a", "z");
2552 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2553 ret
= _stricmp("z", "a");
2554 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2555 ret
= _stricmp("\xa5", "\xb9");
2556 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2558 if(!setlocale(LC_ALL
, "polish")) {
2559 win_skip("stricmp tests\n");
2563 ret
= _stricmp("test", "test");
2564 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2565 ret
= _stricmp("a", "z");
2566 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2567 ret
= _stricmp("z", "a");
2568 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2569 ret
= _stricmp("\xa5", "\xb9");
2570 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2572 setlocale(LC_ALL
, "C");
2575 static void test__wcstoi64(void)
2577 static const WCHAR digit
[] = { '9', 0 };
2578 static const WCHAR stock
[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2579 static const WCHAR tamil
[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2580 static const WCHAR thai
[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2581 static const WCHAR fullwidth
[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2582 static const WCHAR hex
[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
2585 unsigned __int64 ures
;
2588 if (!p_wcstoi64
|| !p_wcstoui64
) {
2589 win_skip("_wcstoi64 or _wcstoui64 not found\n");
2593 res
= p_wcstoi64(digit
, NULL
, 10);
2594 ok(res
== 9, "res != 9\n");
2595 res
= p_wcstoi64(stock
, &endpos
, 10);
2596 ok(res
== 0, "res != 0\n");
2597 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2598 res
= p_wcstoi64(tamil
, &endpos
, 10);
2599 ok(res
== 0, "res != 0\n");
2600 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2601 res
= p_wcstoi64(thai
, NULL
, 10);
2602 todo_wine
ok(res
== 9, "res != 9\n");
2603 res
= p_wcstoi64(fullwidth
, NULL
, 10);
2604 todo_wine
ok(res
== 9, "res != 9\n");
2605 res
= p_wcstoi64(hex
, NULL
, 16);
2606 todo_wine
ok(res
== 0x9f9, "res != 0x9f9\n");
2608 ures
= p_wcstoui64(digit
, NULL
, 10);
2609 ok(ures
== 9, "ures != 9\n");
2610 ures
= p_wcstoui64(stock
, &endpos
, 10);
2611 ok(ures
== 0, "ures != 0\n");
2612 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2613 ures
= p_wcstoui64(tamil
, &endpos
, 10);
2614 ok(ures
== 0, "ures != 0\n");
2615 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2616 ures
= p_wcstoui64(thai
, NULL
, 10);
2617 todo_wine
ok(ures
== 9, "ures != 9\n");
2618 ures
= p_wcstoui64(fullwidth
, NULL
, 10);
2619 todo_wine
ok(ures
== 9, "ures != 9\n");
2620 ures
= p_wcstoui64(hex
, NULL
, 16);
2621 todo_wine
ok(ures
== 0x9f9, "ures != 0x9f9\n");
2626 static void test_atoi(void)
2631 ok(r
== 0, "atoi(0) = %d\n", r
);
2634 ok(r
== -1, "atoi(-1) = %d\n", r
);
2637 ok(r
== 1, "atoi(1) = %d\n", r
);
2639 r
= atoi("4294967296");
2640 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
2643 static void test_strncpy(void)
2645 #define TEST_STRNCPY_LEN 10
2647 char dst
[TEST_STRNCPY_LEN
+ 1];
2648 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
2650 /* strlen(src) > TEST_STRNCPY_LEN */
2651 ret
= strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
2652 ok(ret
== dst
, "ret != dst\n");
2653 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2655 /* without null-terminated */
2656 ret
= strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
2657 ok(ret
== dst
, "ret != dst\n");
2658 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2660 /* strlen(src) < TEST_STRNCPY_LEN */
2661 strcpy(dst
, "0123456789");
2662 ret
= strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
2663 ok(ret
== dst
, "ret != dst\n");
2664 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
2665 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
2667 /* strlen(src) == TEST_STRNCPY_LEN */
2668 ret
= strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
2669 ok(ret
== dst
, "ret != dst\n");
2670 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2676 static const char xilstring
[]="c:/xilinx";
2679 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
2681 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
2682 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
2683 SET(pmemcpy
,"memcpy");
2684 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
2685 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
2686 SET(pmemcmp
,"memcmp");
2687 SET(p_mbctype
,"_mbctype");
2688 SET(p__mb_cur_max
,"__mb_cur_max");
2689 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
2690 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
2691 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
2692 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
2693 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
2694 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
2695 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
2696 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
2697 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
2698 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
2699 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
2700 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
2701 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
2702 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
2703 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
2704 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
2705 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
2706 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
2707 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
2708 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
2709 p_set_invalid_parameter_handler
= (void *) GetProcAddress(hMsvcrt
, "_set_invalid_parameter_handler");
2710 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
2711 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
2712 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
2713 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
2714 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
2715 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
2716 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
2717 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
2718 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
2719 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
2721 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2722 MFC42 CString::Insert seems to rely on that behaviour */
2723 strcpy(mem
,xilstring
);
2724 nLen
=strlen(xilstring
);
2725 pmemcpy(mem
+5, mem
,nLen
+1);
2726 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
2727 "Got result %s\n",mem
+5);
2729 /* run tolower tests first */