Commit e07539d1 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wintrust/tests: Add more tests for CryptCATOpen() file modes.

parent 7ec069d8
...@@ -401,33 +401,65 @@ static void test_calchash(void) ...@@ -401,33 +401,65 @@ static void test_calchash(void)
static void test_CryptCATOpen(void) static void test_CryptCATOpen(void)
{ {
HANDLE hcat; WCHAR filename[MAX_PATH], temp_path[MAX_PATH];
char empty[MAX_PATH]; HANDLE cat;
WCHAR emptyW[MAX_PATH]; DWORD flags;
HANDLE file;
BOOL ret; BOOL ret;
FILE *file;
char buffer[10];
SetLastError(0xdeadbeef); GetTempPathW(ARRAY_SIZE(temp_path), temp_path);
hcat = pCryptCATOpen(NULL, 0, 0, 0, 0); GetTempFileNameW(temp_path, L"cat", 0, filename);
ok(hcat == INVALID_HANDLE_VALUE, "CryptCATOpen succeeded\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
if (!GetTempFileNameA(CURR_DIR, "cat", 0, empty)) return;
file = CreateFileA(empty, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); SetLastError(0xdeadbeef);
ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); cat = pCryptCATOpen(NULL, 0, 0, 0, 0);
CloseHandle(file); ok(cat == INVALID_HANDLE_VALUE, "expected failure\n");
MultiByteToWideChar(CP_ACP, 0, empty, -1, emptyW, MAX_PATH); ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %u\n", GetLastError());
hcat = pCryptCATOpen(emptyW, 0, 0, 0, 0); for (flags = 0; flags < 8; ++flags)
todo_wine {
ok(hcat != INVALID_HANDLE_VALUE, "Expected a correct handle\n"); SetLastError(0xdeadbeef);
cat = pCryptCATOpen(filename, flags, 0, 0, 0);
if (flags == CRYPTCAT_OPEN_EXISTING)
{
ok(cat == INVALID_HANDLE_VALUE, "flags %#x: expected failure\n", flags);
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "flags %#x: got error %u\n", flags, GetLastError());
ret = DeleteFileW(filename);
ok(!ret, "flags %#x: expected failure\n", flags);
}
else
{
todo_wine ok(cat != INVALID_HANDLE_VALUE, "flags %#x: expected success\n", flags);
todo_wine ok(!GetLastError(), "flags %#x: got error %u\n", flags, GetLastError());
ret = pCryptCATClose(cat);
todo_wine ok(ret, "flags %#x: failed to close file\n", flags);
ret = DeleteFileW(filename);
todo_wine_if (flags & (CRYPTCAT_OPEN_ALWAYS | CRYPTCAT_OPEN_CREATENEW))
ok(ret, "flags %#x: failed to delete file, error %u\n", flags, GetLastError());
}
file = _wfopen(filename, L"w");
fputs("test text", file);
fclose(file);
ret = pCryptCATClose(hcat); SetLastError(0xdeadbeef);
todo_wine cat = pCryptCATOpen(filename, flags, 0, 0, 0);
ok(ret, "CryptCATClose failed\n"); todo_wine ok(cat != INVALID_HANDLE_VALUE, "flags %#x: expected success\n", flags);
DeleteFileA(empty); todo_wine ok(!GetLastError(), "flags %#x: got error %u\n", flags, GetLastError());
ret = pCryptCATClose(cat);
todo_wine ok(ret, "flags %#x: failed to close file\n", flags);
file = _wfopen(filename, L"r");
ret = fread(buffer, 1, sizeof(buffer), file);
if (flags & CRYPTCAT_OPEN_CREATENEW)
todo_wine ok(!ret, "flags %#x: got %s\n", flags, debugstr_an(buffer, ret));
else
ok(ret == 9 && !strncmp(buffer, "test text", ret), "flags %#x: got %s\n", flags, debugstr_an(buffer, ret));
fclose(file);
ret = DeleteFileW(filename);
ok(ret, "flags %#x: failed to delete file, error %u\n", flags, GetLastError());
}
} }
static DWORD error_area; static DWORD error_area;
......
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