[MSVCRT_WINETEST]: Sync to Wine 1.5.13.
[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 "winbase.h"
23 #include "winnls.h"
24 #include <string.h>
25 #include <mbstring.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <mbctype.h>
29 #include <locale.h>
30 #include <errno.h>
31 #include <limits.h>
32
33 /* ReactOS */
34 typedef unsigned int __msvcrt_ulong;
35
36 static char *buf_to_string(const unsigned char *bin, int len, int nr)
37 {
38 static char buf[2][1024];
39 char *w = buf[nr];
40 int i;
41
42 for (i = 0; i < len; i++)
43 {
44 sprintf(w, "%02x ", (unsigned char)bin[i]);
45 w += strlen(w);
46 }
47 return buf[nr];
48 }
49
50 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
51 const wchar_t *function, const wchar_t *file,
52 unsigned line, uintptr_t arg)
53 {
54 /* we just ignore handler calls */
55 }
56
57 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
58 #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)); }
59
60 static void* (__cdecl *pmemcpy)(void *, const void *, size_t n);
61 static int (__cdecl *p_memcpy_s)(void *, size_t, const void *, size_t);
62 static int (__cdecl *p_memmove_s)(void *, size_t, const void *, size_t);
63 static int* (__cdecl *pmemcmp)(void *, const void *, size_t n);
64 static int (__cdecl *pstrcpy_s)(char *dst, size_t len, const char *src);
65 static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
66 static int (__cdecl *p_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
67 static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
68 static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
69 static int (__cdecl *p_wcsncpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc, size_t count);
70 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
71 static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
72 static size_t (__cdecl *p_strnlen)(const char *, size_t);
73 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
74 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
75 static int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
76 static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
77 static size_t (__cdecl *pwcsrtombs)(char*, const wchar_t**, size_t, int*);
78 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
79 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
80 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
81 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
82 static int *p__mb_cur_max;
83 static unsigned char *p_mbctype;
84 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
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 int (__cdecl *p_tolower)(int);
90
91 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
92 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
93
94 static HMODULE hMsvcrt;
95
96 static void test_swab( void ) {
97 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
98 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
99 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
100 char expected3[] = "$";
101
102 char from[30];
103 char to[30];
104
105 int testsize;
106
107 /* Test 1 - normal even case */
108 memset(to,'$', sizeof(to));
109 memset(from,'@', sizeof(from));
110 testsize = 26;
111 memcpy(from, original, testsize);
112 _swab( from, to, testsize );
113 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
114
115 /* Test 2 - uneven case */
116 memset(to,'$', sizeof(to));
117 memset(from,'@', sizeof(from));
118 testsize = 25;
119 memcpy(from, original, testsize);
120 _swab( from, to, testsize );
121 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
122
123 /* Test 3 - from = to */
124 memset(to,'$', sizeof(to));
125 memset(from,'@', sizeof(from));
126 testsize = 26;
127 memcpy(to, original, testsize);
128 _swab( to, to, testsize );
129 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
130
131 /* Test 4 - 1 bytes */
132 memset(to,'$', sizeof(to));
133 memset(from,'@', sizeof(from));
134 testsize = 1;
135 memcpy(from, original, testsize);
136 _swab( from, to, testsize );
137 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
138 }
139
140 #if 0 /* use this to generate more tests */
141
142 static void test_codepage(int cp)
143 {
144 int i;
145 int prev;
146 int count = 1;
147
148 ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
149
150 prev = p_mbctype[0];
151 printf("static int result_cp_%d_mbctype[] = { ", cp);
152 for (i = 1; i < 257; i++)
153 {
154 if (p_mbctype[i] != prev)
155 {
156 printf("0x%x,%d, ", prev, count);
157 prev = p_mbctype[i];
158 count = 1;
159 }
160 else
161 count++;
162 }
163 printf("0x%x,%d };\n", prev, count);
164 }
165
166 #else
167
168 /* RLE-encoded mbctype tables for given codepages */
169 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
170 0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
171 static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
172 0xc,126, 0,1 };
173 static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
174 0,1 };
175 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
176 0x0,2, 0x4,32, 0xc,94, 0,1 };
177
178 static void test_cp_table(int cp, int *result)
179 {
180 int i;
181 int count = 0;
182 int curr = 0;
183 _setmbcp(cp);
184 for (i = 0; i < 256; i++)
185 {
186 if (count == 0)
187 {
188 curr = result[0];
189 count = result[1];
190 result += 2;
191 }
192 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);
193 count--;
194 }
195 }
196
197 #define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
198
199 #endif
200
201 static void test_mbcp(void)
202 {
203 int mb_orig_max = *p__mb_cur_max;
204 int curr_mbcp = _getmbcp();
205 unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
206 unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
207 unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
208 unsigned char buf[16];
209 int step;
210 CPINFO cp_info;
211
212 /* _mbtype tests */
213
214 /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
215 * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
216 * CP1252 (or the ACP?) so we test only a few ASCII characters */
217 _setmbcp(1252);
218 expect_eq(p_mbctype[10], 0, char, "%x");
219 expect_eq(p_mbctype[50], 0, char, "%x");
220 expect_eq(p_mbctype[66], _SBUP, char, "%x");
221 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
222 expect_eq(p_mbctype[128], 0, char, "%x");
223 _setmbcp(1250);
224 expect_eq(p_mbctype[10], 0, char, "%x");
225 expect_eq(p_mbctype[50], 0, char, "%x");
226 expect_eq(p_mbctype[66], _SBUP, char, "%x");
227 expect_eq(p_mbctype[100], _SBLOW, char, "%x");
228 expect_eq(p_mbctype[128], 0, char, "%x");
229
230 /* double byte code pages */
231 test_codepage(932);
232 test_codepage(936);
233 test_codepage(949);
234 test_codepage(950);
235
236 _setmbcp(936);
237 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);
238 ok(_ismbblead('\354'), "\354 should be a lead byte\n");
239 ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
240 ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
241 ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
242 ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
243 ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
244
245 /* _ismbslead */
246 expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
247 expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
248 expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
249 expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
250 expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
251 expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
252 expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
253 expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
254 expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
255
256 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
257 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
258 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
259 expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
260
261 /* _ismbstrail */
262 expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
263 expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
264 expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
265 expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
266 expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
267 expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
268 expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
269 expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
270 expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
271
272 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
273 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
274 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
275 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
276 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
277 expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
278
279 /* _mbsbtype */
280 expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
281 expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
282 expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
283 expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
284 expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
285 expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
286 expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
287 expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
288 expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
289
290 expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
291 expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
292 expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
293 expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
294 expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
295 expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
296
297 /* _mbsnextc */
298 expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
299 expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
300 expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
301
302 /* _mbclen/_mbslen */
303 expect_eq(_mbclen(mbstring), 2, int, "%d");
304 expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
305 expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
306 expect_eq(_mbslen(mbstring2), 4, int, "%d");
307 expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
308 expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
309
310 /* _mbccpy/_mbsncpy */
311 memset(buf, 0xff, sizeof(buf));
312 _mbccpy(buf, mbstring);
313 expect_bin(buf, "\xb0\xb1\xff", 3);
314
315 memset(buf, 0xff, sizeof(buf));
316 _mbsncpy(buf, mbstring, 1);
317 expect_bin(buf, "\xb0\xb1\xff", 3);
318 memset(buf, 0xff, sizeof(buf));
319 _mbsncpy(buf, mbstring, 2);
320 expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
321 memset(buf, 0xff, sizeof(buf));
322 _mbsncpy(buf, mbstring, 3);
323 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
324 memset(buf, 0xff, sizeof(buf));
325 _mbsncpy(buf, mbstring, 4);
326 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
327 memset(buf, 0xff, sizeof(buf));
328 _mbsncpy(buf, mbstring, 5);
329 expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
330 memset(buf, 0xff, sizeof(buf));
331 _mbsncpy(buf, mbsonlylead, 6);
332 expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
333
334 memset(buf, 0xff, sizeof(buf));
335 _mbsnbcpy(buf, mbstring2, 2);
336 expect_bin(buf, "\xb0\xb1\xff", 3);
337 _mbsnbcpy(buf, mbstring2, 3);
338 expect_bin(buf, "\xb0\xb1\0\xff", 4);
339 _mbsnbcpy(buf, mbstring2, 4);
340 expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
341 memset(buf, 0xff, sizeof(buf));
342 _mbsnbcpy(buf, mbsonlylead, 5);
343 expect_bin(buf, "\0\0\0\0\0\xff", 6);
344
345 /* _mbsinc/mbsdec */
346 step = _mbsinc(mbstring) - mbstring;
347 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
348 step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
349 ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
350
351 step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
352 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
353 step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
354 ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
355 step = _mbsninc(mbstring2, 0) - mbstring2;
356 ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
357 step = _mbsninc(mbstring2, 1) - mbstring2;
358 ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
359 step = _mbsninc(mbstring2, 2) - mbstring2;
360 ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
361 step = _mbsninc(mbstring2, 3) - mbstring2;
362 ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
363 step = _mbsninc(mbstring2, 4) - mbstring2;
364 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
365 step = _mbsninc(mbstring2, 5) - mbstring2;
366 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
367 step = _mbsninc(mbstring2, 17) - mbstring2;
368 ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
369
370 /* functions that depend on locale codepage, not mbcp.
371 * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
372 * (as of Wine 0.9.43)
373 */
374 GetCPInfo(GetACP(), &cp_info);
375 if (cp_info.MaxCharSize == 1)
376 {
377 expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
378 expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
379 }
380 else
381 skip("Current locale has double-byte charset - could lead to false positives\n");
382
383 _setmbcp(1361);
384 expect_eq(_ismbblead(0x80), 0, int, "%d");
385 todo_wine {
386 expect_eq(_ismbblead(0x81), 1, int, "%d");
387 expect_eq(_ismbblead(0x83), 1, int, "%d");
388 }
389 expect_eq(_ismbblead(0x84), 1, int, "%d");
390 expect_eq(_ismbblead(0xd3), 1, int, "%d");
391 expect_eq(_ismbblead(0xd7), 0, int, "%d");
392 todo_wine {
393 expect_eq(_ismbblead(0xd8), 1, int, "%d");
394 }
395 expect_eq(_ismbblead(0xd9), 1, int, "%d");
396
397 expect_eq(_ismbbtrail(0x30), 0, int, "%d");
398 expect_eq(_ismbbtrail(0x31), 1, int, "%d");
399 expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
400 expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
401 expect_eq(_ismbbtrail(0x80), 0, int, "%d");
402 expect_eq(_ismbbtrail(0x81), 1, int, "%d");
403 expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
404 expect_eq(_ismbbtrail(0xff), 0, int, "%d");
405
406 _setmbcp(curr_mbcp);
407 }
408
409 static void test_mbsspn( void)
410 {
411 unsigned char str1[]="cabernet";
412 unsigned char str2[]="shiraz";
413 unsigned char set[]="abc";
414 unsigned char empty[]="";
415 int ret;
416 ret=_mbsspn( str1, set);
417 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
418 ret=_mbsspn( str2, set);
419 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
420 ret=_mbsspn( str1, empty);
421 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
422 }
423
424 static void test_mbsspnp( void)
425 {
426 unsigned char str1[]="cabernet";
427 unsigned char str2[]="shiraz";
428 unsigned char set[]="abc";
429 unsigned char empty[]="";
430 unsigned char full[]="abcenrt";
431 unsigned char* ret;
432 ret=_mbsspnp( str1, set);
433 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
434 ret=_mbsspnp( str2, set);
435 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
436 ret=_mbsspnp( str1, empty);
437 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
438 ret=_mbsspnp( str1, full);
439 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
440 }
441
442 static void test_strdup(void)
443 {
444 char *str;
445 str = _strdup( 0 );
446 ok( str == 0, "strdup returns %s should be 0\n", str);
447 free( str );
448 }
449
450 static void test_strcpy_s(void)
451 {
452 char dest[8];
453 const char *small = "small";
454 const char *big = "atoolongstringforthislittledestination";
455 int ret;
456
457 if(!pstrcpy_s)
458 {
459 skip("strcpy_s not found\n");
460 return;
461 }
462
463 memset(dest, 'X', sizeof(dest));
464 ret = pstrcpy_s(dest, sizeof(dest), small);
465 ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
466 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
467 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
468 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
469 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
470
471 memset(dest, 'X', sizeof(dest));
472 ret = pstrcpy_s(dest, 0, big);
473 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
474 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
475 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
476 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
477 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
478 ret = pstrcpy_s(dest, 0, NULL);
479 ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
480 ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
481 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
482 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
483 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
484
485 memset(dest, 'X', sizeof(dest));
486 ret = pstrcpy_s(dest, sizeof(dest), big);
487 ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
488 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
489 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
490 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
491 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
492
493 memset(dest, 'X', sizeof(dest));
494 ret = pstrcpy_s(dest, sizeof(dest), NULL);
495 ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
496 ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
497 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
498 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
499 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
500
501 ret = pstrcpy_s(NULL, sizeof(dest), small);
502 ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
503 }
504
505 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
506
507 #define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
508 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
509 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
510 "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
511 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
512
513 static void test_memcpy_s(void)
514 {
515 static char dest[8];
516 static const char tiny[] = {'T',0,'I','N','Y',0};
517 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
518 int ret;
519 if (!p_memcpy_s) {
520 skip("memcpy_s not found\n");
521 return;
522 }
523
524 if (p_set_invalid_parameter_handler)
525 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
526 "Invalid parameter handler was already set\n");
527
528 /* Normal */
529 memset(dest, 'X', sizeof(dest));
530 ret = p_memcpy_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
531 ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret);
532 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
533
534 /* Vary source size */
535 errno = 0xdeadbeef;
536 memset(dest, 'X', sizeof(dest));
537 ret = p_memcpy_s(dest, NUMELMS(dest), big, NUMELMS(big));
538 ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret);
539 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
540 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
541
542 /* Replace source with NULL */
543 errno = 0xdeadbeef;
544 memset(dest, 'X', sizeof(dest));
545 ret = p_memcpy_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
546 ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret);
547 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
548 okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
549
550 /* Vary dest size */
551 errno = 0xdeadbeef;
552 memset(dest, 'X', sizeof(dest));
553 ret = p_memcpy_s(dest, 0, tiny, NUMELMS(tiny));
554 ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret);
555 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
556 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
557
558 /* Replace dest with NULL */
559 errno = 0xdeadbeef;
560 ret = p_memcpy_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
561 ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
562 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
563
564 /* Combinations */
565 errno = 0xdeadbeef;
566 memset(dest, 'X', sizeof(dest));
567 ret = p_memcpy_s(dest, 0, NULL, NUMELMS(tiny));
568 ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
569 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
570 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
571
572 if (p_set_invalid_parameter_handler)
573 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
574 "Cannot reset invalid parameter handler\n");
575 }
576
577 static void test_memmove_s(void)
578 {
579 static char dest[8];
580 static const char tiny[] = {'T',0,'I','N','Y',0};
581 static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
582 int ret;
583 if (!p_memmove_s) {
584 skip("memmove_s not found\n");
585 return;
586 }
587
588 if (p_set_invalid_parameter_handler)
589 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
590 "Invalid parameter handler was already set\n");
591
592 /* Normal */
593 memset(dest, 'X', sizeof(dest));
594 ret = p_memmove_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
595 ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret);
596 okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
597
598 /* Overlapping */
599 memcpy(dest, big, sizeof(dest));
600 ret = p_memmove_s(dest+1, NUMELMS(dest)-1, dest, NUMELMS(dest)-1);
601 ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret);
602 okchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]);
603
604 /* Vary source size */
605 errno = 0xdeadbeef;
606 memset(dest, 'X', sizeof(dest));
607 ret = p_memmove_s(dest, NUMELMS(dest), big, NUMELMS(big));
608 ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret);
609 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
610 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
611
612 /* Replace source with NULL */
613 errno = 0xdeadbeef;
614 memset(dest, 'X', sizeof(dest));
615 ret = p_memmove_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
616 ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret);
617 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
618 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
619
620 /* Vary dest size */
621 errno = 0xdeadbeef;
622 memset(dest, 'X', sizeof(dest));
623 ret = p_memmove_s(dest, 0, tiny, NUMELMS(tiny));
624 ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret);
625 ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
626 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
627
628 /* Replace dest with NULL */
629 errno = 0xdeadbeef;
630 ret = p_memmove_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
631 ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
632 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
633
634 /* Combinations */
635 errno = 0xdeadbeef;
636 memset(dest, 'X', sizeof(dest));
637 ret = p_memmove_s(dest, 0, NULL, NUMELMS(tiny));
638 ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
639 ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
640 okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
641
642 if (p_set_invalid_parameter_handler)
643 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
644 "Cannot reset invalid parameter handler\n");
645 }
646
647 static void test_strcat_s(void)
648 {
649 char dest[8];
650 const char *small = "sma";
651 int ret;
652
653 if(!pstrcat_s)
654 {
655 skip("strcat_s not found\n");
656 return;
657 }
658
659 memset(dest, 'X', sizeof(dest));
660 dest[0] = '\0';
661 ret = pstrcat_s(dest, sizeof(dest), small);
662 ok(ret == 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
663 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == '\0'&&
664 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
665 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
666 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
667 ret = pstrcat_s(dest, sizeof(dest), small);
668 ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
669 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
670 dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
671 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
672 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
673
674 ret = pstrcat_s(dest, sizeof(dest), small);
675 ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
676 ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
677 dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
678 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
679 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
680
681 memset(dest, 'X', sizeof(dest));
682 dest[0] = 'a';
683 dest[1] = '\0';
684
685 ret = pstrcat_s(dest, 0, small);
686 ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
687 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
688 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
689 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
690 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
691
692 ret = pstrcat_s(dest, 0, NULL);
693 ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
694 ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
695 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
696 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
697 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
698
699 ret = pstrcat_s(dest, sizeof(dest), NULL);
700 ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
701 ok(dest[0] == '\0'&& dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
702 dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
703 "Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
704 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
705
706 ret = pstrcat_s(NULL, sizeof(dest), small);
707 ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
708 }
709
710 static void test__mbsnbcpy_s(void)
711 {
712 unsigned char dest[8];
713 const unsigned char big[] = "atoolongstringforthislittledestination";
714 const unsigned char small[] = "small";
715 int ret;
716
717 if(!p_mbsnbcpy_s)
718 {
719 skip("_mbsnbcpy_s not found\n");
720 return;
721 }
722
723 memset(dest, 'X', sizeof(dest));
724 ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
725 ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
726 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
727 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
728 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
729 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
730
731 /* WTF? */
732 memset(dest, 'X', sizeof(dest));
733 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
734 ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
735 ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
736 dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
737 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
738 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
739
740 memset(dest, 'X', sizeof(dest));
741 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
742 ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
743 ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
744 dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
745 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
746 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
747
748 memset(dest, 'X', sizeof(dest));
749 ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
750 ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
751 ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
752 dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
753 "Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
754 dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
755 }
756
757 static void test_wcscpy_s(void)
758 {
759 static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
760 static WCHAR szDest[18];
761 static WCHAR szDestShort[8];
762 int ret;
763
764 if(!p_wcscpy_s)
765 {
766 win_skip("wcscpy_s not found\n");
767 return;
768 }
769
770 /* Test NULL Dest */
771 ret = p_wcscpy_s(NULL, 18, szLongText);
772 ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
773
774 /* Test NULL Source */
775 szDest[0] = 'A';
776 ret = p_wcscpy_s(szDest, 18, NULL);
777 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
778 ok(szDest[0] == 0, "szDest[0] not 0\n");
779
780 /* Test invalid size */
781 szDest[0] = 'A';
782 ret = p_wcscpy_s(szDest, 0, szLongText);
783 /* Later versions changed the return value for this case to EINVAL,
784 * and don't modify the result if the dest size is 0.
785 */
786 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
787 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
788
789 /* Copy same buffer size */
790 ret = p_wcscpy_s(szDest, 18, szLongText);
791 ok(ret == 0, "expected 0 got %d\n", ret);
792 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
793
794 /* Copy smaller buffer size */
795 szDest[0] = 'A';
796 ret = p_wcscpy_s(szDestShort, 8, szLongText);
797 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
798 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
799
800 if(!p_wcsncpy_s)
801 {
802 win_skip("wcsncpy_s not found\n");
803 return;
804 }
805
806 ret = p_wcsncpy_s(NULL, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
807 ok(ret == EINVAL, "p_wcsncpy_s expect EINVAL got %d\n", ret);
808
809 szDest[0] = 'A';
810 ret = p_wcsncpy_s(szDest, 18, NULL, 1);
811 ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
812 ok(szDest[0] == 0, "szDest[0] not 0\n");
813
814 szDest[0] = 'A';
815 ret = p_wcsncpy_s(szDest, 18, NULL, 0);
816 ok(ret == 0, "expected ERROR_SUCCESS got %d\n", ret);
817 ok(szDest[0] == 0, "szDest[0] not 0\n");
818
819 szDest[0] = 'A';
820 ret = p_wcsncpy_s(szDest, 0, szLongText, sizeof(szLongText)/sizeof(WCHAR));
821 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
822 ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
823
824 ret = p_wcsncpy_s(szDest, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
825 ok(ret == 0, "expected 0 got %d\n", ret);
826 ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
827
828 szDest[0] = 'A';
829 ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR));
830 ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
831 ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
832
833 szDest[0] = 'A';
834 ret = p_wcsncpy_s(szDest, 5, szLongText, -1);
835 ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret);
836 ok(szDest[4] == 0, "szDest[4] not 0\n");
837 ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest));
838
839 ret = p_wcsncpy_s(NULL, 0, (void*)0xdeadbeef, 0);
840 ok(ret == 0, "ret = %d\n", ret);
841
842 szDestShort[0] = '1';
843 szDestShort[1] = 0;
844 ret = p_wcsncpy_s(szDestShort+1, 4, szDestShort, -1);
845 ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret);
846 ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1',
847 "szDestShort = %s\n", wine_dbgstr_w(szDestShort));
848 }
849
850 static void test__wcsupr_s(void)
851 {
852 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
853 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
854 static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
855 'W', 'E', 'R', 'U', 'P', 'P', 'E',
856 'R', 0};
857 WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
858 int ret;
859
860 if (!p_wcsupr_s)
861 {
862 win_skip("_wcsupr_s not found\n");
863 return;
864 }
865
866 /* Test NULL input string and invalid size. */
867 errno = EBADF;
868 ret = p_wcsupr_s(NULL, 0);
869 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
870 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
871
872 /* Test NULL input string and valid size. */
873 errno = EBADF;
874 ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
875 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
876 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
877
878 /* Test empty string with zero size. */
879 errno = EBADF;
880 testBuffer[0] = '\0';
881 ret = p_wcsupr_s(testBuffer, 0);
882 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
883 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
884 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
885
886 /* Test empty string with size of one. */
887 testBuffer[0] = '\0';
888 ret = p_wcsupr_s(testBuffer, 1);
889 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
890 ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
891
892 /* Test one-byte buffer with zero size. */
893 errno = EBADF;
894 testBuffer[0] = 'x';
895 ret = p_wcsupr_s(testBuffer, 0);
896 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
897 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
898 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
899
900 /* Test one-byte buffer with size of one. */
901 errno = EBADF;
902 testBuffer[0] = 'x';
903 ret = p_wcsupr_s(testBuffer, 1);
904 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
905 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
906 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
907
908 /* Test invalid size. */
909 wcscpy(testBuffer, mixedString);
910 errno = EBADF;
911 ret = p_wcsupr_s(testBuffer, 0);
912 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
913 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
914 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
915
916 /* Test normal string uppercasing. */
917 wcscpy(testBuffer, mixedString);
918 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
919 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
920 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
921
922 /* Test uppercasing with a shorter buffer size count. */
923 wcscpy(testBuffer, mixedString);
924 errno = EBADF;
925 ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
926 ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
927 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
928 ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
929
930 /* Test uppercasing with a longer buffer size count. */
931 wcscpy(testBuffer, mixedString);
932 ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
933 ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
934 ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
935 }
936
937 static void test__wcslwr_s(void)
938 {
939 static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
940 'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
941 static const WCHAR expectedString[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
942 'w', 'e', 'r', 'u', 'p', 'p', 'e',
943 'r', 0};
944 WCHAR buffer[2*sizeof(mixedString)/sizeof(WCHAR)];
945 int ret;
946
947 if (!p_wcslwr_s)
948 {
949 win_skip("_wcslwr_s not found\n");
950 return;
951 }
952
953 /* Test NULL input string and invalid size. */
954 errno = EBADF;
955 ret = p_wcslwr_s(NULL, 0);
956 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
957 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
958
959 /* Test NULL input string and valid size. */
960 errno = EBADF;
961 ret = p_wcslwr_s(NULL, sizeof(buffer)/sizeof(wchar_t));
962 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
963 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
964
965 /* Test empty string with zero size. */
966 errno = EBADF;
967 buffer[0] = 'a';
968 ret = p_wcslwr_s(buffer, 0);
969 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
970 ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
971 ok(buffer[0] == 0, "expected empty string\n");
972
973 /* Test empty string with size of one. */
974 buffer[0] = 0;
975 ret = p_wcslwr_s(buffer, 1);
976 ok(ret == 0, "got %d\n", ret);
977 ok(buffer[0] == 0, "expected buffer to be unchanged\n");
978
979 /* Test one-byte buffer with zero size. */
980 errno = EBADF;
981 buffer[0] = 'x';
982 ret = p_wcslwr_s(buffer, 0);
983 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
984 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
985 ok(buffer[0] == '\0', "expected empty string\n");
986
987 /* Test one-byte buffer with size of one. */
988 errno = EBADF;
989 buffer[0] = 'x';
990 ret = p_wcslwr_s(buffer, 1);
991 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
992 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
993 ok(buffer[0] == '\0', "expected empty string\n");
994
995 /* Test invalid size. */
996 wcscpy(buffer, mixedString);
997 errno = EBADF;
998 ret = p_wcslwr_s(buffer, 0);
999 ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
1000 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1001 ok(buffer[0] == '\0', "expected empty string\n");
1002
1003 /* Test normal string uppercasing. */
1004 wcscpy(buffer, mixedString);
1005 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR));
1006 ok(ret == 0, "expected 0, got %d\n", ret);
1007 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1008
1009 /* Test uppercasing with a shorter buffer size count. */
1010 wcscpy(buffer, mixedString);
1011 errno = EBADF;
1012 ret = p_wcslwr_s(buffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
1013 ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
1014 ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
1015 ok(buffer[0] == '\0', "expected empty string\n");
1016
1017 /* Test uppercasing with a longer buffer size count. */
1018 wcscpy(buffer, mixedString);
1019 ret = p_wcslwr_s(buffer, sizeof(buffer)/sizeof(WCHAR));
1020 ok(ret == 0, "expected 0, got %d\n", ret);
1021 ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
1022 }
1023
1024 static void test_mbcjisjms(void)
1025 {
1026 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1027 unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
1028 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
1029 {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
1030 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
1031 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1032 unsigned int i, j;
1033 int prev_cp = _getmbcp();
1034
1035 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1036 {
1037 _setmbcp(cp[i]);
1038 for (j = 0; jisjms[j][0] != 0; j++)
1039 {
1040 unsigned int ret, exp;
1041 ret = _mbcjistojms(jisjms[j][0]);
1042 exp = (cp[i] == 932) ? jisjms[j][1] : jisjms[j][0];
1043 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1044 exp, ret, jisjms[j][0], cp[i]);
1045 }
1046 }
1047 _setmbcp(prev_cp);
1048 }
1049
1050 static void test_mbcjmsjis(void)
1051 {
1052 /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
1053 unsigned int jmsjis[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
1054 {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
1055 {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
1056 {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
1057 {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
1058 {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
1059 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1060 unsigned int i, j;
1061 int prev_cp = _getmbcp();
1062
1063 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1064 {
1065 _setmbcp(cp[i]);
1066 for (j = 0; jmsjis[j][0] != 0; j++)
1067 {
1068 unsigned int ret, exp;
1069 ret = _mbcjmstojis(jmsjis[j][0]);
1070 exp = (cp[i] == 932) ? jmsjis[j][1] : jmsjis[j][0];
1071 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
1072 exp, ret, jmsjis[j][0], cp[i]);
1073 }
1074 }
1075 _setmbcp(prev_cp);
1076 }
1077
1078 static void test_mbbtombc(void)
1079 {
1080 static const unsigned int mbbmbc[][2] = {
1081 {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
1082 {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
1083 {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
1084 {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
1085 int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
1086 int i, j;
1087 int prev_cp = _getmbcp();
1088
1089 for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++)
1090 {
1091 _setmbcp(cp[i]);
1092 for (j = 0; mbbmbc[j][0] != 0; j++)
1093 {
1094 unsigned int exp, ret;
1095 ret = _mbbtombc(mbbmbc[j][0]);
1096 exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0];
1097 ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
1098 exp, ret, mbbmbc[j][0], cp[i]);
1099 }
1100 }
1101 _setmbcp(prev_cp);
1102 }
1103
1104 static void test_mbctombb(void)
1105 {
1106 static const unsigned int mbcmbb_932[][2] = {
1107 {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
1108 {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
1109 {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
1110 {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
1111 {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
1112 {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
1113 unsigned int exp, ret, i;
1114 unsigned int prev_cp = _getmbcp();
1115
1116 _setmbcp(932);
1117 for (i = 0; mbcmbb_932[i][0] != 0; i++)
1118 {
1119 ret = _mbctombb(mbcmbb_932[i][0]);
1120 exp = mbcmbb_932[i][1];
1121 ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
1122 }
1123 _setmbcp(prev_cp);
1124 }
1125
1126 static void test_ismbclegal(void) {
1127 unsigned int prev_cp = _getmbcp();
1128 int ret, exp, err;
1129 unsigned int i;
1130
1131 _setmbcp(932); /* Japanese */
1132 err = 0;
1133 for(i = 0; i < 0x10000; i++) {
1134 ret = _ismbclegal(i);
1135 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
1136 (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
1137 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1138 (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
1139 if(ret != exp) {
1140 err = 1;
1141 break;
1142 }
1143 }
1144 ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1145 _setmbcp(936); /* Chinese (GBK) */
1146 err = 0;
1147 for(i = 0; i < 0x10000; i++) {
1148 ret = _ismbclegal(i);
1149 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1150 LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
1151 if(ret != exp) {
1152 err = 1;
1153 break;
1154 }
1155 }
1156 ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1157 _setmbcp(949); /* Korean */
1158 err = 0;
1159 for(i = 0; i < 0x10000; i++) {
1160 ret = _ismbclegal(i);
1161 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1162 LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
1163 if(ret != exp) {
1164 err = 1;
1165 break;
1166 }
1167 }
1168 ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1169 _setmbcp(950); /* Chinese (Big5) */
1170 err = 0;
1171 for(i = 0; i < 0x10000; i++) {
1172 ret = _ismbclegal(i);
1173 exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
1174 ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
1175 (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
1176 if(ret != exp) {
1177 err = 1;
1178 break;
1179 }
1180 }
1181 ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1182 _setmbcp(1361); /* Korean (Johab) */
1183 err = 0;
1184 for(i = 0; i < 0x10000; i++) {
1185 ret = _ismbclegal(i);
1186 exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
1187 (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
1188 ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
1189 (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
1190 HIBYTE(i) != 0xDF;
1191 if(ret != exp) {
1192 err = 1;
1193 break;
1194 }
1195 }
1196 todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
1197
1198 _setmbcp(prev_cp);
1199 }
1200
1201 static const struct {
1202 const char* string;
1203 const char* delimiter;
1204 int exp_offsetret1; /* returned offset from string after first call to strtok()
1205 -1 means NULL */
1206 int exp_offsetret2; /* returned offset from string after second call to strtok()
1207 -1 means NULL */
1208 int exp_offsetret3; /* returned offset from string after third call to strtok()
1209 -1 means NULL */
1210 } testcases_strtok[] = {
1211 { "red cabernet", " ", 0, 4, -1 },
1212 { "sparkling white riesling", " ", 0, 10, 16 },
1213 { " pale cream sherry", "e ", 1, 6, 9 },
1214 /* end mark */
1215 { 0}
1216 };
1217
1218 static void test_strtok(void)
1219 {
1220 int i;
1221 char *strret;
1222 char teststr[100];
1223 for( i = 0; testcases_strtok[i].string; i++){
1224 strcpy( teststr, testcases_strtok[i].string);
1225 strret = strtok( teststr, testcases_strtok[i].delimiter);
1226 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
1227 (!strret && testcases_strtok[i].exp_offsetret1 == -1),
1228 "string (%p) \'%s\' return %p\n",
1229 teststr, testcases_strtok[i].string, strret);
1230 if( !strret) continue;
1231 strret = strtok( NULL, testcases_strtok[i].delimiter);
1232 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
1233 (!strret && testcases_strtok[i].exp_offsetret2 == -1),
1234 "second call string (%p) \'%s\' return %p\n",
1235 teststr, testcases_strtok[i].string, strret);
1236 if( !strret) continue;
1237 strret = strtok( NULL, testcases_strtok[i].delimiter);
1238 ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
1239 (!strret && testcases_strtok[i].exp_offsetret3 == -1),
1240 "third call string (%p) \'%s\' return %p\n",
1241 teststr, testcases_strtok[i].string, strret);
1242 }
1243 }
1244
1245 static void test_strtol(void)
1246 {
1247 char* e;
1248 LONG l;
1249 ULONG ul;
1250
1251 /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
1252 /* errno is modified on W2K8+ */
1253 errno = EBADF;
1254 l = strtol("-1234", &e, 0);
1255 ok(l==-1234, "wrong value %d\n", l);
1256 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1257 errno = EBADF;
1258 ul = strtoul("1234", &e, 0);
1259 ok(ul==1234, "wrong value %u\n", ul);
1260 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1261
1262 errno = EBADF;
1263 l = strtol("2147483647L", &e, 0);
1264 ok(l==2147483647, "wrong value %d\n", l);
1265 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1266 errno = EBADF;
1267 l = strtol("-2147483648L", &e, 0);
1268 ok(l==-2147483647L - 1, "wrong value %d\n", l);
1269 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1270 errno = EBADF;
1271 ul = strtoul("4294967295UL", &e, 0);
1272 ok(ul==4294967295ul, "wrong value %u\n", ul);
1273 ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
1274
1275 errno = 0;
1276 l = strtol("9223372036854775807L", &e, 0);
1277 ok(l==2147483647, "wrong value %d\n", l);
1278 ok(errno == ERANGE, "wrong errno %d\n", errno);
1279 errno = 0;
1280 ul = strtoul("9223372036854775807L", &e, 0);
1281 ok(ul==4294967295ul, "wrong value %u\n", ul);
1282 ok(errno == ERANGE, "wrong errno %d\n", errno);
1283 }
1284
1285 static void test_strnlen(void)
1286 {
1287 static const char str[] = "string";
1288 size_t res;
1289
1290 if(!p_strnlen) {
1291 win_skip("strnlen not found\n");
1292 return;
1293 }
1294
1295 res = p_strnlen(str, 20);
1296 ok(res == 6, "Returned length = %d\n", (int)res);
1297
1298 res = p_strnlen(str, 3);
1299 ok(res == 3, "Returned length = %d\n", (int)res);
1300
1301 res = p_strnlen(NULL, 0);
1302 ok(res == 0, "Returned length = %d\n", (int)res);
1303 }
1304
1305 static void test__strtoi64(void)
1306 {
1307 static const char no1[] = "31923";
1308 static const char no2[] = "-213312";
1309 static const char no3[] = "12aa";
1310 static const char no4[] = "abc12";
1311 static const char overflow[] = "99999999999999999999";
1312 static const char neg_overflow[] = "-99999999999999999999";
1313 static const char hex[] = "0x123";
1314 static const char oct[] = "000123";
1315 static const char blanks[] = " 12 212.31";
1316
1317 __int64 res;
1318 unsigned __int64 ures;
1319 char *endpos;
1320
1321 if(!p_strtoi64 || !p_strtoui64) {
1322 win_skip("_strtoi64 or _strtoui64 not found\n");
1323 return;
1324 }
1325
1326 errno = 0xdeadbeef;
1327 res = p_strtoi64(no1, NULL, 10);
1328 ok(res == 31923, "res != 31923\n");
1329 res = p_strtoi64(no2, NULL, 10);
1330 ok(res == -213312, "res != -213312\n");
1331 res = p_strtoi64(no3, NULL, 10);
1332 ok(res == 12, "res != 12\n");
1333 res = p_strtoi64(no4, &endpos, 10);
1334 ok(res == 0, "res != 0\n");
1335 ok(endpos == no4, "Scanning was not stopped on first character\n");
1336 res = p_strtoi64(hex, &endpos, 10);
1337 ok(res == 0, "res != 0\n");
1338 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1339 res = p_strtoi64(oct, &endpos, 10);
1340 ok(res == 123, "res != 123\n");
1341 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1342 res = p_strtoi64(blanks, &endpos, 10);
1343 ok(res == 12, "res != 12\n");
1344 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1345 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1346
1347 errno = 0xdeadbeef;
1348 res = p_strtoi64(overflow, &endpos, 10);
1349 ok(res == _I64_MAX, "res != _I64_MAX\n");
1350 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1351 ok(errno == ERANGE, "errno = %x\n", errno);
1352
1353 errno = 0xdeadbeef;
1354 res = p_strtoi64(neg_overflow, &endpos, 10);
1355 ok(res == _I64_MIN, "res != _I64_MIN\n");
1356 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1357 ok(errno == ERANGE, "errno = %x\n", errno);
1358
1359 errno = 0xdeadbeef;
1360 res = p_strtoi64(no1, &endpos, 16);
1361 ok(res == 203043, "res != 203043\n");
1362 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1363 res = p_strtoi64(no2, &endpos, 16);
1364 ok(res == -2175762, "res != -2175762\n");
1365 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1366 res = p_strtoi64(no3, &endpos, 16);
1367 ok(res == 4778, "res != 4778\n");
1368 ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
1369 res = p_strtoi64(no4, &endpos, 16);
1370 ok(res == 703506, "res != 703506\n");
1371 ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
1372 res = p_strtoi64(hex, &endpos, 16);
1373 ok(res == 291, "res != 291\n");
1374 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1375 res = p_strtoi64(oct, &endpos, 16);
1376 ok(res == 291, "res != 291\n");
1377 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1378 res = p_strtoi64(blanks, &endpos, 16);
1379 ok(res == 18, "res != 18\n");
1380 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1381 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1382
1383 errno = 0xdeadbeef;
1384 res = p_strtoi64(hex, &endpos, 36);
1385 ok(res == 1541019, "res != 1541019\n");
1386 ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
1387 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1388
1389 errno = 0xdeadbeef;
1390 res = p_strtoi64(no1, &endpos, 0);
1391 ok(res == 31923, "res != 31923\n");
1392 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1393 res = p_strtoi64(no2, &endpos, 0);
1394 ok(res == -213312, "res != -213312\n");
1395 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1396 res = p_strtoi64(no3, &endpos, 10);
1397 ok(res == 12, "res != 12\n");
1398 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1399 res = p_strtoi64(no4, &endpos, 10);
1400 ok(res == 0, "res != 0\n");
1401 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1402 res = p_strtoi64(hex, &endpos, 10);
1403 ok(res == 0, "res != 0\n");
1404 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1405 res = p_strtoi64(oct, &endpos, 10);
1406 ok(res == 123, "res != 123\n");
1407 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1408 res = p_strtoi64(blanks, &endpos, 10);
1409 ok(res == 12, "res != 12\n");
1410 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1411 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1412
1413 errno = 0xdeadbeef;
1414 ures = p_strtoui64(no1, &endpos, 0);
1415 ok(ures == 31923, "ures != 31923\n");
1416 ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
1417 ures = p_strtoui64(no2, &endpos, 0);
1418 ok(ures == -213312, "ures != -213312\n");
1419 ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
1420 ures = p_strtoui64(no3, &endpos, 10);
1421 ok(ures == 12, "ures != 12\n");
1422 ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
1423 ures = p_strtoui64(no4, &endpos, 10);
1424 ok(ures == 0, "ures != 0\n");
1425 ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
1426 ures = p_strtoui64(hex, &endpos, 10);
1427 ok(ures == 0, "ures != 0\n");
1428 ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
1429 ures = p_strtoui64(oct, &endpos, 10);
1430 ok(ures == 123, "ures != 123\n");
1431 ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
1432 ures = p_strtoui64(blanks, &endpos, 10);
1433 ok(ures == 12, "ures != 12\n");
1434 ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
1435 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
1436
1437 errno = 0xdeadbeef;
1438 ures = p_strtoui64(overflow, &endpos, 10);
1439 ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
1440 ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
1441 ok(errno == ERANGE, "errno = %x\n", errno);
1442
1443 errno = 0xdeadbeef;
1444 ures = p_strtoui64(neg_overflow, &endpos, 10);
1445 ok(ures == 1, "ures != 1\n");
1446 ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
1447 ok(errno == ERANGE, "errno = %x\n", errno);
1448 }
1449
1450 static inline BOOL almost_equal(double d1, double d2) {
1451 if(d1-d2>-1e-30 && d1-d2<1e-30)
1452 return TRUE;
1453 return FALSE;
1454 }
1455
1456 static void test__strtod(void)
1457 {
1458 const char double1[] = "12.1";
1459 const char double2[] = "-13.721";
1460 const char double3[] = "INF";
1461 const char double4[] = ".21e12";
1462 const char double5[] = "214353e-3";
1463 const char overflow[] = "1d9999999999999999999";
1464 const char white_chars[] = " d10";
1465
1466 char *end;
1467 double d;
1468
1469 d = strtod(double1, &end);
1470 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1471 ok(end == double1+4, "incorrect end (%d)\n", (int)(end-double1));
1472
1473 d = strtod(double2, &end);
1474 ok(almost_equal(d, -13.721), "d = %lf\n", d);
1475 ok(end == double2+7, "incorrect end (%d)\n", (int)(end-double2));
1476
1477 d = strtod(double3, &end);
1478 ok(almost_equal(d, 0), "d = %lf\n", d);
1479 ok(end == double3, "incorrect end (%d)\n", (int)(end-double3));
1480
1481 d = strtod(double4, &end);
1482 ok(almost_equal(d, 210000000000.0), "d = %lf\n", d);
1483 ok(end == double4+6, "incorrect end (%d)\n", (int)(end-double4));
1484
1485 d = strtod(double5, &end);
1486 ok(almost_equal(d, 214.353), "d = %lf\n", d);
1487 ok(end == double5+9, "incorrect end (%d)\n", (int)(end-double5));
1488
1489 d = strtod("12.1d2", NULL);
1490 ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
1491
1492 d = strtod(white_chars, &end);
1493 ok(almost_equal(d, 0), "d = %lf\n", d);
1494 ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
1495
1496 /* Set locale with non '.' decimal point (',') */
1497 if(!setlocale(LC_ALL, "Polish")) {
1498 win_skip("system with limited locales\n");
1499 return;
1500 }
1501
1502 d = strtod("12.1", NULL);
1503 ok(almost_equal(d, 12.0), "d = %lf\n", d);
1504
1505 d = strtod("12,1", NULL);
1506 ok(almost_equal(d, 12.1), "d = %lf\n", d);
1507
1508 setlocale(LC_ALL, "C");
1509
1510 /* Precision tests */
1511 d = strtod("0.1", NULL);
1512 ok(almost_equal(d, 0.1), "d = %lf\n", d);
1513 d = strtod("-0.1", NULL);
1514 ok(almost_equal(d, -0.1), "d = %lf\n", d);
1515 d = strtod("0.1281832188491894198128921", NULL);
1516 ok(almost_equal(d, 0.1281832188491894198128921), "d = %lf\n", d);
1517 d = strtod("0.82181281288121", NULL);
1518 ok(almost_equal(d, 0.82181281288121), "d = %lf\n", d);
1519 d = strtod("21921922352523587651128218821", NULL);
1520 ok(almost_equal(d, 21921922352523587651128218821.0), "d = %lf\n", d);
1521 d = strtod("0.1d238", NULL);
1522 ok(almost_equal(d, 0.1e238L), "d = %lf\n", d);
1523 d = strtod("0.1D-4736", NULL);
1524 ok(almost_equal(d, 0.1e-4736L), "d = %lf\n", d);
1525
1526 errno = 0xdeadbeef;
1527 strtod(overflow, &end);
1528 ok(errno == ERANGE, "errno = %x\n", errno);
1529 ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
1530
1531 errno = 0xdeadbeef;
1532 strtod("-1d309", NULL);
1533 ok(errno == ERANGE, "errno = %x\n", errno);
1534 }
1535
1536 static void test_mbstowcs(void)
1537 {
1538 static const wchar_t wSimple[] = { 't','e','x','t',0 };
1539 static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
1540 static const char mSimple[] = "text";
1541 static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
1542
1543 const wchar_t *pwstr;
1544 wchar_t wOut[6];
1545 char mOut[6];
1546 size_t ret;
1547 int err;
1548
1549 wOut[4] = '!'; wOut[5] = '\0';
1550 mOut[4] = '!'; mOut[5] = '\0';
1551
1552 ret = mbstowcs(NULL, mSimple, 0);
1553 ok(ret == 4, "mbstowcs did not return 4\n");
1554
1555 ret = mbstowcs(wOut, mSimple, 4);
1556 ok(ret == 4, "mbstowcs did not return 4\n");
1557 ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
1558 ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
1559
1560 ret = wcstombs(NULL, wSimple, 0);
1561 ok(ret == 4, "wcstombs did not return 4\n");
1562
1563 ret = wcstombs(mOut, wSimple, 6);
1564 ok(ret == 4, "wcstombs did not return 4\n");
1565 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1566
1567 ret = wcstombs(mOut, wSimple, 2);
1568 ok(ret == 2, "wcstombs did not return 2\n");
1569 ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
1570
1571 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
1572 win_skip("Japanese_Japan.932 locale not available\n");
1573 return;
1574 }
1575
1576 ret = mbstowcs(wOut, mHiragana, 6);
1577 ok(ret == 2, "mbstowcs did not return 2\n");
1578 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1579
1580 ret = wcstombs(mOut, wHiragana, 6);
1581 ok(ret == 4, "wcstombs did not return 4\n");
1582 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1583
1584 if(!pmbstowcs_s || !pwcstombs_s) {
1585 setlocale(LC_ALL, "C");
1586 win_skip("mbstowcs_s or wcstombs_s not available\n");
1587 return;
1588 }
1589
1590 err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
1591 ok(err == 0, "err = %d\n", err);
1592 ok(ret == 5, "mbstowcs_s did not return 5\n");
1593 ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
1594
1595 err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
1596 ok(err == 0, "err = %d\n", err);
1597 ok(ret == 3, "mbstowcs_s did not return 3\n");
1598 ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
1599
1600 err = pmbstowcs_s(&ret, NULL, 0, mHiragana, 1);
1601 ok(err == 0, "err = %d\n", err);
1602 ok(ret == 3, "mbstowcs_s did not return 3\n");
1603
1604 err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
1605 ok(err == 0, "err = %d\n", err);
1606 ok(ret == 5, "wcstombs_s did not return 5\n");
1607 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1608
1609 err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
1610 ok(err == 0, "err = %d\n", err);
1611 ok(ret == 5, "wcstombs_s did not return 5\n");
1612 ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
1613
1614 err = pwcstombs_s(&ret, NULL, 0, wHiragana, 1);
1615 ok(err == 0, "err = %d\n", err);
1616 ok(ret == 5, "wcstombs_s did not return 5\n");
1617
1618 if(!pwcsrtombs) {
1619 setlocale(LC_ALL, "C");
1620 win_skip("wcsrtombs not available\n");
1621 return;
1622 }
1623
1624 pwstr = wSimple;
1625 err = -3;
1626 ret = pwcsrtombs(mOut, &pwstr, 4, &err);
1627 ok(ret == 4, "wcsrtombs did not return 4\n");
1628 ok(err == 0, "err = %d\n", err);
1629 ok(pwstr == wSimple+4, "pwstr = %p (wszSimple = %p)\n", pwstr, wSimple);
1630 ok(!memcmp(mOut, mSimple, ret), "mOut = %s\n", mOut);
1631
1632 pwstr = wSimple;
1633 ret = pwcsrtombs(mOut, &pwstr, 5, NULL);
1634 ok(ret == 4, "wcsrtombs did not return 4\n");
1635 ok(pwstr == NULL, "pwstr != NULL\n");
1636 ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
1637
1638 setlocale(LC_ALL, "C");
1639 }
1640
1641 static void test_gcvt(void)
1642 {
1643 char buf[1024], *res;
1644 errno_t err;
1645
1646 if(!p_gcvt_s) {
1647 win_skip("Skipping _gcvt tests\n");
1648 return;
1649 }
1650
1651 errno = 0;
1652 res = _gcvt(1.2, -1, buf);
1653 ok(res == NULL, "res != NULL\n");
1654 ok(errno == ERANGE, "errno = %d\n", errno);
1655
1656 errno = 0;
1657 res = _gcvt(1.2, 5, NULL);
1658 ok(res == NULL, "res != NULL\n");
1659 ok(errno == EINVAL, "errno = %d\n", errno);
1660
1661 res = gcvt(1.2, 5, buf);
1662 ok(res == buf, "res != buf\n");
1663 ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
1664
1665 buf[0] = 'x';
1666 err = p_gcvt_s(buf, 5, 1.2, 10);
1667 ok(err == ERANGE, "err = %d\n", err);
1668 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1669
1670 buf[0] = 'x';
1671 err = p_gcvt_s(buf, 4, 123456, 2);
1672 ok(err == ERANGE, "err = %d\n", err);
1673 ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
1674 }
1675
1676 static void test__itoa_s(void)
1677 {
1678 errno_t ret;
1679 char buffer[33];
1680
1681 if (!p_itoa_s)
1682 {
1683 win_skip("Skipping _itoa_s tests\n");
1684 return;
1685 }
1686
1687 if (p_set_invalid_parameter_handler)
1688 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1689 "Invalid parameter handler was already set\n");
1690
1691 errno = EBADF;
1692 ret = p_itoa_s(0, NULL, 0, 0);
1693 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1694 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1695
1696 memset(buffer, 'X', sizeof(buffer));
1697 errno = EBADF;
1698 ret = p_itoa_s(0, buffer, 0, 0);
1699 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1700 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1701 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
1702
1703 memset(buffer, 'X', sizeof(buffer));
1704 errno = EBADF;
1705 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
1706 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1707 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1708 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1709
1710 memset(buffer, 'X', sizeof(buffer));
1711 errno = EBADF;
1712 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
1713 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
1714 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1715 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
1716
1717 memset(buffer, 'X', sizeof(buffer));
1718 errno = EBADF;
1719 ret = p_itoa_s(12345678, buffer, 4, 10);
1720 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1721 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1722 ok(!memcmp(buffer, "\000765", 4),
1723 "Expected the output buffer to be null terminated with truncated output\n");
1724
1725 memset(buffer, 'X', sizeof(buffer));
1726 errno = EBADF;
1727 ret = p_itoa_s(12345678, buffer, 8, 10);
1728 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1729 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1730 ok(!memcmp(buffer, "\0007654321", 8),
1731 "Expected the output buffer to be null terminated with truncated output\n");
1732
1733 memset(buffer, 'X', sizeof(buffer));
1734 errno = EBADF;
1735 ret = p_itoa_s(-12345678, buffer, 9, 10);
1736 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
1737 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1738 ok(!memcmp(buffer, "\00087654321", 9),
1739 "Expected the output buffer to be null terminated with truncated output\n");
1740
1741 ret = p_itoa_s(12345678, buffer, 9, 10);
1742 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1743 ok(!strcmp(buffer, "12345678"),
1744 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
1745 buffer);
1746
1747 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
1748 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1749 ok(!strcmp(buffer, "1010101010101010"),
1750 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
1751 buffer);
1752
1753 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
1754 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1755 ok(!strcmp(buffer, "nell"),
1756 "Expected output buffer string to be \"nell\", got \"%s\"\n",
1757 buffer);
1758
1759 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
1760 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1761 ok(!strcmp(buffer, "hag"),
1762 "Expected output buffer string to be \"hag\", got \"%s\"\n",
1763 buffer);
1764
1765 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
1766 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
1767 ok(!strcmp(buffer, "-12345678"),
1768 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
1769 buffer);
1770 if (p_set_invalid_parameter_handler)
1771 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1772 "Cannot reset invalid parameter handler\n");
1773 }
1774
1775 static void test__strlwr_s(void)
1776 {
1777 errno_t ret;
1778 char buffer[20];
1779
1780 if (!p_strlwr_s)
1781 {
1782 win_skip("Skipping _strlwr_s tests\n");
1783 return;
1784 }
1785
1786 errno = EBADF;
1787 ret = p_strlwr_s(NULL, 0);
1788 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1789 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1790
1791 errno = EBADF;
1792 ret = p_strlwr_s(NULL, sizeof(buffer));
1793 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1794 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1795
1796 errno = EBADF;
1797 ret = p_strlwr_s(buffer, 0);
1798 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1799 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1800
1801 strcpy(buffer, "GoRrIsTeR");
1802 errno = EBADF;
1803 ret = p_strlwr_s(buffer, 5);
1804 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1805 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1806 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1807 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1808
1809 strcpy(buffer, "GoRrIsTeR");
1810 errno = EBADF;
1811 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
1812 ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
1813 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1814 ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
1815 "Expected the output buffer to be \"\\0oRrIsTeR\"\n");
1816
1817 strcpy(buffer, "GoRrIsTeR");
1818 ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
1819 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1820 ok(!strcmp(buffer, "gorrister"),
1821 "Expected the output buffer to be \"gorrister\", got \"%s\"\n",
1822 buffer);
1823
1824 memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
1825 ret = p_strlwr_s(buffer, sizeof(buffer));
1826 ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
1827 ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
1828 "Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
1829 buffer);
1830 }
1831
1832 static void test_wcsncat_s(void)
1833 {
1834 static wchar_t abcW[] = {'a','b','c',0};
1835 int ret;
1836 wchar_t dst[4];
1837 wchar_t src[4];
1838
1839 if (!p_wcsncat_s)
1840 {
1841 win_skip("skipping wcsncat_s tests\n");
1842 return;
1843 }
1844
1845 if (p_set_invalid_parameter_handler)
1846 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
1847 "Invalid parameter handler was already set\n");
1848
1849 memcpy(src, abcW, sizeof(abcW));
1850 dst[0] = 0;
1851 ret = p_wcsncat_s(NULL, 4, src, 4);
1852 ok(ret == EINVAL, "err = %d\n", ret);
1853 ret = p_wcsncat_s(dst, 0, src, 4);
1854 ok(ret == EINVAL, "err = %d\n", ret);
1855 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
1856 ok(ret == EINVAL, "err = %d\n", ret);
1857 ret = p_wcsncat_s(dst, 4, NULL, 0);
1858 ok(ret == 0, "err = %d\n", ret);
1859
1860 dst[0] = 0;
1861 ret = p_wcsncat_s(dst, 2, src, 4);
1862 ok(ret == ERANGE, "err = %d\n", ret);
1863
1864 dst[0] = 0;
1865 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
1866 ok(ret == STRUNCATE, "err = %d\n", ret);
1867 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
1868
1869 memcpy(dst, abcW, sizeof(abcW));
1870 dst[3] = 'd';
1871 ret = p_wcsncat_s(dst, 4, src, 4);
1872 ok(ret == EINVAL, "err = %d\n", ret);
1873
1874 if (p_set_invalid_parameter_handler)
1875 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
1876 "Cannot reset invalid parameter handler\n");
1877 }
1878
1879 static void test__mbsnbcat_s(void)
1880 {
1881 unsigned char dest[16];
1882 const unsigned char first[] = "dinosaur";
1883 const unsigned char second[] = "duck";
1884 int ret;
1885
1886 if (!p_mbsnbcat_s)
1887 {
1888 win_skip("Skipping _mbsnbcat_s tests\n");
1889 return;
1890 }
1891
1892 /* Test invalid arguments. */
1893 ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
1894 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1895
1896 errno = EBADF;
1897 ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
1898 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1899 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1900
1901 errno = EBADF;
1902 ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
1903 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1904 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1905
1906 memset(dest, 'X', sizeof(dest));
1907 errno = EBADF;
1908 ret = p_mbsnbcat_s(dest, 0, NULL, 0);
1909 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1910 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1911 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1912
1913 memset(dest, 'X', sizeof(dest));
1914 errno = EBADF;
1915 ret = p_mbsnbcat_s(dest, 0, second, 0);
1916 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1917 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1918 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
1919
1920 memset(dest, 'X', sizeof(dest));
1921 errno = EBADF;
1922 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
1923 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1924 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1925 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1926
1927 memset(dest, 'X', sizeof(dest));
1928 errno = EBADF;
1929 ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
1930 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1931 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1932 ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
1933
1934 memset(dest, 'X', sizeof(dest));
1935 dest[0] = '\0';
1936 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1937 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1938 ok(!memcmp(dest, second, sizeof(second)),
1939 "Expected the output buffer string to be \"duck\"\n");
1940
1941 /* Test source truncation behavior. */
1942 memset(dest, 'X', sizeof(dest));
1943 memcpy(dest, first, sizeof(first));
1944 ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
1945 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1946 ok(!memcmp(dest, first, sizeof(first)),
1947 "Expected the output buffer string to be \"dinosaur\"\n");
1948
1949 memset(dest, 'X', sizeof(dest));
1950 memcpy(dest, first, sizeof(first));
1951 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
1952 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1953 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1954 "Expected the output buffer string to be \"dinosaurduck\"\n");
1955
1956 memset(dest, 'X', sizeof(dest));
1957 memcpy(dest, first, sizeof(first));
1958 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
1959 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1960 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1961 "Expected the output buffer string to be \"dinosaurduck\"\n");
1962
1963 memset(dest, 'X', sizeof(dest));
1964 memcpy(dest, first, sizeof(first));
1965 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
1966 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1967 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
1968 "Expected the output buffer string to be \"dinosaurduck\"\n");
1969
1970 memset(dest, 'X', sizeof(dest));
1971 memcpy(dest, first, sizeof(first));
1972 ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
1973 ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
1974 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
1975 "Expected the output buffer string to be \"dinosaurduc\"\n");
1976
1977 /* Test destination truncation behavior. */
1978 memset(dest, 'X', sizeof(dest));
1979 memcpy(dest, first, sizeof(first));
1980 errno = EBADF;
1981 ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
1982 ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
1983 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
1984 ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
1985 "Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
1986
1987 memset(dest, 'X', sizeof(dest));
1988 memcpy(dest, first, sizeof(first));
1989 errno = EBADF;
1990 ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
1991 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
1992 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
1993 ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
1994 "Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
1995
1996 memset(dest, 'X', sizeof(dest));
1997 memcpy(dest, first, sizeof(first));
1998 errno = EBADF;
1999 ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
2000 ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
2001 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2002 ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
2003 "Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
2004 }
2005
2006 static void test__mbsupr_s(void)
2007 {
2008 errno_t ret;
2009 unsigned char buffer[20];
2010
2011 if (!p_mbsupr_s)
2012 {
2013 win_skip("Skipping _mbsupr_s tests\n");
2014 return;
2015 }
2016
2017 errno = EBADF;
2018 ret = p_mbsupr_s(NULL, 0);
2019 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2020
2021 errno = EBADF;
2022 ret = p_mbsupr_s(NULL, sizeof(buffer));
2023 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2024 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2025
2026 errno = EBADF;
2027 ret = p_mbsupr_s(buffer, 0);
2028 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2029 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2030
2031 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2032 errno = EBADF;
2033 ret = p_mbsupr_s(buffer, sizeof("abcdefgh"));
2034 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2035 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2036 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2037 buffer);
2038
2039 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2040 errno = EBADF;
2041 ret = p_mbsupr_s(buffer, sizeof(buffer));
2042 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2043 ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
2044 "Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
2045 buffer);
2046
2047 memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
2048 errno = EBADF;
2049 ret = p_mbsupr_s(buffer, 4);
2050 ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
2051 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2052
2053 memcpy(buffer, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
2054 errno = EBADF;
2055 ret = p_mbsupr_s(buffer, sizeof(buffer));
2056 ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
2057 ok(!memcmp(buffer, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
2058 "Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
2059 buffer);
2060
2061 }
2062
2063 static void test__mbslwr_s(void)
2064 {
2065 errno_t ret;
2066 unsigned char buffer[20];
2067
2068 if (!p_mbslwr_s)
2069 {
2070 win_skip("Skipping _mbslwr_s tests\n");
2071 return;
2072 }
2073
2074 errno = EBADF;
2075 ret = p_mbslwr_s(NULL, 0);
2076 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2077
2078 errno = EBADF;
2079 ret = p_mbslwr_s(NULL, sizeof(buffer));
2080 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2081 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2082
2083 errno = EBADF;
2084 ret = p_mbslwr_s(buffer, 0);
2085 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2086 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2087
2088 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2089 errno = EBADF;
2090 ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH"));
2091 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2092 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2093 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2094 buffer);
2095
2096 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2097 errno = EBADF;
2098 ret = p_mbslwr_s(buffer, sizeof(buffer));
2099 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2100 ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
2101 "Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
2102 buffer);
2103
2104 memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
2105 errno = EBADF;
2106 ret = p_mbslwr_s(buffer, 4);
2107 ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
2108 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2109
2110 memcpy(buffer, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
2111 errno = EBADF;
2112 ret = p_mbslwr_s(buffer, sizeof(buffer));
2113 ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
2114 ok(!memcmp(buffer, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
2115 "Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
2116 buffer);
2117 }
2118
2119 static void test__ultoa_s(void)
2120 {
2121 errno_t ret;
2122 char buffer[33];
2123
2124 if (!p_ultoa_s)
2125 {
2126 win_skip("Skipping _ultoa_s tests\n");
2127 return;
2128 }
2129
2130 errno = EBADF;
2131 ret = p_ultoa_s(0, NULL, 0, 0);
2132 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2133 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2134
2135 memset(buffer, 'X', sizeof(buffer));
2136 errno = EBADF;
2137 ret = p_ultoa_s(0, buffer, 0, 0);
2138 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2139 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2140 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
2141
2142 memset(buffer, 'X', sizeof(buffer));
2143 errno = EBADF;
2144 ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
2145 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2146 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2147 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2148
2149 memset(buffer, 'X', sizeof(buffer));
2150 errno = EBADF;
2151 ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
2152 ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
2153 ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
2154 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
2155
2156 memset(buffer, 'X', sizeof(buffer));
2157 errno = EBADF;
2158 ret = p_ultoa_s(12345678, buffer, 4, 10);
2159 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2160 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2161 ok(!memcmp(buffer, "\000765", 4),
2162 "Expected the output buffer to be null terminated with truncated output\n");
2163
2164 memset(buffer, 'X', sizeof(buffer));
2165 errno = EBADF;
2166 ret = p_ultoa_s(12345678, buffer, 8, 10);
2167 ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
2168 ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
2169 ok(!memcmp(buffer, "\0007654321", 8),
2170 "Expected the output buffer to be null terminated with truncated output\n");
2171
2172 ret = p_ultoa_s(12345678, buffer, 9, 10);
2173 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2174 ok(!strcmp(buffer, "12345678"),
2175 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
2176 buffer);
2177
2178 ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
2179 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2180 ok(!strcmp(buffer, "1010101010101010"),
2181 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
2182 buffer);
2183
2184 ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
2185 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2186 ok(!strcmp(buffer, "nell"),
2187 "Expected output buffer string to be \"nell\", got \"%s\"\n",
2188 buffer);
2189
2190 ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
2191 ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
2192 ok(!strcmp(buffer, "hag"),
2193 "Expected output buffer string to be \"hag\", got \"%s\"\n",
2194 buffer);
2195 }
2196
2197 static void test_wctob(void)
2198 {
2199 int ret;
2200
2201 if(!p_wctob || !setlocale(LC_ALL, "chinese-traditional")) {
2202 win_skip("Skipping wctob tests\n");
2203 return;
2204 }
2205
2206 ret = p_wctob(0x8141);
2207 ok(ret == EOF, "ret = %x\n", ret);
2208
2209 ret = p_wctob(0x81);
2210 ok(ret == EOF, "ret = %x\n", ret);
2211
2212 ret = p_wctob(0xe0);
2213 ok(ret == 0x61, "ret = %x\n", ret);
2214
2215 _setmbcp(1250);
2216 ret = p_wctob(0x81);
2217 ok(ret == EOF, "ret = %x\n", ret);
2218
2219 setlocale(LC_ALL, "C");
2220 ret = p_wctob(0x8141);
2221 ok(ret == EOF, "ret = %x\n", ret);
2222
2223 ret = p_wctob(0x81);
2224 ok(ret == (int)(char)0x81, "ret = %x\n", ret);
2225
2226 ret = p_wctob(0x9f);
2227 ok(ret == (int)(char)0x9f, "ret = %x\n", ret);
2228
2229 ret = p_wctob(0xe0);
2230 ok(ret == (int)(char)0xe0, "ret = %x\n", ret);
2231 }
2232
2233 static void test_tolower(void)
2234 {
2235 int ret;
2236
2237 ret = p_tolower(0x41);
2238 ok(ret == 0x61, "ret = %x\n", ret);
2239
2240 ret = p_tolower(0xF4);
2241 ok(ret == 0xF4, "ret = %x\n", ret);
2242
2243 ret = p_tolower((char)0xF4);
2244 ok(ret==0xF4/*Vista+*/ || ret==(char)0xF4, "ret = %x\n", ret);
2245
2246 /* is it using different locale (CP_ACP) for negative values?? */
2247 /* current implementation matches msvcr90 behaviour */
2248 ret = p_tolower((char)0xD0);
2249 todo_wine ok(ret==0xF0/*Vista+*/ || ret==(char)0xD0, "ret = %x\n", ret);
2250
2251 ret = p_tolower(0xD0);
2252 ok(ret == 0xD0, "ret = %x\n", ret);
2253
2254 if(!setlocale(LC_ALL, "us")) {
2255 win_skip("skipping tolower tests that depends on locale\n");
2256 return;
2257 }
2258
2259 ret = p_tolower((char)0xD0);
2260 ok(ret == 0xF0, "ret = %x\n", ret);
2261
2262 ret = p_tolower(0xD0);
2263 ok(ret == 0xF0, "ret = %x\n", ret);
2264
2265 setlocale(LC_ALL, "C");
2266 }
2267
2268 START_TEST(string)
2269 {
2270 char mem[100];
2271 static const char xilstring[]="c:/xilinx";
2272 int nLen;
2273
2274 hMsvcrt = GetModuleHandleA("msvcrt.dll");
2275 if (!hMsvcrt)
2276 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
2277 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
2278 SET(pmemcpy,"memcpy");
2279 p_memcpy_s = (void*)GetProcAddress( hMsvcrt, "memcpy_s" );
2280 p_memmove_s = (void*)GetProcAddress( hMsvcrt, "memmove_s" );
2281 SET(pmemcmp,"memcmp");
2282 SET(p_mbctype,"_mbctype");
2283 SET(p__mb_cur_max,"__mb_cur_max");
2284 pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
2285 pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
2286 p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
2287 p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
2288 p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
2289 p_wcsncpy_s = (void *)GetProcAddress( hMsvcrt,"wcsncpy_s" );
2290 p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
2291 p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
2292 p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
2293 p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
2294 p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
2295 pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
2296 pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
2297 pwcsrtombs = (void *)GetProcAddress(hMsvcrt, "wcsrtombs");
2298 p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
2299 p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
2300 p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
2301 p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
2302 p_set_invalid_parameter_handler = (void *) GetProcAddress(hMsvcrt, "_set_invalid_parameter_handler");
2303 p_wcslwr_s = (void*)GetProcAddress(hMsvcrt, "_wcslwr_s");
2304 p_mbsupr_s = (void*)GetProcAddress(hMsvcrt, "_mbsupr_s");
2305 p_mbslwr_s = (void*)GetProcAddress(hMsvcrt, "_mbslwr_s");
2306 p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob");
2307 p_tolower = (void*)GetProcAddress(hMsvcrt, "tolower");
2308
2309 /* MSVCRT memcpy behaves like memmove for overlapping moves,
2310 MFC42 CString::Insert seems to rely on that behaviour */
2311 strcpy(mem,xilstring);
2312 nLen=strlen(xilstring);
2313 pmemcpy(mem+5, mem,nLen+1);
2314 ok(pmemcmp(mem+5,xilstring, nLen) == 0,
2315 "Got result %s\n",mem+5);
2316
2317 /* Test _swab function */
2318 test_swab();
2319
2320 /* Test ismbblead*/
2321 test_mbcp();
2322 /* test _mbsspn */
2323 test_mbsspn();
2324 test_mbsspnp();
2325 /* test _strdup */
2326 test_strdup();
2327 test_strcpy_s();
2328 test_memcpy_s();
2329 test_memmove_s();
2330 test_strcat_s();
2331 test__mbsnbcpy_s();
2332 test_mbcjisjms();
2333 test_mbcjmsjis();
2334 test_mbbtombc();
2335 test_mbctombb();
2336 test_ismbclegal();
2337 test_strtok();
2338 test_wcscpy_s();
2339 test__wcsupr_s();
2340 test_strtol();
2341 test_strnlen();
2342 test__strtoi64();
2343 test__strtod();
2344 test_mbstowcs();
2345 test_gcvt();
2346 test__itoa_s();
2347 test__strlwr_s();
2348 test_wcsncat_s();
2349 test__mbsnbcat_s();
2350 test__ultoa_s();
2351 test__wcslwr_s();
2352 test__mbsupr_s();
2353 test__mbslwr_s();
2354 test_wctob();
2355 test_tolower();
2356 }