mf/session: Forward more events to the application.
[wine/zf.git] / dlls / msvcr90 / tests / msvcr90.c
blob08cc4e9cf0e867a347cd743679142e101b8e6781
1 /*
2 * Copyright 2010 Detlef Riekenberg
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <math.h>
23 #include <fcntl.h>
24 #include <share.h>
25 #include <sys/stat.h>
26 #include <time.h>
27 #include <locale.h>
28 #include <fpieee.h>
29 #include <excpt.h>
31 #include <windef.h>
32 #include <winbase.h>
33 #include <errno.h>
34 #include "wine/test.h"
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 do { \
41 expect_ ## func = TRUE; \
42 errno = 0xdeadbeef; \
43 }while(0)
45 #define CHECK_EXPECT2(func) \
46 do { \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
49 }while(0)
51 #define CHECK_EXPECT(func) \
52 do { \
53 CHECK_EXPECT2(func); \
54 expect_ ## func = FALSE; \
55 }while(0)
57 #define CHECK_CALLED(func,error) \
58 do { \
59 ok(called_ ## func, "expected " #func "\n"); \
60 ok( errno == (error), "got errno %u instead of %u\n", errno, (error) ); \
61 expect_ ## func = called_ ## func = FALSE; \
62 }while(0)
64 DEFINE_EXPECT(invalid_parameter_handler);
66 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
67 typedef int (__cdecl *_INITTERM_E_FN)(void);
68 static int (__cdecl *p_initterm_e)(_INITTERM_E_FN *table, _INITTERM_E_FN *end);
69 static void* (__cdecl *p_encode_pointer)(void *);
70 static void* (__cdecl *p_decode_pointer)(void *);
71 static void* (__cdecl *p_encoded_null)(void);
72 static int *p_sys_nerr;
73 static int* (__cdecl *p__sys_nerr)(void);
74 static char **p_sys_errlist;
75 static char** (__cdecl *p__sys_errlist)(void);
76 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
77 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
78 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
79 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
80 static void (__cdecl *p_qsort_s)(void *, size_t, size_t, int (__cdecl *)(void *, const void *, const void *), void *);
81 static void* (__cdecl *p_bsearch_s)(const void *, const void *, size_t, size_t,
82 int (__cdecl *compare)(void *, const void *, const void *), void *);
83 static int (__cdecl *p_controlfp_s)(unsigned int *, unsigned int, unsigned int);
84 static int (__cdecl *p_tmpfile_s)(FILE**);
85 static int (__cdecl *p_atoflt)(_CRT_FLOAT *, char *);
86 static unsigned int (__cdecl *p_set_abort_behavior)(unsigned int, unsigned int);
87 static int (__cdecl *p_sopen_s)(int*, const char*, int, int, int);
88 static int (__cdecl *p_wsopen_s)(int*, const wchar_t*, int, int, int);
89 static void* (__cdecl *p_realloc_crt)(void*, size_t);
90 static void* (__cdecl *p_malloc)(size_t);
91 static void (__cdecl *p_free)(void*);
92 static void* (__cdecl *p_getptd)(void);
93 static int* (__cdecl *p_errno)(void);
94 static __msvcrt_ulong* (__cdecl *p_doserrno)(void);
95 static void (__cdecl *p_srand)(unsigned int);
96 static char* (__cdecl *p_strtok)(char*, const char*);
97 static char* (__cdecl *p_strtok_s)(char*, const char*, char**);
98 static wchar_t* (__cdecl *p_wcstok)(wchar_t*, const wchar_t*);
99 static unsigned char* (__cdecl *p__mbstok)(unsigned char*, const unsigned char*);
100 static unsigned char* (__cdecl *p__mbstok_s)(unsigned char*, const unsigned char*, unsigned char**);
101 static char* (__cdecl *p_strerror)(int);
102 static wchar_t* (__cdecl *p_wcserror)(int);
103 static char* (__cdecl *p_tmpnam)(char*);
104 static wchar_t* (__cdecl *p_wtmpnam)(wchar_t*);
105 static char* (__cdecl *p_asctime)(struct tm*);
106 static wchar_t* (__cdecl *p_wasctime)(struct tm*);
107 static struct tm* (__cdecl *p_localtime64)(__time64_t*);
108 static char* (__cdecl *p_ecvt)(double, int, int*, int*);
109 static int* (__cdecl *p_fpecode)(void);
110 static int (__cdecl *p_configthreadlocale)(int);
111 static void* (__cdecl *p_get_terminate)(void);
112 static void* (__cdecl *p_get_unexpected)(void);
113 static int (__cdecl *p__vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, __ms_va_list);
114 static int (__cdecl *p_vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, __ms_va_list);
115 static FILE* (__cdecl *p_fopen)(const char*, const char*);
116 static int (__cdecl *p_fclose)(FILE*);
117 static int (__cdecl *p_unlink)(const char*);
118 static int (__cdecl *p_access_s)(const char*, int);
119 static void (__cdecl *p_lock_file)(FILE*);
120 static void (__cdecl *p_unlock_file)(FILE*);
121 static int (__cdecl *p_fileno)(FILE*);
122 static int (__cdecl *p_feof)(FILE*);
123 static int (__cdecl *p_ferror)(FILE*);
124 static int (__cdecl *p_flsbuf)(int, FILE*);
125 static int (__cdecl *p_filbuf)(FILE*);
126 static unsigned long (__cdecl *p_byteswap_ulong)(unsigned long);
127 static void** (__cdecl *p__pxcptinfoptrs)(void);
128 static void* (__cdecl *p__AdjustPointer)(void*, const void*);
129 static int (__cdecl *p_fflush_nolock)(FILE*);
130 static size_t (__cdecl *p_mbstowcs)(wchar_t*, const char*, size_t);
131 static size_t (__cdecl *p_wcstombs)(char*, const wchar_t*, size_t);
132 static char* (__cdecl *p_setlocale)(int, const char*);
133 static int (__cdecl *p__setmbcp)(int);
134 static int (__cdecl *p__fpieee_flt)(ULONG, EXCEPTION_POINTERS*, int (__cdecl *handler)(_FPIEEE_RECORD*));
135 static int (__cdecl *p__memicmp)(const char*, const char*, size_t);
136 static int (__cdecl *p__memicmp_l)(const char*, const char*, size_t, _locale_t);
137 static int (__cdecl *p__vsnwprintf)(wchar_t *buffer,size_t count, const wchar_t *format, __ms_va_list valist);
138 static size_t (__cdecl *p___strncnt)(const char *str, size_t count);
139 static int (WINAPIV *p_swscanf)(const wchar_t *str, const wchar_t* format, ...);
140 static int (__cdecl *p____mb_cur_max_l_func)(_locale_t locale);
141 static _locale_t (__cdecl *p__create_locale)(int, const char*);
142 static void (__cdecl *p__free_locale)(_locale_t);
143 static _locale_t (__cdecl *p__get_current_locale)(void);
145 struct __lc_time_data {
146 const char *short_wday[7];
147 const char *wday[7];
148 const char *short_mon[12];
149 const char *mon[12];
150 const char *am;
151 const char *pm;
152 const char *short_date;
153 const char *date;
154 const char *time;
155 LCID lcid;
156 int unk;
157 int refcount;
160 /* make sure we use the correct errno */
161 #undef errno
162 #define errno (*p_errno())
164 typedef struct threadmbcinfostruct {
165 int refcount;
166 int mbcodepage;
167 int ismbcodepage;
168 int mblcid;
169 unsigned short mbulinfo[6];
170 unsigned char mbctype[257];
171 unsigned char mbcasemap[256];
172 } threadmbcinfo;
174 /* type info */
175 typedef struct __type_info
177 void *vtable;
178 char *name;
179 char mangled[16];
180 } type_info;
182 struct __type_info_node
184 void *memPtr;
185 struct __type_info_node* next;
188 static char* (WINAPI *p_type_info_name_internal_method)(type_info*, struct __type_info_node *);
189 static void (WINAPI *ptype_info_dtor)(type_info*);
191 #define CXX_FRAME_MAGIC_VC6 0x19930520
192 #define CXX_EXCEPTION 0xe06d7363
194 /* offsets for computing the this pointer */
195 typedef struct
197 int this_offset; /* offset of base class this pointer from start of object */
198 int vbase_descr; /* offset of virtual base class descriptor */
199 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
200 } this_ptr_offsets;
202 typedef void (*cxx_copy_ctor)(void);
204 /* complete information about a C++ type */
205 #ifndef __x86_64__
206 typedef struct __cxx_type_info
208 UINT flags; /* flags (see CLASS_* flags below) */
209 const type_info *type_info; /* C++ type info */
210 this_ptr_offsets offsets; /* offsets for computing the this pointer */
211 unsigned int size; /* object size */
212 cxx_copy_ctor copy_ctor; /* copy constructor */
213 } cxx_type_info;
214 #else
215 typedef struct __cxx_type_info
217 UINT flags;
218 unsigned int type_info;
219 this_ptr_offsets offsets;
220 unsigned int size;
221 unsigned int copy_ctor;
222 } cxx_type_info;
223 #endif
225 /* table of C++ types that apply for a given object */
226 #ifndef __x86_64__
227 typedef struct __cxx_type_info_table
229 UINT count; /* number of types */
230 const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
231 } cxx_type_info_table;
232 #else
233 typedef struct __cxx_type_info_table
235 UINT count;
236 unsigned int info[3];
237 } cxx_type_info_table;
238 #endif
240 /* type information for an exception object */
241 #ifndef __x86_64__
242 typedef struct __cxx_exception_type
244 UINT flags; /* TYPE_FLAG flags */
245 void (*destructor)(void);/* exception object destructor */
246 void *custom_handler; /* custom handler for this exception */
247 const cxx_type_info_table *type_info_table; /* list of types for this exception object */
248 } cxx_exception_type;
249 #else
250 typedef struct
252 UINT flags;
253 unsigned int destructor;
254 unsigned int custom_handler;
255 unsigned int type_info_table;
256 } cxx_exception_type;
257 #endif
259 static int (__cdecl *p_is_exception_typeof)(const type_info*, EXCEPTION_POINTERS*);
261 static void* (WINAPI *pEncodePointer)(void *);
263 static int cb_called[4];
264 static int g_qsort_s_context_counter;
265 static int g_bsearch_s_context_counter;
267 /* ########## */
269 /* thiscall emulation */
270 /* Emulate a __thiscall */
271 #ifdef __i386__
272 #ifdef _MSC_VER
273 static inline void* do_call_func1(void *func, void *_this)
275 volatile void* retval = 0;
276 __asm
278 push ecx
279 mov ecx, _this
280 call func
281 mov retval, eax
282 pop ecx
284 return (void*)retval;
287 static inline void* do_call_func2(void *func, void *_this, const void* arg)
289 volatile void* retval = 0;
290 __asm
292 push ecx
293 push arg
294 mov ecx, _this
295 call func
296 mov retval, eax
297 pop ecx
299 return (void*)retval;
301 #else
302 static void* do_call_func1(void *func, void *_this)
304 void *ret, *dummy;
305 __asm__ __volatile__ ("call *%2"
306 : "=a" (ret), "=c" (dummy)
307 : "g" (func), "1" (_this)
308 : "edx", "memory" );
309 return ret;
312 static void* do_call_func2(void *func, void *_this, const void* arg)
314 void *ret, *dummy;
315 __asm__ __volatile__ ("pushl %3\n\tcall *%2"
316 : "=a" (ret), "=c" (dummy)
317 : "r" (func), "r" (arg), "1" (_this)
318 : "edx", "memory" );
319 return ret;
321 #endif
323 #define call_func1(func,_this) do_call_func1(func,_this)
324 #define call_func2(func,_this,a) do_call_func2(func,_this,(const void*)(a))
326 #else
328 #define call_func1(func,_this) func(_this)
329 #define call_func2(func,_this,a) func(_this,a)
331 #endif /* __i386__ */
333 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
334 const wchar_t *function, const wchar_t *file,
335 unsigned line, uintptr_t arg)
337 CHECK_EXPECT(invalid_parameter_handler);
338 ok(expression == NULL, "expression is not NULL\n");
339 ok(function == NULL, "function is not NULL\n");
340 ok(file == NULL, "file is not NULL\n");
341 ok(line == 0, "line = %u\n", line);
342 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
343 ok(errno != 0xdeadbeef, "errno not set\n");
346 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
347 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
348 static BOOL init(void)
350 HMODULE hcrt;
351 HMODULE hkernel32;
353 SetLastError(0xdeadbeef);
354 hcrt = LoadLibraryA("msvcr90.dll");
355 if (!hcrt) {
356 win_skip("msvcr90.dll not installed (got %d)\n", GetLastError());
357 return FALSE;
360 SET(p_set_invalid_parameter_handler, "_set_invalid_parameter_handler");
361 if(p_set_invalid_parameter_handler)
362 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
363 "Invalid parameter handler was already set\n");
365 SET(p_initterm_e, "_initterm_e");
366 SET(p_encode_pointer, "_encode_pointer");
367 SET(p_decode_pointer, "_decode_pointer");
368 SET(p_encoded_null, "_encoded_null");
369 SET(p_sys_nerr, "_sys_nerr");
370 SET(p__sys_nerr, "__sys_nerr");
371 SET(p_sys_errlist, "_sys_errlist");
372 SET(p__sys_errlist, "__sys_errlist");
373 SET(p_strtoi64, "_strtoi64");
374 SET(p_strtoui64, "_strtoui64");
375 SET(p_itoa_s, "_itoa_s");
376 SET(p_wcsncat_s,"wcsncat_s" );
377 SET(p_qsort_s, "qsort_s");
378 SET(p_bsearch_s, "bsearch_s");
379 SET(p_controlfp_s, "_controlfp_s");
380 SET(p_tmpfile_s, "tmpfile_s");
381 SET(p_atoflt, "_atoflt");
382 SET(p_set_abort_behavior, "_set_abort_behavior");
383 SET(p_sopen_s, "_sopen_s");
384 SET(p_wsopen_s, "_wsopen_s");
385 SET(p_realloc_crt, "_realloc_crt");
386 SET(p_malloc, "malloc");
387 SET(p_free, "free");
388 SET(p_getptd, "_getptd");
389 SET(p_errno, "_errno");
390 SET(p_doserrno, "__doserrno");
391 SET(p_srand, "srand");
392 SET(p_strtok, "strtok");
393 SET(p_strtok_s, "strtok_s");
394 SET(p_wcstok, "wcstok");
395 SET(p__mbstok, "_mbstok");
396 SET(p__mbstok_s, "_mbstok_s");
397 SET(p_strerror, "strerror");
398 SET(p_wcserror, "_wcserror");
399 SET(p_tmpnam, "tmpnam");
400 SET(p_wtmpnam, "_wtmpnam");
401 SET(p_asctime, "asctime");
402 SET(p_wasctime, "_wasctime");
403 SET(p_localtime64, "_localtime64");
404 SET(p_ecvt, "_ecvt");
405 SET(p_fpecode, "__fpecode");
406 SET(p_configthreadlocale, "_configthreadlocale");
407 SET(p_get_terminate, "_get_terminate");
408 SET(p_get_unexpected, "_get_unexpected");
409 SET(p__vswprintf_l, "__vswprintf_l");
410 SET(p_vswprintf_l, "_vswprintf_l");
411 SET(p_fopen, "fopen");
412 SET(p_fclose, "fclose");
413 SET(p_unlink, "_unlink");
414 SET(p_access_s, "_access_s");
415 SET(p_lock_file, "_lock_file");
416 SET(p_unlock_file, "_unlock_file");
417 SET(p_fileno, "_fileno");
418 SET(p_feof, "feof");
419 SET(p_ferror, "ferror");
420 SET(p_flsbuf, "_flsbuf");
421 SET(p_filbuf, "_filbuf");
422 SET(p_byteswap_ulong, "_byteswap_ulong");
423 SET(p__pxcptinfoptrs, "__pxcptinfoptrs");
424 SET(p__AdjustPointer, "__AdjustPointer");
425 SET(p_fflush_nolock, "_fflush_nolock");
426 SET(p_mbstowcs, "mbstowcs");
427 SET(p_wcstombs, "wcstombs");
428 SET(p_setlocale, "setlocale");
429 SET(p__setmbcp, "_setmbcp");
430 SET(p__fpieee_flt, "_fpieee_flt");
431 SET(p__memicmp, "_memicmp");
432 SET(p__memicmp_l, "_memicmp_l");
433 SET(p__vsnwprintf, "_vsnwprintf");
434 SET(p___strncnt, "__strncnt");
435 SET(p_swscanf, "swscanf");
436 SET(p____mb_cur_max_l_func, "___mb_cur_max_l_func");
437 SET(p__create_locale, "_create_locale");
438 SET(p__free_locale, "_free_locale");
439 SET(p__get_current_locale, "_get_current_locale");
441 if (sizeof(void *) == 8)
443 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QEBAPEBDPEAU__type_info_node@@@Z");
444 SET(ptype_info_dtor, "??1type_info@@UEAA@XZ");
445 SET(p_is_exception_typeof, "?_is_exception_typeof@@YAHAEBVtype_info@@PEAU_EXCEPTION_POINTERS@@@Z");
447 else
449 #ifdef __arm__
450 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QBAPBDPAU__type_info_node@@@Z");
451 SET(ptype_info_dtor, "??1type_info@@UAA@XZ");
452 #else
453 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z");
454 SET(ptype_info_dtor, "??1type_info@@UAE@XZ");
455 #endif
456 SET(p_is_exception_typeof, "?_is_exception_typeof@@YAHABVtype_info@@PAU_EXCEPTION_POINTERS@@@Z");
459 hkernel32 = GetModuleHandleA("kernel32.dll");
460 pEncodePointer = (void *) GetProcAddress(hkernel32, "EncodePointer");
461 return TRUE;
464 static int __cdecl initterm_cb0(void)
466 cb_called[0]++;
467 return 0;
470 static int __cdecl initterm_cb1(void)
472 cb_called[1]++;
473 return 1;
476 static int __cdecl initterm_cb2(void)
478 cb_called[2]++;
479 return 2;
483 static void test__initterm_e(void)
485 _INITTERM_E_FN table[4];
486 int res;
488 memset(table, 0, sizeof(table));
490 memset(cb_called, 0, sizeof(cb_called));
491 errno = 0xdeadbeef;
492 res = p_initterm_e(table, table);
493 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
494 "got %d with 0x%x {%d, %d, %d}\n",
495 res, errno, cb_called[0], cb_called[1], cb_called[2]);
497 memset(cb_called, 0, sizeof(cb_called));
498 errno = 0xdeadbeef;
499 res = p_initterm_e(table, NULL);
500 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
501 "got %d with 0x%x {%d, %d, %d}\n",
502 res, errno, cb_called[0], cb_called[1], cb_called[2]);
504 if (0) {
505 /* this crash on Windows */
506 errno = 0xdeadbeef;
507 res = p_initterm_e(NULL, table);
508 trace("got %d with 0x%x\n", res, errno);
511 table[0] = initterm_cb0;
512 memset(cb_called, 0, sizeof(cb_called));
513 errno = 0xdeadbeef;
514 res = p_initterm_e(table, &table[1]);
515 ok( !res && (cb_called[0] == 1) && !cb_called[1] && !cb_called[2],
516 "got %d with 0x%x {%d, %d, %d}\n",
517 res, errno, cb_called[0], cb_called[1], cb_called[2]);
520 /* init-function returning failure */
521 table[1] = initterm_cb1;
522 memset(cb_called, 0, sizeof(cb_called));
523 errno = 0xdeadbeef;
524 res = p_initterm_e(table, &table[3]);
525 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
526 "got %d with 0x%x {%d, %d, %d}\n",
527 res, errno, cb_called[0], cb_called[1], cb_called[2]);
529 /* init-function not called, when end < start */
530 memset(cb_called, 0, sizeof(cb_called));
531 errno = 0xdeadbeef;
532 res = p_initterm_e(&table[3], table);
533 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
534 "got %d with 0x%x {%d, %d, %d}\n",
535 res, errno, cb_called[0], cb_called[1], cb_called[2]);
537 /* initialization stop after first non-zero result */
538 table[2] = initterm_cb0;
539 memset(cb_called, 0, sizeof(cb_called));
540 errno = 0xdeadbeef;
541 res = p_initterm_e(table, &table[3]);
542 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
543 "got %d with 0x%x {%d, %d, %d}\n",
544 res, errno, cb_called[0], cb_called[1], cb_called[2]);
546 /* NULL pointer in the array are skipped */
547 table[1] = NULL;
548 table[2] = initterm_cb2;
549 memset(cb_called, 0, sizeof(cb_called));
550 errno = 0xdeadbeef;
551 res = p_initterm_e(table, &table[3]);
552 ok( (res == 2) && (cb_called[0] == 1) && !cb_called[1] && (cb_called[2] == 1),
553 "got %d with 0x%x {%d, %d, %d}\n",
554 res, errno, cb_called[0], cb_called[1], cb_called[2]);
558 /* Beware that _encode_pointer is a NOP before XP
559 (the parameter is returned unchanged) */
560 static void test__encode_pointer(void)
562 void *ptr, *res;
564 ptr = (void*)0xdeadbeef;
565 res = p_encode_pointer(ptr);
566 res = p_decode_pointer(res);
567 ok(res == ptr, "Pointers are different after encoding and decoding\n");
569 ok(p_encoded_null() == p_encode_pointer(NULL), "Error encoding null\n");
571 ptr = p_encode_pointer(p_encode_pointer);
572 ok(p_decode_pointer(ptr) == p_encode_pointer, "Error decoding pointer\n");
574 /* Not present before XP */
575 if (!pEncodePointer) {
576 win_skip("EncodePointer not found\n");
577 return;
580 res = pEncodePointer(p_encode_pointer);
581 ok(ptr == res, "_encode_pointer produced different result than EncodePointer\n");
585 static void test_error_messages(void)
587 int *size, size_copy;
589 size = p__sys_nerr();
590 size_copy = *size;
591 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
593 *size = 20;
594 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
596 *size = size_copy;
598 ok(*p_sys_errlist == *(p__sys_errlist()), "p_sys_errlist != p__sys_errlist()\n");
601 static void test__strtoi64(void)
603 __int64 res;
604 unsigned __int64 ures;
606 SET_EXPECT(invalid_parameter_handler);
607 res = p_strtoi64(NULL, NULL, 10);
608 ok(res == 0, "res != 0\n");
609 CHECK_CALLED(invalid_parameter_handler, EINVAL);
611 SET_EXPECT(invalid_parameter_handler);
612 res = p_strtoi64("123", NULL, 1);
613 ok(res == 0, "res != 0\n");
614 CHECK_CALLED(invalid_parameter_handler, EINVAL);
616 SET_EXPECT(invalid_parameter_handler);
617 res = p_strtoi64("123", NULL, 37);
618 ok(res == 0, "res != 0\n");
619 CHECK_CALLED(invalid_parameter_handler, EINVAL);
621 SET_EXPECT(invalid_parameter_handler);
622 ures = p_strtoui64(NULL, NULL, 10);
623 ok(ures == 0, "res = %d\n", (int)ures);
624 CHECK_CALLED(invalid_parameter_handler, EINVAL);
626 SET_EXPECT(invalid_parameter_handler);
627 ures = p_strtoui64("123", NULL, 1);
628 ok(ures == 0, "res = %d\n", (int)ures);
629 CHECK_CALLED(invalid_parameter_handler, EINVAL);
631 SET_EXPECT(invalid_parameter_handler);
632 ures = p_strtoui64("123", NULL, 37);
633 ok(ures == 0, "res = %d\n", (int)ures);
634 CHECK_CALLED(invalid_parameter_handler, EINVAL);
637 static void test__itoa_s(void)
639 errno_t ret;
640 char buffer[33];
642 SET_EXPECT(invalid_parameter_handler);
643 ret = p_itoa_s(0, NULL, 0, 0);
644 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
645 CHECK_CALLED(invalid_parameter_handler, EINVAL);
647 memset(buffer, 'X', sizeof(buffer));
648 SET_EXPECT(invalid_parameter_handler);
649 ret = p_itoa_s(0, buffer, 0, 0);
650 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
651 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
652 CHECK_CALLED(invalid_parameter_handler, EINVAL);
654 memset(buffer, 'X', sizeof(buffer));
655 SET_EXPECT(invalid_parameter_handler);
656 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
657 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
658 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
659 CHECK_CALLED(invalid_parameter_handler, EINVAL);
661 memset(buffer, 'X', sizeof(buffer));
662 SET_EXPECT(invalid_parameter_handler);
663 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
664 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
665 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
666 CHECK_CALLED(invalid_parameter_handler, EINVAL);
668 memset(buffer, 'X', sizeof(buffer));
669 SET_EXPECT(invalid_parameter_handler);
670 ret = p_itoa_s(12345678, buffer, 4, 10);
671 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
672 ok(!memcmp(buffer, "\000765", 4),
673 "Expected the output buffer to be null terminated with truncated output\n");
674 CHECK_CALLED(invalid_parameter_handler, ERANGE);
676 memset(buffer, 'X', sizeof(buffer));
677 SET_EXPECT(invalid_parameter_handler);
678 ret = p_itoa_s(12345678, buffer, 8, 10);
679 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
680 ok(!memcmp(buffer, "\0007654321", 8),
681 "Expected the output buffer to be null terminated with truncated output\n");
682 CHECK_CALLED(invalid_parameter_handler, ERANGE);
684 memset(buffer, 'X', sizeof(buffer));
685 SET_EXPECT(invalid_parameter_handler);
686 ret = p_itoa_s(-12345678, buffer, 9, 10);
687 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
688 ok(!memcmp(buffer, "\00087654321", 9),
689 "Expected the output buffer to be null terminated with truncated output\n");
690 CHECK_CALLED(invalid_parameter_handler, ERANGE);
692 ret = p_itoa_s(12345678, buffer, 9, 10);
693 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
694 ok(!strcmp(buffer, "12345678"),
695 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
696 buffer);
698 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
699 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
700 ok(!strcmp(buffer, "1010101010101010"),
701 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
702 buffer);
704 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
705 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
706 ok(!strcmp(buffer, "nell"),
707 "Expected output buffer string to be \"nell\", got \"%s\"\n",
708 buffer);
710 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
711 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
712 ok(!strcmp(buffer, "hag"),
713 "Expected output buffer string to be \"hag\", got \"%s\"\n",
714 buffer);
716 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
717 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
718 ok(!strcmp(buffer, "-12345678"),
719 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
720 buffer);
723 static void test_wcsncat_s(void)
725 int ret;
726 wchar_t dst[4];
727 wchar_t src[4];
729 wcscpy(src, L"abc");
730 dst[0] = 0;
731 SET_EXPECT(invalid_parameter_handler);
732 ret = p_wcsncat_s(NULL, 4, src, 4);
733 ok(ret == EINVAL, "err = %d\n", ret);
734 CHECK_CALLED(invalid_parameter_handler, EINVAL);
736 SET_EXPECT(invalid_parameter_handler);
737 ret = p_wcsncat_s(dst, 0, src, 4);
738 ok(ret == EINVAL, "err = %d\n", ret);
739 CHECK_CALLED(invalid_parameter_handler, EINVAL);
741 SET_EXPECT(invalid_parameter_handler);
742 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
743 ok(ret == EINVAL, "err = %d\n", ret);
744 CHECK_CALLED(invalid_parameter_handler, EINVAL);
746 ret = p_wcsncat_s(dst, 4, NULL, 0);
747 ok(ret == 0, "err = %d\n", ret);
749 dst[0] = 0;
750 SET_EXPECT(invalid_parameter_handler);
751 ret = p_wcsncat_s(dst, 2, src, 4);
752 ok(ret == ERANGE, "err = %d\n", ret);
753 CHECK_CALLED(invalid_parameter_handler, ERANGE);
755 dst[0] = 0;
756 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
757 ok(ret == STRUNCATE, "err = %d\n", ret);
758 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
760 memcpy(dst, L"abcd", 4 * sizeof(wchar_t));
761 SET_EXPECT(invalid_parameter_handler);
762 ret = p_wcsncat_s(dst, 4, src, 4);
763 ok(ret == EINVAL, "err = %d\n", ret);
764 CHECK_CALLED(invalid_parameter_handler, EINVAL);
767 /* Based on dlls/ntdll/tests/string.c */
768 static __cdecl int intcomparefunc(void *context, const void *a, const void *b)
770 const int *p = a, *q = b;
772 ok (a != b, "must never get the same pointer\n");
773 ++*(int *) context;
775 return *p - *q;
778 static __cdecl int charcomparefunc(void *context, const void *a, const void *b)
780 const char *p = a, *q = b;
782 ok (a != b, "must never get the same pointer\n");
783 ++*(int *) context;
785 return *p - *q;
788 static __cdecl int strcomparefunc(void *context, const void *a, const void *b)
790 const char * const *p = a;
791 const char * const *q = b;
793 ok (a != b, "must never get the same pointer\n");
794 ++*(int *) context;
796 return lstrcmpA(*p, *q);
799 static void test_qsort_s(void)
801 int arr[5] = { 23, 42, 8, 4, 16 };
802 int arr2[5] = { 23, 42, 8, 4, 16 };
803 char carr[5] = { 42, 23, 4, 8, 16 };
804 const char *strarr[7] = {
805 "Hello",
806 "Wine",
807 "World",
808 "!",
809 "Hopefully",
810 "Sorted",
814 SET_EXPECT(invalid_parameter_handler);
815 p_qsort_s(NULL, 0, 0, NULL, NULL);
816 CHECK_CALLED(invalid_parameter_handler, EINVAL);
818 SET_EXPECT(invalid_parameter_handler);
819 p_qsort_s(NULL, 0, 0, intcomparefunc, NULL);
820 CHECK_CALLED(invalid_parameter_handler, EINVAL);
822 SET_EXPECT(invalid_parameter_handler);
823 p_qsort_s(NULL, 0, sizeof(int), NULL, NULL);
824 CHECK_CALLED(invalid_parameter_handler, EINVAL);
826 SET_EXPECT(invalid_parameter_handler);
827 p_qsort_s(NULL, 1, sizeof(int), intcomparefunc, NULL);
828 CHECK_CALLED(invalid_parameter_handler, EINVAL);
830 errno = 0xdeadbeef;
831 g_qsort_s_context_counter = 0;
832 p_qsort_s(NULL, 0, sizeof(int), intcomparefunc, NULL);
833 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
834 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
836 /* overflow without side effects, other overflow values crash */
837 errno = 0xdeadbeef;
838 g_qsort_s_context_counter = 0;
839 p_qsort_s((void*)arr2, (((size_t)1) << (8*sizeof(size_t) - 1)) + 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
840 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
841 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
842 ok(arr2[0] == 23, "should remain unsorted, arr2[0] is %d\n", arr2[0]);
843 ok(arr2[1] == 42, "should remain unsorted, arr2[1] is %d\n", arr2[1]);
844 ok(arr2[2] == 8, "should remain unsorted, arr2[2] is %d\n", arr2[2]);
845 ok(arr2[3] == 4, "should remain unsorted, arr2[3] is %d\n", arr2[3]);
847 errno = 0xdeadbeef;
848 g_qsort_s_context_counter = 0;
849 p_qsort_s((void*)arr, 0, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
850 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
851 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
852 ok(arr[0] == 23, "badly sorted, nmemb=0, arr[0] is %d\n", arr[0]);
853 ok(arr[1] == 42, "badly sorted, nmemb=0, arr[1] is %d\n", arr[1]);
854 ok(arr[2] == 8, "badly sorted, nmemb=0, arr[2] is %d\n", arr[2]);
855 ok(arr[3] == 4, "badly sorted, nmemb=0, arr[3] is %d\n", arr[3]);
856 ok(arr[4] == 16, "badly sorted, nmemb=0, arr[4] is %d\n", arr[4]);
858 errno = 0xdeadbeef;
859 g_qsort_s_context_counter = 0;
860 p_qsort_s((void*)arr, 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
861 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
862 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
863 ok(arr[0] == 23, "badly sorted, nmemb=1, arr[0] is %d\n", arr[0]);
864 ok(arr[1] == 42, "badly sorted, nmemb=1, arr[1] is %d\n", arr[1]);
865 ok(arr[2] == 8, "badly sorted, nmemb=1, arr[2] is %d\n", arr[2]);
866 ok(arr[3] == 4, "badly sorted, nmemb=1, arr[3] is %d\n", arr[3]);
867 ok(arr[4] == 16, "badly sorted, nmemb=1, arr[4] is %d\n", arr[4]);
869 SET_EXPECT(invalid_parameter_handler);
870 g_qsort_s_context_counter = 0;
871 p_qsort_s((void*)arr, 5, 0, intcomparefunc, &g_qsort_s_context_counter);
872 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
873 ok(arr[0] == 23, "badly sorted, size=0, arr[0] is %d\n", arr[0]);
874 ok(arr[1] == 42, "badly sorted, size=0, arr[1] is %d\n", arr[1]);
875 ok(arr[2] == 8, "badly sorted, size=0, arr[2] is %d\n", arr[2]);
876 ok(arr[3] == 4, "badly sorted, size=0, arr[3] is %d\n", arr[3]);
877 ok(arr[4] == 16, "badly sorted, size=0, arr[4] is %d\n", arr[4]);
878 CHECK_CALLED(invalid_parameter_handler, EINVAL);
880 g_qsort_s_context_counter = 0;
881 p_qsort_s((void*)arr, 5, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
882 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
883 ok(arr[0] == 4, "badly sorted, arr[0] is %d\n", arr[0]);
884 ok(arr[1] == 8, "badly sorted, arr[1] is %d\n", arr[1]);
885 ok(arr[2] == 16, "badly sorted, arr[2] is %d\n", arr[2]);
886 ok(arr[3] == 23, "badly sorted, arr[3] is %d\n", arr[3]);
887 ok(arr[4] == 42, "badly sorted, arr[4] is %d\n", arr[4]);
889 g_qsort_s_context_counter = 0;
890 p_qsort_s((void*)carr, 5, sizeof(char), charcomparefunc, &g_qsort_s_context_counter);
891 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
892 ok(carr[0] == 4, "badly sorted, carr[0] is %d\n", carr[0]);
893 ok(carr[1] == 8, "badly sorted, carr[1] is %d\n", carr[1]);
894 ok(carr[2] == 16, "badly sorted, carr[2] is %d\n", carr[2]);
895 ok(carr[3] == 23, "badly sorted, carr[3] is %d\n", carr[3]);
896 ok(carr[4] == 42, "badly sorted, carr[4] is %d\n", carr[4]);
898 g_qsort_s_context_counter = 0;
899 p_qsort_s((void*)strarr, 7, sizeof(char*), strcomparefunc, &g_qsort_s_context_counter);
900 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
901 ok(!strcmp(strarr[0],"!"), "badly sorted, strarr[0] is %s\n", strarr[0]);
902 ok(!strcmp(strarr[1],"."), "badly sorted, strarr[1] is %s\n", strarr[1]);
903 ok(!strcmp(strarr[2],"Hello"), "badly sorted, strarr[2] is %s\n", strarr[2]);
904 ok(!strcmp(strarr[3],"Hopefully"), "badly sorted, strarr[3] is %s\n", strarr[3]);
905 ok(!strcmp(strarr[4],"Sorted"), "badly sorted, strarr[4] is %s\n", strarr[4]);
906 ok(!strcmp(strarr[5],"Wine"), "badly sorted, strarr[5] is %s\n", strarr[5]);
907 ok(!strcmp(strarr[6],"World"), "badly sorted, strarr[6] is %s\n", strarr[6]);
910 static void test_bsearch_s(void)
912 int arr[7] = { 1, 3, 4, 8, 16, 23, 42 };
913 int *x, l, i, j = 1;
915 SET_EXPECT(invalid_parameter_handler);
916 x = p_bsearch_s(NULL, NULL, 0, 0, NULL, NULL);
917 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
918 CHECK_CALLED(invalid_parameter_handler, EINVAL);
920 g_bsearch_s_context_counter = 0;
921 SET_EXPECT(invalid_parameter_handler);
922 x = p_bsearch_s(&l, arr, j, 0, intcomparefunc, &g_bsearch_s_context_counter);
923 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
924 ok(g_bsearch_s_context_counter == 0, "callback shouldn't have been called\n");
925 CHECK_CALLED(invalid_parameter_handler, EINVAL);
927 g_bsearch_s_context_counter = 0;
928 SET_EXPECT(invalid_parameter_handler);
929 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), NULL, &g_bsearch_s_context_counter);
930 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
931 ok(g_bsearch_s_context_counter == 0, "callback shouldn't have been called\n");
932 CHECK_CALLED(invalid_parameter_handler, EINVAL);
934 /* just try all array sizes */
935 for (j=1; j<ARRAY_SIZE(arr); j++) {
936 for (i=0;i<j;i++) {
937 l = arr[i];
938 g_bsearch_s_context_counter = 0;
939 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), intcomparefunc, &g_bsearch_s_context_counter);
940 ok (x == &arr[i], "bsearch_s did not find %d entry in loopsize %d.\n", i, j);
941 ok(g_bsearch_s_context_counter > 0, "callback wasn't called\n");
943 l = 4242;
944 g_bsearch_s_context_counter = 0;
945 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), intcomparefunc, &g_bsearch_s_context_counter);
946 ok (x == NULL, "bsearch_s did find 4242 entry in loopsize %d.\n", j);
947 ok(g_bsearch_s_context_counter > 0, "callback wasn't called\n");
951 static void test_controlfp_s(void)
953 unsigned int cur;
954 int ret;
956 SET_EXPECT(invalid_parameter_handler);
957 ret = p_controlfp_s( NULL, ~0, ~0 );
958 ok( ret == EINVAL, "wrong result %d\n", ret );
959 CHECK_CALLED(invalid_parameter_handler, EINVAL);
961 cur = 0xdeadbeef;
962 SET_EXPECT(invalid_parameter_handler);
963 ret = p_controlfp_s( &cur, ~0, ~0 );
964 ok( ret == EINVAL, "wrong result %d\n", ret );
965 ok( cur != 0xdeadbeef, "value not set\n" );
966 CHECK_CALLED(invalid_parameter_handler, EINVAL);
968 cur = 0xdeadbeef;
969 ret = p_controlfp_s( &cur, 0, 0 );
970 ok( !ret, "wrong result %d\n", ret );
971 ok( cur != 0xdeadbeef, "value not set\n" );
973 SET_EXPECT(invalid_parameter_handler);
974 cur = 0xdeadbeef;
975 ret = p_controlfp_s( &cur, 0x80000000, 0x80000000 );
976 ok( ret == EINVAL, "wrong result %d\n", ret );
977 ok( cur != 0xdeadbeef, "value not set\n" );
978 CHECK_CALLED(invalid_parameter_handler, EINVAL);
980 cur = 0xdeadbeef;
981 /* mask is only checked when setting invalid bits */
982 ret = p_controlfp_s( &cur, 0, 0x80000000 );
983 ok( !ret, "wrong result %d\n", ret );
984 ok( cur != 0xdeadbeef, "value not set\n" );
987 static void test_tmpfile_s( void )
989 int ret;
991 SET_EXPECT(invalid_parameter_handler);
992 ret = p_tmpfile_s(NULL);
993 ok(ret == EINVAL, "Expected tmpfile_s to return EINVAL, got %i\n", ret);
994 CHECK_CALLED(invalid_parameter_handler, EINVAL);
997 typedef struct
999 const char *str;
1000 float flt;
1001 int ret;
1002 } _atoflt_test;
1004 static const _atoflt_test _atoflt_testdata[] = {
1005 { "12.1", 12.1, 0 },
1006 { "-13.721", -13.721, 0 },
1007 { "INF", 0.0, 0 },
1008 { ".21e12", 0.21e12, 0 },
1009 { "214353e-3", 214.353, 0 },
1010 { "1d9999999999999999999", 0.0, _OVERFLOW },
1011 { " d10", 0.0, 0 },
1012 /* more significant digits */
1013 { "1.23456789", 1.23456789, 0 },
1014 { "1.23456789e1", 12.3456789, 0 },
1015 { "1e39", 0.0, _OVERFLOW },
1016 { "1e-39", 0.0, _UNDERFLOW },
1017 { NULL }
1020 static void test__atoflt(void)
1022 _CRT_FLOAT flt;
1023 int ret, i = 0;
1025 if (0)
1027 /* crashes on native */
1028 p_atoflt(NULL, NULL);
1029 p_atoflt(NULL, (char*)_atoflt_testdata[0].str);
1030 p_atoflt(&flt, NULL);
1033 while (_atoflt_testdata[i].str)
1035 ret = p_atoflt(&flt, (char*)_atoflt_testdata[i].str);
1036 ok(ret == _atoflt_testdata[i].ret, "got ret %d, expected ret %d, for %s\n", ret,
1037 _atoflt_testdata[i].ret, _atoflt_testdata[i].str);
1039 if (ret == 0)
1040 ok(flt.f == _atoflt_testdata[i].flt, "got %f, expected %f, for %s\n", flt.f,
1041 _atoflt_testdata[i].flt, _atoflt_testdata[i].str);
1043 i++;
1047 static void test__set_abort_behavior(void)
1049 unsigned int res;
1051 /* default is _WRITE_ABORT_MSG | _CALL_REPORTFAULT */
1052 res = p_set_abort_behavior(0, 0);
1053 ok (res == (_WRITE_ABORT_MSG | _CALL_REPORTFAULT),
1054 "got 0x%x (expected 0x%x)\n", res, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
1056 /* no internal mask */
1057 p_set_abort_behavior(0xffffffff, 0xffffffff);
1058 res = p_set_abort_behavior(0, 0);
1059 ok (res == 0xffffffff, "got 0x%x (expected 0x%x)\n", res, 0xffffffff);
1061 /* set to default value */
1062 p_set_abort_behavior(_WRITE_ABORT_MSG | _CALL_REPORTFAULT, 0xffffffff);
1065 static void test__sopen_s(void)
1067 int ret, fd;
1069 SET_EXPECT(invalid_parameter_handler);
1070 ret = p_sopen_s(NULL, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1071 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
1072 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1074 fd = 0xdead;
1075 ret = p_sopen_s(&fd, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1076 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
1077 ok(fd == -1, "got %d\n", fd);
1080 static void test__wsopen_s(void)
1082 int ret, fd;
1084 SET_EXPECT(invalid_parameter_handler);
1085 ret = p_wsopen_s(NULL, L"test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1086 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
1087 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1089 fd = 0xdead;
1090 ret = p_wsopen_s(&fd, L"test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1091 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
1092 ok(fd == -1, "got %d\n", fd);
1095 static void test__realloc_crt(void)
1097 void *mem;
1099 if (0)
1101 /* crashes on some systems starting Vista */
1102 p_realloc_crt(NULL, 10);
1105 mem = p_malloc(10);
1106 ok(mem != NULL, "memory not allocated\n");
1108 mem = p_realloc_crt(mem, 20);
1109 ok(mem != NULL, "memory not reallocated\n");
1111 mem = p_realloc_crt(mem, 0);
1112 ok(mem == NULL, "memory not freed\n");
1114 mem = p_realloc_crt(NULL, 0);
1115 ok(mem != NULL, "memory not (re)allocated for size 0\n");
1116 p_free(mem);
1119 static void test_typeinfo(void)
1121 static type_info t1 = { NULL, NULL,{'.','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
1122 struct __type_info_node node;
1123 char *name;
1125 /* name */
1126 t1.name = NULL;
1127 node.memPtr = NULL;
1128 node.next = NULL;
1129 name = call_func2(p_type_info_name_internal_method, &t1, &node);
1130 ok(name != NULL, "got %p\n", name);
1131 ok(name && t1.name && !strcmp(name, t1.name), "bad name '%s' for t1\n", name);
1133 ok(t1.name && !strcmp(t1.name, "class test1"), "demangled to '%s' for t1\n", t1.name);
1134 call_func1(ptype_info_dtor, &t1);
1137 /* Keep in sync with msvcrt/msvcrt.h */
1138 struct __thread_data {
1139 DWORD tid;
1140 HANDLE handle;
1141 int thread_errno;
1142 __msvcrt_ulong thread_doserrno;
1143 int unk1;
1144 unsigned int random_seed;
1145 char *strtok_next;
1146 wchar_t *wcstok_next;
1147 unsigned char *mbstok_next;
1148 char *strerror_buffer;
1149 wchar_t *wcserror_buffer;
1150 char *tmpnam_buffer;
1151 wchar_t *wtmpnam_buffer;
1152 void *unk2[2];
1153 char *asctime_buffer;
1154 wchar_t *wasctime_buffer;
1155 struct tm *time_buffer;
1156 char *efcvt_buffer;
1157 int unk3[2];
1158 void *unk4[3];
1159 EXCEPTION_POINTERS *xcptinfo;
1160 int fpecode;
1161 pthreadmbcinfo mbcinfo;
1162 pthreadlocinfo locinfo;
1163 BOOL have_locale;
1164 int unk5[1];
1165 void* terminate_handler;
1166 void* unexpected_handler;
1167 void* se_translator;
1168 void *unk6;
1169 EXCEPTION_RECORD *exc_record;
1172 static void test_getptd(void)
1174 struct __thread_data *ptd = p_getptd();
1175 DWORD tid = GetCurrentThreadId();
1176 wchar_t testW[] = L"test", *wp;
1177 char test[] = "test", *p;
1178 unsigned char mbstok_test[] = "test", *up;
1179 struct tm time;
1180 __time64_t secs = 0;
1181 int dec, sign;
1182 void *mbcinfo, *locinfo;
1184 ok(ptd->tid == tid, "ptd->tid = %x, expected %x\n", ptd->tid, tid);
1185 ok(ptd->handle == INVALID_HANDLE_VALUE, "ptd->handle = %p\n", ptd->handle);
1186 ok(p_errno() == &ptd->thread_errno, "ptd->thread_errno is different then _errno()\n");
1187 ok(p_doserrno() == &ptd->thread_doserrno, "ptd->thread_doserrno is different then __doserrno()\n");
1188 p_srand(1234);
1189 ok(ptd->random_seed == 1234, "ptd->random_seed = %d\n", ptd->random_seed);
1190 p = p_strtok(test, "t");
1191 ok(ptd->strtok_next == p+3, "ptd->strtok_next is incorrect\n");
1192 wp = p_wcstok(testW, L"t");
1193 ok(ptd->wcstok_next == wp+3, "ptd->wcstok_next is incorrect\n");
1194 up = p__mbstok(mbstok_test, (unsigned char*)"t");
1195 ok(ptd->mbstok_next == up+3, "ptd->mbstok_next is incorrect\n");
1196 ok(p_strerror(0) == ptd->strerror_buffer, "ptd->strerror_buffer is incorrect\n");
1197 ok(p_wcserror(0) == ptd->wcserror_buffer, "ptd->wcserror_buffer is incorrect\n");
1198 ok(p_tmpnam(NULL) == ptd->tmpnam_buffer, "ptd->tmpnam_buffer is incorrect\n");
1199 ok(p_wtmpnam(NULL) == ptd->wtmpnam_buffer, "ptd->wtmpnam_buffer is incorrect\n");
1200 memset(&time, 0, sizeof(time));
1201 time.tm_mday = 1;
1202 ok(p_asctime(&time) == ptd->asctime_buffer, "ptd->asctime_buffer is incorrect\n");
1203 ok(p_wasctime(&time) == ptd->wasctime_buffer, "ptd->wasctime_buffer is incorrect\n");
1204 ok(p_localtime64(&secs) == ptd->time_buffer, "ptd->time_buffer is incorrect\n");
1205 ok(p_ecvt(3.12, 1, &dec, &sign) == ptd->efcvt_buffer, "ptd->efcvt_buffer is incorrect\n");
1206 ok(p__pxcptinfoptrs() == (void**)&ptd->xcptinfo, "ptd->xcptinfo is incorrect\n");
1207 ok(p_fpecode() == &ptd->fpecode, "ptd->fpecode is incorrect\n");
1208 mbcinfo = ptd->mbcinfo;
1209 locinfo = ptd->locinfo;
1210 ok(ptd->have_locale == 1, "ptd->have_locale = %x\n", ptd->have_locale);
1211 p_configthreadlocale(1);
1212 ok(mbcinfo == ptd->mbcinfo, "ptd->mbcinfo != mbcinfo\n");
1213 ok(locinfo == ptd->locinfo, "ptd->locinfo != locinfo\n");
1214 ok(ptd->have_locale == 3, "ptd->have_locale = %x\n", ptd->have_locale);
1215 ok(p_get_terminate() == ptd->terminate_handler, "ptd->terminate_handler != _get_terminate()\n");
1216 ok(p_get_unexpected() == ptd->unexpected_handler, "ptd->unexpected_handler != _get_unexpected()\n");
1219 static int WINAPIV __vswprintf_l_wrapper(wchar_t *buf,
1220 const wchar_t *format, _locale_t locale, ...)
1222 int ret;
1223 __ms_va_list valist;
1224 __ms_va_start(valist, locale);
1225 ret = p__vswprintf_l(buf, format, locale, valist);
1226 __ms_va_end(valist);
1227 return ret;
1230 static int WINAPIV _vswprintf_l_wrapper(wchar_t *buf,
1231 const wchar_t *format, _locale_t locale, ...)
1233 int ret;
1234 __ms_va_list valist;
1235 __ms_va_start(valist, locale);
1236 ret = p_vswprintf_l(buf, format, locale, valist);
1237 __ms_va_end(valist);
1238 return ret;
1241 static void test__vswprintf_l(void)
1243 wchar_t buf[32];
1244 int ret;
1246 ret = __vswprintf_l_wrapper(buf, L"test", NULL);
1247 ok(ret == 4, "ret = %d\n", ret);
1248 ok(!wcscmp(buf, L"test"), "buf = %s\n", wine_dbgstr_w(buf));
1250 ret = _vswprintf_l_wrapper(buf, L"test", NULL);
1251 ok(ret == 4, "ret = %d\n", ret);
1252 ok(!wcscmp(buf, L"test"), "buf = %s\n", wine_dbgstr_w(buf));
1255 struct block_file_arg
1257 FILE *read;
1258 FILE *write;
1259 HANDLE init;
1260 HANDLE finish;
1261 int deadlock_test;
1264 static DWORD WINAPI block_file(void *arg)
1266 struct block_file_arg *files = arg;
1267 int deadlock_test;
1269 p_lock_file(files->read);
1270 p_lock_file(files->write);
1271 SetEvent(files->init);
1273 WaitForSingleObject(files->finish, INFINITE);
1274 Sleep(200);
1275 deadlock_test = InterlockedIncrement(&files->deadlock_test);
1276 ok(deadlock_test == 1, "deadlock_test = %d\n", deadlock_test);
1277 p_unlock_file(files->read);
1278 p_unlock_file(files->write);
1279 return 0;
1282 static void test_nonblocking_file_access(void)
1284 HANDLE thread;
1285 struct block_file_arg arg;
1286 FILE *filer, *filew;
1287 int ret;
1289 if(!p_lock_file || !p_unlock_file) {
1290 win_skip("_lock_file not available\n");
1291 return;
1294 filew = p_fopen("test_file", "w");
1295 ok(filew != NULL, "unable to create test file\n");
1296 if(!filew)
1297 return;
1298 filer = p_fopen("test_file", "r");
1299 ok(filer != NULL, "unable to open test file\n");
1300 if(!filer) {
1301 p_fclose(filew);
1302 p_unlink("test_file");
1303 return;
1306 arg.read = filer;
1307 arg.write = filew;
1308 arg.init = CreateEventW(NULL, FALSE, FALSE, NULL);
1309 arg.finish = CreateEventW(NULL, FALSE, FALSE, NULL);
1310 arg.deadlock_test = 0;
1311 ok(arg.init != NULL, "CreateEventW failed\n");
1312 ok(arg.finish != NULL, "CreateEventW failed\n");
1313 thread = CreateThread(NULL, 0, block_file, (void*)&arg, 0, NULL);
1314 ok(thread != NULL, "CreateThread failed\n");
1315 WaitForSingleObject(arg.init, INFINITE);
1317 ret = p_fileno(filer);
1318 ok(ret, "_fileno(filer) returned %d\n", ret);
1319 ret = p_fileno(filew);
1320 ok(ret, "_fileno(filew) returned %d\n", ret);
1322 ret = p_feof(filer);
1323 ok(ret==0, "feof(filer) returned %d\n", ret);
1324 ret = p_feof(filew);
1325 ok(ret==0, "feof(filew) returned %d\n", ret);
1327 ret = p_ferror(filer);
1328 ok(ret==0, "ferror(filer) returned %d\n", ret);
1329 ret = p_ferror(filew);
1330 ok(ret==0, "ferror(filew) returned %d\n", ret);
1332 ret = p_flsbuf('a', filer);
1333 ok(ret==-1, "_flsbuf(filer) returned %d\n", ret);
1334 ret = p_flsbuf('a', filew);
1335 ok(ret=='a', "_flsbuf(filew) returned %d\n", ret);
1337 ret = p_filbuf(filer);
1338 ok(ret==-1, "_filbuf(filer) returned %d\n", ret);
1339 ret = p_filbuf(filew);
1340 ok(ret==-1, "_filbuf(filew) returned %d\n", ret);
1342 ret = p_fflush_nolock(filer);
1343 ok(ret==0, "_fflush_nolock(filer) returned %d\n", ret);
1344 ret = p_fflush_nolock(filew);
1345 ok(ret==0, "_fflush_nolock(filew) returned %d\n", ret);
1347 SetEvent(arg.finish);
1349 ret = p_fflush_nolock(NULL);
1350 ok(ret==0, "_fflush_nolock(NULL) returned %d\n", ret);
1351 ret = InterlockedIncrement(&arg.deadlock_test);
1352 ok(ret==2, "InterlockedIncrement returned %d\n", ret);
1354 WaitForSingleObject(thread, INFINITE);
1355 CloseHandle(arg.init);
1356 CloseHandle(arg.finish);
1357 CloseHandle(thread);
1358 p_fclose(filer);
1359 p_fclose(filew);
1360 p_unlink("test_file");
1363 static void test_byteswap(void)
1365 unsigned long ret;
1367 ret = p_byteswap_ulong(0x12345678);
1368 ok(ret == 0x78563412, "ret = %lx\n", ret);
1370 ret = p_byteswap_ulong(0);
1371 ok(ret == 0, "ret = %lx\n", ret);
1374 static void test_access_s(void)
1376 FILE *f;
1377 int res;
1379 f = p_fopen("test_file", "w");
1380 ok(f != NULL, "unable to create test file\n");
1381 if(!f)
1382 return;
1384 p_fclose(f);
1386 errno = 0xdeadbeef;
1387 res = p_access_s("test_file", 0);
1388 ok(res == 0, "got %x\n", res);
1389 ok(errno == 0xdeadbeef, "got %x\n", res);
1391 errno = 0xdeadbeef;
1392 res = p_access_s("test_file", 2);
1393 ok(res == 0, "got %x\n", res);
1394 ok(errno == 0xdeadbeef, "got %x\n", res);
1396 errno = 0xdeadbeef;
1397 res = p_access_s("test_file", 4);
1398 ok(res == 0, "got %x\n", res);
1399 ok(errno == 0xdeadbeef, "got %x\n", res);
1401 errno = 0xdeadbeef;
1402 res = p_access_s("test_file", 6);
1403 ok(res == 0, "got %x\n", res);
1404 ok(errno == 0xdeadbeef, "got %x\n", res);
1406 SetFileAttributesA("test_file", FILE_ATTRIBUTE_READONLY);
1408 errno = 0xdeadbeef;
1409 res = p_access_s("test_file", 0);
1410 ok(res == 0, "got %x\n", res);
1411 ok(errno == 0xdeadbeef, "got %x\n", res);
1413 errno = 0xdeadbeef;
1414 res = p_access_s("test_file", 2);
1415 ok(res == EACCES, "got %x\n", res);
1416 ok(errno == EACCES, "got %x\n", res);
1418 errno = 0xdeadbeef;
1419 res = p_access_s("test_file", 4);
1420 ok(res == 0, "got %x\n", res);
1421 ok(errno == 0xdeadbeef, "got %x\n", res);
1423 errno = 0xdeadbeef;
1424 res = p_access_s("test_file", 6);
1425 ok(res == EACCES, "got %x\n", res);
1426 ok(errno == EACCES, "got %x\n", res);
1428 SetFileAttributesA("test_file", FILE_ATTRIBUTE_NORMAL);
1430 p_unlink("test_file");
1432 errno = 0xdeadbeef;
1433 res = p_access_s("test_file", 0);
1434 ok(res == ENOENT, "got %x\n", res);
1435 ok(errno == ENOENT, "got %x\n", res);
1437 errno = 0xdeadbeef;
1438 res = p_access_s("test_file", 2);
1439 ok(res == ENOENT, "got %x\n", res);
1440 ok(errno == ENOENT, "got %x\n", res);
1442 errno = 0xdeadbeef;
1443 res = p_access_s("test_file", 4);
1444 ok(res == ENOENT, "got %x\n", res);
1445 ok(errno == ENOENT, "got %x\n", res);
1447 errno = 0xdeadbeef;
1448 res = p_access_s("test_file", 6);
1449 ok(res == ENOENT, "got %x\n", res);
1450 ok(errno == ENOENT, "got %x\n", res);
1453 #ifndef __x86_64__
1454 #define EXCEPTION_REF(instance, name) &instance.name
1455 #else
1456 #define EXCEPTION_REF(instance, name) FIELD_OFFSET(struct _exception_data, name)
1457 #endif
1458 static void test_is_exception_typeof(void)
1460 const type_info ti1 = {NULL, NULL, {'.','?','A','V','t','e','s','t','1','@','@',0}};
1461 const type_info ti2 = {NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0}};
1462 const type_info ti3 = {NULL, NULL, {'.','?','A','V','t','e','s','t','3','@','@',0}};
1464 const struct _exception_data {
1465 type_info ti1;
1466 type_info ti2;
1467 cxx_type_info cti1;
1468 cxx_type_info cti2;
1469 cxx_type_info_table tit;
1470 cxx_exception_type et;
1471 } exception_data = {
1472 {NULL, NULL, {'.','?','A','V','t','e','s','t','1','@','@',0}},
1473 {NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0}},
1474 {0, EXCEPTION_REF(exception_data, ti1)},
1475 {0, EXCEPTION_REF(exception_data, ti2)},
1476 {2, {EXCEPTION_REF(exception_data, cti1), EXCEPTION_REF(exception_data, cti2)}},
1477 {0, 0, 0, EXCEPTION_REF(exception_data, tit)}
1480 EXCEPTION_RECORD rec = {CXX_EXCEPTION, 0, NULL, NULL, 3, {CXX_FRAME_MAGIC_VC6, 0, (ULONG_PTR)&exception_data.et}};
1481 EXCEPTION_POINTERS except_ptrs = {&rec, NULL};
1483 int ret;
1485 #ifdef __x86_64__
1486 rec.NumberParameters = 4;
1487 rec.ExceptionInformation[3] = (ULONG_PTR)&exception_data;
1488 #endif
1490 ret = p_is_exception_typeof(&ti1, &except_ptrs);
1491 ok(ret == 1, "_is_exception_typeof returned %d\n", ret);
1492 ret = p_is_exception_typeof(&ti2, &except_ptrs);
1493 ok(ret == 1, "_is_exception_typeof returned %d\n", ret);
1494 ret = p_is_exception_typeof(&ti3, &except_ptrs);
1495 ok(ret == 0, "_is_exception_typeof returned %d\n", ret);
1498 static void test__AdjustPointer(void)
1500 struct {
1501 int vbase;
1502 int off;
1503 } obj = { 0, 0xf0 };
1504 void *obj1 = &obj.off;
1505 void *obj2 = &obj;
1506 struct test_data {
1507 void *ptr;
1508 void *ret;
1509 struct {
1510 int this_offset;
1511 int vbase_descr;
1512 int vbase_offset;
1513 } this_ptr_offsets;
1514 } data[] = {
1515 {NULL, NULL, {0, -1, 0}},
1516 {(void*)0xbeef, (void*)0xbef0, {1, -1, 1}},
1517 {(void*)0xbeef, (void*)0xbeee, {-1, -1, 0}},
1518 {&obj1, (char*)&obj1 + obj.off, {0, 0, 0}},
1519 {(char*)&obj1 - 5, (char*)&obj1 + obj.off, {0, 5, 0}},
1520 {(char*)&obj1 - 3, (char*)&obj1 + obj.off + 24, {24, 3, 0}},
1521 {(char*)&obj2 - 17, (char*)&obj2 + obj.off + 4, {4, 17, sizeof(int)}}
1523 void *ret;
1524 int i;
1526 for(i=0; i<ARRAY_SIZE(data); i++) {
1527 ret = p__AdjustPointer(data[i].ptr, &data[i].this_ptr_offsets);
1528 ok(ret == data[i].ret, "%d) __AdjustPointer returned %p, expected %p\n", i, ret, data[i].ret);
1532 static void test_mbstowcs(void)
1534 wchar_t bufw[16];
1535 char buf[16];
1536 size_t ret;
1538 buf[0] = 'a';
1539 buf[1] = 0;
1540 memset(bufw, 'x', sizeof(bufw));
1541 ret = p_mbstowcs(bufw, buf, -1);
1542 ok(ret == 1, "ret = %d\n", (int)ret);
1543 ok(bufw[0] == 'a', "bufw[0] = '%c'\n", bufw[0]);
1544 ok(bufw[1] == 0, "bufw[1] = '%c'\n", bufw[1]);
1546 memset(bufw, 'x', sizeof(bufw));
1547 ret = p_mbstowcs(bufw, buf, -1000);
1548 ok(ret == 1, "ret = %d\n", (int)ret);
1549 ok(bufw[0] == 'a', "bufw[0] = '%c'\n", bufw[0]);
1550 ok(bufw[1] == 0, "bufw[1] = '%c'\n", bufw[1]);
1552 memset(buf, 'x', sizeof(buf));
1553 ret = p_wcstombs(buf, bufw, -1);
1554 ok(ret == 1, "ret = %d\n", (int)ret);
1555 ok(buf[0] == 'a', "buf[0] = '%c'\n", buf[0]);
1556 ok(buf[1] == 0, "buf[1] = '%c'\n", buf[1]);
1558 memset(buf, 'x', sizeof(buf));
1559 ret = p_wcstombs(buf, bufw, -1000);
1560 ok(ret == 1, "ret = %d\n", (int)ret);
1561 ok(buf[0] == 'a', "buf[0] = '%c'\n", buf[0]);
1562 ok(buf[1] == 0, "buf[1] = '%c'\n", buf[1]);
1564 if(!p_setlocale(LC_ALL, "English")) {
1565 win_skip("English locale not available\n");
1566 return;
1569 buf[0] = 'a';
1570 buf[1] = 0;
1571 memset(bufw, 'x', sizeof(bufw));
1572 ret = p_mbstowcs(bufw, buf, -1);
1573 ok(ret == -1, "ret = %d\n", (int)ret);
1574 ok(bufw[0] == 0, "bufw[0] = '%c'\n", bufw[0]);
1576 memset(bufw, 'x', sizeof(bufw));
1577 ret = p_mbstowcs(bufw, buf, -1000);
1578 ok(ret == -1, "ret = %d\n", (int)ret);
1579 ok(bufw[0] == 0, "bufw[0] = '%c'\n", bufw[0]);
1581 memset(buf, 'x', sizeof(buf));
1582 ret = p_wcstombs(buf, bufw, -1);
1583 ok(ret == 0, "ret = %d\n", (int)ret);
1584 ok(buf[0] == 0, "buf[0] = '%c'\n", buf[0]);
1586 memset(buf, 'x', sizeof(buf));
1587 ret = p_wcstombs(buf, bufw, -1000);
1588 ok(ret == 0, "ret = %d\n", (int)ret);
1589 ok(buf[0] == 0, "buf[0] = '%c'\n", buf[0]);
1591 p_setlocale(LC_ALL, "C");
1594 static void test_strtok_s(void)
1596 char test[] = "a/b";
1597 char empty[] = "";
1598 char space[] = " ";
1599 char delim[] = "/";
1600 char *strret;
1601 char *context;
1603 context = (char*)0xdeadbeef;
1604 strret = p_strtok_s( test, delim, &context);
1605 ok(strret == test, "Expected test, got %p.\n", strret);
1606 ok(context == test+2, "Expected test+2, got %p.\n", context);
1608 strret = p_strtok_s( NULL, delim, &context);
1609 ok(strret == test+2, "Expected test+2, got %p.\n", strret);
1610 ok(context == test+3, "Expected test+3, got %p.\n", context);
1612 strret = p_strtok_s( NULL, delim, &context);
1613 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1614 ok(context == test+3, "Expected test+3, got %p.\n", context);
1616 context = NULL;
1617 strret = p_strtok_s( empty, delim, &context);
1618 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1619 ok(context == empty, "Expected empty, got %p.\n", context);
1621 strret = p_strtok_s( NULL, delim, &context);
1622 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1623 ok(context == empty, "Expected empty, got %p.\n", context);
1625 context = NULL;
1626 strret = p_strtok_s( space, delim, &context);
1627 ok(strret == space, "Expected space, got %p.\n", strret);
1628 ok(context == space+1, "Expected space+1, got %p.\n", context);
1630 strret = p_strtok_s( NULL, delim, &context);
1631 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1632 ok(context == space+1, "Expected space+1, got %p.\n", context);
1635 static void test__mbstok_s(void)
1637 unsigned char test[] = "a/b";
1638 unsigned char empty[] = "";
1639 unsigned char space[] = " ";
1640 unsigned char delim[] = "/";
1641 unsigned char *strret;
1642 unsigned char *context;
1644 context = (unsigned char*)0xdeadbeef;
1645 strret = p__mbstok_s( test, delim, &context);
1646 ok(strret == test, "Expected test, got %p.\n", strret);
1647 ok(context == test+2, "Expected test+2, got %p.\n", context);
1649 strret = p__mbstok_s( NULL, delim, &context);
1650 ok(strret == test+2, "Expected test+2, got %p.\n", strret);
1651 ok(context == test+3, "Expected test+3, got %p.\n", context);
1653 strret = p__mbstok_s( NULL, delim, &context);
1654 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1655 ok(context == test+3, "Expected test+3, got %p.\n", context);
1657 context = NULL;
1658 strret = p__mbstok_s( empty, delim, &context);
1659 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1660 ok(context == empty, "Expected empty, got %p.\n", context);
1662 strret = p__mbstok_s( NULL, delim, &context);
1663 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1664 ok(context == empty, "Expected empty, got %p.\n", context);
1666 context = NULL;
1667 strret = p__mbstok_s( space, delim, &context);
1668 ok(strret == space, "Expected space, got %p.\n", strret);
1669 ok(context == space+1, "Expected space+1, got %p.\n", context);
1671 strret = p__mbstok_s( NULL, delim, &context);
1672 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1673 ok(context == space+1, "Expected space+1, got %p.\n", context);
1676 #ifdef __i386__
1677 static _FPIEEE_RECORD fpieee_record;
1678 static int handler_called;
1679 static int __cdecl fpieee_handler(_FPIEEE_RECORD *rec)
1681 handler_called++;
1682 fpieee_record = *rec;
1683 return EXCEPTION_CONTINUE_EXECUTION;
1686 static void test__fpieee_flt(void)
1688 double argd = 1.5;
1689 struct {
1690 DWORD exception_code;
1691 WORD opcode;
1692 DWORD data_offset;
1693 DWORD control_word;
1694 DWORD status_word;
1695 _FPIEEE_RECORD rec;
1696 int ret;
1697 } test_data[] = {
1698 { STATUS_FLOAT_DIVIDE_BY_ZERO, 0x35dc, (DWORD)&argd, 0, 0,
1699 {0, 2, _FpCodeDivide,
1700 {0}, {1, 1, 1, 1, 1}, {0},
1701 {{0}, 1, _FpFormatFp80},
1702 {{0}, 1, _FpFormatFp64},
1703 {{0}, 0, _FpFormatFp80}},
1704 EXCEPTION_CONTINUE_EXECUTION },
1705 { STATUS_FLOAT_INEXACT_RESULT, 0x35dc, (DWORD)&argd, 0, 0,
1706 {0, 2, _FpCodeDivide,
1707 {0}, {1, 1, 1, 1, 1}, {0},
1708 {{0}, 0, _FpFormatFp80},
1709 {{0}, 1, _FpFormatFp64},
1710 {{0}, 1, _FpFormatFp80}},
1711 EXCEPTION_CONTINUE_EXECUTION },
1712 { STATUS_FLOAT_INVALID_OPERATION, 0x35dc, (DWORD)&argd, 0, 0,
1713 {0, 2, _FpCodeDivide,
1714 {0}, {1, 1, 1, 1, 1}, {0},
1715 {{0}, 1, _FpFormatFp80},
1716 {{0}, 1, _FpFormatFp64},
1717 {{0}, 0, _FpFormatFp80}},
1718 EXCEPTION_CONTINUE_EXECUTION },
1719 { STATUS_FLOAT_OVERFLOW, 0x35dc, (DWORD)&argd, 0, 0,
1720 {0, 2, _FpCodeDivide,
1721 {0}, {1, 1, 1, 1, 1}, {0},
1722 {{0}, 0, _FpFormatFp80},
1723 {{0}, 1, _FpFormatFp64},
1724 {{0}, 1, _FpFormatFp80}},
1725 EXCEPTION_CONTINUE_EXECUTION },
1726 { STATUS_FLOAT_UNDERFLOW, 0x35dc, (DWORD)&argd, 0, 0,
1727 {0, 2, _FpCodeDivide,
1728 {0}, {1, 1, 1, 1, 1}, {0},
1729 {{0}, 0, _FpFormatFp80},
1730 {{0}, 1, _FpFormatFp64},
1731 {{0}, 1, _FpFormatFp80}},
1732 EXCEPTION_CONTINUE_EXECUTION },
1733 { STATUS_FLOAT_DIVIDE_BY_ZERO, 0x35dc, (DWORD)&argd, 0, 0xffffffff,
1734 {0, 2, _FpCodeDivide,
1735 {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1},
1736 {{0}, 1, _FpFormatFp80},
1737 {{0}, 1, _FpFormatFp64},
1738 {{0}, 0, _FpFormatFp80}},
1739 EXCEPTION_CONTINUE_EXECUTION },
1740 { STATUS_FLOAT_DIVIDE_BY_ZERO, 0x35dc, (DWORD)&argd, 0xffffffff, 0xffffffff,
1741 {3, 0, _FpCodeDivide,
1742 {0}, {0}, {1, 1, 1, 1, 1},
1743 {{0}, 1, _FpFormatFp80},
1744 {{0}, 1, _FpFormatFp64},
1745 {{0}, 0, _FpFormatFp80}},
1746 EXCEPTION_CONTINUE_EXECUTION },
1748 EXCEPTION_POINTERS ep;
1749 EXCEPTION_RECORD rec;
1750 CONTEXT ctx;
1751 int i, ret;
1753 if(!p__fpieee_flt) {
1754 win_skip("_fpieee_flt not available\n");
1755 return;
1758 ep.ExceptionRecord = &rec;
1759 ep.ContextRecord = &ctx;
1760 memset(&rec, 0, sizeof(rec));
1761 memset(&ctx, 0, sizeof(ctx));
1762 ret = p__fpieee_flt(1, &ep, fpieee_handler);
1763 ok(ret == EXCEPTION_CONTINUE_SEARCH, "_fpieee_flt returned %d\n", ret);
1764 ok(handler_called == 0, "handler_called = %d\n", handler_called);
1766 for(i=0; i<ARRAY_SIZE(test_data); i++) {
1767 ep.ExceptionRecord = &rec;
1768 ep.ContextRecord = &ctx;
1769 memset(&rec, 0, sizeof(rec));
1770 memset(&ctx, 0, sizeof(ctx));
1772 ctx.FloatSave.ErrorOffset = (DWORD)&test_data[i].opcode;
1773 ctx.FloatSave.DataOffset = test_data[i].data_offset;
1774 ctx.FloatSave.ControlWord = test_data[i].control_word;
1775 ctx.FloatSave.StatusWord = test_data[i].status_word;
1777 handler_called = 0;
1778 ret = p__fpieee_flt(test_data[i].exception_code, &ep, fpieee_handler);
1779 ok(ret == test_data[i].ret, "%d) _fpieee_flt returned %d\n", i, ret);
1780 ok(handler_called == 1, "%d) handler_called = %d\n", i, handler_called);
1782 ok(fpieee_record.RoundingMode == test_data[i].rec.RoundingMode,
1783 "%d) RoundingMode = %x\n", i, fpieee_record.RoundingMode);
1784 ok(fpieee_record.Precision == test_data[i].rec.Precision,
1785 "%d) Precision = %x\n", i, fpieee_record.Precision);
1786 ok(fpieee_record.Operation == test_data[i].rec.Operation,
1787 "%d) Operation = %x\n", i, fpieee_record.Operation);
1788 ok(fpieee_record.Cause.Inexact == test_data[i].rec.Cause.Inexact,
1789 "%d) Cause.Inexact = %x\n", i, fpieee_record.Cause.Inexact);
1790 ok(fpieee_record.Cause.Underflow == test_data[i].rec.Cause.Underflow,
1791 "%d) Cause.Underflow = %x\n", i, fpieee_record.Cause.Underflow);
1792 ok(fpieee_record.Cause.Overflow == test_data[i].rec.Cause.Overflow,
1793 "%d) Cause.Overflow = %x\n", i, fpieee_record.Cause.Overflow);
1794 ok(fpieee_record.Cause.ZeroDivide == test_data[i].rec.Cause.ZeroDivide,
1795 "%d) Cause.ZeroDivide = %x\n", i, fpieee_record.Cause.ZeroDivide);
1796 ok(fpieee_record.Cause.InvalidOperation == test_data[i].rec.Cause.InvalidOperation,
1797 "%d) Cause.InvalidOperation = %x\n", i, fpieee_record.Cause.InvalidOperation);
1798 ok(fpieee_record.Enable.Inexact == test_data[i].rec.Enable.Inexact,
1799 "%d) Enable.Inexact = %x\n", i, fpieee_record.Enable.Inexact);
1800 ok(fpieee_record.Enable.Underflow == test_data[i].rec.Enable.Underflow,
1801 "%d) Enable.Underflow = %x\n", i, fpieee_record.Enable.Underflow);
1802 ok(fpieee_record.Enable.Overflow == test_data[i].rec.Enable.Overflow,
1803 "%d) Enable.Overflow = %x\n", i, fpieee_record.Enable.Overflow);
1804 ok(fpieee_record.Enable.ZeroDivide == test_data[i].rec.Enable.ZeroDivide,
1805 "%d) Enable.ZeroDivide = %x\n", i, fpieee_record.Enable.ZeroDivide);
1806 ok(fpieee_record.Enable.InvalidOperation == test_data[i].rec.Enable.InvalidOperation,
1807 "%d) Enable.InvalidOperation = %x\n", i, fpieee_record.Enable.InvalidOperation);
1808 ok(fpieee_record.Status.Inexact == test_data[i].rec.Status.Inexact,
1809 "%d) Status.Inexact = %x\n", i, fpieee_record.Status.Inexact);
1810 ok(fpieee_record.Status.Underflow == test_data[i].rec.Status.Underflow,
1811 "%d) Status.Underflow = %x\n", i, fpieee_record.Status.Underflow);
1812 ok(fpieee_record.Status.Overflow == test_data[i].rec.Status.Overflow,
1813 "%d) Status.Overflow = %x\n", i, fpieee_record.Status.Overflow);
1814 ok(fpieee_record.Status.ZeroDivide == test_data[i].rec.Status.ZeroDivide,
1815 "%d) Status.ZeroDivide = %x\n", i, fpieee_record.Status.ZeroDivide);
1816 ok(fpieee_record.Status.InvalidOperation == test_data[i].rec.Status.InvalidOperation,
1817 "%d) Status.InvalidOperation = %x\n", i, fpieee_record.Status.InvalidOperation);
1818 ok(fpieee_record.Operand1.OperandValid == test_data[i].rec.Operand1.OperandValid,
1819 "%d) Operand1.OperandValid = %x\n", i, fpieee_record.Operand1.OperandValid);
1820 if(fpieee_record.Operand1.OperandValid) {
1821 ok(fpieee_record.Operand1.Format == test_data[i].rec.Operand1.Format,
1822 "%d) Operand1.Format = %x\n", i, fpieee_record.Operand1.Format);
1824 ok(fpieee_record.Operand2.OperandValid == test_data[i].rec.Operand2.OperandValid,
1825 "%d) Operand2.OperandValid = %x\n", i, fpieee_record.Operand2.OperandValid);
1826 ok(fpieee_record.Operand2.Format == test_data[i].rec.Operand2.Format,
1827 "%d) Operand2.Format = %x\n", i, fpieee_record.Operand2.Format);
1828 ok(fpieee_record.Result.OperandValid == test_data[i].rec.Result.OperandValid,
1829 "%d) Result.OperandValid = %x\n", i, fpieee_record.Result.OperandValid);
1830 ok(fpieee_record.Result.Format == test_data[i].rec.Result.Format,
1831 "%d) Result.Format = %x\n", i, fpieee_record.Result.Format);
1834 #endif
1836 static void test__memicmp(void)
1838 static const char *s1 = "abc";
1839 static const char *s2 = "aBd";
1840 int ret;
1842 ret = p__memicmp(NULL, NULL, 0);
1843 ok(!ret, "got %d\n", ret);
1845 SET_EXPECT(invalid_parameter_handler);
1846 ret = p__memicmp(NULL, NULL, 1);
1847 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1848 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1850 SET_EXPECT(invalid_parameter_handler);
1851 ret = p__memicmp(s1, NULL, 1);
1852 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1853 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1855 SET_EXPECT(invalid_parameter_handler);
1856 ret = p__memicmp(NULL, s2, 1);
1857 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1858 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1860 ret = p__memicmp(s1, s2, 2);
1861 ok(!ret, "got %d\n", ret);
1863 ret = p__memicmp(s1, s2, 3);
1864 ok(ret == -1, "got %d\n", ret);
1867 static void test__memicmp_l(void)
1869 static const char *s1 = "abc";
1870 static const char *s2 = "aBd";
1871 int ret;
1873 ret = p__memicmp_l(NULL, NULL, 0, NULL);
1874 ok(!ret, "got %d\n", ret);
1876 SET_EXPECT(invalid_parameter_handler);
1877 ret = p__memicmp_l(NULL, NULL, 1, NULL);
1878 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1879 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1881 SET_EXPECT(invalid_parameter_handler);
1882 ret = p__memicmp_l(s1, NULL, 1, NULL);
1883 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1884 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1886 SET_EXPECT(invalid_parameter_handler);
1887 ret = p__memicmp_l(NULL, s2, 1, NULL);
1888 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1889 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1891 ret = p__memicmp_l(s1, s2, 2, NULL);
1892 ok(!ret, "got %d\n", ret);
1894 ret = p__memicmp_l(s1, s2, 3, NULL);
1895 ok(ret == -1, "got %d\n", ret);
1898 static int WINAPIV _vsnwprintf_wrapper(wchar_t *str, size_t len, const wchar_t *format, ...)
1900 int ret;
1901 __ms_va_list valist;
1902 __ms_va_start(valist, format);
1903 ret = p__vsnwprintf(str, len, format, valist);
1904 __ms_va_end(valist);
1905 return ret;
1908 static void test__vsnwprintf(void)
1910 int ret;
1911 WCHAR str[2] = {0};
1913 _invalid_parameter_handler old_handler = p_set_invalid_parameter_handler(test_invalid_parameter_handler);
1915 SET_EXPECT(invalid_parameter_handler);
1916 errno = 0xdeadbeef;
1917 str[0] = 'x';
1918 ret = _vsnwprintf_wrapper(str, 0, NULL);
1919 ok(ret == -1, "got %d, expected -1\n", ret);
1920 ok(str[0] == 'x', "Expected string to be unchanged.\n");
1921 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1923 ok(p_set_invalid_parameter_handler(old_handler) == test_invalid_parameter_handler, "Cannot reset invalid parameter handler\n");
1926 static void test___strncnt(void)
1928 static const struct
1930 const char *str;
1931 size_t size;
1932 size_t ret;
1934 strncnt_tests[] =
1936 { NULL, 0, 0 },
1937 { "a", 0, 0 },
1938 { "a", 1, 1 },
1939 { "a", 10, 1 },
1940 { "abc", 1, 1 },
1942 unsigned int i;
1943 size_t ret;
1945 if (0)
1946 ret = p___strncnt(NULL, 1);
1948 for (i = 0; i < ARRAY_SIZE(strncnt_tests); ++i)
1950 ret = p___strncnt(strncnt_tests[i].str, strncnt_tests[i].size);
1951 ok(ret == strncnt_tests[i].ret, "%u: unexpected return value %u.\n", i, (int)ret);
1955 static void test_swscanf(void)
1958 wchar_t buffer[100];
1959 int ret;
1961 /* check WEOF */
1962 ret = p_swscanf(L" \t\n\n", L"%s", buffer);
1963 ok( ret == (short)WEOF, "ret = %d\n", ret );
1966 static void test____mb_cur_max_l_func(void)
1968 int ret;
1969 _locale_t l;
1971 ret = p____mb_cur_max_l_func(NULL);
1972 ok( ret == 1, "MB_CUR_MAX_L(NULL) = %d\n", ret );
1974 l = p__create_locale(LC_ALL, "chinese-traditional");
1975 if (!l)
1977 skip("DBCS locale not available\n");
1978 return;
1980 ret = p____mb_cur_max_l_func(l);
1981 ok( ret == 2, "MB_CUR_MAX_L(cht) = %d\n", ret );
1982 p__free_locale(l);
1985 static void test__get_current_locale(void)
1987 _locale_t l, l2;
1988 int i;
1990 ok(!p__setmbcp(1252), "_setmbcp failed\n");
1991 l = p__get_current_locale();
1992 l2 = p__get_current_locale();
1994 ok(!strcmp(l->locinfo->lc_category[LC_COLLATE].locale, "C"),
1995 "LC_COLLATE = \"%s\"\n", l->locinfo->lc_category[LC_COLLATE].locale);
1996 ok(!strcmp(l->locinfo->lc_category[LC_CTYPE].locale, "C"),
1997 "LC_CTYPE = \"%s\"\n", l->locinfo->lc_category[LC_CTYPE].locale);
1998 ok(!strcmp(l->locinfo->lc_category[LC_MONETARY].locale, "C"),
1999 "LC_MONETARY = \"%s\"\n", l->locinfo->lc_category[LC_MONETARY].locale);
2000 ok(!strcmp(l->locinfo->lc_category[LC_NUMERIC].locale, "C"),
2001 "LC_NUMERIC = \"%s\"\n", l->locinfo->lc_category[LC_NUMERIC].locale);
2002 ok(!strcmp(l->locinfo->lc_category[LC_TIME].locale, "C"),
2003 "LC_TIME = \"%s\"\n", l->locinfo->lc_category[LC_TIME].locale);
2004 ok(l->mbcinfo->mbcodepage == 1252, "mbcodepage = %d\n", l->mbcinfo->mbcodepage);
2006 ok(l->locinfo->refcount == 3, "refcount = %d\n", l->locinfo->refcount);
2008 if(!p_setlocale(LC_ALL, "english")) {
2009 win_skip("English locale not available\n");
2010 p__free_locale(l);
2011 p__free_locale(l2);
2012 return;
2014 ok(!p__setmbcp(932), "_setmbcp failed\n");
2016 ok(!strcmp(l->locinfo->lc_category[LC_COLLATE].locale, "C"),
2017 "LC_COLLATE = \"%s\"\n", l->locinfo->lc_category[LC_COLLATE].locale);
2018 ok(!strcmp(l->locinfo->lc_category[LC_CTYPE].locale, "C"),
2019 "LC_CTYPE = \"%s\"\n", l->locinfo->lc_category[LC_CTYPE].locale);
2020 ok(!strcmp(l->locinfo->lc_category[LC_MONETARY].locale, "C"),
2021 "LC_MONETARY = \"%s\"\n", l->locinfo->lc_category[LC_MONETARY].locale);
2022 ok(!strcmp(l->locinfo->lc_category[LC_NUMERIC].locale, "C"),
2023 "LC_NUMERIC = \"%s\"\n", l->locinfo->lc_category[LC_NUMERIC].locale);
2024 ok(!strcmp(l->locinfo->lc_category[LC_TIME].locale, "C"),
2025 "LC_TIME = \"%s\"\n", l->locinfo->lc_category[LC_TIME].locale);
2026 ok(l->mbcinfo->mbcodepage == 1252, "mbcodepage = %d\n", l->mbcinfo->mbcodepage);
2028 ok(l->locinfo->refcount == 2, "refcount = %d\n", l->locinfo->refcount);
2029 ok(l->locinfo == l2->locinfo, "different locinfo pointers\n");
2030 ok(l->mbcinfo == l2->mbcinfo, "different mbcinfo pointers\n");
2032 p__free_locale(l);
2033 p__free_locale(l2);
2035 l = p__get_current_locale();
2036 p_setlocale(LC_COLLATE, "C");
2037 l2 = p__get_current_locale();
2039 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2040 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2042 ok(l->locinfo->lc_category[LC_COLLATE].locale != l2->locinfo->lc_category[LC_COLLATE].locale,
2043 "same locale name pointers for LC_COLLATE\n");
2044 ok(l->locinfo->lc_category[LC_COLLATE].refcount != l2->locinfo->lc_category[LC_COLLATE].refcount,
2045 "same refcount pointers for LC_COLLATE\n");
2046 ok(*l2->locinfo->lc_category[LC_COLLATE].refcount == 2, "refcount = %d\n",
2047 *l2->locinfo->lc_category[LC_COLLATE].refcount);
2048 ok(*l->locinfo->lc_category[LC_COLLATE].refcount == 1, "refcount = %d\n",
2049 *l->locinfo->lc_category[LC_COLLATE].refcount);
2050 for(i = LC_CTYPE; i <= LC_MAX; i++) {
2051 ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale,
2052 "different locale name pointers for category %d\n", i);
2053 ok(l->locinfo->lc_category[i].refcount == l2->locinfo->lc_category[i].refcount,
2054 "different refcount pointers for category %d\n", i);
2055 ok(*l->locinfo->lc_category[i].refcount == 3, "refcount = %d for category %d\n",
2056 *l->locinfo->lc_category[i].refcount, i);
2059 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2060 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2062 ok(l->locinfo->lc_codepage == l2->locinfo->lc_codepage, "different lc_codepages %u, %u\n",
2063 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2064 ok(l->locinfo->lc_clike == l2->locinfo->lc_clike, "different lc_clike values %d, %d\n",
2065 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2066 /* The meaning of this member seems to be reversed--go figure */
2067 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2068 ok(l->locinfo->ctype1 == l2->locinfo->ctype1, "different ctype1 pointers\n");
2069 ok(l->locinfo->pclmap == l2->locinfo->pclmap, "different clmap pointers\n");
2070 ok(l->locinfo->pcumap == l2->locinfo->pcumap, "different cumap pointers\n");
2071 ok(l->locinfo->ctype1_refcount == l2->locinfo->ctype1_refcount, "different ctype1_refcount pointers\n");
2072 ok(*l->locinfo->ctype1_refcount == 3, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2074 ok(l->locinfo->lconv == l2->locinfo->lconv, "different lconv pointers\n");
2075 ok(l->locinfo->lconv_intl_refcount == l2->locinfo->lconv_intl_refcount, "different lconv_intl_refcount pointers\n");
2076 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2077 ok(*l->locinfo->lconv_intl_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2079 ok(l->locinfo->lconv->decimal_point == l2->locinfo->lconv->decimal_point, "different LC_NUMERIC pointers\n");
2080 ok(l->locinfo->lconv_num_refcount == l2->locinfo->lconv_num_refcount, "different lconv_num_refcount pointers\n");
2081 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2082 ok(*l->locinfo->lconv_num_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2084 ok(l->locinfo->lconv->currency_symbol == l2->locinfo->lconv->currency_symbol, "different LC_MONETARY pointers\n");
2085 ok(l->locinfo->lconv_mon_refcount == l2->locinfo->lconv_mon_refcount, "different lconv_mon_refcount pointers\n");
2086 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2087 ok(*l->locinfo->lconv_mon_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2089 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2090 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2091 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2093 p__free_locale(l2);
2095 p_setlocale(LC_CTYPE, "C");
2096 l2 = p__get_current_locale();
2098 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2099 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2101 for(i = LC_COLLATE; i < LC_MONETARY; i++) {
2102 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2103 "same locale name pointers for category %d\n", i);
2104 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2105 "same refcount pointers for category %d\n", i);
2106 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2107 *l2->locinfo->lc_category[i].refcount, i);
2108 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2109 *l->locinfo->lc_category[i].refcount, i);
2111 for(i = LC_MONETARY; i <= LC_MAX; i++) {
2112 ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale,
2113 "different locale name pointers for category %d\n", i);
2114 ok(l->locinfo->lc_category[i].refcount == l2->locinfo->lc_category[i].refcount,
2115 "different refcount pointers for category %d\n", i);
2116 ok(*l->locinfo->lc_category[i].refcount == 3, "refcount = %d for category %d\n",
2117 *l->locinfo->lc_category[i].refcount, i);
2120 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2121 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2123 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2124 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2125 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2126 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2127 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2128 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2129 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2130 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2131 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2132 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2133 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2134 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2135 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2137 ok(l->locinfo->lconv == l2->locinfo->lconv, "different lconv pointers\n");
2138 ok(l->locinfo->lconv_intl_refcount == l2->locinfo->lconv_intl_refcount, "different lconv_intl_refcount pointers\n");
2139 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2140 ok(*l->locinfo->lconv_intl_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2142 ok(l->locinfo->lconv->decimal_point == l2->locinfo->lconv->decimal_point, "different LC_NUMERIC pointers\n");
2143 ok(l->locinfo->lconv_num_refcount == l2->locinfo->lconv_num_refcount, "different lconv_num_refcount pointers\n");
2144 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2145 ok(*l->locinfo->lconv_num_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2147 ok(l->locinfo->lconv->currency_symbol == l2->locinfo->lconv->currency_symbol, "different LC_MONETARY pointers\n");
2148 ok(l->locinfo->lconv_mon_refcount == l2->locinfo->lconv_mon_refcount, "different lconv_mon_refcount pointers\n");
2149 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2150 ok(*l->locinfo->lconv_mon_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2152 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2153 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2154 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2156 p__free_locale(l2);
2158 p_setlocale(LC_MONETARY, "C");
2159 l2 = p__get_current_locale();
2161 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2162 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2164 for(i = LC_COLLATE; i <= LC_MONETARY; i++) {
2165 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2166 "same locale name pointers for category %d\n", i);
2167 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2168 "same refcount pointers for category %d\n", i);
2169 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2170 *l2->locinfo->lc_category[i].refcount, i);
2171 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2172 *l->locinfo->lc_category[i].refcount, i);
2174 for(i = LC_NUMERIC; i <= LC_MAX; i++) {
2175 ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale,
2176 "different locale name pointers for category %d\n", i);
2177 ok(l->locinfo->lc_category[i].refcount == l2->locinfo->lc_category[i].refcount,
2178 "different refcount pointers for category %d\n", i);
2179 ok(*l->locinfo->lc_category[i].refcount == 3, "refcount = %d for category %d\n",
2180 *l->locinfo->lc_category[i].refcount, i);
2183 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2184 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2186 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2187 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2188 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2189 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2190 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2191 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2192 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2193 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2194 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2195 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2196 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2197 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2198 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2200 ok(l->locinfo->lconv != l2->locinfo->lconv, "same lconv pointers\n");
2201 ok(l->locinfo->lconv_intl_refcount != l2->locinfo->lconv_intl_refcount, "same lconv_intl_refcount pointers\n");
2202 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2203 ok(*l->locinfo->lconv_intl_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2204 ok(!!l2->locinfo->lconv_intl_refcount, "null refcount pointer for C locale\n");
2205 ok(*l2->locinfo->lconv_intl_refcount == 2, "refcount = %d\n", *l2->locinfo->lconv_intl_refcount);
2207 ok(l->locinfo->lconv->decimal_point == l2->locinfo->lconv->decimal_point, "different LC_NUMERIC pointers\n");
2208 ok(l->locinfo->lconv_num_refcount == l2->locinfo->lconv_num_refcount, "different lconv_num_refcount pointers\n");
2209 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2210 ok(*l->locinfo->lconv_num_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2212 ok(l->locinfo->lconv->currency_symbol != l2->locinfo->lconv->currency_symbol, "same LC_MONETARY pointers\n");
2213 ok(l->locinfo->lconv_mon_refcount != l2->locinfo->lconv_mon_refcount, "same lconv_mon_refcount pointers\n");
2214 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2215 ok(*l->locinfo->lconv_mon_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2216 ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
2218 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2219 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2220 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2222 p__free_locale(l2);
2224 p_setlocale(LC_NUMERIC, "C");
2225 l2 = p__get_current_locale();
2227 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2228 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2230 for(i = LC_COLLATE; i <= LC_NUMERIC; i++) {
2231 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2232 "same locale name pointers for category %d\n", i);
2233 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2234 "same refcount pointers for category %d\n", i);
2235 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2236 *l2->locinfo->lc_category[i].refcount, i);
2237 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2238 *l->locinfo->lc_category[i].refcount, i);
2240 ok(l->locinfo->lc_category[LC_TIME].locale == l2->locinfo->lc_category[LC_TIME].locale,
2241 "different locale name pointers for LC_TIME\n");
2242 ok(l->locinfo->lc_category[LC_TIME].refcount == l2->locinfo->lc_category[LC_TIME].refcount,
2243 "different refcount pointers for LC_TIME\n");
2244 ok(*l->locinfo->lc_category[LC_TIME].refcount == 3, "refcount = %d\n",
2245 *l->locinfo->lc_category[LC_TIME].refcount);
2247 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2248 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2250 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2251 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2252 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2253 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2254 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2255 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2256 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2257 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2258 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2259 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2260 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2261 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2262 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2264 ok(l->locinfo->lconv != l2->locinfo->lconv, "same lconv pointers\n");
2265 ok(l->locinfo->lconv_intl_refcount != l2->locinfo->lconv_intl_refcount, "same lconv_intl_refcount pointers\n");
2266 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2267 ok(*l->locinfo->lconv_intl_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2268 ok(!l2->locinfo->lconv_intl_refcount, "nonnull refcount pointer for C locale\n");
2270 ok(l->locinfo->lconv->decimal_point != l2->locinfo->lconv->decimal_point, "same LC_NUMERIC pointers\n");
2271 ok(l->locinfo->lconv_num_refcount != l2->locinfo->lconv_num_refcount, "same lconv_num_refcount pointers\n");
2272 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2273 ok(*l->locinfo->lconv_num_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2274 ok(!l2->locinfo->lconv_num_refcount, "nonnull refcount pointer for C locale\n");
2276 ok(l->locinfo->lconv->currency_symbol != l2->locinfo->lconv->currency_symbol, "same LC_MONETARY pointers\n");
2277 ok(l->locinfo->lconv_mon_refcount != l2->locinfo->lconv_mon_refcount, "same lconv_mon_refcount pointers\n");
2278 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2279 ok(*l->locinfo->lconv_mon_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2280 ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
2282 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2283 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2284 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2286 p__free_locale(l2);
2288 p_setlocale(LC_TIME, "C");
2289 l2 = p__get_current_locale();
2291 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2292 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2294 for(i = LC_MIN+1; i <= LC_MAX; i++) {
2295 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2296 "same locale name pointers for category %d\n", i);
2297 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2298 "same refcount pointers for category %d\n", i);
2299 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2300 *l2->locinfo->lc_category[i].refcount, i);
2301 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2302 *l->locinfo->lc_category[i].refcount, i);
2305 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2306 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2308 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2309 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2310 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2311 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2312 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2313 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2314 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2315 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2316 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2317 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2318 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2319 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2320 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2322 ok(l->locinfo->lconv != l2->locinfo->lconv, "same lconv pointers\n");
2323 ok(l->locinfo->lconv_intl_refcount != l2->locinfo->lconv_intl_refcount, "same lconv_intl_refcount pointers\n");
2324 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2325 ok(*l->locinfo->lconv_intl_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2326 ok(!l2->locinfo->lconv_intl_refcount, "nonnull refcount pointer for C locale\n");
2328 ok(l->locinfo->lconv->decimal_point != l2->locinfo->lconv->decimal_point, "same LC_NUMERIC pointers\n");
2329 ok(l->locinfo->lconv_num_refcount != l2->locinfo->lconv_num_refcount, "same lconv_num_refcount pointers\n");
2330 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2331 ok(*l->locinfo->lconv_num_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2332 ok(!l2->locinfo->lconv_num_refcount, "nonnull refcount pointer for C locale\n");
2334 ok(l->locinfo->lconv->currency_symbol != l2->locinfo->lconv->currency_symbol, "same LC_MONETARY pointers\n");
2335 ok(l->locinfo->lconv_mon_refcount != l2->locinfo->lconv_mon_refcount, "same lconv_mon_refcount pointers\n");
2336 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2337 ok(*l->locinfo->lconv_mon_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2338 ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
2340 ok(l->locinfo->lc_time_curr != l2->locinfo->lc_time_curr, "same lc_time_curr pointers\n");
2341 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2342 ok(l->locinfo->lc_time_curr->refcount == 1, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2343 ok(l2->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l2->locinfo->lc_time_curr->unk);
2344 ok(l2->locinfo->lc_time_curr->refcount == 3 || broken(l2->locinfo->lc_time_curr->refcount == 2),
2345 "refcount = %d\n", l2->locinfo->lc_time_curr->refcount);
2347 p__free_locale(l2);
2349 p__free_locale(l);
2350 p_setlocale(LC_ALL, "C");
2353 START_TEST(msvcr90)
2355 if(!init())
2356 return;
2358 test__initterm_e();
2359 test__encode_pointer();
2360 test_error_messages();
2361 test__strtoi64();
2362 test__itoa_s();
2363 test_wcsncat_s();
2364 test_qsort_s();
2365 test_bsearch_s();
2366 test_controlfp_s();
2367 test_tmpfile_s();
2368 test__atoflt();
2369 test__set_abort_behavior();
2370 test__sopen_s();
2371 test__wsopen_s();
2372 test__realloc_crt();
2373 test_typeinfo();
2374 test_getptd();
2375 test__vswprintf_l();
2376 test_nonblocking_file_access();
2377 test_byteswap();
2378 test_access_s();
2379 test_is_exception_typeof();
2380 test__AdjustPointer();
2381 test_mbstowcs();
2382 test_strtok_s();
2383 test__mbstok_s();
2384 test__memicmp();
2385 test__memicmp_l();
2386 test__vsnwprintf();
2387 #ifdef __i386__
2388 test__fpieee_flt();
2389 #endif
2390 test___strncnt();
2391 test_swscanf();
2392 test____mb_cur_max_l_func();
2393 test__get_current_locale();