Module: wine Branch: master Commit: 8f3afb41204ba9886b88da58d0b4478346940948 URL: http://source.winehq.org/git/wine.git/?a=commit;h=8f3afb41204ba9886b88da58d0...
Author: Hans Leidekker hans@it.vu.nl Date: Sun Dec 2 22:12:19 2007 +0100
kernel32: Implement and test {G, S}etConsoleInputExeName{A, W}.
---
dlls/kernel32/console.c | 88 +++++++++++++++++++++++++--------------- dlls/kernel32/tests/console.c | 53 ++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 33 deletions(-)
diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c index ec9c15c..1f24614 100644 --- a/dlls/kernel32/console.c +++ b/dlls/kernel32/console.c @@ -55,6 +55,15 @@
WINE_DEFAULT_DEBUG_CHANNEL(console);
+static CRITICAL_SECTION CONSOLE_CritSect; +static CRITICAL_SECTION_DEBUG critsect_debug = +{ + 0, 0, &CONSOLE_CritSect, + { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": CONSOLE_CritSect") } +}; +static CRITICAL_SECTION CONSOLE_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 }; + static const WCHAR coninW[] = {'C','O','N','I','N','$',0}; static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
@@ -982,23 +991,35 @@ BOOL WINAPI GetConsoleKeyboardLayoutNameW(LPWSTR layoutName) return TRUE; }
+static WCHAR input_exe[MAX_PATH + 1]; + /*********************************************************************** - * GetConsoleInputExeNameA (KERNEL32.@) + * GetConsoleInputExeNameW (KERNEL32.@) */ -DWORD WINAPI GetConsoleInputExeNameA(DWORD BufferLength, LPSTR lpBuffer) +BOOL WINAPI GetConsoleInputExeNameW(DWORD buflen, LPWSTR buffer) { - DWORD ret = 0; - FIXME( "stub %u %p\n", BufferLength, lpBuffer); - return ret; + TRACE("%u %p\n", buflen, buffer); + + RtlEnterCriticalSection(&CONSOLE_CritSect); + if (buflen > strlenW(input_exe)) strcpyW(buffer, input_exe); + else SetLastError(ERROR_BUFFER_OVERFLOW); + RtlLeaveCriticalSection(&CONSOLE_CritSect); + + return TRUE; }
/*********************************************************************** - * GetConsoleInputExeNameW (KERNEL32.@) + * GetConsoleInputExeNameA (KERNEL32.@) */ -DWORD WINAPI GetConsoleInputExeNameW(DWORD BufferLength, LPWSTR lpBuffer) +BOOL WINAPI GetConsoleInputExeNameA(DWORD buflen, LPSTR buffer) { - DWORD ret = 0; - FIXME( "stub %u %p\n", BufferLength, lpBuffer); + WCHAR *bufferW; + BOOL ret; + + if (!(bufferW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflen))) return FALSE; + if ((ret = GetConsoleInputExeNameW(buflen, bufferW))) + WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, buflen, NULL, NULL); + HeapFree(GetProcessHeap(), 0, bufferW); return ret; }
@@ -1467,35 +1488,45 @@ BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
/****************************************************************************** * SetConsoleInputExeNameW [KERNEL32.@] - * - * BUGS - * Unimplemented */ BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR name) { - FIXME("(%s): stub!\n", debugstr_w(name)); + TRACE("(%s)\n", debugstr_w(name)); + + if (!name || !name[0]) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + RtlEnterCriticalSection(&CONSOLE_CritSect); + if (strlenW(name) < sizeof(input_exe)/sizeof(WCHAR)) strcpyW(input_exe, name); + RtlLeaveCriticalSection(&CONSOLE_CritSect);
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED); return TRUE; }
/****************************************************************************** * SetConsoleInputExeNameA [KERNEL32.@] - * - * BUGS - * Unimplemented */ BOOL WINAPI SetConsoleInputExeNameA(LPCSTR name) { - int len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0); - LPWSTR xptr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - BOOL ret; + int len; + LPWSTR nameW; + BOOL ret;
- if (!xptr) return FALSE; + if (!name || !name[0]) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0); + if (!(nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
- MultiByteToWideChar(CP_ACP, 0, name, -1, xptr, len); - ret = SetConsoleInputExeNameW(xptr); - HeapFree(GetProcessHeap(), 0, xptr); + MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, len); + ret = SetConsoleInputExeNameW(nameW); + HeapFree(GetProcessHeap(), 0, nameW);
return ret; } @@ -1534,15 +1565,6 @@ struct ConsoleHandler static struct ConsoleHandler CONSOLE_DefaultConsoleHandler = {CONSOLE_DefaultHandler, NULL}; static struct ConsoleHandler* CONSOLE_Handlers = &CONSOLE_DefaultConsoleHandler;
-static CRITICAL_SECTION CONSOLE_CritSect; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &CONSOLE_CritSect, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": CONSOLE_CritSect") } -}; -static CRITICAL_SECTION CONSOLE_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 }; - /*****************************************************************************/
/****************************************************************** diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c index 2a8c467..109b6bb 100644 --- a/dlls/kernel32/tests/console.c +++ b/dlls/kernel32/tests/console.c @@ -23,6 +23,11 @@ #include <windows.h> #include <stdio.h>
+BOOL WINAPI GetConsoleInputExeNameA(DWORD, LPSTR); +BOOL WINAPI GetConsoleInputExeNameW(DWORD, LPWSTR); +BOOL WINAPI SetConsoleInputExeNameA(LPCSTR); +BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR); + /* DEFAULT_ATTRIB is used for all initial filling of the console. * all modifications are made with TEST_ATTRIB so that we could check * what has to be modified or not @@ -746,6 +751,52 @@ static void testScreenBuffer(HANDLE hConOut) SetConsoleOutputCP(oldcp); }
+static void test_GetSetConsoleInputExeName(void) +{ + BOOL ret; + DWORD error; + char buffer[MAX_PATH], module[MAX_PATH], *p; + static char input_exe[MAX_PATH] = "winetest.exe"; + + SetLastError(0xdeadbeef); + ret = GetConsoleInputExeNameA(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); + error = GetLastError(); + ok(ret, "GetConsoleInputExeNameA failed\n"); + ok(error == ERROR_BUFFER_OVERFLOW, "got %u expected ERROR_BUFFER_OVERFLOW\n", error); + + GetModuleFileNameA(GetModuleHandle(NULL), module, sizeof(module)); + p = strrchr(module, '\') + 1; + + ret = GetConsoleInputExeNameA(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); + error = GetLastError(); + ok(!ret, "SetConsoleInputExeNameA failed\n"); + ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error); + + SetLastError(0xdeadbeef); + ret = SetConsoleInputExeNameA(""); + error = GetLastError(); + ok(!ret, "SetConsoleInputExeNameA failed\n"); + ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error); + + ret = SetConsoleInputExeNameA(input_exe); + ok(ret, "SetConsoleInputExeNameA failed\n"); + + ret = GetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer); + ok(ret, "GetConsoleInputExeNameA failed\n"); + ok(!lstrcmpA(buffer, input_exe), "got %s expected %s\n", buffer, input_exe); +} + START_TEST(console) { HANDLE hConIn, hConOut; @@ -784,4 +835,6 @@ START_TEST(console) testScreenBuffer(hConOut); testCtrlHandler(); /* still to be done: access rights & access on objects */ + + test_GetSetConsoleInputExeName(); }