[FORMATTING] Remove trailing whitespace. Addendum to 34593d93.
[reactos.git] / modules / rostests / apitests / user32 / SetActiveWindow.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetActiveWindow
5 * PROGRAMMERS: Giannis Adamopoulos
6 */
7
8 #include "precomp.h"
9
10 HWND hWnd1, hWnd2;
11
12 /* FIXME: test for HWND_TOP, etc...*/
13 static int get_iwnd(HWND hWnd)
14 {
15 if(hWnd == hWnd1) return 1;
16 else if(hWnd == hWnd2) return 2;
17 else return 0;
18 }
19
20 LRESULT CALLBACK OwnerTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
21 {
22 int iwnd = get_iwnd(hWnd);
23
24 if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message))
25 return DefWindowProc(hWnd, message, wParam, lParam);
26
27 switch(message)
28 {
29 case WM_QUERYNEWPALETTE:
30 {
31 HDC hdc = GetDC(0);
32 int bits = GetDeviceCaps(hdc,BITSPIXEL);
33 ok( bits == 8 , "expected WM_QUERYNEWPALETTE only on 8bpp\n");
34 ReleaseDC(0, hdc);
35 return FALSE;
36 }
37 case WM_IME_SETCONTEXT:
38 case WM_IME_NOTIFY :
39 case WM_GETICON :
40 case WM_GETTEXT:
41 break;
42 case WM_WINDOWPOSCHANGING:
43 case WM_WINDOWPOSCHANGED:
44 {
45 WINDOWPOS* pwp = (WINDOWPOS*)lParam;
46 ok(wParam==0,"expected wParam=0\n");
47 RECORD_MESSAGE(iwnd, message, SENT, get_iwnd(pwp->hwndInsertAfter), pwp->flags);
48 break;
49 }
50 default:
51 RECORD_MESSAGE(iwnd, message, SENT, 0,0);
52 }
53 return DefWindowProc(hWnd, message, wParam, lParam);
54 }
55
56 static void FlushMessages()
57 {
58 MSG msg;
59
60 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
61 {
62 int iwnd = get_iwnd(msg.hwnd);
63 if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
64 RECORD_MESSAGE(iwnd, msg.message, POST,0,0);
65 DispatchMessageA( &msg );
66 }
67 }
68
69 static void create_test_windows()
70 {
71 RegisterSimpleClass(OwnerTestProc, L"ownertest");
72 hWnd1 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
73 20, 20, 300, 300, NULL, NULL, 0, NULL);
74
75 hWnd2 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
76 200, 200, 300, 300, NULL, NULL, 0, NULL);
77 }
78
79 static void set_default_zorder()
80 {
81 SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
82 SetWindowPos(hWnd2, 0, 0,0,0,0, SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
83
84 FlushMessages();
85 EMPTY_CACHE();
86 }
87
88 static void destroy_test_window()
89 {
90 DestroyWindow(hWnd1);
91 DestroyWindow(hWnd2);
92 UnregisterClassW(L"testClass", 0);
93 }
94
95 MSG_ENTRY activate2to1_chain[]={
96 {2,WM_NCACTIVATE},
97 {2,WM_ACTIVATE},
98 {1,WM_WINDOWPOSCHANGING, SENT,0, SWP_NOSIZE|SWP_NOMOVE},
99 {1,WM_WINDOWPOSCHANGED, SENT,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
100 {1,WM_NCACTIVATE},
101 {1,WM_ACTIVATE},
102 {2,WM_KILLFOCUS},
103 {1,WM_SETFOCUS},
104 {0,0}};
105
106 MSG_ENTRY activate1to2_chain[]={
107 {1,WM_NCACTIVATE},
108 {1,WM_ACTIVATE},
109 {2,WM_WINDOWPOSCHANGING, SENT,0, SWP_NOSIZE|SWP_NOMOVE},
110 {2,WM_WINDOWPOSCHANGED, SENT,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
111 {2,WM_NCACTIVATE},
112 {2,WM_ACTIVATE},
113 {1,WM_KILLFOCUS},
114 {2,WM_SETFOCUS},
115 {0,0}};
116
117 void Test_msg_simple()
118 {
119 SetCursorPos(0,0);
120
121 create_test_windows();
122 set_default_zorder();
123
124 SetActiveWindow(hWnd1);
125 FlushMessages();
126 COMPARE_CACHE(activate2to1_chain);
127
128 SetActiveWindow(hWnd2);
129 FlushMessages();
130 COMPARE_CACHE(activate1to2_chain);
131
132 destroy_test_window();
133 }
134
135 START_TEST(SetActiveWindow)
136 {
137 Test_msg_simple();
138 }