Commit 7692d400 authored by YongHao Hu's avatar YongHao Hu Committed by Alexandre Julliard

msvcp110: Add tr2_sys__Copy_file implementation and test.

parent 372b0e1e
......@@ -1163,8 +1163,8 @@
@ extern -arch=win64 ?_Clocptr@_Locimp@locale@std@@0PEAV123@EA locale__Locimp__Clocptr
@ stub -arch=win32 ?_Close_dir@sys@tr2@std@@YAXPAX@Z
@ stub -arch=win64 ?_Close_dir@sys@tr2@std@@YAXPEAX@Z
@ stub -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z
@ stub -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z
@ cdecl -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z(str str long) tr2_sys__Copy_file
@ cdecl -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z(str str long) tr2_sys__Copy_file
@ stub -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPB_W0_N@Z
@ stub -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEB_W0_N@Z
@ cdecl -arch=win32 ?_Current_get@sys@tr2@std@@YAPADPAD@Z(ptr) tr2_sys__Current_get
......
......@@ -1128,8 +1128,8 @@
@ extern -arch=win64 ?_Clocptr@_Locimp@locale@std@@0PEAV123@EA locale__Locimp__Clocptr
@ stub -arch=win32 ?_Close_dir@sys@tr2@std@@YAXPAX@Z
@ stub -arch=win64 ?_Close_dir@sys@tr2@std@@YAXPEAX@Z
@ stub -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z
@ stub -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z
@ cdecl -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z(str str long) tr2_sys__Copy_file
@ cdecl -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z(str str long) tr2_sys__Copy_file
@ stub -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPB_W0_N@Z
@ stub -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEB_W0_N@Z
@ cdecl -arch=win32 ?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z(ptr) tr2_sys__Current_get
......
......@@ -66,6 +66,7 @@ static char* (__cdecl *p_tr2_sys__Current_get)(char *);
static MSVCP_bool (__cdecl *p_tr2_sys__Current_set)(char const*);
static int (__cdecl *p_tr2_sys__Make_dir)(char const*);
static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir)(char const*);
static int (__cdecl *p_tr2_sys__Copy_file)(char const*, char const*, MSVCP_bool);
static HMODULE msvcp;
#define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
......@@ -106,6 +107,8 @@ static BOOL init(void)
"?_Make_dir@sys@tr2@std@@YAHPEBD@Z");
SET(p_tr2_sys__Remove_dir,
"?_Remove_dir@sys@tr2@std@@YA_NPEBD@Z");
SET(p_tr2_sys__Copy_file,
"?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z");
} else {
SET(p_tr2_sys__File_size,
"?_File_size@sys@tr2@std@@YA_KPBD@Z");
......@@ -119,6 +122,8 @@ static BOOL init(void)
"?_Make_dir@sys@tr2@std@@YAHPBD@Z");
SET(p_tr2_sys__Remove_dir,
"?_Remove_dir@sys@tr2@std@@YA_NPBD@Z");
SET(p_tr2_sys__Copy_file,
"?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z");
}
msvcr = GetModuleHandleA("msvcr120.dll");
......@@ -329,11 +334,12 @@ static void test_tr2_sys__File_size(void)
{
ULONGLONG val;
HANDLE file;
LARGE_INTEGER file_size = {{7, 0}};
LARGE_INTEGER file_size;
CreateDirectoryA("tr2_test_dir", NULL);
file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
file_size.QuadPart = 7;
ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
ok(SetEndOfFile(file), "SetEndOfFile failed\n");
CloseHandle(file);
......@@ -526,6 +532,60 @@ static void test_tr2_sys__Remove_dir(void)
}
}
static void test_tr2_sys__Copy_file(void)
{
HANDLE file;
int ret, i;
LARGE_INTEGER file_size;
struct {
char const *source;
char const *dest;
MSVCP_bool fail_if_exists;
int last_error;
MSVCP_bool is_todo;
} tests[] = {
{ "f1", "f1_copy", TRUE, ERROR_SUCCESS, FALSE },
{ "f1", "tr2_test_dir\\f1_copy", TRUE, ERROR_SUCCESS, FALSE },
{ "f1", "tr2_test_dir\\f1_copy", TRUE, ERROR_FILE_EXISTS, FALSE },
{ "f1", "tr2_test_dir\\f1_copy", FALSE, ERROR_SUCCESS, FALSE },
{ "f1", "tr2_test_dir", TRUE, ERROR_ACCESS_DENIED, TRUE },
{ "tr2_test_dir", "f1", TRUE, ERROR_ACCESS_DENIED, FALSE },
{ "tr2_test_dir", "tr2_test_dir_copy", TRUE, ERROR_ACCESS_DENIED, FALSE },
{ NULL, "f1", TRUE, ERROR_INVALID_PARAMETER, TRUE },
{ "f1", NULL, TRUE, ERROR_INVALID_PARAMETER, TRUE },
{ "not_exist", "tr2_test_dir", TRUE, ERROR_FILE_NOT_FOUND, FALSE },
{ "f1", "not_exist_dir\\f1_copy", TRUE, ERROR_PATH_NOT_FOUND, FALSE }
};
ret = p_tr2_sys__Make_dir("tr2_test_dir");
ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
file = CreateFileA("f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
file_size.QuadPart = 7;
ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
ok(SetEndOfFile(file), "SetEndOfFile failed\n");
CloseHandle(file);
for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
errno = 0xdeadbeef;
ret = p_tr2_sys__Copy_file(tests[i].source, tests[i].dest, tests[i].fail_if_exists);
if(tests[i].is_todo)
todo_wine ok(ret == tests[i].last_error, "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n", i+1, tests[i].last_error, ret);
else
ok(ret == tests[i].last_error, "test_tr2_sys__Copy_file(): test %d expect: %d, got %d\n", i+1, tests[i].last_error, ret);
ok(errno == 0xdeadbeef, "test_tr2_sys__Copy_file(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
if(ret == ERROR_SUCCESS)
ok(p_tr2_sys__File_size(tests[i].source) == p_tr2_sys__File_size(tests[i].dest),
"test_tr2_sys__Copy_file(): test %d failed, two files' size are not equal\n", i+1);
}
ok(DeleteFileA("f1"), "expect f1 to exist\n");
ok(DeleteFileA("f1_copy"), "expect f1_copy to exist\n");
ok(DeleteFileA("tr2_test_dir/f1_copy"), "expect tr2_test_dir/f1 to exist\n");
ret = p_tr2_sys__Remove_dir("tr2_test_dir");
ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
}
START_TEST(msvcp120)
{
if(!init()) return;
......@@ -541,5 +601,6 @@ START_TEST(msvcp120)
test_tr2_sys__Current_set();
test_tr2_sys__Make_dir();
test_tr2_sys__Remove_dir();
test_tr2_sys__Copy_file();
FreeLibrary(msvcp);
}
......@@ -1128,8 +1128,8 @@
@ extern -arch=win64 ?_Clocptr@_Locimp@locale@std@@0PEAV123@EA msvcp120.?_Clocptr@_Locimp@locale@std@@0PEAV123@EA
@ stub -arch=win32 ?_Close_dir@sys@tr2@std@@YAXPAX@Z
@ stub -arch=win64 ?_Close_dir@sys@tr2@std@@YAXPEAX@Z
@ stub -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z
@ stub -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z
@ cdecl -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z(str str long) msvcp120.?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z
@ cdecl -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z(str str long) msvcp120.?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z
@ stub -arch=win32 ?_Copy_file@sys@tr2@std@@YAHPB_W0_N@Z
@ stub -arch=win64 ?_Copy_file@sys@tr2@std@@YAHPEB_W0_N@Z
@ cdecl -arch=win32 ?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z(ptr) msvcp120.?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z
......
......@@ -14284,6 +14284,17 @@ MSVCP_bool __cdecl tr2_sys__Remove_dir(char const* path)
return RemoveDirectoryA(path) != 0;
}
/* ?_Copy_file@sys@tr2@std@@YAHPBD0_N@Z */
/* ?_Copy_file@sys@tr2@std@@YAHPEBD0_N@Z */
int __cdecl tr2_sys__Copy_file(char const* source, char const* dest, MSVCP_bool fail_if_exists)
{
TRACE("(%s %s %x)\n", debugstr_a(source), debugstr_a(dest), fail_if_exists);
if(CopyFileA(source, dest, fail_if_exists))
return ERROR_SUCCESS;
return GetLastError();
}
/* ??0strstream@std@@QAE@PADHH@Z */
/* ??0strstream@std@@QEAA@PEAD_JH@Z */
#if STREAMSIZE_BITS == 64
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment