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
22 #include "wine/test.h"
25 typedef int MSVCRT_long
;
26 typedef unsigned char MSVCP_bool
;
48 status_unknown
, file_not_found
, regular_file
, directory_file
,
49 symlink_file
, block_file
, character_file
, fifo_file
, socket_file
,
53 static inline const char* debugstr_longlong(ULONGLONG ll
)
55 static char string
[17];
56 if (sizeof(ll
) > sizeof(unsigned long) && ll
>> 32)
57 sprintf(string
, "%lx%08lx", (unsigned long)(ll
>> 32), (unsigned long)ll
);
59 sprintf(string
, "%lx", (unsigned long)ll
);
63 static char* (__cdecl
*p_setlocale
)(int, const char*);
64 static int (__cdecl
*p__setmbcp
)(int);
65 static int (__cdecl
*p_isleadbyte
)(int);
67 static MSVCRT_long (__cdecl
*p__Xtime_diff_to_millis2
)(const xtime
*, const xtime
*);
68 static int (__cdecl
*p_xtime_get
)(xtime
*, int);
69 static _Cvtvec
* (__cdecl
*p__Getcvt
)(_Cvtvec
*);
70 static void (CDECL
*p__Call_once
)(int *once
, void (CDECL
*func
)(void));
71 static void (CDECL
*p__Call_onceEx
)(int *once
, void (CDECL
*func
)(void*), void *argv
);
72 static void (CDECL
*p__Do_call
)(void *this);
75 static ULONGLONG(__cdecl
*p_tr2_sys__File_size
)(char const*);
76 static ULONGLONG(__cdecl
*p_tr2_sys__File_size_wchar
)(WCHAR
const*);
77 static int (__cdecl
*p_tr2_sys__Equivalent
)(char const*, char const*);
78 static int (__cdecl
*p_tr2_sys__Equivalent_wchar
)(WCHAR
const*, WCHAR
const*);
79 static char* (__cdecl
*p_tr2_sys__Current_get
)(char *);
80 static WCHAR
* (__cdecl
*p_tr2_sys__Current_get_wchar
)(WCHAR
*);
81 static MSVCP_bool (__cdecl
*p_tr2_sys__Current_set
)(char const*);
82 static MSVCP_bool (__cdecl
*p_tr2_sys__Current_set_wchar
)(WCHAR
const*);
83 static int (__cdecl
*p_tr2_sys__Make_dir
)(char const*);
84 static int (__cdecl
*p_tr2_sys__Make_dir_wchar
)(WCHAR
const*);
85 static MSVCP_bool (__cdecl
*p_tr2_sys__Remove_dir
)(char const*);
86 static MSVCP_bool (__cdecl
*p_tr2_sys__Remove_dir_wchar
)(WCHAR
const*);
87 static int (__cdecl
*p_tr2_sys__Copy_file
)(char const*, char const*, MSVCP_bool
);
88 static int (__cdecl
*p_tr2_sys__Copy_file_wchar
)(WCHAR
const*, WCHAR
const*, MSVCP_bool
);
89 static int (__cdecl
*p_tr2_sys__Rename
)(char const*, char const*);
90 static int (__cdecl
*p_tr2_sys__Rename_wchar
)(WCHAR
const*, WCHAR
const*);
91 static struct space_info (__cdecl
*p_tr2_sys__Statvfs
)(char const*);
92 static enum file_type (__cdecl
*p_tr2_sys__Stat
)(char const*, int *);
93 static enum file_type (__cdecl
*p_tr2_sys__Lstat
)(char const*, int *);
96 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
97 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
98 static BOOL
init(void)
102 msvcp
= LoadLibraryA("msvcp120.dll");
105 win_skip("msvcp120.dll not installed\n");
109 SET(p__Xtime_diff_to_millis2
,
110 "_Xtime_diff_to_millis2");
121 if(sizeof(void*) == 8) { /* 64-bit initialization */
122 SET(p_tr2_sys__File_size
,
123 "?_File_size@sys@tr2@std@@YA_KPEBD@Z");
124 SET(p_tr2_sys__File_size_wchar
,
125 "?_File_size@sys@tr2@std@@YA_KPEB_W@Z");
126 SET(p_tr2_sys__Equivalent
,
127 "?_Equivalent@sys@tr2@std@@YAHPEBD0@Z");
128 SET(p_tr2_sys__Equivalent_wchar
,
129 "?_Equivalent@sys@tr2@std@@YAHPEB_W0@Z");
130 SET(p_tr2_sys__Current_get
,
131 "?_Current_get@sys@tr2@std@@YAPEADAEAY0BAE@D@Z");
132 SET(p_tr2_sys__Current_get_wchar
,
133 "?_Current_get@sys@tr2@std@@YAPEA_WAEAY0BAE@_W@Z");
134 SET(p_tr2_sys__Current_set
,
135 "?_Current_set@sys@tr2@std@@YA_NPEBD@Z");
136 SET(p_tr2_sys__Current_set_wchar
,
137 "?_Current_set@sys@tr2@std@@YA_NPEB_W@Z");
138 SET(p_tr2_sys__Make_dir
,
139 "?_Make_dir@sys@tr2@std@@YAHPEBD@Z");
140 SET(p_tr2_sys__Make_dir_wchar
,
141 "?_Make_dir@sys@tr2@std@@YAHPEB_W@Z");
142 SET(p_tr2_sys__Remove_dir
,
143 "?_Remove_dir@sys@tr2@std@@YA_NPEBD@Z");
144 SET(p_tr2_sys__Remove_dir_wchar
,
145 "?_Remove_dir@sys@tr2@std@@YA_NPEB_W@Z");
146 SET(p_tr2_sys__Copy_file
,
147 "?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z");
148 SET(p_tr2_sys__Copy_file_wchar
,
149 "?_Copy_file@sys@tr2@std@@YAHPEB_W0_N@Z");
150 SET(p_tr2_sys__Rename
,
151 "?_Rename@sys@tr2@std@@YAHPEBD0@Z");
152 SET(p_tr2_sys__Rename_wchar
,
153 "?_Rename@sys@tr2@std@@YAHPEB_W0@Z");
154 SET(p_tr2_sys__Statvfs
,
155 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PEBD@Z");
157 "?_Stat@sys@tr2@std@@YA?AW4file_type@123@PEBDAEAH@Z");
158 SET(p_tr2_sys__Lstat
,
159 "?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PEBDAEAH@Z");
161 SET(p_tr2_sys__File_size
,
162 "?_File_size@sys@tr2@std@@YA_KPBD@Z");
163 SET(p_tr2_sys__File_size_wchar
,
164 "?_File_size@sys@tr2@std@@YA_KPB_W@Z");
165 SET(p_tr2_sys__Equivalent
,
166 "?_Equivalent@sys@tr2@std@@YAHPBD0@Z");
167 SET(p_tr2_sys__Equivalent_wchar
,
168 "?_Equivalent@sys@tr2@std@@YAHPB_W0@Z");
169 SET(p_tr2_sys__Current_get
,
170 "?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z");
171 SET(p_tr2_sys__Current_get_wchar
,
172 "?_Current_get@sys@tr2@std@@YAPA_WAAY0BAE@_W@Z");
173 SET(p_tr2_sys__Current_set
,
174 "?_Current_set@sys@tr2@std@@YA_NPBD@Z");
175 SET(p_tr2_sys__Current_set_wchar
,
176 "?_Current_set@sys@tr2@std@@YA_NPB_W@Z");
177 SET(p_tr2_sys__Make_dir
,
178 "?_Make_dir@sys@tr2@std@@YAHPBD@Z");
179 SET(p_tr2_sys__Make_dir_wchar
,
180 "?_Make_dir@sys@tr2@std@@YAHPB_W@Z");
181 SET(p_tr2_sys__Remove_dir
,
182 "?_Remove_dir@sys@tr2@std@@YA_NPBD@Z");
183 SET(p_tr2_sys__Remove_dir_wchar
,
184 "?_Remove_dir@sys@tr2@std@@YA_NPB_W@Z");
185 SET(p_tr2_sys__Copy_file
,
186 "?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z");
187 SET(p_tr2_sys__Copy_file_wchar
,
188 "?_Copy_file@sys@tr2@std@@YAHPB_W0_N@Z");
189 SET(p_tr2_sys__Rename
,
190 "?_Rename@sys@tr2@std@@YAHPBD0@Z");
191 SET(p_tr2_sys__Rename_wchar
,
192 "?_Rename@sys@tr2@std@@YAHPB_W0@Z");
193 SET(p_tr2_sys__Statvfs
,
194 "?_Statvfs@sys@tr2@std@@YA?AUspace_info@123@PBD@Z");
196 "?_Stat@sys@tr2@std@@YA?AW4file_type@123@PBDAAH@Z");
197 SET(p_tr2_sys__Lstat
,
198 "?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PBDAAH@Z");
201 msvcr
= GetModuleHandleA("msvcr120.dll");
202 p_setlocale
= (void*)GetProcAddress(msvcr
, "setlocale");
203 p__setmbcp
= (void*)GetProcAddress(msvcr
, "_setmbcp");
204 p_isleadbyte
= (void*)GetProcAddress(msvcr
, "isleadbyte");
208 static void test__Xtime_diff_to_millis2(void)
211 __time64_t sec_before
;
212 MSVCRT_long nsec_before
;
213 __time64_t sec_after
;
214 MSVCRT_long nsec_after
;
218 {0, 1000000000, 0, 2000000000, 1000},
219 {1, 100000000, 2, 100000000, 1000},
220 {1, 100000000, 1, 200000000, 100},
221 {0, 0, 0, 1000000000, 1000},
222 {0, 0, 0, 1200000000, 1200},
223 {0, 0, 0, 1230000000, 1230},
224 {0, 0, 0, 1234000000, 1234},
225 {0, 0, 0, 1234100000, 1235},
226 {0, 0, 0, 1234900000, 1235},
227 {0, 0, 0, 1234010000, 1235},
228 {0, 0, 0, 1234090000, 1235},
229 {0, 0, 0, 1234000001, 1235},
230 {0, 0, 0, 1234000009, 1235},
232 {0, 0, 0, -10000000, 0},
233 {0, 0, -1, -100000000, 0},
235 {0, -100000000, 0, 0, 100},
236 {-1, -100000000, 0, 0, 1100},
237 {0, 0, -1, 2000000000, 1000},
238 {0, 0, -2, 2000000000, 0},
239 {0, 0, -2, 2100000000, 100}
245 for(i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++ i
)
247 t1
.sec
= tests
[i
].sec_before
;
248 t1
.nsec
= tests
[i
].nsec_before
;
249 t2
.sec
= tests
[i
].sec_after
;
250 t2
.nsec
= tests
[i
].nsec_after
;
251 ret
= p__Xtime_diff_to_millis2(&t2
, &t1
);
252 ok(ret
== tests
[i
].expect
,
253 "_Xtime_diff_to_millis2(): test: %d expect: %d, got: %d\n",
254 i
, tests
[i
].expect
, ret
);
258 static void test_xtime_get(void)
260 static const MSVCRT_long tests
[] = {1, 50, 100, 200, 500};
265 for(i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
267 p_xtime_get(&before
, 1);
269 p_xtime_get(&after
, 1);
271 diff
= p__Xtime_diff_to_millis2(&after
, &before
);
274 "xtime_get() not functioning correctly, test: %d, expect: ge %d, got: %d\n",
278 /* Test parameter and return value */
279 before
.sec
= 0xdeadbeef, before
.nsec
= 0xdeadbeef;
280 i
= p_xtime_get(&before
, 0);
281 ok(i
== 0, "expect xtime_get() to return 0, got: %d\n", i
);
282 ok(before
.sec
== 0xdeadbeef && before
.nsec
== 0xdeadbeef,
283 "xtime_get() shouldn't have modified the xtime struct with the given option\n");
285 before
.sec
= 0xdeadbeef, before
.nsec
= 0xdeadbeef;
286 i
= p_xtime_get(&before
, 1);
287 ok(i
== 1, "expect xtime_get() to return 1, got: %d\n", i
);
288 ok(before
.sec
!= 0xdeadbeef && before
.nsec
!= 0xdeadbeef,
289 "xtime_get() should have modified the xtime struct with the given option\n");
292 static void test__Getcvt(void)
298 ok(cvtvec
.page
== 0, "cvtvec.page = %d\n", cvtvec
.page
);
299 ok(cvtvec
.mb_max
== 1, "cvtvec.mb_max = %d\n", cvtvec
.mb_max
);
300 todo_wine
ok(cvtvec
.unk
== 1, "cvtvec.unk = %d\n", cvtvec
.unk
);
302 ok(cvtvec
.isleadbyte
[i
] == 0, "cvtvec.isleadbyte[%d] = %x\n", i
, cvtvec
.isleadbyte
[i
]);
304 if(!p_setlocale(LC_ALL
, ".936")) {
305 win_skip("_Getcvt tests\n");
309 ok(cvtvec
.page
== 936, "cvtvec.page = %d\n", cvtvec
.page
);
310 ok(cvtvec
.mb_max
== 2, "cvtvec.mb_max = %d\n", cvtvec
.mb_max
);
311 ok(cvtvec
.unk
== 0, "cvtvec.unk = %d\n", cvtvec
.unk
);
313 ok(cvtvec
.isleadbyte
[i
] == 0, "cvtvec.isleadbyte[%d] = %x\n", i
, cvtvec
.isleadbyte
[i
]);
317 ok(cvtvec
.page
== 936, "cvtvec.page = %d\n", cvtvec
.page
);
318 ok(cvtvec
.mb_max
== 2, "cvtvec.mb_max = %d\n", cvtvec
.mb_max
);
319 ok(cvtvec
.unk
== 0, "cvtvec.unk = %d\n", cvtvec
.unk
);
320 for(i
=0; i
<32; i
++) {
325 b
|= (p_isleadbyte(i
*8+j
) ? 1 : 0) << j
;
326 ok(cvtvec
.isleadbyte
[i
] ==b
, "cvtvec.isleadbyte[%d] = %x (%x)\n", i
, cvtvec
.isleadbyte
[i
], b
);
333 static void __cdecl
call_once_func(void)
335 ok(!once
, "once != 0\n");
339 static void __cdecl
call_once_ex_func(void *arg
)
343 ok(!once
, "once != 0\n");
347 static DWORD WINAPI
call_once_thread(void *arg
)
349 p__Call_once(&once
, call_once_func
);
353 static DWORD WINAPI
call_once_ex_thread(void *arg
)
355 p__Call_onceEx(&once
, call_once_ex_func
, &cnt
);
359 static void test__Call_once(void)
365 h
[i
] = CreateThread(NULL
, 0, call_once_thread
, &once
, 0, NULL
);
366 ok(WaitForMultipleObjects(4, h
, TRUE
, INFINITE
) == WAIT_OBJECT_0
,
367 "error waiting for all threads to finish\n");
368 ok(cnt
== 0x10000, "cnt = %x\n", cnt
);
369 ok(once
== 1, "once = %x\n", once
);
373 h
[i
] = CreateThread(NULL
, 0, call_once_ex_thread
, &once
, 0, NULL
);
374 ok(WaitForMultipleObjects(4, h
, TRUE
, INFINITE
) == WAIT_OBJECT_0
,
375 "error waiting for all threads to finish\n");
376 ok(cnt
== 1, "cnt = %x\n", cnt
);
377 ok(once
== 1, "once = %x\n", once
);
380 static void **vtbl_func0
;
382 /* TODO: this should be a __thiscall function */
383 static void __stdcall
thiscall_func(void)
388 static void __cdecl
thiscall_func(void *this)
390 ok(this == &vtbl_func0
, "incorrect this value\n");
395 static void test__Do_call(void)
397 void *pfunc
= thiscall_func
;
401 p__Do_call(&vtbl_func0
);
402 ok(cnt
== 1, "func was not called\n");
405 static void test_tr2_sys__File_size(void)
409 LARGE_INTEGER file_size
;
410 WCHAR testW
[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
411 CreateDirectoryA("tr2_test_dir", NULL
);
413 file
= CreateFileA("tr2_test_dir/f1", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
414 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
415 file_size
.QuadPart
= 7;
416 ok(SetFilePointerEx(file
, file_size
, NULL
, FILE_BEGIN
), "SetFilePointerEx failed\n");
417 ok(SetEndOfFile(file
), "SetEndOfFile failed\n");
419 val
= p_tr2_sys__File_size("tr2_test_dir/f1");
420 ok(val
== 7, "file_size is %s\n", debugstr_longlong(val
));
421 val
= p_tr2_sys__File_size_wchar(testW
);
422 ok(val
== 7, "file_size is %s\n", debugstr_longlong(val
));
424 file
= CreateFileA("tr2_test_dir/f2", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
425 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
427 val
= p_tr2_sys__File_size("tr2_test_dir/f2");
428 ok(val
== 0, "file_size is %s\n", debugstr_longlong(val
));
430 val
= p_tr2_sys__File_size("tr2_test_dir");
431 ok(val
== 0, "file_size is %s\n", debugstr_longlong(val
));
434 val
= p_tr2_sys__File_size("tr2_test_dir/not_exists_file");
435 ok(val
== 0, "file_size is %s\n", debugstr_longlong(val
));
436 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
439 val
= p_tr2_sys__File_size(NULL
);
440 ok(val
== 0, "file_size is %s\n", debugstr_longlong(val
));
441 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
443 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
444 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
445 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
448 static void test_tr2_sys__Equivalent(void)
452 char temp_path
[MAX_PATH
], current_path
[MAX_PATH
];
453 WCHAR testW
[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
454 WCHAR testW2
[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','2',0};
463 { "f1", "tr2_test_dir", -1 },
464 { "tr2_test_dir", "f1", -1 },
465 { "tr2_test_dir", "tr2_test_dir", -1 },
466 { "tr2_test_dir/./f1", "tr2_test_dir/f2", 0 },
467 { "tr2_test_dir/f1" , "tr2_test_dir/f1", 1 },
468 { "not_exists_file" , "tr2_test_dir/f1", 0 },
469 { "tr2_test_dir\\f1" , "tr2_test_dir/./f1", 1 },
470 { "not_exists_file" , "not_exists_file", -1 },
471 { "tr2_test_dir/f1" , "not_exists_file", 0 },
472 { "tr2_test_dir/../tr2_test_dir/f1", "tr2_test_dir/f1", 1 }
475 memset(current_path
, 0, MAX_PATH
);
476 GetCurrentDirectoryA(MAX_PATH
, current_path
);
477 memset(temp_path
, 0, MAX_PATH
);
478 GetTempPathA(MAX_PATH
, temp_path
);
479 ok(SetCurrentDirectoryA(temp_path
), "SetCurrentDirectoryA to temp_path failed\n");
480 CreateDirectoryA("tr2_test_dir", NULL
);
482 file
= CreateFileA("tr2_test_dir/f1", 0, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
483 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
485 file
= CreateFileA("tr2_test_dir/f2", 0, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
486 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
489 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
491 val
= p_tr2_sys__Equivalent(tests
[i
].path1
, tests
[i
].path2
);
492 ok(tests
[i
].equivalent
== val
, "tr2_sys__Equivalent(): test %d expect: %d, got %d\n", i
+1, tests
[i
].equivalent
, val
);
493 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
496 val
= p_tr2_sys__Equivalent_wchar(testW
, testW
);
497 ok(val
== 1, "tr2_sys__Equivalent(): expect: 1, got %d\n", val
);
498 val
= p_tr2_sys__Equivalent_wchar(testW
, testW2
);
499 ok(val
== 0, "tr2_sys__Equivalent(): expect: 0, got %d\n", val
);
501 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
502 ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
503 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
504 ok(SetCurrentDirectoryA(current_path
), "SetCurrentDirectoryA failed\n");
507 static void test_tr2_sys__Current_get(void)
509 char temp_path
[MAX_PATH
], current_path
[MAX_PATH
], origin_path
[MAX_PATH
];
511 WCHAR temp_path_wchar
[MAX_PATH
], current_path_wchar
[MAX_PATH
];
513 memset(origin_path
, 0, MAX_PATH
);
514 GetCurrentDirectoryA(MAX_PATH
, origin_path
);
515 memset(temp_path
, 0, MAX_PATH
);
516 GetTempPathA(MAX_PATH
, temp_path
);
518 ok(SetCurrentDirectoryA(temp_path
), "SetCurrentDirectoryA to temp_path failed\n");
519 memset(current_path
, 0, MAX_PATH
);
520 temp
= p_tr2_sys__Current_get(current_path
);
521 ok(temp
== current_path
, "p_tr2_sys__Current_get returned different buffer\n");
522 temp
[strlen(temp
)] = '\\';
523 ok(!strcmp(temp_path
, current_path
), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path
, current_path
);
525 GetTempPathW(MAX_PATH
, temp_path_wchar
);
526 ok(SetCurrentDirectoryW(temp_path_wchar
), "SetCurrentDirectoryW to temp_path_wchar failed\n");
527 memset(current_path_wchar
, 0, MAX_PATH
);
528 temp_wchar
= p_tr2_sys__Current_get_wchar(current_path_wchar
);
529 ok(temp_wchar
== current_path_wchar
, "p_tr2_sys__Current_get_wchar returned different buffer\n");
530 temp_wchar
[wcslen(temp_wchar
)] = '\\';
531 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
));
533 ok(SetCurrentDirectoryA(origin_path
), "SetCurrentDirectoryA to origin_path failed\n");
534 memset(current_path
, 0, MAX_PATH
);
535 temp
= p_tr2_sys__Current_get(current_path
);
536 ok(temp
== current_path
, "p_tr2_sys__Current_get returned different buffer\n");
537 ok(!strcmp(origin_path
, current_path
), "test_tr2_sys__Current_get(): expect: %s, got %s\n", origin_path
, current_path
);
540 static void test_tr2_sys__Current_set(void)
542 char temp_path
[MAX_PATH
], current_path
[MAX_PATH
], origin_path
[MAX_PATH
];
544 WCHAR testW
[] = {'.','/',0};
545 memset(temp_path
, 0, MAX_PATH
);
546 GetTempPathA(MAX_PATH
, temp_path
);
547 memset(origin_path
, 0, MAX_PATH
);
548 GetCurrentDirectoryA(MAX_PATH
, origin_path
);
549 temp
= p_tr2_sys__Current_get(origin_path
);
550 ok(temp
== origin_path
, "p_tr2_sys__Current_get returned different buffer\n");
552 ok(p_tr2_sys__Current_set(temp_path
), "p_tr2_sys__Current_set to temp_path failed\n");
553 memset(current_path
, 0, MAX_PATH
);
554 temp
= p_tr2_sys__Current_get(current_path
);
555 ok(temp
== current_path
, "p_tr2_sys__Current_get returned different buffer\n");
556 temp
[strlen(temp
)] = '\\';
557 ok(!strcmp(temp_path
, current_path
), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path
, current_path
);
559 ok(p_tr2_sys__Current_set_wchar(testW
), "p_tr2_sys__Current_set_wchar to temp_path failed\n");
560 memset(current_path
, 0, MAX_PATH
);
561 temp
= p_tr2_sys__Current_get(current_path
);
562 ok(temp
== current_path
, "p_tr2_sys__Current_get returned different buffer\n");
563 temp
[strlen(temp
)] = '\\';
564 ok(!strcmp(temp_path
, current_path
), "test_tr2_sys__Current_get(): expect: %s, got %s\n", temp_path
, current_path
);
567 ok(!p_tr2_sys__Current_set("not_exisist_dir"), "p_tr2_sys__Current_set to not_exist_dir succeed\n");
568 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
571 ok(!p_tr2_sys__Current_set("??invalid_name>>"), "p_tr2_sys__Current_set to ??invalid_name>> succeed\n");
572 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
574 ok(p_tr2_sys__Current_set(origin_path
), "p_tr2_sys__Current_set to origin_path failed\n");
575 memset(current_path
, 0, MAX_PATH
);
576 temp
= p_tr2_sys__Current_get(current_path
);
577 ok(temp
== current_path
, "p_tr2_sys__Current_get returned different buffer\n");
578 ok(!strcmp(origin_path
, current_path
), "test_tr2_sys__Current_get(): expect: %s, got %s\n", origin_path
, current_path
);
581 static void test_tr2_sys__Make_dir(void)
584 WCHAR testW
[] = {'w','d',0};
589 { "tr2_test_dir", 1 },
590 { "tr2_test_dir", 0 },
592 { "??invalid_name>>", -1 }
595 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
597 ret
= p_tr2_sys__Make_dir(tests
[i
].path
);
598 ok(ret
== tests
[i
].val
, "tr2_sys__Make_dir(): test %d expect: %d, got %d\n", i
+1, tests
[i
].val
, ret
);
599 ok(errno
== 0xdeadbeef, "tr2_sys__Make_dir(): test %d errno expect 0xdeadbeef, got %d\n", i
+1, errno
);
601 ret
= p_tr2_sys__Make_dir_wchar(testW
);
602 ok(ret
== 1, "tr2_sys__Make_dir(): expect: 1, got %d\n", ret
);
604 ok(p_tr2_sys__Remove_dir("tr2_test_dir"), "expect tr2_test_dir to exist\n");
605 ok(p_tr2_sys__Remove_dir_wchar(testW
), "expect wd to exist\n");
608 static void test_tr2_sys__Remove_dir(void)
616 { "tr2_test_dir", TRUE
},
617 { "tr2_test_dir", FALSE
},
619 { "??invalid_name>>", FALSE
}
622 ok(p_tr2_sys__Make_dir("tr2_test_dir"), "tr2_sys__Make_dir() failed\n");
624 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
626 ret
= p_tr2_sys__Remove_dir(tests
[i
].path
);
627 ok(ret
== tests
[i
].val
, "test_tr2_sys__Remove_dir(): test %d expect: %d, got %d\n", i
+1, tests
[i
].val
, ret
);
628 ok(errno
== 0xdeadbeef, "test_tr2_sys__Remove_dir(): test %d errno expect 0xdeadbeef, got %d\n", i
+1, errno
);
632 static void test_tr2_sys__Copy_file(void)
636 LARGE_INTEGER file_size
;
637 WCHAR testW
[] = {'f','1',0}, testW2
[] = {'f','w',0};
641 MSVCP_bool fail_if_exists
;
646 { "f1", "f1_copy", TRUE
, ERROR_SUCCESS
, ERROR_SUCCESS
, FALSE
},
647 { "f1", "tr2_test_dir\\f1_copy", TRUE
, ERROR_SUCCESS
, ERROR_SUCCESS
, FALSE
},
648 { "f1", "tr2_test_dir\\f1_copy", TRUE
, ERROR_FILE_EXISTS
, ERROR_FILE_EXISTS
, FALSE
},
649 { "f1", "tr2_test_dir\\f1_copy", FALSE
, ERROR_SUCCESS
, ERROR_SUCCESS
, FALSE
},
650 { "tr2_test_dir", "f1", TRUE
, ERROR_ACCESS_DENIED
, ERROR_ACCESS_DENIED
, FALSE
},
651 { "tr2_test_dir", "tr2_test_dir_copy", TRUE
, ERROR_ACCESS_DENIED
, ERROR_ACCESS_DENIED
, FALSE
},
652 { NULL
, "f1", TRUE
, ERROR_INVALID_PARAMETER
, ERROR_INVALID_PARAMETER
, TRUE
},
653 { "f1", NULL
, TRUE
, ERROR_INVALID_PARAMETER
, ERROR_INVALID_PARAMETER
, TRUE
},
654 { "not_exist", "tr2_test_dir", TRUE
, ERROR_FILE_NOT_FOUND
, ERROR_FILE_NOT_FOUND
, FALSE
},
655 { "f1", "not_exist_dir\\f1_copy", TRUE
, ERROR_PATH_NOT_FOUND
, ERROR_FILE_NOT_FOUND
, FALSE
},
656 { "f1", "tr2_test_dir", TRUE
, ERROR_ACCESS_DENIED
, ERROR_FILE_EXISTS
, FALSE
}
659 ret
= p_tr2_sys__Make_dir("tr2_test_dir");
660 ok(ret
== 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret
);
661 file
= CreateFileA("f1", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
662 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
663 file_size
.QuadPart
= 7;
664 ok(SetFilePointerEx(file
, file_size
, NULL
, FILE_BEGIN
), "SetFilePointerEx failed\n");
665 ok(SetEndOfFile(file
), "SetEndOfFile failed\n");
668 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
670 ret
= p_tr2_sys__Copy_file(tests
[i
].source
, tests
[i
].dest
, tests
[i
].fail_if_exists
);
672 todo_wine
ok(ret
== tests
[i
].last_error
|| ret
== tests
[i
].last_error2
,
673 "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n",
674 i
+1, tests
[i
].last_error
, ret
);
676 ok(ret
== tests
[i
].last_error
|| ret
== tests
[i
].last_error2
,
677 "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n",
678 i
+1, tests
[i
].last_error
, ret
);
679 ok(errno
== 0xdeadbeef, "test_tr2_sys__Copy_file(): test %d errno expect 0xdeadbeef, got %d\n", i
+1, errno
);
680 if(ret
== ERROR_SUCCESS
)
681 ok(p_tr2_sys__File_size(tests
[i
].source
) == p_tr2_sys__File_size(tests
[i
].dest
),
682 "test_tr2_sys__Copy_file(): test %d failed, two files' size are not equal\n", i
+1);
684 ret
= p_tr2_sys__Copy_file_wchar(testW
, testW2
, TRUE
);
685 ok(ret
== ERROR_SUCCESS
, "test_tr2_sys__Copy_file_wchar() expect ERROR_SUCCESS, got %d\n", ret
);
687 ok(DeleteFileA("f1"), "expect f1 to exist\n");
688 ok(DeleteFileW(testW2
), "expect fw to exist\n");
689 ok(DeleteFileA("f1_copy"), "expect f1_copy to exist\n");
690 ok(DeleteFileA("tr2_test_dir/f1_copy"), "expect tr2_test_dir/f1 to exist\n");
691 ret
= p_tr2_sys__Remove_dir("tr2_test_dir");
692 ok(ret
== 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret
);
695 static void test_tr2_sys__Rename(void)
699 BY_HANDLE_FILE_INFORMATION info1
, info2
;
700 char temp_path
[MAX_PATH
], current_path
[MAX_PATH
];
701 LARGE_INTEGER file_size
;
702 WCHAR testW
[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
703 WCHAR testW2
[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','w',0};
705 char const *old_path
;
706 char const *new_path
;
709 { "tr2_test_dir\\f1", "tr2_test_dir\\f1_rename", ERROR_SUCCESS
},
710 { "tr2_test_dir\\f1", NULL
, ERROR_INVALID_PARAMETER
},
711 { "tr2_test_dir\\f1", "tr2_test_dir\\f1_rename", ERROR_FILE_NOT_FOUND
},
712 { NULL
, "tr2_test_dir\\NULL_rename", ERROR_INVALID_PARAMETER
},
713 { "tr2_test_dir\\f1_rename", "tr2_test_dir\\??invalid_name>>", ERROR_INVALID_NAME
},
714 { "tr2_test_dir\\not_exist_file", "tr2_test_dir\\not_exist_rename", ERROR_FILE_NOT_FOUND
}
717 memset(current_path
, 0, MAX_PATH
);
718 GetCurrentDirectoryA(MAX_PATH
, current_path
);
719 memset(temp_path
, 0, MAX_PATH
);
720 GetTempPathA(MAX_PATH
, temp_path
);
721 ok(SetCurrentDirectoryA(temp_path
), "SetCurrentDirectoryA to temp_path failed\n");
722 ret
= p_tr2_sys__Make_dir("tr2_test_dir");
724 ok(ret
== 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret
);
725 file
= CreateFileA("tr2_test_dir\\f1", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
726 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
729 ret
= p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1");
730 todo_wine
ok(ERROR_SUCCESS
== ret
, "test_tr2_sys__Rename(): expect: ERROR_SUCCESS, got %d\n", ret
);
731 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
733 if(tests
[i
].val
== ERROR_SUCCESS
) {
734 h1
= CreateFileA(tests
[i
].old_path
, 0, FILE_SHARE_DELETE
| FILE_SHARE_READ
| FILE_SHARE_WRITE
,
735 NULL
, OPEN_EXISTING
, 0, 0);
736 ok(h1
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
737 ok(GetFileInformationByHandle(h1
, &info1
), "GetFileInformationByHandle failed\n");
740 SetLastError(0xdeadbeef);
741 ret
= p_tr2_sys__Rename(tests
[i
].old_path
, tests
[i
].new_path
);
742 ok(ret
== tests
[i
].val
, "test_tr2_sys__Rename(): test %d expect: %d, got %d\n", i
+1, tests
[i
].val
, ret
);
743 ok(errno
== 0xdeadbeef, "test_tr2_sys__Rename(): test %d errno expect 0xdeadbeef, got %d\n", i
+1, errno
);
744 if(ret
== ERROR_SUCCESS
) {
745 h2
= CreateFileA(tests
[i
].new_path
, 0, FILE_SHARE_DELETE
| FILE_SHARE_READ
| FILE_SHARE_WRITE
,
746 NULL
, OPEN_EXISTING
, 0, 0);
747 ok(h2
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
748 ok(GetFileInformationByHandle(h2
, &info2
), "GetFileInformationByHandle failed\n");
750 ok(info1
.nFileIndexHigh
== info2
.nFileIndexHigh
751 && info1
.nFileIndexLow
== info2
.nFileIndexLow
,
752 "test_tr2_sys__Rename(): test %d expect two files equivalent\n", i
+1);
756 file
= CreateFileA("tr2_test_dir\\f1", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
757 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
758 file_size
.QuadPart
= 7;
759 ok(SetFilePointerEx(file
, file_size
, NULL
, FILE_BEGIN
), "SetFilePointerEx failed\n");
760 ok(SetEndOfFile(file
), "SetEndOfFile failed\n");
762 ret
= p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1_rename");
763 ok(ret
== ERROR_ALREADY_EXISTS
, "test_tr2_sys__Rename(): expect: ERROR_ALREADY_EXISTS, got %d\n", ret
);
764 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")));
765 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")));
766 ret
= p_tr2_sys__Rename_wchar(testW
, testW2
);
767 ok(ret
== ERROR_SUCCESS
, "tr2_sys__Rename_wchar(): expect: ERROR_SUCCESS, got %d\n", ret
);
769 ok(DeleteFileW(testW2
), "expect fw to exist\n");
770 ok(DeleteFileA("tr2_test_dir\\f1_rename"), "expect f1_rename to exist\n");
771 ret
= p_tr2_sys__Remove_dir("tr2_test_dir");
772 ok(ret
== 1, "test_tr2_sys__Remove_dir(): expect %d got %d\n", 1, ret
);
773 ok(SetCurrentDirectoryA(current_path
), "SetCurrentDirectoryA failed\n");
776 static void test_tr2_sys__Statvfs(void)
778 struct space_info info
;
779 char current_path
[MAX_PATH
];
780 memset(current_path
, 0, MAX_PATH
);
781 p_tr2_sys__Current_get(current_path
);
783 info
= p_tr2_sys__Statvfs(current_path
);
784 ok(info
.capacity
>= info
.free
, "test_tr2_sys__Statvfs(): info.capacity < info.free\n");
785 ok(info
.free
>= info
.available
, "test_tr2_sys__Statvfs(): info.free < info.available\n");
787 info
= p_tr2_sys__Statvfs(NULL
);
788 ok(info
.available
== 0, "test_tr2_sys__Statvfs(): info.available expect: %d, got %s\n",
789 0, debugstr_longlong(info
.available
));
790 ok(info
.capacity
== 0, "test_tr2_sys__Statvfs(): info.capacity expect: %d, got %s\n",
791 0, debugstr_longlong(info
.capacity
));
792 ok(info
.free
== 0, "test_tr2_sys__Statvfs(): info.free expect: %d, got %s\n",
793 0, debugstr_longlong(info
.free
));
795 info
= p_tr2_sys__Statvfs("not_exist");
796 ok(info
.available
== 0, "test_tr2_sys__Statvfs(): info.available expect: %d, got %s\n",
797 0, debugstr_longlong(info
.available
));
798 ok(info
.capacity
== 0, "test_tr2_sys__Statvfs(): info.capacity expect: %d, got %s\n",
799 0, debugstr_longlong(info
.capacity
));
800 ok(info
.free
== 0, "test_tr2_sys__Statvfs(): info.free expect: %d, got %s\n",
801 0, debugstr_longlong(info
.free
));
804 static void test_tr2_sys__Stat(void)
806 int i
, err_code
, ret
;
815 { NULL
, status_unknown
, ERROR_INVALID_PARAMETER
, FALSE
},
816 { "tr2_test_dir", directory_file
, ERROR_SUCCESS
, FALSE
},
817 { "tr2_test_dir\\f1", regular_file
, ERROR_SUCCESS
, FALSE
},
818 { "tr2_test_dir\\not_exist_file ", file_not_found
, ERROR_SUCCESS
, FALSE
},
819 { "tr2_test_dir\\??invalid_name>>", file_not_found
, ERROR_SUCCESS
, FALSE
},
820 { "tr2_test_dir\\f1_link" , regular_file
, ERROR_SUCCESS
, TRUE
},
821 { "tr2_test_dir\\dir_link", directory_file
, ERROR_SUCCESS
, TRUE
},
824 CreateDirectoryA("tr2_test_dir", NULL
);
825 file
= CreateFileA("tr2_test_dir/f1", 0, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
826 ok(file
!= INVALID_HANDLE_VALUE
, "create file failed: INVALID_HANDLE_VALUE\n");
827 ok(CloseHandle(file
), "CloseHandle\n");
828 SetLastError(0xdeadbeef);
829 ret
= CreateSymbolicLinkA("tr2_test_dir/f1_link", "tr2_test_dir/f1", 0);
830 if(!ret
&& (GetLastError()==ERROR_PRIVILEGE_NOT_HELD
||GetLastError()==ERROR_INVALID_FUNCTION
)) {
831 tests
[5].ret
= tests
[6].ret
= file_not_found
;
832 win_skip("Privilege not held or symbolic link not supported, skipping symbolic link tests.\n");
834 ok(ret
, "CreateSymbolicLinkA failed\n");
835 ok(CreateSymbolicLinkA("tr2_test_dir/dir_link", "tr2_test_dir", 1), "CreateSymbolicLinkA failed\n");
838 file
= CreateNamedPipeA("\\\\.\\PiPe\\tests_pipe.c",
839 PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
, 2, 1024, 1024,
840 NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
841 ok(file
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
842 err_code
= 0xdeadbeef;
843 val
= p_tr2_sys__Stat("\\\\.\\PiPe\\tests_pipe.c", &err_code
);
844 todo_wine
ok(regular_file
== val
, "tr2_sys__Stat(): expect: regular_file, got %d\n", val
);
845 todo_wine
ok(ERROR_SUCCESS
== err_code
, "tr2_sys__Stat(): err_code expect: ERROR_SUCCESS, got %d\n", err_code
);
846 err_code
= 0xdeadbeef;
847 val
= p_tr2_sys__Lstat("\\\\.\\PiPe\\tests_pipe.c", &err_code
);
848 ok(status_unknown
== val
, "tr2_sys__Lstat(): expect: status_unknown, got %d\n", val
);
849 todo_wine
ok(ERROR_PIPE_BUSY
== err_code
, "tr2_sys__Lstat(): err_code expect: ERROR_PIPE_BUSY, got %d\n", err_code
);
850 ok(CloseHandle(file
), "CloseHandle\n");
851 file
= CreateNamedPipeA("\\\\.\\PiPe\\tests_pipe.c",
852 PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
, 2, 1024, 1024,
853 NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
854 ok(file
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
855 err_code
= 0xdeadbeef;
856 val
= p_tr2_sys__Lstat("\\\\.\\PiPe\\tests_pipe.c", &err_code
);
857 todo_wine
ok(regular_file
== val
, "tr2_sys__Lstat(): expect: regular_file, got %d\n", val
);
858 todo_wine
ok(ERROR_SUCCESS
== err_code
, "tr2_sys__Lstat(): err_code expect: ERROR_SUCCESS, got %d\n", err_code
);
859 ok(CloseHandle(file
), "CloseHandle\n");
861 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
862 err_code
= 0xdeadbeef;
863 val
= p_tr2_sys__Stat(tests
[i
].path
, &err_code
);
865 todo_wine
ok(tests
[i
].ret
== val
, "tr2_sys__Stat(): test %d expect: %d, got %d\n",
866 i
+1, tests
[i
].ret
, val
);
868 ok(tests
[i
].ret
== val
, "tr2_sys__Stat(): test %d expect: %d, got %d\n", i
+1, tests
[i
].ret
, val
);
869 ok(tests
[i
].err_code
== err_code
, "tr2_sys__Stat(): test %d err_code expect: %d, got %d\n",
870 i
+1, tests
[i
].err_code
, err_code
);
872 /* test tr2_sys__Lstat */
873 err_code
= 0xdeadbeef;
874 val
= p_tr2_sys__Lstat(tests
[i
].path
, &err_code
);
876 todo_wine
ok(tests
[i
].ret
== val
, "tr2_sys__Lstat(): test %d expect: %d, got %d\n",
877 i
+1, tests
[i
].ret
, val
);
879 ok(tests
[i
].ret
== val
, "tr2_sys__Lstat(): test %d expect: %d, got %d\n", i
+1, tests
[i
].ret
, val
);
881 ok(tests
[i
].err_code
== err_code
, "tr2_sys__Lstat(): test %d err_code expect: %d, got %d\n",
882 i
+1, tests
[i
].err_code
, err_code
);
886 todo_wine
ok(DeleteFileA("tr2_test_dir/f1_link"), "expect tr2_test_dir/f1_link to exist\n");
887 todo_wine
ok(RemoveDirectoryA("tr2_test_dir/dir_link"), "expect tr2_test_dir/dir_link to exist\n");
889 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
890 ok(RemoveDirectoryA("tr2_test_dir"), "expect tr2_test_dir to exist\n");
896 test__Xtime_diff_to_millis2();
902 test_tr2_sys__File_size();
903 test_tr2_sys__Equivalent();
904 test_tr2_sys__Current_get();
905 test_tr2_sys__Current_set();
906 test_tr2_sys__Make_dir();
907 test_tr2_sys__Remove_dir();
908 test_tr2_sys__Copy_file();
909 test_tr2_sys__Rename();
910 test_tr2_sys__Statvfs();
911 test_tr2_sys__Stat();