[02/10] wintrust: Convert crypt tests to Unicode.
Hans Leidekker
hans at codeweavers.com
Mon Dec 22 07:18:49 CST 2008
diff --git a/dlls/wintrust/tests/crypt.c b/dlls/wintrust/tests/crypt.c
index 6811fd4..41cb39a 100644
--- a/dlls/wintrust/tests/crypt.c
+++ b/dlls/wintrust/tests/crypt.c
@@ -27,8 +27,8 @@
#include "wine/test.h"
-static char selfname[MAX_PATH];
-static CHAR CURR_DIR[MAX_PATH];
+static WCHAR selfname[MAX_PATH];
+static WCHAR current_dir[MAX_PATH];
/*
* Minimalistic catalog file. To reconstruct, save text below as winetest.cdf,
@@ -248,12 +248,13 @@ static void test_context(void)
/* TODO: Check whether SHA-1 is the algorithm that's always used */
static void test_calchash(void)
{
+ static const WCHAR hshW[] = {'h','s','h',0};
BOOL ret;
HANDLE file;
DWORD hashsize = 0;
BYTE* hash;
BYTE expectedhash[20] = {0x3a,0xa1,0x19,0x08,0xec,0xa6,0x0d,0x2e,0x7e,0xcc,0x7a,0xca,0xf5,0xb8,0x2e,0x62,0x6a,0xda,0xf0,0x19};
- CHAR temp[MAX_PATH];
+ WCHAR temp[MAX_PATH];
DWORD written;
/* All NULL */
@@ -271,7 +272,7 @@ static void test_calchash(void)
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
/* Correct filehandle, rest is NULL */
- file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+ file = CreateFileW(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
SetLastError(0xdeadbeef);
ret = pCryptCATAdminCalcHashFromFileHandle(file, NULL, NULL, 0);
ok(!ret, "Expected failure\n");
@@ -280,7 +281,7 @@ static void test_calchash(void)
CloseHandle(file);
/* All OK, but dwFlags set to 1 */
- file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+ file = CreateFileW(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
SetLastError(0xdeadbeef);
ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 1);
ok(!ret, "Expected failure\n");
@@ -289,7 +290,7 @@ static void test_calchash(void)
CloseHandle(file);
/* All OK, requesting the size of the hash */
- file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ file = CreateFileW(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
@@ -302,7 +303,7 @@ static void test_calchash(void)
/* All OK, retrieve the hash
* Double the hash buffer to see what happens to the size parameter
*/
- file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ file = CreateFileW(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
hashsize *= 2;
hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
SetLastError(0xdeadbeef);
@@ -317,13 +318,13 @@ static void test_calchash(void)
/* Do the same test with a file created and filled by ourselves (and we thus
* have a known hash for).
*/
- GetTempFileNameA(CURR_DIR, "hsh", 0, temp);
- file = CreateFileA(temp, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+ GetTempFileNameW(current_dir, hshW, 0, temp);
+ file = CreateFileW(temp, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
WriteFile(file, "Text in this file is needed to create a know hash", 49, &written, NULL);
CloseHandle(file);
/* All OK, first request the size and then retrieve the hash */
- file = CreateFileA(temp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+ file = CreateFileW(temp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
hashsize = 0;
pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
@@ -338,16 +339,16 @@ static void test_calchash(void)
CloseHandle(file);
HeapFree(GetProcessHeap(), 0, hash);
- DeleteFileA(temp);
+ DeleteFileW(temp);
}
static void test_CryptCATAdminAddRemoveCatalog(void)
{
+ static const WCHAR catW[] = {'c','a','t',0};
static WCHAR basenameW[] = {'w','i','n','e','t','e','s','t','.','c','a','t',0};
HCATADMIN hcatadmin;
HCATINFO hcatinfo;
- WCHAR tmpfileW[MAX_PATH];
- char tmpfile[MAX_PATH];
+ WCHAR tmpfile[MAX_PATH];
HANDLE file;
DWORD error, written;
BOOL ret;
@@ -359,10 +360,10 @@ static void test_CryptCATAdminAddRemoveCatalog(void)
return;
}
- if (!GetTempFileNameA(CURR_DIR, "cat", 0, tmpfile)) return;
- DeleteFileA(tmpfile);
- file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
- ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError());
+ if (!GetTempFileNameW(current_dir, catW, 0, tmpfile)) return;
+ DeleteFileW(tmpfile);
+ file = CreateFileW(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
+ ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %u\n", GetLastError());
CloseHandle(file);
ret = pCryptCATAdminAcquireContext(&hcatadmin, &dummy, 0);
@@ -380,10 +381,8 @@ static void test_CryptCATAdminAddRemoveCatalog(void)
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
ok(error == ERROR_INVALID_PARAMETER, "got %u expected INVALID_PARAMTER\n", GetLastError());
- MultiByteToWideChar(0, 0, tmpfile, -1, tmpfileW, MAX_PATH);
-
SetLastError(0xdeadbeef);
- hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
+ hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfile, basenameW, 0);
error = GetLastError();
todo_wine {
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
@@ -391,39 +390,39 @@ static void test_CryptCATAdminAddRemoveCatalog(void)
}
SetLastError(0xdeadbeef);
- hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 1);
+ hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfile, basenameW, 1);
error = GetLastError();
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMTER\n", GetLastError());
SetLastError(0xdeadbeef);
- hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
+ hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfile, NULL, 0);
error = GetLastError();
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
todo_wine ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
- DeleteFileA(tmpfile);
- file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
- ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError());
+ DeleteFileW(tmpfile);
+ file = CreateFileW(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
+ ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %u\n", GetLastError());
WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL);
CloseHandle(file);
- hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
+ hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfile, NULL, 0);
todo_wine ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
- hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
+ hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfile, basenameW, 0);
ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
ret = pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0);
ok(ret, "CryptCATAdminReleaseCatalogContext failed %u\n", GetLastError());
- ret = pCryptCATAdminRemoveCatalog(hcatadmin, tmpfileW, 0);
+ ret = pCryptCATAdminRemoveCatalog(hcatadmin, tmpfile, 0);
ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
ret = pCryptCATAdminReleaseContext(hcatadmin, 0);
ok(ret, "CryptCATAdminReleaseContext failed %u\n", GetLastError());
- DeleteFileA(tmpfile);
+ DeleteFileW(tmpfile);
}
START_TEST(crypt)
@@ -440,9 +439,9 @@ START_TEST(crypt)
}
myARGC = winetest_get_mainargs(&myARGV);
- strcpy(selfname, myARGV[0]);
+ MultiByteToWideChar(0, 0, myARGV[0], -1, selfname, MAX_PATH);
- GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
+ GetCurrentDirectoryW(MAX_PATH, current_dir);
test_context();
test_calchash();
More information about the wine-patches
mailing list