kernel32/tests: Add a test for multiple loading of DLL.
Alexander Morozov
amorozov at etersoft.ru
Wed Jun 10 03:59:47 CDT 2009
Changelog
Add a test for multiple loading of DLL
This is a test for bug #18775.
http://www.winehq.org/pipermail/wine-devel/2009-June/076207.html
http://www.winehq.org/pipermail/wine-devel/2009-June/076345.html
-------------- next part --------------
From 7dd23c51dc6ad21a61f8a25933714ac91a993acb Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov at etersoft.ru>
Date: Tue, 9 Jun 2009 14:42:16 +0400
Subject: [PATCH] kernel32/tests: Add a test for multiple loading of DLL.
---
dlls/kernel32/tests/loader.c | 167 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 167 insertions(+), 0 deletions(-)
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 9361ed5..487b654 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -541,8 +541,175 @@ static void test_ImportDescriptors(void)
}
}
+static void test_MultipleLoading(void)
+{
+ static const char lib_name[] = "long_name.dll";
+ static const char section_data[0x10] = "section data";
+ char dll_path[MAX_PATH], long_path[MAX_PATH], short_path[MAX_PATH];
+ char *p, old_dir[MAX_PATH], new_dir[MAX_PATH];
+ HMODULE hModule1, hModule2;
+ SYSTEM_INFO si;
+ HANDLE hfile;
+ DWORD dummy;
+
+ GetSystemInfo(&si);
+
+ GetTempPath(MAX_PATH, dll_path);
+ strcat(dll_path, lib_name);
+ hfile = CreateFileA(dll_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ if (hfile == INVALID_HANDLE_VALUE)
+ {
+ ok(0, "could not create %s\n", dll_path);
+ return;
+ }
+
+ SetLastError(0xdeadbeef);
+ ok(WriteFile(hfile, &dos_header, sizeof(dos_header), &dummy, NULL),
+ "WriteFile error %d\n", GetLastError());
+
+ 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) + sizeof(IMAGE_SECTION_HEADER) + 0x1000;
+ nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) +
+ sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER);
+
+ SetLastError(0xdeadbeef);
+ ok(WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL),
+ "WriteFile error %d\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ ok(WriteFile(hfile, &nt_header.OptionalHeader,
+ min(nt_header.FileHeader.SizeOfOptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER)),
+ &dummy, NULL),
+ "WriteFile error %d\n", GetLastError());
+
+ if (nt_header.OptionalHeader.SectionAlignment >= si.dwPageSize)
+ {
+ section.PointerToRawData = sizeof(dos_header);
+ section.VirtualAddress = nt_header.OptionalHeader.SectionAlignment;
+ section.Misc.VirtualSize = section.SizeOfRawData * 10;
+ }
+ else
+ {
+ section.PointerToRawData = nt_header.OptionalHeader.SizeOfHeaders;
+ section.VirtualAddress = nt_header.OptionalHeader.SizeOfHeaders;
+ section.Misc.VirtualSize = 5;
+ }
+
+ SetLastError(0xdeadbeef);
+ ok(WriteFile(hfile, §ion, sizeof(section), &dummy, NULL),
+ "WriteFile error %d\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ ok(WriteFile(hfile, section_data, sizeof(section_data), &dummy, NULL),
+ "WriteFile error %d\n", GetLastError());
+
+ CloseHandle(hfile);
+
+ strcpy(long_path, dll_path);
+ GetShortPathNameA(long_path, short_path, sizeof(short_path));
+
+ hModule1 = LoadLibraryA(long_path);
+ ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", long_path);
+ hModule2 = LoadLibraryA(short_path);
+ ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", short_path);
+ todo_wine
+ ok(hModule1 == hModule2, "LoadLibrary(%s) != LoadLibrary(%s)\n", long_path, short_path);
+ if (hModule1 != NULL)
+ ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
+ if (hModule2 != NULL && hModule2 != hModule1)
+ ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
+
+ GetCurrentDirectoryA(sizeof(old_dir), old_dir);
+ strcpy(new_dir, dll_path);
+ *strrchr(new_dir, '\\') = 0;
+ p = strrchr(new_dir, '\\');
+ if (p) *p = 0;
+ SetCurrentDirectoryA(new_dir);
+ memmove(long_path, long_path + 2, strlen(long_path + 2) + 1);
+ GetShortPathNameA(long_path, short_path, sizeof(short_path));
+
+ hModule1 = LoadLibraryA(long_path);
+ ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", long_path);
+ hModule2 = LoadLibraryA(short_path);
+ ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", short_path);
+ todo_wine
+ ok(hModule1 == hModule2, "LoadLibrary(%s) != LoadLibrary(%s)\n", long_path, short_path);
+ if (hModule1 != NULL)
+ ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
+ if (hModule2 != NULL && hModule2 != hModule1)
+ ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
+
+ memmove(long_path, long_path + strlen(new_dir) - 1,
+ strlen(long_path + strlen(new_dir) - 1) + 1);
+ GetShortPathNameA(long_path, short_path, sizeof(short_path));
+
+ hModule1 = LoadLibraryA(long_path);
+ ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", long_path);
+ hModule2 = LoadLibraryA(short_path);
+ ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", short_path);
+ todo_wine
+ ok(hModule1 == hModule2, "LoadLibrary(%s) != LoadLibrary(%s)\n", long_path, short_path);
+ if (hModule1 != NULL)
+ ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
+ if (hModule2 != NULL && hModule2 != hModule1)
+ ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
+
+ strcpy(new_dir, dll_path);
+ *strrchr(new_dir, '\\') = 0;
+ SetCurrentDirectoryA(new_dir);
+ strcpy(long_path, ".\\");
+ strcat(long_path, lib_name);
+ GetShortPathNameA(long_path, short_path, sizeof(short_path));
+
+ hModule1 = LoadLibraryA(long_path);
+ ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", long_path);
+ hModule2 = LoadLibraryA(short_path);
+ ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", short_path);
+ todo_wine
+ ok(hModule1 == hModule2, "LoadLibrary(%s) != LoadLibrary(%s)\n", long_path, short_path);
+ if (hModule1 != NULL)
+ ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
+ if (hModule2 != NULL && hModule2 != hModule1)
+ ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
+
+ GetFullPathNameA(lib_name, sizeof(long_path), long_path, NULL);
+ strcpy(long_path + 2, lib_name);
+ GetShortPathNameA(long_path, short_path, sizeof(short_path));
+
+ hModule1 = LoadLibraryA(long_path);
+ ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", long_path);
+ hModule2 = LoadLibraryA(short_path);
+ ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", short_path);
+ ok(hModule1 != hModule2, "LoadLibrary(%s) == LoadLibrary(%s)\n", long_path, short_path);
+ if (hModule1 != NULL)
+ ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
+ if (hModule2 != NULL)
+ ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
+
+ strcpy(long_path, lib_name);
+ GetShortPathNameA(long_path, short_path, sizeof(short_path));
+
+ hModule1 = LoadLibraryA(long_path);
+ ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", long_path);
+ hModule2 = LoadLibraryA(short_path);
+ ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", short_path);
+ ok(hModule1 != hModule2, "LoadLibrary(%s) == LoadLibrary(%s)\n", long_path, short_path);
+ if (hModule1 != NULL)
+ ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
+ if (hModule2 != NULL)
+ ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
+
+ DeleteFileA(lib_name);
+ SetCurrentDirectoryA(old_dir);
+}
+
START_TEST(loader)
{
test_Loader();
test_ImportDescriptors();
+ test_MultipleLoading();
}
--
1.6.3.2
More information about the wine-patches
mailing list