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