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 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
53 #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)); }
55 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
56 static int (__cdecl
*p_memcpy_s
)(void *, size_t, const void *, size_t);
57 static int (__cdecl
*p_memmove_s
)(void *, size_t, const void *, size_t);
58 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
59 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
60 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
61 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
62 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
63 static int (__cdecl
*p__mbscpy_s
)(unsigned char*, size_t, const unsigned char*);
64 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
65 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
66 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
67 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
68 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
69 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
70 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
71 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
72 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
73 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
74 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
75 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
76 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
77 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
78 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
79 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
80 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
81 static int *p__mb_cur_max
;
82 static unsigned char *p_mbctype
;
83 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
84 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
85 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
86 static int (__cdecl
*p_wctob
)(wint_t);
87 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
88 static int (__cdecl
*p_tolower
)(int);
89 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
90 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
91 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
93 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
94 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
96 static HMODULE hMsvcrt
;
98 static void test_swab( void ) {
99 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
100 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
101 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
102 char expected3
[] = "$";
109 /* Test 1 - normal even case */
110 memset(to
,'$', sizeof(to
));
111 memset(from
,'@', sizeof(from
));
113 memcpy(from
, original
, testsize
);
114 _swab( from
, to
, testsize
);
115 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
117 /* Test 2 - uneven case */
118 memset(to
,'$', sizeof(to
));
119 memset(from
,'@', sizeof(from
));
121 memcpy(from
, original
, testsize
);
122 _swab( from
, to
, testsize
);
123 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
125 /* Test 3 - from = to */
126 memset(to
,'$', sizeof(to
));
127 memset(from
,'@', sizeof(from
));
129 memcpy(to
, original
, testsize
);
130 _swab( to
, to
, testsize
);
131 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
133 /* Test 4 - 1 bytes */
134 memset(to
,'$', sizeof(to
));
135 memset(from
,'@', sizeof(from
));
137 memcpy(from
, original
, testsize
);
138 _swab( from
, to
, testsize
);
139 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
142 #if 0 /* use this to generate more tests */
144 static void test_codepage(int cp
)
150 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
153 printf("static int result_cp_%d_mbctype[] = { ", cp
);
154 for (i
= 1; i
< 257; i
++)
156 if (p_mbctype
[i
] != prev
)
158 printf("0x%x,%d, ", prev
, count
);
165 printf("0x%x,%d };\n", prev
, count
);
170 /* RLE-encoded mbctype tables for given codepages */
171 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
172 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
173 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
175 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
177 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
178 0x0,2, 0x4,32, 0xc,94, 0,1 };
180 static void test_cp_table(int cp
, int *result
)
186 for (i
= 0; i
< 256; i
++)
194 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
);
199 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
203 static void test_mbcp(void)
205 int mb_orig_max
= *p__mb_cur_max
;
206 int curr_mbcp
= _getmbcp();
207 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
208 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
209 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
210 unsigned char buf
[16];
216 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
217 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
218 * CP1252 (or the ACP?) so we test only a few ASCII characters */
220 expect_eq(p_mbctype
[10], 0, char, "%x");
221 expect_eq(p_mbctype
[50], 0, char, "%x");
222 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
223 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
224 expect_eq(p_mbctype
[128], 0, char, "%x");
226 expect_eq(p_mbctype
[10], 0, char, "%x");
227 expect_eq(p_mbctype
[50], 0, char, "%x");
228 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
229 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
230 expect_eq(p_mbctype
[128], 0, char, "%x");
232 /* double byte code pages */
239 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
);
240 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
241 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
242 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
243 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
244 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
245 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
248 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
249 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
250 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
251 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
252 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
253 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
254 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
255 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
256 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
258 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
259 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
260 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
261 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
264 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
265 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
266 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
267 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
268 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
269 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
270 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
271 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
272 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
274 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
275 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
276 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
277 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
278 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
279 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
282 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
283 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
284 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
285 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
286 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
287 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
288 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
289 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
290 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
292 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
293 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
294 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
295 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
296 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
297 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
300 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
301 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
302 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
304 /* _mbclen/_mbslen */
305 expect_eq(_mbclen(mbstring
), 2, int, "%d");
306 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
307 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
308 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
309 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
310 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
313 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
314 win_skip("mbrlen tests\n");
317 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
318 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
319 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
320 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
321 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
322 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
323 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
327 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
328 win_skip("mbrtowc tests\n");
332 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
333 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
334 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
335 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
336 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
337 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
338 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
339 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
340 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
341 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
342 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
343 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
344 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
345 ok(state
== 0, "incorrect state value (%x)\n", state
);
347 setlocale(LC_ALL
, "C");
349 /* _mbccpy/_mbsncpy */
350 memset(buf
, 0xff, sizeof(buf
));
351 _mbccpy(buf
, mbstring
);
352 expect_bin(buf
, "\xb0\xb1\xff", 3);
354 memset(buf
, 0xff, sizeof(buf
));
355 _mbsncpy(buf
, mbstring
, 1);
356 expect_bin(buf
, "\xb0\xb1\xff", 3);
357 memset(buf
, 0xff, sizeof(buf
));
358 _mbsncpy(buf
, mbstring
, 2);
359 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
360 memset(buf
, 0xff, sizeof(buf
));
361 _mbsncpy(buf
, mbstring
, 3);
362 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
363 memset(buf
, 0xff, sizeof(buf
));
364 _mbsncpy(buf
, mbstring
, 4);
365 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
366 memset(buf
, 0xff, sizeof(buf
));
367 _mbsncpy(buf
, mbstring
, 5);
368 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
369 memset(buf
, 0xff, sizeof(buf
));
370 _mbsncpy(buf
, mbsonlylead
, 6);
371 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
373 memset(buf
, 0xff, sizeof(buf
));
374 _mbsnbcpy(buf
, mbstring2
, 2);
375 expect_bin(buf
, "\xb0\xb1\xff", 3);
376 _mbsnbcpy(buf
, mbstring2
, 3);
377 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
378 _mbsnbcpy(buf
, mbstring2
, 4);
379 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
380 memset(buf
, 0xff, sizeof(buf
));
381 _mbsnbcpy(buf
, mbsonlylead
, 5);
382 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
385 step
= _mbsinc(mbstring
) - mbstring
;
386 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
387 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
388 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
390 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
391 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
392 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
393 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
394 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
395 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
396 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
397 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
398 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
399 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
400 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
401 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
402 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
403 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
404 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
405 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
406 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
407 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
409 /* functions that depend on locale codepage, not mbcp.
410 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
411 * (as of Wine 0.9.43)
413 GetCPInfo(GetACP(), &cp_info
);
414 if (cp_info
.MaxCharSize
== 1)
416 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
417 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
420 skip("Current locale has double-byte charset - could lead to false positives\n");
423 expect_eq(_ismbblead(0x80), 0, int, "%d");
425 expect_eq(_ismbblead(0x81), 1, int, "%d");
426 expect_eq(_ismbblead(0x83), 1, int, "%d");
428 expect_eq(_ismbblead(0x84), 1, int, "%d");
429 expect_eq(_ismbblead(0xd3), 1, int, "%d");
430 expect_eq(_ismbblead(0xd7), 0, int, "%d");
431 expect_eq(_ismbblead(0xd8), 1, int, "%d");
432 expect_eq(_ismbblead(0xd9), 1, int, "%d");
434 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
435 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
436 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
437 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
438 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
439 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
440 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
441 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
446 static void test_mbsspn( void)
448 unsigned char str1
[]="cabernet";
449 unsigned char str2
[]="shiraz";
450 unsigned char set
[]="abc";
451 unsigned char empty
[]="";
453 ret
=_mbsspn( str1
, set
);
454 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
455 ret
=_mbsspn( str2
, set
);
456 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
457 ret
=_mbsspn( str1
, empty
);
458 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
461 static void test_mbsspnp( void)
463 unsigned char str1
[]="cabernet";
464 unsigned char str2
[]="shiraz";
465 unsigned char set
[]="abc";
466 unsigned char empty
[]="";
467 unsigned char full
[]="abcenrt";
469 ret
=_mbsspnp( str1
, set
);
470 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
471 ret
=_mbsspnp( str2
, set
);
472 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
473 ret
=_mbsspnp( str1
, empty
);
474 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
475 ret
=_mbsspnp( str1
, full
);
476 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
479 static void test_strdup(void)
483 ok( str
== 0, "strdup returns %s should be 0\n", str
);
487 static void test_strcpy_s(void)
490 const char *small
= "small";
491 const char *big
= "atoolongstringforthislittledestination";
496 win_skip("strcpy_s not found\n");
500 memset(dest
, 'X', sizeof(dest
));
501 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
502 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
503 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
504 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
505 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
506 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
508 memset(dest
, 'X', sizeof(dest
));
509 ret
= pstrcpy_s(dest
, 0, big
);
510 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
511 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
512 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
513 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
514 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
515 ret
= pstrcpy_s(dest
, 0, NULL
);
516 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
517 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
518 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
519 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
520 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
522 memset(dest
, 'X', sizeof(dest
));
523 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
524 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
525 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
526 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
527 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
528 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
530 memset(dest
, 'X', sizeof(dest
));
531 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
532 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
533 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
534 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
535 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
536 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
538 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
539 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
542 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
544 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
545 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
546 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
547 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
548 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
550 static void test_memcpy_s(void)
553 static const char tiny
[] = {'T',0,'I','N','Y',0};
554 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
557 win_skip("memcpy_s not found\n");
562 memset(dest
, 'X', sizeof(dest
));
563 ret
= p_memcpy_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
564 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
565 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
567 /* Vary source size */
569 memset(dest
, 'X', sizeof(dest
));
570 ret
= p_memcpy_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
571 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
572 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
573 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
575 /* Replace source with NULL */
577 memset(dest
, 'X', sizeof(dest
));
578 ret
= p_memcpy_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
579 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
580 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
581 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
585 memset(dest
, 'X', sizeof(dest
));
586 ret
= p_memcpy_s(dest
, 0, tiny
, NUMELMS(tiny
));
587 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
588 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
589 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
591 /* Replace dest with NULL */
593 ret
= p_memcpy_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
594 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
595 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
599 memset(dest
, 'X', sizeof(dest
));
600 ret
= p_memcpy_s(dest
, 0, NULL
, NUMELMS(tiny
));
601 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
602 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
603 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
606 static void test_memmove_s(void)
609 static const char tiny
[] = {'T',0,'I','N','Y',0};
610 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
613 win_skip("memmove_s not found\n");
618 memset(dest
, 'X', sizeof(dest
));
619 ret
= p_memmove_s(dest
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
620 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
621 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
624 memcpy(dest
, big
, sizeof(dest
));
625 ret
= p_memmove_s(dest
+1, NUMELMS(dest
)-1, dest
, NUMELMS(dest
)-1);
626 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
627 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
629 /* Vary source size */
631 memset(dest
, 'X', sizeof(dest
));
632 ret
= p_memmove_s(dest
, NUMELMS(dest
), big
, NUMELMS(big
));
633 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
634 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
635 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
637 /* Replace source with NULL */
639 memset(dest
, 'X', sizeof(dest
));
640 ret
= p_memmove_s(dest
, NUMELMS(dest
), NULL
, NUMELMS(tiny
));
641 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
642 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
643 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
647 memset(dest
, 'X', sizeof(dest
));
648 ret
= p_memmove_s(dest
, 0, tiny
, NUMELMS(tiny
));
649 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
650 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
651 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
653 /* Replace dest with NULL */
655 ret
= p_memmove_s(NULL
, NUMELMS(dest
), tiny
, NUMELMS(tiny
));
656 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
657 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
661 memset(dest
, 'X', sizeof(dest
));
662 ret
= p_memmove_s(dest
, 0, NULL
, NUMELMS(tiny
));
663 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
664 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
665 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
668 static void test_strcat_s(void)
671 const char *small
= "sma";
676 win_skip("strcat_s not found\n");
680 memset(dest
, 'X', sizeof(dest
));
682 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
683 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
684 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
685 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
686 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
687 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
688 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
689 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
690 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
691 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
692 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
693 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
695 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
696 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
697 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
698 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
699 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
700 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
702 memset(dest
, 'X', sizeof(dest
));
706 ret
= pstrcat_s(dest
, 0, small
);
707 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
708 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
709 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
710 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
711 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
713 ret
= pstrcat_s(dest
, 0, NULL
);
714 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
715 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
716 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
717 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
718 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
720 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
721 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
722 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
723 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
724 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
725 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
727 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
728 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
731 static void test__mbsnbcpy_s(void)
733 unsigned char dest
[8];
734 const unsigned char big
[] = "atoolongstringforthislittledestination";
735 const unsigned char small
[] = "small";
740 win_skip("_mbsnbcpy_s not found\n");
744 memset(dest
, 'X', sizeof(dest
));
745 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
746 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
747 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
748 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
749 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
750 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
753 memset(dest
, 'X', sizeof(dest
));
754 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
755 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
756 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
757 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
758 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
759 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
761 memset(dest
, 'X', sizeof(dest
));
762 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
763 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
764 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
765 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
766 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
767 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
769 memset(dest
, 'X', sizeof(dest
));
770 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
771 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
772 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
773 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
774 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
775 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
778 static void test__mbscpy_s(void)
780 const unsigned char src
[] = "source string";
781 unsigned char dest
[16];
786 win_skip("_mbscpy_s not found\n");
790 ret
= p__mbscpy_s(NULL
, 0, src
);
791 ok(ret
== EINVAL
, "got %d\n", ret
);
792 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
793 ok(ret
== EINVAL
, "got %d\n", ret
);
794 ret
= p__mbscpy_s(dest
, 0, src
);
795 ok(ret
== EINVAL
, "got %d\n", ret
);
797 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
798 ok(ret
== EINVAL
, "got %d\n", ret
);
799 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
801 memset(dest
, 'X', sizeof(dest
));
802 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
803 ok(!ret
, "got %d\n", ret
);
804 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
805 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
807 memset(dest
, 'X', sizeof(dest
));
808 ret
= p__mbscpy_s(dest
, 4, src
);
809 ok(ret
== ERANGE
, "got %d\n", ret
);
810 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
811 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
814 static void test_wcscpy_s(void)
816 static const WCHAR szLongText
[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
817 static WCHAR szDest
[18];
818 static WCHAR szDestShort
[8];
823 win_skip("wcscpy_s not found\n");
829 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
830 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
831 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
833 /* Test NULL Source */
836 ret
= p_wcscpy_s(szDest
, 18, NULL
);
837 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
838 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
839 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
841 /* Test invalid size */
844 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
845 /* Later versions changed the return value for this case to EINVAL,
846 * and don't modify the result if the dest size is 0.
848 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
849 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
850 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
852 /* Copy same buffer size */
853 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
854 ok(ret
== 0, "expected 0 got %d\n", ret
);
855 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
857 /* Copy smaller buffer size */
860 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
861 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
862 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
863 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
867 win_skip("wcsncpy_s not found\n");
871 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
872 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
875 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
876 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
877 ok(szDest
[0] == 0, "szDest[0] not 0\n");
880 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
881 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
882 ok(szDest
[0] == 0, "szDest[0] not 0\n");
885 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
886 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
887 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
889 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
890 ok(ret
== 0, "expected 0 got %d\n", ret
);
891 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
894 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, sizeof(szLongText
)/sizeof(WCHAR
));
895 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
896 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
899 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
900 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
901 ok(szDest
[4] == 0, "szDest[4] not 0\n");
902 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
904 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
905 ok(ret
== 0, "ret = %d\n", ret
);
907 szDestShort
[0] = '1';
909 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
910 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
911 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
912 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
915 static void test__wcsupr_s(void)
917 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
918 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
919 static const WCHAR expectedString
[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
920 'W', 'E', 'R', 'U', 'P', 'P', 'E',
922 WCHAR testBuffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
927 win_skip("_wcsupr_s not found\n");
931 /* Test NULL input string and invalid size. */
933 ret
= p_wcsupr_s(NULL
, 0);
934 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
935 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
937 /* Test NULL input string and valid size. */
939 ret
= p_wcsupr_s(NULL
, sizeof(testBuffer
)/sizeof(WCHAR
));
940 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
941 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
943 /* Test empty string with zero size. */
945 testBuffer
[0] = '\0';
946 ret
= p_wcsupr_s(testBuffer
, 0);
947 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
948 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
949 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
951 /* Test empty string with size of one. */
952 testBuffer
[0] = '\0';
953 ret
= p_wcsupr_s(testBuffer
, 1);
954 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
955 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
957 /* Test one-byte buffer with zero size. */
960 ret
= p_wcsupr_s(testBuffer
, 0);
961 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
962 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
963 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
965 /* Test one-byte buffer with size of one. */
968 ret
= p_wcsupr_s(testBuffer
, 1);
969 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
970 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
971 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
973 /* Test invalid size. */
974 wcscpy(testBuffer
, mixedString
);
976 ret
= p_wcsupr_s(testBuffer
, 0);
977 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
978 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
979 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
981 /* Test normal string uppercasing. */
982 wcscpy(testBuffer
, mixedString
);
983 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
));
984 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
985 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
987 /* Test uppercasing with a shorter buffer size count. */
988 wcscpy(testBuffer
, mixedString
);
990 ret
= p_wcsupr_s(testBuffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
991 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
992 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
993 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
995 /* Test uppercasing with a longer buffer size count. */
996 wcscpy(testBuffer
, mixedString
);
997 ret
= p_wcsupr_s(testBuffer
, sizeof(testBuffer
)/sizeof(WCHAR
));
998 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
999 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1002 static void test__wcslwr_s(void)
1004 static const WCHAR mixedString
[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1005 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1006 static const WCHAR expectedString
[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1007 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1009 WCHAR buffer
[2*sizeof(mixedString
)/sizeof(WCHAR
)];
1014 win_skip("_wcslwr_s not found\n");
1018 /* Test NULL input string and invalid size. */
1020 ret
= p_wcslwr_s(NULL
, 0);
1021 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1022 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1024 /* Test NULL input string and valid size. */
1026 ret
= p_wcslwr_s(NULL
, sizeof(buffer
)/sizeof(wchar_t));
1027 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1028 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1030 /* Test empty string with zero size. */
1033 ret
= p_wcslwr_s(buffer
, 0);
1034 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1035 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1036 ok(buffer
[0] == 0, "expected empty string\n");
1038 /* Test empty string with size of one. */
1040 ret
= p_wcslwr_s(buffer
, 1);
1041 ok(ret
== 0, "got %d\n", ret
);
1042 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1044 /* Test one-byte buffer with zero size. */
1047 ret
= p_wcslwr_s(buffer
, 0);
1048 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1049 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1050 ok(buffer
[0] == '\0', "expected empty string\n");
1052 /* Test one-byte buffer with size of one. */
1055 ret
= p_wcslwr_s(buffer
, 1);
1056 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1057 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1058 ok(buffer
[0] == '\0', "expected empty string\n");
1060 /* Test invalid size. */
1061 wcscpy(buffer
, mixedString
);
1063 ret
= p_wcslwr_s(buffer
, 0);
1064 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1065 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1066 ok(buffer
[0] == '\0', "expected empty string\n");
1068 /* Test normal string uppercasing. */
1069 wcscpy(buffer
, mixedString
);
1070 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
));
1071 ok(ret
== 0, "expected 0, got %d\n", ret
);
1072 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1074 /* Test uppercasing with a shorter buffer size count. */
1075 wcscpy(buffer
, mixedString
);
1077 ret
= p_wcslwr_s(buffer
, sizeof(mixedString
)/sizeof(WCHAR
) - 1);
1078 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1079 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1080 ok(buffer
[0] == '\0', "expected empty string\n");
1082 /* Test uppercasing with a longer buffer size count. */
1083 wcscpy(buffer
, mixedString
);
1084 ret
= p_wcslwr_s(buffer
, sizeof(buffer
)/sizeof(WCHAR
));
1085 ok(ret
== 0, "expected 0, got %d\n", ret
);
1086 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1089 static void test_mbcjisjms(void)
1091 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1092 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1093 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1094 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1095 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1096 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1098 int prev_cp
= _getmbcp();
1100 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1103 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1105 unsigned int ret
, exp
;
1106 ret
= _mbcjistojms(jisjms
[j
][0]);
1107 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1108 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1109 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1115 static void test_mbcjmsjis(void)
1117 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1118 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1119 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1120 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1121 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1122 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1123 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1124 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1126 int prev_cp
= _getmbcp();
1128 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1131 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1133 unsigned int ret
, exp
;
1134 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1135 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1136 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1137 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1143 static void test_mbbtombc(void)
1145 static const unsigned int mbbmbc
[][2] = {
1146 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1147 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1148 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1149 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1150 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1152 int prev_cp
= _getmbcp();
1154 for (i
= 0; i
< sizeof(cp
)/sizeof(cp
[0]); i
++)
1157 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1159 unsigned int exp
, ret
;
1160 ret
= _mbbtombc(mbbmbc
[j
][0]);
1161 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1162 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1163 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1169 static void test_mbctombb(void)
1171 static const unsigned int mbcmbb_932
[][2] = {
1172 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1173 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1174 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1175 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1176 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1177 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1178 unsigned int exp
, ret
, i
;
1179 unsigned int prev_cp
= _getmbcp();
1182 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1184 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1185 exp
= mbcmbb_932
[i
][1];
1186 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1191 static void test_ismbclegal(void) {
1192 unsigned int prev_cp
= _getmbcp();
1196 _setmbcp(932); /* Japanese */
1198 for(i
= 0; i
< 0x10000; i
++) {
1199 ret
= _ismbclegal(i
);
1200 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1201 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1202 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1203 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1209 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1210 _setmbcp(936); /* Chinese (GBK) */
1212 for(i
= 0; i
< 0x10000; i
++) {
1213 ret
= _ismbclegal(i
);
1214 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1215 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1221 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1222 _setmbcp(949); /* Korean */
1224 for(i
= 0; i
< 0x10000; i
++) {
1225 ret
= _ismbclegal(i
);
1226 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1227 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1233 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1234 _setmbcp(950); /* Chinese (Big5) */
1236 for(i
= 0; i
< 0x10000; i
++) {
1237 ret
= _ismbclegal(i
);
1238 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1239 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1240 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1246 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1247 _setmbcp(1361); /* Korean (Johab) */
1249 for(i
= 0; i
< 0x10000; i
++) {
1250 ret
= _ismbclegal(i
);
1251 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1252 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1253 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1254 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1261 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1266 static const struct {
1268 const char* delimiter
;
1269 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1271 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1273 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1275 } testcases_strtok
[] = {
1276 { "red cabernet", " ", 0, 4, -1 },
1277 { "sparkling white riesling", " ", 0, 10, 16 },
1278 { " pale cream sherry", "e ", 1, 6, 9 },
1283 static void test_strtok(void)
1288 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1289 strcpy( teststr
, testcases_strtok
[i
].string
);
1290 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1291 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1292 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1293 "string (%p) \'%s\' return %p\n",
1294 teststr
, testcases_strtok
[i
].string
, strret
);
1295 if( !strret
) continue;
1296 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1297 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1298 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1299 "second call string (%p) \'%s\' return %p\n",
1300 teststr
, testcases_strtok
[i
].string
, strret
);
1301 if( !strret
) continue;
1302 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1303 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1304 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1305 "third call string (%p) \'%s\' return %p\n",
1306 teststr
, testcases_strtok
[i
].string
, strret
);
1310 static void test_strtol(void)
1316 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1317 /* errno is modified on W2K8+ */
1319 l
= strtol("-1234", &e
, 0);
1320 ok(l
==-1234, "wrong value %d\n", l
);
1321 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1323 ul
= strtoul("1234", &e
, 0);
1324 ok(ul
==1234, "wrong value %u\n", ul
);
1325 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1328 l
= strtol("2147483647L", &e
, 0);
1329 ok(l
==2147483647, "wrong value %d\n", l
);
1330 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1332 l
= strtol("-2147483648L", &e
, 0);
1333 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1334 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1336 ul
= strtoul("4294967295UL", &e
, 0);
1337 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1338 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1341 l
= strtol("9223372036854775807L", &e
, 0);
1342 ok(l
==2147483647, "wrong value %d\n", l
);
1343 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1345 ul
= strtoul("9223372036854775807L", &e
, 0);
1346 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1347 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1350 ul
= strtoul("-2", NULL
, 0);
1351 ok(ul
== -2, "wrong value %u\n", ul
);
1352 ok(errno
== 0, "wrong errno %d\n", errno
);
1355 ul
= strtoul("-4294967294", NULL
, 0);
1356 ok(ul
== 2, "wrong value %u\n", ul
);
1357 ok(errno
== 0, "wrong errno %d\n", errno
);
1360 ul
= strtoul("-4294967295", NULL
, 0);
1361 ok(ul
==1, "wrong value %u\n", ul
);
1362 ok(errno
== 0, "wrong errno %d\n", errno
);
1365 ul
= strtoul("-4294967296", NULL
, 0);
1366 ok(ul
== 1, "wrong value %u\n", ul
);
1367 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1370 static void test_strnlen(void)
1372 static const char str
[] = "string";
1376 win_skip("strnlen not found\n");
1380 res
= p_strnlen(str
, 20);
1381 ok(res
== 6, "Returned length = %d\n", (int)res
);
1383 res
= p_strnlen(str
, 3);
1384 ok(res
== 3, "Returned length = %d\n", (int)res
);
1386 res
= p_strnlen(NULL
, 0);
1387 ok(res
== 0, "Returned length = %d\n", (int)res
);
1390 static void test__strtoi64(void)
1392 static const char no1
[] = "31923";
1393 static const char no2
[] = "-213312";
1394 static const char no3
[] = "12aa";
1395 static const char no4
[] = "abc12";
1396 static const char overflow
[] = "99999999999999999999";
1397 static const char neg_overflow
[] = "-99999999999999999999";
1398 static const char hex
[] = "0x123";
1399 static const char oct
[] = "000123";
1400 static const char blanks
[] = " 12 212.31";
1403 unsigned __int64 ures
;
1406 if(!p_strtoi64
|| !p_strtoui64
) {
1407 win_skip("_strtoi64 or _strtoui64 not found\n");
1412 res
= p_strtoi64(no1
, NULL
, 10);
1413 ok(res
== 31923, "res != 31923\n");
1414 res
= p_strtoi64(no2
, NULL
, 10);
1415 ok(res
== -213312, "res != -213312\n");
1416 res
= p_strtoi64(no3
, NULL
, 10);
1417 ok(res
== 12, "res != 12\n");
1418 res
= p_strtoi64(no4
, &endpos
, 10);
1419 ok(res
== 0, "res != 0\n");
1420 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1421 res
= p_strtoi64(hex
, &endpos
, 10);
1422 ok(res
== 0, "res != 0\n");
1423 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1424 res
= p_strtoi64(oct
, &endpos
, 10);
1425 ok(res
== 123, "res != 123\n");
1426 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1427 res
= p_strtoi64(blanks
, &endpos
, 10);
1428 ok(res
== 12, "res != 12\n");
1429 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1430 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1433 res
= p_strtoi64(overflow
, &endpos
, 10);
1434 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1435 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1436 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1439 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1440 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1441 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1442 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1445 res
= p_strtoi64(no1
, &endpos
, 16);
1446 ok(res
== 203043, "res != 203043\n");
1447 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1448 res
= p_strtoi64(no2
, &endpos
, 16);
1449 ok(res
== -2175762, "res != -2175762\n");
1450 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1451 res
= p_strtoi64(no3
, &endpos
, 16);
1452 ok(res
== 4778, "res != 4778\n");
1453 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1454 res
= p_strtoi64(no4
, &endpos
, 16);
1455 ok(res
== 703506, "res != 703506\n");
1456 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1457 res
= p_strtoi64(hex
, &endpos
, 16);
1458 ok(res
== 291, "res != 291\n");
1459 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1460 res
= p_strtoi64(oct
, &endpos
, 16);
1461 ok(res
== 291, "res != 291\n");
1462 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1463 res
= p_strtoi64(blanks
, &endpos
, 16);
1464 ok(res
== 18, "res != 18\n");
1465 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1466 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1469 res
= p_strtoi64(hex
, &endpos
, 36);
1470 ok(res
== 1541019, "res != 1541019\n");
1471 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1472 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1475 res
= p_strtoi64(no1
, &endpos
, 0);
1476 ok(res
== 31923, "res != 31923\n");
1477 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1478 res
= p_strtoi64(no2
, &endpos
, 0);
1479 ok(res
== -213312, "res != -213312\n");
1480 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1481 res
= p_strtoi64(no3
, &endpos
, 10);
1482 ok(res
== 12, "res != 12\n");
1483 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1484 res
= p_strtoi64(no4
, &endpos
, 10);
1485 ok(res
== 0, "res != 0\n");
1486 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1487 res
= p_strtoi64(hex
, &endpos
, 10);
1488 ok(res
== 0, "res != 0\n");
1489 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1490 res
= p_strtoi64(oct
, &endpos
, 10);
1491 ok(res
== 123, "res != 123\n");
1492 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1493 res
= p_strtoi64(blanks
, &endpos
, 10);
1494 ok(res
== 12, "res != 12\n");
1495 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1496 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1499 ures
= p_strtoui64(no1
, &endpos
, 0);
1500 ok(ures
== 31923, "ures != 31923\n");
1501 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1502 ures
= p_strtoui64(no2
, &endpos
, 0);
1503 ok(ures
== -213312, "ures != -213312\n");
1504 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1505 ures
= p_strtoui64(no3
, &endpos
, 10);
1506 ok(ures
== 12, "ures != 12\n");
1507 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1508 ures
= p_strtoui64(no4
, &endpos
, 10);
1509 ok(ures
== 0, "ures != 0\n");
1510 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1511 ures
= p_strtoui64(hex
, &endpos
, 10);
1512 ok(ures
== 0, "ures != 0\n");
1513 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1514 ures
= p_strtoui64(oct
, &endpos
, 10);
1515 ok(ures
== 123, "ures != 123\n");
1516 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1517 ures
= p_strtoui64(blanks
, &endpos
, 10);
1518 ok(ures
== 12, "ures != 12\n");
1519 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1520 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1523 ures
= p_strtoui64(overflow
, &endpos
, 10);
1524 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1525 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1526 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1529 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1530 ok(ures
== 1, "ures != 1\n");
1531 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1532 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1535 static inline BOOL
almost_equal(double d1
, double d2
) {
1536 if(d1
-d2
>-1e-30 && d1
-d2
<1e-30)
1541 static void test__strtod(void)
1543 const char double1
[] = "12.1";
1544 const char double2
[] = "-13.721";
1545 const char double3
[] = "INF";
1546 const char double4
[] = ".21e12";
1547 const char double5
[] = "214353e-3";
1548 const char overflow
[] = "1d9999999999999999999";
1549 const char white_chars
[] = " d10";
1554 d
= strtod(double1
, &end
);
1555 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1556 ok(end
== double1
+4, "incorrect end (%d)\n", (int)(end
-double1
));
1558 d
= strtod(double2
, &end
);
1559 ok(almost_equal(d
, -13.721), "d = %lf\n", d
);
1560 ok(end
== double2
+7, "incorrect end (%d)\n", (int)(end
-double2
));
1562 d
= strtod(double3
, &end
);
1563 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1564 ok(end
== double3
, "incorrect end (%d)\n", (int)(end
-double3
));
1566 d
= strtod(double4
, &end
);
1567 ok(almost_equal(d
, 210000000000.0), "d = %lf\n", d
);
1568 ok(end
== double4
+6, "incorrect end (%d)\n", (int)(end
-double4
));
1570 d
= strtod(double5
, &end
);
1571 ok(almost_equal(d
, 214.353), "d = %lf\n", d
);
1572 ok(end
== double5
+9, "incorrect end (%d)\n", (int)(end
-double5
));
1574 d
= strtod("12.1d2", NULL
);
1575 ok(almost_equal(d
, 12.1e2
), "d = %lf\n", d
);
1577 d
= strtod(white_chars
, &end
);
1578 ok(almost_equal(d
, 0), "d = %lf\n", d
);
1579 ok(end
== white_chars
, "incorrect end (%d)\n", (int)(end
-white_chars
));
1581 /* Set locale with non '.' decimal point (',') */
1582 if(!setlocale(LC_ALL
, "Polish")) {
1583 win_skip("system with limited locales\n");
1587 d
= strtod("12.1", NULL
);
1588 ok(almost_equal(d
, 12.0), "d = %lf\n", d
);
1590 d
= strtod("12,1", NULL
);
1591 ok(almost_equal(d
, 12.1), "d = %lf\n", d
);
1593 setlocale(LC_ALL
, "C");
1595 /* Precision tests */
1596 d
= strtod("0.1", NULL
);
1597 ok(almost_equal(d
, 0.1), "d = %lf\n", d
);
1598 d
= strtod("-0.1", NULL
);
1599 ok(almost_equal(d
, -0.1), "d = %lf\n", d
);
1600 d
= strtod("0.1281832188491894198128921", NULL
);
1601 ok(almost_equal(d
, 0.1281832188491894198128921), "d = %lf\n", d
);
1602 d
= strtod("0.82181281288121", NULL
);
1603 ok(almost_equal(d
, 0.82181281288121), "d = %lf\n", d
);
1604 d
= strtod("21921922352523587651128218821", NULL
);
1605 ok(almost_equal(d
, 21921922352523587651128218821.0), "d = %lf\n", d
);
1606 d
= strtod("0.1d238", NULL
);
1607 ok(almost_equal(d
, 0.1e238L
), "d = %lf\n", d
);
1608 d
= strtod("0.1D-4736", NULL
);
1609 ok(almost_equal(d
, 0.1e-4736L), "d = %lf\n", d
);
1612 strtod(overflow
, &end
);
1613 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1614 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
1617 strtod("-1d309", NULL
);
1618 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1621 static void test_mbstowcs(void)
1623 static const wchar_t wSimple
[] = { 't','e','x','t',0 };
1624 static const wchar_t wHiragana
[] = { 0x3042,0x3043,0 };
1625 static const char mSimple
[] = "text";
1626 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
1628 const wchar_t *pwstr
;
1636 wOut
[4] = '!'; wOut
[5] = '\0';
1637 mOut
[4] = '!'; mOut
[5] = '\0';
1640 /* crashes on some systems */
1642 ret
= mbstowcs(wOut
, NULL
, 4);
1643 ok(ret
== -1, "mbstowcs did not return -1\n");
1644 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1647 ret
= mbstowcs(NULL
, mSimple
, 0);
1648 ok(ret
== 4, "mbstowcs did not return 4\n");
1650 ret
= mbstowcs(wOut
, mSimple
, 4);
1651 ok(ret
== 4, "mbstowcs did not return 4\n");
1652 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1653 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
1655 ret
= wcstombs(NULL
, wSimple
, 0);
1656 ok(ret
== 4, "wcstombs did not return 4\n");
1658 ret
= wcstombs(mOut
, wSimple
, 6);
1659 ok(ret
== 4, "wcstombs did not return 4\n");
1660 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1662 ret
= wcstombs(mOut
, wSimple
, 2);
1663 ok(ret
== 2, "wcstombs did not return 2\n");
1664 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
1666 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
1667 win_skip("Japanese_Japan.932 locale not available\n");
1671 ret
= mbstowcs(wOut
, mHiragana
, 6);
1672 ok(ret
== 2, "mbstowcs did not return 2\n");
1673 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1675 ret
= wcstombs(mOut
, wHiragana
, 6);
1676 ok(ret
== 4, "wcstombs did not return 4\n");
1677 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1679 if(!pmbstowcs_s
|| !pwcstombs_s
) {
1680 setlocale(LC_ALL
, "C");
1681 win_skip("mbstowcs_s or wcstombs_s not available\n");
1685 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
1686 ok(err
== 0, "err = %d\n", err
);
1687 ok(ret
== 5, "mbstowcs_s did not return 5\n");
1688 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1690 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
1691 ok(err
== 0, "err = %d\n", err
);
1692 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1693 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1695 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
1696 ok(err
== 0, "err = %d\n", err
);
1697 ok(ret
== 3, "mbstowcs_s did not return 3\n");
1699 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
1700 ok(err
== 0, "err = %d\n", err
);
1701 ok(ret
== 5, "wcstombs_s did not return 5\n");
1702 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1704 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
1705 ok(err
== 0, "err = %d\n", err
);
1706 ok(ret
== 5, "wcstombs_s did not return 5\n");
1707 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
1709 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
1710 ok(err
== 0, "err = %d\n", err
);
1711 ok(ret
== 5, "wcstombs_s did not return 5\n");
1714 setlocale(LC_ALL
, "C");
1715 win_skip("wcsrtombs not available\n");
1721 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
1722 ok(ret
== 4, "wcsrtombs did not return 4\n");
1723 ok(err
== 0, "err = %d\n", err
);
1724 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
1725 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
1728 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
1729 ok(ret
== 4, "wcsrtombs did not return 4\n");
1730 ok(pwstr
== NULL
, "pwstr != NULL\n");
1731 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
1734 setlocale(LC_ALL
, "C");
1735 win_skip("mbsrtowcs not available\n");
1740 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
1741 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1742 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
1743 ok(!pmbstr
, "pmbstr != NULL\n");
1745 state
= mHiragana
[0];
1746 pmbstr
= mHiragana
+1;
1747 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
1748 ok(ret
== 2, "mbsrtowcs did not return 2\n");
1749 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
1750 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
1751 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
1752 ok(!pmbstr
, "pmbstr != NULL\n");
1755 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
1756 ok(ret
== -1, "mbsrtowcs did not return -1\n");
1757 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1759 setlocale(LC_ALL
, "C");
1762 static void test_gcvt(void)
1764 char buf
[1024], *res
;
1768 win_skip("Skipping _gcvt tests\n");
1773 res
= _gcvt(1.2, -1, buf
);
1774 ok(res
== NULL
, "res != NULL\n");
1775 ok(errno
== ERANGE
, "errno = %d\n", errno
);
1778 res
= _gcvt(1.2, 5, NULL
);
1779 ok(res
== NULL
, "res != NULL\n");
1780 ok(errno
== EINVAL
, "errno = %d\n", errno
);
1782 res
= gcvt(1.2, 5, buf
);
1783 ok(res
== buf
, "res != buf\n");
1784 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
1787 err
= p_gcvt_s(buf
, 5, 1.2, 10);
1788 ok(err
== ERANGE
, "err = %d\n", err
);
1789 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1792 err
= p_gcvt_s(buf
, 4, 123456, 2);
1793 ok(err
== ERANGE
, "err = %d\n", err
);
1794 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
1797 static void test__itoa_s(void)
1804 win_skip("Skipping _itoa_s tests\n");
1809 ret
= p_itoa_s(0, NULL
, 0, 0);
1810 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1811 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1813 memset(buffer
, 'X', sizeof(buffer
));
1815 ret
= p_itoa_s(0, buffer
, 0, 0);
1816 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1817 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1818 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
1820 memset(buffer
, 'X', sizeof(buffer
));
1822 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
1823 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1824 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1825 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1827 memset(buffer
, 'X', sizeof(buffer
));
1829 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
1830 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
1831 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1832 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
1834 memset(buffer
, 'X', sizeof(buffer
));
1836 ret
= p_itoa_s(12345678, buffer
, 4, 10);
1837 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1838 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1839 ok(!memcmp(buffer
, "\000765", 4),
1840 "Expected the output buffer to be null terminated with truncated output\n");
1842 memset(buffer
, 'X', sizeof(buffer
));
1844 ret
= p_itoa_s(12345678, buffer
, 8, 10);
1845 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1846 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1847 ok(!memcmp(buffer
, "\0007654321", 8),
1848 "Expected the output buffer to be null terminated with truncated output\n");
1850 memset(buffer
, 'X', sizeof(buffer
));
1852 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
1853 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
1854 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
1855 ok(!memcmp(buffer
, "\00087654321", 9),
1856 "Expected the output buffer to be null terminated with truncated output\n");
1858 ret
= p_itoa_s(12345678, buffer
, 9, 10);
1859 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1860 ok(!strcmp(buffer
, "12345678"),
1861 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1864 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
1865 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1866 ok(!strcmp(buffer
, "1010101010101010"),
1867 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1870 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
1871 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1872 ok(!strcmp(buffer
, "nell"),
1873 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1876 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
1877 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1878 ok(!strcmp(buffer
, "hag"),
1879 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1882 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
1883 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
1884 ok(!strcmp(buffer
, "-12345678"),
1885 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1888 itoa(100, buffer
, 100);
1889 ok(!strcmp(buffer
, "10"),
1890 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
1893 static void test__strlwr_s(void)
1900 win_skip("Skipping _strlwr_s tests\n");
1905 ret
= p_strlwr_s(NULL
, 0);
1906 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1907 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1910 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
1911 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1912 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1915 ret
= p_strlwr_s(buffer
, 0);
1916 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1917 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1919 strcpy(buffer
, "GoRrIsTeR");
1921 ret
= p_strlwr_s(buffer
, 5);
1922 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1923 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1924 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1925 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1927 strcpy(buffer
, "GoRrIsTeR");
1929 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
1930 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
1931 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1932 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1933 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1935 strcpy(buffer
, "GoRrIsTeR");
1936 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
1937 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1938 ok(!strcmp(buffer
, "gorrister"),
1939 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1942 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1943 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
1944 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
1945 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1946 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1950 static void test_wcsncat_s(void)
1952 static wchar_t abcW
[] = {'a','b','c',0};
1959 win_skip("skipping wcsncat_s tests\n");
1963 memcpy(src
, abcW
, sizeof(abcW
));
1965 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
1966 ok(ret
== EINVAL
, "err = %d\n", ret
);
1967 ret
= p_wcsncat_s(dst
, 0, src
, 4);
1968 ok(ret
== EINVAL
, "err = %d\n", ret
);
1969 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
1970 ok(ret
== EINVAL
, "err = %d\n", ret
);
1971 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
1972 ok(ret
== 0, "err = %d\n", ret
);
1975 ret
= p_wcsncat_s(dst
, 2, src
, 4);
1976 ok(ret
== ERANGE
, "err = %d\n", ret
);
1979 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
1980 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
1981 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
1983 memcpy(dst
, abcW
, sizeof(abcW
));
1985 ret
= p_wcsncat_s(dst
, 4, src
, 4);
1986 ok(ret
== EINVAL
, "err = %d\n", ret
);
1989 static void test__mbsnbcat_s(void)
1991 unsigned char dest
[16];
1992 const unsigned char first
[] = "dinosaur";
1993 const unsigned char second
[] = "duck";
1998 win_skip("Skipping _mbsnbcat_s tests\n");
2002 /* Test invalid arguments. */
2003 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2004 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2007 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2008 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2009 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2012 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2013 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2014 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2016 memset(dest
, 'X', sizeof(dest
));
2018 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2019 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2020 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2021 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2023 memset(dest
, 'X', sizeof(dest
));
2025 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2026 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2027 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2028 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2030 memset(dest
, 'X', sizeof(dest
));
2032 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2033 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2034 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2035 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2037 memset(dest
, 'X', sizeof(dest
));
2039 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
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] == '\0', "Expected the output buffer to be null terminated\n");
2044 memset(dest
, 'X', sizeof(dest
));
2046 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2047 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2048 ok(!memcmp(dest
, second
, sizeof(second
)),
2049 "Expected the output buffer string to be \"duck\"\n");
2051 /* Test source truncation behavior. */
2052 memset(dest
, 'X', sizeof(dest
));
2053 memcpy(dest
, first
, sizeof(first
));
2054 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2055 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2056 ok(!memcmp(dest
, first
, sizeof(first
)),
2057 "Expected the output buffer string to be \"dinosaur\"\n");
2059 memset(dest
, 'X', sizeof(dest
));
2060 memcpy(dest
, first
, sizeof(first
));
2061 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2062 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2063 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2064 "Expected the output buffer string to be \"dinosaurduck\"\n");
2066 memset(dest
, 'X', sizeof(dest
));
2067 memcpy(dest
, first
, sizeof(first
));
2068 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2069 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2070 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2071 "Expected the output buffer string to be \"dinosaurduck\"\n");
2073 memset(dest
, 'X', sizeof(dest
));
2074 memcpy(dest
, first
, sizeof(first
));
2075 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2076 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2077 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2078 "Expected the output buffer string to be \"dinosaurduck\"\n");
2080 memset(dest
, 'X', sizeof(dest
));
2081 memcpy(dest
, first
, sizeof(first
));
2082 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2083 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2084 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2085 "Expected the output buffer string to be \"dinosaurduc\"\n");
2087 /* Test destination truncation behavior. */
2088 memset(dest
, 'X', sizeof(dest
));
2089 memcpy(dest
, first
, sizeof(first
));
2091 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2092 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2093 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2094 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2095 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2097 memset(dest
, 'X', sizeof(dest
));
2098 memcpy(dest
, first
, sizeof(first
));
2100 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2101 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2102 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2103 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2104 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2106 memset(dest
, 'X', sizeof(dest
));
2107 memcpy(dest
, first
, sizeof(first
));
2109 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2110 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2111 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2112 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2113 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2116 static void test__mbsupr_s(void)
2119 unsigned char buffer
[20];
2123 win_skip("Skipping _mbsupr_s tests\n");
2128 ret
= p_mbsupr_s(NULL
, 0);
2129 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2132 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2133 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2134 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2137 ret
= p_mbsupr_s(buffer
, 0);
2138 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2139 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2141 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2143 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2144 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2145 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2146 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2149 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2151 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2152 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2153 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2154 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2157 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2159 ret
= p_mbsupr_s(buffer
, 4);
2160 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2161 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2163 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2165 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2166 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2167 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2168 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2173 static void test__mbslwr_s(void)
2176 unsigned char buffer
[20];
2180 win_skip("Skipping _mbslwr_s tests\n");
2185 ret
= p_mbslwr_s(NULL
, 0);
2186 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2189 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2190 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2191 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2194 ret
= p_mbslwr_s(buffer
, 0);
2195 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2196 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2198 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2200 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2201 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2202 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2203 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2206 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2208 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2209 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2210 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2211 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2214 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2216 ret
= p_mbslwr_s(buffer
, 4);
2217 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2218 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2220 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2222 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2223 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2224 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2225 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2229 static void test__mbstok(void)
2231 const unsigned char delim
[] = "t";
2233 char str
[] = "!.!test";
2238 ret
= _mbstok(NULL
, delim
);
2239 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2240 ok(!ret
|| broken((char*)ret
==str
+4),
2241 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2243 ret
= _mbstok(NULL
, delim
);
2244 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2247 static void test__ultoa_s(void)
2254 win_skip("Skipping _ultoa_s tests\n");
2259 ret
= p_ultoa_s(0, NULL
, 0, 0);
2260 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2261 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2263 memset(buffer
, 'X', sizeof(buffer
));
2265 ret
= p_ultoa_s(0, buffer
, 0, 0);
2266 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2267 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2268 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2270 memset(buffer
, 'X', sizeof(buffer
));
2272 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2273 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2274 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2275 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2277 memset(buffer
, 'X', sizeof(buffer
));
2279 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2280 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2281 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2282 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2284 memset(buffer
, 'X', sizeof(buffer
));
2286 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2287 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2288 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2289 ok(!memcmp(buffer
, "\000765", 4),
2290 "Expected the output buffer to be null terminated with truncated output\n");
2292 memset(buffer
, 'X', sizeof(buffer
));
2294 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2295 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2296 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2297 ok(!memcmp(buffer
, "\0007654321", 8),
2298 "Expected the output buffer to be null terminated with truncated output\n");
2300 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2301 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2302 ok(!strcmp(buffer
, "12345678"),
2303 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2306 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2307 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2308 ok(!strcmp(buffer
, "1010101010101010"),
2309 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2312 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2313 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2314 ok(!strcmp(buffer
, "nell"),
2315 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2318 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2319 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2320 ok(!strcmp(buffer
, "hag"),
2321 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2325 static void test_wctob(void)
2329 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2330 win_skip("Skipping wctob tests\n");
2334 ret
= p_wctob(0x8141);
2335 ok(ret
== EOF
, "ret = %x\n", ret
);
2337 ret
= p_wctob(0x81);
2338 ok(ret
== EOF
, "ret = %x\n", ret
);
2340 ret
= p_wctob(0xe0);
2341 ok(ret
== 0x61, "ret = %x\n", ret
);
2344 ret
= p_wctob(0x81);
2345 ok(ret
== EOF
, "ret = %x\n", ret
);
2347 setlocale(LC_ALL
, "C");
2348 ret
= p_wctob(0x8141);
2349 ok(ret
== EOF
, "ret = %x\n", ret
);
2351 ret
= p_wctob(0x81);
2352 ok(ret
== (int)(char)0x81, "ret = %x\n", ret
);
2354 ret
= p_wctob(0x9f);
2355 ok(ret
== (int)(char)0x9f, "ret = %x\n", ret
);
2357 ret
= p_wctob(0xe0);
2358 ok(ret
== (int)(char)0xe0, "ret = %x\n", ret
);
2360 static void test_wctomb(void)
2363 unsigned char dst
[10];
2366 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
2367 win_skip("wcrtomb tests\n");
2371 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
2372 ok(ret
== 2, "wcrtomb did not return 2\n");
2376 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
2377 ok(ret
== 2, "wcrtomb did not return 2\n");
2378 ok(state
== 0, "state != 0\n");
2379 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2380 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
2381 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
2383 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
2384 ok(ret
== 2, "wcrtomb did not return 2\n");
2385 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
2386 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
2388 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
2389 ok(ret
== 1, "wcrtomb did not return 1\n");
2390 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
2392 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
2393 ok(ret
== -1, "wcrtomb did not return -1\n");
2394 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
2396 setlocale(LC_ALL
, "C");
2399 static void test_tolower(void)
2404 /* test C locale when locale was never changed */
2405 ret
= p_tolower(0x41);
2406 ok(ret
== 0x61, "ret = %x\n", ret
);
2408 ret
= p_tolower(0xF4);
2409 ok(ret
== 0xF4, "ret = %x\n", ret
);
2412 ret
= p_tolower((char)0xF4);
2413 todo_wine
ok(ret
== (char)0xF4, "ret = %x\n", ret
);
2414 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2417 ret
= p_tolower((char)0xD0);
2418 todo_wine
ok(ret
== (char)0xD0, "ret = %x\n", ret
);
2419 todo_wine
ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2421 /* test C locale after setting locale */
2422 if(!setlocale(LC_ALL
, "us")) {
2423 win_skip("skipping tolower tests that depends on locale\n");
2426 setlocale(LC_ALL
, "C");
2430 ret
= p_tolower(ch
);
2431 len
= LCMapStringA(0, LCMAP_LOWERCASE
, &ch
, 1, &lch
, 1);
2433 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2435 ok(ret
== ch
, "ret = %x\n", ret
);
2436 if(!len
|| ret
==(unsigned char)lch
)
2437 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2441 ret
= p_tolower(ch
);
2442 len
= LCMapStringA(0, LCMAP_LOWERCASE
, &ch
, 1, &lch
, 1);
2444 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
2446 ok(ret
== ch
, "ret = %x\n", ret
);
2447 if(!len
|| ret
==(unsigned char)lch
)
2448 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2450 ret
= p_tolower(0xD0);
2451 ok(ret
== 0xD0, "ret = %x\n", ret
);
2453 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
2455 ret
= p_tolower((char)0xD0);
2456 ok(ret
== 0xF0, "ret = %x\n", ret
);
2458 ret
= p_tolower(0xD0);
2459 ok(ret
== 0xF0, "ret = %x\n", ret
);
2461 setlocale(LC_ALL
, "C");
2464 static void test__atodbl(void)
2471 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2472 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2473 win_skip("_atodbl_l is not available\n");
2478 ret
= p__atodbl_l(&d
, num
, NULL
);
2479 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
2480 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2481 ret
= _atodbl(&d
, num
);
2482 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
2483 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2486 ret
= p__atodbl_l(&d
, num
, NULL
);
2487 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
2488 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2489 ret
= _atodbl(&d
, num
);
2490 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
2491 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2494 ret
= p__atodbl_l(&d
, num
, NULL
);
2495 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
2496 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2497 ret
= _atodbl(&d
, num
);
2498 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
2499 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
2502 ret
= p__atodbl_l(&d
, num
, NULL
);
2503 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
2504 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2505 ret
= _atodbl(&d
, num
);
2506 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
2507 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
2509 strcpy(num
, "1e-309");
2510 ret
= p__atodbl_l(&d
, num
, NULL
);
2511 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
2512 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2513 ret
= _atodbl(&d
, num
);
2514 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
2515 ok(d
.x
!=0 && almost_equal(d
.x
, 0), "d.x = %le, expected 0\n", d
.x
);
2517 strcpy(num
, "1e309");
2518 ret
= p__atodbl_l(&d
, num
, NULL
);
2519 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
2520 ret
= _atodbl(&d
, num
);
2521 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
2524 static void test__stricmp(void)
2528 ret
= _stricmp("test", "test");
2529 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2530 ret
= _stricmp("a", "z");
2531 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2532 ret
= _stricmp("z", "a");
2533 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2534 ret
= _stricmp("\xa5", "\xb9");
2535 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2537 if(!setlocale(LC_ALL
, "polish")) {
2538 win_skip("stricmp tests\n");
2542 ret
= _stricmp("test", "test");
2543 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2544 ret
= _stricmp("a", "z");
2545 ok(ret
< 0, "_stricmp returned %d\n", ret
);
2546 ret
= _stricmp("z", "a");
2547 ok(ret
> 0, "_stricmp returned %d\n", ret
);
2548 ret
= _stricmp("\xa5", "\xb9");
2549 ok(ret
== 0, "_stricmp returned %d\n", ret
);
2551 setlocale(LC_ALL
, "C");
2554 static void test__wcstoi64(void)
2556 static const WCHAR digit
[] = { '9', 0 };
2557 static const WCHAR stock
[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2558 static const WCHAR tamil
[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2559 static const WCHAR thai
[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2560 static const WCHAR fullwidth
[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2561 static const WCHAR hex
[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
2564 unsigned __int64 ures
;
2567 if (!p_wcstoi64
|| !p_wcstoui64
) {
2568 win_skip("_wcstoi64 or _wcstoui64 not found\n");
2572 res
= p_wcstoi64(digit
, NULL
, 10);
2573 ok(res
== 9, "res != 9\n");
2574 res
= p_wcstoi64(stock
, &endpos
, 10);
2575 ok(res
== 0, "res != 0\n");
2576 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2577 res
= p_wcstoi64(tamil
, &endpos
, 10);
2578 ok(res
== 0, "res != 0\n");
2579 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2580 res
= p_wcstoi64(thai
, NULL
, 10);
2581 todo_wine
ok(res
== 9, "res != 9\n");
2582 res
= p_wcstoi64(fullwidth
, NULL
, 10);
2583 todo_wine
ok(res
== 9, "res != 9\n");
2584 res
= p_wcstoi64(hex
, NULL
, 16);
2585 todo_wine
ok(res
== 0x9f9, "res != 0x9f9\n");
2587 ures
= p_wcstoui64(digit
, NULL
, 10);
2588 ok(ures
== 9, "ures != 9\n");
2589 ures
= p_wcstoui64(stock
, &endpos
, 10);
2590 ok(ures
== 0, "ures != 0\n");
2591 ok(endpos
== stock
, "Incorrect endpos (%p-%p)\n", stock
, endpos
);
2592 ures
= p_wcstoui64(tamil
, &endpos
, 10);
2593 ok(ures
== 0, "ures != 0\n");
2594 ok(endpos
== tamil
, "Incorrect endpos (%p-%p)\n", tamil
, endpos
);
2595 ures
= p_wcstoui64(thai
, NULL
, 10);
2596 todo_wine
ok(ures
== 9, "ures != 9\n");
2597 ures
= p_wcstoui64(fullwidth
, NULL
, 10);
2598 todo_wine
ok(ures
== 9, "ures != 9\n");
2599 ures
= p_wcstoui64(hex
, NULL
, 16);
2600 todo_wine
ok(ures
== 0x9f9, "ures != 0x9f9\n");
2605 static void test_atoi(void)
2610 ok(r
== 0, "atoi(0) = %d\n", r
);
2613 ok(r
== -1, "atoi(-1) = %d\n", r
);
2616 ok(r
== 1, "atoi(1) = %d\n", r
);
2618 r
= atoi("4294967296");
2619 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
2622 static void test_strncpy(void)
2624 #define TEST_STRNCPY_LEN 10
2626 char dst
[TEST_STRNCPY_LEN
+ 1];
2627 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
2629 /* strlen(src) > TEST_STRNCPY_LEN */
2630 ret
= strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
2631 ok(ret
== dst
, "ret != dst\n");
2632 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2634 /* without null-terminated */
2635 ret
= strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
2636 ok(ret
== dst
, "ret != dst\n");
2637 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2639 /* strlen(src) < TEST_STRNCPY_LEN */
2640 strcpy(dst
, "0123456789");
2641 ret
= strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
2642 ok(ret
== dst
, "ret != dst\n");
2643 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
2644 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
2646 /* strlen(src) == TEST_STRNCPY_LEN */
2647 ret
= strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
2648 ok(ret
== dst
, "ret != dst\n");
2649 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
2652 static void test_strxfrm(void)
2657 /* crashes on old version of msvcrt */
2660 ret
= strxfrm(NULL
, "src", 1);
2661 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
2662 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2665 ret
= strxfrm(dest
, NULL
, 100);
2666 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
2667 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2670 ret
= strxfrm(NULL
, "src", 0);
2671 ok(ret
== 3, "ret = %d\n", (int)ret
);
2673 ret
= strxfrm(dest
, "src", 0);
2674 ok(ret
== 3, "ret = %d\n", (int)ret
);
2675 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
2678 ret
= strxfrm(dest
, "src", 5);
2679 ok(ret
== 3, "ret = %d\n", (int)ret
);
2680 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
2684 ret
= strxfrm(dest
, "src", 1);
2685 ok(ret
== 3, "ret = %d\n", (int)ret
);
2686 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
2687 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
2688 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
2690 ret
= strxfrm(dest
, "", 5);
2691 ok(ret
== 0, "ret = %d\n", (int)ret
);
2692 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
2694 if(!setlocale(LC_ALL
, "polish")) {
2695 win_skip("stxfrm tests\n");
2699 ret
= strxfrm(NULL
, "src", 0);
2700 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2702 ret
= strxfrm(dest
, "src", 0);
2703 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2704 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
2706 ret
= strxfrm(dest
, "src", ret
+1);
2707 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2708 ok(dest
[0], "dest[0] = 0\n");
2712 ret
= strxfrm(dest
, "src", 5);
2713 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
2714 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
2716 setlocale(LC_ALL
, "C");
2722 static const char xilstring
[]="c:/xilinx";
2725 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
2727 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
2728 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
2729 SET(pmemcpy
,"memcpy");
2730 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
2731 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
2732 SET(pmemcmp
,"memcmp");
2733 SET(p_mbctype
,"_mbctype");
2734 SET(p__mb_cur_max
,"__mb_cur_max");
2735 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
2736 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
2737 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
2738 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
2739 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
2740 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
2741 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
2742 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
2743 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
2744 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
2745 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
2746 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
2747 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
2748 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
2749 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
2750 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
2751 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
2752 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
2753 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
2754 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
2755 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
2756 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
2757 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
2758 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
2759 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
2760 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
2761 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
2762 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
2763 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
2764 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
2765 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
2767 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2768 MFC42 CString::Insert seems to rely on that behaviour */
2769 strcpy(mem
,xilstring
);
2770 nLen
=strlen(xilstring
);
2771 pmemcpy(mem
+5, mem
,nLen
+1);
2772 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
2773 "Got result %s\n",mem
+5);
2775 /* run tolower tests first */