diff --git a/modules/rostests/apitests/user32/CMakeLists.txt b/modules/rostests/apitests/user32/CMakeLists.txt index 47188cc34d8..da9e7083400 100644 --- a/modules/rostests/apitests/user32/CMakeLists.txt +++ b/modules/rostests/apitests/user32/CMakeLists.txt @@ -29,6 +29,7 @@ list(APPEND SOURCE GetWindowPlacement.c GW_ENABLEDPOPUP.c InitializeLpkHooks.c + IsServerSideWindow.c KbdLayout.c keybd_event.c LoadImage.c diff --git a/modules/rostests/apitests/user32/IsServerSideWindow.c b/modules/rostests/apitests/user32/IsServerSideWindow.c new file mode 100644 index 00000000000..3418c6f54df --- /dev/null +++ b/modules/rostests/apitests/user32/IsServerSideWindow.c @@ -0,0 +1,104 @@ +/* + * PROJECT: ReactOS API tests + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Test for IsServerSideWindow + * COPYRIGHT: Copyright 2024 Oleg Dubinskiy + * Copyright 2026 Mohammad Amin Mollazadeh + */ + +#include "precomp.h" + +static const WCHAR WndClass[] = L"window class"; + +static LRESULT +CALLBACK +Test_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_PAINT: + return 0; + + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + + return DefWindowProcW(hWnd, msg, wParam, lParam); +} + +START_TEST(IsServerSideWindow) +{ + HWND hWnd; + WNDCLASSEXW wcx; + BOOL ret; + + ZeroMemory(&wcx, sizeof(wcx)); + wcx.cbSize = sizeof(wcx); + wcx.lpfnWndProc = Test_WndProc; + wcx.hInstance = GetModuleHandleW(NULL); + wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcx.lpszClassName = WndClass; + + if (!RegisterClassExW(&wcx)) + { + skip("RegisterClassExW failed with error %lu\n", GetLastError()); + return; + } + + /* 1. Invalid window */ + hWnd = (HWND)(UINT_PTR)0xdeadbeef; + SetLastError(0xfeedfab1); + ret = IsServerSideWindow(hWnd); + ok(!ret, "The window %p is invalid but IsServerSideWindow() returned TRUE\n", hWnd); + ok_eq_ulong(GetLastError(), ERROR_INVALID_WINDOW_HANDLE); + + /* 2. Window with a kernel-mode WndProc. + * ScrollBar is an example of a server-side window that can be created from user-mode code. */ + hWnd = CreateWindowExW(0, + L"ScrollBar", + NULL, + SBS_HORZ | WS_VISIBLE, + CW_USEDEFAULT, CW_USEDEFAULT, + 400, 100, + NULL, 0, + wcx.hInstance, NULL); + if (!hWnd) + { + skip("CreateWindowExW failed with error %lu\n", GetLastError()); + goto Quit; + } + + SetLastError(0xfeedfab1); + ret = IsServerSideWindow(hWnd); + ok(ret, "The window %p is invalid or doesn't have a valid kernel-mode WndProc\n", hWnd); + ok_eq_ulong(GetLastError(), 0xfeedfab1); // The last-error shouldn't change. + + DestroyWindow(hWnd); + + /* 3. Window with a user-mode WndProc */ + hWnd = CreateWindowExW(0, + WndClass, + NULL, + WS_CAPTION | WS_SYSMENU, + CW_USEDEFAULT, CW_USEDEFAULT, + 400, 100, + NULL, 0, + wcx.hInstance, NULL); + if (!hWnd) + { + skip("CreateWindowExW failed with error %lu\n", GetLastError()); + goto Quit; + } + + SetLastError(0xfeedfab1); + ret = IsServerSideWindow(hWnd); + ok(!ret, "The window %p has a valid kernel-mode WndProc when it should not\n", hWnd); + ok_eq_ulong(GetLastError(), 0xfeedfab1); // The last-error shouldn't change. + + DestroyWindow(hWnd); + +Quit: + UnregisterClassW(WndClass, wcx.hInstance); + return; +} diff --git a/modules/rostests/apitests/user32/testlist.c b/modules/rostests/apitests/user32/testlist.c index a73593f3153..4bc21ef39fc 100644 --- a/modules/rostests/apitests/user32/testlist.c +++ b/modules/rostests/apitests/user32/testlist.c @@ -29,6 +29,7 @@ extern void func_GetUserObjectInformation(void); extern void func_GetWindowPlacement(void); extern void func_GW_ENABLEDPOPUP(void); extern void func_InitializeLpkHooks(void); +extern void func_IsServerSideWindow(void); extern void func_KbdLayout(void); extern void func_keybd_event(void); extern void func_LoadImage(void); @@ -94,6 +95,7 @@ const struct test winetest_testlist[] = { "GetWindowPlacement", func_GetWindowPlacement }, { "GW_ENABLEDPOPUP", func_GW_ENABLEDPOPUP }, { "InitializeLpkHooks", func_InitializeLpkHooks }, + { "IsServerSideWindow", func_IsServerSideWindow }, { "KbdLayout", func_KbdLayout }, { "keybd_event", func_keybd_event }, { "LoadImage", func_LoadImage },