msvcrt: Fix strncmp return value.
[wine.git] / dlls / msvcr90 / tests / msvcr90.c
blobcf73097b818a84085efb7497b676e27b9e6cee93
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 WX_OPEN 0x01
37 #define WX_ATEOF 0x02
38 #define WX_READNL 0x04
39 #define WX_PIPE 0x08
40 #define WX_DONTINHERIT 0x10
41 #define WX_APPEND 0x20
42 #define WX_TTY 0x40
43 #define WX_TEXT 0x80
45 #define MSVCRT_FD_BLOCK_SIZE 32
47 typedef struct {
48 HANDLE handle;
49 unsigned char wxflag;
50 char lookahead[3];
51 int exflag;
52 CRITICAL_SECTION crit;
53 char textmode : 7;
54 char unicode : 1;
55 char pipech2[2];
56 __int64 startpos;
57 BOOL utf8translations;
58 char dbcsBuffer;
59 BOOL dbcsBufferUsed;
60 } ioinfo;
61 static ioinfo **__pioinfo;
63 #define DEFINE_EXPECT(func) \
64 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
66 #define SET_EXPECT(func) \
67 do { \
68 expect_ ## func = TRUE; \
69 errno = 0xdeadbeef; \
70 }while(0)
72 #define CHECK_EXPECT2(func) \
73 do { \
74 ok(expect_ ##func, "unexpected call " #func "\n"); \
75 called_ ## func = TRUE; \
76 }while(0)
78 #define CHECK_EXPECT(func) \
79 do { \
80 CHECK_EXPECT2(func); \
81 expect_ ## func = FALSE; \
82 }while(0)
84 #define CHECK_CALLED(func,error) \
85 do { \
86 ok(called_ ## func, "expected " #func "\n"); \
87 ok( errno == (error), "got errno %u instead of %u\n", errno, (error) ); \
88 expect_ ## func = called_ ## func = FALSE; \
89 }while(0)
91 DEFINE_EXPECT(invalid_parameter_handler);
93 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
94 typedef int (__cdecl *_INITTERM_E_FN)(void);
95 static int (__cdecl *p_initterm_e)(_INITTERM_E_FN *table, _INITTERM_E_FN *end);
96 static void* (__cdecl *p_encode_pointer)(void *);
97 static void* (__cdecl *p_decode_pointer)(void *);
98 static void* (__cdecl *p_encoded_null)(void);
99 static int *p_sys_nerr;
100 static int* (__cdecl *p__sys_nerr)(void);
101 static char **p_sys_errlist;
102 static char** (__cdecl *p__sys_errlist)(void);
103 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
104 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
105 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
106 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
107 static void (__cdecl *p_qsort_s)(void *, size_t, size_t, int (__cdecl *)(void *, const void *, const void *), void *);
108 static void* (__cdecl *p_bsearch_s)(const void *, const void *, size_t, size_t,
109 int (__cdecl *compare)(void *, const void *, const void *), void *);
110 static int (__cdecl *p_controlfp_s)(unsigned int *, unsigned int, unsigned int);
111 static int (__cdecl *p_tmpfile_s)(FILE**);
112 static int (__cdecl *p_atoflt)(_CRT_FLOAT *, char *);
113 static unsigned int (__cdecl *p_set_abort_behavior)(unsigned int, unsigned int);
114 static int (__cdecl *p__open)(const char *, int, ...);
115 static int (__cdecl *p__close)(int);
116 static intptr_t (__cdecl *p__get_osfhandle)(int);
117 static int (__cdecl *p_sopen_s)(int*, const char*, int, int, int);
118 static int (__cdecl *p_wsopen_s)(int*, const wchar_t*, int, int, int);
119 static void* (__cdecl *p_realloc_crt)(void*, size_t);
120 static void* (__cdecl *p_malloc)(size_t);
121 static void (__cdecl *p_free)(void*);
122 static void* (__cdecl *p_getptd)(void);
123 static int* (__cdecl *p_errno)(void);
124 static __msvcrt_ulong* (__cdecl *p_doserrno)(void);
125 static void (__cdecl *p_srand)(unsigned int);
126 static char* (__cdecl *p_strtok)(char*, const char*);
127 static char* (__cdecl *p_strtok_s)(char*, const char*, char**);
128 static wchar_t* (__cdecl *p_wcstok)(wchar_t*, const wchar_t*);
129 static unsigned char* (__cdecl *p__mbstok)(unsigned char*, const unsigned char*);
130 static unsigned char* (__cdecl *p__mbstok_s)(unsigned char*, const unsigned char*, unsigned char**);
131 static char* (__cdecl *p_strerror)(int);
132 static wchar_t* (__cdecl *p_wcserror)(int);
133 static char* (__cdecl *p_tmpnam)(char*);
134 static wchar_t* (__cdecl *p_wtmpnam)(wchar_t*);
135 static char* (__cdecl *p_asctime)(struct tm*);
136 static wchar_t* (__cdecl *p_wasctime)(struct tm*);
137 static struct tm* (__cdecl *p_localtime64)(__time64_t*);
138 static char* (__cdecl *p_ecvt)(double, int, int*, int*);
139 static int* (__cdecl *p_fpecode)(void);
140 static int (__cdecl *p_configthreadlocale)(int);
141 static void* (__cdecl *p_get_terminate)(void);
142 static void* (__cdecl *p_get_unexpected)(void);
143 static int (__cdecl *p__vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, va_list);
144 static int (__cdecl *p_vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, va_list);
145 static FILE* (__cdecl *p_fopen)(const char*, const char*);
146 static int (__cdecl *p_fclose)(FILE*);
147 static int (__cdecl *p_unlink)(const char*);
148 static int (__cdecl *p_access_s)(const char*, int);
149 static void (__cdecl *p_lock_file)(FILE*);
150 static void (__cdecl *p_unlock_file)(FILE*);
151 static int (__cdecl *p_fileno)(FILE*);
152 static int (__cdecl *p_feof)(FILE*);
153 static int (__cdecl *p_ferror)(FILE*);
154 static int (__cdecl *p_flsbuf)(int, FILE*);
155 static int (__cdecl *p_filbuf)(FILE*);
156 static unsigned long (__cdecl *p_byteswap_ulong)(unsigned long);
157 static void** (__cdecl *p__pxcptinfoptrs)(void);
158 static void* (__cdecl *p__AdjustPointer)(void*, const void*);
159 static int (__cdecl *p_fflush_nolock)(FILE*);
160 static size_t (__cdecl *p_mbstowcs)(wchar_t*, const char*, size_t);
161 static size_t (__cdecl *p_wcstombs)(char*, const wchar_t*, size_t);
162 static char* (__cdecl *p_setlocale)(int, const char*);
163 static int (__cdecl *p__setmbcp)(int);
164 static int (__cdecl *p__fpieee_flt)(ULONG, EXCEPTION_POINTERS*, int (__cdecl *handler)(_FPIEEE_RECORD*));
165 static int (__cdecl *p__memicmp)(const char*, const char*, size_t);
166 static int (__cdecl *p__memicmp_l)(const char*, const char*, size_t, _locale_t);
167 static int (__cdecl *p__vsnwprintf)(wchar_t *buffer,size_t count, const wchar_t *format, va_list valist);
168 static size_t (__cdecl *p___strncnt)(const char *str, size_t count);
169 static int (WINAPIV *p_swscanf)(const wchar_t *str, const wchar_t* format, ...);
170 static int (__cdecl *p____mb_cur_max_l_func)(_locale_t locale);
171 static _locale_t (__cdecl *p__create_locale)(int, const char*);
172 static void (__cdecl *p__free_locale)(_locale_t);
173 static _locale_t (__cdecl *p__get_current_locale)(void);
174 static int (__cdecl *p_strcmp)(const char *, const char *);
175 static int (__cdecl *p_strncmp)(const char *, const char *, size_t);
177 struct __lc_time_data {
178 const char *short_wday[7];
179 const char *wday[7];
180 const char *short_mon[12];
181 const char *mon[12];
182 const char *am;
183 const char *pm;
184 const char *short_date;
185 const char *date;
186 const char *time;
187 LCID lcid;
188 int unk;
189 int refcount;
192 /* make sure we use the correct errno */
193 #undef errno
194 #define errno (*p_errno())
196 typedef struct threadmbcinfostruct {
197 int refcount;
198 int mbcodepage;
199 int ismbcodepage;
200 int mblcid;
201 unsigned short mbulinfo[6];
202 unsigned char mbctype[257];
203 unsigned char mbcasemap[256];
204 } threadmbcinfo;
206 /* type info */
207 typedef struct __type_info
209 void *vtable;
210 char *name;
211 char mangled[16];
212 } type_info;
214 struct __type_info_node
216 void *memPtr;
217 struct __type_info_node* next;
220 static char* (WINAPI *p_type_info_name_internal_method)(type_info*, struct __type_info_node *);
221 static void (WINAPI *ptype_info_dtor)(type_info*);
223 #define CXX_FRAME_MAGIC_VC6 0x19930520
224 #define CXX_EXCEPTION 0xe06d7363
226 /* offsets for computing the this pointer */
227 typedef struct
229 int this_offset; /* offset of base class this pointer from start of object */
230 int vbase_descr; /* offset of virtual base class descriptor */
231 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
232 } this_ptr_offsets;
234 typedef void (*cxx_copy_ctor)(void);
236 /* complete information about a C++ type */
237 #ifndef __x86_64__
238 typedef struct __cxx_type_info
240 UINT flags; /* flags (see CLASS_* flags below) */
241 const type_info *type_info; /* C++ type info */
242 this_ptr_offsets offsets; /* offsets for computing the this pointer */
243 unsigned int size; /* object size */
244 cxx_copy_ctor copy_ctor; /* copy constructor */
245 } cxx_type_info;
246 #else
247 typedef struct __cxx_type_info
249 UINT flags;
250 unsigned int type_info;
251 this_ptr_offsets offsets;
252 unsigned int size;
253 unsigned int copy_ctor;
254 } cxx_type_info;
255 #endif
257 /* table of C++ types that apply for a given object */
258 #ifndef __x86_64__
259 typedef struct __cxx_type_info_table
261 UINT count; /* number of types */
262 const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
263 } cxx_type_info_table;
264 #else
265 typedef struct __cxx_type_info_table
267 UINT count;
268 unsigned int info[3];
269 } cxx_type_info_table;
270 #endif
272 /* type information for an exception object */
273 #ifndef __x86_64__
274 typedef struct __cxx_exception_type
276 UINT flags; /* TYPE_FLAG flags */
277 void (*destructor)(void);/* exception object destructor */
278 void *custom_handler; /* custom handler for this exception */
279 const cxx_type_info_table *type_info_table; /* list of types for this exception object */
280 } cxx_exception_type;
281 #else
282 typedef struct
284 UINT flags;
285 unsigned int destructor;
286 unsigned int custom_handler;
287 unsigned int type_info_table;
288 } cxx_exception_type;
289 #endif
291 static int (__cdecl *p_is_exception_typeof)(const type_info*, EXCEPTION_POINTERS*);
293 static void* (WINAPI *pEncodePointer)(void *);
295 static int cb_called[4];
296 static int g_qsort_s_context_counter;
297 static int g_bsearch_s_context_counter;
299 /* ########## */
301 /* thiscall emulation */
302 /* Emulate a __thiscall */
303 #ifdef __i386__
304 #ifdef _MSC_VER
305 static inline void* do_call_func1(void *func, void *_this)
307 volatile void* retval = 0;
308 __asm
310 push ecx
311 mov ecx, _this
312 call func
313 mov retval, eax
314 pop ecx
316 return (void*)retval;
319 static inline void* do_call_func2(void *func, void *_this, const void* arg)
321 volatile void* retval = 0;
322 __asm
324 push ecx
325 push arg
326 mov ecx, _this
327 call func
328 mov retval, eax
329 pop ecx
331 return (void*)retval;
333 #else
334 static void* do_call_func1(void *func, void *_this)
336 void *ret, *dummy;
337 __asm__ __volatile__ ("call *%2"
338 : "=a" (ret), "=c" (dummy)
339 : "g" (func), "1" (_this)
340 : "edx", "memory" );
341 return ret;
344 static void* do_call_func2(void *func, void *_this, const void* arg)
346 void *ret, *dummy;
347 __asm__ __volatile__ ("pushl %3\n\tcall *%2"
348 : "=a" (ret), "=c" (dummy)
349 : "r" (func), "r" (arg), "1" (_this)
350 : "edx", "memory" );
351 return ret;
353 #endif
355 #define call_func1(func,_this) do_call_func1(func,_this)
356 #define call_func2(func,_this,a) do_call_func2(func,_this,(const void*)(a))
358 #else
360 #define call_func1(func,_this) func(_this)
361 #define call_func2(func,_this,a) func(_this,a)
363 #endif /* __i386__ */
365 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
366 const wchar_t *function, const wchar_t *file,
367 unsigned line, uintptr_t arg)
369 CHECK_EXPECT(invalid_parameter_handler);
370 ok(expression == NULL, "expression is not NULL\n");
371 ok(function == NULL, "function is not NULL\n");
372 ok(file == NULL, "file is not NULL\n");
373 ok(line == 0, "line = %u\n", line);
374 ok(arg == 0, "arg = %Ix\n", arg);
375 ok(errno != 0xdeadbeef, "errno not set\n");
378 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
379 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
380 static BOOL init(void)
382 HMODULE hcrt;
383 HMODULE hkernel32;
385 SetLastError(0xdeadbeef);
386 hcrt = LoadLibraryA("msvcr90.dll");
387 if (!hcrt) {
388 win_skip("msvcr90.dll not installed (got %ld)\n", GetLastError());
389 return FALSE;
392 SET(p_set_invalid_parameter_handler, "_set_invalid_parameter_handler");
393 if(p_set_invalid_parameter_handler)
394 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
395 "Invalid parameter handler was already set\n");
397 SET(__pioinfo, "__pioinfo");
398 SET(p_initterm_e, "_initterm_e");
399 SET(p_encode_pointer, "_encode_pointer");
400 SET(p_decode_pointer, "_decode_pointer");
401 SET(p_encoded_null, "_encoded_null");
402 SET(p_sys_nerr, "_sys_nerr");
403 SET(p__sys_nerr, "__sys_nerr");
404 SET(p_sys_errlist, "_sys_errlist");
405 SET(p__sys_errlist, "__sys_errlist");
406 SET(p_strtoi64, "_strtoi64");
407 SET(p_strtoui64, "_strtoui64");
408 SET(p_itoa_s, "_itoa_s");
409 SET(p_wcsncat_s,"wcsncat_s" );
410 SET(p_qsort_s, "qsort_s");
411 SET(p_bsearch_s, "bsearch_s");
412 SET(p_controlfp_s, "_controlfp_s");
413 SET(p_tmpfile_s, "tmpfile_s");
414 SET(p_atoflt, "_atoflt");
415 SET(p_set_abort_behavior, "_set_abort_behavior");
416 SET(p_sopen_s, "_sopen_s");
417 SET(p_wsopen_s, "_wsopen_s");
418 SET(p__open,"_open");
419 SET(p__close,"_close");
420 SET(p__get_osfhandle, "_get_osfhandle");
421 SET(p_realloc_crt, "_realloc_crt");
422 SET(p_malloc, "malloc");
423 SET(p_free, "free");
424 SET(p_getptd, "_getptd");
425 SET(p_errno, "_errno");
426 SET(p_doserrno, "__doserrno");
427 SET(p_srand, "srand");
428 SET(p_strtok, "strtok");
429 SET(p_strtok_s, "strtok_s");
430 SET(p_wcstok, "wcstok");
431 SET(p__mbstok, "_mbstok");
432 SET(p__mbstok_s, "_mbstok_s");
433 SET(p_strerror, "strerror");
434 SET(p_wcserror, "_wcserror");
435 SET(p_tmpnam, "tmpnam");
436 SET(p_wtmpnam, "_wtmpnam");
437 SET(p_asctime, "asctime");
438 SET(p_wasctime, "_wasctime");
439 SET(p_localtime64, "_localtime64");
440 SET(p_ecvt, "_ecvt");
441 SET(p_fpecode, "__fpecode");
442 SET(p_configthreadlocale, "_configthreadlocale");
443 SET(p_get_terminate, "_get_terminate");
444 SET(p_get_unexpected, "_get_unexpected");
445 SET(p__vswprintf_l, "__vswprintf_l");
446 SET(p_vswprintf_l, "_vswprintf_l");
447 SET(p_fopen, "fopen");
448 SET(p_fclose, "fclose");
449 SET(p_unlink, "_unlink");
450 SET(p_access_s, "_access_s");
451 SET(p_lock_file, "_lock_file");
452 SET(p_unlock_file, "_unlock_file");
453 SET(p_fileno, "_fileno");
454 SET(p_feof, "feof");
455 SET(p_ferror, "ferror");
456 SET(p_flsbuf, "_flsbuf");
457 SET(p_filbuf, "_filbuf");
458 SET(p_byteswap_ulong, "_byteswap_ulong");
459 SET(p__pxcptinfoptrs, "__pxcptinfoptrs");
460 SET(p__AdjustPointer, "__AdjustPointer");
461 SET(p_fflush_nolock, "_fflush_nolock");
462 SET(p_mbstowcs, "mbstowcs");
463 SET(p_wcstombs, "wcstombs");
464 SET(p_setlocale, "setlocale");
465 SET(p__setmbcp, "_setmbcp");
466 SET(p__fpieee_flt, "_fpieee_flt");
467 SET(p__memicmp, "_memicmp");
468 SET(p__memicmp_l, "_memicmp_l");
469 SET(p__vsnwprintf, "_vsnwprintf");
470 SET(p___strncnt, "__strncnt");
471 SET(p_swscanf, "swscanf");
472 SET(p____mb_cur_max_l_func, "___mb_cur_max_l_func");
473 SET(p__create_locale, "_create_locale");
474 SET(p__free_locale, "_free_locale");
475 SET(p__get_current_locale, "_get_current_locale");
476 SET(p_strcmp, "strcmp");
477 SET(p_strncmp, "strncmp");
479 if (sizeof(void *) == 8)
481 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QEBAPEBDPEAU__type_info_node@@@Z");
482 SET(ptype_info_dtor, "??1type_info@@UEAA@XZ");
483 SET(p_is_exception_typeof, "?_is_exception_typeof@@YAHAEBVtype_info@@PEAU_EXCEPTION_POINTERS@@@Z");
485 else
487 #ifdef __arm__
488 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QBAPBDPAU__type_info_node@@@Z");
489 SET(ptype_info_dtor, "??1type_info@@UAA@XZ");
490 #else
491 SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z");
492 SET(ptype_info_dtor, "??1type_info@@UAE@XZ");
493 #endif
494 SET(p_is_exception_typeof, "?_is_exception_typeof@@YAHABVtype_info@@PAU_EXCEPTION_POINTERS@@@Z");
497 hkernel32 = GetModuleHandleA("kernel32.dll");
498 pEncodePointer = (void *) GetProcAddress(hkernel32, "EncodePointer");
499 return TRUE;
502 static int __cdecl initterm_cb0(void)
504 cb_called[0]++;
505 return 0;
508 static int __cdecl initterm_cb1(void)
510 cb_called[1]++;
511 return 1;
514 static int __cdecl initterm_cb2(void)
516 cb_called[2]++;
517 return 2;
521 static void test__initterm_e(void)
523 _INITTERM_E_FN table[4];
524 int res;
526 memset(table, 0, sizeof(table));
528 memset(cb_called, 0, sizeof(cb_called));
529 errno = 0xdeadbeef;
530 res = p_initterm_e(table, table);
531 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
532 "got %d with 0x%x {%d, %d, %d}\n",
533 res, errno, cb_called[0], cb_called[1], cb_called[2]);
535 memset(cb_called, 0, sizeof(cb_called));
536 errno = 0xdeadbeef;
537 res = p_initterm_e(table, NULL);
538 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
539 "got %d with 0x%x {%d, %d, %d}\n",
540 res, errno, cb_called[0], cb_called[1], cb_called[2]);
542 if (0) {
543 /* this crash on Windows */
544 errno = 0xdeadbeef;
545 res = p_initterm_e(NULL, table);
546 trace("got %d with 0x%x\n", res, errno);
549 table[0] = initterm_cb0;
550 memset(cb_called, 0, sizeof(cb_called));
551 errno = 0xdeadbeef;
552 res = p_initterm_e(table, &table[1]);
553 ok( !res && (cb_called[0] == 1) && !cb_called[1] && !cb_called[2],
554 "got %d with 0x%x {%d, %d, %d}\n",
555 res, errno, cb_called[0], cb_called[1], cb_called[2]);
558 /* init-function returning failure */
559 table[1] = initterm_cb1;
560 memset(cb_called, 0, sizeof(cb_called));
561 errno = 0xdeadbeef;
562 res = p_initterm_e(table, &table[3]);
563 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
564 "got %d with 0x%x {%d, %d, %d}\n",
565 res, errno, cb_called[0], cb_called[1], cb_called[2]);
567 /* init-function not called, when end < start */
568 memset(cb_called, 0, sizeof(cb_called));
569 errno = 0xdeadbeef;
570 res = p_initterm_e(&table[3], table);
571 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
572 "got %d with 0x%x {%d, %d, %d}\n",
573 res, errno, cb_called[0], cb_called[1], cb_called[2]);
575 /* initialization stop after first non-zero result */
576 table[2] = initterm_cb0;
577 memset(cb_called, 0, sizeof(cb_called));
578 errno = 0xdeadbeef;
579 res = p_initterm_e(table, &table[3]);
580 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
581 "got %d with 0x%x {%d, %d, %d}\n",
582 res, errno, cb_called[0], cb_called[1], cb_called[2]);
584 /* NULL pointer in the array are skipped */
585 table[1] = NULL;
586 table[2] = initterm_cb2;
587 memset(cb_called, 0, sizeof(cb_called));
588 errno = 0xdeadbeef;
589 res = p_initterm_e(table, &table[3]);
590 ok( (res == 2) && (cb_called[0] == 1) && !cb_called[1] && (cb_called[2] == 1),
591 "got %d with 0x%x {%d, %d, %d}\n",
592 res, errno, cb_called[0], cb_called[1], cb_called[2]);
596 /* Beware that _encode_pointer is a NOP before XP
597 (the parameter is returned unchanged) */
598 static void test__encode_pointer(void)
600 void *ptr, *res;
602 ptr = (void*)0xdeadbeef;
603 res = p_encode_pointer(ptr);
604 res = p_decode_pointer(res);
605 ok(res == ptr, "Pointers are different after encoding and decoding\n");
607 ok(p_encoded_null() == p_encode_pointer(NULL), "Error encoding null\n");
609 ptr = p_encode_pointer(p_encode_pointer);
610 ok(p_decode_pointer(ptr) == p_encode_pointer, "Error decoding pointer\n");
612 /* Not present before XP */
613 if (!pEncodePointer) {
614 win_skip("EncodePointer not found\n");
615 return;
618 res = pEncodePointer(p_encode_pointer);
619 ok(ptr == res, "_encode_pointer produced different result than EncodePointer\n");
623 static void test_error_messages(void)
625 int *size, size_copy;
627 size = p__sys_nerr();
628 size_copy = *size;
629 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
631 *size = 20;
632 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
634 *size = size_copy;
636 ok(*p_sys_errlist == *(p__sys_errlist()), "p_sys_errlist != p__sys_errlist()\n");
639 static void test__strtoi64(void)
641 __int64 res;
642 unsigned __int64 ures;
644 SET_EXPECT(invalid_parameter_handler);
645 res = p_strtoi64(NULL, NULL, 10);
646 ok(res == 0, "res != 0\n");
647 CHECK_CALLED(invalid_parameter_handler, EINVAL);
649 SET_EXPECT(invalid_parameter_handler);
650 res = p_strtoi64("123", NULL, 1);
651 ok(res == 0, "res != 0\n");
652 CHECK_CALLED(invalid_parameter_handler, EINVAL);
654 SET_EXPECT(invalid_parameter_handler);
655 res = p_strtoi64("123", NULL, 37);
656 ok(res == 0, "res != 0\n");
657 CHECK_CALLED(invalid_parameter_handler, EINVAL);
659 SET_EXPECT(invalid_parameter_handler);
660 ures = p_strtoui64(NULL, NULL, 10);
661 ok(ures == 0, "res = %d\n", (int)ures);
662 CHECK_CALLED(invalid_parameter_handler, EINVAL);
664 SET_EXPECT(invalid_parameter_handler);
665 ures = p_strtoui64("123", NULL, 1);
666 ok(ures == 0, "res = %d\n", (int)ures);
667 CHECK_CALLED(invalid_parameter_handler, EINVAL);
669 SET_EXPECT(invalid_parameter_handler);
670 ures = p_strtoui64("123", NULL, 37);
671 ok(ures == 0, "res = %d\n", (int)ures);
672 CHECK_CALLED(invalid_parameter_handler, EINVAL);
675 static void test__itoa_s(void)
677 errno_t ret;
678 char buffer[33];
680 SET_EXPECT(invalid_parameter_handler);
681 ret = p_itoa_s(0, NULL, 0, 0);
682 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
683 CHECK_CALLED(invalid_parameter_handler, EINVAL);
685 memset(buffer, 'X', sizeof(buffer));
686 SET_EXPECT(invalid_parameter_handler);
687 ret = p_itoa_s(0, buffer, 0, 0);
688 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
689 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
690 CHECK_CALLED(invalid_parameter_handler, EINVAL);
692 memset(buffer, 'X', sizeof(buffer));
693 SET_EXPECT(invalid_parameter_handler);
694 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
695 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
696 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
697 CHECK_CALLED(invalid_parameter_handler, EINVAL);
699 memset(buffer, 'X', sizeof(buffer));
700 SET_EXPECT(invalid_parameter_handler);
701 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
702 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
703 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
704 CHECK_CALLED(invalid_parameter_handler, EINVAL);
706 memset(buffer, 'X', sizeof(buffer));
707 SET_EXPECT(invalid_parameter_handler);
708 ret = p_itoa_s(12345678, buffer, 4, 10);
709 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
710 ok(!memcmp(buffer, "\000765", 4),
711 "Expected the output buffer to be null terminated with truncated output\n");
712 CHECK_CALLED(invalid_parameter_handler, ERANGE);
714 memset(buffer, 'X', sizeof(buffer));
715 SET_EXPECT(invalid_parameter_handler);
716 ret = p_itoa_s(12345678, buffer, 8, 10);
717 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
718 ok(!memcmp(buffer, "\0007654321", 8),
719 "Expected the output buffer to be null terminated with truncated output\n");
720 CHECK_CALLED(invalid_parameter_handler, ERANGE);
722 memset(buffer, 'X', sizeof(buffer));
723 SET_EXPECT(invalid_parameter_handler);
724 ret = p_itoa_s(-12345678, buffer, 9, 10);
725 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
726 ok(!memcmp(buffer, "\00087654321", 9),
727 "Expected the output buffer to be null terminated with truncated output\n");
728 CHECK_CALLED(invalid_parameter_handler, ERANGE);
730 ret = p_itoa_s(12345678, buffer, 9, 10);
731 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
732 ok(!strcmp(buffer, "12345678"),
733 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
734 buffer);
736 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
737 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
738 ok(!strcmp(buffer, "1010101010101010"),
739 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
740 buffer);
742 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
743 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
744 ok(!strcmp(buffer, "nell"),
745 "Expected output buffer string to be \"nell\", got \"%s\"\n",
746 buffer);
748 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
749 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
750 ok(!strcmp(buffer, "hag"),
751 "Expected output buffer string to be \"hag\", got \"%s\"\n",
752 buffer);
754 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
755 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
756 ok(!strcmp(buffer, "-12345678"),
757 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
758 buffer);
761 static void test_wcsncat_s(void)
763 int ret;
764 wchar_t dst[4];
765 wchar_t src[4];
767 wcscpy(src, L"abc");
768 dst[0] = 0;
769 SET_EXPECT(invalid_parameter_handler);
770 ret = p_wcsncat_s(NULL, 4, src, 4);
771 ok(ret == EINVAL, "err = %d\n", ret);
772 CHECK_CALLED(invalid_parameter_handler, EINVAL);
774 SET_EXPECT(invalid_parameter_handler);
775 ret = p_wcsncat_s(dst, 0, src, 4);
776 ok(ret == EINVAL, "err = %d\n", ret);
777 CHECK_CALLED(invalid_parameter_handler, EINVAL);
779 SET_EXPECT(invalid_parameter_handler);
780 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
781 ok(ret == EINVAL, "err = %d\n", ret);
782 CHECK_CALLED(invalid_parameter_handler, EINVAL);
784 ret = p_wcsncat_s(dst, 4, NULL, 0);
785 ok(ret == 0, "err = %d\n", ret);
787 dst[0] = 0;
788 SET_EXPECT(invalid_parameter_handler);
789 ret = p_wcsncat_s(dst, 2, src, 4);
790 ok(ret == ERANGE, "err = %d\n", ret);
791 CHECK_CALLED(invalid_parameter_handler, ERANGE);
793 dst[0] = 0;
794 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
795 ok(ret == STRUNCATE, "err = %d\n", ret);
796 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
798 memcpy(dst, L"abcd", 4 * sizeof(wchar_t));
799 SET_EXPECT(invalid_parameter_handler);
800 ret = p_wcsncat_s(dst, 4, src, 4);
801 ok(ret == EINVAL, "err = %d\n", ret);
802 CHECK_CALLED(invalid_parameter_handler, EINVAL);
805 /* Based on dlls/ntdll/tests/string.c */
806 static __cdecl int intcomparefunc(void *context, const void *a, const void *b)
808 const int *p = a, *q = b;
810 ok (a != b, "must never get the same pointer\n");
811 ++*(int *) context;
813 return *p - *q;
816 static __cdecl int charcomparefunc(void *context, const void *a, const void *b)
818 const char *p = a, *q = b;
820 ok (a != b, "must never get the same pointer\n");
821 ++*(int *) context;
823 return *p - *q;
826 static __cdecl int strcomparefunc(void *context, const void *a, const void *b)
828 const char * const *p = a;
829 const char * const *q = b;
831 ok (a != b, "must never get the same pointer\n");
832 ++*(int *) context;
834 return lstrcmpA(*p, *q);
837 static void test_qsort_s(void)
839 int arr[5] = { 23, 42, 8, 4, 16 };
840 int arr2[5] = { 23, 42, 8, 4, 16 };
841 char carr[5] = { 42, 23, 4, 8, 16 };
842 const char *strarr[7] = {
843 "Hello",
844 "Wine",
845 "World",
846 "!",
847 "Hopefully",
848 "Sorted",
852 SET_EXPECT(invalid_parameter_handler);
853 p_qsort_s(NULL, 0, 0, NULL, NULL);
854 CHECK_CALLED(invalid_parameter_handler, EINVAL);
856 SET_EXPECT(invalid_parameter_handler);
857 p_qsort_s(NULL, 0, 0, intcomparefunc, NULL);
858 CHECK_CALLED(invalid_parameter_handler, EINVAL);
860 SET_EXPECT(invalid_parameter_handler);
861 p_qsort_s(NULL, 0, sizeof(int), NULL, NULL);
862 CHECK_CALLED(invalid_parameter_handler, EINVAL);
864 SET_EXPECT(invalid_parameter_handler);
865 p_qsort_s(NULL, 1, sizeof(int), intcomparefunc, NULL);
866 CHECK_CALLED(invalid_parameter_handler, EINVAL);
868 errno = 0xdeadbeef;
869 g_qsort_s_context_counter = 0;
870 p_qsort_s(NULL, 0, sizeof(int), intcomparefunc, NULL);
871 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
872 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
874 /* overflow without side effects, other overflow values crash */
875 errno = 0xdeadbeef;
876 g_qsort_s_context_counter = 0;
877 p_qsort_s((void*)arr2, (((size_t)1) << (8*sizeof(size_t) - 1)) + 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
878 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
879 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
880 ok(arr2[0] == 23, "should remain unsorted, arr2[0] is %d\n", arr2[0]);
881 ok(arr2[1] == 42, "should remain unsorted, arr2[1] is %d\n", arr2[1]);
882 ok(arr2[2] == 8, "should remain unsorted, arr2[2] is %d\n", arr2[2]);
883 ok(arr2[3] == 4, "should remain unsorted, arr2[3] is %d\n", arr2[3]);
885 errno = 0xdeadbeef;
886 g_qsort_s_context_counter = 0;
887 p_qsort_s((void*)arr, 0, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
888 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
889 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
890 ok(arr[0] == 23, "badly sorted, nmemb=0, arr[0] is %d\n", arr[0]);
891 ok(arr[1] == 42, "badly sorted, nmemb=0, arr[1] is %d\n", arr[1]);
892 ok(arr[2] == 8, "badly sorted, nmemb=0, arr[2] is %d\n", arr[2]);
893 ok(arr[3] == 4, "badly sorted, nmemb=0, arr[3] is %d\n", arr[3]);
894 ok(arr[4] == 16, "badly sorted, nmemb=0, arr[4] is %d\n", arr[4]);
896 errno = 0xdeadbeef;
897 g_qsort_s_context_counter = 0;
898 p_qsort_s((void*)arr, 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
899 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
900 ok( errno == 0xdeadbeef, "wrong errno %u\n", errno );
901 ok(arr[0] == 23, "badly sorted, nmemb=1, arr[0] is %d\n", arr[0]);
902 ok(arr[1] == 42, "badly sorted, nmemb=1, arr[1] is %d\n", arr[1]);
903 ok(arr[2] == 8, "badly sorted, nmemb=1, arr[2] is %d\n", arr[2]);
904 ok(arr[3] == 4, "badly sorted, nmemb=1, arr[3] is %d\n", arr[3]);
905 ok(arr[4] == 16, "badly sorted, nmemb=1, arr[4] is %d\n", arr[4]);
907 SET_EXPECT(invalid_parameter_handler);
908 g_qsort_s_context_counter = 0;
909 p_qsort_s((void*)arr, 5, 0, intcomparefunc, &g_qsort_s_context_counter);
910 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
911 ok(arr[0] == 23, "badly sorted, size=0, arr[0] is %d\n", arr[0]);
912 ok(arr[1] == 42, "badly sorted, size=0, arr[1] is %d\n", arr[1]);
913 ok(arr[2] == 8, "badly sorted, size=0, arr[2] is %d\n", arr[2]);
914 ok(arr[3] == 4, "badly sorted, size=0, arr[3] is %d\n", arr[3]);
915 ok(arr[4] == 16, "badly sorted, size=0, arr[4] is %d\n", arr[4]);
916 CHECK_CALLED(invalid_parameter_handler, EINVAL);
918 g_qsort_s_context_counter = 0;
919 p_qsort_s((void*)arr, 5, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
920 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
921 ok(arr[0] == 4, "badly sorted, arr[0] is %d\n", arr[0]);
922 ok(arr[1] == 8, "badly sorted, arr[1] is %d\n", arr[1]);
923 ok(arr[2] == 16, "badly sorted, arr[2] is %d\n", arr[2]);
924 ok(arr[3] == 23, "badly sorted, arr[3] is %d\n", arr[3]);
925 ok(arr[4] == 42, "badly sorted, arr[4] is %d\n", arr[4]);
927 g_qsort_s_context_counter = 0;
928 p_qsort_s((void*)carr, 5, sizeof(char), charcomparefunc, &g_qsort_s_context_counter);
929 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
930 ok(carr[0] == 4, "badly sorted, carr[0] is %d\n", carr[0]);
931 ok(carr[1] == 8, "badly sorted, carr[1] is %d\n", carr[1]);
932 ok(carr[2] == 16, "badly sorted, carr[2] is %d\n", carr[2]);
933 ok(carr[3] == 23, "badly sorted, carr[3] is %d\n", carr[3]);
934 ok(carr[4] == 42, "badly sorted, carr[4] is %d\n", carr[4]);
936 g_qsort_s_context_counter = 0;
937 p_qsort_s((void*)strarr, 7, sizeof(char*), strcomparefunc, &g_qsort_s_context_counter);
938 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
939 ok(!strcmp(strarr[0],"!"), "badly sorted, strarr[0] is %s\n", strarr[0]);
940 ok(!strcmp(strarr[1],"."), "badly sorted, strarr[1] is %s\n", strarr[1]);
941 ok(!strcmp(strarr[2],"Hello"), "badly sorted, strarr[2] is %s\n", strarr[2]);
942 ok(!strcmp(strarr[3],"Hopefully"), "badly sorted, strarr[3] is %s\n", strarr[3]);
943 ok(!strcmp(strarr[4],"Sorted"), "badly sorted, strarr[4] is %s\n", strarr[4]);
944 ok(!strcmp(strarr[5],"Wine"), "badly sorted, strarr[5] is %s\n", strarr[5]);
945 ok(!strcmp(strarr[6],"World"), "badly sorted, strarr[6] is %s\n", strarr[6]);
948 static void test_bsearch_s(void)
950 int arr[7] = { 1, 3, 4, 8, 16, 23, 42 };
951 int *x, l, i, j = 1;
953 SET_EXPECT(invalid_parameter_handler);
954 x = p_bsearch_s(NULL, NULL, 0, 0, NULL, NULL);
955 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
956 CHECK_CALLED(invalid_parameter_handler, EINVAL);
958 g_bsearch_s_context_counter = 0;
959 SET_EXPECT(invalid_parameter_handler);
960 x = p_bsearch_s(&l, arr, j, 0, intcomparefunc, &g_bsearch_s_context_counter);
961 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
962 ok(g_bsearch_s_context_counter == 0, "callback shouldn't have been called\n");
963 CHECK_CALLED(invalid_parameter_handler, EINVAL);
965 g_bsearch_s_context_counter = 0;
966 SET_EXPECT(invalid_parameter_handler);
967 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), NULL, &g_bsearch_s_context_counter);
968 ok(x == NULL, "Expected bsearch_s to return NULL, got %p\n", x);
969 ok(g_bsearch_s_context_counter == 0, "callback shouldn't have been called\n");
970 CHECK_CALLED(invalid_parameter_handler, EINVAL);
972 /* just try all array sizes */
973 for (j=1; j<ARRAY_SIZE(arr); j++) {
974 for (i=0;i<j;i++) {
975 l = arr[i];
976 g_bsearch_s_context_counter = 0;
977 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), intcomparefunc, &g_bsearch_s_context_counter);
978 ok (x == &arr[i], "bsearch_s did not find %d entry in loopsize %d.\n", i, j);
979 ok(g_bsearch_s_context_counter > 0, "callback wasn't called\n");
981 l = 4242;
982 g_bsearch_s_context_counter = 0;
983 x = p_bsearch_s(&l, arr, j, sizeof(arr[0]), intcomparefunc, &g_bsearch_s_context_counter);
984 ok (x == NULL, "bsearch_s did find 4242 entry in loopsize %d.\n", j);
985 ok(g_bsearch_s_context_counter > 0, "callback wasn't called\n");
989 static void test_controlfp_s(void)
991 unsigned int cur;
992 int ret;
994 SET_EXPECT(invalid_parameter_handler);
995 ret = p_controlfp_s( NULL, ~0, ~0 );
996 ok( ret == EINVAL, "wrong result %d\n", ret );
997 CHECK_CALLED(invalid_parameter_handler, EINVAL);
999 cur = 0xdeadbeef;
1000 SET_EXPECT(invalid_parameter_handler);
1001 ret = p_controlfp_s( &cur, ~0, ~0 );
1002 ok( ret == EINVAL, "wrong result %d\n", ret );
1003 ok( cur != 0xdeadbeef, "value not set\n" );
1004 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1006 cur = 0xdeadbeef;
1007 ret = p_controlfp_s( &cur, 0, 0 );
1008 ok( !ret, "wrong result %d\n", ret );
1009 ok( cur != 0xdeadbeef, "value not set\n" );
1011 SET_EXPECT(invalid_parameter_handler);
1012 cur = 0xdeadbeef;
1013 ret = p_controlfp_s( &cur, 0x80000000, 0x80000000 );
1014 ok( ret == EINVAL, "wrong result %d\n", ret );
1015 ok( cur != 0xdeadbeef, "value not set\n" );
1016 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1018 cur = 0xdeadbeef;
1019 /* mask is only checked when setting invalid bits */
1020 ret = p_controlfp_s( &cur, 0, 0x80000000 );
1021 ok( !ret, "wrong result %d\n", ret );
1022 ok( cur != 0xdeadbeef, "value not set\n" );
1025 static void test_tmpfile_s( void )
1027 int ret;
1029 SET_EXPECT(invalid_parameter_handler);
1030 ret = p_tmpfile_s(NULL);
1031 ok(ret == EINVAL, "Expected tmpfile_s to return EINVAL, got %i\n", ret);
1032 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1035 typedef struct
1037 const char *str;
1038 float flt;
1039 int ret;
1040 } _atoflt_test;
1042 static const _atoflt_test _atoflt_testdata[] = {
1043 { "12.1", 12.1, 0 },
1044 { "-13.721", -13.721, 0 },
1045 { "INF", 0.0, 0 },
1046 { ".21e12", 0.21e12, 0 },
1047 { "214353e-3", 214.353, 0 },
1048 { "1d9999999999999999999", 0.0, _OVERFLOW },
1049 { " d10", 0.0, 0 },
1050 /* more significant digits */
1051 { "1.23456789", 1.23456789, 0 },
1052 { "1.23456789e1", 12.3456789, 0 },
1053 { "1e39", 0.0, _OVERFLOW },
1054 { "1e-39", 0.0, _UNDERFLOW },
1055 { NULL }
1058 static void test__atoflt(void)
1060 _CRT_FLOAT flt;
1061 int ret, i = 0;
1063 if (0)
1065 /* crashes on native */
1066 p_atoflt(NULL, NULL);
1067 p_atoflt(NULL, (char*)_atoflt_testdata[0].str);
1068 p_atoflt(&flt, NULL);
1071 while (_atoflt_testdata[i].str)
1073 ret = p_atoflt(&flt, (char*)_atoflt_testdata[i].str);
1074 ok(ret == _atoflt_testdata[i].ret, "got ret %d, expected ret %d, for %s\n", ret,
1075 _atoflt_testdata[i].ret, _atoflt_testdata[i].str);
1077 if (ret == 0)
1078 ok(flt.f == _atoflt_testdata[i].flt, "got %f, expected %f, for %s\n", flt.f,
1079 _atoflt_testdata[i].flt, _atoflt_testdata[i].str);
1081 i++;
1085 static void test__set_abort_behavior(void)
1087 unsigned int res;
1089 /* default is _WRITE_ABORT_MSG | _CALL_REPORTFAULT */
1090 res = p_set_abort_behavior(0, 0);
1091 ok (res == (_WRITE_ABORT_MSG | _CALL_REPORTFAULT),
1092 "got 0x%x (expected 0x%x)\n", res, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
1094 /* no internal mask */
1095 p_set_abort_behavior(0xffffffff, 0xffffffff);
1096 res = p_set_abort_behavior(0, 0);
1097 ok (res == 0xffffffff, "got 0x%x (expected 0x%x)\n", res, 0xffffffff);
1099 /* set to default value */
1100 p_set_abort_behavior(_WRITE_ABORT_MSG | _CALL_REPORTFAULT, 0xffffffff);
1103 static void test__sopen_s(void)
1105 int ret, fd;
1107 SET_EXPECT(invalid_parameter_handler);
1108 ret = p_sopen_s(NULL, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1109 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
1110 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1112 fd = 0xdead;
1113 ret = p_sopen_s(&fd, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1114 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
1115 ok(fd == -1, "got %d\n", fd);
1118 static void test__wsopen_s(void)
1120 int ret, fd;
1122 SET_EXPECT(invalid_parameter_handler);
1123 ret = p_wsopen_s(NULL, L"test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1124 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
1125 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1127 fd = 0xdead;
1128 ret = p_wsopen_s(&fd, L"test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
1129 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
1130 ok(fd == -1, "got %d\n", fd);
1133 static void test__realloc_crt(void)
1135 void *mem;
1137 if (0)
1139 /* crashes on some systems starting Vista */
1140 p_realloc_crt(NULL, 10);
1143 mem = p_malloc(10);
1144 ok(mem != NULL, "memory not allocated\n");
1146 mem = p_realloc_crt(mem, 20);
1147 ok(mem != NULL, "memory not reallocated\n");
1149 mem = p_realloc_crt(mem, 0);
1150 ok(mem == NULL, "memory not freed\n");
1152 mem = p_realloc_crt(NULL, 0);
1153 ok(mem != NULL, "memory not (re)allocated for size 0\n");
1154 p_free(mem);
1157 static void test_typeinfo(void)
1159 static type_info t1 = { NULL, NULL,{'.','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
1160 struct __type_info_node node;
1161 char *name;
1163 /* name */
1164 t1.name = NULL;
1165 node.memPtr = NULL;
1166 node.next = NULL;
1167 name = call_func2(p_type_info_name_internal_method, &t1, &node);
1168 ok(name != NULL, "got %p\n", name);
1169 ok(name && t1.name && !strcmp(name, t1.name), "bad name '%s' for t1\n", name);
1171 ok(t1.name && !strcmp(t1.name, "class test1"), "demangled to '%s' for t1\n", t1.name);
1172 call_func1(ptype_info_dtor, &t1);
1175 /* Keep in sync with msvcrt/msvcrt.h */
1176 struct __thread_data {
1177 DWORD tid;
1178 HANDLE handle;
1179 int thread_errno;
1180 __msvcrt_ulong thread_doserrno;
1181 int unk1;
1182 unsigned int random_seed;
1183 char *strtok_next;
1184 wchar_t *wcstok_next;
1185 unsigned char *mbstok_next;
1186 char *strerror_buffer;
1187 wchar_t *wcserror_buffer;
1188 char *tmpnam_buffer;
1189 wchar_t *wtmpnam_buffer;
1190 void *unk2[2];
1191 char *asctime_buffer;
1192 wchar_t *wasctime_buffer;
1193 struct tm *time_buffer;
1194 char *efcvt_buffer;
1195 int unk3[2];
1196 void *unk4[3];
1197 EXCEPTION_POINTERS *xcptinfo;
1198 int fpecode;
1199 pthreadmbcinfo mbcinfo;
1200 pthreadlocinfo locinfo;
1201 BOOL have_locale;
1202 int unk5[1];
1203 void* terminate_handler;
1204 void* unexpected_handler;
1205 void* se_translator;
1206 void *unk6;
1207 EXCEPTION_RECORD *exc_record;
1210 static void test_getptd(void)
1212 struct __thread_data *ptd = p_getptd();
1213 DWORD tid = GetCurrentThreadId();
1214 wchar_t testW[] = L"test", *wp;
1215 char test[] = "test", *p;
1216 unsigned char mbstok_test[] = "test", *up;
1217 struct tm time;
1218 __time64_t secs = 0;
1219 int dec, sign;
1220 void *mbcinfo, *locinfo;
1222 ok(ptd->tid == tid, "ptd->tid = %lx, expected %lx\n", ptd->tid, tid);
1223 ok(ptd->handle == INVALID_HANDLE_VALUE, "ptd->handle = %p\n", ptd->handle);
1224 ok(p_errno() == &ptd->thread_errno, "ptd->thread_errno is different then _errno()\n");
1225 ok(p_doserrno() == &ptd->thread_doserrno, "ptd->thread_doserrno is different then __doserrno()\n");
1226 p_srand(1234);
1227 ok(ptd->random_seed == 1234, "ptd->random_seed = %d\n", ptd->random_seed);
1228 p = p_strtok(test, "t");
1229 ok(ptd->strtok_next == p+3, "ptd->strtok_next is incorrect\n");
1230 wp = p_wcstok(testW, L"t");
1231 ok(ptd->wcstok_next == wp+3, "ptd->wcstok_next is incorrect\n");
1232 up = p__mbstok(mbstok_test, (unsigned char*)"t");
1233 ok(ptd->mbstok_next == up+3, "ptd->mbstok_next is incorrect\n");
1234 ok(p_strerror(0) == ptd->strerror_buffer, "ptd->strerror_buffer is incorrect\n");
1235 ok(p_wcserror(0) == ptd->wcserror_buffer, "ptd->wcserror_buffer is incorrect\n");
1236 ok(p_tmpnam(NULL) == ptd->tmpnam_buffer, "ptd->tmpnam_buffer is incorrect\n");
1237 ok(p_wtmpnam(NULL) == ptd->wtmpnam_buffer, "ptd->wtmpnam_buffer is incorrect\n");
1238 memset(&time, 0, sizeof(time));
1239 time.tm_mday = 1;
1240 ok(p_asctime(&time) == ptd->asctime_buffer, "ptd->asctime_buffer is incorrect\n");
1241 ok(p_wasctime(&time) == ptd->wasctime_buffer, "ptd->wasctime_buffer is incorrect\n");
1242 ok(p_localtime64(&secs) == ptd->time_buffer, "ptd->time_buffer is incorrect\n");
1243 ok(p_ecvt(3.12, 1, &dec, &sign) == ptd->efcvt_buffer, "ptd->efcvt_buffer is incorrect\n");
1244 ok(p__pxcptinfoptrs() == (void**)&ptd->xcptinfo, "ptd->xcptinfo is incorrect\n");
1245 ok(p_fpecode() == &ptd->fpecode, "ptd->fpecode is incorrect\n");
1246 mbcinfo = ptd->mbcinfo;
1247 locinfo = ptd->locinfo;
1248 ok(ptd->have_locale == 1, "ptd->have_locale = %x\n", ptd->have_locale);
1249 p_configthreadlocale(1);
1250 ok(mbcinfo == ptd->mbcinfo, "ptd->mbcinfo != mbcinfo\n");
1251 ok(locinfo == ptd->locinfo, "ptd->locinfo != locinfo\n");
1252 ok(ptd->have_locale == 3, "ptd->have_locale = %x\n", ptd->have_locale);
1253 ok(p_get_terminate() == ptd->terminate_handler, "ptd->terminate_handler != _get_terminate()\n");
1254 ok(p_get_unexpected() == ptd->unexpected_handler, "ptd->unexpected_handler != _get_unexpected()\n");
1257 static int WINAPIV __vswprintf_l_wrapper(wchar_t *buf,
1258 const wchar_t *format, _locale_t locale, ...)
1260 int ret;
1261 va_list valist;
1262 va_start(valist, locale);
1263 ret = p__vswprintf_l(buf, format, locale, valist);
1264 va_end(valist);
1265 return ret;
1268 static int WINAPIV _vswprintf_l_wrapper(wchar_t *buf,
1269 const wchar_t *format, _locale_t locale, ...)
1271 int ret;
1272 va_list valist;
1273 va_start(valist, locale);
1274 ret = p_vswprintf_l(buf, format, locale, valist);
1275 va_end(valist);
1276 return ret;
1279 static void test__vswprintf_l(void)
1281 wchar_t buf[32];
1282 int ret;
1284 ret = __vswprintf_l_wrapper(buf, L"test", NULL);
1285 ok(ret == 4, "ret = %d\n", ret);
1286 ok(!wcscmp(buf, L"test"), "buf = %s\n", wine_dbgstr_w(buf));
1288 ret = _vswprintf_l_wrapper(buf, L"test", NULL);
1289 ok(ret == 4, "ret = %d\n", ret);
1290 ok(!wcscmp(buf, L"test"), "buf = %s\n", wine_dbgstr_w(buf));
1293 struct block_file_arg
1295 FILE *read;
1296 FILE *write;
1297 HANDLE init;
1298 HANDLE finish;
1299 LONG deadlock_test;
1302 static DWORD WINAPI block_file(void *arg)
1304 struct block_file_arg *files = arg;
1305 int deadlock_test;
1307 p_lock_file(files->read);
1308 p_lock_file(files->write);
1309 SetEvent(files->init);
1311 WaitForSingleObject(files->finish, INFINITE);
1312 Sleep(200);
1313 deadlock_test = InterlockedIncrement(&files->deadlock_test);
1314 ok(deadlock_test == 1, "deadlock_test = %d\n", deadlock_test);
1315 p_unlock_file(files->read);
1316 p_unlock_file(files->write);
1317 return 0;
1320 static void test_nonblocking_file_access(void)
1322 HANDLE thread;
1323 struct block_file_arg arg;
1324 FILE *filer, *filew;
1325 int ret;
1327 if(!p_lock_file || !p_unlock_file) {
1328 win_skip("_lock_file not available\n");
1329 return;
1332 filew = p_fopen("test_file", "w");
1333 ok(filew != NULL, "unable to create test file\n");
1334 if(!filew)
1335 return;
1336 filer = p_fopen("test_file", "r");
1337 ok(filer != NULL, "unable to open test file\n");
1338 if(!filer) {
1339 p_fclose(filew);
1340 p_unlink("test_file");
1341 return;
1344 arg.read = filer;
1345 arg.write = filew;
1346 arg.init = CreateEventW(NULL, FALSE, FALSE, NULL);
1347 arg.finish = CreateEventW(NULL, FALSE, FALSE, NULL);
1348 arg.deadlock_test = 0;
1349 ok(arg.init != NULL, "CreateEventW failed\n");
1350 ok(arg.finish != NULL, "CreateEventW failed\n");
1351 thread = CreateThread(NULL, 0, block_file, (void*)&arg, 0, NULL);
1352 ok(thread != NULL, "CreateThread failed\n");
1353 WaitForSingleObject(arg.init, INFINITE);
1355 ret = p_fileno(filer);
1356 ok(ret, "_fileno(filer) returned %d\n", ret);
1357 ret = p_fileno(filew);
1358 ok(ret, "_fileno(filew) returned %d\n", ret);
1360 ret = p_feof(filer);
1361 ok(ret==0, "feof(filer) returned %d\n", ret);
1362 ret = p_feof(filew);
1363 ok(ret==0, "feof(filew) returned %d\n", ret);
1365 ret = p_ferror(filer);
1366 ok(ret==0, "ferror(filer) returned %d\n", ret);
1367 ret = p_ferror(filew);
1368 ok(ret==0, "ferror(filew) returned %d\n", ret);
1370 ret = p_flsbuf('a', filer);
1371 ok(ret==-1, "_flsbuf(filer) returned %d\n", ret);
1372 ret = p_flsbuf('a', filew);
1373 ok(ret=='a', "_flsbuf(filew) returned %d\n", ret);
1375 ret = p_filbuf(filer);
1376 ok(ret==-1, "_filbuf(filer) returned %d\n", ret);
1377 ret = p_filbuf(filew);
1378 ok(ret==-1, "_filbuf(filew) returned %d\n", ret);
1380 ret = p_fflush_nolock(filer);
1381 ok(ret==0, "_fflush_nolock(filer) returned %d\n", ret);
1382 ret = p_fflush_nolock(filew);
1383 ok(ret==0, "_fflush_nolock(filew) returned %d\n", ret);
1385 SetEvent(arg.finish);
1387 ret = p_fflush_nolock(NULL);
1388 ok(ret==0, "_fflush_nolock(NULL) returned %d\n", ret);
1389 ret = InterlockedIncrement(&arg.deadlock_test);
1390 ok(ret==2, "InterlockedIncrement returned %d\n", ret);
1392 WaitForSingleObject(thread, INFINITE);
1393 CloseHandle(arg.init);
1394 CloseHandle(arg.finish);
1395 CloseHandle(thread);
1396 p_fclose(filer);
1397 p_fclose(filew);
1398 p_unlink("test_file");
1401 static void test_byteswap(void)
1403 unsigned long ret;
1405 ret = p_byteswap_ulong(0x12345678);
1406 ok(ret == 0x78563412, "ret = %lx\n", ret);
1408 ret = p_byteswap_ulong(0);
1409 ok(ret == 0, "ret = %lx\n", ret);
1412 static void test_access_s(void)
1414 FILE *f;
1415 int res;
1417 f = p_fopen("test_file", "w");
1418 ok(f != NULL, "unable to create test file\n");
1419 if(!f)
1420 return;
1422 p_fclose(f);
1424 errno = 0xdeadbeef;
1425 res = p_access_s("test_file", 0);
1426 ok(res == 0, "got %x\n", res);
1427 ok(errno == 0xdeadbeef, "got %x\n", res);
1429 errno = 0xdeadbeef;
1430 res = p_access_s("test_file", 2);
1431 ok(res == 0, "got %x\n", res);
1432 ok(errno == 0xdeadbeef, "got %x\n", res);
1434 errno = 0xdeadbeef;
1435 res = p_access_s("test_file", 4);
1436 ok(res == 0, "got %x\n", res);
1437 ok(errno == 0xdeadbeef, "got %x\n", res);
1439 errno = 0xdeadbeef;
1440 res = p_access_s("test_file", 6);
1441 ok(res == 0, "got %x\n", res);
1442 ok(errno == 0xdeadbeef, "got %x\n", res);
1444 SetFileAttributesA("test_file", FILE_ATTRIBUTE_READONLY);
1446 errno = 0xdeadbeef;
1447 res = p_access_s("test_file", 0);
1448 ok(res == 0, "got %x\n", res);
1449 ok(errno == 0xdeadbeef, "got %x\n", res);
1451 errno = 0xdeadbeef;
1452 res = p_access_s("test_file", 2);
1453 ok(res == EACCES, "got %x\n", res);
1454 ok(errno == EACCES, "got %x\n", res);
1456 errno = 0xdeadbeef;
1457 res = p_access_s("test_file", 4);
1458 ok(res == 0, "got %x\n", res);
1459 ok(errno == 0xdeadbeef, "got %x\n", res);
1461 errno = 0xdeadbeef;
1462 res = p_access_s("test_file", 6);
1463 ok(res == EACCES, "got %x\n", res);
1464 ok(errno == EACCES, "got %x\n", res);
1466 SetFileAttributesA("test_file", FILE_ATTRIBUTE_NORMAL);
1468 p_unlink("test_file");
1470 errno = 0xdeadbeef;
1471 res = p_access_s("test_file", 0);
1472 ok(res == ENOENT, "got %x\n", res);
1473 ok(errno == ENOENT, "got %x\n", res);
1475 errno = 0xdeadbeef;
1476 res = p_access_s("test_file", 2);
1477 ok(res == ENOENT, "got %x\n", res);
1478 ok(errno == ENOENT, "got %x\n", res);
1480 errno = 0xdeadbeef;
1481 res = p_access_s("test_file", 4);
1482 ok(res == ENOENT, "got %x\n", res);
1483 ok(errno == ENOENT, "got %x\n", res);
1485 errno = 0xdeadbeef;
1486 res = p_access_s("test_file", 6);
1487 ok(res == ENOENT, "got %x\n", res);
1488 ok(errno == ENOENT, "got %x\n", res);
1491 #ifndef __x86_64__
1492 #define EXCEPTION_REF(instance, name) &instance.name
1493 #else
1494 #define EXCEPTION_REF(instance, name) FIELD_OFFSET(struct _exception_data, name)
1495 #endif
1496 static void test_is_exception_typeof(void)
1498 const type_info ti1 = {NULL, NULL, {'.','?','A','V','t','e','s','t','1','@','@',0}};
1499 const type_info ti2 = {NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0}};
1500 const type_info ti3 = {NULL, NULL, {'.','?','A','V','t','e','s','t','3','@','@',0}};
1502 const struct _exception_data {
1503 type_info ti1;
1504 type_info ti2;
1505 cxx_type_info cti1;
1506 cxx_type_info cti2;
1507 cxx_type_info_table tit;
1508 cxx_exception_type et;
1509 } exception_data = {
1510 {NULL, NULL, {'.','?','A','V','t','e','s','t','1','@','@',0}},
1511 {NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0}},
1512 {0, EXCEPTION_REF(exception_data, ti1)},
1513 {0, EXCEPTION_REF(exception_data, ti2)},
1514 {2, {EXCEPTION_REF(exception_data, cti1), EXCEPTION_REF(exception_data, cti2)}},
1515 {0, 0, 0, EXCEPTION_REF(exception_data, tit)}
1518 EXCEPTION_RECORD rec = {CXX_EXCEPTION, 0, NULL, NULL, 3, {CXX_FRAME_MAGIC_VC6, 0, (ULONG_PTR)&exception_data.et}};
1519 EXCEPTION_POINTERS except_ptrs = {&rec, NULL};
1521 int ret;
1523 #ifdef __x86_64__
1524 rec.NumberParameters = 4;
1525 rec.ExceptionInformation[3] = (ULONG_PTR)&exception_data;
1526 #endif
1528 ret = p_is_exception_typeof(&ti1, &except_ptrs);
1529 ok(ret == 1, "_is_exception_typeof returned %d\n", ret);
1530 ret = p_is_exception_typeof(&ti2, &except_ptrs);
1531 ok(ret == 1, "_is_exception_typeof returned %d\n", ret);
1532 ret = p_is_exception_typeof(&ti3, &except_ptrs);
1533 ok(ret == 0, "_is_exception_typeof returned %d\n", ret);
1536 static void test__AdjustPointer(void)
1538 struct {
1539 int vbase;
1540 int off;
1541 } obj = { 0, 0xf0 };
1542 void *obj1 = &obj.off;
1543 void *obj2 = &obj;
1544 struct test_data {
1545 void *ptr;
1546 void *ret;
1547 struct {
1548 int this_offset;
1549 int vbase_descr;
1550 int vbase_offset;
1551 } this_ptr_offsets;
1552 } data[] = {
1553 {NULL, NULL, {0, -1, 0}},
1554 {(void*)0xbeef, (void*)0xbef0, {1, -1, 1}},
1555 {(void*)0xbeef, (void*)0xbeee, {-1, -1, 0}},
1556 {&obj1, (char*)&obj1 + obj.off, {0, 0, 0}},
1557 {(char*)&obj1 - 5, (char*)&obj1 + obj.off, {0, 5, 0}},
1558 {(char*)&obj1 - 3, (char*)&obj1 + obj.off + 24, {24, 3, 0}},
1559 {(char*)&obj2 - 17, (char*)&obj2 + obj.off + 4, {4, 17, sizeof(int)}}
1561 void *ret;
1562 int i;
1564 for(i=0; i<ARRAY_SIZE(data); i++) {
1565 ret = p__AdjustPointer(data[i].ptr, &data[i].this_ptr_offsets);
1566 ok(ret == data[i].ret, "%d) __AdjustPointer returned %p, expected %p\n", i, ret, data[i].ret);
1570 static void test_mbstowcs(void)
1572 wchar_t bufw[16];
1573 char buf[16];
1574 size_t ret;
1576 buf[0] = 'a';
1577 buf[1] = 0;
1578 memset(bufw, 'x', sizeof(bufw));
1579 ret = p_mbstowcs(bufw, buf, -1);
1580 ok(ret == 1, "ret = %d\n", (int)ret);
1581 ok(bufw[0] == 'a', "bufw[0] = '%c'\n", bufw[0]);
1582 ok(bufw[1] == 0, "bufw[1] = '%c'\n", bufw[1]);
1584 memset(bufw, 'x', sizeof(bufw));
1585 ret = p_mbstowcs(bufw, buf, -1000);
1586 ok(ret == 1, "ret = %d\n", (int)ret);
1587 ok(bufw[0] == 'a', "bufw[0] = '%c'\n", bufw[0]);
1588 ok(bufw[1] == 0, "bufw[1] = '%c'\n", bufw[1]);
1590 memset(buf, 'x', sizeof(buf));
1591 ret = p_wcstombs(buf, bufw, -1);
1592 ok(ret == 1, "ret = %d\n", (int)ret);
1593 ok(buf[0] == 'a', "buf[0] = '%c'\n", buf[0]);
1594 ok(buf[1] == 0, "buf[1] = '%c'\n", buf[1]);
1596 memset(buf, 'x', sizeof(buf));
1597 ret = p_wcstombs(buf, bufw, -1000);
1598 ok(ret == 1, "ret = %d\n", (int)ret);
1599 ok(buf[0] == 'a', "buf[0] = '%c'\n", buf[0]);
1600 ok(buf[1] == 0, "buf[1] = '%c'\n", buf[1]);
1602 if(!p_setlocale(LC_ALL, "English")) {
1603 win_skip("English locale not available\n");
1604 return;
1607 buf[0] = 'a';
1608 buf[1] = 0;
1609 memset(bufw, 'x', sizeof(bufw));
1610 ret = p_mbstowcs(bufw, buf, -1);
1611 ok(ret == -1, "ret = %d\n", (int)ret);
1612 ok(bufw[0] == 0, "bufw[0] = '%c'\n", bufw[0]);
1614 memset(bufw, 'x', sizeof(bufw));
1615 ret = p_mbstowcs(bufw, buf, -1000);
1616 ok(ret == -1, "ret = %d\n", (int)ret);
1617 ok(bufw[0] == 0, "bufw[0] = '%c'\n", bufw[0]);
1619 memset(buf, 'x', sizeof(buf));
1620 ret = p_wcstombs(buf, bufw, -1);
1621 ok(ret == 0, "ret = %d\n", (int)ret);
1622 ok(buf[0] == 0, "buf[0] = '%c'\n", buf[0]);
1624 memset(buf, 'x', sizeof(buf));
1625 ret = p_wcstombs(buf, bufw, -1000);
1626 ok(ret == 0, "ret = %d\n", (int)ret);
1627 ok(buf[0] == 0, "buf[0] = '%c'\n", buf[0]);
1629 p_setlocale(LC_ALL, "C");
1632 static void test_strtok_s(void)
1634 char test[] = "a/b";
1635 char empty[] = "";
1636 char space[] = " ";
1637 char delim[] = "/";
1638 char *strret;
1639 char *context;
1641 context = (char*)0xdeadbeef;
1642 strret = p_strtok_s( test, delim, &context);
1643 ok(strret == test, "Expected test, got %p.\n", strret);
1644 ok(context == test+2, "Expected test+2, got %p.\n", context);
1646 strret = p_strtok_s( NULL, delim, &context);
1647 ok(strret == test+2, "Expected test+2, got %p.\n", strret);
1648 ok(context == test+3, "Expected test+3, got %p.\n", context);
1650 strret = p_strtok_s( NULL, delim, &context);
1651 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1652 ok(context == test+3, "Expected test+3, got %p.\n", context);
1654 context = NULL;
1655 strret = p_strtok_s( empty, delim, &context);
1656 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1657 ok(context == empty, "Expected empty, got %p.\n", context);
1659 strret = p_strtok_s( NULL, delim, &context);
1660 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1661 ok(context == empty, "Expected empty, got %p.\n", context);
1663 context = NULL;
1664 strret = p_strtok_s( space, delim, &context);
1665 ok(strret == space, "Expected space, got %p.\n", strret);
1666 ok(context == space+1, "Expected space+1, got %p.\n", context);
1668 strret = p_strtok_s( NULL, delim, &context);
1669 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1670 ok(context == space+1, "Expected space+1, got %p.\n", context);
1673 static void test__mbstok_s(void)
1675 unsigned char test[] = "a/b";
1676 unsigned char empty[] = "";
1677 unsigned char space[] = " ";
1678 unsigned char delim[] = "/";
1679 unsigned char *strret;
1680 unsigned char *context;
1682 context = (unsigned char*)0xdeadbeef;
1683 strret = p__mbstok_s( test, delim, &context);
1684 ok(strret == test, "Expected test, got %p.\n", strret);
1685 ok(context == test+2, "Expected test+2, got %p.\n", context);
1687 strret = p__mbstok_s( NULL, delim, &context);
1688 ok(strret == test+2, "Expected test+2, got %p.\n", strret);
1689 ok(context == test+3, "Expected test+3, got %p.\n", context);
1691 strret = p__mbstok_s( NULL, delim, &context);
1692 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1693 ok(context == test+3, "Expected test+3, got %p.\n", context);
1695 context = NULL;
1696 strret = p__mbstok_s( empty, delim, &context);
1697 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1698 ok(context == empty, "Expected empty, got %p.\n", context);
1700 strret = p__mbstok_s( NULL, delim, &context);
1701 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1702 ok(context == empty, "Expected empty, got %p.\n", context);
1704 context = NULL;
1705 strret = p__mbstok_s( space, delim, &context);
1706 ok(strret == space, "Expected space, got %p.\n", strret);
1707 ok(context == space+1, "Expected space+1, got %p.\n", context);
1709 strret = p__mbstok_s( NULL, delim, &context);
1710 ok(strret == NULL, "Expected NULL, got %p.\n", strret);
1711 ok(context == space+1, "Expected space+1, got %p.\n", context);
1714 #ifdef __i386__
1715 static _FPIEEE_RECORD fpieee_record;
1716 static int handler_called;
1717 static int __cdecl fpieee_handler(_FPIEEE_RECORD *rec)
1719 handler_called++;
1720 fpieee_record = *rec;
1721 return EXCEPTION_CONTINUE_EXECUTION;
1724 static void test__fpieee_flt(void)
1726 double argd = 1.5;
1727 struct {
1728 DWORD exception_code;
1729 WORD opcode;
1730 DWORD data_offset;
1731 DWORD control_word;
1732 DWORD status_word;
1733 _FPIEEE_RECORD rec;
1734 int ret;
1735 } test_data[] = {
1736 { STATUS_FLOAT_DIVIDE_BY_ZERO, 0x35dc, (DWORD)&argd, 0, 0,
1737 {0, 2, _FpCodeDivide,
1738 {0}, {1, 1, 1, 1, 1}, {0},
1739 {{0}, 1, _FpFormatFp80},
1740 {{0}, 1, _FpFormatFp64},
1741 {{0}, 0, _FpFormatFp80}},
1742 EXCEPTION_CONTINUE_EXECUTION },
1743 { STATUS_FLOAT_INEXACT_RESULT, 0x35dc, (DWORD)&argd, 0, 0,
1744 {0, 2, _FpCodeDivide,
1745 {0}, {1, 1, 1, 1, 1}, {0},
1746 {{0}, 0, _FpFormatFp80},
1747 {{0}, 1, _FpFormatFp64},
1748 {{0}, 1, _FpFormatFp80}},
1749 EXCEPTION_CONTINUE_EXECUTION },
1750 { STATUS_FLOAT_INVALID_OPERATION, 0x35dc, (DWORD)&argd, 0, 0,
1751 {0, 2, _FpCodeDivide,
1752 {0}, {1, 1, 1, 1, 1}, {0},
1753 {{0}, 1, _FpFormatFp80},
1754 {{0}, 1, _FpFormatFp64},
1755 {{0}, 0, _FpFormatFp80}},
1756 EXCEPTION_CONTINUE_EXECUTION },
1757 { STATUS_FLOAT_OVERFLOW, 0x35dc, (DWORD)&argd, 0, 0,
1758 {0, 2, _FpCodeDivide,
1759 {0}, {1, 1, 1, 1, 1}, {0},
1760 {{0}, 0, _FpFormatFp80},
1761 {{0}, 1, _FpFormatFp64},
1762 {{0}, 1, _FpFormatFp80}},
1763 EXCEPTION_CONTINUE_EXECUTION },
1764 { STATUS_FLOAT_UNDERFLOW, 0x35dc, (DWORD)&argd, 0, 0,
1765 {0, 2, _FpCodeDivide,
1766 {0}, {1, 1, 1, 1, 1}, {0},
1767 {{0}, 0, _FpFormatFp80},
1768 {{0}, 1, _FpFormatFp64},
1769 {{0}, 1, _FpFormatFp80}},
1770 EXCEPTION_CONTINUE_EXECUTION },
1771 { STATUS_FLOAT_DIVIDE_BY_ZERO, 0x35dc, (DWORD)&argd, 0, 0xffffffff,
1772 {0, 2, _FpCodeDivide,
1773 {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1},
1774 {{0}, 1, _FpFormatFp80},
1775 {{0}, 1, _FpFormatFp64},
1776 {{0}, 0, _FpFormatFp80}},
1777 EXCEPTION_CONTINUE_EXECUTION },
1778 { STATUS_FLOAT_DIVIDE_BY_ZERO, 0x35dc, (DWORD)&argd, 0xffffffff, 0xffffffff,
1779 {3, 0, _FpCodeDivide,
1780 {0}, {0}, {1, 1, 1, 1, 1},
1781 {{0}, 1, _FpFormatFp80},
1782 {{0}, 1, _FpFormatFp64},
1783 {{0}, 0, _FpFormatFp80}},
1784 EXCEPTION_CONTINUE_EXECUTION },
1786 EXCEPTION_POINTERS ep;
1787 EXCEPTION_RECORD rec;
1788 CONTEXT ctx;
1789 int i, ret;
1791 if(!p__fpieee_flt) {
1792 win_skip("_fpieee_flt not available\n");
1793 return;
1796 ep.ExceptionRecord = &rec;
1797 ep.ContextRecord = &ctx;
1798 memset(&rec, 0, sizeof(rec));
1799 memset(&ctx, 0, sizeof(ctx));
1800 ret = p__fpieee_flt(1, &ep, fpieee_handler);
1801 ok(ret == EXCEPTION_CONTINUE_SEARCH, "_fpieee_flt returned %d\n", ret);
1802 ok(handler_called == 0, "handler_called = %d\n", handler_called);
1804 for(i=0; i<ARRAY_SIZE(test_data); i++) {
1805 ep.ExceptionRecord = &rec;
1806 ep.ContextRecord = &ctx;
1807 memset(&rec, 0, sizeof(rec));
1808 memset(&ctx, 0, sizeof(ctx));
1810 ctx.FloatSave.ErrorOffset = (DWORD)&test_data[i].opcode;
1811 ctx.FloatSave.DataOffset = test_data[i].data_offset;
1812 ctx.FloatSave.ControlWord = test_data[i].control_word;
1813 ctx.FloatSave.StatusWord = test_data[i].status_word;
1815 handler_called = 0;
1816 ret = p__fpieee_flt(test_data[i].exception_code, &ep, fpieee_handler);
1817 ok(ret == test_data[i].ret, "%d) _fpieee_flt returned %d\n", i, ret);
1818 ok(handler_called == 1, "%d) handler_called = %d\n", i, handler_called);
1820 ok(fpieee_record.RoundingMode == test_data[i].rec.RoundingMode,
1821 "%d) RoundingMode = %x\n", i, fpieee_record.RoundingMode);
1822 ok(fpieee_record.Precision == test_data[i].rec.Precision,
1823 "%d) Precision = %x\n", i, fpieee_record.Precision);
1824 ok(fpieee_record.Operation == test_data[i].rec.Operation,
1825 "%d) Operation = %x\n", i, fpieee_record.Operation);
1826 ok(fpieee_record.Cause.Inexact == test_data[i].rec.Cause.Inexact,
1827 "%d) Cause.Inexact = %x\n", i, fpieee_record.Cause.Inexact);
1828 ok(fpieee_record.Cause.Underflow == test_data[i].rec.Cause.Underflow,
1829 "%d) Cause.Underflow = %x\n", i, fpieee_record.Cause.Underflow);
1830 ok(fpieee_record.Cause.Overflow == test_data[i].rec.Cause.Overflow,
1831 "%d) Cause.Overflow = %x\n", i, fpieee_record.Cause.Overflow);
1832 ok(fpieee_record.Cause.ZeroDivide == test_data[i].rec.Cause.ZeroDivide,
1833 "%d) Cause.ZeroDivide = %x\n", i, fpieee_record.Cause.ZeroDivide);
1834 ok(fpieee_record.Cause.InvalidOperation == test_data[i].rec.Cause.InvalidOperation,
1835 "%d) Cause.InvalidOperation = %x\n", i, fpieee_record.Cause.InvalidOperation);
1836 ok(fpieee_record.Enable.Inexact == test_data[i].rec.Enable.Inexact,
1837 "%d) Enable.Inexact = %x\n", i, fpieee_record.Enable.Inexact);
1838 ok(fpieee_record.Enable.Underflow == test_data[i].rec.Enable.Underflow,
1839 "%d) Enable.Underflow = %x\n", i, fpieee_record.Enable.Underflow);
1840 ok(fpieee_record.Enable.Overflow == test_data[i].rec.Enable.Overflow,
1841 "%d) Enable.Overflow = %x\n", i, fpieee_record.Enable.Overflow);
1842 ok(fpieee_record.Enable.ZeroDivide == test_data[i].rec.Enable.ZeroDivide,
1843 "%d) Enable.ZeroDivide = %x\n", i, fpieee_record.Enable.ZeroDivide);
1844 ok(fpieee_record.Enable.InvalidOperation == test_data[i].rec.Enable.InvalidOperation,
1845 "%d) Enable.InvalidOperation = %x\n", i, fpieee_record.Enable.InvalidOperation);
1846 ok(fpieee_record.Status.Inexact == test_data[i].rec.Status.Inexact,
1847 "%d) Status.Inexact = %x\n", i, fpieee_record.Status.Inexact);
1848 ok(fpieee_record.Status.Underflow == test_data[i].rec.Status.Underflow,
1849 "%d) Status.Underflow = %x\n", i, fpieee_record.Status.Underflow);
1850 ok(fpieee_record.Status.Overflow == test_data[i].rec.Status.Overflow,
1851 "%d) Status.Overflow = %x\n", i, fpieee_record.Status.Overflow);
1852 ok(fpieee_record.Status.ZeroDivide == test_data[i].rec.Status.ZeroDivide,
1853 "%d) Status.ZeroDivide = %x\n", i, fpieee_record.Status.ZeroDivide);
1854 ok(fpieee_record.Status.InvalidOperation == test_data[i].rec.Status.InvalidOperation,
1855 "%d) Status.InvalidOperation = %x\n", i, fpieee_record.Status.InvalidOperation);
1856 ok(fpieee_record.Operand1.OperandValid == test_data[i].rec.Operand1.OperandValid,
1857 "%d) Operand1.OperandValid = %x\n", i, fpieee_record.Operand1.OperandValid);
1858 if(fpieee_record.Operand1.OperandValid) {
1859 ok(fpieee_record.Operand1.Format == test_data[i].rec.Operand1.Format,
1860 "%d) Operand1.Format = %x\n", i, fpieee_record.Operand1.Format);
1862 ok(fpieee_record.Operand2.OperandValid == test_data[i].rec.Operand2.OperandValid,
1863 "%d) Operand2.OperandValid = %x\n", i, fpieee_record.Operand2.OperandValid);
1864 ok(fpieee_record.Operand2.Format == test_data[i].rec.Operand2.Format,
1865 "%d) Operand2.Format = %x\n", i, fpieee_record.Operand2.Format);
1866 ok(fpieee_record.Result.OperandValid == test_data[i].rec.Result.OperandValid,
1867 "%d) Result.OperandValid = %x\n", i, fpieee_record.Result.OperandValid);
1868 ok(fpieee_record.Result.Format == test_data[i].rec.Result.Format,
1869 "%d) Result.Format = %x\n", i, fpieee_record.Result.Format);
1872 #endif
1874 static void test__memicmp(void)
1876 static const char *s1 = "abc";
1877 static const char *s2 = "aBd";
1878 int ret;
1880 ret = p__memicmp(NULL, NULL, 0);
1881 ok(!ret, "got %d\n", ret);
1883 SET_EXPECT(invalid_parameter_handler);
1884 ret = p__memicmp(NULL, NULL, 1);
1885 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1886 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1888 SET_EXPECT(invalid_parameter_handler);
1889 ret = p__memicmp(s1, NULL, 1);
1890 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1891 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1893 SET_EXPECT(invalid_parameter_handler);
1894 ret = p__memicmp(NULL, s2, 1);
1895 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1896 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1898 ret = p__memicmp(s1, s2, 2);
1899 ok(!ret, "got %d\n", ret);
1901 ret = p__memicmp(s1, s2, 3);
1902 ok(ret == -1, "got %d\n", ret);
1905 static void test__memicmp_l(void)
1907 static const char *s1 = "abc";
1908 static const char *s2 = "aBd";
1909 int ret;
1911 ret = p__memicmp_l(NULL, NULL, 0, NULL);
1912 ok(!ret, "got %d\n", ret);
1914 SET_EXPECT(invalid_parameter_handler);
1915 ret = p__memicmp_l(NULL, NULL, 1, NULL);
1916 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1917 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1919 SET_EXPECT(invalid_parameter_handler);
1920 ret = p__memicmp_l(s1, NULL, 1, NULL);
1921 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1922 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1924 SET_EXPECT(invalid_parameter_handler);
1925 ret = p__memicmp_l(NULL, s2, 1, NULL);
1926 ok(ret == _NLSCMPERROR, "got %d\n", ret);
1927 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1929 ret = p__memicmp_l(s1, s2, 2, NULL);
1930 ok(!ret, "got %d\n", ret);
1932 ret = p__memicmp_l(s1, s2, 3, NULL);
1933 ok(ret == -1, "got %d\n", ret);
1936 static int WINAPIV _vsnwprintf_wrapper(wchar_t *str, size_t len, const wchar_t *format, ...)
1938 int ret;
1939 va_list valist;
1940 va_start(valist, format);
1941 ret = p__vsnwprintf(str, len, format, valist);
1942 va_end(valist);
1943 return ret;
1946 static void test__vsnwprintf(void)
1948 int ret;
1949 WCHAR str[2] = {0};
1951 _invalid_parameter_handler old_handler = p_set_invalid_parameter_handler(test_invalid_parameter_handler);
1953 SET_EXPECT(invalid_parameter_handler);
1954 errno = 0xdeadbeef;
1955 str[0] = 'x';
1956 ret = _vsnwprintf_wrapper(str, 0, NULL);
1957 ok(ret == -1, "got %d, expected -1\n", ret);
1958 ok(str[0] == 'x', "Expected string to be unchanged.\n");
1959 CHECK_CALLED(invalid_parameter_handler, EINVAL);
1961 ok(p_set_invalid_parameter_handler(old_handler) == test_invalid_parameter_handler, "Cannot reset invalid parameter handler\n");
1964 static void test___strncnt(void)
1966 static const struct
1968 const char *str;
1969 size_t size;
1970 size_t ret;
1972 strncnt_tests[] =
1974 { NULL, 0, 0 },
1975 { "a", 0, 0 },
1976 { "a", 1, 1 },
1977 { "a", 10, 1 },
1978 { "abc", 1, 1 },
1980 unsigned int i;
1981 size_t ret;
1983 if (0)
1984 ret = p___strncnt(NULL, 1);
1986 for (i = 0; i < ARRAY_SIZE(strncnt_tests); ++i)
1988 ret = p___strncnt(strncnt_tests[i].str, strncnt_tests[i].size);
1989 ok(ret == strncnt_tests[i].ret, "%u: unexpected return value %u.\n", i, (int)ret);
1993 static void test_swscanf(void)
1996 wchar_t buffer[100];
1997 int ret;
1999 /* check WEOF */
2000 ret = p_swscanf(L" \t\n\n", L"%s", buffer);
2001 ok( ret == (short)WEOF, "ret = %d\n", ret );
2004 static void test____mb_cur_max_l_func(void)
2006 int ret;
2007 _locale_t l;
2009 ret = p____mb_cur_max_l_func(NULL);
2010 ok( ret == 1, "MB_CUR_MAX_L(NULL) = %d\n", ret );
2012 l = p__create_locale(LC_ALL, "chinese-traditional");
2013 if (!l)
2015 skip("DBCS locale not available\n");
2016 return;
2018 ret = p____mb_cur_max_l_func(l);
2019 ok( ret == 2, "MB_CUR_MAX_L(cht) = %d\n", ret );
2020 p__free_locale(l);
2023 static void test__get_current_locale(void)
2025 _locale_t l, l2;
2026 int i;
2028 ok(!p__setmbcp(1252), "_setmbcp failed\n");
2029 l = p__get_current_locale();
2030 l2 = p__get_current_locale();
2032 ok(!strcmp(l->locinfo->lc_category[LC_COLLATE].locale, "C"),
2033 "LC_COLLATE = \"%s\"\n", l->locinfo->lc_category[LC_COLLATE].locale);
2034 ok(!strcmp(l->locinfo->lc_category[LC_CTYPE].locale, "C"),
2035 "LC_CTYPE = \"%s\"\n", l->locinfo->lc_category[LC_CTYPE].locale);
2036 ok(!strcmp(l->locinfo->lc_category[LC_MONETARY].locale, "C"),
2037 "LC_MONETARY = \"%s\"\n", l->locinfo->lc_category[LC_MONETARY].locale);
2038 ok(!strcmp(l->locinfo->lc_category[LC_NUMERIC].locale, "C"),
2039 "LC_NUMERIC = \"%s\"\n", l->locinfo->lc_category[LC_NUMERIC].locale);
2040 ok(!strcmp(l->locinfo->lc_category[LC_TIME].locale, "C"),
2041 "LC_TIME = \"%s\"\n", l->locinfo->lc_category[LC_TIME].locale);
2042 ok(l->mbcinfo->mbcodepage == 1252, "mbcodepage = %d\n", l->mbcinfo->mbcodepage);
2044 ok(l->locinfo->refcount == 3, "refcount = %d\n", l->locinfo->refcount);
2046 if(!p_setlocale(LC_ALL, "english")) {
2047 win_skip("English locale not available\n");
2048 p__free_locale(l);
2049 p__free_locale(l2);
2050 return;
2052 ok(!p__setmbcp(932), "_setmbcp failed\n");
2054 ok(!strcmp(l->locinfo->lc_category[LC_COLLATE].locale, "C"),
2055 "LC_COLLATE = \"%s\"\n", l->locinfo->lc_category[LC_COLLATE].locale);
2056 ok(!strcmp(l->locinfo->lc_category[LC_CTYPE].locale, "C"),
2057 "LC_CTYPE = \"%s\"\n", l->locinfo->lc_category[LC_CTYPE].locale);
2058 ok(!strcmp(l->locinfo->lc_category[LC_MONETARY].locale, "C"),
2059 "LC_MONETARY = \"%s\"\n", l->locinfo->lc_category[LC_MONETARY].locale);
2060 ok(!strcmp(l->locinfo->lc_category[LC_NUMERIC].locale, "C"),
2061 "LC_NUMERIC = \"%s\"\n", l->locinfo->lc_category[LC_NUMERIC].locale);
2062 ok(!strcmp(l->locinfo->lc_category[LC_TIME].locale, "C"),
2063 "LC_TIME = \"%s\"\n", l->locinfo->lc_category[LC_TIME].locale);
2064 ok(l->mbcinfo->mbcodepage == 1252, "mbcodepage = %d\n", l->mbcinfo->mbcodepage);
2066 ok(l->locinfo->refcount == 2, "refcount = %d\n", l->locinfo->refcount);
2067 ok(l->locinfo == l2->locinfo, "different locinfo pointers\n");
2068 ok(l->mbcinfo == l2->mbcinfo, "different mbcinfo pointers\n");
2070 p__free_locale(l);
2071 p__free_locale(l2);
2073 l = p__get_current_locale();
2074 p_setlocale(LC_COLLATE, "C");
2075 l2 = p__get_current_locale();
2077 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2078 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2080 ok(l->locinfo->lc_category[LC_COLLATE].locale != l2->locinfo->lc_category[LC_COLLATE].locale,
2081 "same locale name pointers for LC_COLLATE\n");
2082 ok(l->locinfo->lc_category[LC_COLLATE].refcount != l2->locinfo->lc_category[LC_COLLATE].refcount,
2083 "same refcount pointers for LC_COLLATE\n");
2084 ok(*l2->locinfo->lc_category[LC_COLLATE].refcount == 2, "refcount = %d\n",
2085 *l2->locinfo->lc_category[LC_COLLATE].refcount);
2086 ok(*l->locinfo->lc_category[LC_COLLATE].refcount == 1, "refcount = %d\n",
2087 *l->locinfo->lc_category[LC_COLLATE].refcount);
2088 for(i = LC_CTYPE; i <= LC_MAX; i++) {
2089 ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale,
2090 "different locale name pointers for category %d\n", i);
2091 ok(l->locinfo->lc_category[i].refcount == l2->locinfo->lc_category[i].refcount,
2092 "different refcount pointers for category %d\n", i);
2093 ok(*l->locinfo->lc_category[i].refcount == 3, "refcount = %d for category %d\n",
2094 *l->locinfo->lc_category[i].refcount, i);
2097 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2098 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2100 ok(l->locinfo->lc_codepage == l2->locinfo->lc_codepage, "different lc_codepages %u, %u\n",
2101 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2102 ok(l->locinfo->lc_clike == l2->locinfo->lc_clike, "different lc_clike values %d, %d\n",
2103 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2104 /* The meaning of this member seems to be reversed--go figure */
2105 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2106 ok(l->locinfo->ctype1 == l2->locinfo->ctype1, "different ctype1 pointers\n");
2107 ok(l->locinfo->pclmap == l2->locinfo->pclmap, "different clmap pointers\n");
2108 ok(l->locinfo->pcumap == l2->locinfo->pcumap, "different cumap pointers\n");
2109 ok(l->locinfo->ctype1_refcount == l2->locinfo->ctype1_refcount, "different ctype1_refcount pointers\n");
2110 ok(*l->locinfo->ctype1_refcount == 3, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2112 ok(l->locinfo->lconv == l2->locinfo->lconv, "different lconv pointers\n");
2113 ok(l->locinfo->lconv_intl_refcount == l2->locinfo->lconv_intl_refcount, "different lconv_intl_refcount pointers\n");
2114 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2115 ok(*l->locinfo->lconv_intl_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2117 ok(l->locinfo->lconv->decimal_point == l2->locinfo->lconv->decimal_point, "different LC_NUMERIC pointers\n");
2118 ok(l->locinfo->lconv_num_refcount == l2->locinfo->lconv_num_refcount, "different lconv_num_refcount pointers\n");
2119 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2120 ok(*l->locinfo->lconv_num_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2122 ok(l->locinfo->lconv->currency_symbol == l2->locinfo->lconv->currency_symbol, "different LC_MONETARY pointers\n");
2123 ok(l->locinfo->lconv_mon_refcount == l2->locinfo->lconv_mon_refcount, "different lconv_mon_refcount pointers\n");
2124 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2125 ok(*l->locinfo->lconv_mon_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2127 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2128 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2129 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2131 p__free_locale(l2);
2133 p_setlocale(LC_CTYPE, "C");
2134 l2 = p__get_current_locale();
2136 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2137 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2139 for(i = LC_COLLATE; i < LC_MONETARY; i++) {
2140 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2141 "same locale name pointers for category %d\n", i);
2142 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2143 "same refcount pointers for category %d\n", i);
2144 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2145 *l2->locinfo->lc_category[i].refcount, i);
2146 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2147 *l->locinfo->lc_category[i].refcount, i);
2149 for(i = LC_MONETARY; i <= LC_MAX; i++) {
2150 ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale,
2151 "different locale name pointers for category %d\n", i);
2152 ok(l->locinfo->lc_category[i].refcount == l2->locinfo->lc_category[i].refcount,
2153 "different refcount pointers for category %d\n", i);
2154 ok(*l->locinfo->lc_category[i].refcount == 3, "refcount = %d for category %d\n",
2155 *l->locinfo->lc_category[i].refcount, i);
2158 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2159 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2161 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2162 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2163 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2164 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2165 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2166 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2167 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2168 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2169 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2170 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2171 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2172 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2173 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2175 ok(l->locinfo->lconv == l2->locinfo->lconv, "different lconv pointers\n");
2176 ok(l->locinfo->lconv_intl_refcount == l2->locinfo->lconv_intl_refcount, "different lconv_intl_refcount pointers\n");
2177 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2178 ok(*l->locinfo->lconv_intl_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2180 ok(l->locinfo->lconv->decimal_point == l2->locinfo->lconv->decimal_point, "different LC_NUMERIC pointers\n");
2181 ok(l->locinfo->lconv_num_refcount == l2->locinfo->lconv_num_refcount, "different lconv_num_refcount pointers\n");
2182 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2183 ok(*l->locinfo->lconv_num_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2185 ok(l->locinfo->lconv->currency_symbol == l2->locinfo->lconv->currency_symbol, "different LC_MONETARY pointers\n");
2186 ok(l->locinfo->lconv_mon_refcount == l2->locinfo->lconv_mon_refcount, "different lconv_mon_refcount pointers\n");
2187 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2188 ok(*l->locinfo->lconv_mon_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2190 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2191 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2192 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2194 p__free_locale(l2);
2196 p_setlocale(LC_MONETARY, "C");
2197 l2 = p__get_current_locale();
2199 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2200 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2202 for(i = LC_COLLATE; i <= LC_MONETARY; i++) {
2203 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2204 "same locale name pointers for category %d\n", i);
2205 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2206 "same refcount pointers for category %d\n", i);
2207 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2208 *l2->locinfo->lc_category[i].refcount, i);
2209 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2210 *l->locinfo->lc_category[i].refcount, i);
2212 for(i = LC_NUMERIC; i <= LC_MAX; i++) {
2213 ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale,
2214 "different locale name pointers for category %d\n", i);
2215 ok(l->locinfo->lc_category[i].refcount == l2->locinfo->lc_category[i].refcount,
2216 "different refcount pointers for category %d\n", i);
2217 ok(*l->locinfo->lc_category[i].refcount == 3, "refcount = %d for category %d\n",
2218 *l->locinfo->lc_category[i].refcount, i);
2221 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2222 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2224 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2225 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2226 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2227 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2228 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2229 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2230 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2231 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2232 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2233 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2234 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2235 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2236 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2238 ok(l->locinfo->lconv != l2->locinfo->lconv, "same lconv pointers\n");
2239 ok(l->locinfo->lconv_intl_refcount != l2->locinfo->lconv_intl_refcount, "same lconv_intl_refcount pointers\n");
2240 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2241 ok(*l->locinfo->lconv_intl_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2242 ok(!!l2->locinfo->lconv_intl_refcount, "null refcount pointer for C locale\n");
2243 ok(*l2->locinfo->lconv_intl_refcount == 2, "refcount = %d\n", *l2->locinfo->lconv_intl_refcount);
2245 ok(l->locinfo->lconv->decimal_point == l2->locinfo->lconv->decimal_point, "different LC_NUMERIC pointers\n");
2246 ok(l->locinfo->lconv_num_refcount == l2->locinfo->lconv_num_refcount, "different lconv_num_refcount pointers\n");
2247 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2248 ok(*l->locinfo->lconv_num_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2250 ok(l->locinfo->lconv->currency_symbol != l2->locinfo->lconv->currency_symbol, "same LC_MONETARY pointers\n");
2251 ok(l->locinfo->lconv_mon_refcount != l2->locinfo->lconv_mon_refcount, "same lconv_mon_refcount pointers\n");
2252 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2253 ok(*l->locinfo->lconv_mon_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2254 ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
2256 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2257 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2258 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2260 p__free_locale(l2);
2262 p_setlocale(LC_NUMERIC, "C");
2263 l2 = p__get_current_locale();
2265 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2266 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2268 for(i = LC_COLLATE; i <= LC_NUMERIC; i++) {
2269 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2270 "same locale name pointers for category %d\n", i);
2271 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2272 "same refcount pointers for category %d\n", i);
2273 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2274 *l2->locinfo->lc_category[i].refcount, i);
2275 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2276 *l->locinfo->lc_category[i].refcount, i);
2278 ok(l->locinfo->lc_category[LC_TIME].locale == l2->locinfo->lc_category[LC_TIME].locale,
2279 "different locale name pointers for LC_TIME\n");
2280 ok(l->locinfo->lc_category[LC_TIME].refcount == l2->locinfo->lc_category[LC_TIME].refcount,
2281 "different refcount pointers for LC_TIME\n");
2282 ok(*l->locinfo->lc_category[LC_TIME].refcount == 3, "refcount = %d\n",
2283 *l->locinfo->lc_category[LC_TIME].refcount);
2285 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2286 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2288 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2289 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2290 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2291 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2292 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2293 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2294 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2295 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2296 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2297 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2298 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2299 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2300 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2302 ok(l->locinfo->lconv != l2->locinfo->lconv, "same lconv pointers\n");
2303 ok(l->locinfo->lconv_intl_refcount != l2->locinfo->lconv_intl_refcount, "same lconv_intl_refcount pointers\n");
2304 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2305 ok(*l->locinfo->lconv_intl_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2306 ok(!l2->locinfo->lconv_intl_refcount, "nonnull refcount pointer for C locale\n");
2308 ok(l->locinfo->lconv->decimal_point != l2->locinfo->lconv->decimal_point, "same LC_NUMERIC pointers\n");
2309 ok(l->locinfo->lconv_num_refcount != l2->locinfo->lconv_num_refcount, "same lconv_num_refcount pointers\n");
2310 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2311 ok(*l->locinfo->lconv_num_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2312 ok(!l2->locinfo->lconv_num_refcount, "nonnull refcount pointer for C locale\n");
2314 ok(l->locinfo->lconv->currency_symbol != l2->locinfo->lconv->currency_symbol, "same LC_MONETARY pointers\n");
2315 ok(l->locinfo->lconv_mon_refcount != l2->locinfo->lconv_mon_refcount, "same lconv_mon_refcount pointers\n");
2316 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2317 ok(*l->locinfo->lconv_mon_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2318 ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
2320 ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
2321 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2322 ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2324 p__free_locale(l2);
2326 p_setlocale(LC_TIME, "C");
2327 l2 = p__get_current_locale();
2329 ok(l->locinfo->refcount == 1, "refcount = %d\n", l->locinfo->refcount);
2330 ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount);
2332 for(i = LC_MIN+1; i <= LC_MAX; i++) {
2333 ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale,
2334 "same locale name pointers for category %d\n", i);
2335 ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount,
2336 "same refcount pointers for category %d\n", i);
2337 ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n",
2338 *l2->locinfo->lc_category[i].refcount, i);
2339 ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n",
2340 *l->locinfo->lc_category[i].refcount, i);
2343 ok(l->locinfo->lc_collate_cp != l2->locinfo->lc_collate_cp, "same lc_collate_cp %u, %u\n",
2344 l->locinfo->lc_collate_cp, l2->locinfo->lc_collate_cp);
2346 ok(l->locinfo->lc_codepage != l2->locinfo->lc_codepage, "same lc_codepages %u, %u\n",
2347 l->locinfo->lc_codepage, l2->locinfo->lc_codepage);
2348 todo_wine ok(l->locinfo->lc_clike != l2->locinfo->lc_clike, "same lc_clike values %d, %d\n",
2349 l->locinfo->lc_clike, l2->locinfo->lc_clike);
2350 ok(l->locinfo->lc_clike, "non-C locale is C-like\n");
2351 todo_wine ok(!l2->locinfo->lc_clike, "C locale is not C-like\n");
2352 ok(l->locinfo->ctype1 != l2->locinfo->ctype1, "same ctype1 pointers\n");
2353 ok(l->locinfo->pclmap != l2->locinfo->pclmap, "same clmap pointers\n");
2354 ok(l->locinfo->pcumap != l2->locinfo->pcumap, "same cumap pointers\n");
2355 ok(l->locinfo->ctype1_refcount != l2->locinfo->ctype1_refcount, "same ctype1_refcount pointers\n");
2356 ok(!!l->locinfo->ctype1_refcount, "null refcount pointer for non-C locale\n");
2357 ok(*l->locinfo->ctype1_refcount == 1, "refcount = %d\n", *l->locinfo->ctype1_refcount);
2358 ok(!l2->locinfo->ctype1_refcount, "nonnull refcount pointer for C locale\n");
2360 ok(l->locinfo->lconv != l2->locinfo->lconv, "same lconv pointers\n");
2361 ok(l->locinfo->lconv_intl_refcount != l2->locinfo->lconv_intl_refcount, "same lconv_intl_refcount pointers\n");
2362 ok(!!l->locinfo->lconv_intl_refcount, "null refcount pointer in non-C locale\n");
2363 ok(*l->locinfo->lconv_intl_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_intl_refcount);
2364 ok(!l2->locinfo->lconv_intl_refcount, "nonnull refcount pointer for C locale\n");
2366 ok(l->locinfo->lconv->decimal_point != l2->locinfo->lconv->decimal_point, "same LC_NUMERIC pointers\n");
2367 ok(l->locinfo->lconv_num_refcount != l2->locinfo->lconv_num_refcount, "same lconv_num_refcount pointers\n");
2368 ok(!!l->locinfo->lconv_num_refcount, "null refcount pointer in non-C locale\n");
2369 ok(*l->locinfo->lconv_num_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_num_refcount);
2370 ok(!l2->locinfo->lconv_num_refcount, "nonnull refcount pointer for C locale\n");
2372 ok(l->locinfo->lconv->currency_symbol != l2->locinfo->lconv->currency_symbol, "same LC_MONETARY pointers\n");
2373 ok(l->locinfo->lconv_mon_refcount != l2->locinfo->lconv_mon_refcount, "same lconv_mon_refcount pointers\n");
2374 ok(!!l->locinfo->lconv_mon_refcount, "null refcount pointer in non-C locale\n");
2375 ok(*l->locinfo->lconv_mon_refcount == 1, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
2376 ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
2378 ok(l->locinfo->lc_time_curr != l2->locinfo->lc_time_curr, "same lc_time_curr pointers\n");
2379 ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
2380 ok(l->locinfo->lc_time_curr->refcount == 1, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
2381 ok(l2->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l2->locinfo->lc_time_curr->unk);
2382 ok(l2->locinfo->lc_time_curr->refcount == 3 || broken(l2->locinfo->lc_time_curr->refcount == 2),
2383 "refcount = %d\n", l2->locinfo->lc_time_curr->refcount);
2385 p__free_locale(l2);
2387 p__free_locale(l);
2388 p_setlocale(LC_ALL, "C");
2391 static void test_ioinfo_flags(void)
2393 HANDLE handle;
2394 ioinfo *info;
2395 char *tempf;
2396 int tempfd;
2398 tempf = _tempnam(".","wne");
2400 tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_WTEXT, _S_IWRITE);
2401 ok(tempfd != -1, "_open failed with error: %d\n", errno);
2402 handle = (HANDLE)p__get_osfhandle(tempfd);
2403 info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
2404 ok(!!info, "NULL info.\n");
2405 ok(info->handle == handle, "Unexpected handle %p, expected %p.\n", info->handle, handle);
2406 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
2407 ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
2408 ok(info->unicode, "Unicode is not set.\n");
2409 ok(info->textmode == 2, "Unexpected textmode %d.\n", info->textmode);
2410 p__close(tempfd);
2412 ok(info->handle == INVALID_HANDLE_VALUE, "Unexpected handle %p.\n", info->handle);
2413 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
2414 ok(info->unicode, "Unicode is not set.\n");
2415 ok(!info->wxflag, "Unexpected wxflag %#x.\n", info->wxflag);
2416 ok(info->textmode == 2, "Unexpected textmode %d.\n", info->textmode);
2418 info = &__pioinfo[(tempfd + 4) / MSVCRT_FD_BLOCK_SIZE][(tempfd + 4) % MSVCRT_FD_BLOCK_SIZE];
2419 ok(!!info, "NULL info.\n");
2420 ok(info->handle == INVALID_HANDLE_VALUE, "Unexpected handle %p.\n", info->handle);
2421 ok(!info->exflag, "Unexpected exflag %#x.\n", info->exflag);
2422 ok(!info->textmode, "Unexpected textmode %d.\n", info->textmode);
2424 tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_TEXT, _S_IWRITE);
2425 ok(tempfd != -1, "_open failed with error: %d\n", errno);
2426 info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
2427 ok(!!info, "NULL info.\n");
2428 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
2429 ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
2430 ok(!info->unicode, "Unicode is not set.\n");
2431 ok(!info->textmode, "Unexpected textmode %d.\n", info->textmode);
2432 p__close(tempfd);
2434 tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_U8TEXT, _S_IWRITE);
2435 ok(tempfd != -1, "_open failed with error: %d\n", errno);
2436 info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
2437 ok(!!info, "NULL info.\n");
2438 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
2439 ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
2440 ok(!info->unicode, "Unicode is not set.\n");
2441 ok(info->textmode == 1, "Unexpected textmode %d.\n", info->textmode);
2442 p__close(tempfd);
2444 unlink(tempf);
2445 free(tempf);
2448 static void test_strcmp(void)
2450 int ret = p_strcmp( "abc", "abcd" );
2451 ok( ret == -1, "wrong ret %d\n", ret );
2452 ret = p_strcmp( "", "abc" );
2453 ok( ret == -1, "wrong ret %d\n", ret );
2454 ret = p_strcmp( "abc", "ab\xa0" );
2455 ok( ret == -1, "wrong ret %d\n", ret );
2456 ret = p_strcmp( "ab\xb0", "ab\xa0" );
2457 ok( ret == 1, "wrong ret %d\n", ret );
2458 ret = p_strcmp( "ab\xc2", "ab\xc2" );
2459 ok( ret == 0, "wrong ret %d\n", ret );
2461 ret = p_strncmp( "abc", "abcd", 3 );
2462 ok( ret == 0, "wrong ret %d\n", ret );
2463 #ifdef _WIN64
2464 ret = p_strncmp( "", "abc", 3 );
2465 ok( ret == -1, "wrong ret %d\n", ret );
2466 ret = p_strncmp( "abc", "ab\xa0", 4 );
2467 ok( ret == -1, "wrong ret %d\n", ret );
2468 ret = p_strncmp( "ab\xb0", "ab\xa0", 3 );
2469 ok( ret == 1, "wrong ret %d\n", ret );
2470 #else
2471 ret = p_strncmp( "", "abc", 3 );
2472 ok( ret == 0 - 'a', "wrong ret %d\n", ret );
2473 ret = p_strncmp( "abc", "ab\xa0", 4 );
2474 ok( ret == 'c' - 0xa0, "wrong ret %d\n", ret );
2475 ret = p_strncmp( "ab\xb0", "ab\xa0", 3 );
2476 ok( ret == 0xb0 - 0xa0, "wrong ret %d\n", ret );
2477 #endif
2478 ret = p_strncmp( "ab\xb0", "ab\xa0", 2 );
2479 ok( ret == 0, "wrong ret %d\n", ret );
2480 ret = p_strncmp( "ab\xc2", "ab\xc2", 3 );
2481 ok( ret == 0, "wrong ret %d\n", ret );
2482 ret = p_strncmp( "abc", "abd", 0 );
2483 ok( ret == 0, "wrong ret %d\n", ret );
2484 ret = p_strncmp( "abc", "abc", 12 );
2485 ok( ret == 0, "wrong ret %d\n", ret );
2488 START_TEST(msvcr90)
2490 if(!init())
2491 return;
2493 test__initterm_e();
2494 test__encode_pointer();
2495 test_error_messages();
2496 test__strtoi64();
2497 test__itoa_s();
2498 test_wcsncat_s();
2499 test_qsort_s();
2500 test_bsearch_s();
2501 test_controlfp_s();
2502 test_tmpfile_s();
2503 test__atoflt();
2504 test__set_abort_behavior();
2505 test__sopen_s();
2506 test__wsopen_s();
2507 test__realloc_crt();
2508 test_typeinfo();
2509 test_getptd();
2510 test__vswprintf_l();
2511 test_nonblocking_file_access();
2512 test_byteswap();
2513 test_access_s();
2514 test_is_exception_typeof();
2515 test__AdjustPointer();
2516 test_mbstowcs();
2517 test_strtok_s();
2518 test__mbstok_s();
2519 test__memicmp();
2520 test__memicmp_l();
2521 test__vsnwprintf();
2522 #ifdef __i386__
2523 test__fpieee_flt();
2524 #endif
2525 test___strncnt();
2526 test_swscanf();
2527 test____mb_cur_max_l_func();
2528 test__get_current_locale();
2529 test_ioinfo_flags();
2530 test_strcmp();