[4/4] kernel32/tests: Add tests for LoadLibrary with LIBRARY_SEARCH_* flags
Carlos Palminha
CARLOS.PALMINHA at synopsys.com
Thu Aug 3 11:07:48 CDT 2017
Test LIBRARY_SEARCH_* flags when loading libraries.
Uses helper from path.c to create the test dll file.
Signed-off-by: Carlos Palminha <palminha at synopsys.com>
---
dlls/kernel32/kernel_private.h | 3 ++
dlls/kernel32/path.c | 2 +-
dlls/kernel32/tests/loader.c | 4 +-
dlls/kernel32/tests/module.c | 107 ++++++++++++++++++++++++++++++++++++++++-
4 files changed, 112 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h
index 076f147096..5ede351bb2 100644
--- a/dlls/kernel32/kernel_private.h
+++ b/dlls/kernel32/kernel_private.h
@@ -88,6 +88,9 @@ struct binary_info
void *res_end;
};
+/* path.c */
+extern BOOL contains_pathW (LPCWSTR name);
+
/* module.c */
extern WCHAR *MODULE_get_dll_load_path_flags( DWORD flags ) DECLSPEC_HIDDEN;
extern WCHAR *MODULE_get_dll_load_path( LPCWSTR module ) DECLSPEC_HIDDEN;
diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index c746693a75..c6f964cceb 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -758,7 +758,7 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR
* Check if the file name contains a path; helper for SearchPathW.
* A relative path is not considered a path unless it starts with ./ or ../
*/
-static inline BOOL contains_pathW (LPCWSTR name)
+BOOL contains_pathW (LPCWSTR name)
{
if (RtlDetermineDosPathNameType_U( name ) != RELATIVE_PATH) return TRUE;
if (name[0] != '.') return FALSE;
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 09c21d8120..68d1189013 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -84,7 +84,7 @@ static PVOID RVAToAddr(DWORD_PTR rva, HMODULE module)
static IMAGE_DOS_HEADER dos_header;
-static const IMAGE_NT_HEADERS nt_header_template =
+const IMAGE_NT_HEADERS nt_header_template =
{
IMAGE_NT_SIGNATURE, /* Signature */
{
@@ -162,7 +162,7 @@ static IMAGE_SECTION_HEADER section =
static const char filler[0x1000];
static const char section_data[0x10] = "section data";
-static DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
+DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
const IMAGE_NT_HEADERS *nt_header, const char *dll_name )
{
DWORD dummy, size, file_align;
diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
index bb22c24316..78e32128cf 100644
--- a/dlls/kernel32/tests/module.c
+++ b/dlls/kernel32/tests/module.c
@@ -407,6 +407,111 @@ static void testLoadLibraryEx(void)
FreeLibrary(hmodule);
}
+/* use some functions and strcutures from loader.c */
+extern DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
+ const IMAGE_NT_HEADERS *nt_header, const char *dll_name );
+extern const IMAGE_NT_HEADERS nt_header_template;
+
+static void testLoadLibraryExSearchFlags(void)
+{
+ HMODULE hmodule;
+ char tmpPath[MAX_PATH];
+ char dllName[] = "testFlags.dll";
+ char tmpFullFile[MAX_PATH];
+ char sysFullFile[MAX_PATH];
+ IMAGE_DOS_HEADER dos_header;
+ IMAGE_NT_HEADERS nt_header;
+ ULONG file_size;
+ char fullPath[MAX_PATH];
+
+ GetTempPathA(MAX_PATH, tmpPath);
+ lstrcpyA(tmpFullFile, tmpPath);
+ lstrcatA(tmpFullFile, dllName);
+
+ /* check for required function */
+ if (!pSetDllDirectoryA)
+ {
+ win_skip("SetDllDirectoryA not available\n");
+ return;
+ }
+
+ /* try to load test dll from test path before creating it*/
+ SetLastError(0xdeadbeef);
+ pSetDllDirectoryA(tmpPath);
+ hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
+ ok (hmodule == NULL, "Test library %s should not be loaded from %s\n", dllName, tmpPath);
+ ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND,
+ "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x), got %d\n", GetLastError());
+ FreeLibrary(hmodule);
+ pSetDllDirectoryA(NULL);
+
+ /* create test library */
+ lstrcpyA(fullPath, tmpPath);
+ lstrcatA(fullPath, dllName);
+
+ dos_header.e_magic = IMAGE_DOS_SIGNATURE;
+ dos_header.e_lfanew = sizeof(dos_header);
+
+ nt_header = nt_header_template;
+
+ nt_header.FileHeader.NumberOfSections = 1;
+ nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
+ nt_header.OptionalHeader.SectionAlignment = 0x1000;
+ nt_header.OptionalHeader.FileAlignment = 0x1000;
+ nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000;
+ nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER);
+
+ file_size = create_test_dll(&dos_header, sizeof(dos_header), &nt_header, fullPath);
+ ok( file_size, "could not create '%s'\n",fullPath);
+
+ /* try to load test dll from test path */
+ SetLastError(0xdeadbeef);
+ pSetDllDirectoryA(tmpPath);
+ hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
+ ok (hmodule!=NULL, "Could not load test library %s from %s\n", dllName, tmpPath);
+ ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS,
+ "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());
+ FreeLibrary(hmodule);
+ pSetDllDirectoryA(NULL);
+
+ /* load non-existing test dll from system32 */
+ SetLastError(0xdeadbeef);
+ hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ ok(hmodule == NULL, "%s should not be loaded\n", dllName);
+ ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND,
+ "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x), got %d\n", GetLastError());
+ FreeLibrary(hmodule);
+
+ /* move library from temp path to system32 and delete from old path */
+ GetWindowsDirectoryA(sysFullFile,MAX_PATH);
+ lstrcatA(sysFullFile,"\\system32\\");
+ lstrcatA(sysFullFile, dllName);
+ MoveFileA(tmpFullFile,sysFullFile);
+ DeleteFileA(tmpFullFile);
+
+ /* try to load dll using more than one flag */
+ pSetDllDirectoryA(tmpPath);
+ SetLastError(0xdeadbeef);
+ hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS | LOAD_LIBRARY_SEARCH_SYSTEM32);
+ ok (hmodule != NULL, "Library %s was expected to be loaded from 'system32'\n", dllName);
+ ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS,
+ "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());
+ FreeLibrary(hmodule);
+ pSetDllDirectoryA(NULL);
+
+ /* try to load test dll from system32 */
+ SetLastError(0xdeadbeef);
+ hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ ok (hmodule != NULL, "Library %s was expected to be loaded from 'system32'\n", dllName);
+ ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS,
+ "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());
+ FreeLibrary(hmodule);
+
+ /* delete test dll from system32 directory */
+ DeleteFileA(sysFullFile);
+
+}
+
static void testGetDllDirectory(void)
{
CHAR bufferA[MAX_PATH];
@@ -744,7 +849,6 @@ START_TEST(module)
WCHAR filenameW[MAX_PATH];
/* Test if we can use GetModuleFileNameW */
-
SetLastError(0xdeadbeef);
GetModuleFileNameW(NULL, filenameW, MAX_PATH);
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
@@ -766,6 +870,7 @@ START_TEST(module)
testLoadLibraryA_Wrong();
testGetProcAddress_Wrong();
testLoadLibraryEx();
+ testLoadLibraryExSearchFlags();
testGetModuleHandleEx();
testK32GetModuleInformation();
}
--
2.11.0
More information about the wine-patches
mailing list