msvcrt: Add _mbctohira implementation.
[wine.git] / dlls / msvcrt / tests / string.c
blob4e48cd2dc4a92e3295930699b51f2a1bbc9bda3e
1 /*
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"
22 #include <string.h>
23 #include <mbstring.h>
24 #include <wchar.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <mbctype.h>
28 #include <locale.h>
29 #include <errno.h>
30 #include <limits.h>
31 #include <math.h>
33 /* make it use a definition from string.h */
34 #undef strncpy
35 #include "winbase.h"
36 #include "winnls.h"
38 static char *buf_to_string(const unsigned char *bin, int len, int nr)
40 static char buf[2][1024];
41 char *w = buf[nr];
42 int i;
44 for (i = 0; i < len; i++)
46 sprintf(w, "%02x ", (unsigned char)bin[i]);
47 w += strlen(w);
49 return buf[nr];
52 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
53 #define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); }
55 static void* (__cdecl *pmemcpy)(void *, const void *, size_t n);
56 static int (__cdecl *p_memcpy_s)(void *, size_t, const void *, size_t);
57 static int (__cdecl *p_memmove_s)(void *, size_t, const void *, size_t);
58 static int* (__cdecl *pmemcmp)(void *, const void *, size_t n);
59 static int (__cdecl *pstrcpy_s)(char *dst, size_t len, const char *src);
60 static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
61 static int (__cdecl *p_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
62 static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
63 static int (__cdecl *p__mbscpy_s)(unsigned char*, size_t, const unsigned char*);
64 static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
65 static int (__cdecl *p_wcsncpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc, size_t count);
66 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
67 static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
68 static size_t (__cdecl *p_strnlen)(const char *, size_t);
69 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
70 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
71 static __int64 (__cdecl *p_wcstoi64)(const wchar_t *, wchar_t **, int);
72 static unsigned __int64 (__cdecl *p_wcstoui64)(const wchar_t *, wchar_t **, int);
73 static int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
74 static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
75 static size_t (__cdecl *p_mbsrtowcs)(wchar_t*, const char**, size_t, mbstate_t*);
76 static size_t (__cdecl *pwcsrtombs)(char*, const wchar_t**, size_t, int*);
77 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
78 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
79 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
80 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
81 static int *p__mb_cur_max;
82 static unsigned char *p_mbctype;
83 static int (__cdecl *p_wcslwr_s)(wchar_t*,size_t);
84 static errno_t (__cdecl *p_mbsupr_s)(unsigned char *str, size_t numberOfElements);
85 static errno_t (__cdecl *p_mbslwr_s)(unsigned char *str, size_t numberOfElements);
86 static int (__cdecl *p_wctob)(wint_t);
87 static size_t (__cdecl *p_wcrtomb)(char*, wchar_t, mbstate_t*);
88 static int (__cdecl *p_tolower)(int);
89 static size_t (__cdecl *p_mbrlen)(const char*, size_t, mbstate_t*);
90 static size_t (__cdecl *p_mbrtowc)(wchar_t*, const char*, size_t, mbstate_t*);
91 static int (__cdecl *p__atodbl_l)(_CRT_DOUBLE*,char*,_locale_t);
92 static int (__cdecl *p__strnset_s)(char*,size_t,int,size_t);
93 static int (__cdecl *p__wcsset_s)(wchar_t*,size_t,wchar_t);
95 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
96 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
98 static HMODULE hMsvcrt;
100 static void test_swab( void ) {
101 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
102 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
103 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
104 char expected3[] = "$";
106 char from[30];
107 char to[30];
109 int testsize;
111 /* Test 1 - normal even case */
112 memset(to,'$', sizeof(to));
113 memset(from,'@', sizeof(from));
114 testsize = 26;
115 memcpy(from, original, testsize);
116 _swab( from, to, testsize );
117 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
119 /* Test 2 - uneven case */
120 memset(to,'$', sizeof(to));
121 memset(from,'@', sizeof(from));
122 testsize = 25;
123 memcpy(from, original, testsize);
124 _swab( from, to, testsize );
125 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
127 /* Test 3 - from = to */
128 memset(to,'$', sizeof(to));
129 memset(from,'@', sizeof(from));
130 testsize = 26;
131 memcpy(to, original, testsize);
132 _swab( to, to, testsize );
133 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
135 /* Test 4 - 1 bytes */
136 memset(to,'$', sizeof(to));
137 memset(from,'@', sizeof(from));
138 testsize = 1;
139 memcpy(from, original, testsize);
140 _swab( from, to, testsize );
141 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
144 #if 0 /* use this to generate more tests */
146 static void test_codepage(int cp)
148 int i;
149 int prev;
150 int count = 1;
152 ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
154 prev = p_mbctype[0];
155 printf("static int result_cp_%d_mbctype[] = { ", cp);
156 for (i = 1; i < 257; i++)
158 if (p_mbctype[i] != prev)
160 printf("0x%x,%d, ", prev, count);
161 prev = p_mbctype[i];
162 count = 1;
164 else
165 count++;
167 printf("0x%x,%d };\n", prev, count);
170 #else
172 /* RLE-encoded mbctype tables for given codepages */
173 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
174 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
175 static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
176 0xc,126, 0,1 };
177 static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
178 0,1 };
179 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
180 0x0,2, 0x4,32, 0xc,94, 0,1 };
182 static void test_cp_table(int cp, int *result)
184 int i;
185 int count = 0;
186 int curr = 0;
187 _setmbcp(cp);
188 for (i = 0; i < 256; i++)
190 if (count == 0)
192 curr = result[0];
193 count = result[1];
194 result += 2;
196 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);
197 count--;
201 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
203 #endif
205 static void test_mbcp(void)
207 int mb_orig_max = *p__mb_cur_max;
208 int curr_mbcp = _getmbcp();
209 unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
210 unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
211 unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
212 unsigned char buf[16];
213 int step;
214 CPINFO cp_info;
216 /* _mbtype tests */
218 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
219 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
220 * CP1252 (or the ACP?) so we test only a few ASCII characters */
221 _setmbcp(1252);
222 expect_eq(p_mbctype[10], 0, char, "%x");
223 expect_eq(p_mbctype[50], 0, char, "%x");
224 expect_eq(p_mbctype[66], _SBUP, char, "%x");
225 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
226 expect_eq(p_mbctype[128], 0, char, "%x");
227 _setmbcp(1250);
228 expect_eq(p_mbctype[10], 0, char, "%x");
229 expect_eq(p_mbctype[50], 0, char, "%x");
230 expect_eq(p_mbctype[66], _SBUP, char, "%x");
231 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
232 expect_eq(p_mbctype[128], 0, char, "%x");
234 /* double byte code pages */
235 test_codepage(932);
236 test_codepage(936);
237 test_codepage(949);
238 test_codepage(950);
240 _setmbcp(936);
241 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);
242 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
243 ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
244 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
245 ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
246 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
247 ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
249 /* _ismbslead */
250 expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
251 expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
252 expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
253 expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
254 expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
255 expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
256 expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
257 expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
258 expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
260 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
261 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
262 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
263 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
265 /* _ismbstrail */
266 expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
267 expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
268 expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
269 expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
270 expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
271 expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
272 expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
273 expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
274 expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
276 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
277 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
278 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
279 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
280 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
281 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
283 /* _mbsbtype */
284 expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
285 expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
286 expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
287 expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
288 expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
289 expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
290 expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
291 expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
292 expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
294 expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
295 expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
296 expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
297 expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
298 expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
299 expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
301 /* _mbsnextc */
302 expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
303 expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
304 expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
306 /* _mbclen/_mbslen */
307 expect_eq(_mbclen(mbstring), 2, int, "%d");
308 expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
309 expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
310 expect_eq(_mbslen(mbstring2), 4, int, "%d");
311 expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
312 expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
314 /* mbrlen */
315 if(!setlocale(LC_ALL, ".936") || !p_mbrlen) {
316 win_skip("mbrlen tests\n");
317 }else {
318 mbstate_t state = 0;
319 expect_eq(p_mbrlen((const char*)mbstring, 2, NULL), 2, int, "%d");
320 expect_eq(p_mbrlen((const char*)&mbstring[2], 2, NULL), 2, int, "%d");
321 expect_eq(p_mbrlen((const char*)&mbstring[3], 2, NULL), 1, int, "%d");
322 expect_eq(p_mbrlen((const char*)mbstring, 1, NULL), -2, int, "%d");
323 expect_eq(p_mbrlen((const char*)mbstring, 1, &state), -2, int, "%d");
324 ok(state == mbstring[0], "incorrect state value (%x)\n", state);
325 expect_eq(p_mbrlen((const char*)&mbstring[1], 1, &state), 2, int, "%d");
328 /* mbrtowc */
329 if(!setlocale(LC_ALL, ".936") || !p_mbrtowc) {
330 win_skip("mbrtowc tests\n");
331 }else {
332 mbstate_t state = 0;
333 wchar_t dst;
334 expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 2, NULL), 2, int, "%d");
335 ok(dst == 0x6c28, "dst = %x, expected 0x6c28\n", dst);
336 expect_eq(p_mbrtowc(&dst, (const char*)mbstring+2, 2, NULL), 2, int, "%d");
337 ok(dst == 0x3f, "dst = %x, expected 0x3f\n", dst);
338 expect_eq(p_mbrtowc(&dst, (const char*)mbstring+3, 2, NULL), 1, int, "%d");
339 ok(dst == 0x20, "dst = %x, expected 0x20\n", dst);
340 expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 1, NULL), -2, int, "%d");
341 ok(dst == 0, "dst = %x, expected 0\n", dst);
342 expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 1, &state), -2, int, "%d");
343 ok(dst == 0, "dst = %x, expected 0\n", dst);
344 ok(state == mbstring[0], "incorrect state value (%x)\n", state);
345 expect_eq(p_mbrtowc(&dst, (const char*)mbstring+1, 1, &state), 2, int, "%d");
346 ok(dst == 0x6c28, "dst = %x, expected 0x6c28\n", dst);
347 ok(state == 0, "incorrect state value (%x)\n", state);
349 setlocale(LC_ALL, "C");
351 /* _mbccpy/_mbsncpy */
352 memset(buf, 0xff, sizeof(buf));
353 _mbccpy(buf, mbstring);
354 expect_bin(buf, "\xb0\xb1\xff", 3);
356 memset(buf, 0xff, sizeof(buf));
357 _mbsncpy(buf, mbstring, 1);
358 expect_bin(buf, "\xb0\xb1\xff", 3);
359 memset(buf, 0xff, sizeof(buf));
360 _mbsncpy(buf, mbstring, 2);
361 expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
362 memset(buf, 0xff, sizeof(buf));
363 _mbsncpy(buf, mbstring, 3);
364 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
365 memset(buf, 0xff, sizeof(buf));
366 _mbsncpy(buf, mbstring, 4);
367 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
368 memset(buf, 0xff, sizeof(buf));
369 _mbsncpy(buf, mbstring, 5);
370 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
371 memset(buf, 0xff, sizeof(buf));
372 _mbsncpy(buf, mbsonlylead, 6);
373 expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
375 memset(buf, 0xff, sizeof(buf));
376 _mbsnbcpy(buf, mbstring2, 2);
377 expect_bin(buf, "\xb0\xb1\xff", 3);
378 _mbsnbcpy(buf, mbstring2, 3);
379 expect_bin(buf, "\xb0\xb1\0\xff", 4);
380 _mbsnbcpy(buf, mbstring2, 4);
381 expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
382 memset(buf, 0xff, sizeof(buf));
383 _mbsnbcpy(buf, mbsonlylead, 5);
384 expect_bin(buf, "\0\0\0\0\0\xff", 6);
386 /* _mbsinc/mbsdec */
387 step = _mbsinc(mbstring) - mbstring;
388 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
389 step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
390 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
392 step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
393 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
394 step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
395 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
396 step = _mbsninc(mbstring2, 0) - mbstring2;
397 ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
398 step = _mbsninc(mbstring2, 1) - mbstring2;
399 ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
400 step = _mbsninc(mbstring2, 2) - mbstring2;
401 ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
402 step = _mbsninc(mbstring2, 3) - mbstring2;
403 ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
404 step = _mbsninc(mbstring2, 4) - mbstring2;
405 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
406 step = _mbsninc(mbstring2, 5) - mbstring2;
407 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
408 step = _mbsninc(mbstring2, 17) - mbstring2;
409 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
411 /* functions that depend on locale codepage, not mbcp.
412 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
413 * (as of Wine 0.9.43)
415 GetCPInfo(GetACP(), &cp_info);
416 if (cp_info.MaxCharSize == 1)
418 expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
419 expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
421 else
422 skip("Current locale has double-byte charset - could lead to false positives\n");
424 _setmbcp(1361);
425 expect_eq(_ismbblead(0x80), 0, int, "%d");
426 todo_wine {
427 expect_eq(_ismbblead(0x81), 1, int, "%d");
428 expect_eq(_ismbblead(0x83), 1, int, "%d");
430 expect_eq(_ismbblead(0x84), 1, int, "%d");
431 expect_eq(_ismbblead(0xd3), 1, int, "%d");
432 expect_eq(_ismbblead(0xd7), 0, int, "%d");
433 expect_eq(_ismbblead(0xd8), 1, int, "%d");
434 expect_eq(_ismbblead(0xd9), 1, int, "%d");
436 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
437 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
438 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
439 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
440 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
441 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
442 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
443 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
445 _setmbcp(curr_mbcp);
448 static void test_mbsspn( void)
450 unsigned char str1[]="cabernet";
451 unsigned char str2[]="shiraz";
452 unsigned char set[]="abc";
453 unsigned char empty[]="";
454 int ret;
455 ret=_mbsspn( str1, set);
456 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
457 ret=_mbsspn( str2, set);
458 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
459 ret=_mbsspn( str1, empty);
460 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
463 static void test_mbsspnp( void)
465 unsigned char str1[]="cabernet";
466 unsigned char str2[]="shiraz";
467 unsigned char set[]="abc";
468 unsigned char empty[]="";
469 unsigned char full[]="abcenrt";
470 unsigned char* ret;
471 ret=_mbsspnp( str1, set);
472 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
473 ret=_mbsspnp( str2, set);
474 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
475 ret=_mbsspnp( str1, empty);
476 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
477 ret=_mbsspnp( str1, full);
478 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
481 static void test_strdup(void)
483 char *str;
484 str = _strdup( 0 );
485 ok( str == 0, "strdup returns %s should be 0\n", str);
486 free( str );
489 static void test_strcpy_s(void)
491 char dest[8];
492 const char *small = "small";
493 const char *big = "atoolongstringforthislittledestination";
494 int ret;
496 if(!pstrcpy_s)
498 win_skip("strcpy_s not found\n");
499 return;
502 memset(dest, 'X', sizeof(dest));
503 ret = pstrcpy_s(dest, sizeof(dest), small);
504 ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
505 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
506 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
507 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
508 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
510 memset(dest, 'X', sizeof(dest));
511 ret = pstrcpy_s(dest, 0, big);
512 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
513 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
514 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
515 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
516 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
517 ret = pstrcpy_s(dest, 0, NULL);
518 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
519 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
520 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
521 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
522 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
524 memset(dest, 'X', sizeof(dest));
525 ret = pstrcpy_s(dest, sizeof(dest), big);
526 ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
527 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
528 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
529 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
530 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
532 memset(dest, 'X', sizeof(dest));
533 ret = pstrcpy_s(dest, sizeof(dest), NULL);
534 ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
535 ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
536 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
537 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
538 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
540 ret = pstrcpy_s(NULL, sizeof(dest), small);
541 ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
544 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
546 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
547 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
548 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
549 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
550 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
552 static void test_memcpy_s(void)
554 static char dest[8];
555 static const char tiny[] = {'T',0,'I','N','Y',0};
556 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
557 int ret;
558 if (!p_memcpy_s) {
559 win_skip("memcpy_s not found\n");
560 return;
563 /* Normal */
564 memset(dest, 'X', sizeof(dest));
565 ret = p_memcpy_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
566 ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret);
567 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
569 /* Vary source size */
570 errno = 0xdeadbeef;
571 memset(dest, 'X', sizeof(dest));
572 ret = p_memcpy_s(dest, NUMELMS(dest), big, NUMELMS(big));
573 ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret);
574 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
575 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
577 /* Replace source with NULL */
578 errno = 0xdeadbeef;
579 memset(dest, 'X', sizeof(dest));
580 ret = p_memcpy_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
581 ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret);
582 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
583 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
585 /* Vary dest size */
586 errno = 0xdeadbeef;
587 memset(dest, 'X', sizeof(dest));
588 ret = p_memcpy_s(dest, 0, tiny, NUMELMS(tiny));
589 ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret);
590 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
591 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
593 /* Replace dest with NULL */
594 errno = 0xdeadbeef;
595 ret = p_memcpy_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
596 ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
597 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
599 /* Combinations */
600 errno = 0xdeadbeef;
601 memset(dest, 'X', sizeof(dest));
602 ret = p_memcpy_s(dest, 0, NULL, NUMELMS(tiny));
603 ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
604 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
605 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
608 static void test_memmove_s(void)
610 static char dest[8];
611 static const char tiny[] = {'T',0,'I','N','Y',0};
612 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
613 int ret;
614 if (!p_memmove_s) {
615 win_skip("memmove_s not found\n");
616 return;
619 /* Normal */
620 memset(dest, 'X', sizeof(dest));
621 ret = p_memmove_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
622 ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret);
623 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
625 /* Overlapping */
626 memcpy(dest, big, sizeof(dest));
627 ret = p_memmove_s(dest+1, NUMELMS(dest)-1, dest, NUMELMS(dest)-1);
628 ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret);
629 okchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]);
631 /* Vary source size */
632 errno = 0xdeadbeef;
633 memset(dest, 'X', sizeof(dest));
634 ret = p_memmove_s(dest, NUMELMS(dest), big, NUMELMS(big));
635 ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret);
636 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
637 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
639 /* Replace source with NULL */
640 errno = 0xdeadbeef;
641 memset(dest, 'X', sizeof(dest));
642 ret = p_memmove_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
643 ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret);
644 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
645 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
647 /* Vary dest size */
648 errno = 0xdeadbeef;
649 memset(dest, 'X', sizeof(dest));
650 ret = p_memmove_s(dest, 0, tiny, NUMELMS(tiny));
651 ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret);
652 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
653 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
655 /* Replace dest with NULL */
656 errno = 0xdeadbeef;
657 ret = p_memmove_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
658 ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
659 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
661 /* Combinations */
662 errno = 0xdeadbeef;
663 memset(dest, 'X', sizeof(dest));
664 ret = p_memmove_s(dest, 0, NULL, NUMELMS(tiny));
665 ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
666 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
667 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
670 static void test_strcat_s(void)
672 char dest[8];
673 const char *small = "sma";
674 int ret;
676 if(!pstrcat_s)
678 win_skip("strcat_s not found\n");
679 return;
682 memset(dest, 'X', sizeof(dest));
683 dest[0] = '\0';
684 ret = pstrcat_s(dest, sizeof(dest), small);
685 ok(ret == 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
686 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == '\0'&&
687 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
688 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
689 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
690 ret = pstrcat_s(dest, sizeof(dest), small);
691 ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
692 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
693 dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
694 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
695 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
697 ret = pstrcat_s(dest, sizeof(dest), small);
698 ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
699 ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
700 dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
701 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
702 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
704 memset(dest, 'X', sizeof(dest));
705 dest[0] = 'a';
706 dest[1] = '\0';
708 ret = pstrcat_s(dest, 0, small);
709 ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
710 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
711 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
712 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
713 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
715 ret = pstrcat_s(dest, 0, NULL);
716 ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
717 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
718 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
719 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
720 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
722 ret = pstrcat_s(dest, sizeof(dest), NULL);
723 ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
724 ok(dest[0] == '\0'&& dest[1] == '\0'&& 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 = pstrcat_s(NULL, sizeof(dest), small);
730 ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
733 static void test__mbsnbcpy_s(void)
735 unsigned char dest[8];
736 const unsigned char big[] = "atoolongstringforthislittledestination";
737 const unsigned char small[] = "small";
738 int ret;
740 if(!p_mbsnbcpy_s)
742 win_skip("_mbsnbcpy_s not found\n");
743 return;
746 memset(dest, 'X', sizeof(dest));
747 ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
748 ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
749 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
750 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
751 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
752 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
754 /* WTF? */
755 memset(dest, 'X', sizeof(dest));
756 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
757 ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
758 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
759 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
760 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
761 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
763 memset(dest, 'X', sizeof(dest));
764 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
765 ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
766 ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
767 dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
768 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
769 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
771 memset(dest, 'X', sizeof(dest));
772 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
773 ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
774 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
775 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
776 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
777 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
780 static void test__mbscpy_s(void)
782 const unsigned char src[] = "source string";
783 unsigned char dest[16];
784 int ret;
786 if(!p__mbscpy_s)
788 win_skip("_mbscpy_s not found\n");
789 return;
792 ret = p__mbscpy_s(NULL, 0, src);
793 ok(ret == EINVAL, "got %d\n", ret);
794 ret = p__mbscpy_s(NULL, sizeof(dest), src);
795 ok(ret == EINVAL, "got %d\n", ret);
796 ret = p__mbscpy_s(dest, 0, src);
797 ok(ret == EINVAL, "got %d\n", ret);
798 dest[0] = 'x';
799 ret = p__mbscpy_s(dest, sizeof(dest), NULL);
800 ok(ret == EINVAL, "got %d\n", ret);
801 ok(!dest[0], "dest buffer was not modified on invalid argument\n");
803 memset(dest, 'X', sizeof(dest));
804 ret = p__mbscpy_s(dest, sizeof(dest), src);
805 ok(!ret, "got %d\n", ret);
806 ok(!memcmp(dest, src, sizeof(src)), "dest = %s\n", dest);
807 ok(dest[sizeof(src)] == 'X', "unused part of buffer was modified\n");
809 memset(dest, 'X', sizeof(dest));
810 ret = p__mbscpy_s(dest, 4, src);
811 ok(ret == ERANGE, "got %d\n", ret);
812 ok(!dest[0], "incorrect dest buffer (%d)\n", dest[0]);
813 ok(dest[1] == src[1], "incorrect dest buffer (%d)\n", dest[1]);
816 static void test_wcscpy_s(void)
818 static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
819 static WCHAR szDest[18];
820 static WCHAR szDestShort[8];
821 int ret;
823 if(!p_wcscpy_s)
825 win_skip("wcscpy_s not found\n");
826 return;
829 /* Test NULL Dest */
830 errno = EBADF;
831 ret = p_wcscpy_s(NULL, 18, szLongText);
832 ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
833 ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
835 /* Test NULL Source */
836 errno = EBADF;
837 szDest[0] = 'A';
838 ret = p_wcscpy_s(szDest, 18, NULL);
839 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
840 ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
841 ok(szDest[0] == 0, "szDest[0] not 0, got %c\n", szDest[0]);
843 /* Test invalid size */
844 errno = EBADF;
845 szDest[0] = 'A';
846 ret = p_wcscpy_s(szDest, 0, szLongText);
847 /* Later versions changed the return value for this case to EINVAL,
848 * and don't modify the result if the dest size is 0.
850 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
851 ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
852 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
854 /* Copy same buffer size */
855 ret = p_wcscpy_s(szDest, 18, szLongText);
856 ok(ret == 0, "expected 0 got %d\n", ret);
857 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
859 /* Copy smaller buffer size */
860 errno = EBADF;
861 szDest[0] = 'A';
862 ret = p_wcscpy_s(szDestShort, 8, szLongText);
863 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
864 ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
865 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
867 if(!p_wcsncpy_s)
869 win_skip("wcsncpy_s not found\n");
870 return;
873 ret = p_wcsncpy_s(NULL, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
874 ok(ret == EINVAL, "p_wcsncpy_s expect EINVAL got %d\n", ret);
876 szDest[0] = 'A';
877 ret = p_wcsncpy_s(szDest, 18, NULL, 1);
878 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
879 ok(szDest[0] == 0, "szDest[0] not 0\n");
881 szDest[0] = 'A';
882 ret = p_wcsncpy_s(szDest, 18, NULL, 0);
883 ok(ret == 0, "expected ERROR_SUCCESS got %d\n", ret);
884 ok(szDest[0] == 0, "szDest[0] not 0\n");
886 szDest[0] = 'A';
887 ret = p_wcsncpy_s(szDest, 0, szLongText, sizeof(szLongText)/sizeof(WCHAR));
888 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
889 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
891 ret = p_wcsncpy_s(szDest, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
892 ok(ret == 0, "expected 0 got %d\n", ret);
893 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
895 szDest[0] = 'A';
896 ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR));
897 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
898 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
900 szDest[0] = 'A';
901 ret = p_wcsncpy_s(szDest, 5, szLongText, -1);
902 ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret);
903 ok(szDest[4] == 0, "szDest[4] not 0\n");
904 ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest));
906 ret = p_wcsncpy_s(NULL, 0, (void*)0xdeadbeef, 0);
907 ok(ret == 0, "ret = %d\n", ret);
909 szDestShort[0] = '1';
910 szDestShort[1] = 0;
911 ret = p_wcsncpy_s(szDestShort+1, 4, szDestShort, -1);
912 ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret);
913 ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1',
914 "szDestShort = %s\n", wine_dbgstr_w(szDestShort));
917 static void test__wcsupr_s(void)
919 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
920 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
921 static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
922 'W', 'E', 'R', 'U', 'P', 'P', 'E',
923 'R', 0};
924 WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
925 int ret;
927 if (!p_wcsupr_s)
929 win_skip("_wcsupr_s not found\n");
930 return;
933 /* Test NULL input string and invalid size. */
934 errno = EBADF;
935 ret = p_wcsupr_s(NULL, 0);
936 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
937 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
939 /* Test NULL input string and valid size. */
940 errno = EBADF;
941 ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
942 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
943 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
945 /* Test empty string with zero size. */
946 errno = EBADF;
947 testBuffer[0] = '\0';
948 ret = p_wcsupr_s(testBuffer, 0);
949 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
950 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
951 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
953 /* Test empty string with size of one. */
954 testBuffer[0] = '\0';
955 ret = p_wcsupr_s(testBuffer, 1);
956 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
957 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
959 /* Test one-byte buffer with zero size. */
960 errno = EBADF;
961 testBuffer[0] = 'x';
962 ret = p_wcsupr_s(testBuffer, 0);
963 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
964 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
965 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
967 /* Test one-byte buffer with size of one. */
968 errno = EBADF;
969 testBuffer[0] = 'x';
970 ret = p_wcsupr_s(testBuffer, 1);
971 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
972 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
973 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
975 /* Test invalid size. */
976 wcscpy(testBuffer, mixedString);
977 errno = EBADF;
978 ret = p_wcsupr_s(testBuffer, 0);
979 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
980 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
981 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
983 /* Test normal string uppercasing. */
984 wcscpy(testBuffer, mixedString);
985 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
986 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
987 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
989 /* Test uppercasing with a shorter buffer size count. */
990 wcscpy(testBuffer, mixedString);
991 errno = EBADF;
992 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
993 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
994 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
995 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
997 /* Test uppercasing with a longer buffer size count. */
998 wcscpy(testBuffer, mixedString);
999 ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
1000 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
1001 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
1004 static void test__wcslwr_s(void)
1006 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1007 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1008 static const WCHAR expectedString[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1009 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1010 'r', 0};
1011 WCHAR buffer[2*sizeof(mixedString)/sizeof(WCHAR)];
1012 int ret;
1014 if (!p_wcslwr_s)
1016 win_skip("_wcslwr_s not found\n");
1017 return;
1020 /* Test NULL input string and invalid size. */
1021 errno = EBADF;
1022 ret = p_wcslwr_s(NULL, 0);
1023 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1024 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
1026 /* Test NULL input string and valid size. */
1027 errno = EBADF;
1028 ret = p_wcslwr_s(NULL, sizeof(buffer)/sizeof(wchar_t));
1029 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1030 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
1032 /* Test empty string with zero size. */
1033 errno = EBADF;
1034 buffer[0] = 'a';
1035 ret = p_wcslwr_s(buffer, 0);
1036 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1037 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
1038 ok(buffer[0] == 0, "expected empty string\n");
1040 /* Test empty string with size of one. */
1041 buffer[0] = 0;
1042 ret = p_wcslwr_s(buffer, 1);
1043 ok(ret == 0, "got %d\n", ret);
1044 ok(buffer[0] == 0, "expected buffer to be unchanged\n");
1046 /* Test one-byte buffer with zero size. */
1047 errno = EBADF;
1048 buffer[0] = 'x';
1049 ret = p_wcslwr_s(buffer, 0);
1050 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1051 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1052 ok(buffer[0] == '\0', "expected empty string\n");
1054 /* Test one-byte buffer with size of one. */
1055 errno = EBADF;
1056 buffer[0] = 'x';
1057 ret = p_wcslwr_s(buffer, 1);
1058 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1059 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1060 ok(buffer[0] == '\0', "expected empty string\n");
1062 /* Test invalid size. */
1063 wcscpy(buffer, mixedString);
1064 errno = EBADF;
1065 ret = p_wcslwr_s(buffer, 0);
1066 ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
1067 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1068 ok(buffer[0] == '\0', "expected empty string\n");
1070 /* Test normal string uppercasing. */
1071 wcscpy(buffer, mixedString);
1072 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR));
1073 ok(ret == 0, "expected 0, got %d\n", ret);
1074 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1076 /* Test uppercasing with a shorter buffer size count. */
1077 wcscpy(buffer, mixedString);
1078 errno = EBADF;
1079 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
1080 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1081 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1082 ok(buffer[0] == '\0', "expected empty string\n");
1084 /* Test uppercasing with a longer buffer size count. */
1085 wcscpy(buffer, mixedString);
1086 ret = p_wcslwr_s(buffer, sizeof(buffer)/sizeof(WCHAR));
1087 ok(ret == 0, "expected 0, got %d\n", ret);
1088 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1091 static void test_mbcjisjms(void)
1093 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1094 unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1095 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1096 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1097 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1098 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1099 unsigned int i, j;
1100 int prev_cp = _getmbcp();
1102 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1104 _setmbcp(cp[i]);
1105 for (j = 0; jisjms[j][0] != 0; j++)
1107 unsigned int ret, exp;
1108 ret = _mbcjistojms(jisjms[j][0]);
1109 exp = (cp[i] == 932) ? jisjms[j][1] : jisjms[j][0];
1110 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1111 exp, ret, jisjms[j][0], cp[i]);
1114 _setmbcp(prev_cp);
1117 static void test_mbcjmsjis(void)
1119 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1120 unsigned int jmsjis[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1121 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1122 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1123 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1124 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1125 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1126 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1127 unsigned int i, j;
1128 int prev_cp = _getmbcp();
1130 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1132 _setmbcp(cp[i]);
1133 for (j = 0; jmsjis[j][0] != 0; j++)
1135 unsigned int ret, exp;
1136 ret = _mbcjmstojis(jmsjis[j][0]);
1137 exp = (cp[i] == 932) ? jmsjis[j][1] : jmsjis[j][0];
1138 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1139 exp, ret, jmsjis[j][0], cp[i]);
1142 _setmbcp(prev_cp);
1145 static void test_mbctohira(void)
1147 static const unsigned int mbchira_932[][2] = {
1148 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1149 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1150 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1151 {0x8396, 0x8396}, {0x8397, 0x8397},
1152 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1153 unsigned int i;
1154 unsigned int prev_cp = _getmbcp();
1156 _setmbcp(_MB_CP_SBCS);
1157 for (i = 0; i < sizeof(mbchira_932)/sizeof(mbchira_932[0]); i++)
1159 int ret, exp = mbchira_932[i][0];
1160 ret = _mbctohira(mbchira_932[i][0]);
1161 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1164 _setmbcp(932);
1165 for (i = 0; i < sizeof(mbchira_932)/sizeof(mbchira_932[0]); i++)
1167 unsigned int ret, exp;
1168 ret = _mbctohira(mbchira_932[i][0]);
1169 exp = mbchira_932[i][1];
1170 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1172 _setmbcp(prev_cp);
1175 static void test_mbbtombc(void)
1177 static const unsigned int mbbmbc[][2] = {
1178 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1179 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1180 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1181 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1182 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1183 int i, j;
1184 int prev_cp = _getmbcp();
1186 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1188 _setmbcp(cp[i]);
1189 for (j = 0; mbbmbc[j][0] != 0; j++)
1191 unsigned int exp, ret;
1192 ret = _mbbtombc(mbbmbc[j][0]);
1193 exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0];
1194 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1195 exp, ret, mbbmbc[j][0], cp[i]);
1198 _setmbcp(prev_cp);
1201 static void test_mbctombb(void)
1203 static const unsigned int mbcmbb_932[][2] = {
1204 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1205 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1206 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1207 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1208 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1209 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1210 unsigned int exp, ret, i;
1211 unsigned int prev_cp = _getmbcp();
1213 _setmbcp(932);
1214 for (i = 0; mbcmbb_932[i][0] != 0; i++)
1216 ret = _mbctombb(mbcmbb_932[i][0]);
1217 exp = mbcmbb_932[i][1];
1218 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1220 _setmbcp(prev_cp);
1223 static void test_ismbckata(void) {
1224 struct katakana_pair {
1225 UINT c;
1226 BOOL exp;
1228 static const struct katakana_pair tests[] = {
1229 {0x8152, FALSE}, {0x8153, FALSE}, {0x8154, FALSE}, {0x8155, FALSE},
1230 {0x82a0, FALSE}, {0x833f, FALSE}, {0x8340, TRUE }, {0x837e, TRUE },
1231 {0x837f, FALSE}, {0x8380, TRUE }, {0x8396, TRUE }, {0x8397, FALSE},
1232 {0xa5, FALSE}, {0xb0, FALSE}, {0xdd, FALSE}
1234 unsigned int prev_cp = _getmbcp();
1235 int ret;
1236 unsigned int i;
1238 _setmbcp(_MB_CP_SBCS);
1239 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
1240 ret = _ismbckata(tests[i].c);
1241 ok(!ret, "expected 0, got %d for %04x\n", ret, tests[i].c);
1244 _setmbcp(932);
1245 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
1246 ret = _ismbckata(tests[i].c);
1247 ok(!!ret == tests[i].exp, "expected %d, got %d for %04x\n",
1248 tests[i].exp, !!ret, tests[i].c);
1251 _setmbcp(prev_cp);
1254 static void test_ismbclegal(void) {
1255 unsigned int prev_cp = _getmbcp();
1256 int ret, exp, err;
1257 unsigned int i;
1259 _setmbcp(932); /* Japanese */
1260 err = 0;
1261 for(i = 0; i < 0x10000; i++) {
1262 ret = _ismbclegal(i);
1263 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
1264 (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
1265 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1266 (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
1267 if(ret != exp) {
1268 err = 1;
1269 break;
1272 ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1273 _setmbcp(936); /* Chinese (GBK) */
1274 err = 0;
1275 for(i = 0; i < 0x10000; i++) {
1276 ret = _ismbclegal(i);
1277 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1278 LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
1279 if(ret != exp) {
1280 err = 1;
1281 break;
1284 ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1285 _setmbcp(949); /* Korean */
1286 err = 0;
1287 for(i = 0; i < 0x10000; i++) {
1288 ret = _ismbclegal(i);
1289 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1290 LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
1291 if(ret != exp) {
1292 err = 1;
1293 break;
1296 ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1297 _setmbcp(950); /* Chinese (Big5) */
1298 err = 0;
1299 for(i = 0; i < 0x10000; i++) {
1300 ret = _ismbclegal(i);
1301 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1302 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1303 (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
1304 if(ret != exp) {
1305 err = 1;
1306 break;
1309 ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1310 _setmbcp(1361); /* Korean (Johab) */
1311 err = 0;
1312 for(i = 0; i < 0x10000; i++) {
1313 ret = _ismbclegal(i);
1314 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
1315 (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
1316 ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
1317 (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
1318 HIBYTE(i) != 0xDF;
1319 if(ret != exp) {
1320 err = 1;
1321 break;
1324 todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1326 _setmbcp(prev_cp);
1329 static const struct {
1330 const char* string;
1331 const char* delimiter;
1332 int exp_offsetret1; /* returned offset from string after first call to strtok()
1333 -1 means NULL */
1334 int exp_offsetret2; /* returned offset from string after second call to strtok()
1335 -1 means NULL */
1336 int exp_offsetret3; /* returned offset from string after third call to strtok()
1337 -1 means NULL */
1338 } testcases_strtok[] = {
1339 { "red cabernet", " ", 0, 4, -1 },
1340 { "sparkling white riesling", " ", 0, 10, 16 },
1341 { " pale cream sherry", "e ", 1, 6, 9 },
1342 /* end mark */
1343 { 0}
1346 static void test_strtok(void)
1348 int i;
1349 char *strret;
1350 char teststr[100];
1351 for( i = 0; testcases_strtok[i].string; i++){
1352 strcpy( teststr, testcases_strtok[i].string);
1353 strret = strtok( teststr, testcases_strtok[i].delimiter);
1354 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
1355 (!strret && testcases_strtok[i].exp_offsetret1 == -1),
1356 "string (%p) \'%s\' return %p\n",
1357 teststr, testcases_strtok[i].string, strret);
1358 if( !strret) continue;
1359 strret = strtok( NULL, testcases_strtok[i].delimiter);
1360 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
1361 (!strret && testcases_strtok[i].exp_offsetret2 == -1),
1362 "second call string (%p) \'%s\' return %p\n",
1363 teststr, testcases_strtok[i].string, strret);
1364 if( !strret) continue;
1365 strret = strtok( NULL, testcases_strtok[i].delimiter);
1366 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
1367 (!strret && testcases_strtok[i].exp_offsetret3 == -1),
1368 "third call string (%p) \'%s\' return %p\n",
1369 teststr, testcases_strtok[i].string, strret);
1373 static void test_strtol(void)
1375 char* e;
1376 LONG l;
1377 ULONG ul;
1379 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1380 /* errno is modified on W2K8+ */
1381 errno = EBADF;
1382 l = strtol("-1234", &e, 0);
1383 ok(l==-1234, "wrong value %d\n", l);
1384 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1385 errno = EBADF;
1386 ul = strtoul("1234", &e, 0);
1387 ok(ul==1234, "wrong value %u\n", ul);
1388 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1390 errno = EBADF;
1391 l = strtol("2147483647L", &e, 0);
1392 ok(l==2147483647, "wrong value %d\n", l);
1393 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1394 errno = EBADF;
1395 l = strtol("-2147483648L", &e, 0);
1396 ok(l==-2147483647L - 1, "wrong value %d\n", l);
1397 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1398 errno = EBADF;
1399 ul = strtoul("4294967295UL", &e, 0);
1400 ok(ul==4294967295ul, "wrong value %u\n", ul);
1401 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1403 errno = 0;
1404 l = strtol("9223372036854775807L", &e, 0);
1405 ok(l==2147483647, "wrong value %d\n", l);
1406 ok(errno == ERANGE, "wrong errno %d\n", errno);
1407 errno = 0;
1408 ul = strtoul("9223372036854775807L", &e, 0);
1409 ok(ul==4294967295ul, "wrong value %u\n", ul);
1410 ok(errno == ERANGE, "wrong errno %d\n", errno);
1412 errno = 0;
1413 ul = strtoul("-2", NULL, 0);
1414 ok(ul == -2, "wrong value %u\n", ul);
1415 ok(errno == 0, "wrong errno %d\n", errno);
1417 errno = 0;
1418 ul = strtoul("-4294967294", NULL, 0);
1419 ok(ul == 2, "wrong value %u\n", ul);
1420 ok(errno == 0, "wrong errno %d\n", errno);
1422 errno = 0;
1423 ul = strtoul("-4294967295", NULL, 0);
1424 ok(ul==1, "wrong value %u\n", ul);
1425 ok(errno == 0, "wrong errno %d\n", errno);
1427 errno = 0;
1428 ul = strtoul("-4294967296", NULL, 0);
1429 ok(ul == 1, "wrong value %u\n", ul);
1430 ok(errno == ERANGE, "wrong errno %d\n", errno);
1433 static void test_strnlen(void)
1435 static const char str[] = "string";
1436 size_t res;
1438 if(!p_strnlen) {
1439 win_skip("strnlen not found\n");
1440 return;
1443 res = p_strnlen(str, 20);
1444 ok(res == 6, "Returned length = %d\n", (int)res);
1446 res = p_strnlen(str, 3);
1447 ok(res == 3, "Returned length = %d\n", (int)res);
1449 res = p_strnlen(NULL, 0);
1450 ok(res == 0, "Returned length = %d\n", (int)res);
1453 static void test__strtoi64(void)
1455 static const char no1[] = "31923";
1456 static const char no2[] = "-213312";
1457 static const char no3[] = "12aa";
1458 static const char no4[] = "abc12";
1459 static const char overflow[] = "99999999999999999999";
1460 static const char neg_overflow[] = "-99999999999999999999";
1461 static const char hex[] = "0x123";
1462 static const char oct[] = "000123";
1463 static const char blanks[] = " 12 212.31";
1465 __int64 res;
1466 unsigned __int64 ures;
1467 char *endpos;
1469 if(!p_strtoi64 || !p_strtoui64) {
1470 win_skip("_strtoi64 or _strtoui64 not found\n");
1471 return;
1474 errno = 0xdeadbeef;
1475 res = p_strtoi64(no1, NULL, 10);
1476 ok(res == 31923, "res != 31923\n");
1477 res = p_strtoi64(no2, NULL, 10);
1478 ok(res == -213312, "res != -213312\n");
1479 res = p_strtoi64(no3, NULL, 10);
1480 ok(res == 12, "res != 12\n");
1481 res = p_strtoi64(no4, &endpos, 10);
1482 ok(res == 0, "res != 0\n");
1483 ok(endpos == no4, "Scanning was not stopped on first character\n");
1484 res = p_strtoi64(hex, &endpos, 10);
1485 ok(res == 0, "res != 0\n");
1486 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1487 res = p_strtoi64(oct, &endpos, 10);
1488 ok(res == 123, "res != 123\n");
1489 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1490 res = p_strtoi64(blanks, &endpos, 10);
1491 ok(res == 12, "res != 12\n");
1492 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1493 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1495 errno = 0xdeadbeef;
1496 res = p_strtoi64(overflow, &endpos, 10);
1497 ok(res == _I64_MAX, "res != _I64_MAX\n");
1498 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1499 ok(errno == ERANGE, "errno = %x\n", errno);
1501 errno = 0xdeadbeef;
1502 res = p_strtoi64(neg_overflow, &endpos, 10);
1503 ok(res == _I64_MIN, "res != _I64_MIN\n");
1504 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1505 ok(errno == ERANGE, "errno = %x\n", errno);
1507 errno = 0xdeadbeef;
1508 res = p_strtoi64(no1, &endpos, 16);
1509 ok(res == 203043, "res != 203043\n");
1510 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1511 res = p_strtoi64(no2, &endpos, 16);
1512 ok(res == -2175762, "res != -2175762\n");
1513 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1514 res = p_strtoi64(no3, &endpos, 16);
1515 ok(res == 4778, "res != 4778\n");
1516 ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
1517 res = p_strtoi64(no4, &endpos, 16);
1518 ok(res == 703506, "res != 703506\n");
1519 ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
1520 res = p_strtoi64(hex, &endpos, 16);
1521 ok(res == 291, "res != 291\n");
1522 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1523 res = p_strtoi64(oct, &endpos, 16);
1524 ok(res == 291, "res != 291\n");
1525 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1526 res = p_strtoi64(blanks, &endpos, 16);
1527 ok(res == 18, "res != 18\n");
1528 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1529 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1531 errno = 0xdeadbeef;
1532 res = p_strtoi64(hex, &endpos, 36);
1533 ok(res == 1541019, "res != 1541019\n");
1534 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1535 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1537 errno = 0xdeadbeef;
1538 res = p_strtoi64(no1, &endpos, 0);
1539 ok(res == 31923, "res != 31923\n");
1540 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1541 res = p_strtoi64(no2, &endpos, 0);
1542 ok(res == -213312, "res != -213312\n");
1543 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1544 res = p_strtoi64(no3, &endpos, 10);
1545 ok(res == 12, "res != 12\n");
1546 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1547 res = p_strtoi64(no4, &endpos, 10);
1548 ok(res == 0, "res != 0\n");
1549 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1550 res = p_strtoi64(hex, &endpos, 10);
1551 ok(res == 0, "res != 0\n");
1552 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1553 res = p_strtoi64(oct, &endpos, 10);
1554 ok(res == 123, "res != 123\n");
1555 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1556 res = p_strtoi64(blanks, &endpos, 10);
1557 ok(res == 12, "res != 12\n");
1558 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1559 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1561 errno = 0xdeadbeef;
1562 ures = p_strtoui64(no1, &endpos, 0);
1563 ok(ures == 31923, "ures != 31923\n");
1564 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1565 ures = p_strtoui64(no2, &endpos, 0);
1566 ok(ures == -213312, "ures != -213312\n");
1567 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1568 ures = p_strtoui64(no3, &endpos, 10);
1569 ok(ures == 12, "ures != 12\n");
1570 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1571 ures = p_strtoui64(no4, &endpos, 10);
1572 ok(ures == 0, "ures != 0\n");
1573 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1574 ures = p_strtoui64(hex, &endpos, 10);
1575 ok(ures == 0, "ures != 0\n");
1576 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1577 ures = p_strtoui64(oct, &endpos, 10);
1578 ok(ures == 123, "ures != 123\n");
1579 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1580 ures = p_strtoui64(blanks, &endpos, 10);
1581 ok(ures == 12, "ures != 12\n");
1582 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1583 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1585 errno = 0xdeadbeef;
1586 ures = p_strtoui64(overflow, &endpos, 10);
1587 ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
1588 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1589 ok(errno == ERANGE, "errno = %x\n", errno);
1591 errno = 0xdeadbeef;
1592 ures = p_strtoui64(neg_overflow, &endpos, 10);
1593 ok(ures == 1, "ures != 1\n");
1594 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1595 ok(errno == ERANGE, "errno = %x\n", errno);
1598 static inline BOOL almost_equal(double d1, double d2) {
1599 if(d1-d2>-1e-30 && d1-d2<1e-30)
1600 return TRUE;
1601 return FALSE;
1604 static void test__strtod(void)
1606 const char double1[] = "12.1";
1607 const char double2[] = "-13.721";
1608 const char double3[] = "INF";
1609 const char double4[] = ".21e12";
1610 const char double5[] = "214353e-3";
1611 const char overflow[] = "1d9999999999999999999";
1612 const char white_chars[] = " d10";
1614 char *end;
1615 double d;
1617 d = strtod(double1, &end);
1618 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1619 ok(end == double1+4, "incorrect end (%d)\n", (int)(end-double1));
1621 d = strtod(double2, &end);
1622 ok(almost_equal(d, -13.721), "d = %lf\n", d);
1623 ok(end == double2+7, "incorrect end (%d)\n", (int)(end-double2));
1625 d = strtod(double3, &end);
1626 ok(almost_equal(d, 0), "d = %lf\n", d);
1627 ok(end == double3, "incorrect end (%d)\n", (int)(end-double3));
1629 d = strtod(double4, &end);
1630 ok(almost_equal(d, 210000000000.0), "d = %lf\n", d);
1631 ok(end == double4+6, "incorrect end (%d)\n", (int)(end-double4));
1633 d = strtod(double5, &end);
1634 ok(almost_equal(d, 214.353), "d = %lf\n", d);
1635 ok(end == double5+9, "incorrect end (%d)\n", (int)(end-double5));
1637 d = strtod("12.1d2", NULL);
1638 ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
1640 d = strtod(white_chars, &end);
1641 ok(almost_equal(d, 0), "d = %lf\n", d);
1642 ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
1644 /* Set locale with non '.' decimal point (',') */
1645 if(!setlocale(LC_ALL, "Polish")) {
1646 win_skip("system with limited locales\n");
1647 return;
1650 d = strtod("12.1", NULL);
1651 ok(almost_equal(d, 12.0), "d = %lf\n", d);
1653 d = strtod("12,1", NULL);
1654 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1656 setlocale(LC_ALL, "C");
1658 /* Precision tests */
1659 d = strtod("0.1", NULL);
1660 ok(almost_equal(d, 0.1), "d = %lf\n", d);
1661 d = strtod("-0.1", NULL);
1662 ok(almost_equal(d, -0.1), "d = %lf\n", d);
1663 d = strtod("0.1281832188491894198128921", NULL);
1664 ok(almost_equal(d, 0.1281832188491894198128921), "d = %lf\n", d);
1665 d = strtod("0.82181281288121", NULL);
1666 ok(almost_equal(d, 0.82181281288121), "d = %lf\n", d);
1667 d = strtod("21921922352523587651128218821", NULL);
1668 ok(almost_equal(d, 21921922352523587651128218821.0), "d = %lf\n", d);
1669 d = strtod("0.1d238", NULL);
1670 ok(almost_equal(d, 0.1e238L), "d = %lf\n", d);
1671 d = strtod("0.1D-4736", NULL);
1672 ok(almost_equal(d, 0.1e-4736L), "d = %lf\n", d);
1674 errno = 0xdeadbeef;
1675 strtod(overflow, &end);
1676 ok(errno == ERANGE, "errno = %x\n", errno);
1677 ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
1679 errno = 0xdeadbeef;
1680 strtod("-1d309", NULL);
1681 ok(errno == ERANGE, "errno = %x\n", errno);
1684 static void test_mbstowcs(void)
1686 static const wchar_t wSimple[] = { 't','e','x','t',0 };
1687 static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
1688 static const char mSimple[] = "text";
1689 static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
1691 const wchar_t *pwstr;
1692 wchar_t wOut[6];
1693 char mOut[6];
1694 size_t ret;
1695 int err;
1696 const char *pmbstr;
1697 mbstate_t state;
1699 wOut[4] = '!'; wOut[5] = '\0';
1700 mOut[4] = '!'; mOut[5] = '\0';
1702 if(pmbstowcs_s) {
1703 /* crashes on some systems */
1704 errno = 0xdeadbeef;
1705 ret = mbstowcs(wOut, NULL, 4);
1706 ok(ret == -1, "mbstowcs did not return -1\n");
1707 ok(errno == EINVAL, "errno = %d\n", errno);
1710 ret = mbstowcs(NULL, mSimple, 0);
1711 ok(ret == 4, "mbstowcs did not return 4\n");
1713 ret = mbstowcs(wOut, mSimple, 4);
1714 ok(ret == 4, "mbstowcs did not return 4\n");
1715 ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
1716 ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
1718 ret = wcstombs(NULL, wSimple, 0);
1719 ok(ret == 4, "wcstombs did not return 4\n");
1721 ret = wcstombs(mOut, wSimple, 6);
1722 ok(ret == 4, "wcstombs did not return 4\n");
1723 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1725 ret = wcstombs(mOut, wSimple, 2);
1726 ok(ret == 2, "wcstombs did not return 2\n");
1727 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1729 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
1730 win_skip("Japanese_Japan.932 locale not available\n");
1731 return;
1734 ret = mbstowcs(wOut, mHiragana, 6);
1735 ok(ret == 2, "mbstowcs did not return 2\n");
1736 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1738 ret = wcstombs(mOut, wHiragana, 6);
1739 ok(ret == 4, "wcstombs did not return 4\n");
1740 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1742 if(!pmbstowcs_s || !pwcstombs_s) {
1743 setlocale(LC_ALL, "C");
1744 win_skip("mbstowcs_s or wcstombs_s not available\n");
1745 return;
1748 err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
1749 ok(err == 0, "err = %d\n", err);
1750 ok(ret == 5, "mbstowcs_s did not return 5\n");
1751 ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
1753 err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
1754 ok(err == 0, "err = %d\n", err);
1755 ok(ret == 3, "mbstowcs_s did not return 3\n");
1756 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1758 err = pmbstowcs_s(&ret, NULL, 0, mHiragana, 1);
1759 ok(err == 0, "err = %d\n", err);
1760 ok(ret == 3, "mbstowcs_s did not return 3\n");
1762 err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
1763 ok(err == 0, "err = %d\n", err);
1764 ok(ret == 5, "wcstombs_s did not return 5\n");
1765 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1767 err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
1768 ok(err == 0, "err = %d\n", err);
1769 ok(ret == 5, "wcstombs_s did not return 5\n");
1770 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1772 err = pwcstombs_s(&ret, NULL, 0, wHiragana, 1);
1773 ok(err == 0, "err = %d\n", err);
1774 ok(ret == 5, "wcstombs_s did not return 5\n");
1776 if(!pwcsrtombs) {
1777 setlocale(LC_ALL, "C");
1778 win_skip("wcsrtombs not available\n");
1779 return;
1782 pwstr = wSimple;
1783 err = -3;
1784 ret = pwcsrtombs(mOut, &pwstr, 4, &err);
1785 ok(ret == 4, "wcsrtombs did not return 4\n");
1786 ok(err == 0, "err = %d\n", err);
1787 ok(pwstr == wSimple+4, "pwstr = %p (wszSimple = %p)\n", pwstr, wSimple);
1788 ok(!memcmp(mOut, mSimple, ret), "mOut = %s\n", mOut);
1790 pwstr = wSimple;
1791 ret = pwcsrtombs(mOut, &pwstr, 5, NULL);
1792 ok(ret == 4, "wcsrtombs did not return 4\n");
1793 ok(pwstr == NULL, "pwstr != NULL\n");
1794 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1796 if(!p_mbsrtowcs) {
1797 setlocale(LC_ALL, "C");
1798 win_skip("mbsrtowcs not available\n");
1799 return;
1802 pmbstr = mHiragana;
1803 ret = p_mbsrtowcs(wOut, &pmbstr, 6, NULL);
1804 ok(ret == 2, "mbsrtowcs did not return 2\n");
1805 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1806 ok(!pmbstr, "pmbstr != NULL\n");
1808 state = mHiragana[0];
1809 pmbstr = mHiragana+1;
1810 ret = p_mbsrtowcs(wOut, &pmbstr, 6, &state);
1811 ok(ret == 2, "mbsrtowcs did not return 2\n");
1812 ok(wOut[0] == 0x3042, "wOut[0] = %x\n", wOut[0]);
1813 ok(wOut[1] == 0xff61, "wOut[1] = %x\n", wOut[1]);
1814 ok(wOut[2] == 0, "wOut[2] = %x\n", wOut[2]);
1815 ok(!pmbstr, "pmbstr != NULL\n");
1817 errno = EBADF;
1818 ret = p_mbsrtowcs(wOut, NULL, 6, &state);
1819 ok(ret == -1, "mbsrtowcs did not return -1\n");
1820 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1822 setlocale(LC_ALL, "C");
1825 static void test_gcvt(void)
1827 char buf[1024], *res;
1828 errno_t err;
1830 if(!p_gcvt_s) {
1831 win_skip("Skipping _gcvt tests\n");
1832 return;
1835 errno = 0;
1836 res = _gcvt(1.2, -1, buf);
1837 ok(res == NULL, "res != NULL\n");
1838 ok(errno == ERANGE, "errno = %d\n", errno);
1840 errno = 0;
1841 res = _gcvt(1.2, 5, NULL);
1842 ok(res == NULL, "res != NULL\n");
1843 ok(errno == EINVAL, "errno = %d\n", errno);
1845 res = gcvt(1.2, 5, buf);
1846 ok(res == buf, "res != buf\n");
1847 ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
1849 buf[0] = 'x';
1850 err = p_gcvt_s(buf, 5, 1.2, 10);
1851 ok(err == ERANGE, "err = %d\n", err);
1852 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1854 buf[0] = 'x';
1855 err = p_gcvt_s(buf, 4, 123456, 2);
1856 ok(err == ERANGE, "err = %d\n", err);
1857 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1860 static void test__itoa_s(void)
1862 errno_t ret;
1863 char buffer[33];
1865 if (!p_itoa_s)
1867 win_skip("Skipping _itoa_s tests\n");
1868 return;
1871 errno = EBADF;
1872 ret = p_itoa_s(0, NULL, 0, 0);
1873 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1874 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1876 memset(buffer, 'X', sizeof(buffer));
1877 errno = EBADF;
1878 ret = p_itoa_s(0, buffer, 0, 0);
1879 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1880 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1881 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1883 memset(buffer, 'X', sizeof(buffer));
1884 errno = EBADF;
1885 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
1886 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1887 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1888 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1890 memset(buffer, 'X', sizeof(buffer));
1891 errno = EBADF;
1892 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
1893 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1894 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1895 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1897 memset(buffer, 'X', sizeof(buffer));
1898 errno = EBADF;
1899 ret = p_itoa_s(12345678, buffer, 4, 10);
1900 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1901 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1902 ok(!memcmp(buffer, "\000765", 4),
1903 "Expected the output buffer to be null terminated with truncated output\n");
1905 memset(buffer, 'X', sizeof(buffer));
1906 errno = EBADF;
1907 ret = p_itoa_s(12345678, buffer, 8, 10);
1908 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1909 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1910 ok(!memcmp(buffer, "\0007654321", 8),
1911 "Expected the output buffer to be null terminated with truncated output\n");
1913 memset(buffer, 'X', sizeof(buffer));
1914 errno = EBADF;
1915 ret = p_itoa_s(-12345678, buffer, 9, 10);
1916 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1917 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1918 ok(!memcmp(buffer, "\00087654321", 9),
1919 "Expected the output buffer to be null terminated with truncated output\n");
1921 ret = p_itoa_s(12345678, buffer, 9, 10);
1922 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1923 ok(!strcmp(buffer, "12345678"),
1924 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1925 buffer);
1927 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
1928 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1929 ok(!strcmp(buffer, "1010101010101010"),
1930 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1931 buffer);
1933 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
1934 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1935 ok(!strcmp(buffer, "nell"),
1936 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1937 buffer);
1939 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
1940 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1941 ok(!strcmp(buffer, "hag"),
1942 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1943 buffer);
1945 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
1946 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1947 ok(!strcmp(buffer, "-12345678"),
1948 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1949 buffer);
1951 itoa(100, buffer, 100);
1952 ok(!strcmp(buffer, "10"),
1953 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer);
1956 static void test__strlwr_s(void)
1958 errno_t ret;
1959 char buffer[20];
1961 if (!p_strlwr_s)
1963 win_skip("Skipping _strlwr_s tests\n");
1964 return;
1967 errno = EBADF;
1968 ret = p_strlwr_s(NULL, 0);
1969 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1970 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1972 errno = EBADF;
1973 ret = p_strlwr_s(NULL, sizeof(buffer));
1974 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1975 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1977 errno = EBADF;
1978 ret = p_strlwr_s(buffer, 0);
1979 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1980 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1982 strcpy(buffer, "GoRrIsTeR");
1983 errno = EBADF;
1984 ret = p_strlwr_s(buffer, 5);
1985 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1986 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1987 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1988 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1990 strcpy(buffer, "GoRrIsTeR");
1991 errno = EBADF;
1992 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
1993 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1994 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1995 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1996 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1998 strcpy(buffer, "GoRrIsTeR");
1999 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
2000 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
2001 ok(!strcmp(buffer, "gorrister"),
2002 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2003 buffer);
2005 memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2006 ret = p_strlwr_s(buffer, sizeof(buffer));
2007 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
2008 ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2009 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2010 buffer);
2013 static void test_wcsncat_s(void)
2015 static wchar_t abcW[] = {'a','b','c',0};
2016 int ret;
2017 wchar_t dst[4];
2018 wchar_t src[4];
2020 if (!p_wcsncat_s)
2022 win_skip("skipping wcsncat_s tests\n");
2023 return;
2026 memcpy(src, abcW, sizeof(abcW));
2027 dst[0] = 0;
2028 ret = p_wcsncat_s(NULL, 4, src, 4);
2029 ok(ret == EINVAL, "err = %d\n", ret);
2030 ret = p_wcsncat_s(dst, 0, src, 4);
2031 ok(ret == EINVAL, "err = %d\n", ret);
2032 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
2033 ok(ret == EINVAL, "err = %d\n", ret);
2034 ret = p_wcsncat_s(dst, 4, NULL, 0);
2035 ok(ret == 0, "err = %d\n", ret);
2037 dst[0] = 0;
2038 ret = p_wcsncat_s(dst, 2, src, 4);
2039 ok(ret == ERANGE, "err = %d\n", ret);
2041 dst[0] = 0;
2042 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
2043 ok(ret == STRUNCATE, "err = %d\n", ret);
2044 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
2046 memcpy(dst, abcW, sizeof(abcW));
2047 dst[3] = 'd';
2048 ret = p_wcsncat_s(dst, 4, src, 4);
2049 ok(ret == EINVAL, "err = %d\n", ret);
2052 static void test__mbsnbcat_s(void)
2054 unsigned char dest[16];
2055 const unsigned char first[] = "dinosaur";
2056 const unsigned char second[] = "duck";
2057 int ret;
2059 if (!p_mbsnbcat_s)
2061 win_skip("Skipping _mbsnbcat_s tests\n");
2062 return;
2065 /* Test invalid arguments. */
2066 ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
2067 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2069 errno = EBADF;
2070 ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
2071 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2072 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2074 errno = EBADF;
2075 ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
2076 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2077 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2079 memset(dest, 'X', sizeof(dest));
2080 errno = EBADF;
2081 ret = p_mbsnbcat_s(dest, 0, NULL, 0);
2082 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2083 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2084 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
2086 memset(dest, 'X', sizeof(dest));
2087 errno = EBADF;
2088 ret = p_mbsnbcat_s(dest, 0, second, 0);
2089 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2090 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2091 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
2093 memset(dest, 'X', sizeof(dest));
2094 errno = EBADF;
2095 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
2096 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2097 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2098 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
2100 memset(dest, 'X', sizeof(dest));
2101 errno = EBADF;
2102 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
2103 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2104 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2105 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
2107 memset(dest, 'X', sizeof(dest));
2108 dest[0] = '\0';
2109 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
2110 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2111 ok(!memcmp(dest, second, sizeof(second)),
2112 "Expected the output buffer string to be \"duck\"\n");
2114 /* Test source truncation behavior. */
2115 memset(dest, 'X', sizeof(dest));
2116 memcpy(dest, first, sizeof(first));
2117 ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
2118 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2119 ok(!memcmp(dest, first, sizeof(first)),
2120 "Expected the output buffer string to be \"dinosaur\"\n");
2122 memset(dest, 'X', sizeof(dest));
2123 memcpy(dest, first, sizeof(first));
2124 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
2125 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2126 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
2127 "Expected the output buffer string to be \"dinosaurduck\"\n");
2129 memset(dest, 'X', sizeof(dest));
2130 memcpy(dest, first, sizeof(first));
2131 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
2132 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2133 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
2134 "Expected the output buffer string to be \"dinosaurduck\"\n");
2136 memset(dest, 'X', sizeof(dest));
2137 memcpy(dest, first, sizeof(first));
2138 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
2139 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2140 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
2141 "Expected the output buffer string to be \"dinosaurduck\"\n");
2143 memset(dest, 'X', sizeof(dest));
2144 memcpy(dest, first, sizeof(first));
2145 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
2146 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2147 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
2148 "Expected the output buffer string to be \"dinosaurduc\"\n");
2150 /* Test destination truncation behavior. */
2151 memset(dest, 'X', sizeof(dest));
2152 memcpy(dest, first, sizeof(first));
2153 errno = EBADF;
2154 ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
2155 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2156 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2157 ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
2158 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2160 memset(dest, 'X', sizeof(dest));
2161 memcpy(dest, first, sizeof(first));
2162 errno = EBADF;
2163 ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
2164 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
2165 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2166 ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
2167 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2169 memset(dest, 'X', sizeof(dest));
2170 memcpy(dest, first, sizeof(first));
2171 errno = EBADF;
2172 ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
2173 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
2174 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2175 ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2176 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2179 static void test__mbsupr_s(void)
2181 errno_t ret;
2182 unsigned char buffer[20];
2184 if (!p_mbsupr_s)
2186 win_skip("Skipping _mbsupr_s tests\n");
2187 return;
2190 errno = EBADF;
2191 ret = p_mbsupr_s(NULL, 0);
2192 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2194 errno = EBADF;
2195 ret = p_mbsupr_s(NULL, sizeof(buffer));
2196 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2197 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2199 errno = EBADF;
2200 ret = p_mbsupr_s(buffer, 0);
2201 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2202 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2204 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2205 errno = EBADF;
2206 ret = p_mbsupr_s(buffer, sizeof("abcdefgh"));
2207 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2208 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2209 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2210 buffer);
2212 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2213 errno = EBADF;
2214 ret = p_mbsupr_s(buffer, sizeof(buffer));
2215 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2216 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2217 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2218 buffer);
2220 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2221 errno = EBADF;
2222 ret = p_mbsupr_s(buffer, 4);
2223 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2224 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2226 memcpy(buffer, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2227 errno = EBADF;
2228 ret = p_mbsupr_s(buffer, sizeof(buffer));
2229 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2230 ok(!memcmp(buffer, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2231 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2232 buffer);
2236 static void test__mbslwr_s(void)
2238 errno_t ret;
2239 unsigned char buffer[20];
2241 if (!p_mbslwr_s)
2243 win_skip("Skipping _mbslwr_s tests\n");
2244 return;
2247 errno = EBADF;
2248 ret = p_mbslwr_s(NULL, 0);
2249 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2251 errno = EBADF;
2252 ret = p_mbslwr_s(NULL, sizeof(buffer));
2253 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2254 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2256 errno = EBADF;
2257 ret = p_mbslwr_s(buffer, 0);
2258 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2259 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2261 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2262 errno = EBADF;
2263 ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH"));
2264 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2265 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2266 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2267 buffer);
2269 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2270 errno = EBADF;
2271 ret = p_mbslwr_s(buffer, sizeof(buffer));
2272 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2273 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2274 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2275 buffer);
2277 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2278 errno = EBADF;
2279 ret = p_mbslwr_s(buffer, 4);
2280 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2281 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2283 memcpy(buffer, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2284 errno = EBADF;
2285 ret = p_mbslwr_s(buffer, sizeof(buffer));
2286 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2287 ok(!memcmp(buffer, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2288 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2289 buffer);
2292 static void test__mbstok(void)
2294 const unsigned char delim[] = "t";
2296 char str[] = "!.!test";
2297 unsigned char *ret;
2299 strtok(str, "!");
2301 ret = _mbstok(NULL, delim);
2302 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2303 ok(!ret || broken((char*)ret==str+4),
2304 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret, str);
2306 ret = _mbstok(NULL, delim);
2307 ok(!ret, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret);
2310 static void test__ultoa_s(void)
2312 errno_t ret;
2313 char buffer[33];
2315 if (!p_ultoa_s)
2317 win_skip("Skipping _ultoa_s tests\n");
2318 return;
2321 errno = EBADF;
2322 ret = p_ultoa_s(0, NULL, 0, 0);
2323 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2324 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2326 memset(buffer, 'X', sizeof(buffer));
2327 errno = EBADF;
2328 ret = p_ultoa_s(0, buffer, 0, 0);
2329 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2330 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2331 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
2333 memset(buffer, 'X', sizeof(buffer));
2334 errno = EBADF;
2335 ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
2336 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2337 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2338 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2340 memset(buffer, 'X', sizeof(buffer));
2341 errno = EBADF;
2342 ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
2343 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2344 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2345 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2347 memset(buffer, 'X', sizeof(buffer));
2348 errno = EBADF;
2349 ret = p_ultoa_s(12345678, buffer, 4, 10);
2350 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2351 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2352 ok(!memcmp(buffer, "\000765", 4),
2353 "Expected the output buffer to be null terminated with truncated output\n");
2355 memset(buffer, 'X', sizeof(buffer));
2356 errno = EBADF;
2357 ret = p_ultoa_s(12345678, buffer, 8, 10);
2358 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2359 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2360 ok(!memcmp(buffer, "\0007654321", 8),
2361 "Expected the output buffer to be null terminated with truncated output\n");
2363 ret = p_ultoa_s(12345678, buffer, 9, 10);
2364 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2365 ok(!strcmp(buffer, "12345678"),
2366 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2367 buffer);
2369 ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
2370 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2371 ok(!strcmp(buffer, "1010101010101010"),
2372 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2373 buffer);
2375 ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
2376 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2377 ok(!strcmp(buffer, "nell"),
2378 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2379 buffer);
2381 ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
2382 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2383 ok(!strcmp(buffer, "hag"),
2384 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2385 buffer);
2388 static void test_wctob(void)
2390 int ret;
2392 if(!p_wctob || !setlocale(LC_ALL, "chinese-traditional")) {
2393 win_skip("Skipping wctob tests\n");
2394 return;
2397 ret = p_wctob(0x8141);
2398 ok(ret == EOF, "ret = %x\n", ret);
2400 ret = p_wctob(0x81);
2401 ok(ret == EOF, "ret = %x\n", ret);
2403 ret = p_wctob(0xe0);
2404 ok(ret == 0x61, "ret = %x\n", ret);
2406 _setmbcp(1250);
2407 ret = p_wctob(0x81);
2408 ok(ret == EOF, "ret = %x\n", ret);
2410 setlocale(LC_ALL, "C");
2411 ret = p_wctob(0x8141);
2412 ok(ret == EOF, "ret = %x\n", ret);
2414 ret = p_wctob(0x81);
2415 ok(ret == (int)(char)0x81, "ret = %x\n", ret);
2417 ret = p_wctob(0x9f);
2418 ok(ret == (int)(char)0x9f, "ret = %x\n", ret);
2420 ret = p_wctob(0xe0);
2421 ok(ret == (int)(char)0xe0, "ret = %x\n", ret);
2423 static void test_wctomb(void)
2425 mbstate_t state;
2426 unsigned char dst[10];
2427 size_t ret;
2429 if(!p_wcrtomb || !setlocale(LC_ALL, "Japanese_Japan.932")) {
2430 win_skip("wcrtomb tests\n");
2431 return;
2434 ret = p_wcrtomb(NULL, 0x3042, NULL);
2435 ok(ret == 2, "wcrtomb did not return 2\n");
2437 state = 1;
2438 dst[2] = 'a';
2439 ret = p_wcrtomb((char*)dst, 0x3042, &state);
2440 ok(ret == 2, "wcrtomb did not return 2\n");
2441 ok(state == 0, "state != 0\n");
2442 ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
2443 ok(dst[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst[1]);
2444 ok(dst[2] == 'a', "dst[2] != 'a'\n");
2446 ret = p_wcrtomb((char*)dst, 0x3043, NULL);
2447 ok(ret == 2, "wcrtomb did not return 2\n");
2448 ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
2449 ok(dst[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst[1]);
2451 ret = p_wcrtomb((char*)dst, 0x20, NULL);
2452 ok(ret == 1, "wcrtomb did not return 1\n");
2453 ok(dst[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst[0]);
2455 ret = p_wcrtomb((char*)dst, 0xffff, NULL);
2456 ok(ret == -1, "wcrtomb did not return -1\n");
2457 ok(dst[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst[0]);
2459 setlocale(LC_ALL, "C");
2462 static void test_tolower(void)
2464 char ch, lch;
2465 int ret, len;
2467 /* test C locale when locale was never changed */
2468 ret = p_tolower(0x41);
2469 ok(ret == 0x61, "ret = %x\n", ret);
2471 ret = p_tolower(0xF4);
2472 ok(ret == 0xF4, "ret = %x\n", ret);
2474 errno = 0xdeadbeef;
2475 ret = p_tolower((char)0xF4);
2476 todo_wine ok(ret == (char)0xF4, "ret = %x\n", ret);
2477 todo_wine ok(errno == 0xdeadbeef, "errno = %d\n", errno);
2479 errno = 0xdeadbeef;
2480 ret = p_tolower((char)0xD0);
2481 todo_wine ok(ret == (char)0xD0, "ret = %x\n", ret);
2482 todo_wine ok(errno == 0xdeadbeef, "errno = %d\n", errno);
2484 /* test C locale after setting locale */
2485 if(!setlocale(LC_ALL, "us")) {
2486 win_skip("skipping tolower tests that depends on locale\n");
2487 return;
2489 setlocale(LC_ALL, "C");
2491 ch = 0xF4;
2492 errno = 0xdeadbeef;
2493 ret = p_tolower(ch);
2494 len = LCMapStringA(0, LCMAP_LOWERCASE, &ch, 1, &lch, 1);
2495 if(len)
2496 ok(ret==(unsigned char)lch || broken(ret==ch)/*WinXP-*/, "ret = %x\n", ret);
2497 else
2498 ok(ret == ch, "ret = %x\n", ret);
2499 if(!len || ret==(unsigned char)lch)
2500 ok(errno == EILSEQ, "errno = %d\n", errno);
2502 ch = 0xD0;
2503 errno = 0xdeadbeef;
2504 ret = p_tolower(ch);
2505 len = LCMapStringA(0, LCMAP_LOWERCASE, &ch, 1, &lch, 1);
2506 if(len)
2507 ok(ret==(unsigned char)lch || broken(ret==ch)/*WinXP-*/, "ret = %x\n", ret);
2508 else
2509 ok(ret == ch, "ret = %x\n", ret);
2510 if(!len || ret==(unsigned char)lch)
2511 ok(errno == EILSEQ, "errno = %d\n", errno);
2513 ret = p_tolower(0xD0);
2514 ok(ret == 0xD0, "ret = %x\n", ret);
2516 ok(setlocale(LC_ALL, "us") != NULL, "setlocale failed\n");
2518 ret = p_tolower((char)0xD0);
2519 ok(ret == 0xF0, "ret = %x\n", ret);
2521 ret = p_tolower(0xD0);
2522 ok(ret == 0xF0, "ret = %x\n", ret);
2524 setlocale(LC_ALL, "C");
2527 static void test__atodbl(void)
2529 _CRT_DOUBLE d;
2530 char num[32];
2531 int ret;
2533 if(!p__atodbl_l) {
2534 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2535 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2536 win_skip("_atodbl_l is not available\n");
2537 return;
2540 num[0] = 0;
2541 ret = p__atodbl_l(&d, num, NULL);
2542 ok(ret == 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret);
2543 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2544 ret = _atodbl(&d, num);
2545 ok(ret == 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret);
2546 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2548 strcpy(num, "t");
2549 ret = p__atodbl_l(&d, num, NULL);
2550 ok(ret == 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret);
2551 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2552 ret = _atodbl(&d, num);
2553 ok(ret == 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret);
2554 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2556 strcpy(num, "0");
2557 ret = p__atodbl_l(&d, num, NULL);
2558 ok(ret == 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret);
2559 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2560 ret = _atodbl(&d, num);
2561 ok(ret == 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret);
2562 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2564 strcpy(num, "123");
2565 ret = p__atodbl_l(&d, num, NULL);
2566 ok(ret == 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret);
2567 ok(d.x == 123, "d.x = %lf, expected 123\n", d.x);
2568 ret = _atodbl(&d, num);
2569 ok(ret == 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret);
2570 ok(d.x == 123, "d.x = %lf, expected 123\n", d.x);
2572 strcpy(num, "1e-309");
2573 ret = p__atodbl_l(&d, num, NULL);
2574 ok(ret == _UNDERFLOW, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret);
2575 ok(d.x!=0 && almost_equal(d.x, 0), "d.x = %le, expected 0\n", d.x);
2576 ret = _atodbl(&d, num);
2577 ok(ret == _UNDERFLOW, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret);
2578 ok(d.x!=0 && almost_equal(d.x, 0), "d.x = %le, expected 0\n", d.x);
2580 strcpy(num, "1e309");
2581 ret = p__atodbl_l(&d, num, NULL);
2582 ok(ret == _OVERFLOW, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret);
2583 ret = _atodbl(&d, num);
2584 ok(ret == _OVERFLOW, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret);
2587 static void test__stricmp(void)
2589 int ret;
2591 ret = _stricmp("test", "test");
2592 ok(ret == 0, "_stricmp returned %d\n", ret);
2593 ret = _stricmp("a", "z");
2594 ok(ret < 0, "_stricmp returned %d\n", ret);
2595 ret = _stricmp("z", "a");
2596 ok(ret > 0, "_stricmp returned %d\n", ret);
2597 ret = _stricmp("\xa5", "\xb9");
2598 ok(ret < 0, "_stricmp returned %d\n", ret);
2600 if(!setlocale(LC_ALL, "polish")) {
2601 win_skip("stricmp tests\n");
2602 return;
2605 ret = _stricmp("test", "test");
2606 ok(ret == 0, "_stricmp returned %d\n", ret);
2607 ret = _stricmp("a", "z");
2608 ok(ret < 0, "_stricmp returned %d\n", ret);
2609 ret = _stricmp("z", "a");
2610 ok(ret > 0, "_stricmp returned %d\n", ret);
2611 ret = _stricmp("\xa5", "\xb9");
2612 ok(ret == 0, "_stricmp returned %d\n", ret);
2613 ret = _stricmp("a", "\xb9");
2614 ok(ret < 0, "_stricmp returned %d\n", ret);
2616 setlocale(LC_ALL, "C");
2619 static void test__wcstoi64(void)
2621 static const WCHAR digit[] = { '9', 0 };
2622 static const WCHAR stock[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2623 static const WCHAR tamil[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2624 static const WCHAR thai[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2625 static const WCHAR fullwidth[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2626 static const WCHAR hex[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
2628 __int64 res;
2629 unsigned __int64 ures;
2630 WCHAR *endpos;
2632 if (!p_wcstoi64 || !p_wcstoui64) {
2633 win_skip("_wcstoi64 or _wcstoui64 not found\n");
2634 return;
2637 res = p_wcstoi64(digit, NULL, 10);
2638 ok(res == 9, "res != 9\n");
2639 res = p_wcstoi64(stock, &endpos, 10);
2640 ok(res == 0, "res != 0\n");
2641 ok(endpos == stock, "Incorrect endpos (%p-%p)\n", stock, endpos);
2642 res = p_wcstoi64(tamil, &endpos, 10);
2643 ok(res == 0, "res != 0\n");
2644 ok(endpos == tamil, "Incorrect endpos (%p-%p)\n", tamil, endpos);
2645 res = p_wcstoi64(thai, NULL, 10);
2646 todo_wine ok(res == 9, "res != 9\n");
2647 res = p_wcstoi64(fullwidth, NULL, 10);
2648 todo_wine ok(res == 9, "res != 9\n");
2649 res = p_wcstoi64(hex, NULL, 16);
2650 todo_wine ok(res == 0x9f9, "res != 0x9f9\n");
2652 ures = p_wcstoui64(digit, NULL, 10);
2653 ok(ures == 9, "ures != 9\n");
2654 ures = p_wcstoui64(stock, &endpos, 10);
2655 ok(ures == 0, "ures != 0\n");
2656 ok(endpos == stock, "Incorrect endpos (%p-%p)\n", stock, endpos);
2657 ures = p_wcstoui64(tamil, &endpos, 10);
2658 ok(ures == 0, "ures != 0\n");
2659 ok(endpos == tamil, "Incorrect endpos (%p-%p)\n", tamil, endpos);
2660 ures = p_wcstoui64(thai, NULL, 10);
2661 todo_wine ok(ures == 9, "ures != 9\n");
2662 ures = p_wcstoui64(fullwidth, NULL, 10);
2663 todo_wine ok(ures == 9, "ures != 9\n");
2664 ures = p_wcstoui64(hex, NULL, 16);
2665 todo_wine ok(ures == 0x9f9, "ures != 0x9f9\n");
2667 return;
2670 static void test_atoi(void)
2672 int r;
2674 r = atoi("0");
2675 ok(r == 0, "atoi(0) = %d\n", r);
2677 r = atoi("-1");
2678 ok(r == -1, "atoi(-1) = %d\n", r);
2680 r = atoi("1");
2681 ok(r == 1, "atoi(1) = %d\n", r);
2683 r = atoi("4294967296");
2684 ok(r == 0, "atoi(4294967296) = %d\n", r);
2687 static void test_strncpy(void)
2689 #define TEST_STRNCPY_LEN 10
2690 char *ret;
2691 char dst[TEST_STRNCPY_LEN + 1];
2692 char not_null_terminated[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
2694 /* strlen(src) > TEST_STRNCPY_LEN */
2695 ret = strncpy(dst, "01234567890123456789", TEST_STRNCPY_LEN);
2696 ok(ret == dst, "ret != dst\n");
2697 ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
2699 /* without null-terminated */
2700 ret = strncpy(dst, not_null_terminated, TEST_STRNCPY_LEN);
2701 ok(ret == dst, "ret != dst\n");
2702 ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
2704 /* strlen(src) < TEST_STRNCPY_LEN */
2705 strcpy(dst, "0123456789");
2706 ret = strncpy(dst, "012345", TEST_STRNCPY_LEN);
2707 ok(ret == dst, "ret != dst\n");
2708 ok(!strcmp(dst, "012345"), "dst != 012345\n");
2709 ok(dst[TEST_STRNCPY_LEN - 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
2711 /* strlen(src) == TEST_STRNCPY_LEN */
2712 ret = strncpy(dst, "0123456789", TEST_STRNCPY_LEN);
2713 ok(ret == dst, "ret != dst\n");
2714 ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
2717 static void test_strxfrm(void)
2719 char dest[256];
2720 size_t ret;
2722 /* crashes on old version of msvcrt */
2723 if(p__atodbl_l) {
2724 errno = 0xdeadbeef;
2725 ret = strxfrm(NULL, "src", 1);
2726 ok(ret == INT_MAX, "ret = %d\n", (int)ret);
2727 ok(errno == EINVAL, "errno = %d\n", errno);
2729 errno = 0xdeadbeef;
2730 ret = strxfrm(dest, NULL, 100);
2731 ok(ret == INT_MAX, "ret = %d\n", (int)ret);
2732 ok(errno == EINVAL, "errno = %d\n", errno);
2735 ret = strxfrm(NULL, "src", 0);
2736 ok(ret == 3, "ret = %d\n", (int)ret);
2737 dest[0] = 'a';
2738 ret = strxfrm(dest, "src", 0);
2739 ok(ret == 3, "ret = %d\n", (int)ret);
2740 ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
2742 dest[3] = 'a';
2743 ret = strxfrm(dest, "src", 5);
2744 ok(ret == 3, "ret = %d\n", (int)ret);
2745 ok(!strcmp(dest, "src"), "dest = %s\n", dest);
2747 errno = 0xdeadbeef;
2748 dest[1] = 'a';
2749 ret = strxfrm(dest, "src", 1);
2750 ok(ret == 3, "ret = %d\n", (int)ret);
2751 ok(dest[0] == 's', "dest[0] = %d\n", dest[0]);
2752 ok(dest[1] == 'a', "dest[1] = %d\n", dest[1]);
2753 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
2755 ret = strxfrm(dest, "", 5);
2756 ok(ret == 0, "ret = %d\n", (int)ret);
2757 ok(!dest[0], "dest[0] = %d\n", dest[0]);
2759 if(!setlocale(LC_ALL, "polish")) {
2760 win_skip("stxfrm tests\n");
2761 return;
2764 ret = strxfrm(NULL, "src", 0);
2765 ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
2766 dest[0] = 'a';
2767 ret = strxfrm(dest, "src", 0);
2768 ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
2769 ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
2771 ret = strxfrm(dest, "src", ret+1);
2772 ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
2773 ok(dest[0], "dest[0] = 0\n");
2775 errno = 0xdeadbeef;
2776 dest[0] = 'a';
2777 ret = strxfrm(dest, "src", 5);
2778 ok(ret>5 && ret<sizeof(dest)-1, "ret = %d\n", (int)ret);
2779 ok(!dest[0] || broken(!p__atodbl_l && dest[0]=='a'), "dest[0] = %d\n", dest[0]);
2781 setlocale(LC_ALL, "C");
2784 static void test__strnset_s(void)
2786 char buf[5] = {0};
2787 int r;
2789 if(!p__strnset_s) {
2790 win_skip("_strnset_s not available\n");
2791 return;
2794 r = p__strnset_s(NULL, 0, 'a', 0);
2795 ok(r == 0, "r = %d\n", r);
2797 buf[0] = buf[1] = buf[2] = 'b';
2798 r = p__strnset_s(buf, sizeof(buf), 'a', 2);
2799 ok(r == 0, "r = %d\n", r);
2800 ok(!strcmp(buf, "aab"), "buf = %s\n", buf);
2802 r = p__strnset_s(buf, 0, 'a', 0);
2803 ok(r == EINVAL, "r = %d\n", r);
2805 r = p__strnset_s(NULL, 0, 'a', 1);
2806 ok(r == EINVAL, "r = %d\n", r);
2808 buf[3] = 'b';
2809 r = p__strnset_s(buf, sizeof(buf)-1, 'c', 2);
2810 ok(r == EINVAL, "r = %d\n", r);
2811 ok(!buf[0] && buf[1]=='c' && buf[2]=='b', "buf = %s\n", buf);
2814 static void test__wcsset_s(void)
2816 wchar_t str[10];
2817 int r;
2819 if(!p__wcsset_s) {
2820 win_skip("_wcsset_s not available\n");
2821 return;
2824 r = p__wcsset_s(NULL, 0, 'a');
2825 ok(r == EINVAL, "r = %d\n", r);
2827 str[0] = 'a';
2828 r = p__wcsset_s(str, 0, 'a');
2829 ok(r == EINVAL, "r = %d\n", r);
2830 ok(str[0] == 'a', "str[0] = %d\n", str[0]);
2832 str[0] = 'a';
2833 str[1] = 'b';
2834 r = p__wcsset_s(str, 2, 'c');
2835 ok(r == EINVAL, "r = %d\n", r);
2836 ok(!str[0], "str[0] = %d\n", str[0]);
2837 ok(str[1] == 'b', "str[1] = %d\n", str[1]);
2839 str[0] = 'a';
2840 str[1] = 0;
2841 str[2] = 'b';
2842 r = p__wcsset_s(str, 3, 'c');
2843 ok(str[0] == 'c', "str[0] = %d\n", str[0]);
2844 ok(str[1] == 0, "str[1] = %d\n", str[1]);
2845 ok(str[2] == 'b', "str[2] = %d\n", str[2]);
2848 START_TEST(string)
2850 char mem[100];
2851 static const char xilstring[]="c:/xilinx";
2852 int nLen;
2854 hMsvcrt = GetModuleHandleA("msvcrt.dll");
2855 if (!hMsvcrt)
2856 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
2857 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
2858 SET(pmemcpy,"memcpy");
2859 p_memcpy_s = (void*)GetProcAddress( hMsvcrt, "memcpy_s" );
2860 p_memmove_s = (void*)GetProcAddress( hMsvcrt, "memmove_s" );
2861 SET(pmemcmp,"memcmp");
2862 SET(p_mbctype,"_mbctype");
2863 SET(p__mb_cur_max,"__mb_cur_max");
2864 pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
2865 pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
2866 p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
2867 p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
2868 p__mbscpy_s = (void *)GetProcAddress( hMsvcrt,"_mbscpy_s" );
2869 p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
2870 p_wcsncpy_s = (void *)GetProcAddress( hMsvcrt,"wcsncpy_s" );
2871 p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
2872 p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
2873 p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
2874 p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
2875 p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
2876 p_wcstoi64 = (void *)GetProcAddress(hMsvcrt, "_wcstoi64");
2877 p_wcstoui64 = (void *)GetProcAddress(hMsvcrt, "_wcstoui64");
2878 pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
2879 pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
2880 pwcsrtombs = (void *)GetProcAddress(hMsvcrt, "wcsrtombs");
2881 p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
2882 p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
2883 p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
2884 p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
2885 p_wcslwr_s = (void*)GetProcAddress(hMsvcrt, "_wcslwr_s");
2886 p_mbsupr_s = (void*)GetProcAddress(hMsvcrt, "_mbsupr_s");
2887 p_mbslwr_s = (void*)GetProcAddress(hMsvcrt, "_mbslwr_s");
2888 p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob");
2889 p_wcrtomb = (void*)GetProcAddress(hMsvcrt, "wcrtomb");
2890 p_tolower = (void*)GetProcAddress(hMsvcrt, "tolower");
2891 p_mbrlen = (void*)GetProcAddress(hMsvcrt, "mbrlen");
2892 p_mbrtowc = (void*)GetProcAddress(hMsvcrt, "mbrtowc");
2893 p_mbsrtowcs = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs");
2894 p__atodbl_l = (void*)GetProcAddress(hMsvcrt, "_atodbl_l");
2895 p__strnset_s = (void*)GetProcAddress(hMsvcrt, "_strnset_s");
2896 p__wcsset_s = (void*)GetProcAddress(hMsvcrt, "_wcsset_s");
2898 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2899 MFC42 CString::Insert seems to rely on that behaviour */
2900 strcpy(mem,xilstring);
2901 nLen=strlen(xilstring);
2902 pmemcpy(mem+5, mem,nLen+1);
2903 ok(pmemcmp(mem+5,xilstring, nLen) == 0,
2904 "Got result %s\n",mem+5);
2906 /* run tolower tests first */
2907 test_tolower();
2908 test_swab();
2909 test_mbcp();
2910 test_mbsspn();
2911 test_mbsspnp();
2912 test_strdup();
2913 test_strcpy_s();
2914 test_memcpy_s();
2915 test_memmove_s();
2916 test_strcat_s();
2917 test__mbsnbcpy_s();
2918 test__mbscpy_s();
2919 test_mbcjisjms();
2920 test_mbcjmsjis();
2921 test_mbctohira();
2922 test_mbbtombc();
2923 test_mbctombb();
2924 test_ismbckata();
2925 test_ismbclegal();
2926 test_strtok();
2927 test__mbstok();
2928 test_wcscpy_s();
2929 test__wcsupr_s();
2930 test_strtol();
2931 test_strnlen();
2932 test__strtoi64();
2933 test__strtod();
2934 test_mbstowcs();
2935 test_gcvt();
2936 test__itoa_s();
2937 test__strlwr_s();
2938 test_wcsncat_s();
2939 test__mbsnbcat_s();
2940 test__ultoa_s();
2941 test__wcslwr_s();
2942 test__mbsupr_s();
2943 test__mbslwr_s();
2944 test_wctob();
2945 test_wctomb();
2946 test__atodbl();
2947 test__stricmp();
2948 test__wcstoi64();
2949 test_atoi();
2950 test_strncpy();
2951 test_strxfrm();
2952 test__strnset_s();
2953 test__wcsset_s();