From 0ada917873a69f96aaa0e07817194b63e5d2896e Mon Sep 17 00:00:00 2001 From: Paul Vriens Date: Wed, 5 Dec 2007 11:40:05 +0100 Subject: [PATCH] kernel32: Make tests run on Win98 again. --- dlls/kernel32/tests/console.c | 45 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c index 109b6bb417..d3605aa39a 100644 --- a/dlls/kernel32/tests/console.c +++ b/dlls/kernel32/tests/console.c @@ -23,10 +23,8 @@ #include #include -BOOL WINAPI GetConsoleInputExeNameA(DWORD, LPSTR); -BOOL WINAPI GetConsoleInputExeNameW(DWORD, LPWSTR); -BOOL WINAPI SetConsoleInputExeNameA(LPCSTR); -BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR); +static BOOL (WINAPI *pGetConsoleInputExeNameA)(DWORD, LPSTR); +static BOOL (WINAPI *pSetConsoleInputExeNameA)(LPCSTR); /* DEFAULT_ATTRIB is used for all initial filling of the console. * all modifications are made with TEST_ATTRIB so that we could check @@ -55,6 +53,21 @@ BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR); ok(expect, "At (%d,%d): expecting attr %04x got %04x\n", (c).X, (c).Y, (attr), __attr); \ } while (0) +static void init_function_pointers(void) +{ + HMODULE hKernel32; + +#define KERNEL32_GET_PROC(func) \ + p##func = (void *)GetProcAddress(hKernel32, #func); \ + if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func); + + hKernel32 = GetModuleHandleA("kernel32.dll"); + KERNEL32_GET_PROC(GetConsoleInputExeNameA); + KERNEL32_GET_PROC(SetConsoleInputExeNameA); + +#undef KERNEL32_GET_PROC +} + /* FIXME: this could be optimized on a speed point of view */ static void resetContent(HANDLE hCon, COORD sbSize, BOOL content) { @@ -759,13 +772,13 @@ static void test_GetSetConsoleInputExeName(void) static char input_exe[MAX_PATH] = "winetest.exe"; SetLastError(0xdeadbeef); - ret = GetConsoleInputExeNameA(0, NULL); + ret = pGetConsoleInputExeNameA(0, NULL); error = GetLastError(); ok(ret, "GetConsoleInputExeNameA failed\n"); ok(error == ERROR_BUFFER_OVERFLOW, "got %u expected ERROR_BUFFER_OVERFLOW\n", error); SetLastError(0xdeadbeef); - ret = GetConsoleInputExeNameA(0, buffer); + ret = pGetConsoleInputExeNameA(0, buffer); error = GetLastError(); ok(ret, "GetConsoleInputExeNameA failed\n"); ok(error == ERROR_BUFFER_OVERFLOW, "got %u expected ERROR_BUFFER_OVERFLOW\n", error); @@ -773,26 +786,26 @@ static void test_GetSetConsoleInputExeName(void) GetModuleFileNameA(GetModuleHandle(NULL), module, sizeof(module)); p = strrchr(module, '\\') + 1; - ret = GetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer); + ret = pGetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer); ok(ret, "GetConsoleInputExeNameA failed\n"); todo_wine ok(!lstrcmpA(buffer, p), "got %s expected %s\n", buffer, p); SetLastError(0xdeadbeef); - ret = SetConsoleInputExeNameA(NULL); + ret = pSetConsoleInputExeNameA(NULL); error = GetLastError(); ok(!ret, "SetConsoleInputExeNameA failed\n"); ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error); SetLastError(0xdeadbeef); - ret = SetConsoleInputExeNameA(""); + ret = pSetConsoleInputExeNameA(""); error = GetLastError(); ok(!ret, "SetConsoleInputExeNameA failed\n"); ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error); - ret = SetConsoleInputExeNameA(input_exe); + ret = pSetConsoleInputExeNameA(input_exe); ok(ret, "SetConsoleInputExeNameA failed\n"); - ret = GetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer); + ret = pGetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer); ok(ret, "GetConsoleInputExeNameA failed\n"); ok(!lstrcmpA(buffer, input_exe), "got %s expected %s\n", buffer, input_exe); } @@ -803,6 +816,8 @@ START_TEST(console) BOOL ret; CONSOLE_SCREEN_BUFFER_INFO sbi; + init_function_pointers(); + /* be sure we have a clean console (and that's our own) * FIXME: this will make the test fail (currently) if we don't run * under X11 @@ -836,5 +851,11 @@ START_TEST(console) testCtrlHandler(); /* still to be done: access rights & access on objects */ - test_GetSetConsoleInputExeName(); + if (!pGetConsoleInputExeNameA && !pSetConsoleInputExeNameA) + { + skip("GetConsoleInputExeNameA and/or SetConsoleInputExeNameA is not available\n"); + return; + } + else + test_GetSetConsoleInputExeName(); }