comctl32: Don't use the RECT from the custom draw structure when referring to the...
[wine/multimedia.git] / dlls / msvcr90 / tests / msvcr90.c
blob0a81edc992fcdb2e8c4f5a9b171017bb9555d57a
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>
29 #include <windef.h>
30 #include <winbase.h>
31 #include <errno.h>
32 #include "wine/test.h"
34 #define DEFINE_EXPECT(func) \
35 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37 #define SET_EXPECT(func) \
38 do { \
39 expect_ ## func = TRUE; \
40 errno = 0xdeadbeef; \
41 }while(0)
43 #define CHECK_EXPECT2(func) \
44 do { \
45 ok(expect_ ##func, "unexpected call " #func "\n"); \
46 called_ ## func = TRUE; \
47 }while(0)
49 #define CHECK_EXPECT(func) \
50 do { \
51 CHECK_EXPECT2(func); \
52 expect_ ## func = FALSE; \
53 }while(0)
55 #define CHECK_CALLED(func,error) \
56 do { \
57 ok(called_ ## func, "expected " #func "\n"); \
58 ok( errno == (error), "got errno %u instead of %u\n", errno, (error) ); \
59 expect_ ## func = called_ ## func = FALSE; \
60 }while(0)
62 DEFINE_EXPECT(invalid_parameter_handler);
64 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
65 typedef int (__cdecl *_INITTERM_E_FN)(void);
66 static int (__cdecl *p_initterm_e)(_INITTERM_E_FN *table, _INITTERM_E_FN *end);
67 static void* (__cdecl *p_encode_pointer)(void *);
68 static void* (__cdecl *p_decode_pointer)(void *);
69 static void* (__cdecl *p_encoded_null)(void);
70 static int *p_sys_nerr;
71 static int* (__cdecl *p__sys_nerr)(void);
72 static char **p_sys_errlist;
73 static char** (__cdecl *p__sys_errlist)(void);
74 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
75 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
76 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
77 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
78 static void (__cdecl *p_qsort_s)(void *, size_t, size_t, int (__cdecl *)(void *, const void *, const void *), void *);
79 static void* (__cdecl *p_bsearch_s)(const void *, const void *, size_t, size_t,
80 int (__cdecl *compare)(void *, const void *, const void *), void *);
81 static int (__cdecl *p_controlfp_s)(unsigned int *, unsigned int, unsigned int);
82 static int (__cdecl *p_tmpfile_s)(FILE**);
83 static int (__cdecl *p_atoflt)(_CRT_FLOAT *, char *);
84 static unsigned int (__cdecl *p_set_abort_behavior)(unsigned int, unsigned int);
85 static int (__cdecl *p_sopen_s)(int*, const char*, int, int, int);
86 static int (__cdecl *p_wsopen_s)(int*, const wchar_t*, int, int, int);
87 static void* (__cdecl *p_realloc_crt)(void*, size_t);
88 static void* (__cdecl *p_malloc)(size_t);
89 static void (__cdecl *p_free)(void*);
90 static void* (__cdecl *p_getptd)(void);
91 static int* (__cdecl *p_errno)(void);
92 static __msvcrt_ulong* (__cdecl *p_doserrno)(void);
93 static void (__cdecl *p_srand)(unsigned int);
94 static char* (__cdecl *p_strtok)(char*, const char*);
95 static wchar_t* (__cdecl *p_wcstok)(wchar_t*, const wchar_t*);
96 static unsigned char* (__cdecl *p__mbstok)(unsigned char*, const unsigned char*);
97 static char* (__cdecl *p_strerror)(int);
98 static wchar_t* (__cdecl *p_wcserror)(int);
99 static char* (__cdecl *p_tmpnam)(char*);
100 static wchar_t* (__cdecl *p_wtmpnam)(wchar_t*);
101 static char* (__cdecl *p_asctime)(struct tm*);
102 static wchar_t* (__cdecl *p_wasctime)(struct tm*);
103 static struct tm* (__cdecl *p_localtime64)(__time64_t*);
104 static char* (__cdecl *p_ecvt)(double, int, int*, int*);
105 static int* (__cdecl *p_fpecode)(void);
106 static int (__cdecl *p_configthreadlocale)(int);
107 static void* (__cdecl *p_get_terminate)(void);
108 static void* (__cdecl *p_get_unexpected)(void);
109 static int (__cdecl *p__vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, __ms_va_list);
110 static int (__cdecl *p_vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, __ms_va_list);
111 static FILE* (__cdecl *p_fopen)(const char*, const char*);
112 static int (__cdecl *p_fclose)(FILE*);
113 static int (__cdecl *p_unlink)(const char*);
114 static int (__cdecl *p_access_s)(const char*, int);
115 static void (__cdecl *p_lock_file)(FILE*);
116 static void (__cdecl *p_unlock_file)(FILE*);
117 static int (__cdecl *p_fileno)(FILE*);
118 static int (__cdecl *p_feof)(FILE*);
119 static int (__cdecl *p_ferror)(FILE*);
120 static int (__cdecl *p_flsbuf)(int, FILE*);
121 static unsigned long (__cdecl *p_byteswap_ulong)(unsigned long);
122 static void** (__cdecl *p__pxcptinfoptrs)(void);
123 static void* (__cdecl *p__AdjustPointer)(void*, const void*);
125 /* make sure we use the correct errno */
126 #undef errno
127 #define errno (*p_errno())
129 /* type info */
130 typedef struct __type_info
132 void *vtable;
133 char *name;
134 char mangled[16];
135 } type_info;
137 struct __type_info_node
139 void *memPtr;
140 struct __type_info_node* next;
143 static char* (WINAPI *p_type_info_name_internal_method)(type_info*, struct __type_info_node *);
144 static void (WINAPI *ptype_info_dtor)(type_info*);
146 #define CXX_FRAME_MAGIC_VC6 0x19930520
147 #define CXX_EXCEPTION 0xe06d7363
149 /* offsets for computing the this pointer */
150 typedef struct
152 int this_offset; /* offset of base class this pointer from start of object */
153 int vbase_descr; /* offset of virtual base class descriptor */
154 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
155 } this_ptr_offsets;
157 typedef void (*cxx_copy_ctor)(void);
159 /* complete information about a C++ type */
160 #ifndef __x86_64__
161 typedef struct __cxx_type_info
163 UINT flags; /* flags (see CLASS_* flags below) */
164 const type_info *type_info; /* C++ type info */
165 this_ptr_offsets offsets; /* offsets for computing the this pointer */
166 unsigned int size; /* object size */
167 cxx_copy_ctor copy_ctor; /* copy constructor */
168 } cxx_type_info;
169 #else
170 typedef struct __cxx_type_info
172 UINT flags;
173 unsigned int type_info;
174 this_ptr_offsets offsets;
175 unsigned int size;
176 unsigned int copy_ctor;
177 } cxx_type_info;
178 #endif
180 /* table of C++ types that apply for a given object */
181 #ifndef __x86_64__
182 typedef struct __cxx_type_info_table
184 UINT count; /* number of types */
185 const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
186 } cxx_type_info_table;
187 #else
188 typedef struct __cxx_type_info_table
190 UINT count;
191 unsigned int info[3];
192 } cxx_type_info_table;
193 #endif
195 /* type information for an exception object */
196 #ifndef __x86_64__
197 typedef struct __cxx_exception_type
199 UINT flags; /* TYPE_FLAG flags */
200 void (*destructor)(void);/* exception object destructor */
201 void *custom_handler; /* custom handler for this exception */
202 const cxx_type_info_table *type_info_table; /* list of types for this exception object */
203 } cxx_exception_type;
204 #else
205 typedef struct
207 UINT flags;
208 unsigned int destructor;
209 unsigned int custom_handler;
210 unsigned int type_info_table;
211 } cxx_exception_type;
212 #endif
214 static int (__cdecl *p_is_exception_typeof)(const type_info*, EXCEPTION_POINTERS*);
216 static void* (WINAPI *pEncodePointer)(void *);
218 static int cb_called[4];
219 static int g_qsort_s_context_counter;
220 static int g_bsearch_s_context_counter;
222 static inline int almost_equal_f(float f1, float f2)
224 return f1-f2 > -1e-30 && f1-f2 < 1e-30;
227 /* ########## */
229 /* thiscall emulation */
230 /* Emulate a __thiscall */
231 #ifdef __i386__
232 #ifdef _MSC_VER
233 static inline void* do_call_func1(void *func, void *_this)
235 volatile void* retval = 0;
236 __asm
238 push ecx
239 mov ecx, _this
240 call func
241 mov retval, eax
242 pop ecx
244 return (void*)retval;
247 static inline void* do_call_func2(void *func, void *_this, const void* arg)
249 volatile void* retval = 0;
250 __asm
252 push ecx
253 push arg
254 mov ecx, _this
255 call func
256 mov retval, eax
257 pop ecx
259 return (void*)retval;
261 #else
262 static void* do_call_func1(void *func, void *_this)
264 void *ret, *dummy;
265 __asm__ __volatile__ ("call *%2"
266 : "=a" (ret), "=c" (dummy)
267 : "g" (func), "1" (_this)
268 : "edx", "memory" );
269 return ret;
272 static void* do_call_func2(void *func, void *_this, const void* arg)
274 void *ret, *dummy;
275 __asm__ __volatile__ ("pushl %3\n\tcall *%2"
276 : "=a" (ret), "=c" (dummy)
277 : "r" (func), "r" (arg), "1" (_this)
278 : "edx", "memory" );
279 return ret;
281 #endif
283 #define call_func1(func,_this) do_call_func1(func,_this)
284 #define call_func2(func,_this,a) do_call_func2(func,_this,(const void*)a)
286 #else
288 #define call_func1(func,_this) func(_this)
289 #define call_func2(func,_this,a) func(_this,a)
291 #endif /* __i386__ */
293 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
294 const wchar_t *function, const wchar_t *file,
295 unsigned line, uintptr_t arg)
297 CHECK_EXPECT(invalid_parameter_handler);
298 ok(expression == NULL, "expression is not NULL\n");
299 ok(function == NULL, "function is not NULL\n");
300 ok(file == NULL, "file is not NULL\n");
301 ok(line == 0, "line = %u\n", line);
302 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
303 ok(errno != 0xdeadbeef, "errno not set\n");
306 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
307 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
308 static BOOL init(void)
310 HMODULE hcrt;
311 HMODULE hkernel32;
313 SetLastError(0xdeadbeef);
314 hcrt = LoadLibraryA("msvcr90.dll");
315 if (!hcrt) {
316 win_skip("msvcr90.dll not installed (got %d)\n", GetLastError());
317 return FALSE;
320 SET(p_set_invalid_parameter_handler, "_set_invalid_parameter_handler");
321 if(p_set_invalid_parameter_handler)
322 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
323 "Invalid parameter handler was already set\n");
325 SET(p_initterm_e, "_initterm_e");
326 SET(p_encode_pointer, "_encode_pointer");
327 SET(p_decode_pointer, "_decode_pointer");
328 SET(p_encoded_null, "_encoded_null");
329 SET(p_sys_nerr, "_sys_nerr");
330 SET(p__sys_nerr, "__sys_nerr");
331 SET(p_sys_errlist, "_sys_errlist");
332 SET(p__sys_errlist, "__sys_errlist");
333 SET(p_strtoi64, "_strtoi64");
334 SET(p_strtoui64, "_strtoui64");
335 SET(p_itoa_s, "_itoa_s");
336 SET(p_wcsncat_s,"wcsncat_s" );
337 SET(p_qsort_s, "qsort_s");
338 SET(p_bsearch_s, "bsearch_s");
339 SET(p_controlfp_s, "_controlfp_s");
340 SET(p_tmpfile_s, "tmpfile_s");
341 SET(p_atoflt, "_atoflt");
342 SET(p_set_abort_behavior, "_set_abort_behavior");
343 SET(p_sopen_s, "_sopen_s");
344 SET(p_wsopen_s, "_wsopen_s");
345 SET(p_realloc_crt, "_realloc_crt");
346 SET(p_malloc, "malloc");
347 SET(p_free, "free");
348 SET(p_getptd, "_getptd");
349 SET(p_errno, "_errno");
350 SET(p_doserrno, "__doserrno");
351 SET(p_srand, "srand");
352 SET(p_strtok, "strtok");
353 SET(p_wcstok, "wcstok");
354 SET(p__mbstok, "_mbstok");
355 SET(p_strerror, "strerror");
356 SET(p_wcserror, "_wcserror");
357 SET(p_tmpnam, "tmpnam");
358 SET(p_wtmpnam, "_wtmpnam");
359 SET(p_asctime, "asctime");
360 SET(p_wasctime, "_wasctime");
361 SET(p_localtime64, "_localtime64");
362 SET(p_ecvt, "_ecvt");
363 SET(p_fpecode, "__fpecode");
364 SET(p_configthreadlocale, "_configthreadlocale");
365 SET(p_get_terminate, "_get_terminate");
366 SET(p_get_unexpected, "_get_unexpected");
367 SET(p__vswprintf_l, "__vswprintf_l");
368 SET(p_vswprintf_l, "_vswprintf_l");
369 SET(p_fopen, "fopen");
370 SET(p_fclose, "fclose");
371 SET(p_unlink, "_unlink");
372 SET(p_access_s, "_access_s");
373 SET(p_lock_file, "_lock_file");
374 SET(p_unlock_file, "_unlock_file");
375 SET(p_fileno, "_fileno");
376 SET(p_feof, "feof");
377 SET(p_ferror, "ferror");
378 SET(p_flsbuf, "_flsbuf");
379 SET(p_byteswap_ulong, "_byteswap_ulong");
380 SET(p__pxcptinfoptrs, "__pxcptinfoptrs");
381 SET(p__AdjustPointer, "__AdjustPointer");
382 if (sizeof(void *) == 8)
384 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QEBAPEBDPEAU__type_info_node@@@Z");
385 SET(ptype_info_dtor, "??1type_info@@UEAA@XZ");
386 SET(p_is_exception_typeof, "?_is_exception_typeof@@YAHAEBVtype_info@@PEAU_EXCEPTION_POINTERS@@@Z");
388 else
390 #ifdef __arm__
391 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QBAPBDPAU__type_info_node@@@Z");
392 SET(ptype_info_dtor, "??1type_info@@UAA@XZ");
393 #else
394 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z");
395 SET(ptype_info_dtor, "??1type_info@@UAE@XZ");
396 #endif
397 SET(p_is_exception_typeof, "?_is_exception_typeof@@YAHABVtype_info@@PAU_EXCEPTION_POINTERS@@@Z");
400 hkernel32 = GetModuleHandleA("kernel32.dll");
401 pEncodePointer = (void *) GetProcAddress(hkernel32, "EncodePointer");
402 return TRUE;
405 static int __cdecl initterm_cb0(void)
407 cb_called[0]++;
408 return 0;
411 static int __cdecl initterm_cb1(void)
413 cb_called[1]++;
414 return 1;
417 static int __cdecl initterm_cb2(void)
419 cb_called[2]++;
420 return 2;
424 static void test__initterm_e(void)
426 _INITTERM_E_FN table[4];
427 int res;
429 memset(table, 0, sizeof(table));
431 memset(cb_called, 0, sizeof(cb_called));
432 errno = 0xdeadbeef;
433 res = p_initterm_e(table, table);
434 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
435 "got %d with 0x%x {%d, %d, %d}\n",
436 res, errno, cb_called[0], cb_called[1], cb_called[2]);
438 memset(cb_called, 0, sizeof(cb_called));
439 errno = 0xdeadbeef;
440 res = p_initterm_e(table, NULL);
441 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
442 "got %d with 0x%x {%d, %d, %d}\n",
443 res, errno, cb_called[0], cb_called[1], cb_called[2]);
445 if (0) {
446 /* this crash on Windows */
447 errno = 0xdeadbeef;
448 res = p_initterm_e(NULL, table);
449 trace("got %d with 0x%x\n", res, errno);
452 table[0] = initterm_cb0;
453 memset(cb_called, 0, sizeof(cb_called));
454 errno = 0xdeadbeef;
455 res = p_initterm_e(table, &table[1]);
456 ok( !res && (cb_called[0] == 1) && !cb_called[1] && !cb_called[2],
457 "got %d with 0x%x {%d, %d, %d}\n",
458 res, errno, cb_called[0], cb_called[1], cb_called[2]);
461 /* init-function returning failure */
462 table[1] = initterm_cb1;
463 memset(cb_called, 0, sizeof(cb_called));
464 errno = 0xdeadbeef;
465 res = p_initterm_e(table, &table[3]);
466 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
467 "got %d with 0x%x {%d, %d, %d}\n",
468 res, errno, cb_called[0], cb_called[1], cb_called[2]);
470 /* init-function not called, when end < start */
471 memset(cb_called, 0, sizeof(cb_called));
472 errno = 0xdeadbeef;
473 res = p_initterm_e(&table[3], table);
474 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
475 "got %d with 0x%x {%d, %d, %d}\n",
476 res, errno, cb_called[0], cb_called[1], cb_called[2]);
478 /* initialization stop after first non-zero result */
479 table[2] = initterm_cb0;
480 memset(cb_called, 0, sizeof(cb_called));
481 errno = 0xdeadbeef;
482 res = p_initterm_e(table, &table[3]);
483 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
484 "got %d with 0x%x {%d, %d, %d}\n",
485 res, errno, cb_called[0], cb_called[1], cb_called[2]);
487 /* NULL pointer in the array are skipped */
488 table[1] = NULL;
489 table[2] = initterm_cb2;
490 memset(cb_called, 0, sizeof(cb_called));
491 errno = 0xdeadbeef;
492 res = p_initterm_e(table, &table[3]);
493 ok( (res == 2) && (cb_called[0] == 1) && !cb_called[1] && (cb_called[2] == 1),
494 "got %d with 0x%x {%d, %d, %d}\n",
495 res, errno, cb_called[0], cb_called[1], cb_called[2]);
499 /* Beware that _encode_pointer is a NOP before XP
500 (the parameter is returned unchanged) */
501 static void test__encode_pointer(void)
503 void *ptr, *res;
505 ptr = (void*)0xdeadbeef;
506 res = p_encode_pointer(ptr);
507 res = p_decode_pointer(res);
508 ok(res == ptr, "Pointers are different after encoding and decoding\n");
510 ok(p_encoded_null() == p_encode_pointer(NULL), "Error encoding null\n");
512 ptr = p_encode_pointer(p_encode_pointer);
513 ok(p_decode_pointer(ptr) == p_encode_pointer, "Error decoding pointer\n");
515 /* Not present before XP */
516 if (!pEncodePointer) {
517 win_skip("EncodePointer not found\n");
518 return;
521 res = pEncodePointer(p_encode_pointer);
522 ok(ptr == res, "_encode_pointer produced different result than EncodePointer\n");
526 static void test_error_messages(void)
528 int *size, size_copy;
530 size = p__sys_nerr();
531 size_copy = *size;
532 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
534 *size = 20;
535 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
537 *size = size_copy;
539 ok(*p_sys_errlist == *(p__sys_errlist()), "p_sys_errlist != p__sys_errlist()\n");
542 static void test__strtoi64(void)
544 __int64 res;
545 unsigned __int64 ures;
547 SET_EXPECT(invalid_parameter_handler);
548 res = p_strtoi64(NULL, NULL, 10);
549 ok(res == 0, "res != 0\n");
550 CHECK_CALLED(invalid_parameter_handler, EINVAL);
552 SET_EXPECT(invalid_parameter_handler);
553 res = p_strtoi64("123", NULL, 1);
554 ok(res == 0, "res != 0\n");
555 CHECK_CALLED(invalid_parameter_handler, EINVAL);
557 SET_EXPECT(invalid_parameter_handler);
558 res = p_strtoi64("123", NULL, 37);
559 ok(res == 0, "res != 0\n");
560 CHECK_CALLED(invalid_parameter_handler, EINVAL);
562 SET_EXPECT(invalid_parameter_handler);
563 ures = p_strtoui64(NULL, NULL, 10);
564 ok(ures == 0, "res = %d\n", (int)ures);
565 CHECK_CALLED(invalid_parameter_handler, EINVAL);
567 SET_EXPECT(invalid_parameter_handler);
568 ures = p_strtoui64("123", NULL, 1);
569 ok(ures == 0, "res = %d\n", (int)ures);
570 CHECK_CALLED(invalid_parameter_handler, EINVAL);
572 SET_EXPECT(invalid_parameter_handler);
573 ures = p_strtoui64("123", NULL, 37);
574 ok(ures == 0, "res = %d\n", (int)ures);
575 CHECK_CALLED(invalid_parameter_handler, EINVAL);
578 static void test__itoa_s(void)
580 errno_t ret;
581 char buffer[33];
583 SET_EXPECT(invalid_parameter_handler);
584 ret = p_itoa_s(0, NULL, 0, 0);
585 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
586 CHECK_CALLED(invalid_parameter_handler, EINVAL);
588 memset(buffer, 'X', sizeof(buffer));
589 SET_EXPECT(invalid_parameter_handler);
590 ret = p_itoa_s(0, buffer, 0, 0);
591 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
592 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
593 CHECK_CALLED(invalid_parameter_handler, EINVAL);
595 memset(buffer, 'X', sizeof(buffer));
596 SET_EXPECT(invalid_parameter_handler);
597 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
598 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
599 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
600 CHECK_CALLED(invalid_parameter_handler, EINVAL);
602 memset(buffer, 'X', sizeof(buffer));
603 SET_EXPECT(invalid_parameter_handler);
604 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
605 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
606 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
607 CHECK_CALLED(invalid_parameter_handler, EINVAL);
609 memset(buffer, 'X', sizeof(buffer));
610 SET_EXPECT(invalid_parameter_handler);
611 ret = p_itoa_s(12345678, buffer, 4, 10);
612 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
613 ok(!memcmp(buffer, "\000765", 4),
614 "Expected the output buffer to be null terminated with truncated output\n");
615 CHECK_CALLED(invalid_parameter_handler, ERANGE);
617 memset(buffer, 'X', sizeof(buffer));
618 SET_EXPECT(invalid_parameter_handler);
619 ret = p_itoa_s(12345678, buffer, 8, 10);
620 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
621 ok(!memcmp(buffer, "\0007654321", 8),
622 "Expected the output buffer to be null terminated with truncated output\n");
623 CHECK_CALLED(invalid_parameter_handler, ERANGE);
625 memset(buffer, 'X', sizeof(buffer));
626 SET_EXPECT(invalid_parameter_handler);
627 ret = p_itoa_s(-12345678, buffer, 9, 10);
628 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
629 ok(!memcmp(buffer, "\00087654321", 9),
630 "Expected the output buffer to be null terminated with truncated output\n");
631 CHECK_CALLED(invalid_parameter_handler, ERANGE);
633 ret = p_itoa_s(12345678, buffer, 9, 10);
634 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
635 ok(!strcmp(buffer, "12345678"),
636 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
637 buffer);
639 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
640 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
641 ok(!strcmp(buffer, "1010101010101010"),
642 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
643 buffer);
645 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
646 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
647 ok(!strcmp(buffer, "nell"),
648 "Expected output buffer string to be \"nell\", got \"%s\"\n",
649 buffer);
651 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
652 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
653 ok(!strcmp(buffer, "hag"),
654 "Expected output buffer string to be \"hag\", got \"%s\"\n",
655 buffer);
657 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
658 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
659 ok(!strcmp(buffer, "-12345678"),
660 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
661 buffer);
664 static void test_wcsncat_s(void)
666 static wchar_t abcW[] = {'a','b','c',0};
667 int ret;
668 wchar_t dst[4];
669 wchar_t src[4];
671 memcpy(src, abcW, sizeof(abcW));
672 dst[0] = 0;
673 SET_EXPECT(invalid_parameter_handler);
674 ret = p_wcsncat_s(NULL, 4, src, 4);
675 ok(ret == EINVAL, "err = %d\n", ret);
676 CHECK_CALLED(invalid_parameter_handler, EINVAL);
678 SET_EXPECT(invalid_parameter_handler);
679 ret = p_wcsncat_s(dst, 0, src, 4);
680 ok(ret == EINVAL, "err = %d\n", ret);
681 CHECK_CALLED(invalid_parameter_handler, EINVAL);
683 SET_EXPECT(invalid_parameter_handler);
684 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
685 ok(ret == EINVAL, "err = %d\n", ret);
686 CHECK_CALLED(invalid_parameter_handler, EINVAL);
688 ret = p_wcsncat_s(dst, 4, NULL, 0);
689 ok(ret == 0, "err = %d\n", ret);
691 dst[0] = 0;
692 SET_EXPECT(invalid_parameter_handler);
693 ret = p_wcsncat_s(dst, 2, src, 4);
694 ok(ret == ERANGE, "err = %d\n", ret);
695 CHECK_CALLED(invalid_parameter_handler, ERANGE);
697 dst[0] = 0;
698 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
699 ok(ret == STRUNCATE, "err = %d\n", ret);
700 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
702 memcpy(dst, abcW, sizeof(abcW));
703 dst[3] = 'd';
704 SET_EXPECT(invalid_parameter_handler);
705 ret = p_wcsncat_s(dst, 4, src, 4);
706 ok(ret == EINVAL, "err = %d\n", ret);
707 CHECK_CALLED(invalid_parameter_handler, EINVAL);
710 /* Based on dlls/ntdll/tests/string.c */
711 static __cdecl int intcomparefunc(void *context, const void *a, const void *b)
713 const int *p = a, *q = b;
715 ok (a != b, "must never get the same pointer\n");
716 ++*(int *) context;
718 return *p - *q;
721 static __cdecl int charcomparefunc(void *context, const void *a, const void *b)
723 const char *p = a, *q = b;
725 ok (a != b, "must never get the same pointer\n");
726 ++*(int *) context;
728 return *p - *q;
731 static __cdecl int strcomparefunc(void *context, const void *a, const void *b)
733 const char * const *p = a;
734 const char * const *q = b;
736 ok (a != b, "must never get the same pointer\n");
737 ++*(int *) context;
739 return lstrcmpA(*p, *q);
742 static void test_qsort_s(void)
744 int arr[5] = { 23, 42, 8, 4, 16 };
745 int arr2[5] = { 23, 42, 8, 4, 16 };
746 char carr[5] = { 42, 23, 4, 8, 16 };
747 const char *strarr[7] = {
748 "Hello",
749 "Wine",
750 "World",
751 "!",
752 "Hopefully",
753 "Sorted",
757 SET_EXPECT(invalid_parameter_handler);
758 p_qsort_s(NULL, 0, 0, NULL, NULL);
759 CHECK_CALLED(invalid_parameter_handler, EINVAL);
761 SET_EXPECT(invalid_parameter_handler);
762 p_qsort_s(NULL, 0, 0, intcomparefunc, NULL);
763 CHECK_CALLED(invalid_parameter_handler, EINVAL);
765 SET_EXPECT(invalid_parameter_handler);
766 p_qsort_s(NULL, 0, sizeof(int), NULL, NULL);
767 CHECK_CALLED(invalid_parameter_handler, EINVAL);
769 SET_EXPECT(invalid_parameter_handler);
770 p_qsort_s(NULL, 1, sizeof(int), intcomparefunc, NULL);
771 CHECK_CALLED(invalid_parameter_handler, EINVAL);
773 errno = 0xdeadbeef;
774 g_qsort_s_context_counter = 0;
775 p_qsort_s(NULL, 0, sizeof(int), intcomparefunc, NULL);
776 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
777 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
779 /* overflow without side effects, other overflow values crash */
780 errno = 0xdeadbeef;
781 g_qsort_s_context_counter = 0;
782 p_qsort_s((void*)arr2, (((size_t)1) << (8*sizeof(size_t) - 1)) + 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
783 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
784 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
785 ok(arr2[0] == 23, "should remain unsorted, arr2[0] is %d\n", arr2[0]);
786 ok(arr2[1] == 42, "should remain unsorted, arr2[1] is %d\n", arr2[1]);
787 ok(arr2[2] == 8, "should remain unsorted, arr2[2] is %d\n", arr2[2]);
788 ok(arr2[3] == 4, "should remain unsorted, arr2[3] is %d\n", arr2[3]);
790 errno = 0xdeadbeef;
791 g_qsort_s_context_counter = 0;
792 p_qsort_s((void*)arr, 0, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
793 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
794 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
795 ok(arr[0] == 23, "badly sorted, nmemb=0, arr[0] is %d\n", arr[0]);
796 ok(arr[1] == 42, "badly sorted, nmemb=0, arr[1] is %d\n", arr[1]);
797 ok(arr[2] == 8, "badly sorted, nmemb=0, arr[2] is %d\n", arr[2]);
798 ok(arr[3] == 4, "badly sorted, nmemb=0, arr[3] is %d\n", arr[3]);
799 ok(arr[4] == 16, "badly sorted, nmemb=0, arr[4] is %d\n", arr[4]);
801 errno = 0xdeadbeef;
802 g_qsort_s_context_counter = 0;
803 p_qsort_s((void*)arr, 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
804 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
805 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
806 ok(arr[0] == 23, "badly sorted, nmemb=1, arr[0] is %d\n", arr[0]);
807 ok(arr[1] == 42, "badly sorted, nmemb=1, arr[1] is %d\n", arr[1]);
808 ok(arr[2] == 8, "badly sorted, nmemb=1, arr[2] is %d\n", arr[2]);
809 ok(arr[3] == 4, "badly sorted, nmemb=1, arr[3] is %d\n", arr[3]);
810 ok(arr[4] == 16, "badly sorted, nmemb=1, arr[4] is %d\n", arr[4]);
812 SET_EXPECT(invalid_parameter_handler);
813 g_qsort_s_context_counter = 0;
814 p_qsort_s((void*)arr, 5, 0, intcomparefunc, &g_qsort_s_context_counter);
815 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
816 ok(arr[0] == 23, "badly sorted, size=0, arr[0] is %d\n", arr[0]);
817 ok(arr[1] == 42, "badly sorted, size=0, arr[1] is %d\n", arr[1]);
818 ok(arr[2] == 8, "badly sorted, size=0, arr[2] is %d\n", arr[2]);
819 ok(arr[3] == 4, "badly sorted, size=0, arr[3] is %d\n", arr[3]);
820 ok(arr[4] == 16, "badly sorted, size=0, arr[4] is %d\n", arr[4]);
821 CHECK_CALLED(invalid_parameter_handler, EINVAL);
823 g_qsort_s_context_counter = 0;
824 p_qsort_s((void*)arr, 5, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
825 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
826 ok(arr[0] == 4, "badly sorted, arr[0] is %d\n", arr[0]);
827 ok(arr[1] == 8, "badly sorted, arr[1] is %d\n", arr[1]);
828 ok(arr[2] == 16, "badly sorted, arr[2] is %d\n", arr[2]);
829 ok(arr[3] == 23, "badly sorted, arr[3] is %d\n", arr[3]);
830 ok(arr[4] == 42, "badly sorted, arr[4] is %d\n", arr[4]);
832 g_qsort_s_context_counter = 0;
833 p_qsort_s((void*)carr, 5, sizeof(char), charcomparefunc, &g_qsort_s_context_counter);
834 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
835 ok(carr[0] == 4, "badly sorted, carr[0] is %d\n", carr[0]);
836 ok(carr[1] == 8, "badly sorted, carr[1] is %d\n", carr[1]);
837 ok(carr[2] == 16, "badly sorted, carr[2] is %d\n", carr[2]);
838 ok(carr[3] == 23, "badly sorted, carr[3] is %d\n", carr[3]);
839 ok(carr[4] == 42, "badly sorted, carr[4] is %d\n", carr[4]);
841 g_qsort_s_context_counter = 0;
842 p_qsort_s((void*)strarr, 7, sizeof(char*), strcomparefunc, &g_qsort_s_context_counter);
843 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
844 ok(!strcmp(strarr[0],"!"), "badly sorted, strarr[0] is %s\n", strarr[0]);
845 ok(!strcmp(strarr[1],"."), "badly sorted, strarr[1] is %s\n", strarr[1]);
846 ok(!strcmp(strarr[2],"Hello"), "badly sorted, strarr[2] is %s\n", strarr[2]);
847 ok(!strcmp(strarr[3],"Hopefully"), "badly sorted, strarr[3] is %s\n", strarr[3]);
848 ok(!strcmp(strarr[4],"Sorted"), "badly sorted, strarr[4] is %s\n", strarr[4]);
849 ok(!strcmp(strarr[5],"Wine"), "badly sorted, strarr[5] is %s\n", strarr[5]);
850 ok(!strcmp(strarr[6],"World"), "badly sorted, strarr[6] is %s\n", strarr[6]);
853 static void test_bsearch_s(void)
855 int arr[7] = { 1, 3, 4, 8, 16, 23, 42 };
856 int *x, l, i, j = 1;
858 SET_EXPECT(invalid_parameter_handler);
859 x = p_bsearch_s(NULL, NULL, 0, 0, NULL, NULL);
860 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
861 CHECK_CALLED(invalid_parameter_handler, EINVAL);
863 g_bsearch_s_context_counter = 0;
864 SET_EXPECT(invalid_parameter_handler);
865 x = p_bsearch_s(&l, arr, j, 0, intcomparefunc, &g_bsearch_s_context_counter);
866 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
867 ok(g_bsearch_s_context_counter == 0, "callback shouldn't have been called\n");
868 CHECK_CALLED(invalid_parameter_handler, EINVAL);
870 g_bsearch_s_context_counter = 0;
871 SET_EXPECT(invalid_parameter_handler);
872 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), NULL, &g_bsearch_s_context_counter);
873 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
874 ok(g_bsearch_s_context_counter == 0, "callback shouldn't have been called\n");
875 CHECK_CALLED(invalid_parameter_handler, EINVAL);
877 /* just try all array sizes */
878 for (j=1;j<sizeof(arr)/sizeof(arr[0]);j++) {
879 for (i=0;i<j;i++) {
880 l = arr[i];
881 g_bsearch_s_context_counter = 0;
882 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), intcomparefunc, &g_bsearch_s_context_counter);
883 ok (x == &arr[i], "bsearch_s did not find %d entry in loopsize %d.\n", i, j);
884 ok(g_bsearch_s_context_counter > 0, "callback wasn't called\n");
886 l = 4242;
887 g_bsearch_s_context_counter = 0;
888 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), intcomparefunc, &g_bsearch_s_context_counter);
889 ok (x == NULL, "bsearch_s did find 4242 entry in loopsize %d.\n", j);
890 ok(g_bsearch_s_context_counter > 0, "callback wasn't called\n");
894 static void test_controlfp_s(void)
896 unsigned int cur;
897 int ret;
899 SET_EXPECT(invalid_parameter_handler);
900 ret = p_controlfp_s( NULL, ~0, ~0 );
901 ok( ret == EINVAL, "wrong result %d\n", ret );
902 CHECK_CALLED(invalid_parameter_handler, EINVAL);
904 cur = 0xdeadbeef;
905 SET_EXPECT(invalid_parameter_handler);
906 ret = p_controlfp_s( &cur, ~0, ~0 );
907 ok( ret == EINVAL, "wrong result %d\n", ret );
908 ok( cur != 0xdeadbeef, "value not set\n" );
909 CHECK_CALLED(invalid_parameter_handler, EINVAL);
911 cur = 0xdeadbeef;
912 ret = p_controlfp_s( &cur, 0, 0 );
913 ok( !ret, "wrong result %d\n", ret );
914 ok( cur != 0xdeadbeef, "value not set\n" );
916 SET_EXPECT(invalid_parameter_handler);
917 cur = 0xdeadbeef;
918 ret = p_controlfp_s( &cur, 0x80000000, 0x80000000 );
919 ok( ret == EINVAL, "wrong result %d\n", ret );
920 ok( cur != 0xdeadbeef, "value not set\n" );
921 CHECK_CALLED(invalid_parameter_handler, EINVAL);
923 cur = 0xdeadbeef;
924 /* mask is only checked when setting invalid bits */
925 ret = p_controlfp_s( &cur, 0, 0x80000000 );
926 ok( !ret, "wrong result %d\n", ret );
927 ok( cur != 0xdeadbeef, "value not set\n" );
930 static void test_tmpfile_s( void )
932 int ret;
934 SET_EXPECT(invalid_parameter_handler);
935 ret = p_tmpfile_s(NULL);
936 ok(ret == EINVAL, "Expected tmpfile_s to return EINVAL, got %i\n", ret);
937 CHECK_CALLED(invalid_parameter_handler, EINVAL);
940 typedef struct
942 const char *str;
943 float flt;
944 int ret;
945 } _atoflt_test;
947 static const _atoflt_test _atoflt_testdata[] = {
948 { "12.1", 12.1, 0 },
949 { "-13.721", -13.721, 0 },
950 { "INF", 0.0, 0 },
951 { ".21e12", 0.21e12, 0 },
952 { "214353e-3", 214.353, 0 },
953 { "1d9999999999999999999", 0.0, _OVERFLOW },
954 { " d10", 0.0, 0 },
955 /* more significant digits */
956 { "1.23456789", 1.23456789, 0 },
957 { "1.23456789e1", 12.3456789, 0 },
958 { "1e39", 0.0, _OVERFLOW },
959 { "1e-39", 0.0, _UNDERFLOW },
960 { NULL }
963 static void test__atoflt(void)
965 _CRT_FLOAT flt;
966 int ret, i = 0;
968 if (0)
970 /* crashes on native */
971 p_atoflt(NULL, NULL);
972 p_atoflt(NULL, (char*)_atoflt_testdata[0].str);
973 p_atoflt(&flt, NULL);
976 while (_atoflt_testdata[i].str)
978 ret = p_atoflt(&flt, (char*)_atoflt_testdata[i].str);
979 ok(ret == _atoflt_testdata[i].ret, "got ret %d, expected ret %d, for %s\n", ret,
980 _atoflt_testdata[i].ret, _atoflt_testdata[i].str);
982 if (ret == 0)
983 ok(almost_equal_f(flt.f, _atoflt_testdata[i].flt), "got %f, expected %f, for %s\n", flt.f,
984 _atoflt_testdata[i].flt, _atoflt_testdata[i].str);
986 i++;
990 static void test__set_abort_behavior(void)
992 unsigned int res;
994 /* default is _WRITE_ABORT_MSG | _CALL_REPORTFAULT */
995 res = p_set_abort_behavior(0, 0);
996 ok (res == (_WRITE_ABORT_MSG | _CALL_REPORTFAULT),
997 "got 0x%x (expected 0x%x)\n", res, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
999 /* no internal mask */
1000 p_set_abort_behavior(0xffffffff, 0xffffffff);
1001 res = p_set_abort_behavior(0, 0);
1002 ok (res == 0xffffffff, "got 0x%x (expected 0x%x)\n", res, 0xffffffff);
1004 /* set to default value */
1005 p_set_abort_behavior(_WRITE_ABORT_MSG | _CALL_REPORTFAULT, 0xffffffff);
1008 static void test__sopen_s(void)
1010 int ret, fd;
1012 SET_EXPECT(invalid_parameter_handler);
1013 ret = p_sopen_s(NULL, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1014 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
1015 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1017 fd = 0xdead;
1018 ret = p_sopen_s(&fd, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1019 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
1020 ok(fd == -1, "got %d\n", fd);
1023 static void test__wsopen_s(void)
1025 wchar_t testW[] = {'t','e','s','t',0};
1026 int ret, fd;
1028 SET_EXPECT(invalid_parameter_handler);
1029 ret = p_wsopen_s(NULL, testW, _O_RDONLY, _SH_DENYNO, _S_IREAD);
1030 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
1031 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1033 fd = 0xdead;
1034 ret = p_wsopen_s(&fd, testW, _O_RDONLY, _SH_DENYNO, _S_IREAD);
1035 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
1036 ok(fd == -1, "got %d\n", fd);
1039 static void test__realloc_crt(void)
1041 void *mem;
1043 if (0)
1045 /* crashes on some systems starting Vista */
1046 p_realloc_crt(NULL, 10);
1049 mem = p_malloc(10);
1050 ok(mem != NULL, "memory not allocated\n");
1052 mem = p_realloc_crt(mem, 20);
1053 ok(mem != NULL, "memory not reallocated\n");
1055 mem = p_realloc_crt(mem, 0);
1056 ok(mem == NULL, "memory not freed\n");
1058 mem = p_realloc_crt(NULL, 0);
1059 ok(mem != NULL, "memory not (re)allocated for size 0\n");
1060 p_free(mem);
1063 static void test_typeinfo(void)
1065 static type_info t1 = { NULL, NULL,{'.','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
1066 struct __type_info_node node;
1067 char *name;
1069 /* name */
1070 t1.name = NULL;
1071 node.memPtr = NULL;
1072 node.next = NULL;
1073 name = call_func2(p_type_info_name_internal_method, &t1, &node);
1074 ok(name != NULL, "got %p\n", name);
1075 ok(name && t1.name && !strcmp(name, t1.name), "bad name '%s' for t1\n", name);
1077 ok(t1.name && !strcmp(t1.name, "class test1"), "demangled to '%s' for t1\n", t1.name);
1078 call_func1(ptype_info_dtor, &t1);
1081 /* Keep in sync with msvcrt/msvcrt.h */
1082 struct __thread_data {
1083 DWORD tid;
1084 HANDLE handle;
1085 int thread_errno;
1086 __msvcrt_ulong thread_doserrno;
1087 int unk1;
1088 unsigned int random_seed;
1089 char *strtok_next;
1090 wchar_t *wcstok_next;
1091 unsigned char *mbstok_next;
1092 char *strerror_buffer;
1093 wchar_t *wcserror_buffer;
1094 char *tmpnam_buffer;
1095 wchar_t *wtmpnam_buffer;
1096 void *unk2[2];
1097 char *asctime_buffer;
1098 wchar_t *wasctime_buffer;
1099 struct tm *time_buffer;
1100 char *efcvt_buffer;
1101 int unk3[2];
1102 void *unk4[3];
1103 EXCEPTION_POINTERS *xcptinfo;
1104 int fpecode;
1105 pthreadmbcinfo mbcinfo;
1106 pthreadlocinfo locinfo;
1107 BOOL have_locale;
1108 int unk5[1];
1109 void* terminate_handler;
1110 void* unexpected_handler;
1111 void* se_translator;
1112 void *unk6[3];
1113 int unk7;
1114 EXCEPTION_RECORD *exc_record;
1117 static void test_getptd(void)
1119 struct __thread_data *ptd = p_getptd();
1120 DWORD tid = GetCurrentThreadId();
1121 wchar_t testW[] = {'t','e','s','t',0}, tW[] = {'t',0}, *wp;
1122 char test[] = "test", *p;
1123 unsigned char mbstok_test[] = "test", *up;
1124 struct tm time;
1125 __time64_t secs = 0;
1126 int dec, sign;
1127 void *mbcinfo, *locinfo;
1129 ok(ptd->tid == tid, "ptd->tid = %x, expected %x\n", ptd->tid, tid);
1130 ok(ptd->handle == INVALID_HANDLE_VALUE, "ptd->handle = %p\n", ptd->handle);
1131 ok(p_errno() == &ptd->thread_errno, "ptd->thread_errno is different then _errno()\n");
1132 ok(p_doserrno() == &ptd->thread_doserrno, "ptd->thread_doserrno is different then __doserrno()\n");
1133 p_srand(1234);
1134 ok(ptd->random_seed == 1234, "ptd->random_seed = %d\n", ptd->random_seed);
1135 p = p_strtok(test, "t");
1136 ok(ptd->strtok_next == p+3, "ptd->strtok_next is incorrect\n");
1137 wp = p_wcstok(testW, tW);
1138 ok(ptd->wcstok_next == wp+3, "ptd->wcstok_next is incorrect\n");
1139 up = p__mbstok(mbstok_test, (unsigned char*)"t");
1140 ok(ptd->mbstok_next == up+3, "ptd->mbstok_next is incorrect\n");
1141 ok(p_strerror(0) == ptd->strerror_buffer, "ptd->strerror_buffer is incorrect\n");
1142 ok(p_wcserror(0) == ptd->wcserror_buffer, "ptd->wcserror_buffer is incorrect\n");
1143 ok(p_tmpnam(NULL) == ptd->tmpnam_buffer, "ptd->tmpnam_buffer is incorrect\n");
1144 ok(p_wtmpnam(NULL) == ptd->wtmpnam_buffer, "ptd->wtmpnam_buffer is incorrect\n");
1145 memset(&time, 0, sizeof(time));
1146 time.tm_mday = 1;
1147 ok(p_asctime(&time) == ptd->asctime_buffer, "ptd->asctime_buffer is incorrect\n");
1148 ok(p_wasctime(&time) == ptd->wasctime_buffer, "ptd->wasctime_buffer is incorrect\n");
1149 ok(p_localtime64(&secs) == ptd->time_buffer, "ptd->time_buffer is incorrect\n");
1150 ok(p_ecvt(3.12, 1, &dec, &sign) == ptd->efcvt_buffer, "ptd->efcvt_buffer is incorrect\n");
1151 ok(p__pxcptinfoptrs() == (void**)&ptd->xcptinfo, "ptd->xcptinfo is incorrect\n");
1152 ok(p_fpecode() == &ptd->fpecode, "ptd->fpecode is incorrect\n");
1153 mbcinfo = ptd->mbcinfo;
1154 locinfo = ptd->locinfo;
1155 todo_wine ok(ptd->have_locale == 1, "ptd->have_locale = %x\n", ptd->have_locale);
1156 p_configthreadlocale(1);
1157 todo_wine ok(mbcinfo == ptd->mbcinfo, "ptd->mbcinfo != mbcinfo\n");
1158 todo_wine ok(locinfo == ptd->locinfo, "ptd->locinfo != locinfo\n");
1159 todo_wine ok(ptd->have_locale == 3, "ptd->have_locale = %x\n", ptd->have_locale);
1160 ok(p_get_terminate() == ptd->terminate_handler, "ptd->terminate_handler != _get_terminate()\n");
1161 ok(p_get_unexpected() == ptd->unexpected_handler, "ptd->unexpected_handler != _get_unexpected()\n");
1164 static int __cdecl __vswprintf_l_wrapper(wchar_t *buf,
1165 const wchar_t *format, _locale_t locale, ...)
1167 int ret;
1168 __ms_va_list valist;
1169 __ms_va_start(valist, locale);
1170 ret = p__vswprintf_l(buf, format, locale, valist);
1171 __ms_va_end(valist);
1172 return ret;
1175 static int __cdecl _vswprintf_l_wrapper(wchar_t *buf,
1176 const wchar_t *format, _locale_t locale, ...)
1178 int ret;
1179 __ms_va_list valist;
1180 __ms_va_start(valist, locale);
1181 ret = p_vswprintf_l(buf, format, locale, valist);
1182 __ms_va_end(valist);
1183 return ret;
1186 static void test__vswprintf_l(void)
1188 static const wchar_t format[] = {'t','e','s','t',0};
1190 wchar_t buf[32];
1191 int ret;
1193 ret = __vswprintf_l_wrapper(buf, format, NULL);
1194 ok(ret == 4, "ret = %d\n", ret);
1195 ok(!memcmp(buf, format, sizeof(format)), "buf = %s, expected %s\n",
1196 wine_dbgstr_w(buf), wine_dbgstr_w(format));
1198 ret = _vswprintf_l_wrapper(buf, format, NULL);
1199 ok(ret == 4, "ret = %d\n", ret);
1200 ok(!memcmp(buf, format, sizeof(format)), "buf = %s, expected %s\n",
1201 wine_dbgstr_w(buf), wine_dbgstr_w(format));
1204 struct block_file_arg
1206 FILE *read;
1207 FILE *write;
1208 HANDLE init;
1209 HANDLE finish;
1212 static DWORD WINAPI block_file(void *arg)
1214 struct block_file_arg *files = arg;
1216 p_lock_file(files->read);
1217 p_lock_file(files->write);
1218 SetEvent(files->init);
1219 WaitForSingleObject(files->finish, INFINITE);
1220 p_unlock_file(files->read);
1221 p_unlock_file(files->write);
1222 return 0;
1225 static void test_nonblocking_file_access(void)
1227 HANDLE thread;
1228 struct block_file_arg arg;
1229 FILE *filer, *filew;
1230 int ret;
1232 if(!p_lock_file || !p_unlock_file) {
1233 win_skip("_lock_file not available\n");
1234 return;
1237 filew = p_fopen("test_file", "w");
1238 ok(filew != NULL, "unable to create test file\n");
1239 if(!filew)
1240 return;
1241 filer = p_fopen("test_file", "r");
1242 ok(filer != NULL, "unable to open test file\n");
1243 if(!filer) {
1244 p_fclose(filew);
1245 p_unlink("test_file");
1246 return;
1249 arg.read = filer;
1250 arg.write = filew;
1251 arg.init = CreateEventW(NULL, FALSE, FALSE, NULL);
1252 arg.finish = CreateEventW(NULL, FALSE, FALSE, NULL);
1253 ok(arg.init != NULL, "CreateEventW failed\n");
1254 ok(arg.finish != NULL, "CreateEventW failed\n");
1255 thread = CreateThread(NULL, 0, block_file, (void*)&arg, 0, NULL);
1256 ok(thread != NULL, "CreateThread failed\n");
1257 WaitForSingleObject(arg.init, INFINITE);
1259 ret = p_fileno(filer);
1260 ok(ret, "_fileno(filer) returned %d\n", ret);
1261 ret = p_fileno(filew);
1262 ok(ret, "_fileno(filew) returned %d\n", ret);
1264 ret = p_feof(filer);
1265 ok(ret==0, "feof(filer) returned %d\n", ret);
1266 ret = p_feof(filew);
1267 ok(ret==0, "feof(filew) returned %d\n", ret);
1269 ret = p_ferror(filer);
1270 ok(ret==0, "ferror(filer) returned %d\n", ret);
1271 ret = p_ferror(filew);
1272 ok(ret==0, "ferror(filew) returned %d\n", ret);
1274 ret = p_flsbuf('a', filer);
1275 ok(ret==-1, "_flsbuf(filer) returned %d\n", ret);
1276 ret = p_flsbuf('a', filew);
1277 ok(ret=='a', "_flsbuf(filew) returned %d\n", ret);
1279 SetEvent(arg.finish);
1280 WaitForSingleObject(thread, INFINITE);
1281 CloseHandle(arg.init);
1282 CloseHandle(arg.finish);
1283 CloseHandle(thread);
1284 p_fclose(filer);
1285 p_fclose(filew);
1286 p_unlink("test_file");
1289 static void test_byteswap(void)
1291 unsigned long ret;
1293 ret = p_byteswap_ulong(0x12345678);
1294 ok(ret == 0x78563412, "ret = %lx\n", ret);
1296 ret = p_byteswap_ulong(0);
1297 ok(ret == 0, "ret = %lx\n", ret);
1300 static void test_access_s(void)
1302 FILE *f;
1303 int res;
1305 f = p_fopen("test_file", "w");
1306 ok(f != NULL, "unable to create test file\n");
1307 if(!f)
1308 return;
1310 p_fclose(f);
1312 errno = 0xdeadbeef;
1313 res = p_access_s("test_file", 0);
1314 ok(res == 0, "got %x\n", res);
1315 ok(errno == 0xdeadbeef, "got %x\n", res);
1317 errno = 0xdeadbeef;
1318 res = p_access_s("test_file", 2);
1319 ok(res == 0, "got %x\n", res);
1320 ok(errno == 0xdeadbeef, "got %x\n", res);
1322 errno = 0xdeadbeef;
1323 res = p_access_s("test_file", 4);
1324 ok(res == 0, "got %x\n", res);
1325 ok(errno == 0xdeadbeef, "got %x\n", res);
1327 errno = 0xdeadbeef;
1328 res = p_access_s("test_file", 6);
1329 ok(res == 0, "got %x\n", res);
1330 ok(errno == 0xdeadbeef, "got %x\n", res);
1332 SetFileAttributesA("test_file", FILE_ATTRIBUTE_READONLY);
1334 errno = 0xdeadbeef;
1335 res = p_access_s("test_file", 0);
1336 ok(res == 0, "got %x\n", res);
1337 ok(errno == 0xdeadbeef, "got %x\n", res);
1339 errno = 0xdeadbeef;
1340 res = p_access_s("test_file", 2);
1341 ok(res == EACCES, "got %x\n", res);
1342 ok(errno == EACCES, "got %x\n", res);
1344 errno = 0xdeadbeef;
1345 res = p_access_s("test_file", 4);
1346 ok(res == 0, "got %x\n", res);
1347 ok(errno == 0xdeadbeef, "got %x\n", res);
1349 errno = 0xdeadbeef;
1350 res = p_access_s("test_file", 6);
1351 ok(res == EACCES, "got %x\n", res);
1352 ok(errno == EACCES, "got %x\n", res);
1354 SetFileAttributesA("test_file", FILE_ATTRIBUTE_NORMAL);
1356 p_unlink("test_file");
1358 errno = 0xdeadbeef;
1359 res = p_access_s("test_file", 0);
1360 ok(res == ENOENT, "got %x\n", res);
1361 ok(errno == ENOENT, "got %x\n", res);
1363 errno = 0xdeadbeef;
1364 res = p_access_s("test_file", 2);
1365 ok(res == ENOENT, "got %x\n", res);
1366 ok(errno == ENOENT, "got %x\n", res);
1368 errno = 0xdeadbeef;
1369 res = p_access_s("test_file", 4);
1370 ok(res == ENOENT, "got %x\n", res);
1371 ok(errno == ENOENT, "got %x\n", res);
1373 errno = 0xdeadbeef;
1374 res = p_access_s("test_file", 6);
1375 ok(res == ENOENT, "got %x\n", res);
1376 ok(errno == ENOENT, "got %x\n", res);
1379 #ifndef __x86_64__
1380 #define EXCEPTION_REF(instance, name) &instance.name
1381 #else
1382 #define EXCEPTION_REF(instance, name) FIELD_OFFSET(struct _exception_data, name)
1383 #endif
1384 static void test_is_exception_typeof(void)
1386 const type_info ti1 = {NULL, NULL, {'.','?','A','V','t','e','s','t','1','@','@',0}};
1387 const type_info ti2 = {NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0}};
1388 const type_info ti3 = {NULL, NULL, {'.','?','A','V','t','e','s','t','3','@','@',0}};
1390 const struct _exception_data {
1391 type_info ti1;
1392 type_info ti2;
1393 cxx_type_info cti1;
1394 cxx_type_info cti2;
1395 cxx_type_info_table tit;
1396 cxx_exception_type et;
1397 } exception_data = {
1398 {NULL, NULL, {'.','?','A','V','t','e','s','t','1','@','@',0}},
1399 {NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0}},
1400 {0, EXCEPTION_REF(exception_data, ti1)},
1401 {0, EXCEPTION_REF(exception_data, ti2)},
1402 {2, {EXCEPTION_REF(exception_data, cti1), EXCEPTION_REF(exception_data, cti2)}},
1403 {0, 0, 0, EXCEPTION_REF(exception_data, tit)}
1406 EXCEPTION_RECORD rec = {CXX_EXCEPTION, 0, NULL, NULL, 3, {CXX_FRAME_MAGIC_VC6, 0, (ULONG_PTR)&exception_data.et}};
1407 EXCEPTION_POINTERS except_ptrs = {&rec, NULL};
1409 int ret;
1411 #ifdef __x86_64__
1412 rec.NumberParameters = 4;
1413 rec.ExceptionInformation[3] = (ULONG_PTR)&exception_data;
1414 #endif
1416 ret = p_is_exception_typeof(&ti1, &except_ptrs);
1417 ok(ret == 1, "_is_exception_typeof returned %d\n", ret);
1418 ret = p_is_exception_typeof(&ti2, &except_ptrs);
1419 ok(ret == 1, "_is_exception_typeof returned %d\n", ret);
1420 ret = p_is_exception_typeof(&ti3, &except_ptrs);
1421 ok(ret == 0, "_is_exception_typeof returned %d\n", ret);
1424 static void test__AdjustPointer(void)
1426 int off = 0xf0;
1427 void *obj1 = &off;
1428 void *obj2 = (char*)&off - 2;
1429 struct test_data {
1430 void *ptr;
1431 void *ret;
1432 struct {
1433 int this_offset;
1434 int vbase_descr;
1435 int vbase_offset;
1436 } this_ptr_offsets;
1437 } data[] = {
1438 {NULL, NULL, {0, -1, 0}},
1439 {(void*)0xbeef, (void*)0xbef0, {1, -1, 1}},
1440 {(void*)0xbeef, (void*)0xbeee, {-1, -1, 0}},
1441 {&obj1, (char*)&obj1 + off, {0, 0, 0}},
1442 {(char*)&obj1 - 5, (char*)&obj1 + off, {0, 5, 0}},
1443 {(char*)&obj1 - 3, (char*)&obj1 + off + 24, {24, 3, 0}},
1444 {(char*)&obj2 - 17, (char*)&obj2 + off + 4, {4, 17, 2}}
1446 void *ret;
1447 int i;
1449 for(i=0; i<sizeof(data)/sizeof(data[0]); i++) {
1450 ret = p__AdjustPointer(data[i].ptr, &data[i].this_ptr_offsets);
1451 ok(ret == data[i].ret, "%d) __AdjustPointer returned %p, expected %p\n", i, ret, data[i].ret);
1455 START_TEST(msvcr90)
1457 if(!init())
1458 return;
1460 test__initterm_e();
1461 test__encode_pointer();
1462 test_error_messages();
1463 test__strtoi64();
1464 test__itoa_s();
1465 test_wcsncat_s();
1466 test_qsort_s();
1467 test_bsearch_s();
1468 test_controlfp_s();
1469 test_tmpfile_s();
1470 test__atoflt();
1471 test__set_abort_behavior();
1472 test__sopen_s();
1473 test__wsopen_s();
1474 test__realloc_crt();
1475 test_typeinfo();
1476 test_getptd();
1477 test__vswprintf_l();
1478 test_nonblocking_file_access();
1479 test_byteswap();
1480 test_access_s();
1481 test_is_exception_typeof();
1482 test__AdjustPointer();