Module: wine Branch: master Commit: 7a9fce25ec725a7d1942e414ec53fecbe4bc0458 URL: http://source.winehq.org/git/wine.git/?a=commit;h=7a9fce25ec725a7d1942e414ec...
Author: Dmitry Timoshkov dmitry@baikal.ru Date: Thu Mar 8 20:29:50 2012 +0800
kernel32: Add some CreateFile disposition and access tests.
---
dlls/kernel32/tests/file.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 39e6cb9..9cfb664 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -3151,6 +3151,92 @@ static void test_ReplaceFileW(void) } }
+static void test_CreatFile(void) +{ + static const struct test_data + { + DWORD disposition, access, error, clean_up; + } td[] = + { + /* 0 */ { 0, 0, ERROR_INVALID_PARAMETER, 0 }, + /* 1 */ { 0, GENERIC_READ, ERROR_INVALID_PARAMETER, 0 }, + /* 2 */ { 0, GENERIC_READ|GENERIC_WRITE, ERROR_INVALID_PARAMETER, 0 }, + /* 3 */ { CREATE_NEW, 0, ERROR_FILE_EXISTS, 1 }, + /* 4 */ { CREATE_NEW, 0, 0, 1 }, + /* 5 */ { CREATE_NEW, GENERIC_READ, 0, 1 }, + /* 6 */ { CREATE_NEW, GENERIC_WRITE, 0, 1 }, + /* 7 */ { CREATE_NEW, GENERIC_READ|GENERIC_WRITE, 0, 0 }, + /* 8 */ { CREATE_ALWAYS, 0, 0, 0 }, + /* 9 */ { CREATE_ALWAYS, GENERIC_READ, 0, 0 }, + /* 10*/ { CREATE_ALWAYS, GENERIC_WRITE, 0, 0 }, + /* 11*/ { CREATE_ALWAYS, GENERIC_READ|GENERIC_WRITE, 0, 1 }, + /* 12*/ { OPEN_EXISTING, 0, ERROR_FILE_NOT_FOUND, 0 }, + /* 13*/ { CREATE_ALWAYS, 0, 0, 0 }, + /* 14*/ { OPEN_EXISTING, 0, 0, 0 }, + /* 15*/ { OPEN_EXISTING, GENERIC_READ, 0, 0 }, + /* 16*/ { OPEN_EXISTING, GENERIC_WRITE, 0, 0 }, + /* 17*/ { OPEN_EXISTING, GENERIC_READ|GENERIC_WRITE, 0, 1 }, + /* 18*/ { OPEN_ALWAYS, 0, 0, 0 }, + /* 19*/ { OPEN_ALWAYS, GENERIC_READ, 0, 0 }, + /* 20*/ { OPEN_ALWAYS, GENERIC_WRITE, 0, 0 }, + /* 21*/ { OPEN_ALWAYS, GENERIC_READ|GENERIC_WRITE, 0, 0 }, + /* 22*/ { TRUNCATE_EXISTING, 0, ERROR_INVALID_PARAMETER, 0 }, + /* 23*/ { TRUNCATE_EXISTING, GENERIC_READ, ERROR_INVALID_PARAMETER, 0 }, + /* 24*/ { TRUNCATE_EXISTING, GENERIC_WRITE, 0, 0 }, + /* 25*/ { TRUNCATE_EXISTING, GENERIC_READ|GENERIC_WRITE, 0, 0 } + }; + char temp_path[MAX_PATH]; + char file_name[MAX_PATH]; + DWORD i, ret, written; + HANDLE hfile; + + GetTempPath(MAX_PATH, temp_path); + GetTempFileName(temp_path, "tmp", 0, file_name); + + for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) + { + SetLastError(0xdeadbeef); + hfile = CreateFile(file_name, td[i].access, 0, NULL, td[i].disposition, 0, 0); + if (!td[i].error) + { + ok(hfile != INVALID_HANDLE_VALUE, "%d: CreateFile error %d\n", i, GetLastError()); + written = 0xdeadbeef; + SetLastError(0xdeadbeef); + ret = WriteFile(hfile, &td[i].error, sizeof(td[i].error), &written, NULL); + if (td[i].access & GENERIC_WRITE) + ok(ret, "%d: WriteFile error %d\n", i, GetLastError()); + else + { + ok(!ret, "%d: WriteFile should fail\n", i); + ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError()); + } + CloseHandle(hfile); + } + else + { + /* FIXME: remove the condition below once Wine is fixed */ + if (td[i].disposition == TRUNCATE_EXISTING && !(td[i].access & GENERIC_WRITE)) + { + todo_wine + { + ok(hfile == INVALID_HANDLE_VALUE, "%d: CreateFile should fail\n", i); + ok(GetLastError() == td[i].error, "%d: expected %d, got %d\n", i, td[i].error, GetLastError()); + } + CloseHandle(hfile); + } + else + { + ok(hfile == INVALID_HANDLE_VALUE, "%d: CreateFile should fail\n", i); + ok(GetLastError() == td[i].error, "%d: expected %d, got %d\n", i, td[i].error, GetLastError()); + } + } + + if (td[i].clean_up) DeleteFile(file_name); + } + + DeleteFile(file_name); +} + START_TEST(file) { InitFunctionPointers(); @@ -3166,6 +3252,7 @@ START_TEST(file) test_GetTempFileNameA(); test_CopyFileA(); test_CopyFileW(); + test_CreatFile(); test_CreateFileA(); test_CreateFileW(); test_DeleteFileA();