[MSVCRT_WINETEST] Sync with Wine Staging 2.9. CORE-13362
[reactos.git] / rostests / winetests / msvcrt / string.c
1 /*
2 * Unit test suite for string functions.
3 *
4 * Copyright 2004 Uwe Bonnes
5 *
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.
10 *
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.
15 *
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
19 */
20
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>
32
33 /* make it use a definition from string.h */
34 #undef strncpy
35 #include "winbase.h"
36 #include "winnls.h"
37
38 static char *buf_to_string(const unsigned char *bin, int len, int nr)
39 {
40 static char buf[2][1024];
41 char *w = buf[nr];
42 int i;
43
44 for (i = 0; i < len; i++)
45 {
46 sprintf(w, "%02x ", (unsigned char)bin[i]);
47 w += strlen(w);
48 }
49 return buf[nr];
50 }
51
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)); }
54
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_mbscat_s)(unsigned char *dst, size_t size, const unsigned char *src);
62 static int (__cdecl *p_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
63 static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
64 static int (__cdecl *p__mbscpy_s)(unsigned char*, size_t, const unsigned char*);
65 static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
66 static int (__cdecl *p_wcsncpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc, size_t count);
67 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
68 static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
69 static size_t (__cdecl *p_strnlen)(const char *, size_t);
70 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
71 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
72 static __int64 (__cdecl *p_wcstoi64)(const wchar_t *, wchar_t **, int);
73 static unsigned __int64 (__cdecl *p_wcstoui64)(const wchar_t *, wchar_t **, int);
74 static int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
75 static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
76 static size_t (__cdecl *p_mbsrtowcs)(wchar_t*, const char**, size_t, mbstate_t*);
77 static int (__cdecl *p_mbsrtowcs_s)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
78 static size_t (__cdecl *pwcsrtombs)(char*, const wchar_t**, size_t, int*);
79 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
80 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
81 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
82 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
83 static int *p__mb_cur_max;
84 static unsigned char *p_mbctype;
85 static int (__cdecl *p_wcslwr_s)(wchar_t*,size_t);
86 static errno_t (__cdecl *p_mbsupr_s)(unsigned char *str, size_t numberOfElements);
87 static errno_t (__cdecl *p_mbslwr_s)(unsigned char *str, size_t numberOfElements);
88 static int (__cdecl *p_wctob)(wint_t);
89 static size_t (__cdecl *p_wcrtomb)(char*, wchar_t, mbstate_t*);
90 static int (__cdecl *p_tolower)(int);
91 static size_t (__cdecl *p_mbrlen)(const char*, size_t, mbstate_t*);
92 static size_t (__cdecl *p_mbrtowc)(wchar_t*, const char*, size_t, mbstate_t*);
93 static int (__cdecl *p__atodbl_l)(_CRT_DOUBLE*,char*,_locale_t);
94 static double (__cdecl *p__atof_l)(const char*,_locale_t);
95 static double (__cdecl *p__strtod_l)(const char *,char**,_locale_t);
96 static int (__cdecl *p__strnset_s)(char*,size_t,int,size_t);
97 static int (__cdecl *p__wcsset_s)(wchar_t*,size_t,wchar_t);
98
99 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
100 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
101
102 static HMODULE hMsvcrt;
103
104 static void test_swab( void ) {
105 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
106 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
107 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
108 char expected3[] = "$";
109
110 char from[30];
111 char to[30];
112
113 int testsize;
114
115 /* Test 1 - normal even case */
116 memset(to,'$', sizeof(to));
117 memset(from,'@', sizeof(from));
118 testsize = 26;
119 memcpy(from, original, testsize);
120 _swab( from, to, testsize );
121 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
122
123 /* Test 2 - uneven case */
124 memset(to,'$', sizeof(to));
125 memset(from,'@', sizeof(from));
126 testsize = 25;
127 memcpy(from, original, testsize);
128 _swab( from, to, testsize );
129 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
130
131 /* Test 3 - from = to */
132 memset(to,'$', sizeof(to));
133 memset(from,'@', sizeof(from));
134 testsize = 26;
135 memcpy(to, original, testsize);
136 _swab( to, to, testsize );
137 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
138
139 /* Test 4 - 1 bytes */
140 memset(to,'$', sizeof(to));
141 memset(from,'@', sizeof(from));
142 testsize = 1;
143 memcpy(from, original, testsize);
144 _swab( from, to, testsize );
145 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
146 }
147
148 #if 0 /* use this to generate more tests */
149
150 static void test_codepage(int cp)
151 {
152 int i;
153 int prev;
154 int count = 1;
155
156 ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
157
158 prev = p_mbctype[0];
159 printf("static int result_cp_%d_mbctype[] = { ", cp);
160 for (i = 1; i < 257; i++)
161 {
162 if (p_mbctype[i] != prev)
163 {
164 printf("0x%x,%d, ", prev, count);
165 prev = p_mbctype[i];
166 count = 1;
167 }
168 else
169 count++;
170 }
171 printf("0x%x,%d };\n", prev, count);
172 }
173
174 #else
175
176 /* RLE-encoded mbctype tables for given codepages */
177 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
178 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
179 static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
180 0xc,126, 0,1 };
181 static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
182 0,1 };
183 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
184 0x0,2, 0x4,32, 0xc,94, 0,1 };
185
186 static void test_cp_table(int cp, int *result)
187 {
188 int i;
189 int count = 0;
190 int curr = 0;
191 _setmbcp(cp);
192 for (i = 0; i < 256; i++)
193 {
194 if (count == 0)
195 {
196 curr = result[0];
197 count = result[1];
198 result += 2;
199 }
200 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);
201 count--;
202 }
203 }
204
205 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
206
207 #endif
208
209 static void test_mbcp(void)
210 {
211 int mb_orig_max = *p__mb_cur_max;
212 int curr_mbcp = _getmbcp();
213 unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
214 unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
215 unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
216 unsigned char buf[16];
217 int step;
218 CPINFO cp_info;
219
220 /* _mbtype tests */
221
222 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
223 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
224 * CP1252 (or the ACP?) so we test only a few ASCII characters */
225 _setmbcp(1252);
226 expect_eq(p_mbctype[10], 0, char, "%x");
227 expect_eq(p_mbctype[50], 0, char, "%x");
228 expect_eq(p_mbctype[66], _SBUP, char, "%x");
229 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
230 expect_eq(p_mbctype[128], 0, char, "%x");
231 _setmbcp(1250);
232 expect_eq(p_mbctype[10], 0, char, "%x");
233 expect_eq(p_mbctype[50], 0, char, "%x");
234 expect_eq(p_mbctype[66], _SBUP, char, "%x");
235 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
236 expect_eq(p_mbctype[128], 0, char, "%x");
237
238 /* double byte code pages */
239 test_codepage(932);
240 test_codepage(936);
241 test_codepage(949);
242 test_codepage(950);
243
244 _setmbcp(936);
245 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);
246 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
247 ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
248 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
249 ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
250 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
251 ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
252
253 /* _ismbslead */
254 expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
255 expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
256 expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
257 expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
258 expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
259 expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
260 expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
261 expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
262 expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
263
264 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
265 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
266 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
267 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
268
269 /* _ismbstrail */
270 expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
271 expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
272 expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
273 expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
274 expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
275 expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
276 expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
277 expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
278 expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
279
280 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
281 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
282 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
283 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
284 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
285 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
286
287 /* _mbsbtype */
288 expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
289 expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
290 expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
291 expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
292 expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
293 expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
294 expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
295 expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
296 expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
297
298 expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
299 expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
300 expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
301 expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
302 expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
303 expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
304
305 /* _mbsnextc */
306 expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
307 expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
308 expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
309
310 /* _mbclen/_mbslen */
311 expect_eq(_mbclen(mbstring), 2, int, "%d");
312 expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
313 expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
314 expect_eq(_mbslen(mbstring2), 4, int, "%d");
315 expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
316 expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
317
318 /* mbrlen */
319 if(!setlocale(LC_ALL, ".936") || !p_mbrlen) {
320 win_skip("mbrlen tests\n");
321 }else {
322 mbstate_t state = 0;
323 expect_eq(p_mbrlen((const char*)mbstring, 2, NULL), 2, int, "%d");
324 expect_eq(p_mbrlen((const char*)&mbstring[2], 2, NULL), 2, int, "%d");
325 expect_eq(p_mbrlen((const char*)&mbstring[3], 2, NULL), 1, int, "%d");
326 expect_eq(p_mbrlen((const char*)mbstring, 1, NULL), -2, int, "%d");
327 expect_eq(p_mbrlen((const char*)mbstring, 1, &state), -2, int, "%d");
328 ok(state == mbstring[0], "incorrect state value (%x)\n", state);
329 expect_eq(p_mbrlen((const char*)&mbstring[1], 1, &state), 2, int, "%d");
330 }
331
332 /* mbrtowc */
333 if(!setlocale(LC_ALL, ".936") || !p_mbrtowc) {
334 win_skip("mbrtowc tests\n");
335 }else {
336 mbstate_t state = 0;
337 wchar_t dst;
338 expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 2, NULL), 2, int, "%d");
339 ok(dst == 0x6c28, "dst = %x, expected 0x6c28\n", dst);
340 expect_eq(p_mbrtowc(&dst, (const char*)mbstring+2, 2, NULL), 2, int, "%d");
341 ok(dst == 0x3f, "dst = %x, expected 0x3f\n", dst);
342 expect_eq(p_mbrtowc(&dst, (const char*)mbstring+3, 2, NULL), 1, int, "%d");
343 ok(dst == 0x20, "dst = %x, expected 0x20\n", dst);
344 expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 1, NULL), -2, int, "%d");
345 ok(dst == 0, "dst = %x, expected 0\n", dst);
346 expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 1, &state), -2, int, "%d");
347 ok(dst == 0, "dst = %x, expected 0\n", dst);
348 ok(state == mbstring[0], "incorrect state value (%x)\n", state);
349 expect_eq(p_mbrtowc(&dst, (const char*)mbstring+1, 1, &state), 2, int, "%d");
350 ok(dst == 0x6c28, "dst = %x, expected 0x6c28\n", dst);
351 ok(state == 0, "incorrect state value (%x)\n", state);
352 }
353 setlocale(LC_ALL, "C");
354
355 /* _mbccpy/_mbsncpy */
356 memset(buf, 0xff, sizeof(buf));
357 _mbccpy(buf, mbstring);
358 expect_bin(buf, "\xb0\xb1\xff", 3);
359
360 memset(buf, 0xff, sizeof(buf));
361 _mbsncpy(buf, mbstring, 1);
362 expect_bin(buf, "\xb0\xb1\xff", 3);
363 memset(buf, 0xff, sizeof(buf));
364 _mbsncpy(buf, mbstring, 2);
365 expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
366 memset(buf, 0xff, sizeof(buf));
367 _mbsncpy(buf, mbstring, 3);
368 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
369 memset(buf, 0xff, sizeof(buf));
370 _mbsncpy(buf, mbstring, 4);
371 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
372 memset(buf, 0xff, sizeof(buf));
373 _mbsncpy(buf, mbstring, 5);
374 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
375 memset(buf, 0xff, sizeof(buf));
376 _mbsncpy(buf, mbsonlylead, 6);
377 expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
378
379 memset(buf, 0xff, sizeof(buf));
380 _mbsnbcpy(buf, mbstring2, 2);
381 expect_bin(buf, "\xb0\xb1\xff", 3);
382 _mbsnbcpy(buf, mbstring2, 3);
383 expect_bin(buf, "\xb0\xb1\0\xff", 4);
384 _mbsnbcpy(buf, mbstring2, 4);
385 expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
386 memset(buf, 0xff, sizeof(buf));
387 _mbsnbcpy(buf, mbsonlylead, 5);
388 expect_bin(buf, "\0\0\0\0\0\xff", 6);
389
390 /* _mbsinc/mbsdec */
391 step = _mbsinc(mbstring) - mbstring;
392 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
393 step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
394 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
395
396 step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
397 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
398 step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
399 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
400 step = _mbsninc(mbstring2, 0) - mbstring2;
401 ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
402 step = _mbsninc(mbstring2, 1) - mbstring2;
403 ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
404 step = _mbsninc(mbstring2, 2) - mbstring2;
405 ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
406 step = _mbsninc(mbstring2, 3) - mbstring2;
407 ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
408 step = _mbsninc(mbstring2, 4) - mbstring2;
409 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
410 step = _mbsninc(mbstring2, 5) - mbstring2;
411 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
412 step = _mbsninc(mbstring2, 17) - mbstring2;
413 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
414
415 /* functions that depend on locale codepage, not mbcp.
416 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
417 * (as of Wine 0.9.43)
418 */
419 GetCPInfo(GetACP(), &cp_info);
420 if (cp_info.MaxCharSize == 1)
421 {
422 expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
423 expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
424 }
425 else
426 skip("Current locale has double-byte charset - could lead to false positives\n");
427
428 _setmbcp(1361);
429 expect_eq(_ismbblead(0x80), 0, int, "%d");
430 todo_wine {
431 expect_eq(_ismbblead(0x81), 1, int, "%d");
432 expect_eq(_ismbblead(0x83), 1, int, "%d");
433 }
434 expect_eq(_ismbblead(0x84), 1, int, "%d");
435 expect_eq(_ismbblead(0xd3), 1, int, "%d");
436 expect_eq(_ismbblead(0xd7), 0, int, "%d");
437 expect_eq(_ismbblead(0xd8), 1, int, "%d");
438 expect_eq(_ismbblead(0xd9), 1, int, "%d");
439
440 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
441 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
442 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
443 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
444 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
445 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
446 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
447 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
448
449 _setmbcp(curr_mbcp);
450 }
451
452 static void test_mbsspn( void)
453 {
454 unsigned char str1[]="cabernet";
455 unsigned char str2[]="shiraz";
456 unsigned char set[]="abc";
457 unsigned char empty[]="";
458 int ret;
459 ret=_mbsspn( str1, set);
460 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
461 ret=_mbsspn( str2, set);
462 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
463 ret=_mbsspn( str1, empty);
464 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
465 }
466
467 static void test_mbsspnp( void)
468 {
469 unsigned char str1[]="cabernet";
470 unsigned char str2[]="shiraz";
471 unsigned char set[]="abc";
472 unsigned char empty[]="";
473 unsigned char full[]="abcenrt";
474 unsigned char* ret;
475 ret=_mbsspnp( str1, set);
476 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
477 ret=_mbsspnp( str2, set);
478 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
479 ret=_mbsspnp( str1, empty);
480 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
481 ret=_mbsspnp( str1, full);
482 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
483 }
484
485 static void test_strdup(void)
486 {
487 char *str;
488 str = _strdup( 0 );
489 ok( str == 0, "strdup returns %s should be 0\n", str);
490 free( str );
491 }
492
493 static void test_strcpy_s(void)
494 {
495 char dest[8];
496 const char *small = "small";
497 const char *big = "atoolongstringforthislittledestination";
498 int ret;
499
500 if(!pstrcpy_s)
501 {
502 win_skip("strcpy_s not found\n");
503 return;
504 }
505
506 memset(dest, 'X', sizeof(dest));
507 ret = pstrcpy_s(dest, sizeof(dest), small);
508 ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
509 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
510 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
511 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
512 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
513
514 memset(dest, 'X', sizeof(dest));
515 ret = pstrcpy_s(dest, 0, big);
516 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
517 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
518 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
519 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
520 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
521 ret = pstrcpy_s(dest, 0, NULL);
522 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
523 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
524 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
525 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
526 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
527
528 memset(dest, 'X', sizeof(dest));
529 ret = pstrcpy_s(dest, sizeof(dest), big);
530 ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
531 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
532 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
533 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
534 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
535
536 memset(dest, 'X', sizeof(dest));
537 ret = pstrcpy_s(dest, sizeof(dest), NULL);
538 ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
539 ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
540 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
541 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
542 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
543
544 ret = pstrcpy_s(NULL, sizeof(dest), small);
545 ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
546 }
547
548 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
549
550 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
551 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
552 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
553 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
554 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
555
556 static void test_memcpy_s(void)
557 {
558 static char dest[8];
559 static const char tiny[] = {'T',0,'I','N','Y',0};
560 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
561 int ret;
562 if (!p_memcpy_s) {
563 win_skip("memcpy_s not found\n");
564 return;
565 }
566
567 /* Normal */
568 memset(dest, 'X', sizeof(dest));
569 ret = p_memcpy_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
570 ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret);
571 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
572
573 /* Vary source size */
574 errno = 0xdeadbeef;
575 memset(dest, 'X', sizeof(dest));
576 ret = p_memcpy_s(dest, NUMELMS(dest), big, NUMELMS(big));
577 ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret);
578 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
579 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
580
581 /* Replace source with NULL */
582 errno = 0xdeadbeef;
583 memset(dest, 'X', sizeof(dest));
584 ret = p_memcpy_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
585 ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret);
586 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
587 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
588
589 /* Vary dest size */
590 errno = 0xdeadbeef;
591 memset(dest, 'X', sizeof(dest));
592 ret = p_memcpy_s(dest, 0, tiny, NUMELMS(tiny));
593 ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret);
594 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
595 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
596
597 /* Replace dest with NULL */
598 errno = 0xdeadbeef;
599 ret = p_memcpy_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
600 ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
601 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
602
603 /* Combinations */
604 errno = 0xdeadbeef;
605 memset(dest, 'X', sizeof(dest));
606 ret = p_memcpy_s(dest, 0, NULL, NUMELMS(tiny));
607 ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
608 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
609 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
610 }
611
612 static void test_memmove_s(void)
613 {
614 static char dest[8];
615 static const char tiny[] = {'T',0,'I','N','Y',0};
616 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
617 int ret;
618 if (!p_memmove_s) {
619 win_skip("memmove_s not found\n");
620 return;
621 }
622
623 /* Normal */
624 memset(dest, 'X', sizeof(dest));
625 ret = p_memmove_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
626 ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret);
627 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
628
629 /* Overlapping */
630 memcpy(dest, big, sizeof(dest));
631 ret = p_memmove_s(dest+1, NUMELMS(dest)-1, dest, NUMELMS(dest)-1);
632 ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret);
633 okchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]);
634
635 /* Vary source size */
636 errno = 0xdeadbeef;
637 memset(dest, 'X', sizeof(dest));
638 ret = p_memmove_s(dest, NUMELMS(dest), big, NUMELMS(big));
639 ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret);
640 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
641 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
642
643 /* Replace source with NULL */
644 errno = 0xdeadbeef;
645 memset(dest, 'X', sizeof(dest));
646 ret = p_memmove_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
647 ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret);
648 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
649 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
650
651 /* Vary dest size */
652 errno = 0xdeadbeef;
653 memset(dest, 'X', sizeof(dest));
654 ret = p_memmove_s(dest, 0, tiny, NUMELMS(tiny));
655 ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret);
656 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
657 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
658
659 /* Replace dest with NULL */
660 errno = 0xdeadbeef;
661 ret = p_memmove_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
662 ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
663 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
664
665 /* Combinations */
666 errno = 0xdeadbeef;
667 memset(dest, 'X', sizeof(dest));
668 ret = p_memmove_s(dest, 0, NULL, NUMELMS(tiny));
669 ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
670 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
671 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
672 }
673
674 static void test_strcat_s(void)
675 {
676 char dest[8];
677 const char *small = "sma";
678 int ret;
679
680 if(!pstrcat_s)
681 {
682 win_skip("strcat_s not found\n");
683 return;
684 }
685
686 memset(dest, 'X', sizeof(dest));
687 dest[0] = '\0';
688 ret = pstrcat_s(dest, sizeof(dest), small);
689 ok(ret == 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
690 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == '\0'&&
691 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
692 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
693 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
694 ret = pstrcat_s(dest, sizeof(dest), small);
695 ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
696 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
697 dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
698 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
699 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
700
701 ret = pstrcat_s(dest, sizeof(dest), small);
702 ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
703 ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
704 dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
705 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
706 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
707
708 memset(dest, 'X', sizeof(dest));
709 dest[0] = 'a';
710 dest[1] = '\0';
711
712 ret = pstrcat_s(dest, 0, small);
713 ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
714 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
715 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
716 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
717 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
718
719 ret = pstrcat_s(dest, 0, NULL);
720 ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
721 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
722 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
723 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
724 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
725
726 ret = pstrcat_s(dest, sizeof(dest), NULL);
727 ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
728 ok(dest[0] == '\0'&& dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
729 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
730 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
731 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
732
733 ret = pstrcat_s(NULL, sizeof(dest), small);
734 ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
735 }
736
737 static void test__mbscat_s(void)
738 {
739 unsigned char dst[8], src[4];
740 int err;
741 int prev_cp = _getmbcp();
742
743 if(!p_mbscat_s)
744 {
745 win_skip("_mbscat_s not found\n");
746 return;
747 }
748
749
750 src[0] = dst[0] = 0;
751 err = p_mbscat_s(NULL, sizeof(dst), src);
752 ok(err == EINVAL, "_mbscat_s returned %d\n", err);
753
754 err = p_mbscat_s(dst, sizeof(dst), NULL);
755 ok(err == EINVAL, "_mbscat_s returned %d\n", err);
756
757 dst[0] = 'a';
758 err = p_mbscat_s(dst, 1, src);
759 ok(err == EINVAL, "_mbscat_s returned %d\n", err);
760
761 memset(dst, 'a', sizeof(dst));
762 dst[6] = 0;
763 src[0] = 'b';
764 src[1] = 0;
765
766 err = p_mbscat_s(dst, sizeof(dst), src);
767 ok(err == 0, "_mbscat_s returned %d\n", err);
768 ok(!memcmp(dst, "aaaaaab", 8), "dst = %s\n", dst);
769
770 err = p_mbscat_s(dst, sizeof(dst), src);
771 ok(err == ERANGE, "_mbscat_s returned %d\n", err);
772 ok(!dst[0], "dst[0] = %c\n", dst[0]);
773 ok(dst[1] == 'a', "dst[1] = %c\n", dst[1]);
774
775 _setmbcp(932);
776 /* test invalid str in dst */
777 dst[0] = 0x81;
778 dst[1] = 0x81;
779 dst[2] = 0x52;
780 dst[3] = 0;
781 src[0] = 'a';
782 src[1] = 0;
783 err = p_mbscat_s(dst, sizeof(dst), src);
784 ok(err == 0, "_mbscat_s returned %d\n", err);
785
786 /* test invalid str in src */
787 dst[0] = 0;
788 src[0] = 0x81;
789 src[1] = 0x81;
790 src[2] = 0x52;
791 src[3] = 0;
792 err = p_mbscat_s(dst, sizeof(dst), src);
793 ok(err == 0, "_mbscat_s returned %d\n", err);
794
795 /* test dst with leading byte on the end of buffer */
796 dst[0] = 'a';
797 dst[1] = 0x81;
798 dst[2] = 0;
799 src[0] = 'R';
800 src[1] = 0;
801 err = p_mbscat_s(dst, sizeof(dst), src);
802 ok(err == EILSEQ, "_mbscat_s returned %d\n", err);
803 ok(!memcmp(dst, "aR", 3), "dst = %s\n", dst);
804
805 /* test src with leading byte on the end of buffer */
806 dst[0] = 'a';
807 dst[1] = 0;
808 src[0] = 'b';
809 src[1] = 0x81;
810 src[2] = 0;
811 err = p_mbscat_s(dst, sizeof(dst), src);
812 ok(err == EILSEQ, "_mbscat_s returned %d\n", err);
813 ok(!memcmp(dst, "ab", 3), "dst = %s\n", dst);
814 _setmbcp(prev_cp);
815 }
816
817 static void test__mbsnbcpy_s(void)
818 {
819 unsigned char dest[8];
820 const unsigned char big[] = "atoolongstringforthislittledestination";
821 const unsigned char small[] = "small";
822 int ret;
823
824 if(!p_mbsnbcpy_s)
825 {
826 win_skip("_mbsnbcpy_s not found\n");
827 return;
828 }
829
830 memset(dest, 'X', sizeof(dest));
831 ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
832 ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
833 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
834 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
835 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
836 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
837
838 /* WTF? */
839 memset(dest, 'X', sizeof(dest));
840 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
841 ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
842 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
843 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
844 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
845 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
846
847 memset(dest, 'X', sizeof(dest));
848 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
849 ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
850 ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
851 dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
852 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
853 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
854
855 memset(dest, 'X', sizeof(dest));
856 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
857 ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
858 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
859 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
860 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
861 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
862 }
863
864 static void test__mbscpy_s(void)
865 {
866 const unsigned char src[] = "source string";
867 unsigned char dest[16];
868 int ret;
869
870 if(!p__mbscpy_s)
871 {
872 win_skip("_mbscpy_s not found\n");
873 return;
874 }
875
876 ret = p__mbscpy_s(NULL, 0, src);
877 ok(ret == EINVAL, "got %d\n", ret);
878 ret = p__mbscpy_s(NULL, sizeof(dest), src);
879 ok(ret == EINVAL, "got %d\n", ret);
880 ret = p__mbscpy_s(dest, 0, src);
881 ok(ret == EINVAL, "got %d\n", ret);
882 dest[0] = 'x';
883 ret = p__mbscpy_s(dest, sizeof(dest), NULL);
884 ok(ret == EINVAL, "got %d\n", ret);
885 ok(!dest[0], "dest buffer was not modified on invalid argument\n");
886
887 memset(dest, 'X', sizeof(dest));
888 ret = p__mbscpy_s(dest, sizeof(dest), src);
889 ok(!ret, "got %d\n", ret);
890 ok(!memcmp(dest, src, sizeof(src)), "dest = %s\n", dest);
891 ok(dest[sizeof(src)] == 'X', "unused part of buffer was modified\n");
892
893 memset(dest, 'X', sizeof(dest));
894 ret = p__mbscpy_s(dest, 4, src);
895 ok(ret == ERANGE, "got %d\n", ret);
896 ok(!dest[0], "incorrect dest buffer (%d)\n", dest[0]);
897 ok(dest[1] == src[1], "incorrect dest buffer (%d)\n", dest[1]);
898 }
899
900 static void test_wcscpy_s(void)
901 {
902 static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
903 static WCHAR szDest[18];
904 static WCHAR szDestShort[8];
905 int ret;
906
907 if(!p_wcscpy_s)
908 {
909 win_skip("wcscpy_s not found\n");
910 return;
911 }
912
913 /* Test NULL Dest */
914 errno = EBADF;
915 ret = p_wcscpy_s(NULL, 18, szLongText);
916 ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
917 ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
918
919 /* Test NULL Source */
920 errno = EBADF;
921 szDest[0] = 'A';
922 ret = p_wcscpy_s(szDest, 18, NULL);
923 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
924 ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
925 ok(szDest[0] == 0, "szDest[0] not 0, got %c\n", szDest[0]);
926
927 /* Test invalid size */
928 errno = EBADF;
929 szDest[0] = 'A';
930 ret = p_wcscpy_s(szDest, 0, szLongText);
931 /* Later versions changed the return value for this case to EINVAL,
932 * and don't modify the result if the dest size is 0.
933 */
934 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
935 ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
936 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
937
938 /* Copy same buffer size */
939 ret = p_wcscpy_s(szDest, 18, szLongText);
940 ok(ret == 0, "expected 0 got %d\n", ret);
941 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
942
943 /* Copy smaller buffer size */
944 errno = EBADF;
945 szDest[0] = 'A';
946 ret = p_wcscpy_s(szDestShort, 8, szLongText);
947 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
948 ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
949 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
950
951 if(!p_wcsncpy_s)
952 {
953 win_skip("wcsncpy_s not found\n");
954 return;
955 }
956
957 ret = p_wcsncpy_s(NULL, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
958 ok(ret == EINVAL, "p_wcsncpy_s expect EINVAL got %d\n", ret);
959
960 szDest[0] = 'A';
961 ret = p_wcsncpy_s(szDest, 18, NULL, 1);
962 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
963 ok(szDest[0] == 0, "szDest[0] not 0\n");
964
965 szDest[0] = 'A';
966 ret = p_wcsncpy_s(szDest, 18, NULL, 0);
967 ok(ret == 0, "expected ERROR_SUCCESS got %d\n", ret);
968 ok(szDest[0] == 0, "szDest[0] not 0\n");
969
970 szDest[0] = 'A';
971 ret = p_wcsncpy_s(szDest, 0, szLongText, sizeof(szLongText)/sizeof(WCHAR));
972 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
973 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
974
975 ret = p_wcsncpy_s(szDest, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
976 ok(ret == 0, "expected 0 got %d\n", ret);
977 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
978
979 szDest[0] = 'A';
980 ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR));
981 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
982 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
983
984 szDest[0] = 'A';
985 ret = p_wcsncpy_s(szDest, 5, szLongText, -1);
986 ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret);
987 ok(szDest[4] == 0, "szDest[4] not 0\n");
988 ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest));
989
990 ret = p_wcsncpy_s(NULL, 0, (void*)0xdeadbeef, 0);
991 ok(ret == 0, "ret = %d\n", ret);
992
993 szDestShort[0] = '1';
994 szDestShort[1] = 0;
995 ret = p_wcsncpy_s(szDestShort+1, 4, szDestShort, -1);
996 ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret);
997 ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1',
998 "szDestShort = %s\n", wine_dbgstr_w(szDestShort));
999 }
1000
1001 static void test__wcsupr_s(void)
1002 {
1003 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1004 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1005 static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
1006 'W', 'E', 'R', 'U', 'P', 'P', 'E',
1007 'R', 0};
1008 WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
1009 int ret;
1010
1011 if (!p_wcsupr_s)
1012 {
1013 win_skip("_wcsupr_s not found\n");
1014 return;
1015 }
1016
1017 /* Test NULL input string and invalid size. */
1018 errno = EBADF;
1019 ret = p_wcsupr_s(NULL, 0);
1020 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1021 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1022
1023 /* Test NULL input string and valid size. */
1024 errno = EBADF;
1025 ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
1026 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1027 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1028
1029 /* Test empty string with zero size. */
1030 errno = EBADF;
1031 testBuffer[0] = '\0';
1032 ret = p_wcsupr_s(testBuffer, 0);
1033 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1034 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1035 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
1036
1037 /* Test empty string with size of one. */
1038 testBuffer[0] = '\0';
1039 ret = p_wcsupr_s(testBuffer, 1);
1040 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
1041 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
1042
1043 /* Test one-byte buffer with zero size. */
1044 errno = EBADF;
1045 testBuffer[0] = 'x';
1046 ret = p_wcsupr_s(testBuffer, 0);
1047 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1048 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1049 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
1050
1051 /* Test one-byte buffer with size of one. */
1052 errno = EBADF;
1053 testBuffer[0] = 'x';
1054 ret = p_wcsupr_s(testBuffer, 1);
1055 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1056 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1057 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
1058
1059 /* Test invalid size. */
1060 wcscpy(testBuffer, mixedString);
1061 errno = EBADF;
1062 ret = p_wcsupr_s(testBuffer, 0);
1063 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1064 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1065 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
1066
1067 /* Test normal string uppercasing. */
1068 wcscpy(testBuffer, mixedString);
1069 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
1070 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
1071 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
1072
1073 /* Test uppercasing with a shorter buffer size count. */
1074 wcscpy(testBuffer, mixedString);
1075 errno = EBADF;
1076 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
1077 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
1078 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1079 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
1080
1081 /* Test uppercasing with a longer buffer size count. */
1082 wcscpy(testBuffer, mixedString);
1083 ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
1084 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
1085 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
1086 }
1087
1088 static void test__wcslwr_s(void)
1089 {
1090 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
1091 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
1092 static const WCHAR expectedString[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
1093 'w', 'e', 'r', 'u', 'p', 'p', 'e',
1094 'r', 0};
1095 WCHAR buffer[2*sizeof(mixedString)/sizeof(WCHAR)];
1096 int ret;
1097
1098 if (!p_wcslwr_s)
1099 {
1100 win_skip("_wcslwr_s not found\n");
1101 return;
1102 }
1103
1104 /* Test NULL input string and invalid size. */
1105 errno = EBADF;
1106 ret = p_wcslwr_s(NULL, 0);
1107 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1108 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
1109
1110 /* Test NULL input string and valid size. */
1111 errno = EBADF;
1112 ret = p_wcslwr_s(NULL, sizeof(buffer)/sizeof(buffer[0]));
1113 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1114 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
1115
1116 /* Test empty string with zero size. */
1117 errno = EBADF;
1118 buffer[0] = 'a';
1119 ret = p_wcslwr_s(buffer, 0);
1120 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1121 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
1122 ok(buffer[0] == 0, "expected empty string\n");
1123
1124 /* Test empty string with size of one. */
1125 buffer[0] = 0;
1126 ret = p_wcslwr_s(buffer, 1);
1127 ok(ret == 0, "got %d\n", ret);
1128 ok(buffer[0] == 0, "expected buffer to be unchanged\n");
1129
1130 /* Test one-byte buffer with zero size. */
1131 errno = EBADF;
1132 buffer[0] = 'x';
1133 ret = p_wcslwr_s(buffer, 0);
1134 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1135 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1136 ok(buffer[0] == '\0', "expected empty string\n");
1137
1138 /* Test one-byte buffer with size of one. */
1139 errno = EBADF;
1140 buffer[0] = 'x';
1141 ret = p_wcslwr_s(buffer, 1);
1142 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1143 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1144 ok(buffer[0] == '\0', "expected empty string\n");
1145
1146 /* Test invalid size. */
1147 wcscpy(buffer, mixedString);
1148 errno = EBADF;
1149 ret = p_wcslwr_s(buffer, 0);
1150 ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
1151 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1152 ok(buffer[0] == '\0', "expected empty string\n");
1153
1154 /* Test normal string uppercasing. */
1155 wcscpy(buffer, mixedString);
1156 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR));
1157 ok(ret == 0, "expected 0, got %d\n", ret);
1158 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1159
1160 /* Test uppercasing with a shorter buffer size count. */
1161 wcscpy(buffer, mixedString);
1162 errno = EBADF;
1163 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
1164 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1165 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1166 ok(buffer[0] == '\0', "expected empty string\n");
1167
1168 /* Test uppercasing with a longer buffer size count. */
1169 wcscpy(buffer, mixedString);
1170 ret = p_wcslwr_s(buffer, sizeof(buffer)/sizeof(WCHAR));
1171 ok(ret == 0, "expected 0, got %d\n", ret);
1172 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1173 }
1174
1175 static void test_mbcjisjms(void)
1176 {
1177 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1178 unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1179 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1180 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1181 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1182 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1183 unsigned int i, j;
1184 int prev_cp = _getmbcp();
1185
1186 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1187 {
1188 _setmbcp(cp[i]);
1189 for (j = 0; jisjms[j][0] != 0; j++)
1190 {
1191 unsigned int ret, exp;
1192 ret = _mbcjistojms(jisjms[j][0]);
1193 exp = (cp[i] == 932) ? jisjms[j][1] : jisjms[j][0];
1194 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1195 exp, ret, jisjms[j][0], cp[i]);
1196 }
1197 }
1198 _setmbcp(prev_cp);
1199 }
1200
1201 static void test_mbcjmsjis(void)
1202 {
1203 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1204 unsigned int jmsjis[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1205 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1206 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1207 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1208 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1209 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1210 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1211 unsigned int i, j;
1212 int prev_cp = _getmbcp();
1213
1214 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1215 {
1216 _setmbcp(cp[i]);
1217 for (j = 0; jmsjis[j][0] != 0; j++)
1218 {
1219 unsigned int ret, exp;
1220 ret = _mbcjmstojis(jmsjis[j][0]);
1221 exp = (cp[i] == 932) ? jmsjis[j][1] : jmsjis[j][0];
1222 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1223 exp, ret, jmsjis[j][0], cp[i]);
1224 }
1225 }
1226 _setmbcp(prev_cp);
1227 }
1228
1229 static void test_mbctohira(void)
1230 {
1231 static const unsigned int mbchira_932[][2] = {
1232 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1233 {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd},
1234 {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394},
1235 {0x8396, 0x8396}, {0x8397, 0x8397},
1236 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1237 unsigned int i;
1238 unsigned int prev_cp = _getmbcp();
1239
1240 _setmbcp(_MB_CP_SBCS);
1241 for (i = 0; i < sizeof(mbchira_932)/sizeof(mbchira_932[0]); i++)
1242 {
1243 int ret, exp = mbchira_932[i][0];
1244 ret = _mbctohira(mbchira_932[i][0]);
1245 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1246 }
1247
1248 _setmbcp(932);
1249 for (i = 0; i < sizeof(mbchira_932)/sizeof(mbchira_932[0]); i++)
1250 {
1251 unsigned int ret, exp;
1252 ret = _mbctohira(mbchira_932[i][0]);
1253 exp = mbchira_932[i][1];
1254 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1255 }
1256 _setmbcp(prev_cp);
1257 }
1258
1259 static void test_mbctokata(void)
1260 {
1261 static const unsigned int mbckata_932[][2] = {
1262 {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155},
1263 {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f},
1264 {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397},
1265 {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} };
1266 unsigned int i;
1267 unsigned int prev_cp = _getmbcp();
1268
1269 _setmbcp(_MB_CP_SBCS);
1270 for (i = 0; i < sizeof(mbckata_932)/sizeof(mbckata_932[0]); i++)
1271 {
1272 int ret, exp = mbckata_932[i][0];
1273 ret = _mbctokata(mbckata_932[i][0]);
1274 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1275 }
1276
1277 _setmbcp(932);
1278 for (i = 0; i < sizeof(mbckata_932)/sizeof(mbckata_932[0]); i++)
1279 {
1280 unsigned int ret, exp;
1281 ret = _mbctokata(mbckata_932[i][0]);
1282 exp = mbckata_932[i][1];
1283 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1284 }
1285 _setmbcp(prev_cp);
1286 }
1287
1288 static void test_mbbtombc(void)
1289 {
1290 static const unsigned int mbbmbc[][2] = {
1291 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1292 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1293 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1294 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1295 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1296 int i, j;
1297 int prev_cp = _getmbcp();
1298
1299 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1300 {
1301 _setmbcp(cp[i]);
1302 for (j = 0; mbbmbc[j][0] != 0; j++)
1303 {
1304 unsigned int exp, ret;
1305 ret = _mbbtombc(mbbmbc[j][0]);
1306 exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0];
1307 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1308 exp, ret, mbbmbc[j][0], cp[i]);
1309 }
1310 }
1311 _setmbcp(prev_cp);
1312 }
1313
1314 static void test_mbctombb(void)
1315 {
1316 static const unsigned int mbcmbb_932[][2] = {
1317 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1318 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1319 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1320 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1321 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1322 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1323 unsigned int exp, ret, i;
1324 unsigned int prev_cp = _getmbcp();
1325
1326 _setmbcp(932);
1327 for (i = 0; mbcmbb_932[i][0] != 0; i++)
1328 {
1329 ret = _mbctombb(mbcmbb_932[i][0]);
1330 exp = mbcmbb_932[i][1];
1331 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1332 }
1333 _setmbcp(prev_cp);
1334 }
1335
1336 static void test_ismbckata(void) {
1337 struct katakana_pair {
1338 UINT c;
1339 BOOL exp;
1340 };
1341 static const struct katakana_pair tests[] = {
1342 {0x8152, FALSE}, {0x8153, FALSE}, {0x8154, FALSE}, {0x8155, FALSE},
1343 {0x82a0, FALSE}, {0x833f, FALSE}, {0x8340, TRUE }, {0x837e, TRUE },
1344 {0x837f, FALSE}, {0x8380, TRUE }, {0x8396, TRUE }, {0x8397, FALSE},
1345 {0xa5, FALSE}, {0xb0, FALSE}, {0xdd, FALSE}
1346 };
1347 unsigned int prev_cp = _getmbcp();
1348 int ret;
1349 unsigned int i;
1350
1351 _setmbcp(_MB_CP_SBCS);
1352 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
1353 ret = _ismbckata(tests[i].c);
1354 ok(!ret, "expected 0, got %d for %04x\n", ret, tests[i].c);
1355 }
1356
1357 _setmbcp(932);
1358 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
1359 ret = _ismbckata(tests[i].c);
1360 ok(!!ret == tests[i].exp, "expected %d, got %d for %04x\n",
1361 tests[i].exp, !!ret, tests[i].c);
1362 }
1363
1364 _setmbcp(prev_cp);
1365 }
1366
1367 static void test_ismbclegal(void) {
1368 unsigned int prev_cp = _getmbcp();
1369 int ret, exp, err;
1370 unsigned int i;
1371
1372 _setmbcp(932); /* Japanese */
1373 err = 0;
1374 for(i = 0; i < 0x10000; i++) {
1375 ret = _ismbclegal(i);
1376 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
1377 (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
1378 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1379 (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
1380 if(ret != exp) {
1381 err = 1;
1382 break;
1383 }
1384 }
1385 ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1386 _setmbcp(936); /* Chinese (GBK) */
1387 err = 0;
1388 for(i = 0; i < 0x10000; i++) {
1389 ret = _ismbclegal(i);
1390 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1391 LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
1392 if(ret != exp) {
1393 err = 1;
1394 break;
1395 }
1396 }
1397 ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1398 _setmbcp(949); /* Korean */
1399 err = 0;
1400 for(i = 0; i < 0x10000; i++) {
1401 ret = _ismbclegal(i);
1402 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1403 LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
1404 if(ret != exp) {
1405 err = 1;
1406 break;
1407 }
1408 }
1409 ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1410 _setmbcp(950); /* Chinese (Big5) */
1411 err = 0;
1412 for(i = 0; i < 0x10000; i++) {
1413 ret = _ismbclegal(i);
1414 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1415 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1416 (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
1417 if(ret != exp) {
1418 err = 1;
1419 break;
1420 }
1421 }
1422 ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1423 _setmbcp(1361); /* Korean (Johab) */
1424 err = 0;
1425 for(i = 0; i < 0x10000; i++) {
1426 ret = _ismbclegal(i);
1427 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
1428 (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
1429 ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
1430 (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
1431 HIBYTE(i) != 0xDF;
1432 if(ret != exp) {
1433 err = 1;
1434 break;
1435 }
1436 }
1437 todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1438
1439 _setmbcp(prev_cp);
1440 }
1441
1442 static const struct {
1443 const char* string;
1444 const char* delimiter;
1445 int exp_offsetret1; /* returned offset from string after first call to strtok()
1446 -1 means NULL */
1447 int exp_offsetret2; /* returned offset from string after second call to strtok()
1448 -1 means NULL */
1449 int exp_offsetret3; /* returned offset from string after third call to strtok()
1450 -1 means NULL */
1451 } testcases_strtok[] = {
1452 { "red cabernet", " ", 0, 4, -1 },
1453 { "sparkling white riesling", " ", 0, 10, 16 },
1454 { " pale cream sherry", "e ", 1, 6, 9 },
1455 /* end mark */
1456 { 0}
1457 };
1458
1459 static void test_strtok(void)
1460 {
1461 int i;
1462 char *strret;
1463 char teststr[100];
1464 for( i = 0; testcases_strtok[i].string; i++){
1465 strcpy( teststr, testcases_strtok[i].string);
1466 strret = strtok( teststr, testcases_strtok[i].delimiter);
1467 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
1468 (!strret && testcases_strtok[i].exp_offsetret1 == -1),
1469 "string (%p) \'%s\' return %p\n",
1470 teststr, testcases_strtok[i].string, strret);
1471 if( !strret) continue;
1472 strret = strtok( NULL, testcases_strtok[i].delimiter);
1473 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
1474 (!strret && testcases_strtok[i].exp_offsetret2 == -1),
1475 "second call string (%p) \'%s\' return %p\n",
1476 teststr, testcases_strtok[i].string, strret);
1477 if( !strret) continue;
1478 strret = strtok( NULL, testcases_strtok[i].delimiter);
1479 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
1480 (!strret && testcases_strtok[i].exp_offsetret3 == -1),
1481 "third call string (%p) \'%s\' return %p\n",
1482 teststr, testcases_strtok[i].string, strret);
1483 }
1484 }
1485
1486 static void test_strtol(void)
1487 {
1488 static char neg[] = "-0x";
1489
1490 char* e;
1491 LONG l;
1492 ULONG ul;
1493
1494 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1495 /* errno is modified on W2K8+ */
1496 errno = EBADF;
1497 l = strtol("-1234", &e, 0);
1498 ok(l==-1234, "wrong value %d\n", l);
1499 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1500 errno = EBADF;
1501 ul = strtoul("1234", &e, 0);
1502 ok(ul==1234, "wrong value %u\n", ul);
1503 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1504
1505 errno = EBADF;
1506 l = strtol("2147483647L", &e, 0);
1507 ok(l==2147483647, "wrong value %d\n", l);
1508 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1509 errno = EBADF;
1510 l = strtol("-2147483648L", &e, 0);
1511 ok(l==-2147483647L - 1, "wrong value %d\n", l);
1512 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1513 errno = EBADF;
1514 ul = strtoul("4294967295UL", &e, 0);
1515 ok(ul==4294967295ul, "wrong value %u\n", ul);
1516 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1517
1518 errno = 0;
1519 l = strtol("9223372036854775807L", &e, 0);
1520 ok(l==2147483647, "wrong value %d\n", l);
1521 ok(errno == ERANGE, "wrong errno %d\n", errno);
1522 errno = 0;
1523 ul = strtoul("9223372036854775807L", &e, 0);
1524 ok(ul==4294967295ul, "wrong value %u\n", ul);
1525 ok(errno == ERANGE, "wrong errno %d\n", errno);
1526
1527 errno = 0;
1528 ul = strtoul("-2", NULL, 0);
1529 ok(ul == -2, "wrong value %u\n", ul);
1530 ok(errno == 0, "wrong errno %d\n", errno);
1531
1532 errno = 0;
1533 ul = strtoul("-4294967294", NULL, 0);
1534 ok(ul == 2, "wrong value %u\n", ul);
1535 ok(errno == 0, "wrong errno %d\n", errno);
1536
1537 errno = 0;
1538 ul = strtoul("-4294967295", NULL, 0);
1539 ok(ul==1, "wrong value %u\n", ul);
1540 ok(errno == 0, "wrong errno %d\n", errno);
1541
1542 errno = 0;
1543 ul = strtoul("-4294967296", NULL, 0);
1544 ok(ul == 1, "wrong value %u\n", ul);
1545 ok(errno == ERANGE, "wrong errno %d\n", errno);
1546
1547 errno = 0;
1548 l = strtol(neg, &e, 0);
1549 ok(l == 0, "wrong value %d\n", l);
1550 ok(errno == 0, "wrong errno %d\n", errno);
1551 ok(e == neg, "e = %p, neg = %p\n", e, neg);
1552 }
1553
1554 static void test_strnlen(void)
1555 {
1556 static const char str[] = "string";
1557 size_t res;
1558
1559 if(!p_strnlen) {
1560 win_skip("strnlen not found\n");
1561 return;
1562 }
1563
1564 res = p_strnlen(str, 20);
1565 ok(res == 6, "Returned length = %d\n", (int)res);
1566
1567 res = p_strnlen(str, 3);
1568 ok(res == 3, "Returned length = %d\n", (int)res);
1569
1570 res = p_strnlen(NULL, 0);
1571 ok(res == 0, "Returned length = %d\n", (int)res);
1572 }
1573
1574 static void test__strtoi64(void)
1575 {
1576 static const char no1[] = "31923";
1577 static const char no2[] = "-213312";
1578 static const char no3[] = "12aa";
1579 static const char no4[] = "abc12";
1580 static const char overflow[] = "99999999999999999999";
1581 static const char neg_overflow[] = "-99999999999999999999";
1582 static const char hex[] = "0x123";
1583 static const char oct[] = "000123";
1584 static const char blanks[] = " 12 212.31";
1585
1586 __int64 res;
1587 unsigned __int64 ures;
1588 char *endpos;
1589
1590 if(!p_strtoi64 || !p_strtoui64) {
1591 win_skip("_strtoi64 or _strtoui64 not found\n");
1592 return;
1593 }
1594
1595 errno = 0xdeadbeef;
1596 res = p_strtoi64(no1, NULL, 10);
1597 ok(res == 31923, "res != 31923\n");
1598 res = p_strtoi64(no2, NULL, 10);
1599 ok(res == -213312, "res != -213312\n");
1600 res = p_strtoi64(no3, NULL, 10);
1601 ok(res == 12, "res != 12\n");
1602 res = p_strtoi64(no4, &endpos, 10);
1603 ok(res == 0, "res != 0\n");
1604 ok(endpos == no4, "Scanning was not stopped on first character\n");
1605 res = p_strtoi64(hex, &endpos, 10);
1606 ok(res == 0, "res != 0\n");
1607 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1608 res = p_strtoi64(oct, &endpos, 10);
1609 ok(res == 123, "res != 123\n");
1610 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1611 res = p_strtoi64(blanks, &endpos, 10);
1612 ok(res == 12, "res != 12\n");
1613 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1614 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1615
1616 errno = 0xdeadbeef;
1617 res = p_strtoi64(overflow, &endpos, 10);
1618 ok(res == _I64_MAX, "res != _I64_MAX\n");
1619 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1620 ok(errno == ERANGE, "errno = %x\n", errno);
1621
1622 errno = 0xdeadbeef;
1623 res = p_strtoi64(neg_overflow, &endpos, 10);
1624 ok(res == _I64_MIN, "res != _I64_MIN\n");
1625 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1626 ok(errno == ERANGE, "errno = %x\n", errno);
1627
1628 errno = 0xdeadbeef;
1629 res = p_strtoi64(no1, &endpos, 16);
1630 ok(res == 203043, "res != 203043\n");
1631 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1632 res = p_strtoi64(no2, &endpos, 16);
1633 ok(res == -2175762, "res != -2175762\n");
1634 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1635 res = p_strtoi64(no3, &endpos, 16);
1636 ok(res == 4778, "res != 4778\n");
1637 ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
1638 res = p_strtoi64(no4, &endpos, 16);
1639 ok(res == 703506, "res != 703506\n");
1640 ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
1641 res = p_strtoi64(hex, &endpos, 16);
1642 ok(res == 291, "res != 291\n");
1643 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1644 res = p_strtoi64(oct, &endpos, 16);
1645 ok(res == 291, "res != 291\n");
1646 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1647 res = p_strtoi64(blanks, &endpos, 16);
1648 ok(res == 18, "res != 18\n");
1649 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1650 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1651
1652 errno = 0xdeadbeef;
1653 res = p_strtoi64(hex, &endpos, 36);
1654 ok(res == 1541019, "res != 1541019\n");
1655 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1656 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1657
1658 errno = 0xdeadbeef;
1659 res = p_strtoi64(no1, &endpos, 0);
1660 ok(res == 31923, "res != 31923\n");
1661 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1662 res = p_strtoi64(no2, &endpos, 0);
1663 ok(res == -213312, "res != -213312\n");
1664 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1665 res = p_strtoi64(no3, &endpos, 10);
1666 ok(res == 12, "res != 12\n");
1667 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1668 res = p_strtoi64(no4, &endpos, 10);
1669 ok(res == 0, "res != 0\n");
1670 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1671 res = p_strtoi64(hex, &endpos, 10);
1672 ok(res == 0, "res != 0\n");
1673 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1674 res = p_strtoi64(oct, &endpos, 10);
1675 ok(res == 123, "res != 123\n");
1676 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1677 res = p_strtoi64(blanks, &endpos, 10);
1678 ok(res == 12, "res != 12\n");
1679 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1680 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1681
1682 errno = 0xdeadbeef;
1683 ures = p_strtoui64(no1, &endpos, 0);
1684 ok(ures == 31923, "ures != 31923\n");
1685 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1686 ures = p_strtoui64(no2, &endpos, 0);
1687 ok(ures == -213312, "ures != -213312\n");
1688 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1689 ures = p_strtoui64(no3, &endpos, 10);
1690 ok(ures == 12, "ures != 12\n");
1691 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1692 ures = p_strtoui64(no4, &endpos, 10);
1693 ok(ures == 0, "ures != 0\n");
1694 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1695 ures = p_strtoui64(hex, &endpos, 10);
1696 ok(ures == 0, "ures != 0\n");
1697 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1698 ures = p_strtoui64(oct, &endpos, 10);
1699 ok(ures == 123, "ures != 123\n");
1700 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1701 ures = p_strtoui64(blanks, &endpos, 10);
1702 ok(ures == 12, "ures != 12\n");
1703 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1704 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1705
1706 errno = 0xdeadbeef;
1707 ures = p_strtoui64(overflow, &endpos, 10);
1708 ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
1709 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1710 ok(errno == ERANGE, "errno = %x\n", errno);
1711
1712 errno = 0xdeadbeef;
1713 ures = p_strtoui64(neg_overflow, &endpos, 10);
1714 ok(ures == 1, "ures != 1\n");
1715 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1716 ok(errno == ERANGE, "errno = %x\n", errno);
1717 }
1718
1719 static inline BOOL almost_equal(double d1, double d2) {
1720 if(d1-d2>-1e-30 && d1-d2<1e-30)
1721 return TRUE;
1722 return FALSE;
1723 }
1724
1725 static void test__strtod(void)
1726 {
1727 const char double1[] = "12.1";
1728 const char double2[] = "-13.721";
1729 const char double3[] = "INF";
1730 const char double4[] = ".21e12";
1731 const char double5[] = "214353e-3";
1732 const char double6[] = "NAN";
1733 const char overflow[] = "1d9999999999999999999";
1734 const char white_chars[] = " d10";
1735
1736 char *end;
1737 double d;
1738
1739 d = strtod(double1, &end);
1740 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1741 ok(end == double1+4, "incorrect end (%d)\n", (int)(end-double1));
1742
1743 d = strtod(double2, &end);
1744 ok(almost_equal(d, -13.721), "d = %lf\n", d);
1745 ok(end == double2+7, "incorrect end (%d)\n", (int)(end-double2));
1746
1747 d = strtod(double3, &end);
1748 ok(almost_equal(d, 0), "d = %lf\n", d);
1749 ok(end == double3, "incorrect end (%d)\n", (int)(end-double3));
1750
1751 d = strtod(double4, &end);
1752 ok(almost_equal(d, 210000000000.0), "d = %lf\n", d);
1753 ok(end == double4+6, "incorrect end (%d)\n", (int)(end-double4));
1754
1755 d = strtod(double5, &end);
1756 ok(almost_equal(d, 214.353), "d = %lf\n", d);
1757 ok(end == double5+9, "incorrect end (%d)\n", (int)(end-double5));
1758
1759 d = strtod(double6, &end);
1760 ok(almost_equal(d, 0), "d = %lf\n", d);
1761 ok(end == double6, "incorrect end (%d)\n", (int)(end-double6));
1762
1763 d = strtod("12.1d2", NULL);
1764 ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
1765
1766 d = strtod(white_chars, &end);
1767 ok(almost_equal(d, 0), "d = %lf\n", d);
1768 ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
1769
1770 if (!p__strtod_l)
1771 win_skip("_strtod_l not found\n");
1772 else
1773 {
1774 errno = EBADF;
1775 d = strtod(NULL, NULL);
1776 ok(almost_equal(d, 0.0), "d = %lf\n", d);
1777 ok(errno == EINVAL, "errno = %x\n", errno);
1778
1779 errno = EBADF;
1780 end = (char *)0xdeadbeef;
1781 d = strtod(NULL, &end);
1782 ok(almost_equal(d, 0.0), "d = %lf\n", d);
1783 ok(errno == EINVAL, "errno = %x\n", errno);
1784 ok(!end, "incorrect end ptr %p\n", end);
1785
1786 errno = EBADF;
1787 d = p__strtod_l(NULL, NULL, NULL);
1788 ok(almost_equal(d, 0.0), "d = %lf\n", d);
1789 ok(errno == EINVAL, "errno = %x\n", errno);
1790 }
1791
1792 /* Set locale with non '.' decimal point (',') */
1793 if(!setlocale(LC_ALL, "Polish")) {
1794 win_skip("system with limited locales\n");
1795 return;
1796 }
1797
1798 d = strtod("12.1", NULL);
1799 ok(almost_equal(d, 12.0), "d = %lf\n", d);
1800
1801 d = strtod("12,1", NULL);
1802 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1803
1804 setlocale(LC_ALL, "C");
1805
1806 /* Precision tests */
1807 d = strtod("0.1", NULL);
1808 ok(almost_equal(d, 0.1), "d = %lf\n", d);
1809 d = strtod("-0.1", NULL);
1810 ok(almost_equal(d, -0.1), "d = %lf\n", d);
1811 d = strtod("0.1281832188491894198128921", NULL);
1812 ok(almost_equal(d, 0.1281832188491894198128921), "d = %lf\n", d);
1813 d = strtod("0.82181281288121", NULL);
1814 ok(almost_equal(d, 0.82181281288121), "d = %lf\n", d);
1815 d = strtod("21921922352523587651128218821", NULL);
1816 ok(almost_equal(d, 21921922352523587651128218821.0), "d = %lf\n", d);
1817 d = strtod("0.1d238", NULL);
1818 ok(almost_equal(d, 0.1e238L), "d = %lf\n", d);
1819 d = strtod("0.1D-4736", NULL);
1820 ok(almost_equal(d, 0.1e-4736L), "d = %lf\n", d);
1821
1822 errno = 0xdeadbeef;
1823 strtod(overflow, &end);
1824 ok(errno == ERANGE, "errno = %x\n", errno);
1825 ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
1826
1827 errno = 0xdeadbeef;
1828 strtod("-1d309", NULL);
1829 ok(errno == ERANGE, "errno = %x\n", errno);
1830 }
1831
1832 static void test_mbstowcs(void)
1833 {
1834 static const wchar_t wSimple[] = { 't','e','x','t',0 };
1835 static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
1836 static const char mSimple[] = "text";
1837 static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
1838
1839 const wchar_t *pwstr;
1840 wchar_t wOut[6];
1841 char mOut[6];
1842 size_t ret;
1843 int err;
1844 const char *pmbstr;
1845 mbstate_t state;
1846
1847 wOut[4] = '!'; wOut[5] = '\0';
1848 mOut[4] = '!'; mOut[5] = '\0';
1849
1850 if(pmbstowcs_s) {
1851 /* crashes on some systems */
1852 errno = 0xdeadbeef;
1853 ret = mbstowcs(wOut, NULL, 4);
1854 ok(ret == -1, "mbstowcs did not return -1\n");
1855 ok(errno == EINVAL, "errno = %d\n", errno);
1856 }
1857
1858 ret = mbstowcs(NULL, mSimple, 0);
1859 ok(ret == 4, "mbstowcs did not return 4\n");
1860
1861 ret = mbstowcs(wOut, mSimple, 4);
1862 ok(ret == 4, "mbstowcs did not return 4\n");
1863 ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
1864 ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
1865
1866 ret = wcstombs(NULL, wSimple, 0);
1867 ok(ret == 4, "wcstombs did not return 4\n");
1868
1869 ret = wcstombs(mOut, wSimple, 6);
1870 ok(ret == 4, "wcstombs did not return 4\n");
1871 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1872
1873 ret = wcstombs(mOut, wSimple, 2);
1874 ok(ret == 2, "wcstombs did not return 2\n");
1875 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1876
1877 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
1878 win_skip("Japanese_Japan.932 locale not available\n");
1879 return;
1880 }
1881
1882 ret = mbstowcs(wOut, mHiragana, 6);
1883 ok(ret == 2, "mbstowcs did not return 2\n");
1884 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1885
1886 ret = wcstombs(mOut, wHiragana, 6);
1887 ok(ret == 4, "wcstombs did not return 4\n");
1888 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1889
1890 if(!pmbstowcs_s || !pwcstombs_s) {
1891 setlocale(LC_ALL, "C");
1892 win_skip("mbstowcs_s or wcstombs_s not available\n");
1893 return;
1894 }
1895
1896 err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
1897 ok(err == 0, "err = %d\n", err);
1898 ok(ret == 5, "mbstowcs_s did not return 5\n");
1899 ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
1900
1901 err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
1902 ok(err == 0, "err = %d\n", err);
1903 ok(ret == 3, "mbstowcs_s did not return 3\n");
1904 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1905
1906 err = pmbstowcs_s(&ret, NULL, 0, mHiragana, 1);
1907 ok(err == 0, "err = %d\n", err);
1908 ok(ret == 3, "mbstowcs_s did not return 3\n");
1909
1910 err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
1911 ok(err == 0, "err = %d\n", err);
1912 ok(ret == 5, "wcstombs_s did not return 5\n");
1913 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1914
1915 err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
1916 ok(err == 0, "err = %d\n", err);
1917 ok(ret == 5, "wcstombs_s did not return 5\n");
1918 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1919
1920 err = pwcstombs_s(&ret, NULL, 0, wHiragana, 1);
1921 ok(err == 0, "err = %d\n", err);
1922 ok(ret == 5, "wcstombs_s did not return 5\n");
1923
1924 if(!pwcsrtombs) {
1925 setlocale(LC_ALL, "C");
1926 win_skip("wcsrtombs not available\n");
1927 return;
1928 }
1929
1930 pwstr = wSimple;
1931 err = -3;
1932 ret = pwcsrtombs(mOut, &pwstr, 4, &err);
1933 ok(ret == 4, "wcsrtombs did not return 4\n");
1934 ok(err == 0, "err = %d\n", err);
1935 ok(pwstr == wSimple+4, "pwstr = %p (wszSimple = %p)\n", pwstr, wSimple);
1936 ok(!memcmp(mOut, mSimple, ret), "mOut = %s\n", mOut);
1937
1938 pwstr = wSimple;
1939 ret = pwcsrtombs(mOut, &pwstr, 5, NULL);
1940 ok(ret == 4, "wcsrtombs did not return 4\n");
1941 ok(pwstr == NULL, "pwstr != NULL\n");
1942 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1943
1944 if(!p_mbsrtowcs) {
1945 setlocale(LC_ALL, "C");
1946 win_skip("mbsrtowcs not available\n");
1947 return;
1948 }
1949
1950 pmbstr = mHiragana;
1951 ret = p_mbsrtowcs(NULL, &pmbstr, 6, NULL);
1952 ok(ret == 2, "mbsrtowcs did not return 2\n");
1953 ok(pmbstr == mHiragana, "pmbstr = %p, expected %p\n", pmbstr, mHiragana);
1954
1955 pmbstr = mHiragana;
1956 ret = p_mbsrtowcs(wOut, &pmbstr, 6, NULL);
1957 ok(ret == 2, "mbsrtowcs did not return 2\n");
1958 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1959 ok(!pmbstr, "pmbstr != NULL\n");
1960
1961 state = mHiragana[0];
1962 pmbstr = mHiragana+1;
1963 ret = p_mbsrtowcs(wOut, &pmbstr, 6, &state);
1964 ok(ret == 2, "mbsrtowcs did not return 2\n");
1965 ok(wOut[0] == 0x3042, "wOut[0] = %x\n", wOut[0]);
1966 ok(wOut[1] == 0xff61, "wOut[1] = %x\n", wOut[1]);
1967 ok(wOut[2] == 0, "wOut[2] = %x\n", wOut[2]);
1968 ok(!pmbstr, "pmbstr != NULL\n");
1969
1970 errno = EBADF;
1971 ret = p_mbsrtowcs(wOut, NULL, 6, &state);
1972 ok(ret == -1, "mbsrtowcs did not return -1\n");
1973 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1974
1975 if(!p_mbsrtowcs_s) {
1976 setlocale(LC_ALL, "C");
1977 win_skip("mbsrtowcs_s not available\n");
1978 return;
1979 }
1980
1981 pmbstr = mHiragana;
1982 err = p_mbsrtowcs_s(&ret, NULL, 0, NULL, 6, NULL);
1983 ok(ret == -1, "mbsrtowcs_s did not return -1\n");
1984 ok(err == EINVAL, "err = %d\n", err);
1985 err = p_mbsrtowcs_s(&ret, NULL, 1, &pmbstr, 6, NULL);
1986 ok(ret == -1, "mbsrtowcs_s did not return -1\n");
1987 ok(err == EINVAL, "err = %d\n", err);
1988 err = p_mbsrtowcs_s(&ret, wOut, 0, &pmbstr, 6, NULL);
1989 ok(ret == -1, "mbsrtowcs_s did not return -1\n");
1990 ok(err == EINVAL, "err = %d\n", err);
1991
1992 pmbstr = mHiragana;
1993 errno = 0;
1994 err = p_mbsrtowcs_s(&ret, NULL, 0, &pmbstr, 6, NULL);
1995 ok(ret == 3, "mbsrtowcs_s did not return 3\n");
1996 ok(err == 0, "err = %d\n", err);
1997 ok(pmbstr == mHiragana, "pmbstr = %p, expected %p\n", pmbstr, mHiragana);
1998 ok(errno == 0, "errno = %d\n", errno);
1999
2000 pmbstr = mHiragana;
2001 err = p_mbsrtowcs_s(&ret, wOut, 1, &pmbstr, 6, NULL);
2002 ok(ret == 2, "mbsrtowcs_s did not return 2\n");
2003 ok(err == 0, "err = %d\n", err);
2004 ok(!wOut[0], "wOut[0] = '%c'\n", wOut[0]);
2005 ok(pmbstr == mHiragana+2, "pmbstr = %p, expected %p\n", pmbstr, mHiragana+2);
2006 ok(errno == 0, "errno = %d\n", errno);
2007
2008 pmbstr = mHiragana;
2009 err = p_mbsrtowcs_s(&ret, wOut, 2, &pmbstr, 6, NULL);
2010 ok(ret == 3, "mbsrtowcs_s did not return 3\n");
2011 ok(err == 0, "err = %d\n", err);
2012 ok(!wOut[0], "wOut[0] = '%c'\n", wOut[0]);
2013 ok(pmbstr == mHiragana+4, "pmbstr = %p, expected %p\n", pmbstr, mHiragana+4);
2014 ok(errno == 0, "errno = %d\n", errno);
2015
2016 pmbstr = mHiragana;
2017 err = p_mbsrtowcs_s(&ret, wOut, 3, &pmbstr, 6, NULL);
2018 ok(ret == 3, "mbsrtowcs_s did not return 3\n");
2019 ok(err == 0, "err = %d\n", err);
2020 ok(!pmbstr, "pmbstr != NULL\n");
2021 ok(errno == 0, "errno = %d\n", errno);
2022
2023 setlocale(LC_ALL, "C");
2024 }
2025
2026 static void test_gcvt(void)
2027 {
2028 char buf[1024], *res;
2029 errno_t err;
2030
2031 if(!p_gcvt_s) {
2032 win_skip("Skipping _gcvt tests\n");
2033 return;
2034 }
2035
2036 errno = 0;
2037 res = _gcvt(1.2, -1, buf);
2038 ok(res == NULL, "res != NULL\n");
2039 ok(errno == ERANGE, "errno = %d\n", errno);
2040
2041 errno = 0;
2042 res = _gcvt(1.2, 5, NULL);
2043 ok(res == NULL, "res != NULL\n");
2044 ok(errno == EINVAL, "errno = %d\n", errno);
2045
2046 res = gcvt(1.2, 5, buf);
2047 ok(res == buf, "res != buf\n");
2048 ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
2049
2050 buf[0] = 'x';
2051 err = p_gcvt_s(buf, 5, 1.2, 10);
2052 ok(err == ERANGE, "err = %d\n", err);
2053 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
2054
2055 buf[0] = 'x';
2056 err = p_gcvt_s(buf, 4, 123456, 2);
2057 ok(err == ERANGE, "err = %d\n", err);
2058 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
2059 }
2060
2061 static void test__itoa_s(void)
2062 {
2063 errno_t ret;
2064 char buffer[33];
2065
2066 if (!p_itoa_s)
2067 {
2068 win_skip("Skipping _itoa_s tests\n");
2069 return;
2070 }
2071
2072 errno = EBADF;
2073 ret = p_itoa_s(0, NULL, 0, 0);
2074 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
2075 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2076
2077 memset(buffer, 'X', sizeof(buffer));
2078 errno = EBADF;
2079 ret = p_itoa_s(0, buffer, 0, 0);
2080 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
2081 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2082 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
2083
2084 memset(buffer, 'X', sizeof(buffer));
2085 errno = EBADF;
2086 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
2087 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
2088 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2089 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2090
2091 memset(buffer, 'X', sizeof(buffer));
2092 errno = EBADF;
2093 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
2094 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
2095 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2096 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2097
2098 memset(buffer, 'X', sizeof(buffer));
2099 errno = EBADF;
2100 ret = p_itoa_s(12345678, buffer, 4, 10);
2101 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
2102 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2103 ok(!memcmp(buffer, "\000765", 4),
2104 "Expected the output buffer to be null terminated with truncated output\n");
2105
2106 memset(buffer, 'X', sizeof(buffer));
2107 errno = EBADF;
2108 ret = p_itoa_s(12345678, buffer, 8, 10);
2109 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
2110 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2111 ok(!memcmp(buffer, "\0007654321", 8),
2112 "Expected the output buffer to be null terminated with truncated output\n");
2113
2114 memset(buffer, 'X', sizeof(buffer));
2115 errno = EBADF;
2116 ret = p_itoa_s(-12345678, buffer, 9, 10);
2117 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
2118 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2119 ok(!memcmp(buffer, "\00087654321", 9),
2120 "Expected the output buffer to be null terminated with truncated output\n");
2121
2122 ret = p_itoa_s(12345678, buffer, 9, 10);
2123 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
2124 ok(!strcmp(buffer, "12345678"),
2125 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2126 buffer);
2127
2128 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
2129 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
2130 ok(!strcmp(buffer, "1010101010101010"),
2131 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2132 buffer);
2133
2134 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
2135 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
2136 ok(!strcmp(buffer, "nell"),
2137 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2138 buffer);
2139
2140 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
2141 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
2142 ok(!strcmp(buffer, "hag"),
2143 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2144 buffer);
2145
2146 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
2147 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
2148 ok(!strcmp(buffer, "-12345678"),
2149 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
2150 buffer);
2151
2152 itoa(100, buffer, 100);
2153 ok(!strcmp(buffer, "10"),
2154 "Expected output buffer string to be \"10\", got \"%s\"\n", buffer);
2155 }
2156
2157 static void test__strlwr_s(void)
2158 {
2159 errno_t ret;
2160 char buffer[20];
2161
2162 if (!p_strlwr_s)
2163 {
2164 win_skip("Skipping _strlwr_s tests\n");
2165 return;
2166 }
2167
2168 errno = EBADF;
2169 ret = p_strlwr_s(NULL, 0);
2170 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
2171 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2172
2173 errno = EBADF;
2174 ret = p_strlwr_s(NULL, sizeof(buffer));
2175 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
2176 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2177
2178 errno = EBADF;
2179 ret = p_strlwr_s(buffer, 0);
2180 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
2181 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2182
2183 strcpy(buffer, "GoRrIsTeR");
2184 errno = EBADF;
2185 ret = p_strlwr_s(buffer, 5);
2186 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
2187 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2188 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2189 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2190
2191 strcpy(buffer, "GoRrIsTeR");
2192 errno = EBADF;
2193 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
2194 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
2195 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2196 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
2197 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
2198
2199 strcpy(buffer, "GoRrIsTeR");
2200 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
2201 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
2202 ok(!strcmp(buffer, "gorrister"),
2203 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
2204 buffer);
2205
2206 memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
2207 ret = p_strlwr_s(buffer, sizeof(buffer));
2208 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
2209 ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
2210 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
2211 buffer);
2212 }
2213
2214 static void test_wcsncat_s(void)
2215 {
2216 static wchar_t abcW[] = {'a','b','c',0};
2217 int ret;
2218 wchar_t dst[4];
2219 wchar_t src[4];
2220
2221 if (!p_wcsncat_s)
2222 {
2223 win_skip("skipping wcsncat_s tests\n");
2224 return;
2225 }
2226
2227 memcpy(src, abcW, sizeof(abcW));
2228 dst[0] = 0;
2229 ret = p_wcsncat_s(NULL, 4, src, 4);
2230 ok(ret == EINVAL, "err = %d\n", ret);
2231 ret = p_wcsncat_s(dst, 0, src, 4);
2232 ok(ret == EINVAL, "err = %d\n", ret);
2233 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
2234 ok(ret == EINVAL, "err = %d\n", ret);
2235 ret = p_wcsncat_s(dst, 4, NULL, 0);
2236 ok(ret == 0, "err = %d\n", ret);
2237
2238 dst[0] = 0;
2239 ret = p_wcsncat_s(dst, 2, src, 4);
2240 ok(ret == ERANGE, "err = %d\n", ret);
2241
2242 dst[0] = 0;
2243 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
2244 ok(ret == STRUNCATE, "err = %d\n", ret);
2245 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
2246
2247 memcpy(dst, abcW, sizeof(abcW));
2248 dst[3] = 'd';
2249 ret = p_wcsncat_s(dst, 4, src, 4);
2250 ok(ret == EINVAL, "err = %d\n", ret);
2251 }
2252
2253 static void test__mbsnbcat_s(void)
2254 {
2255 unsigned char dest[16];
2256 const unsigned char first[] = "dinosaur";
2257 const unsigned char second[] = "duck";
2258 int ret;
2259
2260 if (!p_mbsnbcat_s)
2261 {
2262 win_skip("Skipping _mbsnbcat_s tests\n");
2263 return;
2264 }
2265
2266 /* Test invalid arguments. */
2267 ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
2268 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2269
2270 errno = EBADF;
2271 ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
2272 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2273 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2274
2275 errno = EBADF;
2276 ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
2277 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2278 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2279
2280 memset(dest, 'X', sizeof(dest));
2281 errno = EBADF;
2282 ret = p_mbsnbcat_s(dest, 0, NULL, 0);
2283 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2284 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2285 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
2286
2287 memset(dest, 'X', sizeof(dest));
2288 errno = EBADF;
2289 ret = p_mbsnbcat_s(dest, 0, second, 0);
2290 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2291 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2292 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
2293
2294 memset(dest, 'X', sizeof(dest));
2295 errno = EBADF;
2296 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
2297 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2298 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2299 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
2300
2301 memset(dest, 'X', sizeof(dest));
2302 errno = EBADF;
2303 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
2304 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2305 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2306 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
2307
2308 memset(dest, 'X', sizeof(dest));
2309 dest[0] = '\0';
2310 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
2311 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2312 ok(!memcmp(dest, second, sizeof(second)),
2313 "Expected the output buffer string to be \"duck\"\n");
2314
2315 /* Test source truncation behavior. */
2316 memset(dest, 'X', sizeof(dest));
2317 memcpy(dest, first, sizeof(first));
2318 ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
2319 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2320 ok(!memcmp(dest, first, sizeof(first)),
2321 "Expected the output buffer string to be \"dinosaur\"\n");
2322
2323 memset(dest, 'X', sizeof(dest));
2324 memcpy(dest, first, sizeof(first));
2325 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
2326 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2327 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
2328 "Expected the output buffer string to be \"dinosaurduck\"\n");
2329
2330 memset(dest, 'X', sizeof(dest));
2331 memcpy(dest, first, sizeof(first));
2332 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
2333 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2334 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
2335 "Expected the output buffer string to be \"dinosaurduck\"\n");
2336
2337 memset(dest, 'X', sizeof(dest));
2338 memcpy(dest, first, sizeof(first));
2339 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
2340 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2341 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
2342 "Expected the output buffer string to be \"dinosaurduck\"\n");
2343
2344 memset(dest, 'X', sizeof(dest));
2345 memcpy(dest, first, sizeof(first));
2346 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
2347 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
2348 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
2349 "Expected the output buffer string to be \"dinosaurduc\"\n");
2350
2351 /* Test destination truncation behavior. */
2352 memset(dest, 'X', sizeof(dest));
2353 memcpy(dest, first, sizeof(first));
2354 errno = EBADF;
2355 ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
2356 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
2357 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2358 ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
2359 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
2360
2361 memset(dest, 'X', sizeof(dest));
2362 memcpy(dest, first, sizeof(first));
2363 errno = EBADF;
2364 ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
2365 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
2366 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2367 ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
2368 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
2369
2370 memset(dest, 'X', sizeof(dest));
2371 memcpy(dest, first, sizeof(first));
2372 errno = EBADF;
2373 ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
2374 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
2375 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2376 ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2377 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2378 }
2379
2380 static void test__mbsupr_s(void)
2381 {
2382 errno_t ret;
2383 unsigned char buffer[20];
2384
2385 if (!p_mbsupr_s)
2386 {
2387 win_skip("Skipping _mbsupr_s tests\n");
2388 return;
2389 }
2390
2391 errno = EBADF;
2392 ret = p_mbsupr_s(NULL, 0);
2393 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2394
2395 errno = EBADF;
2396 ret = p_mbsupr_s(NULL, sizeof(buffer));
2397 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2398 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2399
2400 errno = EBADF;
2401 ret = p_mbsupr_s(buffer, 0);
2402 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2403 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2404
2405 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2406 errno = EBADF;
2407 ret = p_mbsupr_s(buffer, sizeof("abcdefgh"));
2408 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2409 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2410 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2411 buffer);
2412
2413 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2414 errno = EBADF;
2415 ret = p_mbsupr_s(buffer, sizeof(buffer));
2416 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2417 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2418 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2419 buffer);
2420
2421 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2422 errno = EBADF;
2423 ret = p_mbsupr_s(buffer, 4);
2424 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2425 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2426
2427 memcpy(buffer, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2428 errno = EBADF;
2429 ret = p_mbsupr_s(buffer, sizeof(buffer));
2430 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2431 ok(!memcmp(buffer, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2432 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2433 buffer);
2434
2435 }
2436
2437 static void test__mbslwr_s(void)
2438 {
2439 errno_t ret;
2440 unsigned char buffer[20];
2441
2442 if (!p_mbslwr_s)
2443 {
2444 win_skip("Skipping _mbslwr_s tests\n");
2445 return;
2446 }
2447
2448 errno = EBADF;
2449 ret = p_mbslwr_s(NULL, 0);
2450 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2451
2452 errno = EBADF;
2453 ret = p_mbslwr_s(NULL, sizeof(buffer));
2454 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2455 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2456
2457 errno = EBADF;
2458 ret = p_mbslwr_s(buffer, 0);
2459 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2460 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2461
2462 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2463 errno = EBADF;
2464 ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH"));
2465 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2466 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2467 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2468 buffer);
2469
2470 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2471 errno = EBADF;
2472 ret = p_mbslwr_s(buffer, sizeof(buffer));
2473 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2474 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2475 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2476 buffer);
2477
2478 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2479 errno = EBADF;
2480 ret = p_mbslwr_s(buffer, 4);
2481 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2482 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2483
2484 memcpy(buffer, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2485 errno = EBADF;
2486 ret = p_mbslwr_s(buffer, sizeof(buffer));
2487 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2488 ok(!memcmp(buffer, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2489 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2490 buffer);
2491 }
2492
2493 static void test__mbstok(void)
2494 {
2495 const unsigned char delim[] = "t";
2496
2497 char str[] = "!.!test";
2498 unsigned char *ret;
2499
2500 strtok(str, "!");
2501
2502 ret = _mbstok(NULL, delim);
2503 /* most versions of msvcrt use the same buffer for strtok and _mbstok */
2504 ok(!ret || broken((char*)ret==str+4),
2505 "_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret, str);
2506
2507 ret = _mbstok(NULL, delim);
2508 ok(!ret, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret);
2509 }
2510
2511 static void test__ultoa_s(void)
2512 {
2513 errno_t ret;
2514 char buffer[33];
2515
2516 if (!p_ultoa_s)
2517 {
2518 win_skip("Skipping _ultoa_s tests\n");
2519 return;
2520 }
2521
2522 errno = EBADF;
2523 ret = p_ultoa_s(0, NULL, 0, 0);
2524 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2525 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2526
2527 memset(buffer, 'X', sizeof(buffer));
2528 errno = EBADF;
2529 ret = p_ultoa_s(0, buffer, 0, 0);
2530 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2531 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2532 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
2533
2534 memset(buffer, 'X', sizeof(buffer));
2535 errno = EBADF;
2536 ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
2537 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2538 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2539 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2540
2541 memset(buffer, 'X', sizeof(buffer));
2542 errno = EBADF;
2543 ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
2544 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2545 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2546 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2547
2548 memset(buffer, 'X', sizeof(buffer));
2549 errno = EBADF;
2550 ret = p_ultoa_s(12345678, buffer, 4, 10);
2551 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2552 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2553 ok(!memcmp(buffer, "\000765", 4),
2554 "Expected the output buffer to be null terminated with truncated output\n");
2555
2556 memset(buffer, 'X', sizeof(buffer));
2557 errno = EBADF;
2558 ret = p_ultoa_s(12345678, buffer, 8, 10);
2559 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2560 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2561 ok(!memcmp(buffer, "\0007654321", 8),
2562 "Expected the output buffer to be null terminated with truncated output\n");
2563
2564 ret = p_ultoa_s(12345678, buffer, 9, 10);
2565 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2566 ok(!strcmp(buffer, "12345678"),
2567 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2568 buffer);
2569
2570 ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
2571 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2572 ok(!strcmp(buffer, "1010101010101010"),
2573 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2574 buffer);
2575
2576 ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
2577 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2578 ok(!strcmp(buffer, "nell"),
2579 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2580 buffer);
2581
2582 ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
2583 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2584 ok(!strcmp(buffer, "hag"),
2585 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2586 buffer);
2587 }
2588
2589 static void test_wctob(void)
2590 {
2591 int ret;
2592
2593 if(!p_wctob || !setlocale(LC_ALL, "chinese-traditional")) {
2594 win_skip("Skipping wctob tests\n");
2595 return;
2596 }
2597
2598 ret = p_wctob(0x8141);
2599 ok(ret == EOF, "ret = %x\n", ret);
2600
2601 ret = p_wctob(0x81);
2602 ok(ret == EOF, "ret = %x\n", ret);
2603
2604 ret = p_wctob(0xe0);
2605 ok(ret == 0x61, "ret = %x\n", ret);
2606
2607 _setmbcp(1250);
2608 ret = p_wctob(0x81);
2609 ok(ret == EOF, "ret = %x\n", ret);
2610
2611 setlocale(LC_ALL, "C");
2612 ret = p_wctob(0x8141);
2613 ok(ret == EOF, "ret = %x\n", ret);
2614
2615 ret = p_wctob(0x81);
2616 ok(ret == (int)(char)0x81, "ret = %x\n", ret);
2617
2618 ret = p_wctob(0x9f);
2619 ok(ret == (int)(char)0x9f, "ret = %x\n", ret);
2620
2621 ret = p_wctob(0xe0);
2622 ok(ret == (int)(char)0xe0, "ret = %x\n", ret);
2623 }
2624 static void test_wctomb(void)
2625 {
2626 mbstate_t state;
2627 unsigned char dst[10];
2628 size_t ret;
2629
2630 if(!p_wcrtomb || !setlocale(LC_ALL, "Japanese_Japan.932")) {
2631 win_skip("wcrtomb tests\n");
2632 return;
2633 }
2634
2635 ret = p_wcrtomb(NULL, 0x3042, NULL);
2636 ok(ret == 2, "wcrtomb did not return 2\n");
2637
2638 state = 1;
2639 dst[2] = 'a';
2640 ret = p_wcrtomb((char*)dst, 0x3042, &state);
2641 ok(ret == 2, "wcrtomb did not return 2\n");
2642 ok(state == 0, "state != 0\n");
2643 ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
2644 ok(dst[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst[1]);
2645 ok(dst[2] == 'a', "dst[2] != 'a'\n");
2646
2647 ret = p_wcrtomb((char*)dst, 0x3043, NULL);
2648 ok(ret == 2, "wcrtomb did not return 2\n");
2649 ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
2650 ok(dst[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst[1]);
2651
2652 ret = p_wcrtomb((char*)dst, 0x20, NULL);
2653 ok(ret == 1, "wcrtomb did not return 1\n");
2654 ok(dst[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst[0]);
2655
2656 ret = p_wcrtomb((char*)dst, 0xffff, NULL);
2657 ok(ret == -1, "wcrtomb did not return -1\n");
2658 ok(dst[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst[0]);
2659
2660 setlocale(LC_ALL, "C");
2661 }
2662
2663 static void test_tolower(void)
2664 {
2665 WCHAR chw, lower;
2666 char ch, lch;
2667 int ret, len;
2668
2669 /* test C locale when locale was never changed */
2670 ret = p_tolower(0x41);
2671 ok(ret == 0x61, "ret = %x\n", ret);
2672
2673 ret = p_tolower(0xF4);
2674 ok(ret == 0xF4, "ret = %x\n", ret);
2675
2676 errno = 0xdeadbeef;
2677 ret = p_tolower((char)0xF4);
2678 todo_wine ok(ret == (char)0xF4, "ret = %x\n", ret);
2679 todo_wine ok(errno == 0xdeadbeef, "errno = %d\n", errno);
2680
2681 errno = 0xdeadbeef;
2682 ret = p_tolower((char)0xD0);
2683 todo_wine ok(ret == (char)0xD0, "ret = %x\n", ret);
2684 todo_wine ok(errno == 0xdeadbeef, "errno = %d\n", errno);
2685
2686 /* test C locale after setting locale */
2687 if(!setlocale(LC_ALL, "us")) {
2688 win_skip("skipping tolower tests that depends on locale\n");
2689 return;
2690 }
2691 setlocale(LC_ALL, "C");
2692
2693 ch = 0xF4;
2694 errno = 0xdeadbeef;
2695 ret = p_tolower(ch);
2696 if(!MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, &ch, 1, &chw, 1) ||
2697 LCMapStringW(CP_ACP, LCMAP_LOWERCASE, &chw, 1, &lower, 1) != 1 ||
2698 (len = WideCharToMultiByte(CP_ACP, 0, &lower, 1, &lch, 1, NULL, NULL)) != 1)
2699 len = 0;
2700 if(len)
2701 ok(ret==(unsigned char)lch || broken(ret==ch)/*WinXP-*/, "ret = %x\n", ret);
2702 else
2703 ok(ret == ch, "ret = %x\n", ret);
2704 if(!len || ret==(unsigned char)lch)
2705 ok(errno == EILSEQ, "errno = %d\n", errno);
2706
2707 ch = 0xD0;
2708 errno = 0xdeadbeef;
2709 ret = p_tolower(ch);
2710 if(!MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, &ch, 1, &chw, 1) ||
2711 LCMapStringW(CP_ACP, LCMAP_LOWERCASE, &chw, 1, &lower, 1) != 1 ||
2712 (len = WideCharToMultiByte(CP_ACP, 0, &lower, 1, &lch, 1, NULL, NULL)) != 1)
2713 len = 0;
2714 if(len)
2715 ok(ret==(unsigned char)lch || broken(ret==ch)/*WinXP-*/, "ret = %x\n", ret);
2716 else
2717 ok(ret == ch, "ret = %x\n", ret);
2718 if(!len || ret==(unsigned char)lch)
2719 ok(errno == EILSEQ, "errno = %d\n", errno);
2720
2721 ret = p_tolower(0xD0);
2722 ok(ret == 0xD0, "ret = %x\n", ret);
2723
2724 ok(setlocale(LC_ALL, "us") != NULL, "setlocale failed\n");
2725
2726 ret = p_tolower((char)0xD0);
2727 ok(ret == 0xF0, "ret = %x\n", ret);
2728
2729 ret = p_tolower(0xD0);
2730 ok(ret == 0xF0, "ret = %x\n", ret);
2731
2732 setlocale(LC_ALL, "C");
2733 }
2734
2735 static void test__atodbl(void)
2736 {
2737 _CRT_DOUBLE d;
2738 char num[32];
2739 int ret;
2740
2741 if(!p__atodbl_l) {
2742 /* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
2743 * Because of this lets skip _atodbl tests when _atodbl_l is not available */
2744 win_skip("_atodbl_l is not available\n");
2745 return;
2746 }
2747
2748 num[0] = 0;
2749 ret = p__atodbl_l(&d, num, NULL);
2750 ok(ret == 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret);
2751 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2752 ret = _atodbl(&d, num);
2753 ok(ret == 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret);
2754 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2755
2756 strcpy(num, "t");
2757 ret = p__atodbl_l(&d, num, NULL);
2758 ok(ret == 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret);
2759 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2760 ret = _atodbl(&d, num);
2761 ok(ret == 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret);
2762 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2763
2764 strcpy(num, "0");
2765 ret = p__atodbl_l(&d, num, NULL);
2766 ok(ret == 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret);
2767 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2768 ret = _atodbl(&d, num);
2769 ok(ret == 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret);
2770 ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
2771
2772 strcpy(num, "123");
2773 ret = p__atodbl_l(&d, num, NULL);
2774 ok(ret == 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret);
2775 ok(d.x == 123, "d.x = %lf, expected 123\n", d.x);
2776 ret = _atodbl(&d, num);
2777 ok(ret == 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret);
2778 ok(d.x == 123, "d.x = %lf, expected 123\n", d.x);
2779
2780 strcpy(num, "1e-309");
2781 ret = p__atodbl_l(&d, num, NULL);
2782 ok(ret == _UNDERFLOW, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret);
2783 ok(d.x!=0 && almost_equal(d.x, 0), "d.x = %le, expected 0\n", d.x);
2784 ret = _atodbl(&d, num);
2785 ok(ret == _UNDERFLOW, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret);
2786 ok(d.x!=0 && almost_equal(d.x, 0), "d.x = %le, expected 0\n", d.x);
2787
2788 strcpy(num, "1e309");
2789 ret = p__atodbl_l(&d, num, NULL);
2790 ok(ret == _OVERFLOW, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret);
2791 ret = _atodbl(&d, num);
2792 ok(ret == _OVERFLOW, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret);
2793 }
2794
2795 static void test__stricmp(void)
2796 {
2797 int ret;
2798
2799 ret = _stricmp("test", "test");
2800 ok(ret == 0, "_stricmp returned %d\n", ret);
2801 ret = _stricmp("a", "z");
2802 ok(ret < 0, "_stricmp returned %d\n", ret);
2803 ret = _stricmp("z", "a");
2804 ok(ret > 0, "_stricmp returned %d\n", ret);
2805 ret = _stricmp("\xa5", "\xb9");
2806 ok(ret < 0, "_stricmp returned %d\n", ret);
2807
2808 if(!setlocale(LC_ALL, "polish")) {
2809 win_skip("stricmp tests\n");
2810 return;
2811 }
2812
2813 ret = _stricmp("test", "test");
2814 ok(ret == 0, "_stricmp returned %d\n", ret);
2815 ret = _stricmp("a", "z");
2816 ok(ret < 0, "_stricmp returned %d\n", ret);
2817 ret = _stricmp("z", "a");
2818 ok(ret > 0, "_stricmp returned %d\n", ret);
2819 ret = _stricmp("\xa5", "\xb9");
2820 ok(ret == 0, "_stricmp returned %d\n", ret);
2821 ret = _stricmp("a", "\xb9");
2822 ok(ret < 0, "_stricmp returned %d\n", ret);
2823
2824 setlocale(LC_ALL, "C");
2825 }
2826
2827 static void test__wcstoi64(void)
2828 {
2829 static const WCHAR digit[] = { '9', 0 };
2830 static const WCHAR space[] = { ' ', 0 };
2831 static const WCHAR stock[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
2832 static const WCHAR cjk_1[] = { 0x4e00, 0 }; /* CJK Ideograph, First */
2833 static const WCHAR tamil[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
2834 static const WCHAR thai[] = { 0x0e59, 0 }; /* THAI DIGIT NINE */
2835 static const WCHAR fullwidth[] = { 0xff19, 0 }; /* FULLWIDTH DIGIT NINE */
2836 static const WCHAR superscript1[] = { 0xb9, 0 }; /* SUPERSCRIPT ONE */
2837 static const WCHAR minus_0x91[] = { '-', 0x0e50, 'x', 0xff19, '1', 0 };
2838 static const WCHAR plus_071[] = { '+', 0x0e50, 0xff17, '1', 0 };
2839 static const WCHAR hex[] = { 0xff19, 'f', 0x0e59, 0xff46, 0 };
2840 static const WCHAR zeros[] = {
2841 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
2842 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
2843 };
2844 int i;
2845
2846 __int64 res;
2847 unsigned __int64 ures;
2848 WCHAR *endpos;
2849
2850 if (!p_wcstoi64 || !p_wcstoui64) {
2851 win_skip("_wcstoi64 or _wcstoui64 not found\n");
2852 return;
2853 }
2854
2855 res = p_wcstoi64(digit, NULL, 10);
2856 ok(res == 9, "res != 9\n");
2857 res = p_wcstoi64(space, &endpos, 0);
2858 ok(endpos == space, "endpos != space\n");
2859 res = p_wcstoi64(stock, &endpos, 10);
2860 ok(res == 0, "res != 0\n");
2861 ok(endpos == stock, "Incorrect endpos (%p-%p)\n", stock, endpos);
2862 res = p_wcstoi64(cjk_1, NULL, 0);
2863 ok(res == 0, "res != 0\n");
2864 res = p_wcstoi64(tamil, &endpos, 10);
2865 ok(res == 0, "res != 0\n");
2866 ok(endpos == tamil, "Incorrect endpos (%p-%p)\n", tamil, endpos);
2867 res = p_wcstoi64(thai, NULL, 10);
2868 ok(res == 9, "res != 9\n");
2869 res = p_wcstoi64(fullwidth, NULL, 10);
2870 ok(res == 9, "res != 9\n");
2871 res = p_wcstoi64(superscript1, NULL, 10);
2872 ok(res == 0, "res != 0\n");
2873 res = p_wcstoi64(hex, NULL, 16);
2874 ok(res == 0x9f9, "res != 0x9f9\n");
2875 res = p_wcstoi64(minus_0x91, NULL, 0);
2876 ok(res == -0x91, "res != -0x91\n");
2877 res = p_wcstoi64(plus_071, NULL, 0);
2878 ok(res == 071, "res != 071\n");
2879
2880 ures = p_wcstoui64(digit, NULL, 10);
2881 ok(ures == 9, "ures != 9\n");
2882 ures = p_wcstoui64(space, &endpos, 0);
2883 ok(endpos == space, "endpos != space\n");
2884 ures = p_wcstoui64(stock, &endpos, 10);
2885 ok(ures == 0, "ures != 0\n");
2886 ok(endpos == stock, "Incorrect endpos (%p-%p)\n", stock, endpos);
2887 ures = p_wcstoui64(tamil, &endpos, 10);
2888 ok(ures == 0, "ures != 0\n");
2889 ok(endpos == tamil, "Incorrect endpos (%p-%p)\n", tamil, endpos);
2890 ures = p_wcstoui64(thai, NULL, 10);
2891 ok(ures == 9, "ures != 9\n");
2892 ures = p_wcstoui64(fullwidth, NULL, 10);
2893 ok(ures == 9, "ures != 9\n");
2894 ures = p_wcstoui64(superscript1, NULL, 10);
2895 ok(ures == 0, "ures != 0\n");
2896 ures = p_wcstoui64(hex, NULL, 16);
2897 ok(ures == 0x9f9, "ures != 0x9f9\n");
2898 ures = p_wcstoui64(plus_071, NULL, 0);
2899 ok(ures == 071, "ures != 071\n");
2900
2901 /* Test various unicode digits */
2902 for (i = 0; i < sizeof(zeros) / sizeof(zeros[0]); ++i) {
2903 WCHAR tmp[] = {zeros[i] + 4, zeros[i], zeros[i] + 5, 0};
2904 res = p_wcstoi64(tmp, NULL, 0);
2905 ok(res == 405, "with zero = U+%04X: got %d, expected 405\n", zeros[i], (int)res);
2906 tmp[1] = zeros[i] + 10;
2907 res = p_wcstoi64(tmp, NULL, 16);
2908 ok(res == 4, "with zero = U+%04X: got %d, expected 4\n", zeros[i], (int)res);
2909 }
2910
2911 return;
2912 }
2913
2914 static void test_atoi(void)
2915 {
2916 int r;
2917
2918 r = atoi("0");
2919 ok(r == 0, "atoi(0) = %d\n", r);
2920
2921 r = atoi("-1");
2922 ok(r == -1, "atoi(-1) = %d\n", r);
2923
2924 r = atoi("1");
2925 ok(r == 1, "atoi(1) = %d\n", r);
2926
2927 r = atoi("4294967296");
2928 ok(r == 0, "atoi(4294967296) = %d\n", r);
2929 }
2930
2931 static void test_atof(void)
2932 {
2933 double d;
2934
2935 d = atof("0.0");
2936 ok(almost_equal(d, 0.0), "d = %lf\n", d);
2937
2938 d = atof("1.0");
2939 ok(almost_equal(d, 1.0), "d = %lf\n", d);
2940
2941 d = atof("-1.0");
2942 ok(almost_equal(d, -1.0), "d = %lf\n", d);
2943
2944 if (!p__atof_l)
2945 {
2946 win_skip("_atof_l not found\n");
2947 return;
2948 }
2949
2950 errno = EBADF;
2951 d = atof(NULL);
2952 ok(almost_equal(d, 0.0), "d = %lf\n", d);
2953 ok(errno == EINVAL, "errno = %x\n", errno);
2954
2955 errno = EBADF;
2956 d = p__atof_l(NULL, NULL);
2957 ok(almost_equal(d, 0.0), "d = %lf\n", d);
2958 ok(errno == EINVAL, "errno = %x\n", errno);
2959 }
2960
2961 static void test_strncpy(void)
2962 {
2963 #define TEST_STRNCPY_LEN 10
2964 char *ret;
2965 char dst[TEST_STRNCPY_LEN + 1];
2966 char not_null_terminated[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
2967
2968 /* strlen(src) > TEST_STRNCPY_LEN */
2969 ret = strncpy(dst, "01234567890123456789", TEST_STRNCPY_LEN);
2970 ok(ret == dst, "ret != dst\n");
2971 ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
2972
2973 /* without null-terminated */
2974 ret = strncpy(dst, not_null_terminated, TEST_STRNCPY_LEN);
2975 ok(ret == dst, "ret != dst\n");
2976 ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
2977
2978 /* strlen(src) < TEST_STRNCPY_LEN */
2979 strcpy(dst, "0123456789");
2980 ret = strncpy(dst, "012345", TEST_STRNCPY_LEN);
2981 ok(ret == dst, "ret != dst\n");
2982 ok(!strcmp(dst, "012345"), "dst != 012345\n");
2983 ok(dst[TEST_STRNCPY_LEN - 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
2984
2985 /* strlen(src) == TEST_STRNCPY_LEN */
2986 ret = strncpy(dst, "0123456789", TEST_STRNCPY_LEN);
2987 ok(ret == dst, "ret != dst\n");
2988 ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
2989 }
2990
2991 static void test_strxfrm(void)
2992 {
2993 char dest[256];
2994 size_t ret;
2995
2996 /* crashes on old version of msvcrt */
2997 if(p__atodbl_l) {
2998 errno = 0xdeadbeef;
2999 ret = strxfrm(NULL, "src", 1);
3000 ok(ret == INT_MAX, "ret = %d\n", (int)ret);
3001 ok(errno == EINVAL, "errno = %d\n", errno);
3002
3003 errno = 0xdeadbeef;
3004 ret = strxfrm(dest, NULL, 100);
3005 ok(ret == INT_MAX, "ret = %d\n", (int)ret);
3006 ok(errno == EINVAL, "errno = %d\n", errno);
3007 }
3008
3009 ret = strxfrm(NULL, "src", 0);
3010 ok(ret == 3, "ret = %d\n", (int)ret);
3011 dest[0] = 'a';
3012 ret = strxfrm(dest, "src", 0);
3013 ok(ret == 3, "ret = %d\n", (int)ret);
3014 ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
3015
3016 dest[3] = 'a';
3017 ret = strxfrm(dest, "src", 5);
3018 ok(ret == 3, "ret = %d\n", (int)ret);
3019 ok(!strcmp(dest, "src"), "dest = %s\n", dest);
3020
3021 errno = 0xdeadbeef;
3022 dest[1] = 'a';
3023 ret = strxfrm(dest, "src", 1);
3024 ok(ret == 3, "ret = %d\n", (int)ret);
3025 ok(dest[0] == 's', "dest[0] = %d\n", dest[0]);
3026 ok(dest[1] == 'a', "dest[1] = %d\n", dest[1]);
3027 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
3028
3029 ret = strxfrm(dest, "", 5);
3030 ok(ret == 0, "ret = %d\n", (int)ret);
3031 ok(!dest[0], "dest[0] = %d\n", dest[0]);
3032
3033 if(!setlocale(LC_ALL, "polish")) {
3034 win_skip("stxfrm tests\n");
3035 return;
3036 }
3037
3038 ret = strxfrm(NULL, "src", 0);
3039 ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
3040 dest[0] = 'a';
3041 ret = strxfrm(dest, "src", 0);
3042 ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
3043 ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
3044
3045 ret = strxfrm(dest, "src", ret+1);
3046 ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
3047 ok(dest[0], "dest[0] = 0\n");
3048
3049 errno = 0xdeadbeef;
3050 dest[0] = 'a';
3051 ret = strxfrm(dest, "src", 5);
3052 ok(ret>5 && ret<sizeof(dest)-1, "ret = %d\n", (int)ret);
3053 ok(!dest[0] || broken(!p__atodbl_l && dest[0]=='a'), "dest[0] = %d\n", dest[0]);
3054
3055 setlocale(LC_ALL, "C");
3056 }
3057
3058 static void test__strnset_s(void)
3059 {
3060 char buf[5] = {0};
3061 int r;
3062
3063 if(!p__strnset_s) {
3064 win_skip("_strnset_s not available\n");
3065 return;
3066 }
3067
3068 r = p__strnset_s(NULL, 0, 'a', 0);
3069 ok(r == 0, "r = %d\n", r);
3070
3071 buf[0] = buf[1] = buf[2] = 'b';
3072 r = p__strnset_s(buf, sizeof(buf), 'a', 2);
3073 ok(r == 0, "r = %d\n", r);
3074 ok(!strcmp(buf, "aab"), "buf = %s\n", buf);
3075
3076 r = p__strnset_s(buf, 0, 'a', 0);
3077 ok(r == EINVAL, "r = %d\n", r);
3078
3079 r = p__strnset_s(NULL, 0, 'a', 1);
3080 ok(r == EINVAL, "r = %d\n", r);
3081
3082 buf[3] = 'b';
3083 r = p__strnset_s(buf, sizeof(buf)-1, 'c', 2);
3084 ok(r == EINVAL, "r = %d\n", r);
3085 ok(!buf[0] && buf[1]=='c' && buf[2]=='b', "buf = %s\n", buf);
3086 }
3087
3088 static void test__wcsset_s(void)
3089 {
3090 wchar_t str[10];
3091 int r;
3092
3093 if(!p__wcsset_s) {
3094 win_skip("_wcsset_s not available\n");
3095 return;
3096 }
3097
3098 r = p__wcsset_s(NULL, 0, 'a');
3099 ok(r == EINVAL, "r = %d\n", r);
3100
3101 str[0] = 'a';
3102 r = p__wcsset_s(str, 0, 'a');
3103 ok(r == EINVAL, "r = %d\n", r);
3104 ok(str[0] == 'a', "str[0] = %d\n", str[0]);
3105
3106 str[0] = 'a';
3107 str[1] = 'b';
3108 r = p__wcsset_s(str, 2, 'c');
3109 ok(r == EINVAL, "r = %d\n", r);
3110 ok(!str[0], "str[0] = %d\n", str[0]);
3111 ok(str[1] == 'b', "str[1] = %d\n", str[1]);
3112
3113 str[0] = 'a';
3114 str[1] = 0;
3115 str[2] = 'b';
3116 r = p__wcsset_s(str, 3, 'c');
3117 ok(str[0] == 'c', "str[0] = %d\n", str[0]);
3118 ok(str[1] == 0, "str[1] = %d\n", str[1]);
3119 ok(str[2] == 'b', "str[2] = %d\n", str[2]);
3120 }
3121
3122 static void test__mbscmp(void)
3123 {
3124 static const unsigned char a[] = {'a',0}, b[] = {'b',0};
3125 int ret;
3126
3127 if (!p_mbrlen)
3128 {
3129 win_skip("_mbscmp tests\n");
3130 return;
3131 }
3132
3133 ret = _mbscmp(NULL, NULL);
3134 ok(ret == INT_MAX, "got %d\n", ret);
3135
3136 ret = _mbscmp(a, NULL);
3137 ok(ret == INT_MAX, "got %d\n", ret);
3138
3139 ret = _mbscmp(NULL, a);
3140 ok(ret == INT_MAX, "got %d\n", ret);
3141
3142 ret = _mbscmp(a, a);
3143 ok(!ret, "got %d\n", ret);
3144
3145 ret = _mbscmp(a, b);
3146 ok(ret == -1, "got %d\n", ret);
3147
3148 ret = _mbscmp(b, a);
3149 ok(ret == 1, "got %d\n", ret);
3150 }
3151
3152 START_TEST(string)
3153 {
3154 char mem[100];
3155 static const char xilstring[]="c:/xilinx";
3156 int nLen;
3157
3158 hMsvcrt = GetModuleHandleA("msvcrt.dll");
3159 if (!hMsvcrt)
3160 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
3161 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
3162 SET(pmemcpy,"memcpy");
3163 p_memcpy_s = (void*)GetProcAddress( hMsvcrt, "memcpy_s" );
3164 p_memmove_s = (void*)GetProcAddress( hMsvcrt, "memmove_s" );
3165 SET(pmemcmp,"memcmp");
3166 SET(p_mbctype,"_mbctype");
3167 SET(p__mb_cur_max,"__mb_cur_max");
3168 pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
3169 pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
3170 p_mbscat_s = (void*)GetProcAddress( hMsvcrt, "_mbscat_s" );
3171 p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
3172 p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
3173 p__mbscpy_s = (void *)GetProcAddress( hMsvcrt,"_mbscpy_s" );
3174 p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
3175 p_wcsncpy_s = (void *)GetProcAddress( hMsvcrt,"wcsncpy_s" );
3176 p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
3177 p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
3178 p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
3179 p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
3180 p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
3181 p_wcstoi64 = (void *)GetProcAddress(hMsvcrt, "_wcstoi64");
3182 p_wcstoui64 = (void *)GetProcAddress(hMsvcrt, "_wcstoui64");
3183 pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
3184 pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
3185 pwcsrtombs = (void *)GetProcAddress(hMsvcrt, "wcsrtombs");
3186 p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
3187 p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
3188 p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
3189 p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
3190 p_wcslwr_s = (void*)GetProcAddress(hMsvcrt, "_wcslwr_s");
3191 p_mbsupr_s = (void*)GetProcAddress(hMsvcrt, "_mbsupr_s");
3192 p_mbslwr_s = (void*)GetProcAddress(hMsvcrt, "_mbslwr_s");
3193 p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob");
3194 p_wcrtomb = (void*)GetProcAddress(hMsvcrt, "wcrtomb");
3195 p_tolower = (void*)GetProcAddress(hMsvcrt, "tolower");
3196 p_mbrlen = (void*)GetProcAddress(hMsvcrt, "mbrlen");
3197 p_mbrtowc = (void*)GetProcAddress(hMsvcrt, "mbrtowc");
3198 p_mbsrtowcs = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs");
3199 p_mbsrtowcs_s = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs_s");
3200 p__atodbl_l = (void*)GetProcAddress(hMsvcrt, "_atodbl_l");
3201 p__atof_l = (void*)GetProcAddress(hMsvcrt, "_atof_l");
3202 p__strtod_l = (void*)GetProcAddress(hMsvcrt, "_strtod_l");
3203 p__strnset_s = (void*)GetProcAddress(hMsvcrt, "_strnset_s");
3204 p__wcsset_s = (void*)GetProcAddress(hMsvcrt, "_wcsset_s");
3205
3206 /* MSVCRT memcpy behaves like memmove for overlapping moves,
3207 MFC42 CString::Insert seems to rely on that behaviour */
3208 strcpy(mem,xilstring);
3209 nLen=strlen(xilstring);
3210 pmemcpy(mem+5, mem,nLen+1);
3211 ok(pmemcmp(mem+5,xilstring, nLen) == 0,
3212 "Got result %s\n",mem+5);
3213
3214 /* run tolower tests first */
3215 test_tolower();
3216 test_swab();
3217 test_mbcp();
3218 test_mbsspn();
3219 test_mbsspnp();
3220 test_strdup();
3221 test_strcpy_s();
3222 test_memcpy_s();
3223 test_memmove_s();
3224 test_strcat_s();
3225 test__mbscat_s();
3226 test__mbsnbcpy_s();
3227 test__mbscpy_s();
3228 test_mbcjisjms();
3229 test_mbcjmsjis();
3230 test_mbctohira();
3231 test_mbctokata();
3232 test_mbbtombc();
3233 test_mbctombb();
3234 test_ismbckata();
3235 test_ismbclegal();
3236 test_strtok();
3237 test__mbstok();
3238 test_wcscpy_s();
3239 test__wcsupr_s();
3240 test_strtol();
3241 test_strnlen();
3242 test__strtoi64();
3243 test__strtod();
3244 test_mbstowcs();
3245 test_gcvt();
3246 test__itoa_s();
3247 test__strlwr_s();
3248 test_wcsncat_s();
3249 test__mbsnbcat_s();
3250 test__ultoa_s();
3251 test__wcslwr_s();
3252 test__mbsupr_s();
3253 test__mbslwr_s();
3254 test_wctob();
3255 test_wctomb();
3256 test__atodbl();
3257 test__stricmp();
3258 test__wcstoi64();
3259 test_atoi();
3260 test_atof();
3261 test_strncpy();
3262 test_strxfrm();
3263 test__strnset_s();
3264 test__wcsset_s();
3265 test__mbscmp();
3266 }