From: Patrick Hibbs Subject: [PATCH v2 6/6] wtsapi32/tests: Add test for WTSRegisterSessionNotification(). Message-Id: <20190714002104.22262-7-hibbsncc1701@gmail.com> Date: Sat, 13 Jul 2019 20:21:04 -0400 In-Reply-To: <20190714002104.22262-1-hibbsncc1701@gmail.com> References: <20190714002104.22262-1-hibbsncc1701@gmail.com> From: Patrick Hibbs Signed-off-by: Patrick Hibbs --- v2: Fix test for Windows XP. --- dlls/wtsapi32/tests/wtsapi.c | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/dlls/wtsapi32/tests/wtsapi.c b/dlls/wtsapi32/tests/wtsapi.c index 67f56bbd7f..1686c077ea 100644 --- a/dlls/wtsapi32/tests/wtsapi.c +++ b/dlls/wtsapi32/tests/wtsapi.c @@ -22,9 +22,12 @@ #include #include #include +#include #include "wine/test.h" +static const CHAR testwindow_class[] = "testwindow"; + static void test_WTSEnumerateProcessesW(void) { BOOL found = FALSE, ret; @@ -115,9 +118,93 @@ static void test_WTSQueryUserToken(void) ok(GetLastError()==ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError()); } +static LRESULT CALLBACK testwindow_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + /* TODO: Actually check for WM_WTSSESSION_CHANGE messages. + */ + return DefWindowProcA(hwnd, msg, wparam, lparam); +} + +static void register_testwindow_class(void) +{ + WNDCLASSEXA cls; + + ZeroMemory(&cls, sizeof(cls)); + cls.cbSize = sizeof(cls); + cls.style = 0; + cls.lpfnWndProc = testwindow_wndproc; + cls.hInstance = NULL; + cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW); + cls.hbrBackground = (HBRUSH) COLOR_WINDOW; + cls.lpszClassName = testwindow_class; + + RegisterClassExA(&cls); +} + +typedef BOOL (WINAPI *RegFunc)(HWND, DWORD); +typedef BOOL (WINAPI *UnRegFunc)(HWND); + +static void test_WTSRegisterSessionNotification(void) +{ + BOOL ret; + HWND hwnd0; + HWND hwnd1; + HANDLE lib; + RegFunc regFunc; + UnRegFunc unRegFunc; + + register_testwindow_class(); + + hwnd0 = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_TOPMOST, + testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, + NULL, NULL, NULL, NULL); + ok(hwnd0 != NULL, "couldn't create window\n"); + + hwnd1 = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_TOPMOST, + testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, + NULL, NULL, NULL, NULL); + ok(hwnd1 != NULL, "couldn't create window\n"); + + lib = LoadLibraryA("WTSAPI32.DLL"); + if (lib != NULL) + { + regFunc = (RegFunc) GetProcAddress(lib, "WTSRegisterSessionNotification"); + unRegFunc = (UnRegFunc) GetProcAddress(lib, "WTSUnRegisterSessionNotification"); + if (regFunc && unRegFunc) + { + ret = regFunc(hwnd0, 0); + ok(ret, "WTSRegisterSessionNotification: Initial call, no registered windows.\n"); + ret = regFunc(hwnd0, 0); + ok(ret, "WTSRegisterSessionNotification: Re-register a window.\n"); + ret = regFunc(hwnd0, 1); + ok(ret, + "WTSRegisterSessionNotification: Re-register a window with diff flags.\n"); + ret = regFunc(hwnd1, 0); + ok(ret, "WTSRegisterSessionNotification: Register additional window.\n"); + ret = regFunc(hwnd1, 0); + ok(ret, "WTSRegisterSessionNotification: Re-register window2.\n"); + ret = regFunc(hwnd1, 1); + ok(ret, + "WTSRegisterSessionNotification: Re-register window2 with diff flags.\n"); + ret = unRegFunc(hwnd0); + ok(ret, "WTSUnRegisterSessionNotification: Initial call with first window.\n"); + ret = unRegFunc(hwnd0); + ok(ret, "WTSUnRegisterSessionNotification: Repeat call with first window.\n"); + ret = unRegFunc(hwnd1); + ok(ret, "WTSUnRegisterSessionNotification: Initial call with second window.\n"); + ret = unRegFunc(hwnd1); + ok(ret, "WTSUnRegisterSessionNotification: Repeat call with second window.\n"); + } + } + + DestroyWindow(hwnd0); + DestroyWindow(hwnd1); +} + START_TEST (wtsapi) { test_WTSEnumerateProcessesW(); test_WTSQuerySessionInformationW(); test_WTSQueryUserToken(); + test_WTSRegisterSessionNotification(); } -- 2.22.0