Author: mjansen Date: Sun May 28 13:55:05 2017 New Revision: 74689 URL: http://svn.reactos.org/svn/reactos?rev=74689&view=rev Log: [USER32_APITEST] Add tests to validate messages sent during window creation / modifying of styles. CORE-12052
Modified: trunk/rostests/apitests/include/msgtrace.c trunk/rostests/apitests/include/msgtrace.h trunk/rostests/apitests/user32/CreateWindowEx.c Modified: trunk/rostests/apitests/include/msgtrace.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/include/msgtrace.c?rev=74689&r1=74688&r2=74689&view=diff ============================================================================== --- trunk/rostests/apitests/include/msgtrace.c [iso-8859-1] (original) +++ trunk/rostests/apitests/include/msgtrace.c [iso-8859-1] Sun May 28 13:55:05 2017 @@ -62,6 +62,8 @@ case WM_COMMAND: return "WM_COMMAND"; case WM_PRINTCLIENT: return "WM_PRINTCLIENT"; case WM_CTLCOLORSTATIC: return "WM_CTLCOLORSTATIC"; + case WM_STYLECHANGING: return "WM_STYLECHANGING"; + case WM_STYLECHANGED: return "WM_STYLECHANGED"; default: return NULL; } } @@ -97,12 +99,14 @@ switch (msg->type) { case POST: + case MARKER: msgName = get_msg_name(msg->msg); - msgType = "post msg"; + msgType = msg->type == POST ? "post msg" : "marker"; break; case SENT: + case SENT_RET: msgName = get_msg_name(msg->msg); - msgType = "sent msg"; + msgType = msg->type == SENT ? "sent msg" : "sent_ret msg"; break; case HOOK: msgName = get_hook_name(msg->msg); Modified: trunk/rostests/apitests/include/msgtrace.h URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/include/msgtrace.h?rev=74689&r1=74688&r2=74689&view=diff ============================================================================== --- trunk/rostests/apitests/include/msgtrace.h [iso-8859-1] (original) +++ trunk/rostests/apitests/include/msgtrace.h [iso-8859-1] Sun May 28 13:55:05 2017 @@ -6,7 +6,9 @@ SENT, POST, HOOK, - EVENT + EVENT, + SENT_RET, + MARKER } MSG_TYPE; typedef struct _MSG_ENTRY Modified: trunk/rostests/apitests/user32/CreateWindowEx.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/user32/CreateWindowEx.c?rev=74689&r1=74688&r2=74689&view=diff ============================================================================== --- trunk/rostests/apitests/user32/CreateWindowEx.c [iso-8859-1] (original) +++ trunk/rostests/apitests/user32/CreateWindowEx.c [iso-8859-1] Sun May 28 13:55:05 2017 @@ -3,13 +3,15 @@ * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory * PURPOSE: Test for CreateWindowEx * PROGRAMMERS: Thomas Faber <thomas.fa...@reactos.org> + * Mark Jansen */ #include <apitest.h> #include <winuser.h> - - -START_TEST(CreateWindowEx) +#include <msgtrace.h> +#include <user32testhelpers.h> + +static void Test_Params(void) { HWND hWnd; DWORD dwError; @@ -65,3 +67,258 @@ ok(hWnd == NULL, "hWnd = %p\n", hWnd); ok(dwError == ERROR_INVALID_WINDOW_HANDLE, "error = %lu\n", dwError); } + +HWND g_TestWindow = NULL; + +static int get_iwnd(HWND hWnd) +{ + if (!g_TestWindow) + g_TestWindow = hWnd; + + return hWnd == g_TestWindow ? 1 : 0; +} + +DWORD g_FaultLine = 0; +DWORD g_NcExpectStyle = 0; +DWORD g_NcExpectExStyle = 0; +DWORD g_ExpectStyle = 0; +DWORD g_ExpectExStyle = 0; + +#define ok_hex_(expression, result) \ + do { \ + int _value = (expression); \ + ok_(__FILE__, g_FaultLine)(_value == (result), "Wrong value for '%s', expected: " #result " (0x%x), got: 0x%x\n", \ + #expression, (int)(result), _value); \ + } while (0) + + + +static int g_ChangeStyle = 0; +static LRESULT CALLBACK MSGTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + LRESULT lRet; + int iwnd = get_iwnd(hWnd); + + if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message)) + return DefWindowProc(hWnd, message, wParam, lParam); + + switch(message) + { + case WM_IME_SETCONTEXT: + case WM_IME_NOTIFY: + case WM_GETICON: + case WM_GETTEXT: + return DefWindowProc(hWnd, message, wParam, lParam); + break; + case WM_NCCREATE: + { + LPCREATESTRUCT create = (LPCREATESTRUCT)lParam; + RECORD_MESSAGE(iwnd, message, SENT, 0, 0); + ok_hex_(create->style, g_NcExpectStyle); + ok_hex_(create->dwExStyle, g_NcExpectExStyle); + if (g_ChangeStyle) + { + DWORD dwStyle = GetWindowLong(hWnd, GWL_EXSTYLE); + dwStyle &= ~(WS_EX_CLIENTEDGE); + SetWindowLong(hWnd, GWL_EXSTYLE, dwStyle); + RECORD_MESSAGE(iwnd, message, MARKER, 0, 0); + SetWindowPos(hWnd, NULL, 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_DRAWFRAME); + + RECORD_MESSAGE(iwnd, message, MARKER, 0, 0); + ok_hex_(create->style, g_NcExpectStyle); + ok_hex_(create->dwExStyle, g_NcExpectExStyle); + } + } + break; + case WM_CREATE: + { + LPCREATESTRUCT create = (LPCREATESTRUCT)lParam; + RECORD_MESSAGE(iwnd, message, SENT, 0, 0); + ok_hex_(create->style, g_ExpectStyle); + ok_hex_(create->dwExStyle, g_ExpectExStyle); + } + break; + case WM_NCCALCSIZE: + case WM_STYLECHANGING: + case WM_STYLECHANGED: + case WM_SIZE: + RECORD_MESSAGE(iwnd, message, SENT, wParam, 0); + break; + case WM_WINDOWPOSCHANGING: + case WM_WINDOWPOSCHANGED: + ok(wParam == 0,"expected wParam=0\n"); + RECORD_MESSAGE(iwnd, message, SENT, ((WINDOWPOS*)lParam)->flags, 0); + break; + default: + RECORD_MESSAGE(iwnd, message, SENT, 0, 0); + break; + } + lRet = DefWindowProc(hWnd, message, wParam, lParam); + RECORD_MESSAGE(iwnd, message, SENT_RET, 0, 0); + return lRet; +} + +MSG_ENTRY create_chain[] = +{ + { 1, WM_GETMINMAXINFO, SENT }, + { 1, WM_GETMINMAXINFO, SENT_RET }, + { 1, WM_NCCREATE, SENT }, + { 1, WM_NCCREATE, SENT_RET }, + { 1, WM_NCCALCSIZE, SENT }, + { 1, WM_NCCALCSIZE, SENT_RET }, + { 1, WM_CREATE, SENT }, + { 1, WM_CREATE, SENT_RET }, + { 0, 0 } +}; + +MSG_ENTRY create_chain_modify[] = +{ + { 1, WM_GETMINMAXINFO, SENT }, + { 1, WM_GETMINMAXINFO, SENT_RET }, + { 1, WM_NCCREATE, SENT }, + { 1, WM_STYLECHANGING, SENT, GWL_EXSTYLE }, + { 1, WM_STYLECHANGING, SENT_RET }, + { 1, WM_STYLECHANGED, SENT, GWL_EXSTYLE }, + { 1, WM_STYLECHANGED, SENT_RET }, + { 1, WM_NCCREATE, MARKER }, + { 1, WM_WINDOWPOSCHANGING, SENT, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED }, + { 1, WM_WINDOWPOSCHANGING, SENT_RET }, + { 1, WM_NCCALCSIZE, SENT, TRUE }, + { 1, WM_NCCALCSIZE, SENT_RET }, + { 1, WM_WINDOWPOSCHANGED, SENT, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED }, + { 1, WM_MOVE, SENT }, + { 1, WM_MOVE, SENT_RET }, + { 1, WM_SIZE, SENT }, + { 1, WM_SIZE, SENT_RET }, + { 1, WM_WINDOWPOSCHANGED, SENT_RET }, + { 1, WM_NCCREATE, MARKER }, + { 1, WM_NCCREATE, SENT_RET }, + { 1, WM_NCCALCSIZE, SENT }, + { 1, WM_NCCALCSIZE, SENT_RET }, + { 1, WM_CREATE, SENT }, + { 1, WM_CREATE, SENT_RET }, + { 0, 0 } +}; + +MSG_ENTRY create_chain_modify_below8_nonsrv[] = +{ + { 1, WM_GETMINMAXINFO, SENT }, + { 1, WM_GETMINMAXINFO, SENT_RET }, + { 1, WM_NCCREATE, SENT }, + { 1, WM_STYLECHANGING, SENT, GWL_EXSTYLE }, + { 1, WM_STYLECHANGING, SENT_RET }, + { 1, WM_STYLECHANGED, SENT, GWL_EXSTYLE }, + { 1, WM_STYLECHANGED, SENT_RET }, + { 1, WM_NCCREATE, MARKER }, + { 1, WM_WINDOWPOSCHANGING, SENT, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED }, + { 1, WM_WINDOWPOSCHANGING, SENT_RET }, + { 1, WM_NCCALCSIZE, SENT, TRUE }, + { 1, WM_NCCALCSIZE, SENT_RET }, + { 1, WM_WINDOWPOSCHANGED, SENT, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED }, + { 1, WM_MOVE, SENT }, + { 1, WM_MOVE, SENT_RET }, + { 1, WM_SIZE, SENT }, + { 1, WM_SIZE, SENT_RET }, + { 1, WM_WINDOWPOSCHANGED, SENT_RET }, + { 1, WM_NCCALCSIZE, SENT, TRUE }, + { 1, WM_NCCALCSIZE, SENT_RET }, + { 1, WM_NCCREATE, MARKER }, + { 1, WM_NCCREATE, SENT_RET }, + { 1, WM_NCCALCSIZE, SENT }, + { 1, WM_NCCALCSIZE, SENT_RET }, + { 1, WM_CREATE, SENT }, + { 1, WM_CREATE, SENT_RET }, + { 0, 0 } +}; + + +static BOOL +IsWindowsServer() +{ + OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, 0, VER_NT_WORKSTATION }; + DWORDLONG const dwlConditionMask = VerSetConditionMask( 0, VER_PRODUCT_TYPE, VER_EQUAL ); + + return !VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, dwlConditionMask); +} + + +static BOOL +IsWindows8OrGreater() +{ + OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 }; + DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask( + VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL), + VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + + osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_WIN8); + osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_WIN8); + + return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; +} + +static void Test_Messages(void) +{ + HWND hWnd; + BOOL Below8NonServer = !IsWindows8OrGreater() && !IsWindowsServer(); + + RegisterSimpleClass(MSGTestProc, L"Test_Message_Window_XX"); + + g_ExpectStyle = g_NcExpectStyle = 0; + g_ExpectExStyle = g_NcExpectExStyle = WS_EX_CLIENTEDGE; + g_FaultLine = __LINE__ + 1; + hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Test_Message_Window_XX", L"", 0, 10, 20, + 200, 210, NULL, NULL, 0, NULL); + + ok(hWnd == g_TestWindow, "We are testing with %p instead of %p\n", g_TestWindow, hWnd); + COMPARE_CACHE(create_chain); + DestroyWindow(hWnd); + g_TestWindow = NULL; + EMPTY_CACHE(); + + g_ExpectStyle = g_NcExpectStyle = WS_OVERLAPPEDWINDOW; + g_ExpectExStyle = g_NcExpectExStyle = WS_EX_OVERLAPPEDWINDOW; + g_FaultLine = __LINE__ + 1; + hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Test_Message_Window_XX", L"", WS_OVERLAPPEDWINDOW, 10, 20, + 200, 210, NULL, NULL, 0, NULL); + + ok(hWnd == g_TestWindow, "We are testing with %p instead of %p\n", g_TestWindow, hWnd); + COMPARE_CACHE(create_chain); + DestroyWindow(hWnd); + g_TestWindow = NULL; + EMPTY_CACHE(); + + g_ChangeStyle = 1; + + g_ExpectStyle = g_NcExpectStyle = 0; + g_ExpectExStyle = g_NcExpectExStyle = WS_EX_CLIENTEDGE; + g_FaultLine = __LINE__ + 1; + hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Test_Message_Window_XX", L"", 0, 10, 20, + 200, 210, NULL, NULL, 0, NULL); + + ok(hWnd == g_TestWindow, "We are testing with %p instead of %p\n", g_TestWindow, hWnd); + COMPARE_CACHE(Below8NonServer ? create_chain_modify_below8_nonsrv : create_chain_modify); + DestroyWindow(hWnd); + g_TestWindow = NULL; + EMPTY_CACHE(); + + g_ExpectStyle = g_NcExpectStyle = WS_OVERLAPPEDWINDOW; + g_ExpectExStyle = g_NcExpectExStyle = WS_EX_OVERLAPPEDWINDOW; + g_FaultLine = __LINE__ + 1; + hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Test_Message_Window_XX", L"", WS_OVERLAPPEDWINDOW, 10, 20, + 200, 210, NULL, NULL, 0, NULL); + + ok(hWnd == g_TestWindow, "We are testing with %p instead of %p\n", g_TestWindow, hWnd); + COMPARE_CACHE(Below8NonServer ? create_chain_modify_below8_nonsrv : create_chain_modify); + DestroyWindow(hWnd); + g_TestWindow = NULL; + EMPTY_CACHE(); +} + + +START_TEST(CreateWindowEx) +{ + Test_Params(); + Test_Messages(); +}