mirror of
https://github.com/reactos/reactos.git
synced 2024-07-07 05:05:09 +00:00
[IMAGEHLP_WINETEST]
* Sync with Wine 1.7.27. CORE-8540 svn path=/trunk/; revision=64355
This commit is contained in:
parent
942cdae879
commit
57ce56eb38
|
@ -31,6 +31,8 @@
|
|||
static HMODULE hImageHlp;
|
||||
|
||||
static BOOL (WINAPI *pImageGetDigestStream)(HANDLE, DWORD, DIGEST_FUNCTION, DIGEST_HANDLE);
|
||||
static BOOL (WINAPI *pBindImageEx)(DWORD Flags, const char *ImageName, const char *DllPath,
|
||||
const char *SymbolPath, PIMAGEHLP_STATUS_ROUTINE StatusRoutine);
|
||||
|
||||
/* minimal PE file image */
|
||||
#define VA_START 0x400000
|
||||
|
@ -149,6 +151,9 @@ struct expected_update_accum
|
|||
BOOL todo;
|
||||
};
|
||||
|
||||
static int status_routine_called[BindSymbolsNotUpdated+1];
|
||||
|
||||
|
||||
static BOOL WINAPI accumulating_stream_output(DIGEST_HANDLE handle, BYTE *pb,
|
||||
DWORD cb)
|
||||
{
|
||||
|
@ -273,6 +278,40 @@ static void update_checksum(void)
|
|||
bin.nt_headers.OptionalHeader.CheckSum = sum;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK testing_status_routine(IMAGEHLP_STATUS_REASON reason, const char *ImageName,
|
||||
const char *DllName, ULONG_PTR Va, ULONG_PTR Parameter)
|
||||
{
|
||||
char kernel32_path[MAX_PATH];
|
||||
|
||||
if (0 <= (int)reason && reason <= BindSymbolsNotUpdated)
|
||||
status_routine_called[reason]++;
|
||||
else
|
||||
ok(0, "expected reason between 0 and %d, got %d\n", BindSymbolsNotUpdated+1, reason);
|
||||
|
||||
switch(reason)
|
||||
{
|
||||
case BindImportModule:
|
||||
ok(!strcmp(DllName, "KERNEL32.DLL"), "expected DllName to be KERNEL32.DLL, got %s\n",
|
||||
DllName);
|
||||
break;
|
||||
|
||||
case BindImportProcedure:
|
||||
case BindForwarderNOT:
|
||||
GetSystemDirectoryA(kernel32_path, MAX_PATH);
|
||||
strcat(kernel32_path, "\\KERNEL32.DLL");
|
||||
ok(!lstrcmpiA(DllName, kernel32_path), "expected DllName to be %s, got %s\n",
|
||||
kernel32_path, DllName);
|
||||
ok(!strcmp((char *)Parameter, "ExitProcess"),
|
||||
"expected Parameter to be ExitProcess, got %s\n", (char *)Parameter);
|
||||
break;
|
||||
|
||||
default:
|
||||
ok(0, "got unexpected reason %d\n", reason);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void test_get_digest_stream(void)
|
||||
{
|
||||
BOOL ret;
|
||||
|
@ -281,6 +320,11 @@ static void test_get_digest_stream(void)
|
|||
DWORD count;
|
||||
struct update_accum accum = { 0, NULL };
|
||||
|
||||
if (!pImageGetDigestStream)
|
||||
{
|
||||
win_skip("ImageGetDigestStream function is not available\n");
|
||||
return;
|
||||
}
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pImageGetDigestStream(NULL, 0, NULL, NULL);
|
||||
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
|
@ -329,6 +373,60 @@ static void test_get_digest_stream(void)
|
|||
DeleteFileA(temp_file);
|
||||
}
|
||||
|
||||
static void test_bind_image_ex(void)
|
||||
{
|
||||
BOOL ret;
|
||||
HANDLE file;
|
||||
char temp_file[MAX_PATH];
|
||||
DWORD count;
|
||||
|
||||
if (!pBindImageEx)
|
||||
{
|
||||
win_skip("BindImageEx function is not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* call with a non-existent file */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, "nonexistent.dll", 0, 0,
|
||||
testing_status_routine);
|
||||
todo_wine ok(!ret && ((GetLastError() == ERROR_FILE_NOT_FOUND) ||
|
||||
(GetLastError() == ERROR_INVALID_PARAMETER)),
|
||||
"expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n",
|
||||
GetLastError());
|
||||
|
||||
file = create_temp_file(temp_file);
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
skip("couldn't create temp file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
WriteFile(file, &bin, sizeof(bin), &count, NULL);
|
||||
CloseHandle(file);
|
||||
|
||||
/* call with a proper PE file, but with StatusRoutine set to NULL */
|
||||
ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0,
|
||||
NULL);
|
||||
ok(ret, "BindImageEx failed: %d\n", GetLastError());
|
||||
|
||||
/* call with a proper PE file and StatusRoutine */
|
||||
ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0,
|
||||
testing_status_routine);
|
||||
ok(ret, "BindImageEx failed: %d\n", GetLastError());
|
||||
|
||||
todo_wine ok(status_routine_called[BindImportModule] == 1,
|
||||
"StatusRoutine was called %d times\n", status_routine_called[BindImportModule]);
|
||||
|
||||
todo_wine ok((status_routine_called[BindImportProcedure] == 1)
|
||||
#if defined(_WIN64)
|
||||
|| broken(status_routine_called[BindImportProcedure] == 0) /* < Win8 */
|
||||
#endif
|
||||
, "StatusRoutine was called %d times\n", status_routine_called[BindImportProcedure]);
|
||||
|
||||
DeleteFileA(temp_file);
|
||||
}
|
||||
|
||||
START_TEST(image)
|
||||
{
|
||||
hImageHlp = LoadLibraryA("imagehlp.dll");
|
||||
|
@ -340,14 +438,10 @@ START_TEST(image)
|
|||
}
|
||||
|
||||
pImageGetDigestStream = (void *) GetProcAddress(hImageHlp, "ImageGetDigestStream");
|
||||
pBindImageEx = (void *) GetProcAddress(hImageHlp, "BindImageEx");
|
||||
|
||||
if (!pImageGetDigestStream)
|
||||
{
|
||||
win_skip("ImageGetDigestStream function is not available\n");
|
||||
} else
|
||||
{
|
||||
test_get_digest_stream();
|
||||
}
|
||||
test_get_digest_stream();
|
||||
test_bind_image_ex();
|
||||
|
||||
FreeLibrary(hImageHlp);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ static DWORD get_file_size(void)
|
|||
return filesize;
|
||||
}
|
||||
|
||||
static void test_add_certificate(const char *cert_data, int len)
|
||||
static DWORD test_add_certificate(const char *cert_data, int len)
|
||||
{
|
||||
HANDLE hFile;
|
||||
LPWIN_CERTIFICATE cert;
|
||||
|
@ -148,7 +148,7 @@ static void test_add_certificate(const char *cert_data, int len)
|
|||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
skip("Unable to open %s, skipping test\n", test_dll_path);
|
||||
return;
|
||||
return ~0;
|
||||
}
|
||||
|
||||
cert_len = sizeof(WIN_CERTIFICATE) + len;
|
||||
|
@ -158,7 +158,7 @@ static void test_add_certificate(const char *cert_data, int len)
|
|||
{
|
||||
skip("Unable to allocate memory, skipping test\n");
|
||||
CloseHandle(hFile);
|
||||
return;
|
||||
return ~0;
|
||||
}
|
||||
|
||||
cert->dwLength = cert_len;
|
||||
|
@ -168,9 +168,11 @@ static void test_add_certificate(const char *cert_data, int len)
|
|||
|
||||
ret = pImageAddCertificate(hFile, cert, &index);
|
||||
ok(ret, "Unable to add certificate to image, error %x\n", GetLastError());
|
||||
trace("added cert index %d\n", index);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, cert);
|
||||
CloseHandle(hFile);
|
||||
return index;
|
||||
}
|
||||
|
||||
static void test_get_certificate(const char *cert_data, int index)
|
||||
|
@ -239,7 +241,7 @@ static void test_remove_certificate(int index)
|
|||
|
||||
START_TEST(integrity)
|
||||
{
|
||||
DWORD file_size, file_size_orig;
|
||||
DWORD file_size, file_size_orig, first, second;
|
||||
|
||||
hImageHlp = LoadLibraryA("imagehlp.dll");
|
||||
|
||||
|
@ -272,25 +274,27 @@ START_TEST(integrity)
|
|||
pImageGetCertificateHeader = (void *) GetProcAddress(hImageHlp, "ImageGetCertificateHeader");
|
||||
pImageRemoveCertificate = (void *) GetProcAddress(hImageHlp, "ImageRemoveCertificate");
|
||||
|
||||
test_add_certificate(test_cert_data, sizeof(test_cert_data));
|
||||
test_get_certificate(test_cert_data, 0);
|
||||
test_remove_certificate(0);
|
||||
first = test_add_certificate(test_cert_data, sizeof(test_cert_data));
|
||||
test_get_certificate(test_cert_data, first);
|
||||
test_remove_certificate(first);
|
||||
|
||||
file_size = get_file_size();
|
||||
ok(file_size == file_size_orig, "File size different after add and remove (old: %d; new: %d)\n", file_size_orig, file_size);
|
||||
|
||||
/* Try adding multiple certificates */
|
||||
test_add_certificate(test_cert_data, sizeof(test_cert_data));
|
||||
test_add_certificate(test_cert_data_2, sizeof(test_cert_data_2));
|
||||
first = test_add_certificate(test_cert_data, sizeof(test_cert_data));
|
||||
second = test_add_certificate(test_cert_data_2, sizeof(test_cert_data_2));
|
||||
ok(second == first + 1, "got %d %d\n", first, second);
|
||||
|
||||
test_get_certificate(test_cert_data, 0);
|
||||
test_get_certificate(test_cert_data_2, 1);
|
||||
test_get_certificate(test_cert_data, first);
|
||||
test_get_certificate(test_cert_data_2, second);
|
||||
|
||||
/* Remove the first one and verify the second certificate is intact */
|
||||
test_remove_certificate(0);
|
||||
test_get_certificate(test_cert_data_2, 0);
|
||||
test_remove_certificate(first);
|
||||
second--;
|
||||
test_get_certificate(test_cert_data_2, second);
|
||||
|
||||
test_remove_certificate(0);
|
||||
test_remove_certificate(second);
|
||||
|
||||
file_size = get_file_size();
|
||||
ok(file_size == file_size_orig, "File size different after add and remove (old: %d; new: %d)\n", file_size_orig, file_size);
|
||||
|
|
Loading…
Reference in a new issue