msvcp120/tests: Add tr2_sys__Last_write_time test.
[wine/multimedia.git] / dlls / msvcp120 / tests / msvcp120.c
blobbf7ed8f4bc4c8aba20248a99191e07a5089c9a7b
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>
23 #include "wine/test.h"
24 #include "winbase.h"
26 static inline float __port_infinity(void)
28 static const unsigned __inf_bytes = 0x7f800000;
29 return *(const float *)&__inf_bytes;
31 #define INFINITY __port_infinity()
33 static inline float __port_nan(void)
35 static const unsigned __nan_bytes = 0x7fc00000;
36 return *(const float *)&__nan_bytes;
38 #define NAN __port_nan()
40 typedef int MSVCRT_long;
41 typedef unsigned char MSVCP_bool;
43 /* xtime */
44 typedef struct {
45 __time64_t sec;
46 MSVCRT_long nsec;
47 } xtime;
49 typedef struct {
50 unsigned page;
51 int mb_max;
52 int unk;
53 BYTE isleadbyte[32];
54 } _Cvtvec;
56 struct space_info {
57 ULONGLONG capacity;
58 ULONGLONG free;
59 ULONGLONG available;
62 enum file_type {
63 status_unknown, file_not_found, regular_file, directory_file,
64 symlink_file, block_file, character_file, fifo_file, socket_file,
65 type_unknown
68 static inline const char* debugstr_longlong(ULONGLONG ll)
70 static char string[17];
71 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
72 sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
73 else
74 sprintf(string, "%lx", (unsigned long)ll);
75 return string;
78 static char* (__cdecl *p_setlocale)(int, const char*);
79 static int (__cdecl *p__setmbcp)(int);
80 static int (__cdecl *p_isleadbyte)(int);
82 static MSVCRT_long (__cdecl *p__Xtime_diff_to_millis2)(const xtime*, const xtime*);
83 static int (__cdecl *p_xtime_get)(xtime*, int);
84 static _Cvtvec* (__cdecl *p__Getcvt)(_Cvtvec*);
85 static void (CDECL *p__Call_once)(int *once, void (CDECL *func)(void));
86 static void (CDECL *p__Call_onceEx)(int *once, void (CDECL *func)(void*), void *argv);
87 static void (CDECL *p__Do_call)(void *this);
88 static short (__cdecl *p__Dtest)(double *d);
90 /* filesystem */
91 static ULONGLONG(__cdecl *p_tr2_sys__File_size)(char const*);
92 static ULONGLONG(__cdecl *p_tr2_sys__File_size_wchar)(WCHAR const*);
93 static int (__cdecl *p_tr2_sys__Equivalent)(char const*, char const*);
94 static int (__cdecl *p_tr2_sys__Equivalent_wchar)(WCHAR const*, WCHAR const*);
95 static char* (__cdecl *p_tr2_sys__Current_get)(char *);
96 static WCHAR* (__cdecl *p_tr2_sys__Current_get_wchar)(WCHAR *);
97 static MSVCP_bool (__cdecl *p_tr2_sys__Current_set)(char const*);
98 static MSVCP_bool (__cdecl *p_tr2_sys__Current_set_wchar)(WCHAR const*);
99 static int (__cdecl *p_tr2_sys__Make_dir)(char const*);
100 static int (__cdecl *p_tr2_sys__Make_dir_wchar)(WCHAR const*);
101 static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir)(char const*);
102 static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir_wchar)(WCHAR const*);
103 static int (__cdecl *p_tr2_sys__Copy_file)(char const*, char const*, MSVCP_bool);
104 static int (__cdecl *p_tr2_sys__Copy_file_wchar)(WCHAR const*, WCHAR const*, MSVCP_bool);
105 static int (__cdecl *p_tr2_sys__Rename)(char const*, char const*);
106 static int (__cdecl *p_tr2_sys__Rename_wchar)(WCHAR const*, WCHAR const*);
107 static struct space_info (__cdecl *p_tr2_sys__Statvfs)(char const*);
108 static struct space_info (__cdecl *p_tr2_sys__Statvfs_wchar)(WCHAR const*);
109 static enum file_type (__cdecl *p_tr2_sys__Stat)(char const*, int *);
110 static enum file_type (__cdecl *p_tr2_sys__Lstat)(char const*, int *);
111 static __int64 (__cdecl *p_tr2_sys__Last_write_time)(char const*);
112 static void (__cdecl *p_tr2_sys__Last_write_time_set)(char const*, __int64);
114 static HMODULE msvcp;
115 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
116 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
117 static BOOL init(void)
119 HANDLE msvcr;
121 msvcp = LoadLibraryA("msvcp120.dll");
122 if(!msvcp)
124 win_skip("msvcp120.dll not installed\n");
125 return FALSE;
128 SET(p__Xtime_diff_to_millis2,
129 "_Xtime_diff_to_millis2");
130 SET(p_xtime_get,
131 "xtime_get");
132 SET(p__Getcvt,
133 "_Getcvt");
134 SET(p__Call_once,
135 "_Call_once");
136 SET(p__Call_onceEx,
137 "_Call_onceEx");
138 SET(p__Do_call,
139 "_Do_call");
140 SET(p__Dtest,
141 "_Dtest");
142 if(sizeof(void*) == 8) { /* 64-bit initialization */
143 SET(p_tr2_sys__File_size,
144 "?_File_size@sys@tr2@std@@YA_KPEBD@Z");
145 SET(p_tr2_sys__File_size_wchar,
146 "?_File_size@sys@tr2@std@@YA_KPEB_W@Z");
147 SET(p_tr2_sys__Equivalent,
148 "?_Equivalent@sys@tr2@std@@YAHPEBD0@Z");
149 SET(p_tr2_sys__Equivalent_wchar,
150 "?_Equivalent@sys@tr2@std@@YAHPEB_W0@Z");
151 SET(p_tr2_sys__Current_get,
152 "?_Current_get@sys@tr2@std@@YAPEADAEAY0BAE@D@Z");
153 SET(p_tr2_sys__Current_get_wchar,
154 "?_Current_get@sys@tr2@std@@YAPEA_WAEAY0BAE@_W@Z");
155 SET(p_tr2_sys__Current_set,
156 "?_Current_set@sys@tr2@std@@YA_NPEBD@Z");
157 SET(p_tr2_sys__Current_set_wchar,
158 "?_Current_set@sys@tr2@std@@YA_NPEB_W@Z");
159 SET(p_tr2_sys__Make_dir,
160 "?_Make_dir@sys@tr2@std@@YAHPEBD@Z");
161 SET(p_tr2_sys__Make_dir_wchar,
162 "?_Make_dir@sys@tr2@std@@YAHPEB_W@Z");
163 SET(p_tr2_sys__Remove_dir,
164 "?_Remove_dir@sys@tr2@std@@YA_NPEBD@Z");
165 SET(p_tr2_sys__Remove_dir_wchar,
166 "?_Remove_dir@sys@tr2@std@@YA_NPEB_W@Z");
167 SET(p_tr2_sys__Copy_file,
168 "?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z");
169 SET(p_tr2_sys__Copy_file_wchar,
170 "?_Copy_file@sys@tr2@std@@YAHPEB_W0_N@Z");
171 SET(p_tr2_sys__Rename,
172 "?_Rename@sys@tr2@std@@YAHPEBD0@Z");
173 SET(p_tr2_sys__Rename_wchar,
174 "?_Rename@sys@tr2@std@@YAHPEB_W0@Z");
175 SET(p_tr2_sys__Statvfs,
176 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PEBD@Z");
177 SET(p_tr2_sys__Statvfs_wchar,
178 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PEB_W@Z");
179 SET(p_tr2_sys__Stat,
180 "?_Stat@sys@tr2@std@@YA?AW4file_type@123@PEBDAEAH@Z");
181 SET(p_tr2_sys__Lstat,
182 "?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PEBDAEAH@Z");
183 SET(p_tr2_sys__Last_write_time,
184 "?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z");
185 SET(p_tr2_sys__Last_write_time_set,
186 "?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z");
187 } else {
188 SET(p_tr2_sys__File_size,
189 "?_File_size@sys@tr2@std@@YA_KPBD@Z");
190 SET(p_tr2_sys__File_size_wchar,
191 "?_File_size@sys@tr2@std@@YA_KPB_W@Z");
192 SET(p_tr2_sys__Equivalent,
193 "?_Equivalent@sys@tr2@std@@YAHPBD0@Z");
194 SET(p_tr2_sys__Equivalent_wchar,
195 "?_Equivalent@sys@tr2@std@@YAHPB_W0@Z");
196 SET(p_tr2_sys__Current_get,
197 "?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z");
198 SET(p_tr2_sys__Current_get_wchar,
199 "?_Current_get@sys@tr2@std@@YAPA_WAAY0BAE@_W@Z");
200 SET(p_tr2_sys__Current_set,
201 "?_Current_set@sys@tr2@std@@YA_NPBD@Z");
202 SET(p_tr2_sys__Current_set_wchar,
203 "?_Current_set@sys@tr2@std@@YA_NPB_W@Z");
204 SET(p_tr2_sys__Make_dir,
205 "?_Make_dir@sys@tr2@std@@YAHPBD@Z");
206 SET(p_tr2_sys__Make_dir_wchar,
207 "?_Make_dir@sys@tr2@std@@YAHPB_W@Z");
208 SET(p_tr2_sys__Remove_dir,
209 "?_Remove_dir@sys@tr2@std@@YA_NPBD@Z");
210 SET(p_tr2_sys__Remove_dir_wchar,
211 "?_Remove_dir@sys@tr2@std@@YA_NPB_W@Z");
212 SET(p_tr2_sys__Copy_file,
213 "?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z");
214 SET(p_tr2_sys__Copy_file_wchar,
215 "?_Copy_file@sys@tr2@std@@YAHPB_W0_N@Z");
216 SET(p_tr2_sys__Rename,
217 "?_Rename@sys@tr2@std@@YAHPBD0@Z");
218 SET(p_tr2_sys__Rename_wchar,
219 "?_Rename@sys@tr2@std@@YAHPB_W0@Z");
220 SET(p_tr2_sys__Statvfs,
221 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PBD@Z");
222 SET(p_tr2_sys__Statvfs_wchar,
223 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PB_W@Z");
224 SET(p_tr2_sys__Stat,
225 "?_Stat@sys@tr2@std@@YA?AW4file_type@123@PBDAAH@Z");
226 SET(p_tr2_sys__Lstat,
227 "?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PBDAAH@Z");
228 SET(p_tr2_sys__Last_write_time,
229 "?_Last_write_time@sys@tr2@std@@YA_JPBD@Z");
230 SET(p_tr2_sys__Last_write_time_set,
231 "?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z");
234 msvcr = GetModuleHandleA("msvcr120.dll");
235 p_setlocale = (void*)GetProcAddress(msvcr, "setlocale");
236 p__setmbcp = (void*)GetProcAddress(msvcr, "_setmbcp");
237 p_isleadbyte = (void*)GetProcAddress(msvcr, "isleadbyte");
238 return TRUE;
241 static void test__Xtime_diff_to_millis2(void)
243 struct {
244 __time64_t sec_before;
245 MSVCRT_long nsec_before;
246 __time64_t sec_after;
247 MSVCRT_long nsec_after;
248 MSVCRT_long expect;
249 } tests[] = {
250 {1, 0, 2, 0, 1000},
251 {0, 1000000000, 0, 2000000000, 1000},
252 {1, 100000000, 2, 100000000, 1000},
253 {1, 100000000, 1, 200000000, 100},
254 {0, 0, 0, 1000000000, 1000},
255 {0, 0, 0, 1200000000, 1200},
256 {0, 0, 0, 1230000000, 1230},
257 {0, 0, 0, 1234000000, 1234},
258 {0, 0, 0, 1234100000, 1235},
259 {0, 0, 0, 1234900000, 1235},
260 {0, 0, 0, 1234010000, 1235},
261 {0, 0, 0, 1234090000, 1235},
262 {0, 0, 0, 1234000001, 1235},
263 {0, 0, 0, 1234000009, 1235},
264 {0, 0, -1, 0, 0},
265 {0, 0, 0, -10000000, 0},
266 {0, 0, -1, -100000000, 0},
267 {-1, 0, 0, 0, 1000},
268 {0, -100000000, 0, 0, 100},
269 {-1, -100000000, 0, 0, 1100},
270 {0, 0, -1, 2000000000, 1000},
271 {0, 0, -2, 2000000000, 0},
272 {0, 0, -2, 2100000000, 100}
274 int i;
275 MSVCRT_long ret;
276 xtime t1, t2;
278 for(i = 0; i < sizeof(tests) / sizeof(tests[0]); ++ i)
280 t1.sec = tests[i].sec_before;
281 t1.nsec = tests[i].nsec_before;
282 t2.sec = tests[i].sec_after;
283 t2.nsec = tests[i].nsec_after;
284 ret = p__Xtime_diff_to_millis2(&t2, &t1);
285 ok(ret == tests[i].expect,
286 "_Xtime_diff_to_millis2(): test: %d expect: %d, got: %d\n",
287 i, tests[i].expect, ret);
291 static void test_xtime_get(void)
293 static const MSVCRT_long tests[] = {1, 50, 100, 200, 500};
294 MSVCRT_long diff;
295 xtime before, after;
296 int i;
298 for(i = 0; i < sizeof(tests) / sizeof(tests[0]); i ++)
300 p_xtime_get(&before, 1);
301 Sleep(tests[i]);
302 p_xtime_get(&after, 1);
304 diff = p__Xtime_diff_to_millis2(&after, &before);
306 ok(diff >= tests[i],
307 "xtime_get() not functioning correctly, test: %d, expect: ge %d, got: %d\n",
308 i, tests[i], diff);
311 /* Test parameter and return value */
312 before.sec = 0xdeadbeef, before.nsec = 0xdeadbeef;
313 i = p_xtime_get(&before, 0);
314 ok(i == 0, "expect xtime_get() to return 0, got: %d\n", i);
315 ok(before.sec == 0xdeadbeef && before.nsec == 0xdeadbeef,
316 "xtime_get() shouldn't have modified the xtime struct with the given option\n");
318 before.sec = 0xdeadbeef, before.nsec = 0xdeadbeef;
319 i = p_xtime_get(&before, 1);
320 ok(i == 1, "expect xtime_get() to return 1, got: %d\n", i);
321 ok(before.sec != 0xdeadbeef && before.nsec != 0xdeadbeef,
322 "xtime_get() should have modified the xtime struct with the given option\n");
325 static void test__Getcvt(void)
327 _Cvtvec cvtvec;
328 int i;
330 p__Getcvt(&cvtvec);
331 ok(cvtvec.page == 0, "cvtvec.page = %d\n", cvtvec.page);
332 ok(cvtvec.mb_max == 1, "cvtvec.mb_max = %d\n", cvtvec.mb_max);
333 todo_wine ok(cvtvec.unk == 1, "cvtvec.unk = %d\n", cvtvec.unk);
334 for(i=0; i<32; i++)
335 ok(cvtvec.isleadbyte[i] == 0, "cvtvec.isleadbyte[%d] = %x\n", i, cvtvec.isleadbyte[i]);
337 if(!p_setlocale(LC_ALL, ".936")) {
338 win_skip("_Getcvt tests\n");
339 return;
341 p__Getcvt(&cvtvec);
342 ok(cvtvec.page == 936, "cvtvec.page = %d\n", cvtvec.page);
343 ok(cvtvec.mb_max == 2, "cvtvec.mb_max = %d\n", cvtvec.mb_max);
344 ok(cvtvec.unk == 0, "cvtvec.unk = %d\n", cvtvec.unk);
345 for(i=0; i<32; i++)
346 ok(cvtvec.isleadbyte[i] == 0, "cvtvec.isleadbyte[%d] = %x\n", i, cvtvec.isleadbyte[i]);
348 p__setmbcp(936);
349 p__Getcvt(&cvtvec);
350 ok(cvtvec.page == 936, "cvtvec.page = %d\n", cvtvec.page);
351 ok(cvtvec.mb_max == 2, "cvtvec.mb_max = %d\n", cvtvec.mb_max);
352 ok(cvtvec.unk == 0, "cvtvec.unk = %d\n", cvtvec.unk);
353 for(i=0; i<32; i++) {
354 BYTE b = 0;
355 int j;
357 for(j=0; j<8; j++)
358 b |= (p_isleadbyte(i*8+j) ? 1 : 0) << j;
359 ok(cvtvec.isleadbyte[i] ==b, "cvtvec.isleadbyte[%d] = %x (%x)\n", i, cvtvec.isleadbyte[i], b);
363 static int cnt;
364 static int once;
366 static void __cdecl call_once_func(void)
368 ok(!once, "once != 0\n");
369 cnt += 0x10000;
372 static void __cdecl call_once_ex_func(void *arg)
374 int *i = arg;
376 ok(!once, "once != 0\n");
377 (*i)++;
380 static DWORD WINAPI call_once_thread(void *arg)
382 p__Call_once(&once, call_once_func);
383 return 0;
386 static DWORD WINAPI call_once_ex_thread(void *arg)
388 p__Call_onceEx(&once, call_once_ex_func, &cnt);
389 return 0;
392 static void test__Call_once(void)
394 HANDLE h[4];
395 int i;
397 for(i=0; i<4; i++)
398 h[i] = CreateThread(NULL, 0, call_once_thread, &once, 0, NULL);
399 ok(WaitForMultipleObjects(4, h, TRUE, INFINITE) == WAIT_OBJECT_0,
400 "error waiting for all threads to finish\n");
401 ok(cnt == 0x10000, "cnt = %x\n", cnt);
402 ok(once == 1, "once = %x\n", once);
404 once = cnt = 0;
405 for(i=0; i<4; i++)
406 h[i] = CreateThread(NULL, 0, call_once_ex_thread, &once, 0, NULL);
407 ok(WaitForMultipleObjects(4, h, TRUE, INFINITE) == WAIT_OBJECT_0,
408 "error waiting for all threads to finish\n");
409 ok(cnt == 1, "cnt = %x\n", cnt);
410 ok(once == 1, "once = %x\n", once);
413 static void **vtbl_func0;
414 #ifdef __i386__
415 /* TODO: this should be a __thiscall function */
416 static void __stdcall thiscall_func(void)
418 cnt = 1;
420 #else
421 static void __cdecl thiscall_func(void *this)
423 ok(this == &vtbl_func0, "incorrect this value\n");
424 cnt = 1;
426 #endif
428 static void test__Do_call(void)
430 void *pfunc = thiscall_func;
432 cnt = 0;
433 vtbl_func0 = &pfunc;
434 p__Do_call(&vtbl_func0);
435 ok(cnt == 1, "func was not called\n");
438 static void test__Dtest(void)
440 double d;
441 short ret;
443 d = 0;
444 ret = p__Dtest(&d);
445 ok(ret == FP_ZERO, "_Dtest(0) returned %x\n", ret);
447 d = 1;
448 ret = p__Dtest(&d);
449 ok(ret == FP_NORMAL, "_Dtest(1) returned %x\n", ret);
451 d = -1;
452 ret = p__Dtest(&d);
453 ok(ret == FP_NORMAL, "_Dtest(-1) returned %x\n", ret);
455 d = INFINITY;
456 ret = p__Dtest(&d);
457 ok(ret == FP_INFINITE, "_Dtest(INF) returned %x\n", ret);
459 d = NAN;
460 ret = p__Dtest(&d);
461 ok(ret == FP_NAN, "_Dtest(NAN) returned %x\n", ret);
464 static void test_tr2_sys__File_size(void)
466 ULONGLONG val;
467 HANDLE file;
468 LARGE_INTEGER file_size;
469 WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
470 CreateDirectoryA("tr2_test_dir", NULL);
472 file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
473 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
474 file_size.QuadPart = 7;
475 ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
476 ok(SetEndOfFile(file), "SetEndOfFile failed\n");
477 CloseHandle(file);
478 val = p_tr2_sys__File_size("tr2_test_dir/f1");
479 ok(val == 7, "file_size is %s\n", debugstr_longlong(val));
480 val = p_tr2_sys__File_size_wchar(testW);
481 ok(val == 7, "file_size is %s\n", debugstr_longlong(val));
483 file = CreateFileA("tr2_test_dir/f2", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
484 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
485 CloseHandle(file);
486 val = p_tr2_sys__File_size("tr2_test_dir/f2");
487 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
489 val = p_tr2_sys__File_size("tr2_test_dir");
490 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
492 errno = 0xdeadbeef;
493 val = p_tr2_sys__File_size("tr2_test_dir/not_exists_file");
494 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
495 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
497 errno = 0xdeadbeef;
498 val = p_tr2_sys__File_size(NULL);
499 ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
500 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
502 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
503 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
504 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
507 static void test_tr2_sys__Equivalent(void)
509 int val, i;
510 HANDLE file;
511 char temp_path[MAX_PATH], current_path[MAX_PATH];
512 WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
513 WCHAR testW2[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','2',0};
514 struct {
515 char const *path1;
516 char const *path2;
517 int equivalent;
518 } tests[] = {
519 { NULL, NULL, -1 },
520 { NULL, "f1", -1 },
521 { "f1", NULL, -1 },
522 { "f1", "tr2_test_dir", -1 },
523 { "tr2_test_dir", "f1", -1 },
524 { "tr2_test_dir", "tr2_test_dir", -1 },
525 { "tr2_test_dir/./f1", "tr2_test_dir/f2", 0 },
526 { "tr2_test_dir/f1" , "tr2_test_dir/f1", 1 },
527 { "not_exists_file" , "tr2_test_dir/f1", 0 },
528 { "tr2_test_dir\\f1" , "tr2_test_dir/./f1", 1 },
529 { "not_exists_file" , "not_exists_file", -1 },
530 { "tr2_test_dir/f1" , "not_exists_file", 0 },
531 { "tr2_test_dir/../tr2_test_dir/f1", "tr2_test_dir/f1", 1 }
534 memset(current_path, 0, MAX_PATH);
535 GetCurrentDirectoryA(MAX_PATH, current_path);
536 memset(temp_path, 0, MAX_PATH);
537 GetTempPathA(MAX_PATH, temp_path);
538 ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
539 CreateDirectoryA("tr2_test_dir", NULL);
541 file = CreateFileA("tr2_test_dir/f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
542 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
543 CloseHandle(file);
544 file = CreateFileA("tr2_test_dir/f2", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
545 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
546 CloseHandle(file);
548 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
549 errno = 0xdeadbeef;
550 val = p_tr2_sys__Equivalent(tests[i].path1, tests[i].path2);
551 ok(tests[i].equivalent == val, "tr2_sys__Equivalent(): test %d expect: %d, got %d\n", i+1, tests[i].equivalent, val);
552 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
555 val = p_tr2_sys__Equivalent_wchar(testW, testW);
556 ok(val == 1, "tr2_sys__Equivalent(): expect: 1, got %d\n", val);
557 val = p_tr2_sys__Equivalent_wchar(testW, testW2);
558 ok(val == 0, "tr2_sys__Equivalent(): expect: 0, got %d\n", val);
560 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
561 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
562 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
563 ok(SetCurrentDirectoryA(current_path), "SetCurrentDirectoryA failed\n");
566 static void test_tr2_sys__Current_get(void)
568 char temp_path[MAX_PATH], current_path[MAX_PATH], origin_path[MAX_PATH];
569 char *temp;
570 WCHAR temp_path_wchar[MAX_PATH], current_path_wchar[MAX_PATH];
571 WCHAR *temp_wchar;
572 memset(origin_path, 0, MAX_PATH);
573 GetCurrentDirectoryA(MAX_PATH, origin_path);
574 memset(temp_path, 0, MAX_PATH);
575 GetTempPathA(MAX_PATH, temp_path);
577 ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
578 memset(current_path, 0, MAX_PATH);
579 temp = p_tr2_sys__Current_get(current_path);
580 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
581 temp[strlen(temp)] = '\\';
582 ok(!strcmp(temp_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path, current_path);
584 GetTempPathW(MAX_PATH, temp_path_wchar);
585 ok(SetCurrentDirectoryW(temp_path_wchar), "SetCurrentDirectoryW to temp_path_wchar failed\n");
586 memset(current_path_wchar, 0, MAX_PATH);
587 temp_wchar = p_tr2_sys__Current_get_wchar(current_path_wchar);
588 ok(temp_wchar == current_path_wchar, "p_tr2_sys__Current_get_wchar returned different buffer\n");
589 temp_wchar[wcslen(temp_wchar)] = '\\';
590 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));
592 ok(SetCurrentDirectoryA(origin_path), "SetCurrentDirectoryA to origin_path failed\n");
593 memset(current_path, 0, MAX_PATH);
594 temp = p_tr2_sys__Current_get(current_path);
595 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
596 ok(!strcmp(origin_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", origin_path, current_path);
599 static void test_tr2_sys__Current_set(void)
601 char temp_path[MAX_PATH], current_path[MAX_PATH], origin_path[MAX_PATH];
602 char *temp;
603 WCHAR testW[] = {'.','/',0};
604 memset(temp_path, 0, MAX_PATH);
605 GetTempPathA(MAX_PATH, temp_path);
606 memset(origin_path, 0, MAX_PATH);
607 GetCurrentDirectoryA(MAX_PATH, origin_path);
608 temp = p_tr2_sys__Current_get(origin_path);
609 ok(temp == origin_path, "p_tr2_sys__Current_get returned different buffer\n");
611 ok(p_tr2_sys__Current_set(temp_path), "p_tr2_sys__Current_set to temp_path failed\n");
612 memset(current_path, 0, MAX_PATH);
613 temp = p_tr2_sys__Current_get(current_path);
614 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
615 temp[strlen(temp)] = '\\';
616 ok(!strcmp(temp_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path, current_path);
618 ok(p_tr2_sys__Current_set_wchar(testW), "p_tr2_sys__Current_set_wchar to temp_path failed\n");
619 memset(current_path, 0, MAX_PATH);
620 temp = p_tr2_sys__Current_get(current_path);
621 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
622 temp[strlen(temp)] = '\\';
623 ok(!strcmp(temp_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path, current_path);
625 errno = 0xdeadbeef;
626 ok(!p_tr2_sys__Current_set("not_exisist_dir"), "p_tr2_sys__Current_set to not_exist_dir succeed\n");
627 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
629 errno = 0xdeadbeef;
630 ok(!p_tr2_sys__Current_set("??invalid_name>>"), "p_tr2_sys__Current_set to ??invalid_name>> succeed\n");
631 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
633 ok(p_tr2_sys__Current_set(origin_path), "p_tr2_sys__Current_set to origin_path failed\n");
634 memset(current_path, 0, MAX_PATH);
635 temp = p_tr2_sys__Current_get(current_path);
636 ok(temp == current_path, "p_tr2_sys__Current_get returned different buffer\n");
637 ok(!strcmp(origin_path, current_path), "test_tr2_sys__Current_get(): expect: %s, got %s\n", origin_path, current_path);
640 static void test_tr2_sys__Make_dir(void)
642 int ret, i;
643 WCHAR testW[] = {'w','d',0};
644 struct {
645 char const *path;
646 int val;
647 } tests[] = {
648 { "tr2_test_dir", 1 },
649 { "tr2_test_dir", 0 },
650 { NULL, -1 },
651 { "??invalid_name>>", -1 }
654 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
655 errno = 0xdeadbeef;
656 ret = p_tr2_sys__Make_dir(tests[i].path);
657 ok(ret == tests[i].val, "tr2_sys__Make_dir(): test %d expect: %d, got %d\n", i+1, tests[i].val, ret);
658 ok(errno == 0xdeadbeef, "tr2_sys__Make_dir(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
660 ret = p_tr2_sys__Make_dir_wchar(testW);
661 ok(ret == 1, "tr2_sys__Make_dir(): expect: 1, got %d\n", ret);
663 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
664 ok(p_tr2_sys__Remove_dir_wchar(testW), "expect wd to exist\n");
667 static void test_tr2_sys__Remove_dir(void)
669 MSVCP_bool ret;
670 int i;
671 struct {
672 char const *path;
673 MSVCP_bool val;
674 } tests[] = {
675 { "tr2_test_dir", TRUE },
676 { "tr2_test_dir", FALSE },
677 { NULL, FALSE },
678 { "??invalid_name>>", FALSE }
681 ok(p_tr2_sys__Make_dir("tr2_test_dir"), "tr2_sys__Make_dir() failed\n");
683 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
684 errno = 0xdeadbeef;
685 ret = p_tr2_sys__Remove_dir(tests[i].path);
686 ok(ret == tests[i].val, "test_tr2_sys__Remove_dir(): test %d expect: %d, got %d\n", i+1, tests[i].val, ret);
687 ok(errno == 0xdeadbeef, "test_tr2_sys__Remove_dir(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
691 static void test_tr2_sys__Copy_file(void)
693 HANDLE file;
694 int ret, i;
695 LARGE_INTEGER file_size;
696 WCHAR testW[] = {'f','1',0}, testW2[] = {'f','w',0};
697 struct {
698 char const *source;
699 char const *dest;
700 MSVCP_bool fail_if_exists;
701 int last_error;
702 int last_error2;
703 MSVCP_bool is_todo;
704 } tests[] = {
705 { "f1", "f1_copy", TRUE, ERROR_SUCCESS, ERROR_SUCCESS, FALSE },
706 { "f1", "tr2_test_dir\\f1_copy", TRUE, ERROR_SUCCESS, ERROR_SUCCESS, FALSE },
707 { "f1", "tr2_test_dir\\f1_copy", TRUE, ERROR_FILE_EXISTS, ERROR_FILE_EXISTS, FALSE },
708 { "f1", "tr2_test_dir\\f1_copy", FALSE, ERROR_SUCCESS, ERROR_SUCCESS, FALSE },
709 { "tr2_test_dir", "f1", TRUE, ERROR_ACCESS_DENIED, ERROR_ACCESS_DENIED, FALSE },
710 { "tr2_test_dir", "tr2_test_dir_copy", TRUE, ERROR_ACCESS_DENIED, ERROR_ACCESS_DENIED, FALSE },
711 { NULL, "f1", TRUE, ERROR_INVALID_PARAMETER, ERROR_INVALID_PARAMETER, TRUE },
712 { "f1", NULL, TRUE, ERROR_INVALID_PARAMETER, ERROR_INVALID_PARAMETER, TRUE },
713 { "not_exist", "tr2_test_dir", TRUE, ERROR_FILE_NOT_FOUND, ERROR_FILE_NOT_FOUND, FALSE },
714 { "f1", "not_exist_dir\\f1_copy", TRUE, ERROR_PATH_NOT_FOUND, ERROR_FILE_NOT_FOUND, FALSE },
715 { "f1", "tr2_test_dir", TRUE, ERROR_ACCESS_DENIED, ERROR_FILE_EXISTS, FALSE }
718 ret = p_tr2_sys__Make_dir("tr2_test_dir");
719 ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
720 file = CreateFileA("f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
721 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
722 file_size.QuadPart = 7;
723 ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
724 ok(SetEndOfFile(file), "SetEndOfFile failed\n");
725 CloseHandle(file);
727 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
728 errno = 0xdeadbeef;
729 ret = p_tr2_sys__Copy_file(tests[i].source, tests[i].dest, tests[i].fail_if_exists);
730 if(tests[i].is_todo)
731 todo_wine ok(ret == tests[i].last_error || ret == tests[i].last_error2,
732 "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n",
733 i+1, tests[i].last_error, ret);
734 else
735 ok(ret == tests[i].last_error || ret == tests[i].last_error2,
736 "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n",
737 i+1, tests[i].last_error, ret);
738 ok(errno == 0xdeadbeef, "test_tr2_sys__Copy_file(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
739 if(ret == ERROR_SUCCESS)
740 ok(p_tr2_sys__File_size(tests[i].source) == p_tr2_sys__File_size(tests[i].dest),
741 "test_tr2_sys__Copy_file(): test %d failed, two files' size are not equal\n", i+1);
743 ret = p_tr2_sys__Copy_file_wchar(testW, testW2, TRUE);
744 ok(ret == ERROR_SUCCESS, "test_tr2_sys__Copy_file_wchar() expect ERROR_SUCCESS, got %d\n", ret);
746 ok(DeleteFileA("f1"), "expect f1 to exist\n");
747 ok(DeleteFileW(testW2), "expect fw to exist\n");
748 ok(DeleteFileA("f1_copy"), "expect f1_copy to exist\n");
749 ok(DeleteFileA("tr2_test_dir/f1_copy"), "expect tr2_test_dir/f1 to exist\n");
750 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
751 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
754 static void test_tr2_sys__Rename(void)
756 int ret, i;
757 HANDLE file, h1, h2;
758 BY_HANDLE_FILE_INFORMATION info1, info2;
759 char temp_path[MAX_PATH], current_path[MAX_PATH];
760 LARGE_INTEGER file_size;
761 WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
762 WCHAR testW2[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','w',0};
763 struct {
764 char const *old_path;
765 char const *new_path;
766 int val;
767 } tests[] = {
768 { "tr2_test_dir\\f1", "tr2_test_dir\\f1_rename", ERROR_SUCCESS },
769 { "tr2_test_dir\\f1", NULL, ERROR_INVALID_PARAMETER },
770 { "tr2_test_dir\\f1", "tr2_test_dir\\f1_rename", ERROR_FILE_NOT_FOUND },
771 { NULL, "tr2_test_dir\\NULL_rename", ERROR_INVALID_PARAMETER },
772 { "tr2_test_dir\\f1_rename", "tr2_test_dir\\??invalid_name>>", ERROR_INVALID_NAME },
773 { "tr2_test_dir\\not_exist_file", "tr2_test_dir\\not_exist_rename", ERROR_FILE_NOT_FOUND }
776 memset(current_path, 0, MAX_PATH);
777 GetCurrentDirectoryA(MAX_PATH, current_path);
778 memset(temp_path, 0, MAX_PATH);
779 GetTempPathA(MAX_PATH, temp_path);
780 ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
781 ret = p_tr2_sys__Make_dir("tr2_test_dir");
783 ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
784 file = CreateFileA("tr2_test_dir\\f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
785 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
786 CloseHandle(file);
788 ret = p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1");
789 todo_wine ok(ERROR_SUCCESS == ret, "test_tr2_sys__Rename(): expect: ERROR_SUCCESS, got %d\n", ret);
790 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
791 errno = 0xdeadbeef;
792 if(tests[i].val == ERROR_SUCCESS) {
793 h1 = CreateFileA(tests[i].old_path, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
794 NULL, OPEN_EXISTING, 0, 0);
795 ok(h1 != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
796 ok(GetFileInformationByHandle(h1, &info1), "GetFileInformationByHandle failed\n");
797 CloseHandle(h1);
799 SetLastError(0xdeadbeef);
800 ret = p_tr2_sys__Rename(tests[i].old_path, tests[i].new_path);
801 ok(ret == tests[i].val, "test_tr2_sys__Rename(): test %d expect: %d, got %d\n", i+1, tests[i].val, ret);
802 ok(errno == 0xdeadbeef, "test_tr2_sys__Rename(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
803 if(ret == ERROR_SUCCESS) {
804 h2 = CreateFileA(tests[i].new_path, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
805 NULL, OPEN_EXISTING, 0, 0);
806 ok(h2 != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
807 ok(GetFileInformationByHandle(h2, &info2), "GetFileInformationByHandle failed\n");
808 CloseHandle(h2);
809 ok(info1.nFileIndexHigh == info2.nFileIndexHigh
810 && info1.nFileIndexLow == info2.nFileIndexLow,
811 "test_tr2_sys__Rename(): test %d expect two files equivalent\n", i+1);
815 file = CreateFileA("tr2_test_dir\\f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
816 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
817 file_size.QuadPart = 7;
818 ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
819 ok(SetEndOfFile(file), "SetEndOfFile failed\n");
820 CloseHandle(file);
821 ret = p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1_rename");
822 ok(ret == ERROR_ALREADY_EXISTS, "test_tr2_sys__Rename(): expect: ERROR_ALREADY_EXISTS, got %d\n", ret);
823 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")));
824 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")));
825 ret = p_tr2_sys__Rename_wchar(testW, testW2);
826 ok(ret == ERROR_SUCCESS, "tr2_sys__Rename_wchar(): expect: ERROR_SUCCESS, got %d\n", ret);
828 ok(DeleteFileW(testW2), "expect fw to exist\n");
829 ok(DeleteFileA("tr2_test_dir\\f1_rename"), "expect f1_rename to exist\n");
830 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
831 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect %d got %d\n", 1, ret);
832 ok(SetCurrentDirectoryA(current_path), "SetCurrentDirectoryA failed\n");
835 static void test_tr2_sys__Statvfs(void)
837 struct space_info info;
838 char current_path[MAX_PATH];
839 WCHAR current_path_wchar[MAX_PATH];
840 memset(current_path, 0, MAX_PATH);
841 p_tr2_sys__Current_get(current_path);
842 memset(current_path_wchar, 0, MAX_PATH);
843 p_tr2_sys__Current_get_wchar(current_path_wchar);
845 info = p_tr2_sys__Statvfs(current_path);
846 ok(info.capacity >= info.free, "test_tr2_sys__Statvfs(): info.capacity < info.free\n");
847 ok(info.free >= info.available, "test_tr2_sys__Statvfs(): info.free < info.available\n");
849 info = p_tr2_sys__Statvfs_wchar(current_path_wchar);
850 ok(info.capacity >= info.free, "tr2_sys__Statvfs_wchar(): info.capacity < info.free\n");
851 ok(info.free >= info.available, "tr2_sys__Statvfs_wchar(): info.free < info.available\n");
853 info = p_tr2_sys__Statvfs(NULL);
854 ok(info.available == 0, "test_tr2_sys__Statvfs(): info.available expect: %d, got %s\n",
855 0, debugstr_longlong(info.available));
856 ok(info.capacity == 0, "test_tr2_sys__Statvfs(): info.capacity expect: %d, got %s\n",
857 0, debugstr_longlong(info.capacity));
858 ok(info.free == 0, "test_tr2_sys__Statvfs(): info.free expect: %d, got %s\n",
859 0, debugstr_longlong(info.free));
861 info = p_tr2_sys__Statvfs("not_exist");
862 ok(info.available == 0, "test_tr2_sys__Statvfs(): info.available expect: %d, got %s\n",
863 0, debugstr_longlong(info.available));
864 ok(info.capacity == 0, "test_tr2_sys__Statvfs(): info.capacity expect: %d, got %s\n",
865 0, debugstr_longlong(info.capacity));
866 ok(info.free == 0, "test_tr2_sys__Statvfs(): info.free expect: %d, got %s\n",
867 0, debugstr_longlong(info.free));
870 static void test_tr2_sys__Stat(void)
872 int i, err_code, ret;
873 HANDLE file;
874 enum file_type val;
875 struct {
876 char const *path;
877 enum file_type ret;
878 int err_code;
879 int is_todo;
880 } tests[] = {
881 { NULL, status_unknown, ERROR_INVALID_PARAMETER, FALSE },
882 { "tr2_test_dir", directory_file, ERROR_SUCCESS, FALSE },
883 { "tr2_test_dir\\f1", regular_file, ERROR_SUCCESS, FALSE },
884 { "tr2_test_dir\\not_exist_file ", file_not_found, ERROR_SUCCESS, FALSE },
885 { "tr2_test_dir\\??invalid_name>>", file_not_found, ERROR_SUCCESS, FALSE },
886 { "tr2_test_dir\\f1_link" , regular_file, ERROR_SUCCESS, TRUE },
887 { "tr2_test_dir\\dir_link", directory_file, ERROR_SUCCESS, TRUE },
890 CreateDirectoryA("tr2_test_dir", NULL);
891 file = CreateFileA("tr2_test_dir/f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
892 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
893 ok(CloseHandle(file), "CloseHandle\n");
894 SetLastError(0xdeadbeef);
895 ret = CreateSymbolicLinkA("tr2_test_dir/f1_link", "tr2_test_dir/f1", 0);
896 if(!ret && (GetLastError()==ERROR_PRIVILEGE_NOT_HELD||GetLastError()==ERROR_INVALID_FUNCTION)) {
897 tests[5].ret = tests[6].ret = file_not_found;
898 win_skip("Privilege not held or symbolic link not supported, skipping symbolic link tests.\n");
899 }else {
900 ok(ret, "CreateSymbolicLinkA failed\n");
901 ok(CreateSymbolicLinkA("tr2_test_dir/dir_link", "tr2_test_dir", 1), "CreateSymbolicLinkA failed\n");
904 file = CreateNamedPipeA("\\\\.\\PiPe\\tests_pipe.c",
905 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 2, 1024, 1024,
906 NMPWAIT_USE_DEFAULT_WAIT, NULL);
907 ok(file != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
908 err_code = 0xdeadbeef;
909 val = p_tr2_sys__Stat("\\\\.\\PiPe\\tests_pipe.c", &err_code);
910 todo_wine ok(regular_file == val, "tr2_sys__Stat(): expect: regular_file, got %d\n", val);
911 todo_wine ok(ERROR_SUCCESS == err_code, "tr2_sys__Stat(): err_code expect: ERROR_SUCCESS, got %d\n", err_code);
912 err_code = 0xdeadbeef;
913 val = p_tr2_sys__Lstat("\\\\.\\PiPe\\tests_pipe.c", &err_code);
914 ok(status_unknown == val, "tr2_sys__Lstat(): expect: status_unknown, got %d\n", val);
915 todo_wine ok(ERROR_PIPE_BUSY == err_code, "tr2_sys__Lstat(): err_code expect: ERROR_PIPE_BUSY, got %d\n", err_code);
916 ok(CloseHandle(file), "CloseHandle\n");
917 file = CreateNamedPipeA("\\\\.\\PiPe\\tests_pipe.c",
918 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 2, 1024, 1024,
919 NMPWAIT_USE_DEFAULT_WAIT, NULL);
920 ok(file != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
921 err_code = 0xdeadbeef;
922 val = p_tr2_sys__Lstat("\\\\.\\PiPe\\tests_pipe.c", &err_code);
923 todo_wine ok(regular_file == val, "tr2_sys__Lstat(): expect: regular_file, got %d\n", val);
924 todo_wine ok(ERROR_SUCCESS == err_code, "tr2_sys__Lstat(): err_code expect: ERROR_SUCCESS, got %d\n", err_code);
925 ok(CloseHandle(file), "CloseHandle\n");
927 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
928 err_code = 0xdeadbeef;
929 val = p_tr2_sys__Stat(tests[i].path, &err_code);
930 if(tests[i].is_todo)
931 todo_wine ok(tests[i].ret == val, "tr2_sys__Stat(): test %d expect: %d, got %d\n",
932 i+1, tests[i].ret, val);
933 else
934 ok(tests[i].ret == val, "tr2_sys__Stat(): test %d expect: %d, got %d\n", i+1, tests[i].ret, val);
935 ok(tests[i].err_code == err_code, "tr2_sys__Stat(): test %d err_code expect: %d, got %d\n",
936 i+1, tests[i].err_code, err_code);
938 /* test tr2_sys__Lstat */
939 err_code = 0xdeadbeef;
940 val = p_tr2_sys__Lstat(tests[i].path, &err_code);
941 if(tests[i].is_todo)
942 todo_wine ok(tests[i].ret == val, "tr2_sys__Lstat(): test %d expect: %d, got %d\n",
943 i+1, tests[i].ret, val);
944 else
945 ok(tests[i].ret == val, "tr2_sys__Lstat(): test %d expect: %d, got %d\n", i+1, tests[i].ret, val);
947 ok(tests[i].err_code == err_code, "tr2_sys__Lstat(): test %d err_code expect: %d, got %d\n",
948 i+1, tests[i].err_code, err_code);
951 if(ret) {
952 todo_wine ok(DeleteFileA("tr2_test_dir/f1_link"), "expect tr2_test_dir/f1_link to exist\n");
953 todo_wine ok(RemoveDirectoryA("tr2_test_dir/dir_link"), "expect tr2_test_dir/dir_link to exist\n");
955 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
956 ok(RemoveDirectoryA("tr2_test_dir"), "expect tr2_test_dir to exist\n");
959 static void test_tr2_sys__Last_write_time(void)
961 HANDLE file;
962 int ret;
963 __int64 last_write_time, newtime;
964 ret = p_tr2_sys__Make_dir("tr2_test_dir");
965 ok(ret == 1, "tr2_sys__Make_dir() expect 1 got %d\n", ret);
967 file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
968 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
969 CloseHandle(file);
971 last_write_time = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
972 newtime = last_write_time + 123456789;
973 p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
974 todo_wine ok(last_write_time == p_tr2_sys__Last_write_time("tr2_test_dir/f1"),
975 "last_write_time before modfied should not equal to last_write_time %s\n",
976 debugstr_longlong(last_write_time));
978 errno = 0xdeadbeef;
979 last_write_time = p_tr2_sys__Last_write_time("not_exist");
980 ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
981 ok(last_write_time == 0, "expect 0 got %s\n", debugstr_longlong(last_write_time));
982 last_write_time = p_tr2_sys__Last_write_time(NULL);
983 ok(last_write_time == 0, "expect 0 got %s\n", debugstr_longlong(last_write_time));
985 p_tr2_sys__Last_write_time_set("not_exist", newtime);
986 errno = 0xdeadbeef;
987 p_tr2_sys__Last_write_time_set(NULL, newtime);
988 ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
990 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
991 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
992 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
995 START_TEST(msvcp120)
997 if(!init()) return;
998 test__Xtime_diff_to_millis2();
999 test_xtime_get();
1000 test__Getcvt();
1001 test__Call_once();
1002 test__Do_call();
1003 test__Dtest();
1005 test_tr2_sys__File_size();
1006 test_tr2_sys__Equivalent();
1007 test_tr2_sys__Current_get();
1008 test_tr2_sys__Current_set();
1009 test_tr2_sys__Make_dir();
1010 test_tr2_sys__Remove_dir();
1011 test_tr2_sys__Copy_file();
1012 test_tr2_sys__Rename();
1013 test_tr2_sys__Statvfs();
1014 test_tr2_sys__Stat();
1015 test_tr2_sys__Last_write_time();
1016 FreeLibrary(msvcp);