2 * Unit test suite for string functions.
4 * Copyright 2004 Uwe Bonnes
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
34 /* make it use a definition from string.h */
40 static char *buf_to_string(const unsigned char *bin
, int len
, int nr
)
42 static char buf
[2][1024];
46 for (i
= 0; i
< len
; i
++)
48 sprintf(w
, "%02x ", (unsigned char)bin
[i
]);
54 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
55 #define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); }
57 static void* (__cdecl
*pmemcpy
)(void *, const void *, size_t n
);
58 static int (__cdecl
*p_memcpy_s
)(void *, size_t, const void *, size_t);
59 static int (__cdecl
*p_memmove_s
)(void *, size_t, const void *, size_t);
60 static int* (__cdecl
*pmemcmp
)(void *, const void *, size_t n
);
61 static int (__cdecl
*p_strcmp
)(const char *, const char *);
62 static int (__cdecl
*p_strncmp
)(const char *, const char *, size_t);
63 static int (__cdecl
*p_strcpy
)(char *dst
, const char *src
);
64 static int (__cdecl
*pstrcpy_s
)(char *dst
, size_t len
, const char *src
);
65 static int (__cdecl
*pstrcat_s
)(char *dst
, size_t len
, const char *src
);
66 static int (__cdecl
*p_mbscat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
);
67 static int (__cdecl
*p_mbsnbcat_s
)(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t count
);
68 static int (__cdecl
*p_mbsnbcpy_s
)(unsigned char * dst
, size_t size
, const unsigned char * src
, size_t count
);
69 static int (__cdecl
*p__mbscpy_s
)(unsigned char*, size_t, const unsigned char*);
70 static int (__cdecl
*p_wcscpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
);
71 static int (__cdecl
*p_wcsncpy_s
)(wchar_t *wcDest
, size_t size
, const wchar_t *wcSrc
, size_t count
);
72 static int (__cdecl
*p_wcsncat_s
)(wchar_t *dst
, size_t elem
, const wchar_t *src
, size_t count
);
73 static int (__cdecl
*p_wcsupr_s
)(wchar_t *str
, size_t size
);
74 static size_t (__cdecl
*p_strnlen
)(const char *, size_t);
75 static __int64 (__cdecl
*p_strtoi64
)(const char *, char **, int);
76 static unsigned __int64 (__cdecl
*p_strtoui64
)(const char *, char **, int);
77 static __int64 (__cdecl
*p_wcstoi64
)(const wchar_t *, wchar_t **, int);
78 static unsigned __int64 (__cdecl
*p_wcstoui64
)(const wchar_t *, wchar_t **, int);
79 static int (__cdecl
*pwcstombs_s
)(size_t*,char*,size_t,const wchar_t*,size_t);
80 static int (__cdecl
*p_wcstombs_s_l
)(size_t*,char*,size_t,const wchar_t*,size_t,_locale_t
);
81 static int (__cdecl
*pmbstowcs_s
)(size_t*,wchar_t*,size_t,const char*,size_t);
82 static size_t (__cdecl
*p_mbsrtowcs
)(wchar_t*, const char**, size_t, mbstate_t*);
83 static int (__cdecl
*p_mbsrtowcs_s
)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
84 static size_t (__cdecl
*pwcsrtombs
)(char*, const wchar_t**, size_t, int*);
85 static errno_t (__cdecl
*p_gcvt_s
)(char*,size_t,double,int);
86 static errno_t (__cdecl
*p_itoa_s
)(int,char*,size_t,int);
87 static errno_t (__cdecl
*p_strlwr_s
)(char*,size_t);
88 static errno_t (__cdecl
*p_ultoa_s
)(__msvcrt_ulong
,char*,size_t,int);
89 static int *p__mb_cur_max
;
90 static unsigned char *p_mbctype
;
91 static int (__cdecl
*p_wcslwr_s
)(wchar_t*,size_t);
92 static errno_t (__cdecl
*p_mbsupr_s
)(unsigned char *str
, size_t numberOfElements
);
93 static errno_t (__cdecl
*p_mbslwr_s
)(unsigned char *str
, size_t numberOfElements
);
94 static int (__cdecl
*p_wctob
)(wint_t);
95 static wint_t (__cdecl
*p_btowc
)(int);
96 static size_t (__cdecl
*p_wcrtomb
)(char*, wchar_t, mbstate_t*);
97 static int (__cdecl
*p_wcrtomb_s
)(size_t*, char*, size_t, wchar_t, mbstate_t*);
98 static int (__cdecl
*p_tolower
)(int);
99 static int (__cdecl
*p_towlower
)(wint_t);
100 static int (__cdecl
*p__towlower_l
)(wint_t, _locale_t
);
101 static int (__cdecl
*p_towupper
)(wint_t);
102 static int (__cdecl
*p__towupper_l
)(wint_t, _locale_t
);
103 static _locale_t(__cdecl
*p__create_locale
)(int, const char*);
104 static void(__cdecl
*p__free_locale
)(_locale_t
);
105 static size_t (__cdecl
*p_mbrlen
)(const char*, size_t, mbstate_t*);
106 static size_t (__cdecl
*p_mbrtowc
)(wchar_t*, const char*, size_t, mbstate_t*);
107 static int (__cdecl
*p__atodbl_l
)(_CRT_DOUBLE
*,char*,_locale_t
);
108 static double (__cdecl
*p__atof_l
)(const char*,_locale_t
);
109 static double (__cdecl
*p__strtod_l
)(const char *,char**,_locale_t
);
110 static int (__cdecl
*p__strnset_s
)(char*,size_t,int,size_t);
111 static int (__cdecl
*p__wcsnset_s
)(wchar_t*,size_t,wchar_t,size_t);
112 static int (__cdecl
*p__wcsset_s
)(wchar_t*,size_t,wchar_t);
113 static size_t (__cdecl
*p__mbsnlen
)(const unsigned char*, size_t);
114 static int (__cdecl
*p__mbccpy_s
)(unsigned char*, size_t, int*, const unsigned char*);
115 static int (__cdecl
*p__memicmp
)(const char*, const char*, size_t);
116 static int (__cdecl
*p__memicmp_l
)(const char*, const char*, size_t, _locale_t
);
117 static size_t (__cdecl
*p___strncnt
)(const char*, size_t);
118 static unsigned int (__cdecl
*p_mbsnextc_l
)(const unsigned char*, _locale_t
);
119 static int (__cdecl
*p_mbscmp_l
)(const unsigned char*, const unsigned char*, _locale_t
);
121 int CDECL
__STRINGTOLD(_LDOUBLE
*, char**, const char*, int);
123 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
124 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
126 static HMODULE hMsvcrt
;
128 static void test_swab( void ) {
129 char original
[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
130 char expected1
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
131 char expected2
[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
132 char expected3
[] = "$";
139 /* Test 1 - normal even case */
140 memset(to
,'$', sizeof(to
));
141 memset(from
,'@', sizeof(from
));
143 memcpy(from
, original
, testsize
);
144 _swab( from
, to
, testsize
);
145 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing even size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
147 /* Test 2 - uneven case */
148 memset(to
,'$', sizeof(to
));
149 memset(from
,'@', sizeof(from
));
151 memcpy(from
, original
, testsize
);
152 _swab( from
, to
, testsize
);
153 ok(memcmp(to
,expected2
,testsize
) == 0, "Testing odd size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
155 /* Test 3 - from = to */
156 memset(to
,'$', sizeof(to
));
157 memset(from
,'@', sizeof(from
));
159 memcpy(to
, original
, testsize
);
160 _swab( to
, to
, testsize
);
161 ok(memcmp(to
,expected1
,testsize
) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
163 /* Test 4 - 1 bytes */
164 memset(to
,'$', sizeof(to
));
165 memset(from
,'@', sizeof(from
));
167 memcpy(from
, original
, testsize
);
168 _swab( from
, to
, testsize
);
169 ok(memcmp(to
,expected3
,testsize
) == 0, "Testing small size %d returned '%*.*s'\n", testsize
, testsize
, testsize
, to
);
172 static void test_strcspn(void)
174 static const struct {
183 { "a\xf1", "\xf1", 1 }
187 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
189 r
= strcspn(tests
[i
].str
, tests
[i
].rej
);
190 ok(r
== tests
[i
].ret
, "strcspn(\"%s\", \"%s\") = %d, expected %d\n",
191 tests
[i
].str
, tests
[i
].rej
, r
, tests
[i
].ret
);
195 #if 0 /* use this to generate more tests */
197 static void test_codepage(int cp
)
203 ok(_setmbcp(cp
) == 0, "Couldn't set mbcp\n");
206 printf("static int result_cp_%d_mbctype[] = { ", cp
);
207 for (i
= 1; i
< 257; i
++)
209 if (p_mbctype
[i
] != prev
)
211 printf("0x%x,%d, ", prev
, count
);
218 printf("0x%x,%d };\n", prev
, count
);
223 /* RLE-encoded mbctype tables for given codepages */
224 static int result_cp_932_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
225 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
226 static int result_cp_936_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
228 static int result_cp_949_mbctype
[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
230 static int result_cp_950_mbctype
[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
231 0x0,2, 0x4,32, 0xc,94, 0,1 };
233 static void test_cp_table(int cp
, int *result
)
239 for (i
= 0; i
< 256; i
++)
247 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
);
252 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
256 static void test_mbcp(void)
258 int mb_orig_max
= *p__mb_cur_max
;
259 int curr_mbcp
= _getmbcp();
260 unsigned char *mbstring
= (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
261 unsigned char *mbstring2
= (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
262 unsigned char *mbsonlylead
= (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
263 unsigned char buf
[16];
269 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
270 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
271 * CP1252 (or the ACP?) so we test only a few ASCII characters */
273 expect_eq(p_mbctype
[10], 0, char, "%x");
274 expect_eq(p_mbctype
[50], 0, char, "%x");
275 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
276 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
277 expect_eq(p_mbctype
[128], 0, char, "%x");
279 expect_eq(p_mbctype
[10], 0, char, "%x");
280 expect_eq(p_mbctype
[50], 0, char, "%x");
281 expect_eq(p_mbctype
[66], _SBUP
, char, "%x");
282 expect_eq(p_mbctype
[100], _SBLOW
, char, "%x");
283 expect_eq(p_mbctype
[128], 0, char, "%x");
285 /* double byte code pages */
292 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
);
293 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
294 ok(_ismbblead(' ') == FALSE
, "' ' should not be a lead byte\n");
295 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
296 ok(_ismbblead(0x123420) == FALSE
, "0x123420 should not be a lead byte\n");
297 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
298 ok(_ismbbtrail(' ') == FALSE
, "' ' should not be a trail byte\n");
301 expect_eq(_ismbslead(mbstring
, &mbstring
[0]), -1, int, "%d");
302 expect_eq(_ismbslead(mbstring
, &mbstring
[1]), FALSE
, int, "%d");
303 expect_eq(_ismbslead(mbstring
, &mbstring
[2]), -1, int, "%d");
304 expect_eq(_ismbslead(mbstring
, &mbstring
[3]), FALSE
, int, "%d");
305 expect_eq(_ismbslead(mbstring
, &mbstring
[4]), -1, int, "%d");
306 expect_eq(_ismbslead(mbstring
, &mbstring
[5]), FALSE
, int, "%d");
307 expect_eq(_ismbslead(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
308 expect_eq(_ismbslead(mbstring
, &mbstring
[7]), -1, int, "%d");
309 expect_eq(_ismbslead(mbstring
, &mbstring
[8]), FALSE
, int, "%d");
311 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[0]), -1, int, "%d");
312 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[1]), FALSE
, int, "%d");
313 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
314 expect_eq(_ismbslead(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
317 expect_eq(_ismbstrail(mbstring
, &mbstring
[0]), FALSE
, int, "%d");
318 expect_eq(_ismbstrail(mbstring
, &mbstring
[1]), -1, int, "%d");
319 expect_eq(_ismbstrail(mbstring
, &mbstring
[2]), FALSE
, int, "%d");
320 expect_eq(_ismbstrail(mbstring
, &mbstring
[3]), -1, int, "%d");
321 expect_eq(_ismbstrail(mbstring
, &mbstring
[4]), FALSE
, int, "%d");
322 expect_eq(_ismbstrail(mbstring
, &mbstring
[5]), -1, int, "%d");
323 expect_eq(_ismbstrail(mbstring
, &mbstring
[6]), FALSE
, int, "%d");
324 expect_eq(_ismbstrail(mbstring
, &mbstring
[7]), FALSE
, int, "%d");
325 expect_eq(_ismbstrail(mbstring
, &mbstring
[8]), -1, int, "%d");
327 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[0]), FALSE
, int, "%d");
328 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[1]), -1, int, "%d");
329 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[2]), FALSE
, int, "%d");
330 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[3]), FALSE
, int, "%d");
331 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[4]), FALSE
, int, "%d");
332 expect_eq(_ismbstrail(mbsonlylead
, &mbsonlylead
[5]), FALSE
, int, "%d");
335 expect_eq(_mbsbtype(mbstring
, 0), _MBC_LEAD
, int, "%d");
336 expect_eq(_mbsbtype(mbstring
, 1), _MBC_TRAIL
, int, "%d");
337 expect_eq(_mbsbtype(mbstring
, 2), _MBC_LEAD
, int, "%d");
338 expect_eq(_mbsbtype(mbstring
, 3), _MBC_ILLEGAL
, int, "%d");
339 expect_eq(_mbsbtype(mbstring
, 4), _MBC_LEAD
, int, "%d");
340 expect_eq(_mbsbtype(mbstring
, 5), _MBC_TRAIL
, int, "%d");
341 expect_eq(_mbsbtype(mbstring
, 6), _MBC_SINGLE
, int, "%d");
342 expect_eq(_mbsbtype(mbstring
, 7), _MBC_LEAD
, int, "%d");
343 expect_eq(_mbsbtype(mbstring
, 8), _MBC_ILLEGAL
, int, "%d");
345 expect_eq(_mbsbtype(mbsonlylead
, 0), _MBC_LEAD
, int, "%d");
346 expect_eq(_mbsbtype(mbsonlylead
, 1), _MBC_ILLEGAL
, int, "%d");
347 expect_eq(_mbsbtype(mbsonlylead
, 2), _MBC_ILLEGAL
, int, "%d");
348 expect_eq(_mbsbtype(mbsonlylead
, 3), _MBC_ILLEGAL
, int, "%d");
349 expect_eq(_mbsbtype(mbsonlylead
, 4), _MBC_ILLEGAL
, int, "%d");
350 expect_eq(_mbsbtype(mbsonlylead
, 5), _MBC_ILLEGAL
, int, "%d");
353 expect_eq(_mbsnextc(mbstring
), 0xb0b1, int, "%x");
354 expect_eq(_mbsnextc(&mbstring
[2]), 0xb220, int, "%x"); /* lead + invalid tail */
355 expect_eq(_mbsnextc(&mbstring
[3]), 0x20, int, "%x"); /* single char */
358 win_skip("_mbsnextc_l tests\n");
360 expect_eq(p_mbsnextc_l(mbstring
, NULL
), 0xb0b1, int, "%x");
362 /* _mbclen/_mbslen */
363 expect_eq(_mbclen(mbstring
), 2, int, "%d");
364 expect_eq(_mbclen(&mbstring
[2]), 2, int, "%d");
365 expect_eq(_mbclen(&mbstring
[3]), 1, int, "%d");
366 expect_eq(_mbslen(mbstring2
), 4, int, "%d");
367 expect_eq(_mbslen(mbsonlylead
), 0, int, "%d"); /* lead + NUL not counted as character */
368 expect_eq(_mbslen(mbstring
), 4, int, "%d"); /* lead + invalid trail counted */
371 win_skip("_mbsnlen tests\n");
373 expect_eq(p__mbsnlen(mbstring
, 8), 8, int, "%d");
374 expect_eq(p__mbsnlen(mbstring
, 9), 4, int, "%d");
375 expect_eq(p__mbsnlen(mbstring
, 10), 4, int, "%d");
376 expect_eq(p__mbsnlen(mbsonlylead
, 0), 0, int, "%d");
377 expect_eq(p__mbsnlen(mbsonlylead
, 1), 1, int, "%d");
378 expect_eq(p__mbsnlen(mbsonlylead
, 2), 0, int, "%d");
379 expect_eq(p__mbsnlen(mbstring2
, 7), 7, int, "%d");
380 expect_eq(p__mbsnlen(mbstring2
, 8), 4, int, "%d");
381 expect_eq(p__mbsnlen(mbstring2
, 9), 4, int, "%d");
385 if(!setlocale(LC_ALL
, ".936") || !p_mbrlen
) {
386 win_skip("mbrlen tests\n");
389 expect_eq(p_mbrlen((const char*)mbstring
, 2, NULL
), 2, int, "%d");
390 expect_eq(p_mbrlen((const char*)&mbstring
[2], 2, NULL
), 2, int, "%d");
391 expect_eq(p_mbrlen((const char*)&mbstring
[3], 2, NULL
), 1, int, "%d");
392 expect_eq(p_mbrlen((const char*)mbstring
, 1, NULL
), -2, int, "%d");
393 expect_eq(p_mbrlen((const char*)mbstring
, 1, &state
), -2, int, "%d");
394 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
395 expect_eq(p_mbrlen((const char*)&mbstring
[1], 1, &state
), 2, int, "%d");
399 if(!setlocale(LC_ALL
, ".936") || !p_mbrtowc
) {
400 win_skip("mbrtowc tests\n");
404 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 2, NULL
), 2, int, "%d");
405 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
406 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+2, 2, NULL
), 2, int, "%d");
407 ok(dst
== 0x3f, "dst = %x, expected 0x3f\n", dst
);
408 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+3, 2, NULL
), 1, int, "%d");
409 ok(dst
== 0x20, "dst = %x, expected 0x20\n", dst
);
410 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, NULL
), -2, int, "%d");
411 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
412 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
, 1, &state
), -2, int, "%d");
413 ok(dst
== 0, "dst = %x, expected 0\n", dst
);
414 ok(state
== mbstring
[0], "incorrect state value (%x)\n", state
);
415 expect_eq(p_mbrtowc(&dst
, (const char*)mbstring
+1, 1, &state
), 2, int, "%d");
416 ok(dst
== 0x6c28, "dst = %x, expected 0x6c28\n", dst
);
417 ok(state
== 0, "incorrect state value (%x)\n", state
);
419 setlocale(LC_ALL
, "C");
421 /* _mbccpy/_mbsncpy */
422 memset(buf
, 0xff, sizeof(buf
));
423 _mbccpy(buf
, mbstring
);
424 expect_bin(buf
, "\xb0\xb1\xff", 3);
427 win_skip("_mbccpy_s tests\n");
431 memset(buf
, 0xff, sizeof(buf
));
433 err
= p__mbccpy_s(buf
, 0, &copied
, mbstring
);
434 ok(err
== EINVAL
, "_mbccpy_s returned %d\n", err
);
435 ok(!copied
, "copied = %d\n", copied
);
436 ok(buf
[0] == 0xff, "buf[0] = %x\n", buf
[0]);
438 memset(buf
, 0xff, sizeof(buf
));
440 err
= p__mbccpy_s(buf
, 1, &copied
, mbstring
);
441 ok(err
== ERANGE
, "_mbccpy_s returned %d\n", err
);
442 ok(!copied
, "copied = %d\n", copied
);
443 ok(!buf
[0], "buf[0] = %x\n", buf
[0]);
445 memset(buf
, 0xff, sizeof(buf
));
447 err
= p__mbccpy_s(buf
, 2, &copied
, mbstring
);
448 ok(!err
, "_mbccpy_s returned %d\n", err
);
449 ok(copied
== 2, "copied = %d\n", copied
);
450 expect_bin(buf
, "\xb0\xb1\xff", 3);
452 memset(buf
, 0xff, sizeof(buf
));
454 err
= p__mbccpy_s(buf
, 2, &copied
, (unsigned char *)"\xb0");
455 ok(err
== EILSEQ
, "_mbccpy_s returned %d\n", err
);
456 ok(copied
== 1, "copied = %d\n", copied
);
457 expect_bin(buf
, "\x00\xff", 2);
460 memset(buf
, 0xff, sizeof(buf
));
461 _mbsncpy(buf
, mbstring
, 1);
462 expect_bin(buf
, "\xb0\xb1\xff", 3);
463 memset(buf
, 0xff, sizeof(buf
));
464 _mbsncpy(buf
, mbstring
, 2);
465 expect_bin(buf
, "\xb0\xb1\xb2 \xff", 5);
466 memset(buf
, 0xff, sizeof(buf
));
467 _mbsncpy(buf
, mbstring
, 3);
468 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
469 memset(buf
, 0xff, sizeof(buf
));
470 _mbsncpy(buf
, mbstring
, 4);
471 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
472 memset(buf
, 0xff, sizeof(buf
));
473 _mbsncpy(buf
, mbstring
, 5);
474 expect_bin(buf
, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
475 memset(buf
, 0xff, sizeof(buf
));
476 _mbsncpy(buf
, mbsonlylead
, 6);
477 expect_bin(buf
, "\0\0\0\0\0\0\0\xff", 8);
479 memset(buf
, 0xff, sizeof(buf
));
480 _mbsnbcpy(buf
, mbstring2
, 2);
481 expect_bin(buf
, "\xb0\xb1\xff", 3);
482 _mbsnbcpy(buf
, mbstring2
, 3);
483 expect_bin(buf
, "\xb0\xb1\0\xff", 4);
484 _mbsnbcpy(buf
, mbstring2
, 4);
485 expect_bin(buf
, "\xb0\xb1\xb2\xb3\xff", 5);
486 memset(buf
, 0xff, sizeof(buf
));
487 _mbsnbcpy(buf
, mbsonlylead
, 5);
488 expect_bin(buf
, "\0\0\0\0\0\xff", 6);
491 step
= _mbsinc(mbstring
) - mbstring
;
492 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
493 step
= _mbsinc(&mbstring
[2]) - &mbstring
[2]; /* lead + invalid tail */
494 ok(step
== 2, "_mbsinc adds %d (exp. 2)\n", step
);
496 step
= _mbsninc(mbsonlylead
, 1) - mbsonlylead
;
497 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
498 step
= _mbsninc(mbsonlylead
, 2) - mbsonlylead
; /* lead + NUL byte + lead + char */
499 ok(step
== 0, "_mbsninc adds %d (exp. 0)\n", step
);
500 step
= _mbsninc(mbstring2
, 0) - mbstring2
;
501 ok(step
== 0, "_mbsninc adds %d (exp. 2)\n", step
);
502 step
= _mbsninc(mbstring2
, 1) - mbstring2
;
503 ok(step
== 2, "_mbsninc adds %d (exp. 2)\n", step
);
504 step
= _mbsninc(mbstring2
, 2) - mbstring2
;
505 ok(step
== 4, "_mbsninc adds %d (exp. 4)\n", step
);
506 step
= _mbsninc(mbstring2
, 3) - mbstring2
;
507 ok(step
== 5, "_mbsninc adds %d (exp. 5)\n", step
);
508 step
= _mbsninc(mbstring2
, 4) - mbstring2
;
509 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
510 step
= _mbsninc(mbstring2
, 5) - mbstring2
;
511 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
512 step
= _mbsninc(mbstring2
, 17) - mbstring2
;
513 ok(step
== 7, "_mbsninc adds %d (exp. 7)\n", step
);
515 /* functions that depend on locale codepage, not mbcp.
516 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
517 * (as of Wine 0.9.43)
519 GetCPInfo(GetACP(), &cp_info
);
520 if (cp_info
.MaxCharSize
== 1)
522 expect_eq(mblen((char *)mbstring
, 3), 1, int, "%x");
523 expect_eq(_mbstrlen((char *)mbstring2
), 7, int, "%d");
526 skip("Current locale has double-byte charset - could lead to false positives\n");
529 expect_eq(_ismbblead(0x80), 0, int, "%d");
531 expect_eq(_ismbblead(0x81), 1, int, "%d");
532 expect_eq(_ismbblead(0x83), 1, int, "%d");
534 expect_eq(_ismbblead(0x84), 1, int, "%d");
535 expect_eq(_ismbblead(0xd3), 1, int, "%d");
536 expect_eq(_ismbblead(0xd7), 0, int, "%d");
537 expect_eq(_ismbblead(0xd8), 1, int, "%d");
538 expect_eq(_ismbblead(0xd9), 1, int, "%d");
540 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
541 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
542 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
543 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
544 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
545 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
546 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
547 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
552 static void test_mbsspn( void)
554 unsigned char str1
[]="cabernet";
555 unsigned char str2
[]="shiraz";
556 unsigned char set
[]="abc";
557 unsigned char empty
[]="";
558 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
559 unsigned char mbset1
[]="0123456789 \x94\x4e";
560 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
561 unsigned char mbset3
[]="\x8e";
562 int ret
, cp
= _getmbcp();
564 ret
=_mbsspn( str1
, set
);
565 ok( ret
==3, "_mbsspn returns %d should be 3\n", ret
);
566 ret
=_mbsspn( str2
, set
);
567 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
568 ret
=_mbsspn( str1
, empty
);
569 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
571 ret
=_mbscspn( str1
, set
);
572 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
573 ret
=_mbscspn( str2
, set
);
574 ok( ret
==4, "_mbscspn returns %d should be 4\n", ret
);
575 ret
=_mbscspn( str1
, empty
);
576 ok( ret
==8, "_mbscspn returns %d should be 8\n", ret
);
579 ret
=_mbsspn( mbstr
, mbset1
);
580 ok( ret
==8, "_mbsspn returns %d should be 8\n", ret
);
581 ret
=_mbsspn( mbstr
, mbset2
);
582 ok( ret
==1, "_mbsspn returns %d should be 1\n", ret
);
583 ret
=_mbsspn( mbstr
+8, mbset1
);
584 ok( ret
==0, "_mbsspn returns %d should be 0\n", ret
);
585 ret
=_mbsspn( mbstr
+8, mbset2
);
586 ok( ret
==2, "_mbsspn returns %d should be 2\n", ret
);
587 ret
=_mbsspn( mbstr
, mbset3
);
588 ok( ret
==14, "_mbsspn returns %d should be 14\n", ret
);
590 ret
=_mbscspn( mbstr
, mbset1
);
591 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
592 ret
=_mbscspn( mbstr
, mbset2
);
593 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
594 ret
=_mbscspn( mbstr
+8, mbset1
);
595 ok( ret
==2, "_mbscspn returns %d should be 2\n", ret
);
596 ret
=_mbscspn( mbstr
+8, mbset2
);
597 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
598 ret
=_mbscspn( mbstr
, mbset3
);
599 ok( ret
==0, "_mbscspn returns %d should be 0\n", ret
);
604 static void test_mbsspnp( void)
606 unsigned char str1
[]="cabernet";
607 unsigned char str2
[]="shiraz";
608 unsigned char set
[]="abc";
609 unsigned char empty
[]="";
610 unsigned char full
[]="abcenrt";
611 unsigned char mbstr
[]=" 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
612 unsigned char mbset1
[]="0123456789 \x94\x4e";
613 unsigned char mbset2
[]=" \x94\x4e\x8c\x8e";
617 ret
=_mbsspnp( str1
, set
);
618 ok( ret
[0]=='e', "_mbsspnp returns %c should be e\n", ret
[0]);
619 ret
=_mbsspnp( str2
, set
);
620 ok( ret
[0]=='s', "_mbsspnp returns %c should be s\n", ret
[0]);
621 ret
=_mbsspnp( str1
, empty
);
622 ok( ret
[0]=='c', "_mbsspnp returns %c should be c\n", ret
[0]);
623 ret
=_mbsspnp( str1
, full
);
624 ok( ret
==NULL
, "_mbsspnp returns %p should be NULL\n", ret
);
627 ret
=_mbsspnp( mbstr
, mbset1
);
628 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
629 ret
=_mbsspnp( mbstr
, mbset2
);
630 ok( ret
==mbstr
+1, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+1);
631 ret
=_mbsspnp( mbstr
+8, mbset1
);
632 ok( ret
==mbstr
+8, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+8);
633 ret
=_mbsspnp( mbstr
+8, mbset2
);
634 ok( ret
==mbstr
+10, "_mbsspnp returns %p should be %p\n", ret
, mbstr
+10);
639 static void test_strdup(void)
643 ok( str
== 0, "strdup returns %s should be 0\n", str
);
647 static void test_strcmp(void)
649 int ret
= p_strcmp( "abc", "abcd" );
650 ok( ret
== -1, "wrong ret %d\n", ret
);
651 ret
= p_strcmp( "", "abc" );
652 ok( ret
== -1, "wrong ret %d\n", ret
);
653 ret
= p_strcmp( "abc", "ab\xa0" );
654 ok( ret
== -1, "wrong ret %d\n", ret
);
655 ret
= p_strcmp( "ab\xb0", "ab\xa0" );
656 ok( ret
== 1, "wrong ret %d\n", ret
);
657 ret
= p_strcmp( "ab\xc2", "ab\xc2" );
658 ok( ret
== 0, "wrong ret %d\n", ret
);
660 ret
= p_strncmp( "abc", "abcd", 3 );
661 ok( ret
== 0, "wrong ret %d\n", ret
);
662 ret
= p_strncmp( "", "abc", 3 );
663 ok( ret
== 0 - 'a' || ret
== -1, "wrong ret %d\n", ret
);
664 ret
= p_strncmp( "abc", "ab\xa0", 4 );
665 ok( ret
== 'c' - 0xa0 || ret
== -1, "wrong ret %d\n", ret
);
666 ret
= p_strncmp( "ab\xb0", "ab\xa0", 3 );
667 ok( ret
== 0xb0 - 0xa0 || ret
== 1, "wrong ret %d\n", ret
);
668 ret
= p_strncmp( "ab\xb0", "ab\xa0", 2 );
669 ok( ret
== 0, "wrong ret %d\n", ret
);
670 ret
= p_strncmp( "ab\xc2", "ab\xc2", 3 );
671 ok( ret
== 0, "wrong ret %d\n", ret
);
672 ret
= p_strncmp( "abc", "abd", 0 );
673 ok( ret
== 0, "wrong ret %d\n", ret
);
674 ret
= p_strncmp( "abc", "abc", 12 );
675 ok( ret
== 0, "wrong ret %d\n", ret
);
678 static void test_strcpy_s(void)
681 const char small
[] = "small";
682 const char big
[] = "atoolongstringforthislittledestination";
687 win_skip("strcpy_s not found\n");
691 memset(dest
, 'X', sizeof(dest
));
692 ret
= pstrcpy_s(dest
, sizeof(dest
), small
);
693 ok(ret
== 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret
);
694 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
695 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
696 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
697 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
699 memset(dest
, 'X', sizeof(dest
));
700 ret
= pstrcpy_s(dest
, 0, big
);
701 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
702 ok(dest
[0] == 'X' && dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
703 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
704 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
705 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
706 ret
= pstrcpy_s(dest
, 0, NULL
);
707 ok(ret
== EINVAL
, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret
);
708 ok(dest
[0] == 'X' && dest
[1] == 'X' && 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 memset(dest
, 'X', sizeof(dest
));
714 ret
= pstrcpy_s(dest
, sizeof(dest
), big
);
715 ok(ret
== ERANGE
, "Copying a big string in a small location returned %d, expected ERANGE\n", ret
);
716 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
717 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'n' && dest
[7] == 'g',
718 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
719 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
721 memset(dest
, 'X', sizeof(dest
));
722 ret
= pstrcpy_s(dest
, sizeof(dest
), NULL
);
723 ok(ret
== EINVAL
, "Copying from a NULL source string returned %d, expected EINVAL\n", ret
);
724 ok(dest
[0] == '\0'&& dest
[1] == 'X' && dest
[2] == 'X' && dest
[3] == 'X' &&
725 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
726 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
727 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
729 ret
= pstrcpy_s(NULL
, sizeof(dest
), small
);
730 ok(ret
== EINVAL
, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret
);
732 /* strcpy overlapping buffers test */
733 memset(dest
, 'X', sizeof(dest
));
734 memcpy(dest
+1, small
, sizeof(small
));
735 p_strcpy(dest
, dest
+1);
736 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
737 dest
[4] == 'l' && dest
[5] == '\0' && dest
[6] == '\0' && dest
[7] == 'X',
738 "Unexpected return data from strcpy: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
739 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
742 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
743 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
744 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
745 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
746 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
748 static void test_memcpy_s(void)
750 static char dest
[8], buf
[32];
751 static const char tiny
[] = {'T',0,'I','N','Y',0};
752 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
755 win_skip("memcpy_s not found\n");
760 memset(dest
, 'X', sizeof(dest
));
761 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
762 ok(ret
== 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret
);
763 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
765 /* Vary source size */
767 memset(dest
, 'X', sizeof(dest
));
768 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
769 ok(ret
== ERANGE
, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
770 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
771 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
773 /* Replace source with NULL */
775 memset(dest
, 'X', sizeof(dest
));
776 ret
= p_memcpy_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
777 ok(ret
== EINVAL
, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret
);
778 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
779 okchars(dest
, 0, 0, 0, 0, 0, 0, 0, 0);
783 memset(dest
, 'X', sizeof(dest
));
784 ret
= p_memcpy_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
785 ok(ret
== ERANGE
, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret
);
786 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
787 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
789 /* Replace dest with NULL */
791 ret
= p_memcpy_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
792 ok(ret
== EINVAL
, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
793 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
797 memset(dest
, 'X', sizeof(dest
));
798 ret
= p_memcpy_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
799 ok(ret
== EINVAL
, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
800 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
801 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
803 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), big
, ARRAY_SIZE(big
));
804 ok(!ret
, "memcpy_s returned %d\n", ret
);
805 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
807 ret
= p_memcpy_s(buf
+ 1, ARRAY_SIZE(buf
) - 1, buf
, ARRAY_SIZE(big
));
808 ok(!ret
, "memcpy_s returned %d\n", ret
);
809 ok(!memcmp(buf
+ 1, big
, sizeof(big
)), "unexpected buf\n");
811 ret
= p_memcpy_s(buf
, ARRAY_SIZE(buf
), buf
+ 1, ARRAY_SIZE(big
));
812 ok(!ret
, "memcpy_s returned %d\n", ret
);
813 ok(!memcmp(buf
, big
, sizeof(big
)), "unexpected buf\n");
816 static void test_memmove_s(void)
819 static const char tiny
[] = {'T',0,'I','N','Y',0};
820 static const char big
[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
823 win_skip("memmove_s not found\n");
828 memset(dest
, 'X', sizeof(dest
));
829 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
830 ok(ret
== 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret
);
831 okchars(dest
, tiny
[0], tiny
[1], tiny
[2], tiny
[3], tiny
[4], tiny
[5], 'X', 'X');
834 memcpy(dest
, big
, sizeof(dest
));
835 ret
= p_memmove_s(dest
+1, ARRAY_SIZE(dest
)-1, dest
, ARRAY_SIZE(dest
)-1);
836 ok(ret
== 0, "Moving a buffer up one char returned %d, expected 0\n", ret
);
837 okchars(dest
, big
[0], big
[0], big
[1], big
[2], big
[3], big
[4], big
[5], big
[6]);
839 /* Vary source size */
841 memset(dest
, 'X', sizeof(dest
));
842 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), big
, ARRAY_SIZE(big
));
843 ok(ret
== ERANGE
, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret
);
844 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
845 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
847 /* Replace source with NULL */
849 memset(dest
, 'X', sizeof(dest
));
850 ret
= p_memmove_s(dest
, ARRAY_SIZE(dest
), NULL
, ARRAY_SIZE(tiny
));
851 ok(ret
== EINVAL
, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret
);
852 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
853 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
857 memset(dest
, 'X', sizeof(dest
));
858 ret
= p_memmove_s(dest
, 0, tiny
, ARRAY_SIZE(tiny
));
859 ok(ret
== ERANGE
, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret
);
860 ok(errno
== ERANGE
, "errno is %d, expected ERANGE\n", errno
);
861 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
863 /* Replace dest with NULL */
865 ret
= p_memmove_s(NULL
, ARRAY_SIZE(dest
), tiny
, ARRAY_SIZE(tiny
));
866 ok(ret
== EINVAL
, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret
);
867 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
871 memset(dest
, 'X', sizeof(dest
));
872 ret
= p_memmove_s(dest
, 0, NULL
, ARRAY_SIZE(tiny
));
873 ok(ret
== EINVAL
, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret
);
874 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
875 okchars(dest
, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
878 static void test_strcat_s(void)
881 const char *small
= "sma";
886 win_skip("strcat_s not found\n");
890 memset(dest
, 'X', sizeof(dest
));
892 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
893 ok(ret
== 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
894 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == '\0'&&
895 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
896 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
897 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
898 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
899 ok(ret
== 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret
);
900 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
901 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == '\0'&& dest
[7] == 'X',
902 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
903 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
905 ret
= pstrcat_s(dest
, sizeof(dest
), small
);
906 ok(ret
== ERANGE
, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret
);
907 ok(dest
[0] == '\0'&& dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 's' &&
908 dest
[4] == 'm' && dest
[5] == 'a' && dest
[6] == 's' && dest
[7] == 'm',
909 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
910 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
912 memset(dest
, 'X', sizeof(dest
));
916 ret
= pstrcat_s(dest
, 0, small
);
917 ok(ret
== EINVAL
, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret
);
918 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
919 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
920 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
921 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
923 ret
= pstrcat_s(dest
, 0, NULL
);
924 ok(ret
== EINVAL
, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret
);
925 ok(dest
[0] == 'a' && dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
926 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
927 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
928 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
930 ret
= pstrcat_s(dest
, sizeof(dest
), NULL
);
931 ok(ret
== EINVAL
, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret
);
932 ok(dest
[0] == '\0'&& dest
[1] == '\0'&& dest
[2] == 'X' && dest
[3] == 'X' &&
933 dest
[4] == 'X' && dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
934 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
935 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
937 ret
= pstrcat_s(NULL
, sizeof(dest
), small
);
938 ok(ret
== EINVAL
, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret
);
941 static void test__mbscat_s(void)
943 unsigned char dst
[8], src
[4];
945 int prev_cp
= _getmbcp();
949 win_skip("_mbscat_s not found\n");
955 err
= p_mbscat_s(NULL
, sizeof(dst
), src
);
956 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
958 err
= p_mbscat_s(dst
, sizeof(dst
), NULL
);
959 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
962 err
= p_mbscat_s(dst
, 1, src
);
963 ok(err
== EINVAL
, "_mbscat_s returned %d\n", err
);
965 memset(dst
, 'a', sizeof(dst
));
970 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
971 ok(err
== 0, "_mbscat_s returned %d\n", err
);
972 ok(!memcmp(dst
, "aaaaaab", 8), "dst = %s\n", dst
);
974 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
975 ok(err
== ERANGE
, "_mbscat_s returned %d\n", err
);
976 ok(!dst
[0], "dst[0] = %c\n", dst
[0]);
977 ok(dst
[1] == 'a', "dst[1] = %c\n", dst
[1]);
980 /* test invalid str in dst */
987 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
988 ok(err
== 0, "_mbscat_s returned %d\n", err
);
990 /* test invalid str in src */
996 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
997 ok(err
== 0, "_mbscat_s returned %d\n", err
);
999 /* test dst with leading byte on the end of buffer */
1005 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
1006 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
1007 ok(!memcmp(dst
, "aR", 3), "dst = %s\n", dst
);
1009 /* test src with leading byte on the end of buffer */
1015 err
= p_mbscat_s(dst
, sizeof(dst
), src
);
1016 ok(err
== EILSEQ
, "_mbscat_s returned %d\n", err
);
1017 ok(!memcmp(dst
, "ab", 3), "dst = %s\n", dst
);
1021 static void test__mbsnbcpy_s(void)
1023 unsigned char dest
[8];
1024 const unsigned char big
[] = "atoolongstringforthislittledestination";
1025 const unsigned char small
[] = "small";
1030 win_skip("_mbsnbcpy_s not found\n");
1034 memset(dest
, 'X', sizeof(dest
));
1035 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
), small
, sizeof(small
));
1036 ok(ret
== 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret
);
1037 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
1038 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
1039 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1040 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1043 memset(dest
, 'X', sizeof(dest
));
1044 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, sizeof(small
));
1045 ok(ret
== ERANGE
, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret
);
1046 ok(dest
[0] == '\0'&& dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
1047 dest
[4] == 'l' && dest
[5] == 'o' && dest
[6] == 'X' && dest
[7] == 'X',
1048 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1049 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1051 memset(dest
, 'X', sizeof(dest
));
1052 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, big
, 4);
1053 ok(ret
== 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret
);
1054 ok(dest
[0] == 'a' && dest
[1] == 't' && dest
[2] == 'o' && dest
[3] == 'o' &&
1055 dest
[4] == '\0'&& dest
[5] == 'X' && dest
[6] == 'X' && dest
[7] == 'X',
1056 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1057 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1059 memset(dest
, 'X', sizeof(dest
));
1060 ret
= p_mbsnbcpy_s(dest
, sizeof(dest
) - 2, small
, sizeof(small
) + 10);
1061 ok(ret
== 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret
);
1062 ok(dest
[0] == 's' && dest
[1] == 'm' && dest
[2] == 'a' && dest
[3] == 'l' &&
1063 dest
[4] == 'l' && dest
[5] == '\0'&& dest
[6] == 'X' && dest
[7] == 'X',
1064 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
1065 dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
1068 static void test__mbscpy_s(void)
1070 const unsigned char src
[] = "source string";
1071 unsigned char dest
[16];
1076 win_skip("_mbscpy_s not found\n");
1080 ret
= p__mbscpy_s(NULL
, 0, src
);
1081 ok(ret
== EINVAL
, "got %d\n", ret
);
1082 ret
= p__mbscpy_s(NULL
, sizeof(dest
), src
);
1083 ok(ret
== EINVAL
, "got %d\n", ret
);
1084 ret
= p__mbscpy_s(dest
, 0, src
);
1085 ok(ret
== EINVAL
, "got %d\n", ret
);
1087 ret
= p__mbscpy_s(dest
, sizeof(dest
), NULL
);
1088 ok(ret
== EINVAL
, "got %d\n", ret
);
1089 ok(!dest
[0], "dest buffer was not modified on invalid argument\n");
1091 memset(dest
, 'X', sizeof(dest
));
1092 ret
= p__mbscpy_s(dest
, sizeof(dest
), src
);
1093 ok(!ret
, "got %d\n", ret
);
1094 ok(!memcmp(dest
, src
, sizeof(src
)), "dest = %s\n", dest
);
1095 ok(dest
[sizeof(src
)] == 'X', "unused part of buffer was modified\n");
1097 memset(dest
, 'X', sizeof(dest
));
1098 ret
= p__mbscpy_s(dest
, 4, src
);
1099 ok(ret
== ERANGE
, "got %d\n", ret
);
1100 ok(!dest
[0], "incorrect dest buffer (%d)\n", dest
[0]);
1101 ok(dest
[1] == src
[1], "incorrect dest buffer (%d)\n", dest
[1]);
1104 static void test_wcscpy_s(void)
1106 static const WCHAR szLongText
[] = L
"ThisALongstring";
1107 static WCHAR szDest
[18];
1108 static WCHAR szDestShort
[8];
1113 win_skip("wcscpy_s not found\n");
1117 /* Test NULL Dest */
1119 ret
= p_wcscpy_s(NULL
, 18, szLongText
);
1120 ok(ret
== EINVAL
, "p_wcscpy_s expect EINVAL got %d\n", ret
);
1121 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1123 /* Test NULL Source */
1126 ret
= p_wcscpy_s(szDest
, 18, NULL
);
1127 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1128 ok(errno
== EINVAL
, "expected errno EINVAL got %d\n", errno
);
1129 ok(szDest
[0] == 0, "szDest[0] not 0, got %c\n", szDest
[0]);
1131 /* Test invalid size */
1134 ret
= p_wcscpy_s(szDest
, 0, szLongText
);
1135 /* Later versions changed the return value for this case to EINVAL,
1136 * and don't modify the result if the dest size is 0.
1138 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1139 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1140 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1142 /* Copy same buffer size */
1143 ret
= p_wcscpy_s(szDest
, 18, szLongText
);
1144 ok(ret
== 0, "expected 0 got %d\n", ret
);
1145 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1147 /* dest == source */
1148 ret
= p_wcscpy_s(szDest
, 18, szDest
);
1149 ok(ret
== 0, "expected 0 got %d\n", ret
);
1150 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1152 /* Copy smaller buffer size */
1155 ret
= p_wcscpy_s(szDestShort
, 8, szLongText
);
1156 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1157 ok(errno
== ERANGE
|| errno
== EINVAL
, "expected errno ERANGE/EINVAL got %d\n", errno
);
1158 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1162 win_skip("wcsncpy_s not found\n");
1166 ret
= p_wcsncpy_s(NULL
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1167 ok(ret
== EINVAL
, "p_wcsncpy_s expect EINVAL got %d\n", ret
);
1170 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 1);
1171 ok(ret
== EINVAL
, "expected EINVAL got %d\n", ret
);
1172 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1175 ret
= p_wcsncpy_s(szDest
, 18, NULL
, 0);
1176 ok(ret
== 0, "expected ERROR_SUCCESS got %d\n", ret
);
1177 ok(szDest
[0] == 0, "szDest[0] not 0\n");
1180 ret
= p_wcsncpy_s(szDest
, 0, szLongText
, ARRAY_SIZE(szLongText
));
1181 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1182 ok(szDest
[0] == 0 || ret
== EINVAL
, "szDest[0] not 0\n");
1184 ret
= p_wcsncpy_s(szDest
, 18, szLongText
, ARRAY_SIZE(szLongText
));
1185 ok(ret
== 0, "expected 0 got %d\n", ret
);
1186 ok(lstrcmpW(szDest
, szLongText
) == 0, "szDest != szLongText\n");
1189 ret
= p_wcsncpy_s(szDestShort
, 8, szLongText
, ARRAY_SIZE(szLongText
));
1190 ok(ret
== ERANGE
|| ret
== EINVAL
, "expected ERANGE/EINVAL got %d\n", ret
);
1191 ok(szDestShort
[0] == 0, "szDestShort[0] not 0\n");
1194 ret
= p_wcsncpy_s(szDest
, 5, szLongText
, -1);
1195 ok(ret
== STRUNCATE
, "expected STRUNCATE got %d\n", ret
);
1196 ok(szDest
[4] == 0, "szDest[4] not 0\n");
1197 ok(!memcmp(szDest
, szLongText
, 4*sizeof(WCHAR
)), "szDest = %s\n", wine_dbgstr_w(szDest
));
1199 ret
= p_wcsncpy_s(NULL
, 0, (void*)0xdeadbeef, 0);
1200 ok(ret
== 0, "ret = %d\n", ret
);
1202 szDestShort
[0] = '1';
1204 ret
= p_wcsncpy_s(szDestShort
+1, 4, szDestShort
, -1);
1205 ok(ret
== STRUNCATE
, "expected ERROR_SUCCESS got %d\n", ret
);
1206 ok(szDestShort
[0]=='1' && szDestShort
[1]=='1' && szDestShort
[2]=='1' && szDestShort
[3]=='1',
1207 "szDestShort = %s\n", wine_dbgstr_w(szDestShort
));
1210 static void test__wcsupr_s(void)
1212 static const WCHAR mixedString
[] = L
"MiXeDlowerUPPER";
1213 static const WCHAR expectedString
[] = L
"MIXEDLOWERUPPER";
1214 WCHAR testBuffer
[2*ARRAY_SIZE(mixedString
)];
1219 win_skip("_wcsupr_s not found\n");
1223 /* Test NULL input string and invalid size. */
1225 ret
= p_wcsupr_s(NULL
, 0);
1226 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1227 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1229 /* Test NULL input string and valid size. */
1231 ret
= p_wcsupr_s(NULL
, ARRAY_SIZE(testBuffer
));
1232 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1233 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1235 /* Test empty string with zero size. */
1237 testBuffer
[0] = '\0';
1238 ret
= p_wcsupr_s(testBuffer
, 0);
1239 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1240 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1241 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1243 /* Test empty string with size of one. */
1244 testBuffer
[0] = '\0';
1245 ret
= p_wcsupr_s(testBuffer
, 1);
1246 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1247 ok(testBuffer
[0] == '\0', "Expected the buffer to be unchanged\n");
1249 /* Test one-byte buffer with zero size. */
1251 testBuffer
[0] = 'x';
1252 ret
= p_wcsupr_s(testBuffer
, 0);
1253 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1254 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1255 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1257 /* Test one-byte buffer with size of one. */
1259 testBuffer
[0] = 'x';
1260 ret
= p_wcsupr_s(testBuffer
, 1);
1261 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1262 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1263 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1265 /* Test invalid size. */
1266 wcscpy(testBuffer
, mixedString
);
1268 ret
= p_wcsupr_s(testBuffer
, 0);
1269 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1270 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1271 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1273 /* Test normal string uppercasing. */
1274 wcscpy(testBuffer
, mixedString
);
1275 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
));
1276 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1277 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1279 /* Test uppercasing with a shorter buffer size count. */
1280 wcscpy(testBuffer
, mixedString
);
1282 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(mixedString
) - 1);
1283 ok(ret
== EINVAL
, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret
);
1284 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
1285 ok(testBuffer
[0] == '\0', "Expected the first buffer character to be null\n");
1287 /* Test uppercasing with a longer buffer size count. */
1288 wcscpy(testBuffer
, mixedString
);
1289 ret
= p_wcsupr_s(testBuffer
, ARRAY_SIZE(testBuffer
));
1290 ok(ret
== 0, "Expected _wcsupr_s to succeed, got %d\n", ret
);
1291 ok(!wcscmp(testBuffer
, expectedString
), "Expected the string to be fully upper-case\n");
1294 static void test__wcslwr_s(void)
1296 static const WCHAR mixedString
[] = L
"MiXeDlowerUPPER";
1297 static const WCHAR expectedString
[] = L
"mixedlowerupper";
1298 WCHAR buffer
[2*ARRAY_SIZE(mixedString
)];
1303 win_skip("_wcslwr_s not found\n");
1307 /* Test NULL input string and invalid size. */
1309 ret
= p_wcslwr_s(NULL
, 0);
1310 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1311 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1313 /* Test NULL input string and valid size. */
1315 ret
= p_wcslwr_s(NULL
, ARRAY_SIZE(buffer
));
1316 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1317 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1319 /* Test empty string with zero size. */
1322 ret
= p_wcslwr_s(buffer
, 0);
1323 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1324 ok(errno
== EINVAL
, "expected errno EINVAL, got %d\n", errno
);
1325 ok(buffer
[0] == 0, "expected empty string\n");
1327 /* Test empty string with size of one. */
1329 ret
= p_wcslwr_s(buffer
, 1);
1330 ok(ret
== 0, "got %d\n", ret
);
1331 ok(buffer
[0] == 0, "expected buffer to be unchanged\n");
1333 /* Test one-byte buffer with zero size. */
1336 ret
= p_wcslwr_s(buffer
, 0);
1337 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1338 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1339 ok(buffer
[0] == '\0', "expected empty string\n");
1341 /* Test one-byte buffer with size of one. */
1344 ret
= p_wcslwr_s(buffer
, 1);
1345 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1346 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1347 ok(buffer
[0] == '\0', "expected empty string\n");
1349 /* Test invalid size. */
1350 wcscpy(buffer
, mixedString
);
1352 ret
= p_wcslwr_s(buffer
, 0);
1353 ok(ret
== EINVAL
, "Expected EINVAL, got %d\n", ret
);
1354 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1355 ok(buffer
[0] == '\0', "expected empty string\n");
1357 /* Test normal string uppercasing. */
1358 wcscpy(buffer
, mixedString
);
1359 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
));
1360 ok(ret
== 0, "expected 0, got %d\n", ret
);
1361 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1363 /* Test uppercasing with a shorter buffer size count. */
1364 wcscpy(buffer
, mixedString
);
1366 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(mixedString
) - 1);
1367 ok(ret
== EINVAL
, "expected EINVAL, got %d\n", ret
);
1368 ok(errno
== EINVAL
, "expected errno to be EINVAL, got %d\n", errno
);
1369 ok(buffer
[0] == '\0', "expected empty string\n");
1371 /* Test uppercasing with a longer buffer size count. */
1372 wcscpy(buffer
, mixedString
);
1373 ret
= p_wcslwr_s(buffer
, ARRAY_SIZE(buffer
));
1374 ok(ret
== 0, "expected 0, got %d\n", ret
);
1375 ok(!wcscmp(buffer
, expectedString
), "expected lowercase\n");
1378 static void test_mbcjisjms(void)
1380 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1381 unsigned int jisjms
[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1382 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1383 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1384 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1385 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1387 int prev_cp
= _getmbcp();
1389 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1392 for (j
= 0; jisjms
[j
][0] != 0; j
++)
1394 unsigned int ret
, exp
;
1395 ret
= _mbcjistojms(jisjms
[j
][0]);
1396 exp
= (cp
[i
] == 932) ? jisjms
[j
][1] : jisjms
[j
][0];
1397 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1398 exp
, ret
, jisjms
[j
][0], cp
[i
]);
1404 static void test_mbcjmsjis(void)
1406 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1407 unsigned int jmsjis
[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1408 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1409 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1410 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1411 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1412 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1413 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1415 int prev_cp
= _getmbcp();
1417 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1420 for (j
= 0; jmsjis
[j
][0] != 0; j
++)
1422 unsigned int ret
, exp
;
1423 ret
= _mbcjmstojis(jmsjis
[j
][0]);
1424 exp
= (cp
[i
] == 932) ? jmsjis
[j
][1] : jmsjis
[j
][0];
1425 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1426 exp
, ret
, jmsjis
[j
][0], cp
[i
]);
1432 static void test_mbctohira(void)
1434 static const unsigned int mbchira_932
[][2] = {
1435 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1436 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1437 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1438 {0x8396, 0x8396}, {0x8397, 0x8397},
1439 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1441 unsigned int prev_cp
= _getmbcp();
1443 _setmbcp(_MB_CP_SBCS
);
1444 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1446 int ret
, exp
= mbchira_932
[i
][0];
1447 ret
= _mbctohira(mbchira_932
[i
][0]);
1448 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1452 for (i
= 0; i
< ARRAY_SIZE(mbchira_932
); i
++)
1454 unsigned int ret
, exp
;
1455 ret
= _mbctohira(mbchira_932
[i
][0]);
1456 exp
= mbchira_932
[i
][1];
1457 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1462 static void test_mbctokata(void)
1464 static const unsigned int mbckata_932
[][2] = {
1465 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1466 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1467 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1468 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1470 unsigned int prev_cp
= _getmbcp();
1472 _setmbcp(_MB_CP_SBCS
);
1473 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1475 int ret
, exp
= mbckata_932
[i
][0];
1476 ret
= _mbctokata(mbckata_932
[i
][0]);
1477 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1481 for (i
= 0; i
< ARRAY_SIZE(mbckata_932
); i
++)
1483 unsigned int ret
, exp
;
1484 ret
= _mbctokata(mbckata_932
[i
][0]);
1485 exp
= mbckata_932
[i
][1];
1486 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1491 static void test_mbbtombc(void)
1493 static const unsigned int mbbmbc
[][2] = {
1494 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1495 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1496 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1497 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1498 int cp
[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS
};
1500 int prev_cp
= _getmbcp();
1502 for (i
= 0; i
< ARRAY_SIZE(cp
); i
++)
1505 for (j
= 0; mbbmbc
[j
][0] != 0; j
++)
1507 unsigned int exp
, ret
;
1508 ret
= _mbbtombc(mbbmbc
[j
][0]);
1509 exp
= (cp
[i
] == 932) ? mbbmbc
[j
][1] : mbbmbc
[j
][0];
1510 ok(ret
== exp
, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1511 exp
, ret
, mbbmbc
[j
][0], cp
[i
]);
1517 static void test_mbctombb(void)
1519 static const unsigned int mbcmbb_932
[][2] = {
1520 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1521 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1522 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1523 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1524 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1525 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1526 unsigned int exp
, ret
, i
;
1527 unsigned int prev_cp
= _getmbcp();
1530 for (i
= 0; mbcmbb_932
[i
][0] != 0; i
++)
1532 ret
= _mbctombb(mbcmbb_932
[i
][0]);
1533 exp
= mbcmbb_932
[i
][1];
1534 ok(ret
== exp
, "Expected 0x%x, got 0x%x\n", exp
, ret
);
1539 static void test_ismbckata(void) {
1540 struct katakana_pair
{
1544 static const struct katakana_pair tests
[] = {
1545 {0x8152, FALSE
}, {0x8153, FALSE
}, {0x8154, FALSE
}, {0x8155, FALSE
},
1546 {0x82a0, FALSE
}, {0x833f, FALSE
}, {0x8340, TRUE
}, {0x837e, TRUE
},
1547 {0x837f, FALSE
}, {0x8380, TRUE
}, {0x8396, TRUE
}, {0x8397, FALSE
},
1548 {0xa5, FALSE
}, {0xb0, FALSE
}, {0xdd, FALSE
}
1550 unsigned int prev_cp
= _getmbcp();
1554 _setmbcp(_MB_CP_SBCS
);
1555 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1556 ret
= _ismbckata(tests
[i
].c
);
1557 ok(!ret
, "expected 0, got %d for %04x\n", ret
, tests
[i
].c
);
1561 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
1562 ret
= _ismbckata(tests
[i
].c
);
1563 ok(!!ret
== tests
[i
].exp
, "expected %d, got %d for %04x\n",
1564 tests
[i
].exp
, !!ret
, tests
[i
].c
);
1570 static void test_ismbclegal(void) {
1571 unsigned int prev_cp
= _getmbcp();
1575 _setmbcp(932); /* Japanese */
1577 for(i
= 0; i
< 0x10000; i
++) {
1578 ret
= _ismbclegal(i
);
1579 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0x9F) ||
1580 (HIBYTE(i
) >= 0xE0 && HIBYTE(i
) <= 0xFC)) &&
1581 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1582 (LOBYTE(i
) >= 0x80 && LOBYTE(i
) <= 0xFC));
1588 ok(!err
, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1589 _setmbcp(936); /* Chinese (GBK) */
1591 for(i
= 0; i
< 0x10000; i
++) {
1592 ret
= _ismbclegal(i
);
1593 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1594 LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0xFE;
1600 ok(!err
, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1601 _setmbcp(949); /* Korean */
1603 for(i
= 0; i
< 0x10000; i
++) {
1604 ret
= _ismbclegal(i
);
1605 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1606 LOBYTE(i
) >= 0x41 && LOBYTE(i
) <= 0xFE;
1612 ok(!err
, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1613 _setmbcp(950); /* Chinese (Big5) */
1615 for(i
= 0; i
< 0x10000; i
++) {
1616 ret
= _ismbclegal(i
);
1617 exp
= HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xFE &&
1618 ((LOBYTE(i
) >= 0x40 && LOBYTE(i
) <= 0x7E) ||
1619 (LOBYTE(i
) >= 0xA1 && LOBYTE(i
) <= 0xFE));
1625 ok(!err
, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1626 _setmbcp(1361); /* Korean (Johab) */
1628 for(i
= 0; i
< 0x10000; i
++) {
1629 ret
= _ismbclegal(i
);
1630 exp
= ((HIBYTE(i
) >= 0x81 && HIBYTE(i
) <= 0xD3) ||
1631 (HIBYTE(i
) >= 0xD8 && HIBYTE(i
) <= 0xF9)) &&
1632 ((LOBYTE(i
) >= 0x31 && LOBYTE(i
) <= 0x7E) ||
1633 (LOBYTE(i
) >= 0x81 && LOBYTE(i
) <= 0xFE)) &&
1640 todo_wine
ok(!err
, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp
, ret
, i
);
1645 static const struct {
1647 const char* delimiter
;
1648 int exp_offsetret1
; /* returned offset from string after first call to strtok()
1650 int exp_offsetret2
; /* returned offset from string after second call to strtok()
1652 int exp_offsetret3
; /* returned offset from string after third call to strtok()
1654 } testcases_strtok
[] = {
1655 { "red cabernet", " ", 0, 4, -1 },
1656 { "sparkling white riesling", " ", 0, 10, 16 },
1657 { " pale cream sherry", "e ", 1, 6, 9 },
1662 static void test_strtok(void)
1667 for( i
= 0; testcases_strtok
[i
].string
; i
++){
1668 strcpy( teststr
, testcases_strtok
[i
].string
);
1669 strret
= strtok( teststr
, testcases_strtok
[i
].delimiter
);
1670 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret1
||
1671 (!strret
&& testcases_strtok
[i
].exp_offsetret1
== -1),
1672 "string (%p) \'%s\' return %p\n",
1673 teststr
, testcases_strtok
[i
].string
, strret
);
1674 if( !strret
) continue;
1675 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1676 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret2
||
1677 (!strret
&& testcases_strtok
[i
].exp_offsetret2
== -1),
1678 "second call string (%p) \'%s\' return %p\n",
1679 teststr
, testcases_strtok
[i
].string
, strret
);
1680 if( !strret
) continue;
1681 strret
= strtok( NULL
, testcases_strtok
[i
].delimiter
);
1682 ok( (int)(strret
- teststr
) == testcases_strtok
[i
].exp_offsetret3
||
1683 (!strret
&& testcases_strtok
[i
].exp_offsetret3
== -1),
1684 "third call string (%p) \'%s\' return %p\n",
1685 teststr
, testcases_strtok
[i
].string
, strret
);
1689 static void test_strtol(void)
1691 static char neg
[] = "-0x";
1697 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1698 /* errno is modified on W2K8+ */
1700 l
= strtol("-1234", &e
, 0);
1701 ok(l
==-1234, "wrong value %d\n", l
);
1702 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1704 ul
= strtoul("1234", &e
, 0);
1705 ok(ul
==1234, "wrong value %u\n", ul
);
1706 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1709 l
= strtol("2147483647L", &e
, 0);
1710 ok(l
==2147483647, "wrong value %d\n", l
);
1711 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1713 l
= strtol("-2147483648L", &e
, 0);
1714 ok(l
==-2147483647L - 1, "wrong value %d\n", l
);
1715 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1717 ul
= strtoul("4294967295UL", &e
, 0);
1718 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1719 ok(errno
== EBADF
|| broken(errno
== 0), "wrong errno %d\n", errno
);
1722 l
= strtol("9223372036854775807L", &e
, 0);
1723 ok(l
==2147483647, "wrong value %d\n", l
);
1724 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1726 ul
= strtoul("9223372036854775807L", &e
, 0);
1727 ok(ul
==4294967295ul, "wrong value %u\n", ul
);
1728 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1731 ul
= strtoul("-2", NULL
, 0);
1732 ok(ul
== -2, "wrong value %u\n", ul
);
1733 ok(errno
== 0, "wrong errno %d\n", errno
);
1736 ul
= strtoul("-4294967294", NULL
, 0);
1737 ok(ul
== 2, "wrong value %u\n", ul
);
1738 ok(errno
== 0, "wrong errno %d\n", errno
);
1741 ul
= strtoul("-4294967295", NULL
, 0);
1742 ok(ul
==1, "wrong value %u\n", ul
);
1743 ok(errno
== 0, "wrong errno %d\n", errno
);
1746 ul
= strtoul("-4294967296", NULL
, 0);
1747 ok(ul
== 1, "wrong value %u\n", ul
);
1748 ok(errno
== ERANGE
, "wrong errno %d\n", errno
);
1751 l
= strtol(neg
, &e
, 0);
1752 ok(l
== 0, "wrong value %d\n", l
);
1753 ok(errno
== 0, "wrong errno %d\n", errno
);
1754 ok(e
== neg
, "e = %p, neg = %p\n", e
, neg
);
1757 static void test_strnlen(void)
1759 static const char str
[] = "string";
1763 win_skip("strnlen not found\n");
1767 res
= p_strnlen(str
, 20);
1768 ok(res
== 6, "Returned length = %d\n", (int)res
);
1770 res
= p_strnlen(str
, 3);
1771 ok(res
== 3, "Returned length = %d\n", (int)res
);
1773 res
= p_strnlen(NULL
, 0);
1774 ok(res
== 0, "Returned length = %d\n", (int)res
);
1777 static void test__strtoi64(void)
1779 static const char no1
[] = "31923";
1780 static const char no2
[] = "-213312";
1781 static const char no3
[] = "12aa";
1782 static const char no4
[] = "abc12";
1783 static const char overflow
[] = "99999999999999999999";
1784 static const char neg_overflow
[] = "-99999999999999999999";
1785 static const char hex
[] = "0x123";
1786 static const char oct
[] = "000123";
1787 static const char blanks
[] = " 12 212.31";
1790 unsigned __int64 ures
;
1793 if(!p_strtoi64
|| !p_strtoui64
) {
1794 win_skip("_strtoi64 or _strtoui64 not found\n");
1799 res
= p_strtoi64(no1
, NULL
, 10);
1800 ok(res
== 31923, "res != 31923\n");
1801 res
= p_strtoi64(no2
, NULL
, 10);
1802 ok(res
== -213312, "res != -213312\n");
1803 res
= p_strtoi64(no3
, NULL
, 10);
1804 ok(res
== 12, "res != 12\n");
1805 res
= p_strtoi64(no4
, &endpos
, 10);
1806 ok(res
== 0, "res != 0\n");
1807 ok(endpos
== no4
, "Scanning was not stopped on first character\n");
1808 res
= p_strtoi64(hex
, &endpos
, 10);
1809 ok(res
== 0, "res != 0\n");
1810 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1811 res
= p_strtoi64(oct
, &endpos
, 10);
1812 ok(res
== 123, "res != 123\n");
1813 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1814 res
= p_strtoi64(blanks
, &endpos
, 10);
1815 ok(res
== 12, "res != 12\n");
1816 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1817 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1820 res
= p_strtoi64(overflow
, &endpos
, 10);
1821 ok(res
== _I64_MAX
, "res != _I64_MAX\n");
1822 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1823 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1826 res
= p_strtoi64(neg_overflow
, &endpos
, 10);
1827 ok(res
== _I64_MIN
, "res != _I64_MIN\n");
1828 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1829 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1832 res
= p_strtoi64(no1
, &endpos
, 16);
1833 ok(res
== 203043, "res != 203043\n");
1834 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1835 res
= p_strtoi64(no2
, &endpos
, 16);
1836 ok(res
== -2175762, "res != -2175762\n");
1837 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1838 res
= p_strtoi64(no3
, &endpos
, 16);
1839 ok(res
== 4778, "res != 4778\n");
1840 ok(endpos
== no3
+strlen(no3
), "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1841 res
= p_strtoi64(no4
, &endpos
, 16);
1842 ok(res
== 703506, "res != 703506\n");
1843 ok(endpos
== no4
+strlen(no4
), "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1844 res
= p_strtoi64(hex
, &endpos
, 16);
1845 ok(res
== 291, "res != 291\n");
1846 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1847 res
= p_strtoi64(oct
, &endpos
, 16);
1848 ok(res
== 291, "res != 291\n");
1849 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1850 res
= p_strtoi64(blanks
, &endpos
, 16);
1851 ok(res
== 18, "res != 18\n");
1852 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1853 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1856 res
= p_strtoi64(hex
, &endpos
, 36);
1857 ok(res
== 1541019, "res != 1541019\n");
1858 ok(endpos
== hex
+strlen(hex
), "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1859 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1862 res
= p_strtoi64(no1
, &endpos
, 0);
1863 ok(res
== 31923, "res != 31923\n");
1864 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1865 res
= p_strtoi64(no2
, &endpos
, 0);
1866 ok(res
== -213312, "res != -213312\n");
1867 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1868 res
= p_strtoi64(no3
, &endpos
, 10);
1869 ok(res
== 12, "res != 12\n");
1870 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1871 res
= p_strtoi64(no4
, &endpos
, 10);
1872 ok(res
== 0, "res != 0\n");
1873 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1874 res
= p_strtoi64(hex
, &endpos
, 10);
1875 ok(res
== 0, "res != 0\n");
1876 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1877 res
= p_strtoi64(oct
, &endpos
, 10);
1878 ok(res
== 123, "res != 123\n");
1879 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1880 res
= p_strtoi64(blanks
, &endpos
, 10);
1881 ok(res
== 12, "res != 12\n");
1882 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1883 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1886 ures
= p_strtoui64(no1
, &endpos
, 0);
1887 ok(ures
== 31923, "ures != 31923\n");
1888 ok(endpos
== no1
+strlen(no1
), "Incorrect endpos (%p-%p)\n", no1
, endpos
);
1889 ures
= p_strtoui64(no2
, &endpos
, 0);
1890 ok(ures
== -213312, "ures != -213312\n");
1891 ok(endpos
== no2
+strlen(no2
), "Incorrect endpos (%p-%p)\n", no2
, endpos
);
1892 ures
= p_strtoui64(no3
, &endpos
, 10);
1893 ok(ures
== 12, "ures != 12\n");
1894 ok(endpos
== no3
+2, "Incorrect endpos (%p-%p)\n", no3
, endpos
);
1895 ures
= p_strtoui64(no4
, &endpos
, 10);
1896 ok(ures
== 0, "ures != 0\n");
1897 ok(endpos
== no4
, "Incorrect endpos (%p-%p)\n", no4
, endpos
);
1898 ures
= p_strtoui64(hex
, &endpos
, 10);
1899 ok(ures
== 0, "ures != 0\n");
1900 ok(endpos
== hex
+1, "Incorrect endpos (%p-%p)\n", hex
, endpos
);
1901 ures
= p_strtoui64(oct
, &endpos
, 10);
1902 ok(ures
== 123, "ures != 123\n");
1903 ok(endpos
== oct
+strlen(oct
), "Incorrect endpos (%p-%p)\n", oct
, endpos
);
1904 ures
= p_strtoui64(blanks
, &endpos
, 10);
1905 ok(ures
== 12, "ures != 12\n");
1906 ok(endpos
== blanks
+10, "Incorrect endpos (%p-%p)\n", blanks
, endpos
);
1907 ok(errno
== 0xdeadbeef, "errno = %x\n", errno
);
1910 ures
= p_strtoui64(overflow
, &endpos
, 10);
1911 ok(ures
== _UI64_MAX
, "ures != _UI64_MAX\n");
1912 ok(endpos
== overflow
+strlen(overflow
), "Incorrect endpos (%p-%p)\n", overflow
, endpos
);
1913 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1916 ures
= p_strtoui64(neg_overflow
, &endpos
, 10);
1917 ok(ures
== 1, "ures != 1\n");
1918 ok(endpos
== neg_overflow
+strlen(neg_overflow
), "Incorrect endpos (%p-%p)\n", neg_overflow
, endpos
);
1919 ok(errno
== ERANGE
, "errno = %x\n", errno
);
1922 static inline BOOL
compare_double(double f
, double g
, unsigned int ulps
)
1924 ULONGLONG x
= *(ULONGLONG
*)&f
;
1925 ULONGLONG y
= *(ULONGLONG
*)&g
;
1930 x
|= ((ULONGLONG
)1)<<63;
1934 y
|= ((ULONGLONG
)1)<<63;
1936 return (x
>y
? x
-y
: y
-x
) <= ulps
;
1939 static void test__strtod(void)
1941 static const struct {
1947 { "12.1", 4, 12.1 },
1948 { "-13.721", 7, -13.721 },
1950 { ".21e12", 6, 210000000000.0 },
1951 { "214353e-3", 9, 214.353 },
1953 { "12.1d2", 6, 12.1e2
},
1956 { "-0.1", 4, -0.1 },
1957 { "0.1281832188491894198128921", 27, 0.1281832188491894198128921 },
1958 { "0.82181281288121", 16, 0.82181281288121 },
1959 { "21921922352523587651128218821", 29, 21921922352523587651128218821.0 },
1960 { "0.1d238", 7, 0.1e238
},
1961 { "0.1D-4736", 9, 0, ERANGE
},
1962 { "3.4028234663852887e38", 21, FLT_MAX
},
1963 { "1.1754943508222875e-38", 22, FLT_MIN
},
1964 { "1.7976931348623158e+308", 23, DBL_MAX
},
1965 { "1.7976931348623159e+308", 23, INFINITY
, ERANGE
},
1966 { "2.2250738585072014e-308", 23, DBL_MIN
},
1967 { "-1.7976931348623158e+308", 24, -DBL_MAX
},
1968 { "-1.7976931348623159e+308", 24, -INFINITY
, ERANGE
},
1975 const char overflow
[] = "1d9999999999999999999";
1981 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
1984 d
= strtod(tests
[i
].str
, &end
);
1985 ok(d
== tests
[i
].ret
, "%d) d = %.16e\n", i
, d
);
1986 ok(end
== tests
[i
].str
+ tests
[i
].len
, "%d) len = %d\n",
1987 i
, (int)(end
- tests
[i
].str
));
1988 ok(errno
== tests
[i
].err
|| (!tests
[i
].err
&& errno
== 0xdeadbeef) /* <= 2003 */,
1989 "%d) errno = %d\n", i
, errno
);
1993 win_skip("_strtod_l not found\n");
1997 d
= strtod(NULL
, NULL
);
1998 ok(d
== 0.0, "d = %.16e\n", d
);
1999 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2002 end
= (char *)0xdeadbeef;
2003 d
= strtod(NULL
, &end
);
2004 ok(d
== 0.0, "d = %.16e\n", d
);
2005 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2006 ok(!end
, "incorrect end ptr %p\n", end
);
2009 d
= p__strtod_l(NULL
, NULL
, NULL
);
2010 ok(d
== 0.0, "d = %.16e\n", d
);
2011 ok(errno
== EINVAL
, "errno = %x\n", errno
);
2014 /* Set locale with non '.' decimal point (',') */
2015 if(!setlocale(LC_ALL
, "Polish")) {
2016 win_skip("system with limited locales\n");
2020 d
= strtod("12.1", NULL
);
2021 ok(d
== 12.0, "d = %.16e\n", d
);
2023 d
= strtod("12,1", NULL
);
2024 ok(d
== 12.1, "d = %.16e\n", d
);
2026 setlocale(LC_ALL
, "C");
2029 strtod(overflow
, &end
);
2030 ok(errno
== ERANGE
, "errno = %x\n", errno
);
2031 ok(end
== overflow
+21, "incorrect end (%d)\n", (int)(end
-overflow
));
2034 strtod("-1d309", NULL
);
2035 ok(errno
== ERANGE
, "errno = %x\n", errno
);
2038 static void test_mbstowcs(void)
2040 static const wchar_t wSimple
[] = L
"text";
2041 static const wchar_t wHiragana
[] = L
"\x3042\x3043";
2042 static const char mSimple
[] = "text";
2043 static const char mHiragana
[] = { 0x82,0xa0,0x82,0xa1,0 };
2045 const wchar_t *pwstr
;
2053 wOut
[4] = '!'; wOut
[5] = '\0';
2054 mOut
[4] = '!'; mOut
[5] = '\0';
2057 /* crashes on some systems */
2059 ret
= mbstowcs(wOut
, NULL
, 4);
2060 ok(ret
== -1, "mbstowcs did not return -1\n");
2061 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2064 ret
= mbstowcs(NULL
, mSimple
, 0);
2065 ok(ret
== 4, "mbstowcs did not return 4\n");
2067 ret
= mbstowcs(wOut
, mSimple
, 4);
2068 ok(ret
== 4, "mbstowcs did not return 4\n");
2069 ok(!memcmp(wOut
, wSimple
, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2070 ok(wOut
[4] == '!', "wOut[4] != \'!\'\n");
2072 ret
= mbstowcs(NULL
, "", 1);
2073 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2075 ret
= mbstowcs(wOut
, "", 1);
2076 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2077 ok(!wOut
[0], "wOut = %s\n", wine_dbgstr_w(wOut
));
2079 ret
= wcstombs(NULL
, wSimple
, 0);
2080 ok(ret
== 4, "wcstombs did not return 4\n");
2082 ret
= wcstombs(mOut
, wSimple
, 6);
2083 ok(ret
== 4, "wcstombs did not return 4\n");
2084 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2086 ret
= wcstombs(mOut
, wSimple
, 2);
2087 ok(ret
== 2, "wcstombs did not return 2\n");
2088 ok(!memcmp(mOut
, mSimple
, 5*sizeof(char)), "mOut = %s\n", mOut
);
2090 ret
= wcstombs(NULL
, L
"", 1);
2091 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2093 ret
= wcstombs(mOut
, L
"", 1);
2094 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2095 ok(!mOut
[0], "mOut = %s\n", mOut
);
2097 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
2098 win_skip("Japanese_Japan.932 locale not available\n");
2102 ret
= mbstowcs(wOut
, mHiragana
, 6);
2103 ok(ret
== 2, "mbstowcs did not return 2\n");
2104 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2106 ret
= mbstowcs(wOut
, "", 6);
2107 ok(ret
== 0, "mbstowcs did not return 0, got %d\n", (int)ret
);
2108 ok(!wOut
[0], "wOut = %s\n", wine_dbgstr_w(wOut
));
2111 ret
= mbstowcs(wOut
, mHiragana
+1, 5);
2112 ok(ret
== -1, "mbstowcs did not return -1\n");
2113 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
2115 ret
= wcstombs(mOut
, wHiragana
, 6);
2116 ok(ret
== 4, "wcstombs did not return 4\n");
2117 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2119 ret
= wcstombs(mOut
, L
"", 6);
2120 ok(ret
== 0, "wcstombs did not return 0, got %d\n", (int)ret
);
2121 ok(!mOut
[0], "mOut = %s\n", mOut
);
2123 if(!pmbstowcs_s
|| !pwcstombs_s
) {
2124 setlocale(LC_ALL
, "C");
2125 win_skip("mbstowcs_s or wcstombs_s not available\n");
2129 err
= pmbstowcs_s(&ret
, wOut
, 1, mSimple
, _TRUNCATE
);
2130 ok(err
== STRUNCATE
, "err = %d\n", err
);
2131 ok(ret
== 1, "mbstowcs_s did not return 0\n");
2132 ok(!wOut
[0], "wOut[0] = %d\n", wOut
[0]);
2134 err
= pmbstowcs_s(&ret
, wOut
, 6, mSimple
, _TRUNCATE
);
2135 ok(err
== 0, "err = %d\n", err
);
2136 ok(ret
== 5, "mbstowcs_s did not return 5\n");
2137 ok(!memcmp(wOut
, wSimple
, sizeof(wSimple
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2139 err
= pmbstowcs_s(&ret
, wOut
, 6, mHiragana
, _TRUNCATE
);
2140 ok(err
== 0, "err = %d\n", err
);
2141 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2142 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2144 err
= pmbstowcs_s(&ret
, wOut
, 6, "", _TRUNCATE
);
2145 ok(err
== 0, "err = %d\n", err
);
2146 ok(ret
== 1, "mbstowcs_s did not return 1, got %d\n", (int)ret
);
2147 ok(!wOut
[0], "wOut = %s\n", wine_dbgstr_w(wOut
));
2149 err
= pmbstowcs_s(&ret
, NULL
, 0, mHiragana
, 1);
2150 ok(err
== 0, "err = %d\n", err
);
2151 ok(ret
== 3, "mbstowcs_s did not return 3\n");
2153 err
= pwcstombs_s(&ret
, mOut
, 6, wSimple
, _TRUNCATE
);
2154 ok(err
== 0, "err = %d\n", err
);
2155 ok(ret
== 5, "wcstombs_s did not return 5\n");
2156 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2158 err
= pwcstombs_s(&ret
, mOut
, 6, wHiragana
, _TRUNCATE
);
2159 ok(err
== 0, "err = %d\n", err
);
2160 ok(ret
== 5, "wcstombs_s did not return 5\n");
2161 ok(!memcmp(mOut
, mHiragana
, sizeof(mHiragana
)), "mOut = %s\n", mOut
);
2163 err
= pwcstombs_s(&ret
, mOut
, 6, L
"", _TRUNCATE
);
2164 ok(err
== 0, "err = %d\n", err
);
2165 ok(ret
== 1, "wcstombs_s did not return 1, got %d\n", (int)ret
);
2166 ok(!mOut
[0], "mOut = %s\n", mOut
);
2168 err
= pwcstombs_s(&ret
, NULL
, 0, wHiragana
, 1);
2169 ok(err
== 0, "err = %d\n", err
);
2170 ok(ret
== 5, "wcstombs_s did not return 5\n");
2173 setlocale(LC_ALL
, "C");
2174 win_skip("wcsrtombs not available\n");
2180 ret
= pwcsrtombs(mOut
, &pwstr
, 4, &err
);
2181 ok(ret
== 4, "wcsrtombs did not return 4\n");
2182 ok(err
== 0, "err = %d\n", err
);
2183 ok(pwstr
== wSimple
+4, "pwstr = %p (wszSimple = %p)\n", pwstr
, wSimple
);
2184 ok(!memcmp(mOut
, mSimple
, ret
), "mOut = %s\n", mOut
);
2187 ret
= pwcsrtombs(mOut
, &pwstr
, 5, NULL
);
2188 ok(ret
== 4, "wcsrtombs did not return 4\n");
2189 ok(pwstr
== NULL
, "pwstr != NULL\n");
2190 ok(!memcmp(mOut
, mSimple
, sizeof(mSimple
)), "mOut = %s\n", mOut
);
2193 setlocale(LC_ALL
, "C");
2194 win_skip("mbsrtowcs not available\n");
2199 ret
= p_mbsrtowcs(NULL
, &pmbstr
, 6, NULL
);
2200 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2201 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2204 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, NULL
);
2205 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2206 ok(!memcmp(wOut
, wHiragana
, sizeof(wHiragana
)), "wOut = %s\n", wine_dbgstr_w(wOut
));
2207 ok(!pmbstr
, "pmbstr != NULL\n");
2209 state
= mHiragana
[0];
2210 pmbstr
= mHiragana
+1;
2211 ret
= p_mbsrtowcs(wOut
, &pmbstr
, 6, &state
);
2212 ok(ret
== 2, "mbsrtowcs did not return 2\n");
2213 ok(wOut
[0] == 0x3042, "wOut[0] = %x\n", wOut
[0]);
2214 ok(wOut
[1] == 0xff61, "wOut[1] = %x\n", wOut
[1]);
2215 ok(wOut
[2] == 0, "wOut[2] = %x\n", wOut
[2]);
2216 ok(!pmbstr
, "pmbstr != NULL\n");
2219 ret
= p_mbsrtowcs(wOut
, NULL
, 6, &state
);
2220 ok(ret
== -1, "mbsrtowcs did not return -1\n");
2221 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2223 if(!p_mbsrtowcs_s
) {
2224 setlocale(LC_ALL
, "C");
2225 win_skip("mbsrtowcs_s not available\n");
2230 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, NULL
, 6, NULL
);
2231 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2232 ok(err
== EINVAL
, "err = %d\n", err
);
2233 err
= p_mbsrtowcs_s(&ret
, NULL
, 1, &pmbstr
, 6, NULL
);
2234 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2235 ok(err
== EINVAL
, "err = %d\n", err
);
2236 err
= p_mbsrtowcs_s(&ret
, wOut
, 0, &pmbstr
, 6, NULL
);
2237 ok(ret
== -1, "mbsrtowcs_s did not return -1\n");
2238 ok(err
== EINVAL
, "err = %d\n", err
);
2242 err
= p_mbsrtowcs_s(&ret
, NULL
, 0, &pmbstr
, 6, NULL
);
2243 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2244 ok(err
== 0, "err = %d\n", err
);
2245 ok(pmbstr
== mHiragana
, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
);
2246 ok(errno
== 0, "errno = %d\n", errno
);
2249 err
= p_mbsrtowcs_s(&ret
, wOut
, 1, &pmbstr
, 6, NULL
);
2250 ok(ret
== 2, "mbsrtowcs_s did not return 2\n");
2251 ok(err
== 0, "err = %d\n", err
);
2252 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2253 ok(pmbstr
== mHiragana
+2, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+2);
2254 ok(errno
== 0, "errno = %d\n", errno
);
2257 err
= p_mbsrtowcs_s(&ret
, wOut
, 2, &pmbstr
, 6, NULL
);
2258 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2259 ok(err
== 0, "err = %d\n", err
);
2260 ok(!wOut
[0], "wOut[0] = '%c'\n", wOut
[0]);
2261 ok(pmbstr
== mHiragana
+4, "pmbstr = %p, expected %p\n", pmbstr
, mHiragana
+4);
2262 ok(errno
== 0, "errno = %d\n", errno
);
2265 err
= p_mbsrtowcs_s(&ret
, wOut
, 3, &pmbstr
, 6, NULL
);
2266 ok(ret
== 3, "mbsrtowcs_s did not return 3\n");
2267 ok(err
== 0, "err = %d\n", err
);
2268 ok(!pmbstr
, "pmbstr != NULL\n");
2269 ok(errno
== 0, "errno = %d\n", errno
);
2271 setlocale(LC_ALL
, "C");
2274 static void test__wcstombs_s_l(void)
2277 const wchar_t *wstr
;
2285 /* wstr str ret err locale */
2286 { L
"", 0, NULL
, 0, 1, 0, NULL
},
2287 { L
"\xfffd", 1, NULL
, 0, 2, 0, NULL
},
2288 { L
"\xfffd", 1, "", 1, 0, EILSEQ
, NULL
},
2289 { L
"\xfffd", 1, "", 6, 0, EILSEQ
, NULL
},
2290 { L
"text", _TRUNCATE
, "text", 5, 5, 0, NULL
},
2291 { L
"text", _TRUNCATE
, "", 1, 1, STRUNCATE
, NULL
},
2292 { L
"text", 5, "", 3, 0, ERANGE
, NULL
},
2294 { L
"", 0, NULL
, 0, 1, 0, "English_United States.1252" },
2295 { L
"\xfffd", 1, NULL
, 0, 0, EILSEQ
, "English_United States.1252" },
2296 { L
"\xfffd", 1, "", 1, 0, EILSEQ
, "English_United States.1252" },
2297 { L
"\xfffd", 1, "", 6, 0, EILSEQ
, "English_United States.1252" },
2298 { L
"text", _TRUNCATE
, "text", 5, 5, 0, "English_United States.1252" },
2299 { L
"text", _TRUNCATE
, "", 1, 1, STRUNCATE
, "English_United States.1252" },
2300 { L
"text", 5, "", 3, 0, ERANGE
, "English_United States.1252" },
2308 if(!p__create_locale
) {
2309 win_skip("_create_locale not available\n");
2313 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
2317 locale
= p__create_locale(LC_ALL
, tests
[i
].locale
);
2318 ok(locale
!= NULL
, "_create_locale failed for %s\n", tests
[i
].locale
);
2324 memset(out
, 0xcc, sizeof(out
));
2325 err
= p_wcstombs_s_l(&ret
, tests
[i
].str
? out
: NULL
, tests
[i
].len
,
2326 tests
[i
].wstr
, tests
[i
].wlen
, locale
);
2327 ok(ret
== tests
[i
].ret
, "%d: expected ret %d, got %d for '%s' in locale %s\n", i
, tests
[i
].ret
, ret
,
2328 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2329 ok(err
== tests
[i
].err
, "%d: expected err %d, got %d for '%s' in locale %s\n", i
, tests
[i
].err
, err
,
2330 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2332 ok(!memcmp(out
, tests
[i
].str
, strlen(tests
[i
].str
)+1),
2333 "%d: expected out %s, got %s for '%s' in locale %s\n", i
, tests
[i
].str
, out
,
2334 wine_dbgstr_w(tests
[i
].wstr
), tests
[i
].locale
);
2336 p__free_locale(locale
);
2340 static void test_gcvt(void)
2342 char buf
[1024], *res
;
2346 win_skip("Skipping _gcvt tests\n");
2351 res
= _gcvt(1.2, -1, buf
);
2352 ok(res
== NULL
, "res != NULL\n");
2353 ok(errno
== ERANGE
, "errno = %d\n", errno
);
2356 res
= _gcvt(1.2, 5, NULL
);
2357 ok(res
== NULL
, "res != NULL\n");
2358 ok(errno
== EINVAL
, "errno = %d\n", errno
);
2360 res
= gcvt(1.2, 5, buf
);
2361 ok(res
== buf
, "res != buf\n");
2362 ok(!strcmp(buf
, "1.2"), "buf = %s\n", buf
);
2365 err
= p_gcvt_s(buf
, 5, 1.2, 10);
2366 ok(err
== ERANGE
, "err = %d\n", err
);
2367 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2370 err
= p_gcvt_s(buf
, 4, 123456, 2);
2371 ok(err
== ERANGE
, "err = %d\n", err
);
2372 ok(buf
[0] == '\0', "buf[0] = %c\n", buf
[0]);
2375 static void test__itoa_s(void)
2382 win_skip("Skipping _itoa_s tests\n");
2387 ret
= p_itoa_s(0, NULL
, 0, 0);
2388 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2389 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2391 memset(buffer
, 'X', sizeof(buffer
));
2393 ret
= p_itoa_s(0, buffer
, 0, 0);
2394 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2395 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2396 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2398 memset(buffer
, 'X', sizeof(buffer
));
2400 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 0);
2401 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2402 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2403 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2405 memset(buffer
, 'X', sizeof(buffer
));
2407 ret
= p_itoa_s(0, buffer
, sizeof(buffer
), 64);
2408 ok(ret
== EINVAL
, "Expected _itoa_s to return EINVAL, got %d\n", ret
);
2409 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2410 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2412 memset(buffer
, 'X', sizeof(buffer
));
2414 ret
= p_itoa_s(12345678, buffer
, 4, 10);
2415 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2416 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2417 ok(!memcmp(buffer
, "\000765", 4),
2418 "Expected the output buffer to be null terminated with truncated output\n");
2420 memset(buffer
, 'X', sizeof(buffer
));
2422 ret
= p_itoa_s(12345678, buffer
, 8, 10);
2423 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2424 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2425 ok(!memcmp(buffer
, "\0007654321", 8),
2426 "Expected the output buffer to be null terminated with truncated output\n");
2428 memset(buffer
, 'X', sizeof(buffer
));
2430 ret
= p_itoa_s(-12345678, buffer
, 9, 10);
2431 ok(ret
== ERANGE
, "Expected _itoa_s to return ERANGE, got %d\n", ret
);
2432 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2433 ok(!memcmp(buffer
, "\00087654321", 9),
2434 "Expected the output buffer to be null terminated with truncated output\n");
2436 ret
= p_itoa_s(12345678, buffer
, 9, 10);
2437 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2438 ok(!strcmp(buffer
, "12345678"),
2439 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2442 ret
= p_itoa_s(43690, buffer
, sizeof(buffer
), 2);
2443 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2444 ok(!strcmp(buffer
, "1010101010101010"),
2445 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2448 ret
= p_itoa_s(1092009, buffer
, sizeof(buffer
), 36);
2449 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2450 ok(!strcmp(buffer
, "nell"),
2451 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2454 ret
= p_itoa_s(5704, buffer
, sizeof(buffer
), 18);
2455 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2456 ok(!strcmp(buffer
, "hag"),
2457 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2460 ret
= p_itoa_s(-12345678, buffer
, sizeof(buffer
), 10);
2461 ok(ret
== 0, "Expected _itoa_s to return 0, got %d\n", ret
);
2462 ok(!strcmp(buffer
, "-12345678"),
2463 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2466 itoa(100, buffer
, 100);
2467 ok(!strcmp(buffer
, "10"),
2468 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer
);
2471 static void test__strlwr_s(void)
2478 win_skip("Skipping _strlwr_s tests\n");
2483 ret
= p_strlwr_s(NULL
, 0);
2484 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2485 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2488 ret
= p_strlwr_s(NULL
, sizeof(buffer
));
2489 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2490 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2493 ret
= p_strlwr_s(buffer
, 0);
2494 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2495 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2497 strcpy(buffer
, "GoRrIsTeR");
2499 ret
= p_strlwr_s(buffer
, 5);
2500 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2501 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2502 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2503 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2505 strcpy(buffer
, "GoRrIsTeR");
2507 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR") - 1);
2508 ok(ret
== EINVAL
, "Expected _strlwr_s to return EINVAL, got %d\n", ret
);
2509 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2510 ok(!memcmp(buffer
, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2511 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2513 strcpy(buffer
, "GoRrIsTeR");
2514 ret
= p_strlwr_s(buffer
, sizeof("GoRrIsTeR"));
2515 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2516 ok(!strcmp(buffer
, "gorrister"),
2517 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2520 memcpy(buffer
, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2521 ret
= p_strlwr_s(buffer
, sizeof(buffer
));
2522 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2523 ok(!memcmp(buffer
, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2524 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2527 ret
= p_strlwr_s((char *)"already_lowercase", sizeof("already_lowercase"));
2528 ok(ret
== 0, "Expected _strlwr_s to return 0, got %d\n", ret
);
2531 static void test_wcsncat_s(void)
2539 win_skip("skipping wcsncat_s tests\n");
2543 wcscpy(src
, L
"abc");
2545 ret
= p_wcsncat_s(NULL
, 4, src
, 4);
2546 ok(ret
== EINVAL
, "err = %d\n", ret
);
2547 ret
= p_wcsncat_s(dst
, 0, src
, 4);
2548 ok(ret
== EINVAL
, "err = %d\n", ret
);
2549 ret
= p_wcsncat_s(dst
, 0, src
, _TRUNCATE
);
2550 ok(ret
== EINVAL
, "err = %d\n", ret
);
2551 ret
= p_wcsncat_s(dst
, 4, NULL
, 0);
2552 ok(ret
== 0, "err = %d\n", ret
);
2555 ret
= p_wcsncat_s(dst
, 2, src
, 4);
2556 ok(ret
== ERANGE
, "err = %d\n", ret
);
2559 ret
= p_wcsncat_s(dst
, 2, src
, _TRUNCATE
);
2560 ok(ret
== STRUNCATE
, "err = %d\n", ret
);
2561 ok(dst
[0] == 'a' && dst
[1] == 0, "dst is %s\n", wine_dbgstr_w(dst
));
2563 wcscpy(dst
, L
"abc");
2565 ret
= p_wcsncat_s(dst
, 4, src
, 4);
2566 ok(ret
== EINVAL
, "err = %d\n", ret
);
2569 static void test__mbsnbcat_s(void)
2571 unsigned char dest
[16];
2572 const unsigned char first
[] = "dinosaur";
2573 const unsigned char second
[] = "duck";
2578 win_skip("Skipping _mbsnbcat_s tests\n");
2582 /* Test invalid arguments. */
2583 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 0);
2584 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2587 ret
= p_mbsnbcat_s(NULL
, 10, NULL
, 0);
2588 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2589 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2592 ret
= p_mbsnbcat_s(NULL
, 0, NULL
, 10);
2593 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2594 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2596 memset(dest
, 'X', sizeof(dest
));
2598 ret
= p_mbsnbcat_s(dest
, 0, NULL
, 0);
2599 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2600 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2601 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2603 memset(dest
, 'X', sizeof(dest
));
2605 ret
= p_mbsnbcat_s(dest
, 0, second
, 0);
2606 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2607 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2608 ok(dest
[0] == 'X', "Expected the output buffer to be untouched\n");
2610 memset(dest
, 'X', sizeof(dest
));
2612 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 0);
2613 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2614 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2615 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2617 memset(dest
, 'X', sizeof(dest
));
2619 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), NULL
, 10);
2620 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2621 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2622 ok(dest
[0] == '\0', "Expected the output buffer to be null terminated\n");
2624 memset(dest
, 'X', sizeof(dest
));
2626 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2627 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2628 ok(!memcmp(dest
, second
, sizeof(second
)),
2629 "Expected the output buffer string to be \"duck\"\n");
2631 /* Test source truncation behavior. */
2632 memset(dest
, 'X', sizeof(dest
));
2633 memcpy(dest
, first
, sizeof(first
));
2634 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, 0);
2635 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2636 ok(!memcmp(dest
, first
, sizeof(first
)),
2637 "Expected the output buffer string to be \"dinosaur\"\n");
2639 memset(dest
, 'X', sizeof(dest
));
2640 memcpy(dest
, first
, sizeof(first
));
2641 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
));
2642 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2643 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2644 "Expected the output buffer string to be \"dinosaurduck\"\n");
2646 memset(dest
, 'X', sizeof(dest
));
2647 memcpy(dest
, first
, sizeof(first
));
2648 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) + 1);
2649 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2650 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2651 "Expected the output buffer string to be \"dinosaurduck\"\n");
2653 memset(dest
, 'X', sizeof(dest
));
2654 memcpy(dest
, first
, sizeof(first
));
2655 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 1);
2656 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2657 ok(!memcmp(dest
, "dinosaurduck", sizeof("dinosaurduck")),
2658 "Expected the output buffer string to be \"dinosaurduck\"\n");
2660 memset(dest
, 'X', sizeof(dest
));
2661 memcpy(dest
, first
, sizeof(first
));
2662 ret
= p_mbsnbcat_s(dest
, sizeof(dest
), second
, sizeof(second
) - 2);
2663 ok(ret
== 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret
);
2664 ok(!memcmp(dest
, "dinosaurduc", sizeof("dinosaurduc")),
2665 "Expected the output buffer string to be \"dinosaurduc\"\n");
2667 /* Test destination truncation behavior. */
2668 memset(dest
, 'X', sizeof(dest
));
2669 memcpy(dest
, first
, sizeof(first
));
2671 ret
= p_mbsnbcat_s(dest
, sizeof(first
) - 1, second
, sizeof(second
));
2672 ok(ret
== EINVAL
, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret
);
2673 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2674 ok(!memcmp(dest
, "\0inosaur", sizeof("\0inosaur") - 1),
2675 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2677 memset(dest
, 'X', sizeof(dest
));
2678 memcpy(dest
, first
, sizeof(first
));
2680 ret
= p_mbsnbcat_s(dest
, sizeof(first
), second
, sizeof(second
));
2681 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2682 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2683 ok(!memcmp(dest
, "\0inosaurd", sizeof("\0inosaurd") - 1),
2684 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2686 memset(dest
, 'X', sizeof(dest
));
2687 memcpy(dest
, first
, sizeof(first
));
2689 ret
= p_mbsnbcat_s(dest
, sizeof(first
) + 1, second
, sizeof(second
));
2690 ok(ret
== ERANGE
, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret
);
2691 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2692 ok(!memcmp(dest
, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2693 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2696 static void test__mbsupr_s(void)
2699 unsigned char buffer
[20];
2703 win_skip("Skipping _mbsupr_s tests\n");
2708 ret
= p_mbsupr_s(NULL
, 0);
2709 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2712 ret
= p_mbsupr_s(NULL
, sizeof(buffer
));
2713 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2714 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2717 ret
= p_mbsupr_s(buffer
, 0);
2718 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2719 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2721 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2723 ret
= p_mbsupr_s(buffer
, sizeof("abcdefgh"));
2724 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2725 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2726 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2729 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2731 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2732 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2733 ok(!memcmp(buffer
, "ABCDEFGH", sizeof("ABCDEFGH")),
2734 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2737 memcpy(buffer
, "abcdefgh", sizeof("abcdefgh"));
2739 ret
= p_mbsupr_s(buffer
, 4);
2740 ok(ret
== EINVAL
, "Expected _mbsupr_s to return EINVAL, got %d\n", ret
);
2741 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2743 memcpy(buffer
, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2745 ret
= p_mbsupr_s(buffer
, sizeof(buffer
));
2746 ok(ret
== 0, "Expected _mbsupr_s to return 0, got %d\n", ret
);
2747 ok(!memcmp(buffer
, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2748 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2753 static void test__mbslwr_s(void)
2756 unsigned char buffer
[20];
2760 win_skip("Skipping _mbslwr_s tests\n");
2765 ret
= p_mbslwr_s(NULL
, 0);
2766 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2769 ret
= p_mbslwr_s(NULL
, sizeof(buffer
));
2770 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2771 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2774 ret
= p_mbslwr_s(buffer
, 0);
2775 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2776 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2778 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2780 ret
= p_mbslwr_s(buffer
, sizeof("ABCDEFGH"));
2781 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2782 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2783 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2786 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2788 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2789 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2790 ok(!memcmp(buffer
, "abcdefgh", sizeof("abcdefgh")),
2791 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2794 memcpy(buffer
, "ABCDEFGH", sizeof("ABCDEFGH"));
2796 ret
= p_mbslwr_s(buffer
, 4);
2797 ok(ret
== EINVAL
, "Expected _mbslwr_s to return EINVAL, got %d\n", ret
);
2798 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2800 memcpy(buffer
, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2802 ret
= p_mbslwr_s(buffer
, sizeof(buffer
));
2803 ok(ret
== 0, "Expected _mbslwr_s to return 0, got %d\n", ret
);
2804 ok(!memcmp(buffer
, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2805 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2809 static void test__mbstok(void)
2811 const unsigned char delim
[] = "t";
2813 char str
[] = "!.!test";
2818 ret
= _mbstok(NULL
, delim
);
2819 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2820 ok(!ret
|| broken((char*)ret
==str
+4),
2821 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret
, str
);
2823 ret
= _mbstok(NULL
, delim
);
2824 ok(!ret
, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret
);
2827 static void test__ultoa_s(void)
2834 win_skip("Skipping _ultoa_s tests\n");
2839 ret
= p_ultoa_s(0, NULL
, 0, 0);
2840 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2841 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2843 memset(buffer
, 'X', sizeof(buffer
));
2845 ret
= p_ultoa_s(0, buffer
, 0, 0);
2846 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2847 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2848 ok(buffer
[0] == 'X', "Expected the output buffer to be untouched\n");
2850 memset(buffer
, 'X', sizeof(buffer
));
2852 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 0);
2853 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2854 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2855 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2857 memset(buffer
, 'X', sizeof(buffer
));
2859 ret
= p_ultoa_s(0, buffer
, sizeof(buffer
), 64);
2860 ok(ret
== EINVAL
, "Expected _ultoa_s to return EINVAL, got %d\n", ret
);
2861 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
2862 ok(buffer
[0] == '\0', "Expected the output buffer to be null terminated\n");
2864 memset(buffer
, 'X', sizeof(buffer
));
2866 ret
= p_ultoa_s(12345678, buffer
, 4, 10);
2867 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2868 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2869 ok(!memcmp(buffer
, "\000765", 4),
2870 "Expected the output buffer to be null terminated with truncated output\n");
2872 memset(buffer
, 'X', sizeof(buffer
));
2874 ret
= p_ultoa_s(12345678, buffer
, 8, 10);
2875 ok(ret
== ERANGE
, "Expected _ultoa_s to return ERANGE, got %d\n", ret
);
2876 ok(errno
== ERANGE
, "Expected errno to be ERANGE, got %d\n", errno
);
2877 ok(!memcmp(buffer
, "\0007654321", 8),
2878 "Expected the output buffer to be null terminated with truncated output\n");
2880 ret
= p_ultoa_s(12345678, buffer
, 9, 10);
2881 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2882 ok(!strcmp(buffer
, "12345678"),
2883 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2886 ret
= p_ultoa_s(43690, buffer
, sizeof(buffer
), 2);
2887 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2888 ok(!strcmp(buffer
, "1010101010101010"),
2889 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2892 ret
= p_ultoa_s(1092009, buffer
, sizeof(buffer
), 36);
2893 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2894 ok(!strcmp(buffer
, "nell"),
2895 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2898 ret
= p_ultoa_s(5704, buffer
, sizeof(buffer
), 18);
2899 ok(ret
== 0, "Expected _ultoa_s to return 0, got %d\n", ret
);
2900 ok(!strcmp(buffer
, "hag"),
2901 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2905 static void test_wctob(void)
2907 int ret
, cp
= _getmbcp();
2909 if(!p_wctob
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2910 win_skip("Skipping wctob tests\n");
2914 ret
= p_wctob(0x8141);
2915 ok(ret
== EOF
, "ret = %x\n", ret
);
2917 ret
= p_wctob(0x81);
2918 ok(ret
== EOF
, "ret = %x\n", ret
);
2920 ret
= p_wctob(0xe0);
2921 ok(ret
== 0x61, "ret = %x\n", ret
);
2924 ret
= p_wctob(0x81);
2925 ok(ret
== EOF
, "ret = %x\n", ret
);
2927 setlocale(LC_ALL
, "C");
2928 ret
= p_wctob(0x8141);
2929 ok(ret
== EOF
, "ret = %x\n", ret
);
2931 ret
= p_wctob(0x81);
2932 ok(ret
== (signed char)0x81, "ret = %x\n", ret
);
2934 ret
= p_wctob(0x9f);
2935 ok(ret
== (signed char)0x9f, "ret = %x\n", ret
);
2937 ret
= p_wctob(0xe0);
2938 ok(ret
== (signed char)0xe0, "ret = %x\n", ret
);
2943 static void test_btowc(void)
2946 int cp
= _getmbcp();
2948 if(!p_btowc
|| !setlocale(LC_ALL
, "chinese-traditional")) {
2949 win_skip("Skipping btowc tests\n");
2954 ok(ret
== WEOF
, "ret = %x\n", ret
);
2956 ret
= p_btowc(0x61);
2957 ok(ret
== 0x61, "ret = %x\n", ret
);
2959 ret
= p_btowc(0x81);
2960 ok(ret
== WEOF
, "ret = %x\n", ret
);
2962 ret
= p_btowc(0xe0);
2963 ok(ret
== WEOF
, "ret = %x\n", ret
);
2966 ret
= p_btowc(0x61);
2967 ok(ret
== 0x61, "ret = %x\n", ret
);
2969 ret
= p_btowc(0x81);
2970 ok(ret
== WEOF
, "ret = %x\n", ret
);
2972 ret
= p_btowc(0xe0);
2973 ok(ret
== WEOF
, "ret = %x\n", ret
);
2975 if(!setlocale(LC_CTYPE
, ".1250")) {
2976 win_skip("No codepage 1250 support\n");
2977 setlocale(LC_ALL
, "C");
2982 ret
= p_btowc(0x61);
2983 ok(ret
== 0x61, "ret = %x\n", ret
);
2985 ret
= p_btowc(0x81);
2986 ok(ret
== 0x81, "ret = %x\n", ret
);
2988 ret
= p_btowc(0xe0);
2989 ok(ret
== 0x155, "ret = %x\n", ret
);
2991 ret
= p_btowc(0x100);
2992 ok(ret
== 0x00, "ret = %x\n", ret
);
2994 ret
= p_btowc(0x1e0);
2995 ok(ret
== 0x155, "ret = %x\n", ret
);
2997 setlocale(LC_ALL
, "C");
2998 ret
= p_btowc(0x61);
2999 ok(ret
== 0x61, "ret = %x\n", ret
);
3001 ret
= p_btowc(0x81);
3002 ok(ret
== 0x81, "ret = %x\n", ret
);
3004 ret
= p_btowc(0x9f);
3005 ok(ret
== 0x9f, "ret = %x\n", ret
);
3007 ret
= p_btowc(0xe0);
3008 ok(ret
== 0xe0, "ret = %x\n", ret
);
3010 ret
= p_btowc(0x100);
3011 ok(ret
== 0x00, "ret = %x\n", ret
);
3013 ret
= p_btowc(0x1e0);
3014 ok(ret
== 0xe0, "ret = %x\n", ret
);
3019 static void test_wctomb(void)
3022 unsigned char dst
[10];
3026 if(!p_wcrtomb
|| !setlocale(LC_ALL
, "Japanese_Japan.932")) {
3027 win_skip("wcrtomb tests\n");
3031 ret
= p_wcrtomb(NULL
, 0x3042, NULL
);
3032 ok(ret
== 2, "wcrtomb did not return 2\n");
3036 ret
= p_wcrtomb((char*)dst
, 0x3042, &state
);
3037 ok(ret
== 2, "wcrtomb did not return 2\n");
3038 ok(state
== 0, "state != 0\n");
3039 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3040 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3041 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
3043 ret
= p_wcrtomb((char*)dst
, 0x3043, NULL
);
3044 ok(ret
== 2, "wcrtomb did not return 2\n");
3045 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3046 ok(dst
[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst
[1]);
3048 ret
= p_wcrtomb((char*)dst
, 0x20, NULL
);
3049 ok(ret
== 1, "wcrtomb did not return 1\n");
3050 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
3052 ret
= p_wcrtomb((char*)dst
, 0xffff, NULL
);
3053 ok(ret
== -1, "wcrtomb did not return -1\n");
3054 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
3057 win_skip("wcrtomb_s tests\n");
3058 setlocale(LC_ALL
, "C");
3064 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x3042, &state
);
3065 ok(!err
, "err = %d\n", err
);
3066 ok(ret
== 2, "ret != 2\n");
3067 ok(!state
, "state != 0\n");
3068 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3069 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3070 ok(dst
[2] == 'a', "dst[2] != 'a'\n");
3072 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x3042, NULL
);
3073 ok(!err
, "err = %d\n", err
);
3074 ok(ret
== 2, "ret != 2\n");
3075 ok(!state
, "state != 0\n");
3076 ok(dst
[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst
[0]);
3077 ok(dst
[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst
[1]);
3079 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0x20, NULL
);
3080 ok(!err
, "err = %d\n", err
);
3081 ok(ret
== 1, "ret != 1\n");
3082 ok(dst
[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst
[0]);
3084 err
= p_wcrtomb_s(&ret
, NULL
, 0, 0x20, NULL
);
3085 ok(!err
, "err = %d\n", err
);
3086 ok(ret
== 1, "ret != 1\n");
3088 err
= p_wcrtomb_s(&ret
, (char*)dst
, sizeof(dst
), 0xffff, NULL
);
3089 ok(err
== EILSEQ
, "err = %d\n", err
);
3090 ok(ret
== -1, "wcrtomb did not return -1\n");
3091 ok(dst
[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst
[0]);
3093 setlocale(LC_ALL
, "C");
3096 static void test_tolower(void)
3102 /* test C locale when locale was never changed */
3103 ret
= p_tolower(0x41);
3104 ok(ret
== 0x61, "ret = %x\n", ret
);
3106 ret
= p_tolower(0xF4);
3107 ok(ret
== 0xF4, "ret = %x\n", ret
);
3110 ret
= p_tolower((char)0xF4);
3111 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
3112 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3115 ret
= p_tolower((char)0xD0);
3116 ok(ret
== (char)0xD0, "ret = %x\n", ret
);
3117 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3119 setlocale(LC_ALL
, "C");
3121 ret
= p_tolower((char)0xF4);
3122 ok(ret
== (char)0xF4, "ret = %x\n", ret
);
3123 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3125 /* test C locale after setting locale */
3126 if(!setlocale(LC_ALL
, "us")) {
3127 win_skip("skipping tolower tests that depends on locale\n");
3130 setlocale(LC_ALL
, "C");
3134 ret
= p_tolower((signed char)ch
);
3135 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
3136 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
3137 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
3140 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
3142 ok(ret
== ch
, "ret = %x\n", ret
);
3143 if(!len
|| ret
==(unsigned char)lch
)
3144 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
3148 ret
= p_tolower((signed char)ch
);
3149 if(!MultiByteToWideChar(CP_ACP
, MB_ERR_INVALID_CHARS
, &ch
, 1, &chw
, 1) ||
3150 LCMapStringW(CP_ACP
, LCMAP_LOWERCASE
, &chw
, 1, &lower
, 1) != 1 ||
3151 (len
= WideCharToMultiByte(CP_ACP
, 0, &lower
, 1, &lch
, 1, NULL
, NULL
)) != 1)
3154 ok(ret
==(unsigned char)lch
|| broken(ret
==ch
)/*WinXP-*/, "ret = %x\n", ret
);
3156 ok(ret
== ch
, "ret = %x\n", ret
);
3157 if(!len
|| ret
==(unsigned char)lch
)
3158 ok(errno
== EILSEQ
, "errno = %d\n", errno
);
3160 ret
= p_tolower((unsigned char)0xD0);
3161 ok(ret
== 0xD0, "ret = %x\n", ret
);
3163 ok(setlocale(LC_ALL
, "us") != NULL
, "setlocale failed\n");
3165 ret
= p_tolower((signed char)0xD0);
3166 ok(ret
== 0xF0, "ret = %x\n", ret
);
3168 ret
= p_tolower((unsigned char)0xD0);
3169 ok(ret
== 0xF0, "ret = %x\n", ret
);
3171 setlocale(LC_ALL
, "C");
3174 static double mul_pow10(double x
, double exp
)
3176 int fpexcept
= _EM_DENORMAL
|_EM_INVALID
|_EM_ZERODIVIDE
|_EM_OVERFLOW
|_EM_UNDERFLOW
|_EM_INEXACT
;
3177 BOOL negexp
= (exp
< 0);
3183 fpcontrol
= _control87(0, 0);
3184 _control87(fpexcept
, 0xffffffff);
3185 ret
= pow(10.0, exp
);
3186 ret
= (negexp
? x
/ret
: x
*ret
);
3187 _control87(fpcontrol
, 0xffffffff);
3191 static void test__atodbl(void)
3198 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
3199 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
3200 win_skip("_atodbl_l is not available\n");
3205 ret
= p__atodbl_l(&d
, num
, NULL
);
3206 ok(ret
== 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret
);
3207 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3208 ret
= _atodbl(&d
, num
);
3209 ok(ret
== 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret
);
3210 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3213 ret
= p__atodbl_l(&d
, num
, NULL
);
3214 ok(ret
== 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret
);
3215 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3216 ret
= _atodbl(&d
, num
);
3217 ok(ret
== 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret
);
3218 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3221 ret
= p__atodbl_l(&d
, num
, NULL
);
3222 ok(ret
== 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret
);
3223 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3224 ret
= _atodbl(&d
, num
);
3225 ok(ret
== 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret
);
3226 ok(d
.x
== 0, "d.x = %lf, expected 0\n", d
.x
);
3229 ret
= p__atodbl_l(&d
, num
, NULL
);
3230 ok(ret
== 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret
);
3231 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
3232 ret
= _atodbl(&d
, num
);
3233 ok(ret
== 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret
);
3234 ok(d
.x
== 123, "d.x = %lf, expected 123\n", d
.x
);
3236 /* check over the whole range of (simple) normal doubles */
3237 for (j
= DBL_MIN_10_EXP
; j
<= DBL_MAX_10_EXP
; j
++) {
3238 for (i
= 1; i
<= 9; i
++) {
3239 double expected
= mul_pow10(i
, j
);
3240 if (expected
< DBL_MIN
|| expected
> DBL_MAX
) continue;
3241 snprintf(num
, sizeof(num
), "%de%d", i
, j
);
3242 ret
= _atodbl(&d
, num
);
3243 ok(compare_double(d
.x
, expected
, 2), "d.x = %.16e, expected %.16e\n", d
.x
, expected
);
3247 /* check with denormal doubles */
3248 strcpy(num
, "1e-309");
3249 ret
= p__atodbl_l(&d
, num
, NULL
);
3250 ok(ret
== _UNDERFLOW
, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret
);
3251 ok(compare_double(d
.x
, 1e-309, 1), "d.x = %.16e, expected 0\n", d
.x
);
3252 ret
= _atodbl(&d
, num
);
3253 ok(ret
== _UNDERFLOW
, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret
);
3254 ok(compare_double(d
.x
, 1e-309, 1), "d.x = %.16e, expected 0\n", d
.x
);
3256 strcpy(num
, "1e309");
3257 ret
= p__atodbl_l(&d
, num
, NULL
);
3258 ok(ret
== _OVERFLOW
, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret
);
3259 ret
= _atodbl(&d
, num
);
3260 ok(ret
== _OVERFLOW
, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret
);
3263 static void test__stricmp(void)
3267 ret
= _stricmp("test", "test");
3268 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3269 ret
= _stricmp("a", "z");
3270 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3271 ret
= _stricmp("z", "a");
3272 ok(ret
> 0, "_stricmp returned %d\n", ret
);
3273 ret
= _stricmp("\xa5", "\xb9");
3274 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3276 if(!setlocale(LC_ALL
, "polish")) {
3277 win_skip("stricmp tests\n");
3281 ret
= _stricmp("test", "test");
3282 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3283 ret
= _stricmp("a", "z");
3284 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3285 ret
= _stricmp("z", "a");
3286 ok(ret
> 0, "_stricmp returned %d\n", ret
);
3287 ret
= _stricmp("\xa5", "\xb9");
3288 ok(ret
== 0, "_stricmp returned %d\n", ret
);
3289 ret
= _stricmp("a", "\xb9");
3290 ok(ret
< 0, "_stricmp returned %d\n", ret
);
3292 setlocale(LC_ALL
, "C");
3295 static void test__wcstoi64(void)
3297 static const struct { WCHAR str
[24]; __int64 res
; unsigned __int64 ures
; int base
; } tests
[] =
3301 { L
"-1234", -1234, -1234 },
3302 { L
"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
3303 { L
"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
3304 { { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
3305 { { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
3306 { { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
3307 { { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
3308 { { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
3309 { { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
3310 { { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
3311 { { '+',0x0e50,0xff17,'1' }, 071, 071 },
3312 { { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
3313 { L
"4294967295", 4294967295, 4294967295 },
3314 { L
"4294967296", 4294967296, 4294967296 },
3315 { L
"9223372036854775807", 9223372036854775807, 9223372036854775807 },
3316 { L
"9223372036854775808", _I64_MAX
, 9223372036854775808u },
3317 { L
"18446744073709551615", _I64_MAX
, _UI64_MAX
},
3318 { L
"18446744073709551616", _I64_MAX
, _UI64_MAX
},
3319 { L
"-4294967295", -4294967295, -4294967295 },
3320 { L
"-4294967296", -4294967296, -4294967296 },
3321 { L
"-9223372036854775807", -9223372036854775807, -9223372036854775807 },
3322 { L
"-9223372036854775808", _I64_MIN
, 9223372036854775808u },
3323 { L
"-18446744073709551615", _I64_MIN
, 1 },
3324 { L
"-18446744073709551616", _I64_MIN
, 1 },
3326 static const WCHAR zeros
[] = {
3327 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3328 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3333 unsigned __int64 ures
;
3336 if (!p_wcstoi64
|| !p_wcstoui64
) {
3337 win_skip("_wcstoi64 or _wcstoui64 not found\n");
3341 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3343 res
= p_wcstoi64( tests
[i
].str
, &endpos
, tests
[i
].base
);
3344 ok( res
== tests
[i
].res
, "%u: %s res %s\n",
3345 i
, wine_dbgstr_w(tests
[i
].str
), wine_dbgstr_longlong(res
) );
3346 if (!res
) ok( endpos
== tests
[i
].str
, "%u: wrong endpos %p/%p\n", i
, endpos
, tests
[i
].str
);
3347 ures
= p_wcstoui64( tests
[i
].str
, &endpos
, tests
[i
].base
);
3348 ok( ures
== tests
[i
].ures
, "%u: %s res %s\n",
3349 i
, wine_dbgstr_w(tests
[i
].str
), wine_dbgstr_longlong(ures
) );
3352 /* Test various unicode digits */
3353 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3354 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3355 res
= p_wcstoi64(tmp
, NULL
, 0);
3356 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3357 tmp
[1] = zeros
[i
] + 10;
3358 res
= p_wcstoi64(tmp
, NULL
, 16);
3359 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3363 static void test__wcstol(void)
3365 static const struct { WCHAR str
[24]; long res
; unsigned long ures
; int base
; } tests
[] =
3369 { L
"-1234", -1234, -1234 },
3370 { L
"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
3371 { L
"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
3372 { { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
3373 { { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
3374 { { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
3375 { { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
3376 { { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
3377 { { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
3378 { { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
3379 { { '+',0x0e50,0xff17,'1' }, 071, 071 },
3380 { { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
3381 { L
"2147483647", 2147483647, 2147483647 },
3382 { L
"2147483648", LONG_MAX
, 2147483648 },
3383 { L
"4294967295", LONG_MAX
, 4294967295 },
3384 { L
"4294967296", LONG_MAX
, ULONG_MAX
},
3385 { L
"9223372036854775807", LONG_MAX
, ULONG_MAX
},
3386 { L
"-2147483647", -2147483647, -2147483647 },
3387 { L
"-2147483648", LONG_MIN
, LONG_MIN
},
3388 { L
"-4294967295", LONG_MIN
, 1 },
3389 { L
"-4294967296", LONG_MIN
, 1 },
3390 { L
"-9223372036854775807", LONG_MIN
, 1 },
3392 static const WCHAR zeros
[] = {
3393 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
3394 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
3402 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3404 res
= wcstol( tests
[i
].str
, &endpos
, tests
[i
].base
);
3405 ok( res
== tests
[i
].res
, "%u: %s res %08lx\n",
3406 i
, wine_dbgstr_w(tests
[i
].str
), res
);
3407 if (!res
) ok( endpos
== tests
[i
].str
, "%u: wrong endpos %p/%p\n", i
, endpos
, tests
[i
].str
);
3408 ures
= wcstoul( tests
[i
].str
, &endpos
, tests
[i
].base
);
3409 ok( ures
== tests
[i
].ures
, "%u: %s res %08lx\n",
3410 i
, wine_dbgstr_w(tests
[i
].str
), ures
);
3413 /* Test various unicode digits */
3414 for (i
= 0; i
< ARRAY_SIZE(zeros
); ++i
) {
3415 WCHAR tmp
[] = {zeros
[i
] + 4, zeros
[i
], zeros
[i
] + 5, 0};
3416 res
= wcstol(tmp
, NULL
, 0);
3417 ok(res
== 405, "with zero = U+%04X: got %d, expected 405\n", zeros
[i
], (int)res
);
3418 tmp
[1] = zeros
[i
] + 10;
3419 res
= wcstol(tmp
, NULL
, 16);
3420 ok(res
== 4, "with zero = U+%04X: got %d, expected 4\n", zeros
[i
], (int)res
);
3424 static void test_atoi(void)
3429 ok(r
== 0, "atoi(0) = %d\n", r
);
3432 ok(r
== -1, "atoi(-1) = %d\n", r
);
3435 ok(r
== 1, "atoi(1) = %d\n", r
);
3437 r
= atoi("4294967296");
3438 ok(r
== 0, "atoi(4294967296) = %d\n", r
);
3441 static void test_atol(void)
3446 ok(r
== 0, "atol(0) = %d\n", r
);
3449 ok(r
== -1, "atol(-1) = %d\n", r
);
3452 ok(r
== 1, "atol(1) = %d\n", r
);
3454 r
= atol("4294967296");
3455 ok(r
== 0, "atol(4294967296) = %d\n", r
);
3458 static void test_atof(void)
3463 ok(d
== 0.0, "d = %lf\n", d
);
3466 ok(d
== 1.0, "d = %lf\n", d
);
3469 ok(d
== -1.0, "d = %lf\n", d
);
3473 win_skip("_atof_l not found\n");
3479 ok(d
== 0.0, "d = %lf\n", d
);
3480 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3483 d
= p__atof_l(NULL
, NULL
);
3484 ok(d
== 0.0, "d = %lf\n", d
);
3485 ok(errno
== EINVAL
, "errno = %x\n", errno
);
3488 static void test_strncpy(void)
3490 #define TEST_STRNCPY_LEN 10
3491 /* use function pointer to bypass gcc builtin */
3492 char *(__cdecl
*p_strncpy
)(char*,const char*,size_t);
3494 char dst
[TEST_STRNCPY_LEN
+ 1];
3495 char not_null_terminated
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
3497 p_strncpy
= (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "strncpy");
3499 /* strlen(src) > TEST_STRNCPY_LEN */
3500 ret
= p_strncpy(dst
, "01234567890123456789", TEST_STRNCPY_LEN
);
3501 ok(ret
== dst
, "ret != dst\n");
3502 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3504 /* without null-terminated */
3505 ret
= p_strncpy(dst
, not_null_terminated
, TEST_STRNCPY_LEN
);
3506 ok(ret
== dst
, "ret != dst\n");
3507 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3509 /* strlen(src) < TEST_STRNCPY_LEN */
3510 strcpy(dst
, "0123456789");
3511 ret
= p_strncpy(dst
, "012345", TEST_STRNCPY_LEN
);
3512 ok(ret
== dst
, "ret != dst\n");
3513 ok(!strcmp(dst
, "012345"), "dst != 012345\n");
3514 ok(dst
[TEST_STRNCPY_LEN
- 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
3516 /* strlen(src) == TEST_STRNCPY_LEN */
3517 ret
= p_strncpy(dst
, "0123456789", TEST_STRNCPY_LEN
);
3518 ok(ret
== dst
, "ret != dst\n");
3519 ok(!strncmp(dst
, "0123456789", TEST_STRNCPY_LEN
), "dst != 0123456789\n");
3522 static void test_strxfrm(void)
3527 /* crashes on old version of msvcrt */
3530 ret
= strxfrm(NULL
, "src", 1);
3531 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3532 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3535 ret
= strxfrm(dest
, NULL
, 100);
3536 ok(ret
== INT_MAX
, "ret = %d\n", (int)ret
);
3537 ok(errno
== EINVAL
, "errno = %d\n", errno
);
3540 ret
= strxfrm(NULL
, "src", 0);
3541 ok(ret
== 3, "ret = %d\n", (int)ret
);
3543 ret
= strxfrm(dest
, "src", 0);
3544 ok(ret
== 3, "ret = %d\n", (int)ret
);
3545 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3548 ret
= strxfrm(dest
, "src", 5);
3549 ok(ret
== 3, "ret = %d\n", (int)ret
);
3550 ok(!strcmp(dest
, "src"), "dest = %s\n", dest
);
3554 ret
= strxfrm(dest
, "src", 1);
3555 ok(ret
== 3, "ret = %d\n", (int)ret
);
3556 ok(dest
[0] == 's', "dest[0] = %d\n", dest
[0]);
3557 ok(dest
[1] == 'a', "dest[1] = %d\n", dest
[1]);
3558 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
3560 ret
= strxfrm(dest
, "", 5);
3561 ok(ret
== 0, "ret = %d\n", (int)ret
);
3562 ok(!dest
[0], "dest[0] = %d\n", dest
[0]);
3564 if(!setlocale(LC_ALL
, "polish")) {
3565 win_skip("stxfrm tests\n");
3569 ret
= strxfrm(NULL
, "src", 0);
3570 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3572 ret
= strxfrm(dest
, "src", 0);
3573 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3574 ok(dest
[0] == 'a', "dest[0] = %d\n", dest
[0]);
3576 ret
= strxfrm(dest
, "src", ret
+1);
3577 ok(ret
< sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3578 ok(dest
[0], "dest[0] = 0\n");
3582 ret
= strxfrm(dest
, "src", 5);
3583 ok(ret
>5 && ret
<sizeof(dest
)-1, "ret = %d\n", (int)ret
);
3584 ok(!dest
[0] || broken(!p__atodbl_l
&& dest
[0]=='a'), "dest[0] = %d\n", dest
[0]);
3586 setlocale(LC_ALL
, "C");
3589 static void test__strnset_s(void)
3595 win_skip("_strnset_s not available\n");
3599 r
= p__strnset_s(NULL
, 0, 'a', 0);
3600 ok(r
== 0, "r = %d\n", r
);
3602 buf
[0] = buf
[1] = buf
[2] = 'b';
3603 r
= p__strnset_s(buf
, sizeof(buf
), 'a', 2);
3604 ok(r
== 0, "r = %d\n", r
);
3605 ok(!strcmp(buf
, "aab"), "buf = %s\n", buf
);
3607 r
= p__strnset_s(buf
, 0, 'a', 0);
3608 ok(r
== EINVAL
, "r = %d\n", r
);
3610 r
= p__strnset_s(NULL
, 0, 'a', 1);
3611 ok(r
== EINVAL
, "r = %d\n", r
);
3614 r
= p__strnset_s(buf
, sizeof(buf
)-1, 'c', 2);
3615 ok(r
== EINVAL
, "r = %d\n", r
);
3616 ok(!buf
[0] && buf
[1]=='c' && buf
[2]=='b', "buf = %s\n", buf
);
3619 static void test__wcsnset_s(void)
3621 wchar_t text
[] = L
"text";
3625 win_skip("_wcsnset_s not available\n");
3629 r
= p__wcsnset_s(NULL
, 0, 'a', 0);
3630 ok(r
== 0, "r = %d\n", r
);
3632 r
= p__wcsnset_s(text
, 0, 'a', 1);
3633 ok(r
== EINVAL
, "r = %d\n", r
);
3634 ok(text
[0] == 't', "text[0] = %d\n", text
[0]);
3636 r
= p__wcsnset_s(NULL
, 2, 'a', 1);
3637 ok(r
== EINVAL
, "r = %d\n", r
);
3639 r
= p__wcsnset_s(text
, 2, 'a', 3);
3640 ok(r
== EINVAL
, "r = %d\n", r
);
3641 ok(text
[0] == 0, "text[0] = %d\n", text
[0]);
3642 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3645 r
= p__wcsnset_s(text
, 5, 'a', 1);
3646 ok(r
== 0, "r = %d\n", r
);
3647 ok(text
[0] == 'a', "text[0] = %d\n", text
[0]);
3648 ok(text
[1] == 'e', "text[1] = %d\n", text
[1]);
3651 r
= p__wcsnset_s(text
, 5, 'b', 3);
3652 ok(r
== 0, "r = %d\n", r
);
3653 ok(text
[0] == 'b', "text[0] = %d\n", text
[0]);
3654 ok(text
[1] == 0, "text[1] = %d\n", text
[1]);
3655 ok(text
[2] == 'x', "text[2] = %d\n", text
[2]);
3658 static void test__wcsset_s(void)
3664 win_skip("_wcsset_s not available\n");
3668 r
= p__wcsset_s(NULL
, 0, 'a');
3669 ok(r
== EINVAL
, "r = %d\n", r
);
3672 r
= p__wcsset_s(str
, 0, 'a');
3673 ok(r
== EINVAL
, "r = %d\n", r
);
3674 ok(str
[0] == 'a', "str[0] = %d\n", str
[0]);
3678 r
= p__wcsset_s(str
, 2, 'c');
3679 ok(r
== EINVAL
, "r = %d\n", r
);
3680 ok(!str
[0], "str[0] = %d\n", str
[0]);
3681 ok(str
[1] == 'b', "str[1] = %d\n", str
[1]);
3686 r
= p__wcsset_s(str
, 3, 'c');
3687 ok(r
== 0, "r = %d\n", r
);
3688 ok(str
[0] == 'c', "str[0] = %d\n", str
[0]);
3689 ok(str
[1] == 0, "str[1] = %d\n", str
[1]);
3690 ok(str
[2] == 'b', "str[2] = %d\n", str
[2]);
3693 static void test__mbscmp(void)
3695 static const unsigned char a
[] = {'a',0}, b
[] = {'b',0};
3700 win_skip("_mbscmp tests\n");
3704 ret
= _mbscmp(NULL
, NULL
);
3705 ok(ret
== INT_MAX
, "got %d\n", ret
);
3707 ret
= _mbscmp(a
, NULL
);
3708 ok(ret
== INT_MAX
, "got %d\n", ret
);
3710 ret
= _mbscmp(NULL
, a
);
3711 ok(ret
== INT_MAX
, "got %d\n", ret
);
3713 ret
= _mbscmp(a
, a
);
3714 ok(!ret
, "got %d\n", ret
);
3716 ret
= _mbscmp(a
, b
);
3717 ok(ret
== -1, "got %d\n", ret
);
3719 ret
= _mbscmp(b
, a
);
3720 ok(ret
== 1, "got %d\n", ret
);
3724 win_skip("_mbscmp_l tests\n");
3728 ret
= p_mbscmp_l(a
, b
, NULL
);
3729 ok(ret
== -1, "got %d\n", ret
);
3732 static void test__ismbclx(void)
3734 int ret
, cp
= _getmbcp();
3737 ok(!ret
, "got %d\n", ret
);
3740 ok(!ret
, "got %d\n", ret
);
3743 ok(!ret
, "got %d\n", ret
);
3747 ret
= _ismbcl0(0x8140);
3748 ok(!ret
, "got %d\n", ret
);
3750 ret
= _ismbcl1(0x889f);
3751 ok(!ret
, "got %d\n", ret
);
3753 ret
= _ismbcl2(0x989f);
3754 ok(!ret
, "got %d\n", ret
);
3759 ok(!ret
, "got %d\n", ret
);
3761 ret
= _ismbcl0(0x8140);
3762 ok(ret
, "got %d\n", ret
);
3764 ret
= _ismbcl0(0x817f);
3765 ok(!ret
, "got %d\n", ret
);
3768 ok(!ret
, "got %d\n", ret
);
3770 ret
= _ismbcl1(0x889f);
3771 ok(ret
, "got %d\n", ret
);
3773 ret
= _ismbcl1(0x88fd);
3774 ok(!ret
, "got %d\n", ret
);
3777 ok(!ret
, "got %d\n", ret
);
3779 ret
= _ismbcl2(0x989f);
3780 ok(ret
, "got %d\n", ret
);
3782 ret
= _ismbcl2(0x993f);
3783 ok(!ret
, "got %d\n", ret
);
3788 static void test__memicmp(void)
3790 static const char *s1
= "abc";
3791 static const char *s2
= "aBd";
3794 ret
= p__memicmp(NULL
, NULL
, 0);
3795 ok(!ret
, "got %d\n", ret
);
3797 ret
= p__memicmp(s1
, s2
, 2);
3798 ok(!ret
, "got %d\n", ret
);
3800 ret
= p__memicmp(s1
, s2
, 3);
3801 ok(ret
== -1, "got %d\n", ret
);
3806 /* Following calls crash on WinXP/W2k3. */
3808 ret
= p__memicmp(NULL
, NULL
, 1);
3809 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3810 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3813 ret
= p__memicmp(s1
, NULL
, 1);
3814 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3815 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3818 ret
= p__memicmp(NULL
, s2
, 1);
3819 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3820 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3823 static void test__memicmp_l(void)
3825 static const char *s1
= "abc";
3826 static const char *s2
= "aBd";
3831 win_skip("_memicmp_l not found.\n");
3836 ret
= p__memicmp_l(NULL
, NULL
, 0, NULL
);
3837 ok(!ret
, "got %d\n", ret
);
3838 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3841 ret
= p__memicmp_l(NULL
, NULL
, 1, NULL
);
3842 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3843 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3846 ret
= p__memicmp_l(s1
, NULL
, 1, NULL
);
3847 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3848 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3851 ret
= p__memicmp_l(NULL
, s2
, 1, NULL
);
3852 ok(ret
== _NLSCMPERROR
, "got %d\n", ret
);
3853 ok(errno
== EINVAL
, "errno is %d, expected EINVAL\n", errno
);
3856 ret
= p__memicmp_l(s1
, s2
, 2, NULL
);
3857 ok(!ret
, "got %d\n", ret
);
3858 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3861 ret
= p__memicmp_l(s1
, s2
, 3, NULL
);
3862 ok(ret
== -1, "got %d\n", ret
);
3863 ok(errno
== 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno
);
3866 static void test__strupr(void)
3868 const char str
[] = "123";
3869 const char *const_p
;
3874 mem
= VirtualAlloc(NULL
, sizeof(str
), MEM_COMMIT
, PAGE_READWRITE
);
3875 ok(mem
!= NULL
, "VirtualAlloc failed\n");
3876 memcpy(mem
, str
, sizeof(str
));
3877 ok(VirtualProtect(mem
, sizeof(str
), PAGE_READONLY
, &prot
), "VirtualProtect failed\n");
3879 strcpy(str2
, "aBc");
3881 ok(p
== str2
, "_strupr returned %p\n", p
);
3882 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3885 ok(p
== mem
, "_strupr returned %p\n", p
);
3886 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3888 const_p
= "ALREADY_UPPERCASE";
3889 p
= _strupr((char *)const_p
);
3890 ok(p
== const_p
, "_strupr returned %p\n", p
);
3892 if(!setlocale(LC_ALL
, "english")) {
3893 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3894 win_skip("English locale _strupr tests\n");
3898 strcpy(str2
, "aBc");
3900 ok(p
== str2
, "_strupr returned %p\n", p
);
3901 ok(!strcmp(str2
, "ABC"), "str2 = %s\n", str2
);
3903 if (0) /* crashes on Windows */
3906 ok(p
== mem
, "_strupr returned %p\n", p
);
3907 ok(!strcmp(mem
, "123"), "mem = %s\n", mem
);
3910 setlocale(LC_ALL
, "C");
3911 VirtualFree(mem
, sizeof(str
), MEM_RELEASE
);
3914 static void test__tcsncoll(void)
3923 static const struct test tests
[] = {
3924 { "English", "ABCD", "ABCD", 4, 0 },
3925 { "English", "ABCD", "ABCD", 10, 0 },
3927 { "English", "ABC", "ABCD", 3, 0 },
3928 { "English", "ABC", "ABCD", 4, -1 },
3929 { "English", "ABC", "ABCD", 10, -1 },
3931 { "English", "ABCD", "ABC", 3, 0 },
3932 { "English", "ABCD", "ABC", 4, 1 },
3933 { "English", "ABCD", "ABC", 10, 1 },
3935 { "English", "ABCe", "ABCf", 3, 0 },
3936 { "English", "abcd", "ABCD", 10, -1 },
3938 { "C", "ABCD", "ABCD", 4, 0 },
3939 { "C", "ABCD", "ABCD", 10, 0 },
3941 { "C", "ABC", "ABCD", 3, 0 },
3942 { "C", "ABC", "ABCD", 10, -1 },
3944 { "C", "ABCD", "ABC", 3, 0 },
3945 { "C", "ABCD", "ABC", 10, 1 },
3947 { "C", "ABCe", "ABCf", 3, 0 },
3948 { "C", "abcd", "ABCD", 10, 1 },
3957 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3959 if (!setlocale(LC_ALL
, tests
[i
].locale
))
3961 win_skip("%s locale _tcsncoll tests\n", tests
[i
].locale
);
3962 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
3963 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
3967 memset(str1
, 0xee, sizeof(str1
));
3968 strcpy(str1
, tests
[i
].str1
);
3970 memset(str2
, 0xff, sizeof(str2
));
3971 strcpy(str2
, tests
[i
].str2
);
3973 ret
= _strncoll(str1
, str2
, tests
[i
].count
);
3975 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3976 else if (tests
[i
].exp
< 0)
3977 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3979 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3981 memset(str1W
, 0xee, sizeof(str1W
));
3982 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
3985 memset(str2W
, 0xff, sizeof(str2W
));
3986 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
3989 ret
= _wcsncoll(str1W
, str2W
, tests
[i
].count
);
3991 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3992 else if (tests
[i
].exp
< 0)
3993 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3995 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
3999 static void test__tcsnicoll(void)
4008 static const struct test tests
[] = {
4009 { "English", "abcd", "ABCD", 4, 0 },
4010 { "English", "abcd", "ABCD", 10, 0 },
4012 { "English", "abc", "ABCD", 3, 0 },
4013 { "English", "abc", "ABCD", 4, -1 },
4014 { "English", "abc", "ABCD", 10, -1 },
4016 { "English", "abcd", "ABC", 3, 0 },
4017 { "English", "abcd", "ABC", 4, 1 },
4018 { "English", "abcd", "ABC", 10, 1 },
4020 { "English", "abcE", "ABCF", 3, 0 },
4022 { "C", "abcd", "ABCD", 4, 0 },
4023 { "C", "abcd", "ABCD", 10, 0 },
4025 { "C", "abc", "ABCD", 3, 0 },
4026 { "C", "abc", "ABCD", 10, -1 },
4028 { "C", "abcd", "ABC", 3, 0 },
4029 { "C", "abcd", "ABC", 10, 1 },
4031 { "C", "abce", "ABCf", 3, 0 },
4040 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4042 if (!setlocale(LC_ALL
, tests
[i
].locale
))
4044 win_skip("%s locale _tcsnicoll tests\n", tests
[i
].locale
);
4045 for (; i
+1 < ARRAY_SIZE(tests
); i
++)
4046 if (strcmp(tests
[i
].locale
, tests
[i
+1].locale
)) break;
4050 memset(str1
, 0xee, sizeof(str1
));
4051 strcpy(str1
, tests
[i
].str1
);
4053 memset(str2
, 0xff, sizeof(str2
));
4054 strcpy(str2
, tests
[i
].str2
);
4056 ret
= _strnicoll(str1
, str2
, tests
[i
].count
);
4058 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4059 else if (tests
[i
].exp
< 0)
4060 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4062 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4064 memset(str1W
, 0xee, sizeof(str1W
));
4065 len
= mbstowcs(str1W
, str1
, ARRAY_SIZE(str1W
));
4068 memset(str2W
, 0xff, sizeof(str2W
));
4069 len
= mbstowcs(str2W
, str2
, ARRAY_SIZE(str2W
));
4072 ret
= _wcsnicoll(str1W
, str2W
, tests
[i
].count
);
4074 ok(!ret
, "expected 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4075 else if (tests
[i
].exp
< 0)
4076 ok(ret
< 0, "expected < 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4078 ok(ret
> 0, "expected > 0, got %d for %s, %s, %d\n", ret
, str1
, str2
, (int)tests
[i
].count
);
4082 static void test___strncnt(void)
4103 win_skip("__strncnt() is not available.\n");
4107 if (0) /* crashes */
4108 ret
= p___strncnt(NULL
, 1);
4110 for (i
= 0; i
< ARRAY_SIZE(strncnt_tests
); ++i
)
4112 ret
= p___strncnt(strncnt_tests
[i
].str
, strncnt_tests
[i
].size
);
4113 ok(ret
== strncnt_tests
[i
].ret
, "%u: unexpected return value %u.\n", i
, (int)ret
);
4117 static void test_C_locale(void)
4122 static const char *locales
[] = { NULL
, "C" };
4124 /* C locale only converts case for [a-zA-Z] */
4125 setlocale(LC_ALL
, "C");
4126 for (i
= 0; i
<= 0xffff; i
++)
4128 ret
= p_towlower(i
);
4129 if (i
>= 'A' && i
<= 'Z')
4131 exp
= i
+ 'a' - 'A';
4132 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4135 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
4137 ret
= p_towupper(i
);
4138 if (i
>= 'a' && i
<= 'z')
4140 exp
= i
+ 'A' - 'a';
4141 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4144 ok(ret
== i
, "expected self %x, got %x for C locale\n", i
, ret
);
4147 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
4149 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
4153 for (i
= 0; i
< ARRAY_SIZE(locales
); i
++) {
4154 locale
= locales
[i
] ? p__create_locale(LC_ALL
, locales
[i
]) : NULL
;
4156 for (j
= 0; j
<= 0xffff; j
++) {
4157 ret
= p__towlower_l(j
, locale
);
4158 if (j
>= 'A' && j
<= 'Z')
4160 exp
= j
+ 'a' - 'A';
4161 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4164 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
4166 ret
= p__towupper_l(j
, locale
);
4167 if (j
>= 'a' && j
<= 'z')
4169 exp
= j
+ 'A' - 'a';
4170 ok(ret
== exp
, "expected %x, got %x for C locale\n", exp
, ret
);
4173 ok(ret
== j
, "expected self %x, got %x for C locale\n", j
, ret
);
4176 p__free_locale(locale
);
4180 static void test_strstr(void)
4182 static char long_str
[1024];
4184 const char *haystack
;
4191 { "aabc", "abc", 1 },
4192 { "aaaa", "aaaa", 0 },
4193 { "simple", "simple", 0 },
4194 { "aaaaxaaaaxaaaa", "aaaaa", -1 },
4195 { "aaaaxaaaaxaaaaa", "aaaaa", 10 },
4196 { "abcabcdababcdabcdabde", "abcdabd", 13 },
4197 { "abababababcabababcababbba", "abababcaba", 4 },
4198 { long_str
, long_str
+1, 0 }
4200 const char *r
, *exp
;
4203 memset(long_str
, 'a', sizeof(long_str
)-1);
4205 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
4207 r
= strstr(tests
[i
].haystack
, tests
[i
].needle
);
4208 exp
= tests
[i
].off
== -1 ? NULL
: tests
[i
].haystack
+ tests
[i
].off
;
4209 ok(r
== exp
, "%d) strstr returned %p, expected %p\n", i
, r
, exp
);
4213 static void test_iswdigit(void)
4215 static const struct {
4222 { 0xff16, C1_DIGIT
},
4223 { 0x0660, C1_DIGIT
},
4224 { 0x0ce6, C1_DIGIT
}
4228 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4230 r
= iswdigit(tests
[i
].c
);
4231 ok(r
== tests
[i
].r
, "iswdigit returned %x for %x\n", r
, tests
[i
].c
);
4235 static void test_wcscmp(void)
4239 r
= wcscmp(L
"a", L
"z");
4240 ok(r
== -1, "wcscmp returned %d\n", r
);
4242 r
= wcscmp(L
"z", L
"a");
4243 ok(r
== 1, "wcscmp returned %d\n", r
);
4245 r
= wcscmp(L
"f", L
"f");
4246 ok(!r
, "wcscmp returned %d\n", r
);
4249 static const char* debugstr_ldouble(_LDOUBLE
*v
)
4251 static char buf
[2 * ARRAY_SIZE(v
->ld
) + 1];
4254 for(i
=0; i
<ARRAY_SIZE(v
->ld
); i
++)
4256 buf
[2*i
] = v
->ld
[i
] / 16 + '0';
4257 if(buf
[2*i
] > '9') buf
[2*i
] -= 10 + '0' - 'a';
4258 buf
[2*i
+1] = v
->ld
[i
] % 16 + '0';
4259 if(buf
[2*i
+1] > '9') buf
[2*i
+1] -= 10 + '0' - 'a';
4261 buf
[2 * ARRAY_SIZE(v
->ld
)] = 0;
4265 static void test___STRINGTOLD(void)
4267 static const struct {
4277 { "-0.0", 4, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }} },
4278 { "1e0", 3, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f }} },
4279 { "1.7976931348623158e+308", 23, 0, {{ 0xaf, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x43 }} },
4280 { "1.7976931348623159e+308", 23, 0, {{ 0xb1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x43 }} },
4281 { "3.65e-4951", 10, 0, {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} },
4282 { "1.82e-4951", 10, 0, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}, TRUE
},
4283 { "1e-99999", 8, 1, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} },
4284 { "1.18e+4932", 10, 0, {{ 0x25, 0x75, 0x06, 0x68, 0x8a, 0xf1, 0xe7, 0xfd, 0xfe, 0x7f }} },
4285 { "1.19e+4932", 10, 2, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f }} },
4286 { "1e+99999", 8, 2, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f }} },
4293 for(i
=0; i
<ARRAY_SIZE(tests
); i
++)
4296 r
= __STRINGTOLD(&v
, &endptr
, tests
[i
].str
, 0);
4297 todo_wine_if(tests
[i
].todo
)
4298 ok(r
== tests
[i
].r
, "%d) r = %d\n", i
, r
);
4299 ok(endptr
== tests
[i
].str
+ tests
[i
].endptr
, "%d) endptr = %p, expected %p\n",
4300 i
, endptr
, tests
[i
].str
+tests
[i
].endptr
);
4301 ok(!memcmp(&v
, &tests
[i
].v
, sizeof(v
)), "%d) v = %s\n", i
, debugstr_ldouble(&v
));
4302 ok(errno
== 0xdeadbeef, "%d) errno = %x\n", i
, errno
);
4306 static void test_SpecialCasing(void)
4317 struct test ucases
[] = {
4318 {"English", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
4319 {"English", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
4321 {"Turkish", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
4322 {"Turkish", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
4324 struct test lcases
[] = {
4325 {"English", 'i', 'I'}, /* LATIN SMALL LETTER I */
4326 {"English", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
4328 {"Turkish", 'i', 'I'}, /* LATIN SMALL LETTER I */
4329 {"Turkish", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
4332 for (i
= 0; i
< ARRAY_SIZE(ucases
); i
++) {
4333 if (!setlocale(LC_ALL
, ucases
[i
].lang
)) {
4334 win_skip("skipping special case tests for %s\n", ucases
[i
].lang
);
4338 ret
= p_towlower(ucases
[i
].ch
);
4339 exp
= ucases
[i
].exp
? ucases
[i
].exp
: ucases
[i
].ch
;
4340 ok(ret
== exp
, "expected lowercase %x, got %x for locale %s\n", exp
, ret
, ucases
[i
].lang
);
4343 for (i
= 0; i
< ARRAY_SIZE(lcases
); i
++) {
4344 if (!setlocale(LC_ALL
, lcases
[i
].lang
)) {
4345 win_skip("skipping special case tests for %s\n", lcases
[i
].lang
);
4349 ret
= p_towupper(lcases
[i
].ch
);
4350 exp
= lcases
[i
].exp
? lcases
[i
].exp
: lcases
[i
].ch
;
4351 ok(ret
== exp
, "expected uppercase %x, got %x for locale %s\n", exp
, ret
, lcases
[i
].lang
);
4354 setlocale(LC_ALL
, "C");
4356 if (!p__towlower_l
|| !p__towupper_l
|| !p__create_locale
)
4358 win_skip("_towlower_l/_towupper_l/_create_locale not available\n");
4362 /* test _towlower_l creating locale */
4363 for (i
= 0; i
< ARRAY_SIZE(ucases
); i
++) {
4364 if (!(locale
= p__create_locale(LC_ALL
, ucases
[i
].lang
))) {
4365 win_skip("locale %s not available. skipping\n", ucases
[i
].lang
);
4369 ret
= p__towlower_l(ucases
[i
].ch
, locale
);
4370 exp
= ucases
[i
].exp
? ucases
[i
].exp
: ucases
[i
].ch
;
4371 ok(ret
== exp
, "expected lowercase %x, got %x for locale %s\n", exp
, ret
, ucases
[i
].lang
);
4373 p__free_locale(locale
);
4376 /* test _towupper_l creating locale */
4377 for (i
= 0; i
< ARRAY_SIZE(lcases
); i
++) {
4378 if (!(locale
= p__create_locale(LC_ALL
, lcases
[i
].lang
))) {
4379 win_skip("locale %s not available. skipping\n", lcases
[i
].lang
);
4383 ret
= p__towupper_l(lcases
[i
].ch
, locale
);
4384 exp
= lcases
[i
].exp
? lcases
[i
].exp
: lcases
[i
].ch
;
4385 ok(ret
== exp
, "expected uppercase %x, got %x for locale %s\n", exp
, ret
, lcases
[i
].lang
);
4387 p__free_locale(locale
);
4392 static void test__mbbtype(void)
4394 static const char *test_locales
[] =
4398 "English_Australia",
4406 "Portuguese_Brazil",
4408 "Spanish_Argentina",
4417 for (i
= 0; i
< ARRAY_SIZE(test_locales
); ++i
)
4419 setlocale(LC_ALL
, test_locales
[i
]);
4420 _setmbcp(_MB_CP_LOCALE
);
4421 for (c
= 0; c
< 256; ++c
)
4424 expected
= _MBC_LEAD
;
4425 else if (isprint(c
))
4426 expected
= _MBC_SINGLE
;
4428 expected
= _MBC_ILLEGAL
;
4430 ret
= _mbbtype(c
, 0);
4431 ok(ret
== expected
, "test %u, c %#x, got ret %#x, expected %#x.\n", i
, c
, ret
, expected
);
4434 expected
= _MBC_TRAIL
;
4436 expected
= _MBC_ILLEGAL
;
4438 ret
= _mbbtype(c
, 1);
4439 ok(ret
== expected
, "test %u, c %#x, got ret %#x, expected %#x.\n", i
, c
, ret
, expected
);
4447 static const char xilstring
[]="c:/xilinx";
4450 hMsvcrt
= GetModuleHandleA("msvcrt.dll");
4452 hMsvcrt
= GetModuleHandleA("msvcrtd.dll");
4453 ok(hMsvcrt
!= 0, "GetModuleHandleA failed\n");
4454 SET(pmemcpy
,"memcpy");
4455 p_memcpy_s
= (void*)GetProcAddress( hMsvcrt
, "memcpy_s" );
4456 p_memmove_s
= (void*)GetProcAddress( hMsvcrt
, "memmove_s" );
4457 SET(pmemcmp
,"memcmp");
4458 SET(p_mbctype
,"_mbctype");
4459 SET(p__mb_cur_max
,"__mb_cur_max");
4460 SET(p_strcpy
, "strcpy");
4461 SET(p_strcmp
, "strcmp");
4462 SET(p_strncmp
, "strncmp");
4463 pstrcpy_s
= (void *)GetProcAddress( hMsvcrt
,"strcpy_s" );
4464 pstrcat_s
= (void *)GetProcAddress( hMsvcrt
,"strcat_s" );
4465 p_mbscat_s
= (void*)GetProcAddress( hMsvcrt
, "_mbscat_s" );
4466 p_mbsnbcat_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcat_s" );
4467 p_mbsnbcpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbsnbcpy_s" );
4468 p__mbscpy_s
= (void *)GetProcAddress( hMsvcrt
,"_mbscpy_s" );
4469 p_wcscpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcscpy_s" );
4470 p_wcsncpy_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncpy_s" );
4471 p_wcsncat_s
= (void *)GetProcAddress( hMsvcrt
,"wcsncat_s" );
4472 p_wcsupr_s
= (void *)GetProcAddress( hMsvcrt
,"_wcsupr_s" );
4473 p_strnlen
= (void *)GetProcAddress( hMsvcrt
,"strnlen" );
4474 p_strtoi64
= (void *)GetProcAddress(hMsvcrt
, "_strtoi64");
4475 p_strtoui64
= (void *)GetProcAddress(hMsvcrt
, "_strtoui64");
4476 p_wcstoi64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoi64");
4477 p_wcstoui64
= (void *)GetProcAddress(hMsvcrt
, "_wcstoui64");
4478 pmbstowcs_s
= (void *)GetProcAddress(hMsvcrt
, "mbstowcs_s");
4479 pwcstombs_s
= (void *)GetProcAddress(hMsvcrt
, "wcstombs_s");
4480 p_wcstombs_s_l
= (void *)GetProcAddress(hMsvcrt
, "_wcstombs_s_l");
4481 pwcsrtombs
= (void *)GetProcAddress(hMsvcrt
, "wcsrtombs");
4482 p_gcvt_s
= (void *)GetProcAddress(hMsvcrt
, "_gcvt_s");
4483 p_itoa_s
= (void *)GetProcAddress(hMsvcrt
, "_itoa_s");
4484 p_strlwr_s
= (void *)GetProcAddress(hMsvcrt
, "_strlwr_s");
4485 p_ultoa_s
= (void *)GetProcAddress(hMsvcrt
, "_ultoa_s");
4486 p_wcslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_wcslwr_s");
4487 p_mbsupr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbsupr_s");
4488 p_mbslwr_s
= (void*)GetProcAddress(hMsvcrt
, "_mbslwr_s");
4489 p_btowc
= (void*)GetProcAddress(hMsvcrt
, "btowc");
4490 p_wctob
= (void*)GetProcAddress(hMsvcrt
, "wctob");
4491 p_wcrtomb
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb");
4492 p_wcrtomb_s
= (void*)GetProcAddress(hMsvcrt
, "wcrtomb_s");
4493 p_tolower
= (void*)GetProcAddress(hMsvcrt
, "tolower");
4494 p_towlower
= (void*)GetProcAddress(hMsvcrt
, "towlower");
4495 p__towlower_l
= (void*)GetProcAddress(hMsvcrt
, "_towlower_l");
4496 p_towupper
= (void*)GetProcAddress(hMsvcrt
, "towupper");
4497 p__towupper_l
= (void*)GetProcAddress(hMsvcrt
, "_towupper_l");
4498 p__create_locale
= (void*)GetProcAddress(hMsvcrt
, "_create_locale");
4499 p__free_locale
= (void*)GetProcAddress(hMsvcrt
, "_free_locale");
4500 p_mbrlen
= (void*)GetProcAddress(hMsvcrt
, "mbrlen");
4501 p_mbrtowc
= (void*)GetProcAddress(hMsvcrt
, "mbrtowc");
4502 p_mbsrtowcs
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs");
4503 p_mbsrtowcs_s
= (void*)GetProcAddress(hMsvcrt
, "mbsrtowcs_s");
4504 p__atodbl_l
= (void*)GetProcAddress(hMsvcrt
, "_atodbl_l");
4505 p__atof_l
= (void*)GetProcAddress(hMsvcrt
, "_atof_l");
4506 p__strtod_l
= (void*)GetProcAddress(hMsvcrt
, "_strtod_l");
4507 p__strnset_s
= (void*)GetProcAddress(hMsvcrt
, "_strnset_s");
4508 p__wcsnset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsnset_s");
4509 p__wcsset_s
= (void*)GetProcAddress(hMsvcrt
, "_wcsset_s");
4510 p__mbsnlen
= (void*)GetProcAddress(hMsvcrt
, "_mbsnlen");
4511 p__mbccpy_s
= (void*)GetProcAddress(hMsvcrt
, "_mbccpy_s");
4512 p__memicmp
= (void*)GetProcAddress(hMsvcrt
, "_memicmp");
4513 p__memicmp_l
= (void*)GetProcAddress(hMsvcrt
, "_memicmp_l");
4514 p___strncnt
= (void*)GetProcAddress(hMsvcrt
, "__strncnt");
4515 p_mbsnextc_l
= (void*)GetProcAddress(hMsvcrt
, "_mbsnextc_l");
4516 p_mbscmp_l
= (void*)GetProcAddress(hMsvcrt
, "_mbscmp_l");
4518 /* MSVCRT memcpy behaves like memmove for overlapping moves,
4519 MFC42 CString::Insert seems to rely on that behaviour */
4520 strcpy(mem
,xilstring
);
4521 nLen
=strlen(xilstring
);
4522 pmemcpy(mem
+5, mem
,nLen
+1);
4523 ok(pmemcmp(mem
+5,xilstring
, nLen
) == 0,
4524 "Got result %s\n",mem
+5);
4526 /* run tolower tests first */
4559 test__wcstombs_s_l();
4596 test___STRINGTOLD();
4597 test_SpecialCasing();