From: Bernhard Reiter Subject: [1/2] imagehlp/tests: Add test for BindImageEx (try 12) Message-Id: <53CD563F.5060903@raz.or.at> Date: Mon, 21 Jul 2014 20:04:47 +0200 Removed all the typecasts I was able to, fixed variable names, and tried to initialize variables whereever required, plus some more minor fixes as told by people on #winehackers and wine-devel. From bc6c9293fca31e5d8dcac8728b694c9ede89219f Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Wed, 7 May 2014 20:58:23 +0200 Subject: Add test for BindImageEx. --- dlls/imagehlp/tests/image.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/dlls/imagehlp/tests/image.c b/dlls/imagehlp/tests/image.c index e008b0b..91c81f7 100644 --- a/dlls/imagehlp/tests/image.c +++ b/dlls/imagehlp/tests/image.c @@ -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, void *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] = {0}; + + static BOOL WINAPI accumulating_stream_output(DIGEST_HANDLE handle, BYTE *pb, DWORD cb) { @@ -273,6 +278,38 @@ static void update_checksum(void) bin.nt_headers.OptionalHeader.CheckSum = sum; } +static BOOL WINAPI testing_status_routine(IMAGEHLP_STATUS_REASON reason, char *ImageName, + char *DllName, ULONG_PTR Va, ULONG_PTR Parameter) +{ + char kernel32_path[MAX_PATH]; + + status_routine_called[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, "expected reason to be one of BindImportModule, BindImportProcedure, or " + "BindForwarderNOT, got %d\n", reason); + break; + } + return TRUE; +} + static void test_get_digest_stream(void) { BOOL ret; @@ -329,6 +366,52 @@ 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] = "nonexistant.dll"; + DWORD count; + + /* Call with a non-existant file */ + SetLastError(0xdeadbeef); + ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, NULL, + NULL, 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); + + /* Finally, call with a proper PE file */ + ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, + NULL, testing_status_routine); + ok(ret, "BindImageEx failed: %d\n", GetLastError()); + + todo_wine ok(status_routine_called[BindImportModule] == 1, + "Expected StatusRoutine to be called once with reason BindImportModule, " + "but it was called %d times\n", status_routine_called[BindImportModule]); + + /* Under 64 bit images of Vista Ultimate, 2008 Server, and 7 Pro, StatusRoutine is called with + * reason BindForwarderNOT instead of BindImportProcedure. */ + todo_wine ok((status_routine_called[BindImportProcedure] == 1) || + (status_routine_called[BindForwarderNOT] == 1), + "Expected StatusRoutine to be called once with reason BindImportProcedure or " + "BindForwarderNOT, but it was called %d and %d times, respectively\n", + status_routine_called[BindImportProcedure], status_routine_called[BindForwarderNOT]); + + DeleteFileA(temp_file); +} + START_TEST(image) { hImageHlp = LoadLibraryA("imagehlp.dll"); @@ -349,5 +432,15 @@ START_TEST(image) test_get_digest_stream(); } + pBindImageEx = (void *) GetProcAddress(hImageHlp, "BindImageEx"); + + if (!pBindImageEx) + { + win_skip("BindImageEx function is not available\n"); + } else + { + test_bind_image_ex(); + } + FreeLibrary(hImageHlp); } -- 1.9.1