TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / msvcp120 / tests / msvcp120.c
blob6ea024a37ed94ff7841769ff09bf834d25895bf1
1 /*
2 * Copyright 2014 Yifu Wang for ESRI
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 <locale.h>
20 #include <stdio.h>
21 #include <math.h>
22 #include <limits.h>
24 #include "wine/test.h"
25 #include "winbase.h"
27 static inline float __port_infinity(void)
29 static const unsigned __inf_bytes = 0x7f800000;
30 return *(const float *)&__inf_bytes;
32 #define INFINITY __port_infinity()
34 static inline float __port_nan(void)
36 static const unsigned __nan_bytes = 0x7fc00000;
37 return *(const float *)&__nan_bytes;
39 #define NAN __port_nan()
41 typedef int MSVCRT_long;
42 typedef unsigned char MSVCP_bool;
44 /* xtime */
45 typedef struct {
46 __time64_t sec;
47 MSVCRT_long nsec;
48 } xtime;
50 typedef struct {
51 unsigned page;
52 int mb_max;
53 int unk;
54 BYTE isleadbyte[32];
55 } _Cvtvec;
57 struct space_info {
58 ULONGLONG capacity;
59 ULONGLONG free;
60 ULONGLONG available;
63 enum file_type {
64 status_unknown, file_not_found, regular_file, directory_file,
65 symlink_file, block_file, character_file, fifo_file, socket_file,
66 type_unknown
69 static BOOL compare_float(float f, float g, unsigned int ulps)
71 int x = *(int *)&f;
72 int y = *(int *)&g;
74 if (x < 0)
75 x = INT_MIN - x;
76 if (y < 0)
77 y = INT_MIN - y;
79 if (abs(x - y) > ulps)
80 return FALSE;
82 return TRUE;
85 static inline const char* debugstr_longlong(ULONGLONG ll)
87 static char string[17];
88 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
89 sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
90 else
91 sprintf(string, "%lx", (unsigned long)ll);
92 return string;
95 static char* (__cdecl *p_setlocale)(int, const char*);
96 static int (__cdecl *p__setmbcp)(int);
97 static int (__cdecl *p_isleadbyte)(int);
99 static MSVCRT_long (__cdecl *p__Xtime_diff_to_millis2)(const xtime*, const xtime*);
100 static int (__cdecl *p_xtime_get)(xtime*, int);
101 static _Cvtvec* (__cdecl *p__Getcvt)(_Cvtvec*);
102 static void (CDECL *p__Call_once)(int *once, void (CDECL *func)(void));
103 static void (CDECL *p__Call_onceEx)(int *once, void (CDECL *func)(void*), void *argv);
104 static void (CDECL *p__Do_call)(void *this);
105 static short (__cdecl *p__Dtest)(double *d);
106 static short (__cdecl *p__Dscale)(double *d, int exp);
107 static short (__cdecl *p__FExp)(float *x, float y, int exp);
109 /* filesystem */
110 static ULONGLONG(__cdecl *p_tr2_sys__File_size)(char const*);
111 static ULONGLONG(__cdecl *p_tr2_sys__File_size_wchar)(WCHAR const*);
112 static int (__cdecl *p_tr2_sys__Equivalent)(char const*, char const*);
113 static int (__cdecl *p_tr2_sys__Equivalent_wchar)(WCHAR const*, WCHAR const*);
114 static char* (__cdecl *p_tr2_sys__Current_get)(char *);
115 static WCHAR* (__cdecl *p_tr2_sys__Current_get_wchar)(WCHAR *);
116 static MSVCP_bool (__cdecl *p_tr2_sys__Current_set)(char const*);
117 static MSVCP_bool (__cdecl *p_tr2_sys__Current_set_wchar)(WCHAR const*);
118 static int (__cdecl *p_tr2_sys__Make_dir)(char const*);
119 static int (__cdecl *p_tr2_sys__Make_dir_wchar)(WCHAR const*);
120 static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir)(char const*);
121 static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir_wchar)(WCHAR const*);
122 static int (__cdecl *p_tr2_sys__Copy_file)(char const*, char const*, MSVCP_bool);
123 static int (__cdecl *p_tr2_sys__Copy_file_wchar)(WCHAR const*, WCHAR const*, MSVCP_bool);
124 static int (__cdecl *p_tr2_sys__Rename)(char const*, char const*);
125 static int (__cdecl *p_tr2_sys__Rename_wchar)(WCHAR const*, WCHAR const*);
126 static struct space_info* (__cdecl *p_tr2_sys__Statvfs)(struct space_info*, char const*);
127 static struct space_info* (__cdecl *p_tr2_sys__Statvfs_wchar)(struct space_info*, WCHAR const*);
128 static enum file_type (__cdecl *p_tr2_sys__Stat)(char const*, int *);
129 static enum file_type (__cdecl *p_tr2_sys__Lstat)(char const*, int *);
130 static __int64 (__cdecl *p_tr2_sys__Last_write_time)(char const*);
131 static void (__cdecl *p_tr2_sys__Last_write_time_set)(char const*, __int64);
132 static void* (__cdecl *p_tr2_sys__Open_dir)(char*, char const*, int *, enum file_type*);
133 static char* (__cdecl *p_tr2_sys__Read_dir)(char*, void*, enum file_type*);
134 static void (__cdecl *p_tr2_sys__Close_dir)(void*);
136 /* thrd */
137 typedef struct
139 HANDLE hnd;
140 DWORD id;
141 } _Thrd_t;
143 #define TIMEDELTA 250 /* 250 ms uncertainty allowed */
145 typedef int (__cdecl *_Thrd_start_t)(void*);
147 static int (__cdecl *p__Thrd_equal)(_Thrd_t, _Thrd_t);
148 static int (__cdecl *p__Thrd_lt)(_Thrd_t, _Thrd_t);
149 static void (__cdecl *p__Thrd_sleep)(const xtime*);
150 static _Thrd_t (__cdecl *p__Thrd_current)(void);
151 static int (__cdecl *p__Thrd_create)(_Thrd_t*, _Thrd_start_t, void*);
152 static int (__cdecl *p__Thrd_join)(_Thrd_t, int*);
154 #ifdef __i386__
155 static ULONGLONG (__cdecl *p_i386_Thrd_current)(void);
156 static _Thrd_t __cdecl i386_Thrd_current(void)
158 union {
159 _Thrd_t thr;
160 ULONGLONG ull;
161 } r;
162 r.ull = p_i386_Thrd_current();
163 return r.thr;
165 #endif
167 /* mtx */
168 typedef void *_Mtx_t;
169 static int (__cdecl *p__Mtx_init)(_Mtx_t*, int);
170 static void (__cdecl *p__Mtx_destroy)(_Mtx_t*);
171 static int (__cdecl *p__Mtx_lock)(_Mtx_t*);
172 static int (__cdecl *p__Mtx_unlock)(_Mtx_t*);
174 /* cnd */
175 typedef void *_Cnd_t;
177 static int (__cdecl *p__Cnd_init)(_Cnd_t*);
178 static void (__cdecl *p__Cnd_destroy)(_Cnd_t*);
179 static int (__cdecl *p__Cnd_wait)(_Cnd_t*, _Mtx_t*);
180 static int (__cdecl *p__Cnd_timedwait)(_Cnd_t*, _Mtx_t*, const xtime*);
181 static int (__cdecl *p__Cnd_broadcast)(_Cnd_t*);
182 static int (__cdecl *p__Cnd_signal)(_Cnd_t*);
185 static HMODULE msvcp;
186 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
187 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
188 static BOOL init(void)
190 HANDLE msvcr;
192 msvcp = LoadLibraryA("msvcp120.dll");
193 if(!msvcp)
195 win_skip("msvcp120.dll not installed\n");
196 return FALSE;
199 SET(p__Xtime_diff_to_millis2,
200 "_Xtime_diff_to_millis2");
201 SET(p_xtime_get,
202 "xtime_get");
203 SET(p__Getcvt,
204 "_Getcvt");
205 SET(p__Call_once,
206 "_Call_once");
207 SET(p__Call_onceEx,
208 "_Call_onceEx");
209 SET(p__Do_call,
210 "_Do_call");
211 SET(p__Dtest,
212 "_Dtest");
213 SET(p__Dscale,
214 "_Dscale");
215 SET(p__FExp,
216 "_FExp");
217 if(sizeof(void*) == 8) { /* 64-bit initialization */
218 SET(p_tr2_sys__File_size,
219 "?_File_size@sys@tr2@std@@YA_KPEBD@Z");
220 SET(p_tr2_sys__File_size_wchar,
221 "?_File_size@sys@tr2@std@@YA_KPEB_W@Z");
222 SET(p_tr2_sys__Equivalent,
223 "?_Equivalent@sys@tr2@std@@YAHPEBD0@Z");
224 SET(p_tr2_sys__Equivalent_wchar,
225 "?_Equivalent@sys@tr2@std@@YAHPEB_W0@Z");
226 SET(p_tr2_sys__Current_get,
227 "?_Current_get@sys@tr2@std@@YAPEADAEAY0BAE@D@Z");
228 SET(p_tr2_sys__Current_get_wchar,
229 "?_Current_get@sys@tr2@std@@YAPEA_WAEAY0BAE@_W@Z");
230 SET(p_tr2_sys__Current_set,
231 "?_Current_set@sys@tr2@std@@YA_NPEBD@Z");
232 SET(p_tr2_sys__Current_set_wchar,
233 "?_Current_set@sys@tr2@std@@YA_NPEB_W@Z");
234 SET(p_tr2_sys__Make_dir,
235 "?_Make_dir@sys@tr2@std@@YAHPEBD@Z");
236 SET(p_tr2_sys__Make_dir_wchar,
237 "?_Make_dir@sys@tr2@std@@YAHPEB_W@Z");
238 SET(p_tr2_sys__Remove_dir,
239 "?_Remove_dir@sys@tr2@std@@YA_NPEBD@Z");
240 SET(p_tr2_sys__Remove_dir_wchar,
241 "?_Remove_dir@sys@tr2@std@@YA_NPEB_W@Z");
242 SET(p_tr2_sys__Copy_file,
243 "?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z");
244 SET(p_tr2_sys__Copy_file_wchar,
245 "?_Copy_file@sys@tr2@std@@YAHPEB_W0_N@Z");
246 SET(p_tr2_sys__Rename,
247 "?_Rename@sys@tr2@std@@YAHPEBD0@Z");
248 SET(p_tr2_sys__Rename_wchar,
249 "?_Rename@sys@tr2@std@@YAHPEB_W0@Z");
250 SET(p_tr2_sys__Statvfs,
251 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PEBD@Z");
252 SET(p_tr2_sys__Statvfs_wchar,
253 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PEB_W@Z");
254 SET(p_tr2_sys__Stat,
255 "?_Stat@sys@tr2@std@@YA?AW4file_type@123@PEBDAEAH@Z");
256 SET(p_tr2_sys__Lstat,
257 "?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PEBDAEAH@Z");
258 SET(p_tr2_sys__Last_write_time,
259 "?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z");
260 SET(p_tr2_sys__Last_write_time_set,
261 "?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z");
262 SET(p_tr2_sys__Open_dir,
263 "?_Open_dir@sys@tr2@std@@YAPEAXAEAY0BAE@DPEBDAEAHAEAW4file_type@123@@Z");
264 SET(p_tr2_sys__Read_dir,
265 "?_Read_dir@sys@tr2@std@@YAPEADAEAY0BAE@DPEAXAEAW4file_type@123@@Z");
266 SET(p_tr2_sys__Close_dir,
267 "?_Close_dir@sys@tr2@std@@YAXPEAX@Z");
268 SET(p__Thrd_current,
269 "_Thrd_current");
270 } else {
271 SET(p_tr2_sys__File_size,
272 "?_File_size@sys@tr2@std@@YA_KPBD@Z");
273 SET(p_tr2_sys__File_size_wchar,
274 "?_File_size@sys@tr2@std@@YA_KPB_W@Z");
275 SET(p_tr2_sys__Equivalent,
276 "?_Equivalent@sys@tr2@std@@YAHPBD0@Z");
277 SET(p_tr2_sys__Equivalent_wchar,
278 "?_Equivalent@sys@tr2@std@@YAHPB_W0@Z");
279 SET(p_tr2_sys__Current_get,
280 "?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z");
281 SET(p_tr2_sys__Current_get_wchar,
282 "?_Current_get@sys@tr2@std@@YAPA_WAAY0BAE@_W@Z");
283 SET(p_tr2_sys__Current_set,
284 "?_Current_set@sys@tr2@std@@YA_NPBD@Z");
285 SET(p_tr2_sys__Current_set_wchar,
286 "?_Current_set@sys@tr2@std@@YA_NPB_W@Z");
287 SET(p_tr2_sys__Make_dir,
288 "?_Make_dir@sys@tr2@std@@YAHPBD@Z");
289 SET(p_tr2_sys__Make_dir_wchar,
290 "?_Make_dir@sys@tr2@std@@YAHPB_W@Z");
291 SET(p_tr2_sys__Remove_dir,
292 "?_Remove_dir@sys@tr2@std@@YA_NPBD@Z");
293 SET(p_tr2_sys__Remove_dir_wchar,
294 "?_Remove_dir@sys@tr2@std@@YA_NPB_W@Z");
295 SET(p_tr2_sys__Copy_file,
296 "?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z");
297 SET(p_tr2_sys__Copy_file_wchar,
298 "?_Copy_file@sys@tr2@std@@YAHPB_W0_N@Z");
299 SET(p_tr2_sys__Rename,
300 "?_Rename@sys@tr2@std@@YAHPBD0@Z");
301 SET(p_tr2_sys__Rename_wchar,
302 "?_Rename@sys@tr2@std@@YAHPB_W0@Z");
303 SET(p_tr2_sys__Statvfs,
304 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PBD@Z");
305 SET(p_tr2_sys__Statvfs_wchar,
306 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PB_W@Z");
307 SET(p_tr2_sys__Stat,
308 "?_Stat@sys@tr2@std@@YA?AW4file_type@123@PBDAAH@Z");
309 SET(p_tr2_sys__Lstat,
310 "?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PBDAAH@Z");
311 SET(p_tr2_sys__Last_write_time,
312 "?_Last_write_time@sys@tr2@std@@YA_JPBD@Z");
313 SET(p_tr2_sys__Last_write_time_set,
314 "?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z");
315 SET(p_tr2_sys__Open_dir,
316 "?_Open_dir@sys@tr2@std@@YAPAXAAY0BAE@DPBDAAHAAW4file_type@123@@Z");
317 SET(p_tr2_sys__Read_dir,
318 "?_Read_dir@sys@tr2@std@@YAPADAAY0BAE@DPAXAAW4file_type@123@@Z");
319 SET(p_tr2_sys__Close_dir,
320 "?_Close_dir@sys@tr2@std@@YAXPAX@Z");
321 #ifdef __i386__
322 SET(p_i386_Thrd_current,
323 "_Thrd_current");
324 p__Thrd_current = i386_Thrd_current;
325 #else
326 SET(p__Thrd_current,
327 "_Thrd_current");
328 #endif
330 SET(p__Thrd_equal,
331 "_Thrd_equal");
332 SET(p__Thrd_lt,
333 "_Thrd_lt");
334 SET(p__Thrd_sleep,
335 "_Thrd_sleep");
336 SET(p__Thrd_create,
337 "_Thrd_create");
338 SET(p__Thrd_join,
339 "_Thrd_join");
341 SET(p__Mtx_init,
342 "_Mtx_init");
343 SET(p__Mtx_destroy,
344 "_Mtx_destroy");
345 SET(p__Mtx_lock,
346 "_Mtx_lock");
347 SET(p__Mtx_unlock,
348 "_Mtx_unlock");
350 SET(p__Cnd_init,
351 "_Cnd_init");
352 SET(p__Cnd_destroy,
353 "_Cnd_destroy");
354 SET(p__Cnd_wait,
355 "_Cnd_wait");
356 SET(p__Cnd_timedwait,
357 "_Cnd_timedwait");
358 SET(p__Cnd_broadcast,
359 "_Cnd_broadcast");
360 SET(p__Cnd_signal,
361 "_Cnd_signal");
363 msvcr = GetModuleHandleA("msvcr120.dll");
364 p_setlocale = (void*)GetProcAddress(msvcr, "setlocale");
365 p__setmbcp = (void*)GetProcAddress(msvcr, "_setmbcp");
366 p_isleadbyte = (void*)GetProcAddress(msvcr, "isleadbyte");
367 return TRUE;
370 static void test__Xtime_diff_to_millis2(void)
372 struct {
373 __time64_t sec_before;
374 MSVCRT_long nsec_before;
375 __time64_t sec_after;
376 MSVCRT_long nsec_after;
377 MSVCRT_long expect;
378 } tests[] = {
379 {1, 0, 2, 0, 1000},
380 {0, 1000000000, 0, 2000000000, 1000},
381 {1, 100000000, 2, 100000000, 1000},
382 {1, 100000000, 1, 200000000, 100},
383 {0, 0, 0, 1000000000, 1000},
384 {0, 0, 0, 1200000000, 1200},
385 {0, 0, 0, 1230000000, 1230},
386 {0, 0, 0, 1234000000, 1234},
387 {0, 0, 0, 1234100000, 1235},
388 {0, 0, 0, 1234900000, 1235},
389 {0, 0, 0, 1234010000, 1235},
390 {0, 0, 0, 1234090000, 1235},
391 {0, 0, 0, 1234000001, 1235},
392 {0, 0, 0, 1234000009, 1235},
393 {0, 0, -1, 0, 0},
394 {0, 0, 0, -10000000, 0},
395 {0, 0, -1, -100000000, 0},
396 {-1, 0, 0, 0, 1000},
397 {0, -100000000, 0, 0, 100},
398 {-1, -100000000, 0, 0, 1100},
399 {0, 0, -1, 2000000000, 1000},
400 {0, 0, -2, 2000000000, 0},
401 {0, 0, -2, 2100000000, 100}
403 int i;
404 MSVCRT_long ret;
405 xtime t1, t2;
407 for(i = 0; i < sizeof(tests) / sizeof(tests[0]); ++ i)
409 t1.sec = tests[i].sec_before;
410 t1.nsec = tests[i].nsec_before;
411 t2.sec = tests[i].sec_after;
412 t2.nsec = tests[i].nsec_after;
413 ret = p__Xtime_diff_to_millis2(&t2, &t1);
414 ok(ret == tests[i].expect,
415 "_Xtime_diff_to_millis2(): test: %d expect: %d, got: %d\n",
416 i, tests[i].expect, ret);
420 static void test_xtime_get(void)
422 static const MSVCRT_long tests[] = {1, 50, 100, 200, 500};
423 MSVCRT_long diff;
424 xtime before, after;
425 int i;
427 for(i = 0; i < sizeof(tests) / sizeof(tests[0]); i ++)
429 p_xtime_get(&before, 1);
430 Sleep(tests[i]);
431 p_xtime_get(&after, 1);
433 diff = p__Xtime_diff_to_millis2(&after, &before);
435 ok(diff >= tests[i],
436 "xtime_get() not functioning correctly, test: %d, expect: ge %d, got: %d\n",
437 i, tests[i], diff);
440 /* Test parameter and return value */
441 before.sec = 0xdeadbeef, before.nsec = 0xdeadbeef;
442 i = p_xtime_get(&before, 0);
443 ok(i == 0, "expect xtime_get() to return 0, got: %d\n", i);
444 ok(before.sec == 0xdeadbeef && before.nsec == 0xdeadbeef,
445 "xtime_get() shouldn't have modified the xtime struct with the given option\n");
447 before.sec = 0xdeadbeef, before.nsec = 0xdeadbeef;
448 i = p_xtime_get(&before, 1);
449 ok(i == 1, "expect xtime_get() to return 1, got: %d\n", i);
450 ok(before.sec != 0xdeadbeef && before.nsec != 0xdeadbeef,
451 "xtime_get() should have modified the xtime struct with the given option\n");
454 static void test__Getcvt(void)
456 _Cvtvec cvtvec;
457 int i;
459 p__Getcvt(&cvtvec);
460 ok(cvtvec.page == 0, "cvtvec.page = %d\n", cvtvec.page);
461 ok(cvtvec.mb_max == 1, "cvtvec.mb_max = %d\n", cvtvec.mb_max);
462 todo_wine ok(cvtvec.unk == 1, "cvtvec.unk = %d\n", cvtvec.unk);
463 for(i=0; i<32; i++)
464 ok(cvtvec.isleadbyte[i] == 0, "cvtvec.isleadbyte[%d] = %x\n", i, cvtvec.isleadbyte[i]);
466 if(!p_setlocale(LC_ALL, ".936")) {
467 win_skip("_Getcvt tests\n");
468 return;
470 p__Getcvt(&cvtvec);
471 ok(cvtvec.page == 936, "cvtvec.page = %d\n", cvtvec.page);
472 ok(cvtvec.mb_max == 2, "cvtvec.mb_max = %d\n", cvtvec.mb_max);
473 ok(cvtvec.unk == 0, "cvtvec.unk = %d\n", cvtvec.unk);
474 for(i=0; i<32; i++)
475 ok(cvtvec.isleadbyte[i] == 0, "cvtvec.isleadbyte[%d] = %x\n", i, cvtvec.isleadbyte[i]);
477 p__setmbcp(936);
478 p__Getcvt(&cvtvec);
479 ok(cvtvec.page == 936, "cvtvec.page = %d\n", cvtvec.page);
480 ok(cvtvec.mb_max == 2, "cvtvec.mb_max = %d\n", cvtvec.mb_max);
481 ok(cvtvec.unk == 0, "cvtvec.unk = %d\n", cvtvec.unk);
482 for(i=0; i<32; i++) {
483 BYTE b = 0;
484 int j;
486 for(j=0; j<8; j++)
487 b |= (p_isleadbyte(i*8+j) ? 1 : 0) << j;
488 ok(cvtvec.isleadbyte[i] ==b, "cvtvec.isleadbyte[%d] = %x (%x)\n", i, cvtvec.isleadbyte[i], b);
492 static int cnt;
493 static int once;
495 static void __cdecl call_once_func(void)
497 ok(!once, "once != 0\n");
498 cnt += 0x10000;
501 static void __cdecl call_once_ex_func(void *arg)
503 int *i = arg;
505 ok(!once, "once != 0\n");
506 (*i)++;
509 static DWORD WINAPI call_once_thread(void *arg)
511 p__Call_once(&once, call_once_func);
512 return 0;
515 static DWORD WINAPI call_once_ex_thread(void *arg)
517 p__Call_onceEx(&once, call_once_ex_func, &cnt);
518 return 0;
521 static void test__Call_once(void)
523 HANDLE h[4];
524 int i;
526 for(i=0; i<4; i++)
527 h[i] = CreateThread(NULL, 0, call_once_thread, &once, 0, NULL);
528 ok(WaitForMultipleObjects(4, h, TRUE, INFINITE) == WAIT_OBJECT_0,
529 "error waiting for all threads to finish\n");
530 ok(cnt == 0x10000, "cnt = %x\n", cnt);
531 ok(once == 1, "once = %x\n", once);
533 once = cnt = 0;
534 for(i=0; i<4; i++)
535 h[i] = CreateThread(NULL, 0, call_once_ex_thread, &once, 0, NULL);
536 ok(WaitForMultipleObjects(4, h, TRUE, INFINITE) == WAIT_OBJECT_0,
537 "error waiting for all threads to finish\n");
538 ok(cnt == 1, "cnt = %x\n", cnt);
539 ok(once == 1, "once = %x\n", once);
542 static void **vtbl_func0;
543 #ifdef __i386__
544 /* TODO: this should be a __thiscall function */
545 static void __stdcall thiscall_func(void)
547 cnt = 1;
549 #else
550 static void __cdecl thiscall_func(void *this)
552 ok(this == &vtbl_func0, "incorrect this value\n");
553 cnt = 1;
555 #endif
557 static void test__Do_call(void)
559 void *pfunc = thiscall_func;
561 cnt = 0;
562 vtbl_func0 = &pfunc;
563 p__Do_call(&vtbl_func0);
564 ok(cnt == 1, "func was not called\n");
567 static void test__Dtest(void)
569 double d;
570 short ret;
572 d = 0;
573 ret = p__Dtest(&d);
574 ok(ret == FP_ZERO, "_Dtest(0) returned %x\n", ret);
576 d = 1;
577 ret = p__Dtest(&d);
578 ok(ret == FP_NORMAL, "_Dtest(1) returned %x\n", ret);
580 d = -1;
581 ret = p__Dtest(&d);
582 ok(ret == FP_NORMAL, "_Dtest(-1) returned %x\n", ret);
584 d = INFINITY;
585 ret = p__Dtest(&d);
586 ok(ret == FP_INFINITE, "_Dtest(INF) returned %x\n", ret);
588 d = NAN;
589 ret = p__Dtest(&d);
590 ok(ret == FP_NAN, "_Dtest(NAN) returned %x\n", ret);
593 static void test__Dscale(void)
595 double d;
596 short ret;
598 d = 0;
599 ret = p__Dscale(&d, 0);
600 ok(d == 0, "d = %f\n", d);
601 ok(ret == FP_ZERO, "ret = %x\n", ret);
603 d = 0;
604 ret = p__Dscale(&d, 1);
605 ok(d == 0, "d = %f\n", d);
606 ok(ret == FP_ZERO, "ret = %x\n", ret);
608 d = 0;
609 ret = p__Dscale(&d, -1);
610 ok(d == 0, "d = %f\n", d);
611 ok(ret == FP_ZERO, "ret = %x\n", ret);
613 d = 1;
614 ret = p__Dscale(&d, 0);
615 ok(d == 1, "d = %f\n", d);
616 ok(ret == FP_NORMAL, "ret = %x\n", ret);
618 d = 1;
619 ret = p__Dscale(&d, 1);
620 ok(d == 2, "d = %f\n", d);
621 ok(ret == FP_NORMAL, "ret = %x\n", ret);
623 d = 1;
624 ret = p__Dscale(&d, -1);
625 ok(d == 0.5, "d = %f\n", d);
626 ok(ret == FP_NORMAL, "ret = %x\n", ret);
628 d = 1;
629 ret = p__Dscale(&d, -99999);
630 ok(d == 0, "d = %f\n", d);
631 ok(ret == FP_ZERO, "ret = %x\n", ret);
633 d = 1;
634 ret = p__Dscale(&d, 999999);
635 ok(d == INFINITY, "d = %f\n", d);
636 ok(ret == FP_INFINITE, "ret = %x\n", ret);
638 d = NAN;
639 ret = p__Dscale(&d, 1);
640 ok(ret == FP_NAN, "ret = %x\n", ret);
643 static void test__FExp(void)
645 float d;
646 short ret;
648 d = 0;
649 ret = p__FExp(&d, 0, 0);
650 ok(d == 0, "d = %f\n", d);
651 ok(ret == FP_ZERO, "ret = %x\n", ret);
653 d = 0;
654 ret = p__FExp(&d, 1, 0);
655 ok(d == 1.0, "d = %f\n", d);
656 ok(ret == FP_NORMAL, "ret = %x\n", ret);
658 d = 0;
659 ret = p__FExp(&d, 1, 1);
660 ok(d == 2.0, "d = %f\n", d);
661 ok(ret == FP_NORMAL, "ret = %x\n", ret);
663 d = 0;
664 ret = p__FExp(&d, 1, 2);
665 ok(d == 4.0, "d = %f\n", d);
666 ok(ret == FP_NORMAL, "ret = %x\n", ret);
668 d = 0;
669 ret = p__FExp(&d, 10, 0);
670 ok(d == 10.0, "d = %f\n", d);
671 ok(ret == FP_NORMAL, "ret = %x\n", ret);
673 d = 1;
674 ret = p__FExp(&d, 0, 0);
675 ok(d == 0, "d = %f\n", d);
676 ok(ret == FP_ZERO, "ret = %x\n", ret);
678 d = 1;
679 ret = p__FExp(&d, 1, 0);
680 ok(compare_float(d, 2.7182817, 4), "d = %f\n", d);
681 ok(ret == FP_NORMAL, "ret = %x\n", ret);
683 d = 9e20;
684 ret = p__FExp(&d, 0, 0);
685 ok(d == 0, "d = %f\n", d);
686 ok(ret == FP_ZERO, "ret = %x\n", ret);
688 d = 90;
689 ret = p__FExp(&d, 1, 0);
690 ok(ret == FP_INFINITE, "ret = %x\n", ret);
692 d = 90;
693 ret = p__FExp(&d, 1, -50);
694 ok(compare_float(d, 1.0839359e+024, 4), "d = %g\n", d);
695 ok(ret == FP_NORMAL, "ret = %x\n", ret);
698 static void test_tr2_sys__File_size(void)
700 ULONGLONG val;
701 HANDLE file;
702 LARGE_INTEGER file_size;
703 WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
704 CreateDirectoryA("tr2_test_dir", NULL);
706 file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
707 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
708 file_size.QuadPart = 7;
709 ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
710 ok(SetEndOfFile(file), "SetEndOfFile failed\n");
711 CloseHandle(file);
712 val = p_tr2_sys__File_size("tr2_test_dir/f1");
713 ok(val == 7, "file_size is %s\n", debugstr_longlong(val));
714 val = p_tr2_sys__File_size_wchar(testW);
715 ok(val == 7, "file_size is %s\n", debugstr_longlong(val));
717 file = CreateFileA("tr2_test_dir/f2", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
718 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
719 CloseHandle(file);
720 val = p_tr2_sys__File_size("tr2_test_dir/f2");
721 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
723 val = p_tr2_sys__File_size("tr2_test_dir");
724 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
726 errno = 0xdeadbeef;
727 val = p_tr2_sys__File_size("tr2_test_dir/not_exists_file");
728 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
729 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
731 errno = 0xdeadbeef;
732 val = p_tr2_sys__File_size(NULL);
733 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
734 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
736 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
737 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
738 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
741 static void test_tr2_sys__Equivalent(void)
743 int val, i;
744 HANDLE file;
745 char temp_path[MAX_PATH], current_path[MAX_PATH];
746 WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
747 WCHAR testW2[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','2',0};
748 struct {
749 char const *path1;
750 char const *path2;
751 int equivalent;
752 } tests[] = {
753 { NULL, NULL, -1 },
754 { NULL, "f1", -1 },
755 { "f1", NULL, -1 },
756 { "f1", "tr2_test_dir", -1 },
757 { "tr2_test_dir", "f1", -1 },
758 { "tr2_test_dir", "tr2_test_dir", -1 },
759 { "tr2_test_dir/./f1", "tr2_test_dir/f2", 0 },
760 { "tr2_test_dir/f1" , "tr2_test_dir/f1", 1 },
761 { "not_exists_file" , "tr2_test_dir/f1", 0 },
762 { "tr2_test_dir\\f1" , "tr2_test_dir/./f1", 1 },
763 { "not_exists_file" , "not_exists_file", -1 },
764 { "tr2_test_dir/f1" , "not_exists_file", 0 },
765 { "tr2_test_dir/../tr2_test_dir/f1", "tr2_test_dir/f1", 1 }
768 memset(current_path, 0, MAX_PATH);
769 GetCurrentDirectoryA(MAX_PATH, current_path);
770 memset(temp_path, 0, MAX_PATH);
771 GetTempPathA(MAX_PATH, temp_path);
772 ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
773 CreateDirectoryA("tr2_test_dir", NULL);
775 file = CreateFileA("tr2_test_dir/f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
776 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
777 CloseHandle(file);
778 file = CreateFileA("tr2_test_dir/f2", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
779 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
780 CloseHandle(file);
782 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
783 errno = 0xdeadbeef;
784 val = p_tr2_sys__Equivalent(tests[i].path1, tests[i].path2);
785 ok(tests[i].equivalent == val, "tr2_sys__Equivalent(): test %d expect: %d, got %d\n", i+1, tests[i].equivalent, val);
786 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
789 val = p_tr2_sys__Equivalent_wchar(testW, testW);
790 ok(val == 1, "tr2_sys__Equivalent(): expect: 1, got %d\n", val);
791 val = p_tr2_sys__Equivalent_wchar(testW, testW2);
792 ok(val == 0, "tr2_sys__Equivalent(): expect: 0, got %d\n", val);
794 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
795 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
796 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
797 ok(SetCurrentDirectoryA(current_path), "SetCurrentDirectoryA failed\n");
800 static void test_tr2_sys__Current_get(void)
802 char temp_path[MAX_PATH], current_path[MAX_PATH], origin_path[MAX_PATH];
803 char *temp;
804 WCHAR temp_path_wchar[MAX_PATH], current_path_wchar[MAX_PATH];
805 WCHAR *temp_wchar;
806 memset(origin_path, 0, MAX_PATH);
807 GetCurrentDirectoryA(MAX_PATH, origin_path);
808 memset(temp_path, 0, MAX_PATH);
809 GetTempPathA(MAX_PATH, temp_path);
811 ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
812 memset(current_path, 0, MAX_PATH);
813 temp = p_tr2_sys__Current_get(current_path);
814 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
815 temp[strlen(temp)] = '\\';
816 ok(!strcmp(temp_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path, current_path);
818 GetTempPathW(MAX_PATH, temp_path_wchar);
819 ok(SetCurrentDirectoryW(temp_path_wchar), "SetCurrentDirectoryW to temp_path_wchar failed\n");
820 memset(current_path_wchar, 0, MAX_PATH);
821 temp_wchar = p_tr2_sys__Current_get_wchar(current_path_wchar);
822 ok(temp_wchar == current_path_wchar, "p_tr2_sys__Current_get_wchar returned different buffer\n");
823 temp_wchar[wcslen(temp_wchar)] = '\\';
824 ok(!wcscmp(temp_path_wchar, current_path_wchar), "test_tr2_sys__Current_get(): expect: %s, got %s\n", wine_dbgstr_w(temp_path_wchar), wine_dbgstr_w(current_path_wchar));
826 ok(SetCurrentDirectoryA(origin_path), "SetCurrentDirectoryA to origin_path failed\n");
827 memset(current_path, 0, MAX_PATH);
828 temp = p_tr2_sys__Current_get(current_path);
829 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
830 ok(!strcmp(origin_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", origin_path, current_path);
833 static void test_tr2_sys__Current_set(void)
835 char temp_path[MAX_PATH], current_path[MAX_PATH], origin_path[MAX_PATH];
836 char *temp;
837 WCHAR testW[] = {'.','/',0};
838 memset(temp_path, 0, MAX_PATH);
839 GetTempPathA(MAX_PATH, temp_path);
840 memset(origin_path, 0, MAX_PATH);
841 GetCurrentDirectoryA(MAX_PATH, origin_path);
842 temp = p_tr2_sys__Current_get(origin_path);
843 ok(temp == origin_path, "p_tr2_sys__Current_get returned different buffer\n");
845 ok(p_tr2_sys__Current_set(temp_path), "p_tr2_sys__Current_set to temp_path failed\n");
846 memset(current_path, 0, MAX_PATH);
847 temp = p_tr2_sys__Current_get(current_path);
848 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
849 temp[strlen(temp)] = '\\';
850 ok(!strcmp(temp_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path, current_path);
852 ok(p_tr2_sys__Current_set_wchar(testW), "p_tr2_sys__Current_set_wchar to temp_path failed\n");
853 memset(current_path, 0, MAX_PATH);
854 temp = p_tr2_sys__Current_get(current_path);
855 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
856 temp[strlen(temp)] = '\\';
857 ok(!strcmp(temp_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path, current_path);
859 errno = 0xdeadbeef;
860 ok(!p_tr2_sys__Current_set("not_exisist_dir"), "p_tr2_sys__Current_set to not_exist_dir succeed\n");
861 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
863 errno = 0xdeadbeef;
864 ok(!p_tr2_sys__Current_set("??invalid_name>>"), "p_tr2_sys__Current_set to ??invalid_name>> succeed\n");
865 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
867 ok(p_tr2_sys__Current_set(origin_path), "p_tr2_sys__Current_set to origin_path failed\n");
868 memset(current_path, 0, MAX_PATH);
869 temp = p_tr2_sys__Current_get(current_path);
870 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
871 ok(!strcmp(origin_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", origin_path, current_path);
874 static void test_tr2_sys__Make_dir(void)
876 int ret, i;
877 WCHAR testW[] = {'w','d',0};
878 struct {
879 char const *path;
880 int val;
881 } tests[] = {
882 { "tr2_test_dir", 1 },
883 { "tr2_test_dir", 0 },
884 { NULL, -1 },
885 { "??invalid_name>>", -1 }
888 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
889 errno = 0xdeadbeef;
890 ret = p_tr2_sys__Make_dir(tests[i].path);
891 ok(ret == tests[i].val, "tr2_sys__Make_dir(): test %d expect: %d, got %d\n", i+1, tests[i].val, ret);
892 ok(errno == 0xdeadbeef, "tr2_sys__Make_dir(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
894 ret = p_tr2_sys__Make_dir_wchar(testW);
895 ok(ret == 1, "tr2_sys__Make_dir(): expect: 1, got %d\n", ret);
897 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
898 ok(p_tr2_sys__Remove_dir_wchar(testW), "expect wd to exist\n");
901 static void test_tr2_sys__Remove_dir(void)
903 MSVCP_bool ret;
904 int i;
905 struct {
906 char const *path;
907 MSVCP_bool val;
908 } tests[] = {
909 { "tr2_test_dir", TRUE },
910 { "tr2_test_dir", FALSE },
911 { NULL, FALSE },
912 { "??invalid_name>>", FALSE }
915 ok(p_tr2_sys__Make_dir("tr2_test_dir"), "tr2_sys__Make_dir() failed\n");
917 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
918 errno = 0xdeadbeef;
919 ret = p_tr2_sys__Remove_dir(tests[i].path);
920 ok(ret == tests[i].val, "test_tr2_sys__Remove_dir(): test %d expect: %d, got %d\n", i+1, tests[i].val, ret);
921 ok(errno == 0xdeadbeef, "test_tr2_sys__Remove_dir(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
925 static void test_tr2_sys__Copy_file(void)
927 HANDLE file;
928 int ret, i;
929 LARGE_INTEGER file_size;
930 WCHAR testW[] = {'f','1',0}, testW2[] = {'f','w',0};
931 struct {
932 char const *source;
933 char const *dest;
934 MSVCP_bool fail_if_exists;
935 int last_error;
936 int last_error2;
937 MSVCP_bool is_todo;
938 } tests[] = {
939 { "f1", "f1_copy", TRUE, ERROR_SUCCESS, ERROR_SUCCESS, FALSE },
940 { "f1", "tr2_test_dir\\f1_copy", TRUE, ERROR_SUCCESS, ERROR_SUCCESS, FALSE },
941 { "f1", "tr2_test_dir\\f1_copy", TRUE, ERROR_FILE_EXISTS, ERROR_FILE_EXISTS, FALSE },
942 { "f1", "tr2_test_dir\\f1_copy", FALSE, ERROR_SUCCESS, ERROR_SUCCESS, FALSE },
943 { "tr2_test_dir", "f1", TRUE, ERROR_ACCESS_DENIED, ERROR_ACCESS_DENIED, FALSE },
944 { "tr2_test_dir", "tr2_test_dir_copy", TRUE, ERROR_ACCESS_DENIED, ERROR_ACCESS_DENIED, FALSE },
945 { NULL, "f1", TRUE, ERROR_INVALID_PARAMETER, ERROR_INVALID_PARAMETER, TRUE },
946 { "f1", NULL, TRUE, ERROR_INVALID_PARAMETER, ERROR_INVALID_PARAMETER, TRUE },
947 { "not_exist", "tr2_test_dir", TRUE, ERROR_FILE_NOT_FOUND, ERROR_FILE_NOT_FOUND, FALSE },
948 { "f1", "not_exist_dir\\f1_copy", TRUE, ERROR_PATH_NOT_FOUND, ERROR_FILE_NOT_FOUND, FALSE },
949 { "f1", "tr2_test_dir", TRUE, ERROR_ACCESS_DENIED, ERROR_FILE_EXISTS, FALSE }
952 ret = p_tr2_sys__Make_dir("tr2_test_dir");
953 ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
954 file = CreateFileA("f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
955 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
956 file_size.QuadPart = 7;
957 ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
958 ok(SetEndOfFile(file), "SetEndOfFile failed\n");
959 CloseHandle(file);
961 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
962 errno = 0xdeadbeef;
963 ret = p_tr2_sys__Copy_file(tests[i].source, tests[i].dest, tests[i].fail_if_exists);
964 if(tests[i].is_todo)
965 todo_wine ok(ret == tests[i].last_error || ret == tests[i].last_error2,
966 "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n",
967 i+1, tests[i].last_error, ret);
968 else
969 ok(ret == tests[i].last_error || ret == tests[i].last_error2,
970 "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n",
971 i+1, tests[i].last_error, ret);
972 ok(errno == 0xdeadbeef, "test_tr2_sys__Copy_file(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
973 if(ret == ERROR_SUCCESS)
974 ok(p_tr2_sys__File_size(tests[i].source) == p_tr2_sys__File_size(tests[i].dest),
975 "test_tr2_sys__Copy_file(): test %d failed, two files' size are not equal\n", i+1);
977 ret = p_tr2_sys__Copy_file_wchar(testW, testW2, TRUE);
978 ok(ret == ERROR_SUCCESS, "test_tr2_sys__Copy_file_wchar() expect ERROR_SUCCESS, got %d\n", ret);
980 ok(DeleteFileA("f1"), "expect f1 to exist\n");
981 ok(DeleteFileW(testW2), "expect fw to exist\n");
982 ok(DeleteFileA("f1_copy"), "expect f1_copy to exist\n");
983 ok(DeleteFileA("tr2_test_dir/f1_copy"), "expect tr2_test_dir/f1 to exist\n");
984 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
985 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
988 static void test_tr2_sys__Rename(void)
990 int ret, i;
991 HANDLE file, h1, h2;
992 BY_HANDLE_FILE_INFORMATION info1, info2;
993 char temp_path[MAX_PATH], current_path[MAX_PATH];
994 LARGE_INTEGER file_size;
995 WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
996 WCHAR testW2[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','w',0};
997 struct {
998 char const *old_path;
999 char const *new_path;
1000 int val;
1001 } tests[] = {
1002 { "tr2_test_dir\\f1", "tr2_test_dir\\f1_rename", ERROR_SUCCESS },
1003 { "tr2_test_dir\\f1", NULL, ERROR_INVALID_PARAMETER },
1004 { "tr2_test_dir\\f1", "tr2_test_dir\\f1_rename", ERROR_FILE_NOT_FOUND },
1005 { NULL, "tr2_test_dir\\NULL_rename", ERROR_INVALID_PARAMETER },
1006 { "tr2_test_dir\\f1_rename", "tr2_test_dir\\??invalid_name>>", ERROR_INVALID_NAME },
1007 { "tr2_test_dir\\not_exist_file", "tr2_test_dir\\not_exist_rename", ERROR_FILE_NOT_FOUND }
1010 memset(current_path, 0, MAX_PATH);
1011 GetCurrentDirectoryA(MAX_PATH, current_path);
1012 memset(temp_path, 0, MAX_PATH);
1013 GetTempPathA(MAX_PATH, temp_path);
1014 ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
1015 ret = p_tr2_sys__Make_dir("tr2_test_dir");
1017 ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
1018 file = CreateFileA("tr2_test_dir\\f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1019 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1020 CloseHandle(file);
1022 ret = p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1");
1023 todo_wine ok(ERROR_SUCCESS == ret, "test_tr2_sys__Rename(): expect: ERROR_SUCCESS, got %d\n", ret);
1024 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1025 errno = 0xdeadbeef;
1026 if(tests[i].val == ERROR_SUCCESS) {
1027 h1 = CreateFileA(tests[i].old_path, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
1028 NULL, OPEN_EXISTING, 0, 0);
1029 ok(h1 != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1030 ok(GetFileInformationByHandle(h1, &info1), "GetFileInformationByHandle failed\n");
1031 CloseHandle(h1);
1033 SetLastError(0xdeadbeef);
1034 ret = p_tr2_sys__Rename(tests[i].old_path, tests[i].new_path);
1035 ok(ret == tests[i].val, "test_tr2_sys__Rename(): test %d expect: %d, got %d\n", i+1, tests[i].val, ret);
1036 ok(errno == 0xdeadbeef, "test_tr2_sys__Rename(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
1037 if(ret == ERROR_SUCCESS) {
1038 h2 = CreateFileA(tests[i].new_path, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
1039 NULL, OPEN_EXISTING, 0, 0);
1040 ok(h2 != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1041 ok(GetFileInformationByHandle(h2, &info2), "GetFileInformationByHandle failed\n");
1042 CloseHandle(h2);
1043 ok(info1.nFileIndexHigh == info2.nFileIndexHigh
1044 && info1.nFileIndexLow == info2.nFileIndexLow,
1045 "test_tr2_sys__Rename(): test %d expect two files equivalent\n", i+1);
1049 file = CreateFileA("tr2_test_dir\\f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1050 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1051 file_size.QuadPart = 7;
1052 ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
1053 ok(SetEndOfFile(file), "SetEndOfFile failed\n");
1054 CloseHandle(file);
1055 ret = p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1_rename");
1056 ok(ret == ERROR_ALREADY_EXISTS, "test_tr2_sys__Rename(): expect: ERROR_ALREADY_EXISTS, got %d\n", ret);
1057 ok(p_tr2_sys__File_size("tr2_test_dir\\f1") == 7, "test_tr2_sys__Rename(): expect: 7, got %s\n", debugstr_longlong(p_tr2_sys__File_size("tr2_test_dir\\f1")));
1058 ok(p_tr2_sys__File_size("tr2_test_dir\\f1_rename") == 0, "test_tr2_sys__Rename(): expect: 0, got %s\n",debugstr_longlong(p_tr2_sys__File_size("tr2_test_dir\\f1_rename")));
1059 ret = p_tr2_sys__Rename_wchar(testW, testW2);
1060 ok(ret == ERROR_SUCCESS, "tr2_sys__Rename_wchar(): expect: ERROR_SUCCESS, got %d\n", ret);
1062 ok(DeleteFileW(testW2), "expect fw to exist\n");
1063 ok(DeleteFileA("tr2_test_dir\\f1_rename"), "expect f1_rename to exist\n");
1064 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
1065 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect %d got %d\n", 1, ret);
1066 ok(SetCurrentDirectoryA(current_path), "SetCurrentDirectoryA failed\n");
1069 static void test_tr2_sys__Statvfs(void)
1071 struct space_info info;
1072 char current_path[MAX_PATH];
1073 WCHAR current_path_wchar[MAX_PATH];
1074 memset(current_path, 0, MAX_PATH);
1075 p_tr2_sys__Current_get(current_path);
1076 memset(current_path_wchar, 0, MAX_PATH);
1077 p_tr2_sys__Current_get_wchar(current_path_wchar);
1079 p_tr2_sys__Statvfs(&info, current_path);
1080 ok(info.capacity >= info.free, "test_tr2_sys__Statvfs(): info.capacity < info.free\n");
1081 ok(info.free >= info.available, "test_tr2_sys__Statvfs(): info.free < info.available\n");
1083 p_tr2_sys__Statvfs_wchar(&info, current_path_wchar);
1084 ok(info.capacity >= info.free, "tr2_sys__Statvfs_wchar(): info.capacity < info.free\n");
1085 ok(info.free >= info.available, "tr2_sys__Statvfs_wchar(): info.free < info.available\n");
1087 p_tr2_sys__Statvfs(&info, NULL);
1088 ok(info.available == 0, "test_tr2_sys__Statvfs(): info.available expect: %d, got %s\n",
1089 0, debugstr_longlong(info.available));
1090 ok(info.capacity == 0, "test_tr2_sys__Statvfs(): info.capacity expect: %d, got %s\n",
1091 0, debugstr_longlong(info.capacity));
1092 ok(info.free == 0, "test_tr2_sys__Statvfs(): info.free expect: %d, got %s\n",
1093 0, debugstr_longlong(info.free));
1095 p_tr2_sys__Statvfs(&info, "not_exist");
1096 ok(info.available == 0, "test_tr2_sys__Statvfs(): info.available expect: %d, got %s\n",
1097 0, debugstr_longlong(info.available));
1098 ok(info.capacity == 0, "test_tr2_sys__Statvfs(): info.capacity expect: %d, got %s\n",
1099 0, debugstr_longlong(info.capacity));
1100 ok(info.free == 0, "test_tr2_sys__Statvfs(): info.free expect: %d, got %s\n",
1101 0, debugstr_longlong(info.free));
1104 static void test_tr2_sys__Stat(void)
1106 int i, err_code, ret;
1107 HANDLE file;
1108 enum file_type val;
1109 struct {
1110 char const *path;
1111 enum file_type ret;
1112 int err_code;
1113 int is_todo;
1114 } tests[] = {
1115 { NULL, status_unknown, ERROR_INVALID_PARAMETER, FALSE },
1116 { "tr2_test_dir", directory_file, ERROR_SUCCESS, FALSE },
1117 { "tr2_test_dir\\f1", regular_file, ERROR_SUCCESS, FALSE },
1118 { "tr2_test_dir\\not_exist_file ", file_not_found, ERROR_SUCCESS, FALSE },
1119 { "tr2_test_dir\\??invalid_name>>", file_not_found, ERROR_SUCCESS, FALSE },
1120 { "tr2_test_dir\\f1_link" , regular_file, ERROR_SUCCESS, TRUE },
1121 { "tr2_test_dir\\dir_link", directory_file, ERROR_SUCCESS, TRUE },
1124 CreateDirectoryA("tr2_test_dir", NULL);
1125 file = CreateFileA("tr2_test_dir/f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
1126 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1127 ok(CloseHandle(file), "CloseHandle\n");
1128 SetLastError(0xdeadbeef);
1129 ret = CreateSymbolicLinkA("tr2_test_dir/f1_link", "tr2_test_dir/f1", 0);
1130 if(!ret && (GetLastError()==ERROR_PRIVILEGE_NOT_HELD||GetLastError()==ERROR_INVALID_FUNCTION)) {
1131 tests[5].ret = tests[6].ret = file_not_found;
1132 win_skip("Privilege not held or symbolic link not supported, skipping symbolic link tests.\n");
1133 }else {
1134 ok(ret, "CreateSymbolicLinkA failed\n");
1135 ok(CreateSymbolicLinkA("tr2_test_dir/dir_link", "tr2_test_dir", 1), "CreateSymbolicLinkA failed\n");
1138 file = CreateNamedPipeA("\\\\.\\PiPe\\tests_pipe.c",
1139 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 2, 1024, 1024,
1140 NMPWAIT_USE_DEFAULT_WAIT, NULL);
1141 ok(file != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
1142 err_code = 0xdeadbeef;
1143 val = p_tr2_sys__Stat("\\\\.\\PiPe\\tests_pipe.c", &err_code);
1144 todo_wine ok(regular_file == val, "tr2_sys__Stat(): expect: regular_file, got %d\n", val);
1145 todo_wine ok(ERROR_SUCCESS == err_code, "tr2_sys__Stat(): err_code expect: ERROR_SUCCESS, got %d\n", err_code);
1146 err_code = 0xdeadbeef;
1147 val = p_tr2_sys__Lstat("\\\\.\\PiPe\\tests_pipe.c", &err_code);
1148 ok(status_unknown == val, "tr2_sys__Lstat(): expect: status_unknown, got %d\n", val);
1149 todo_wine ok(ERROR_PIPE_BUSY == err_code, "tr2_sys__Lstat(): err_code expect: ERROR_PIPE_BUSY, got %d\n", err_code);
1150 ok(CloseHandle(file), "CloseHandle\n");
1151 file = CreateNamedPipeA("\\\\.\\PiPe\\tests_pipe.c",
1152 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 2, 1024, 1024,
1153 NMPWAIT_USE_DEFAULT_WAIT, NULL);
1154 ok(file != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
1155 err_code = 0xdeadbeef;
1156 val = p_tr2_sys__Lstat("\\\\.\\PiPe\\tests_pipe.c", &err_code);
1157 todo_wine ok(regular_file == val, "tr2_sys__Lstat(): expect: regular_file, got %d\n", val);
1158 todo_wine ok(ERROR_SUCCESS == err_code, "tr2_sys__Lstat(): err_code expect: ERROR_SUCCESS, got %d\n", err_code);
1159 ok(CloseHandle(file), "CloseHandle\n");
1161 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1162 err_code = 0xdeadbeef;
1163 val = p_tr2_sys__Stat(tests[i].path, &err_code);
1164 if(tests[i].is_todo)
1165 todo_wine ok(tests[i].ret == val, "tr2_sys__Stat(): test %d expect: %d, got %d\n",
1166 i+1, tests[i].ret, val);
1167 else
1168 ok(tests[i].ret == val, "tr2_sys__Stat(): test %d expect: %d, got %d\n", i+1, tests[i].ret, val);
1169 ok(tests[i].err_code == err_code, "tr2_sys__Stat(): test %d err_code expect: %d, got %d\n",
1170 i+1, tests[i].err_code, err_code);
1172 /* test tr2_sys__Lstat */
1173 err_code = 0xdeadbeef;
1174 val = p_tr2_sys__Lstat(tests[i].path, &err_code);
1175 if(tests[i].is_todo)
1176 todo_wine ok(tests[i].ret == val, "tr2_sys__Lstat(): test %d expect: %d, got %d\n",
1177 i+1, tests[i].ret, val);
1178 else
1179 ok(tests[i].ret == val, "tr2_sys__Lstat(): test %d expect: %d, got %d\n", i+1, tests[i].ret, val);
1181 ok(tests[i].err_code == err_code, "tr2_sys__Lstat(): test %d err_code expect: %d, got %d\n",
1182 i+1, tests[i].err_code, err_code);
1185 if(ret) {
1186 todo_wine ok(DeleteFileA("tr2_test_dir/f1_link"), "expect tr2_test_dir/f1_link to exist\n");
1187 todo_wine ok(RemoveDirectoryA("tr2_test_dir/dir_link"), "expect tr2_test_dir/dir_link to exist\n");
1189 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
1190 ok(RemoveDirectoryA("tr2_test_dir"), "expect tr2_test_dir to exist\n");
1193 static void test_tr2_sys__Last_write_time(void)
1195 HANDLE file;
1196 int ret;
1197 __int64 last_write_time, newtime;
1198 ret = p_tr2_sys__Make_dir("tr2_test_dir");
1199 ok(ret == 1, "tr2_sys__Make_dir() expect 1 got %d\n", ret);
1201 file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1202 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1203 CloseHandle(file);
1205 last_write_time = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
1206 newtime = last_write_time + 123456789;
1207 p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
1208 todo_wine ok(last_write_time == p_tr2_sys__Last_write_time("tr2_test_dir/f1"),
1209 "last_write_time before modfied should not equal to last_write_time %s\n",
1210 debugstr_longlong(last_write_time));
1212 errno = 0xdeadbeef;
1213 last_write_time = p_tr2_sys__Last_write_time("not_exist");
1214 ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
1215 ok(last_write_time == 0, "expect 0 got %s\n", debugstr_longlong(last_write_time));
1216 last_write_time = p_tr2_sys__Last_write_time(NULL);
1217 ok(last_write_time == 0, "expect 0 got %s\n", debugstr_longlong(last_write_time));
1219 p_tr2_sys__Last_write_time_set("not_exist", newtime);
1220 errno = 0xdeadbeef;
1221 p_tr2_sys__Last_write_time_set(NULL, newtime);
1222 ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
1224 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
1225 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
1226 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
1229 static void test_tr2_sys__dir_operation(void)
1231 char *file_name, first_file_name[MAX_PATH], dest[MAX_PATH], longer_path[MAX_PATH];
1232 HANDLE file, result_handle;
1233 enum file_type type;
1234 int err, num_of_f1 = 0, num_of_f2 = 0, num_of_sub_dir = 0, num_of_other_files = 0;
1236 CreateDirectoryA("tr2_test_dir", NULL);
1237 file = CreateFileA("tr2_test_dir/f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
1238 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1239 CloseHandle(file);
1240 file = CreateFileA("tr2_test_dir/f2", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
1241 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1242 CloseHandle(file);
1243 CreateDirectoryA("tr2_test_dir/sub_dir", NULL);
1244 file = CreateFileA("tr2_test_dir/sub_dir/sub_f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
1245 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
1246 CloseHandle(file);
1248 memset(longer_path, 0, MAX_PATH);
1249 GetCurrentDirectoryA(MAX_PATH, longer_path);
1250 strcat(longer_path, "\\tr2_test_dir\\");
1251 while(lstrlenA(longer_path) < MAX_PATH-1)
1252 strcat(longer_path, "s");
1253 ok(lstrlenA(longer_path) == MAX_PATH-1, "tr2_sys__Open_dir(): expect MAX_PATH, got %d\n", lstrlenA(longer_path));
1254 memset(first_file_name, 0, MAX_PATH);
1255 type = err = 0xdeadbeef;
1256 result_handle = NULL;
1257 result_handle = p_tr2_sys__Open_dir(first_file_name, longer_path, &err, &type);
1258 ok(result_handle == NULL, "tr2_sys__Open_dir(): expect NULL, got %p\n", result_handle);
1259 ok(!*first_file_name, "tr2_sys__Open_dir(): expect: 0, got %s\n", first_file_name);
1260 ok(err == ERROR_BAD_PATHNAME, "tr2_sys__Open_dir(): expect: ERROR_BAD_PATHNAME, got %d\n", err);
1261 ok((int)type == 0xdeadbeef, "tr2_sys__Open_dir(): expect 0xdeadbeef, got %d\n", type);
1263 memset(first_file_name, 0, MAX_PATH);
1264 memset(dest, 0, MAX_PATH);
1265 err = type = 0xdeadbeef;
1266 result_handle = NULL;
1267 result_handle = p_tr2_sys__Open_dir(first_file_name, "tr2_test_dir", &err, &type);
1268 ok(result_handle != NULL, "tr2_sys__Open_dir(): expect: not NULL, got %p\n", result_handle);
1269 ok(err == ERROR_SUCCESS, "tr2_sys__Open_dir(): expect: ERROR_SUCCESS, got %d\n", err);
1270 file_name = first_file_name;
1271 while(*file_name) {
1272 if (!strcmp(file_name, "f1")) {
1273 ++num_of_f1;
1274 ok(type == regular_file, "expect regular_file, got %d\n", type);
1275 }else if(!strcmp(file_name, "f2")) {
1276 ++num_of_f2;
1277 ok(type == regular_file, "expect regular_file, got %d\n", type);
1278 }else if(!strcmp(file_name, "sub_dir")) {
1279 ++num_of_sub_dir;
1280 ok(type == directory_file, "expect directory_file, got %d\n", type);
1281 }else {
1282 ++num_of_other_files;
1284 file_name = p_tr2_sys__Read_dir(dest, result_handle, &type);
1286 p_tr2_sys__Close_dir(result_handle);
1287 ok(result_handle != NULL, "tr2_sys__Open_dir(): expect: not NULL, got %p\n", result_handle);
1288 ok(num_of_f1 == 1, "found f1 %d times\n", num_of_f1);
1289 ok(num_of_f2 == 1, "found f2 %d times\n", num_of_f2);
1290 ok(num_of_sub_dir == 1, "found sub_dir %d times\n", num_of_sub_dir);
1291 ok(num_of_other_files == 0, "found %d other files\n", num_of_other_files);
1293 memset(first_file_name, 0, MAX_PATH);
1294 err = type = 0xdeadbeef;
1295 result_handle = file;
1296 result_handle = p_tr2_sys__Open_dir(first_file_name, "not_exist", &err, &type);
1297 ok(result_handle == NULL, "tr2_sys__Open_dir(): expect: NULL, got %p\n", result_handle);
1298 todo_wine ok(err == ERROR_BAD_PATHNAME, "tr2_sys__Open_dir(): expect: ERROR_BAD_PATHNAME, got %d\n", err);
1299 ok((int)type == 0xdeadbeef, "tr2_sys__Open_dir(): expect: 0xdeadbeef, got %d\n", type);
1300 ok(!*first_file_name, "tr2_sys__Open_dir(): expect: 0, got %s\n", first_file_name);
1302 CreateDirectoryA("empty_dir", NULL);
1303 memset(first_file_name, 0, MAX_PATH);
1304 err = type = 0xdeadbeef;
1305 result_handle = file;
1306 result_handle = p_tr2_sys__Open_dir(first_file_name, "empty_dir", &err, &type);
1307 ok(result_handle == NULL, "tr2_sys__Open_dir(): expect: NULL, got %p\n", result_handle);
1308 ok(err == ERROR_SUCCESS, "tr2_sys__Open_dir(): expect: ERROR_SUCCESS, got %d\n", err);
1309 ok(type == status_unknown, "tr2_sys__Open_dir(): expect: status_unknown, got %d\n", type);
1310 ok(!*first_file_name, "tr2_sys__Open_dir(): expect: 0, got %s\n", first_file_name);
1311 p_tr2_sys__Close_dir(result_handle);
1312 ok(result_handle == NULL, "tr2_sys__Open_dir(): expect: NULL, got %p\n", result_handle);
1314 ok(RemoveDirectoryA("empty_dir"), "expect empty_dir to exist\n");
1315 ok(DeleteFileA("tr2_test_dir/sub_dir/sub_f1"), "expect tr2_test_dir/sub_dir/sub_f1 to exist\n");
1316 ok(RemoveDirectoryA("tr2_test_dir/sub_dir"), "expect tr2_test_dir/sub_dir to exist\n");
1317 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
1318 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
1319 ok(RemoveDirectoryA("tr2_test_dir"), "expect tr2_test_dir to exist\n");
1322 static int __cdecl thrd_thread(void *arg)
1324 _Thrd_t *thr = arg;
1326 *thr = p__Thrd_current();
1327 return 0x42;
1330 static void test_thrd(void)
1332 int ret, i, r;
1333 struct test {
1334 _Thrd_t a;
1335 _Thrd_t b;
1336 int r;
1338 const HANDLE hnd1 = (HANDLE)0xcccccccc;
1339 const HANDLE hnd2 = (HANDLE)0xdeadbeef;
1340 xtime xt, before, after;
1341 MSVCRT_long diff;
1342 _Thrd_t ta, tb;
1344 struct test testeq[] = {
1345 { {0, 0}, {0, 0}, 1 },
1346 { {0, 1}, {0, 0}, 0 },
1347 { {hnd1, 0}, {hnd1, 1}, 0 },
1348 { {hnd1, 0}, {hnd2, 0}, 1 }
1351 struct test testlt[] = {
1352 { {0, 0}, {0, 0}, 0 },
1353 { {0, 0}, {0, 1}, 1 },
1354 { {0, 1}, {0, 0}, 0 },
1355 { {hnd1, 0}, {hnd2, 0}, 0 },
1356 { {hnd1, 0}, {hnd2, 1}, 1 }
1359 /* test for equal */
1360 for(i=0; i<sizeof(testeq)/sizeof(testeq[0]); i++) {
1361 ret = p__Thrd_equal(testeq[i].a, testeq[i].b);
1362 ok(ret == testeq[i].r, "(%p %u) = (%p %u) expected %d, got %d\n",
1363 testeq[i].a.hnd, testeq[i].a.id, testeq[i].b.hnd, testeq[i].b.id, testeq[i].r, ret);
1366 /* test for less than */
1367 for(i=0; i<sizeof(testlt)/sizeof(testlt[0]); i++) {
1368 ret = p__Thrd_lt(testlt[i].a, testlt[i].b);
1369 ok(ret == testlt[i].r, "(%p %u) < (%p %u) expected %d, got %d\n",
1370 testlt[i].a.hnd, testlt[i].a.id, testlt[i].b.hnd, testlt[i].b.id, testlt[i].r, ret);
1373 /* test for sleep */
1374 if (0) /* crash on Windows */
1375 p__Thrd_sleep(NULL);
1376 p_xtime_get(&xt, 1);
1377 xt.sec += 2;
1378 p_xtime_get(&before, 1);
1379 p__Thrd_sleep(&xt);
1380 p_xtime_get(&after, 1);
1381 diff = p__Xtime_diff_to_millis2(&after, &before);
1382 ok(diff > 2000 - TIMEDELTA, "got %d\n", diff);
1384 /* test for current */
1385 ta = p__Thrd_current();
1386 tb = p__Thrd_current();
1387 ok(ta.id == tb.id, "got a %d b %d\n", ta.id, tb.id);
1388 ok(ta.id == GetCurrentThreadId(), "expected %d, got %d\n", GetCurrentThreadId(), ta.id);
1389 /* these can be different if new threads are created at same time */
1390 ok(ta.hnd == tb.hnd, "got a %p b %p\n", ta.hnd, tb.hnd);
1391 ok(!CloseHandle(ta.hnd), "handle %p not closed\n", ta.hnd);
1392 ok(!CloseHandle(tb.hnd), "handle %p not closed\n", tb.hnd);
1394 /* test for create/join */
1395 if (0) /* crash on Windows */
1397 p__Thrd_create(NULL, thrd_thread, NULL);
1398 p__Thrd_create(&ta, NULL, NULL);
1400 r = -1;
1401 ret = p__Thrd_create(&ta, thrd_thread, (void*)&tb);
1402 ok(!ret, "failed to create thread, got %d\n", ret);
1403 ret = p__Thrd_join(ta, &r);
1404 ok(!ret, "failed to join thread, got %d\n", ret);
1405 ok(ta.id == tb.id, "expected %d, got %d\n", ta.id, tb.id);
1406 ok(ta.hnd != tb.hnd, "same handles, got %p\n", ta.hnd);
1407 ok(r == 0x42, "expected 0x42, got %d\n", r);
1408 ok(!CloseHandle(ta.hnd), "handle %p not closed\n", ta.hnd);
1411 #define NUM_THREADS 10
1412 struct cndmtx
1414 HANDLE initialized;
1415 int started;
1416 int thread_no;
1418 _Cnd_t cnd;
1419 _Mtx_t mtx;
1420 BOOL timed_wait;
1423 static int __cdecl cnd_wait_thread(void *arg)
1425 struct cndmtx *cm = arg;
1426 int r;
1428 p__Mtx_lock(&cm->mtx);
1430 if(InterlockedIncrement(&cm->started) == cm->thread_no)
1431 SetEvent(cm->initialized);
1433 if(cm->timed_wait) {
1434 xtime xt;
1436 p_xtime_get(&xt, 1);
1437 xt.sec += 2;
1438 r = p__Cnd_timedwait(&cm->cnd, &cm->mtx, &xt);
1439 ok(!r, "timed wait failed\n");
1440 } else {
1441 r = p__Cnd_wait(&cm->cnd, &cm->mtx);
1442 ok(!r, "wait failed\n");
1445 p__Mtx_unlock(&cm->mtx);
1446 return 0;
1449 static void test_cnd(void)
1451 _Thrd_t threads[NUM_THREADS];
1452 xtime xt, before, after;
1453 MSVCRT_long diff;
1454 struct cndmtx cm;
1455 _Cnd_t cnd;
1456 _Mtx_t mtx;
1457 int r, i;
1459 r = p__Cnd_init(&cnd);
1460 ok(!r, "failed to init cnd\n");
1462 r = p__Mtx_init(&mtx, 0);
1463 ok(!r, "failed to init mtx\n");
1465 if (0) /* crash on Windows */
1467 p__Cnd_init(NULL);
1468 p__Cnd_wait(NULL, &mtx);
1469 p__Cnd_wait(&cnd, NULL);
1470 p__Cnd_timedwait(NULL, &mtx, &xt);
1471 p__Cnd_timedwait(&cnd, &mtx, &xt);
1473 p__Cnd_destroy(NULL);
1475 /* test _Cnd_signal/_Cnd_wait */
1476 cm.initialized = CreateEventW(NULL, FALSE, FALSE, NULL);
1477 cm.started = 0;
1478 cm.thread_no = 1;
1479 cm.cnd = cnd;
1480 cm.mtx = mtx;
1481 cm.timed_wait = FALSE;
1482 p__Thrd_create(&threads[0], cnd_wait_thread, (void*)&cm);
1484 WaitForSingleObject(cm.initialized, INFINITE);
1485 p__Mtx_lock(&mtx);
1486 p__Mtx_unlock(&mtx);
1488 r = p__Cnd_signal(&cm.cnd);
1489 ok(!r, "failed to signal\n");
1490 p__Thrd_join(threads[0], NULL);
1492 /* test _Cnd_timedwait time out */
1493 p__Mtx_lock(&mtx);
1494 p_xtime_get(&before, 1);
1495 xt = before;
1496 xt.sec += 1;
1497 r = p__Cnd_timedwait(&cnd, &mtx, &xt);
1498 p_xtime_get(&after, 1);
1499 p__Mtx_unlock(&mtx);
1501 diff = p__Xtime_diff_to_millis2(&after, &before);
1502 ok(r == 2, "should have timed out\n");
1503 ok(diff > 1000 - TIMEDELTA, "got %d\n", diff);
1505 /* test _Cnd_timedwait */
1506 cm.started = 0;
1507 cm.timed_wait = TRUE;
1508 p__Thrd_create(&threads[0], cnd_wait_thread, (void*)&cm);
1510 WaitForSingleObject(cm.initialized, INFINITE);
1511 p__Mtx_lock(&mtx);
1512 p__Mtx_unlock(&mtx);
1514 r = p__Cnd_signal(&cm.cnd);
1515 ok(!r, "failed to signal\n");
1516 p__Thrd_join(threads[0], NULL);
1518 /* test _Cnd_broadcast */
1519 cm.started = 0;
1520 cm.thread_no = NUM_THREADS;
1521 cm.timed_wait = FALSE;
1523 for(i = 0; i < cm.thread_no; i++)
1524 p__Thrd_create(&threads[i], cnd_wait_thread, (void*)&cm);
1526 WaitForSingleObject(cm.initialized, INFINITE);
1527 p__Mtx_lock(&mtx);
1528 p__Mtx_unlock(&mtx);
1530 r = p__Cnd_broadcast(&cnd);
1531 ok(!r, "failed to broadcast\n");
1532 for(i = 0; i < cm.thread_no; i++)
1533 p__Thrd_join(threads[i], NULL);
1535 /* test broadcast with _Cnd_destroy */
1536 cm.started = 0;
1537 for(i = 0; i < cm.thread_no; i++)
1538 p__Thrd_create(&threads[i], cnd_wait_thread, (void*)&cm);
1540 WaitForSingleObject(cm.initialized, INFINITE);
1541 p__Mtx_lock(&mtx);
1542 p__Mtx_unlock(&mtx);
1544 p__Cnd_destroy(&cnd);
1545 for(i = 0; i < cm.thread_no; i++)
1546 p__Thrd_join(threads[i], NULL);
1548 p__Mtx_destroy(&mtx);
1549 CloseHandle(cm.initialized);
1552 START_TEST(msvcp120)
1554 if(!init()) return;
1555 test__Xtime_diff_to_millis2();
1556 test_xtime_get();
1557 test__Getcvt();
1558 test__Call_once();
1559 test__Do_call();
1560 test__Dtest();
1561 test__Dscale();
1562 test__FExp();
1564 test_tr2_sys__File_size();
1565 test_tr2_sys__Equivalent();
1566 test_tr2_sys__Current_get();
1567 test_tr2_sys__Current_set();
1568 test_tr2_sys__Make_dir();
1569 test_tr2_sys__Remove_dir();
1570 test_tr2_sys__Copy_file();
1571 test_tr2_sys__Rename();
1572 test_tr2_sys__Statvfs();
1573 test_tr2_sys__Stat();
1574 test_tr2_sys__Last_write_time();
1575 test_tr2_sys__dir_operation();
1577 test_thrd();
1578 test_cnd();
1580 FreeLibrary(msvcp);