From 7b416af6ea3e681632de74a72b1b922da719f7dd Mon Sep 17 00:00:00 2001 From: Paul Vriens Date: Wed, 27 Jul 2005 10:51:45 +0000 Subject: [PATCH] Fix some tests for win9x and winME. --- dlls/kernel/tests/module.c | 72 ++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/dlls/kernel/tests/module.c b/dlls/kernel/tests/module.c index 85dabaed753..a3e7d238402 100644 --- a/dlls/kernel/tests/module.c +++ b/dlls/kernel/tests/module.c @@ -21,6 +21,8 @@ #include "wine/test.h" #include +static BOOL is_unicode_enabled = TRUE; + static BOOL cmpStrAW(const char* a, const WCHAR* b, DWORD lenA, DWORD lenB) { WCHAR aw[1024]; @@ -36,7 +38,7 @@ static void testGetModuleFileName(const char* name) HMODULE hMod; char bufA[MAX_PATH]; WCHAR bufW[MAX_PATH]; - DWORD len1A, len1W, len2A, len2W; + DWORD len1A, len1W = 0, len2A, len2W = 0; hMod = (name) ? GetModuleHandle(name) : NULL; @@ -44,23 +46,37 @@ static void testGetModuleFileName(const char* name) memset(bufA, '-', sizeof(bufA)); len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA)); ok(len1A > 0, "Getting module filename for handle %p\n", hMod); - memset(bufW, '-', sizeof(bufW)); - len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR)); - ok(len1W > 0, "Getting module filename for handle %p\n", hMod); + + if (is_unicode_enabled) + { + memset(bufW, '-', sizeof(bufW)); + len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR)); + ok(len1W > 0, "Getting module filename for handle %p\n", hMod); + } + ok(len1A == strlen(bufA), "Unexpected length of GetModuleFilenameA (%ld/%d)\n", len1A, strlen(bufA)); - ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%ld/%d)\n", len1W, lstrlenW(bufW)); - ok(cmpStrAW(bufA, bufW, len1A, len1W), "Comparing GetModuleFilenameAW results\n"); + + if (is_unicode_enabled) + { + ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%ld/%d)\n", len1W, lstrlenW(bufW)); + ok(cmpStrAW(bufA, bufW, len1A, len1W), "Comparing GetModuleFilenameAW results\n"); + } /* second test with a buffer too small */ memset(bufA, '-', sizeof(bufA)); len2A = GetModuleFileNameA(hMod, bufA, len1A / 2); ok(len2A > 0, "Getting module filename for handle %p\n", hMod); - memset(bufW, '-', sizeof(bufW)); - len2W = GetModuleFileNameW(hMod, bufW, len1W / 2); - ok(len2W > 0, "Getting module filename for handle %p\n", hMod); - ok(cmpStrAW(bufA, bufW, len2A, len2W), "Comparing GetModuleFilenameAW results with buffer too small\n" ); + + if (is_unicode_enabled) + { + memset(bufW, '-', sizeof(bufW)); + len2W = GetModuleFileNameW(hMod, bufW, len1W / 2); + ok(len2W > 0, "Getting module filename for handle %p\n", hMod); + ok(cmpStrAW(bufA, bufW, len2A, len2W), "Comparing GetModuleFilenameAW results with buffer too small\n" ); + ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%ld/%ld)\n", len1W / 2, len2W); + } + ok(len1A / 2 == len2A, "Correct length in GetModuleFilenameA with buffer too small (%ld/%ld)\n", len1A / 2, len2A); - ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%ld/%ld)\n", len1W / 2, len2W); } static void testGetModuleFileName_Wrong(void) @@ -69,9 +85,12 @@ static void testGetModuleFileName_Wrong(void) WCHAR bufW[MAX_PATH]; /* test wrong handle */ - bufW[0] = '*'; - ok(GetModuleFileNameW((void*)0xffffffff, bufW, sizeof(bufW) / sizeof(WCHAR)) == 0, "Unexpected success in module handle\n"); - ok(bufW[0] == '*', "When failing, buffer shouldn't be written to\n"); + if (is_unicode_enabled) + { + bufW[0] = '*'; + ok(GetModuleFileNameW((void*)0xffffffff, bufW, sizeof(bufW) / sizeof(WCHAR)) == 0, "Unexpected success in module handle\n"); + ok(bufW[0] == '*', "When failing, buffer shouldn't be written to\n"); + } bufA[0] = '*'; ok(GetModuleFileNameA((void*)0xffffffff, bufA, sizeof(bufA)) == 0, "Unexpected success in module handle\n"); @@ -88,7 +107,7 @@ static void testLoadLibraryA(void) ok( hModule != NULL, "ntdll.dll should be loadable\n"); ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %08lx\n", GetLastError()); - fp = GetProcAddress(hModule, "LdrLoadDll"); + fp = GetProcAddress(hModule, "NtCreateFile"); ok( fp != NULL, "Call should be there\n"); ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %08lx\n", GetLastError()); @@ -103,7 +122,8 @@ static void testLoadLibraryA_Wrong(void) SetLastError(0xdeadbeef); hModule = LoadLibraryA("non_ex_pv.dll"); ok( !hModule, "non_ex_pv.dll should be not loadable\n"); - ok( GetLastError() == ERROR_MOD_NOT_FOUND, "Expected ERROR_MOD_NOT_FOUND, got %08lx\n", GetLastError()); + ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND, + "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x), got %08lx\n", GetLastError()); /* Just in case */ FreeLibrary(hModule); @@ -116,14 +136,30 @@ static void testGetProcAddress_Wrong(void) SetLastError(0xdeadbeef); fp = GetProcAddress(NULL, "non_ex_call"); ok( !fp, "non_ex_call should not be found\n"); - ok( GetLastError() == ERROR_PROC_NOT_FOUND, "Expected ERROR_PROC_NOT_FOUND, got %08lx\n", GetLastError()); + ok( GetLastError() == ERROR_PROC_NOT_FOUND || GetLastError() == ERROR_INVALID_HANDLE, + "Expected ERROR_PROC_NOT_FOUND or ERROR_INVALID_HANDLE(win9x), got %08lx\n", GetLastError()); + + SetLastError(0xdeadbeef); fp = GetProcAddress((HMODULE)0xdeadbeef, "non_ex_call"); ok( !fp, "non_ex_call should not be found\n"); - ok( GetLastError() == ERROR_MOD_NOT_FOUND, "Expected ERROR_MOD_NOT_FOUND, got %08lx\n", GetLastError()); + ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_INVALID_HANDLE, + "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_HANDLE(win9x), got %08lx\n", GetLastError()); } 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) + { + trace("GetModuleFileNameW not existing on this platform, skipping W-calls\n"); + is_unicode_enabled = FALSE; + } + testGetModuleFileName(NULL); testGetModuleFileName("kernel32.dll"); testGetModuleFileName_Wrong();