kernel32/tests: Additional tests for CopyFile/MoveFile used on mapped files.

This commit is contained in:
Michael Martin 2009-11-01 09:20:13 +00:00 committed by Alexandre Julliard
parent 59bb360a5d
commit 39d8f13785
1 changed files with 70 additions and 0 deletions

View File

@ -563,6 +563,7 @@ static void test_CopyFileA(void)
char source[MAX_PATH], dest[MAX_PATH]; char source[MAX_PATH], dest[MAX_PATH];
static const char prefix[] = "pfx"; static const char prefix[] = "pfx";
HANDLE hfile; HANDLE hfile;
HANDLE hmapfile;
FILETIME ft1, ft2; FILETIME ft1, ft2;
char buf[10]; char buf[10];
DWORD ret; DWORD ret;
@ -628,6 +629,32 @@ static void test_CopyFileA(void)
ok( retok && ret == sizeof(prefix), ok( retok && ret == sizeof(prefix),
"ReadFile: error %d\n", GetLastError()); "ReadFile: error %d\n", GetLastError());
ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n"); ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n");
/* check error on copying over a mapped file that was opened with FILE_SHARE_READ */
hmapfile = CreateFileMapping(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
ret = CopyFileA(source, dest, FALSE);
ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION,
"CopyFileA with mapped dest file: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
CloseHandle(hmapfile);
CloseHandle(hfile);
hfile = CreateFileA(dest, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
/* check error on copying over a mapped file that was opened with FILE_SHARE_WRITE */
hmapfile = CreateFileMapping(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
ret = CopyFileA(source, dest, FALSE);
todo_wine {
ok(!ret && GetLastError() == ERROR_USER_MAPPED_FILE,
"CopyFileA with mapped dest file: expected ERROR_USER_MAPPED_FILE, got %d\n", GetLastError());
}
CloseHandle(hmapfile);
CloseHandle(hfile); CloseHandle(hfile);
ret = DeleteFileA(source); ret = DeleteFileA(source);
@ -1263,7 +1290,10 @@ static void test_MoveFileA(void)
char tempdir[MAX_PATH]; char tempdir[MAX_PATH];
char source[MAX_PATH], dest[MAX_PATH]; char source[MAX_PATH], dest[MAX_PATH];
static const char prefix[] = "pfx"; static const char prefix[] = "pfx";
HANDLE hfile;
HANDLE hmapfile;
DWORD ret; DWORD ret;
BOOL retok;
ret = GetTempPathA(MAX_PATH, tempdir); ret = GetTempPathA(MAX_PATH, tempdir);
ok(ret != 0, "GetTempPathA error %d\n", GetLastError()); ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
@ -1282,6 +1312,46 @@ static void test_MoveFileA(void)
ret = DeleteFileA(dest); ret = DeleteFileA(dest);
ok(ret, "DeleteFileA: error %d\n", GetLastError()); ok(ret, "DeleteFileA: error %d\n", GetLastError());
hfile = CreateFileA(source, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
retok = WriteFile(hfile, prefix, sizeof(prefix), &ret, NULL );
ok( retok && ret == sizeof(prefix),
"WriteFile error %d\n", GetLastError());
hmapfile = CreateFileMapping(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
ret = MoveFileA(source, dest);
todo_wine {
ok(!ret, "MoveFileA: expected failure\n");
ok(GetLastError() == ERROR_SHARING_VIOLATION, "MoveFileA: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
}
CloseHandle(hmapfile);
CloseHandle(hfile);
/* if MoveFile succeeded, move back to dest */
if (ret) MoveFile(dest, source);
hfile = CreateFileA(source, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
hmapfile = CreateFileMapping(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
ret = MoveFileA(source, dest);
todo_wine {
ok(!ret, "MoveFileA: expected failure\n");
ok(GetLastError() == ERROR_SHARING_VIOLATION, "MoveFileA: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
}
CloseHandle(hmapfile);
CloseHandle(hfile);
/* if MoveFile succeeded, move back to dest */
if (ret) MoveFile(dest, source);
ret = MoveFileA(source, dest); ret = MoveFileA(source, dest);
ok(ret, "MoveFileA: failed, error %d\n", GetLastError()); ok(ret, "MoveFileA: failed, error %d\n", GetLastError());