~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/comctl32/tests/subclass.c

Version: ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /* Unit tests for subclassed windows.
  2  *
  3  * Copyright 2004 Kevin Koltzau
  4  *
  5  * This library is free software; you can redistribute it and/or
  6  * modify it under the terms of the GNU Lesser General Public
  7  * License as published by the Free Software Foundation; either
  8  * version 2.1 of the License, or (at your option) any later version.
  9  *
 10  * This library is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  * Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public
 16  * License along with this library; if not, write to the Free Software
 17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 18  */
 19 
 20 #include <assert.h>
 21 #include <stdarg.h>
 22 
 23 #define _WIN32_WINNT 0x0501 /* For SetWindowSubclass/etc */
 24 
 25 #include "windef.h"
 26 #include "winbase.h"
 27 #include "wingdi.h"
 28 #include "winuser.h"
 29 #include "commctrl.h"
 30 
 31 #include "wine/test.h"
 32 
 33 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
 34 static BOOL (WINAPI *pRemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR);
 35 static LRESULT (WINAPI *pDefSubclassProc)(HWND, UINT, WPARAM, LPARAM);
 36 
 37 #define SEND_NEST   0x01
 38 #define DELETE_SELF 0x02
 39 #define DELETE_PREV 0x04
 40 
 41 struct message {
 42     int procnum;           /* WndProc id message is expected from */
 43     WPARAM wParam;         /* expected value of wParam */
 44 };
 45 
 46 static int sequence_cnt, sequence_size;
 47 static struct message* sequence;
 48 
 49 static const struct message Sub_BasicTest[] = {
 50     { 2, 1 },
 51     { 1, 1 },
 52     { 2, 2 },
 53     { 1, 2 },
 54     { 0 }
 55 };
 56 
 57 static const struct message Sub_DeletedTest[] = {
 58     { 2, 1 },
 59     { 1, 1 },
 60     { 0 }
 61 };
 62 
 63 static const struct message Sub_AfterDeletedTest[] = {
 64     { 1, 1 },
 65     { 0 }
 66 };
 67 
 68 static const struct message Sub_OldAfterNewTest[] = {
 69     { 3, 1 },
 70     { 2, 1 },
 71     { 1, 1 },
 72     { 3, 2 },
 73     { 2, 2 },
 74     { 1, 2 },
 75     { 0 }
 76 };
 77 
 78 static const struct message Sub_MixTest[] = {
 79     { 3, 1 },
 80     { 4, 1 },
 81     { 2, 1 },
 82     { 1, 1 },
 83     { 0 }
 84 };
 85 
 86 static const struct message Sub_MixAndNestTest[] = {
 87     { 3, 1 },
 88     { 4, 1 },
 89     { 3, 2 },
 90     { 4, 2 },
 91     { 2, 2 },
 92     { 1, 2 },
 93     { 2, 1 },
 94     { 1, 1 },
 95     { 0 }
 96 };
 97 
 98 static const struct message Sub_MixNestDelTest[] = {
 99     { 3, 1 },
100     { 4, 1 },
101     { 3, 2 },
102     { 2, 2 },
103     { 1, 2 },
104     { 2, 1 },
105     { 1, 1 },
106     { 0 }
107 };
108 
109 static const struct message Sub_MixDelPrevTest[] = {
110     { 3, 1 },
111     { 5, 1 },
112     { 2, 1 },
113     { 1, 1 },
114     { 0 }
115 };
116 
117 static void add_message(const struct message *msg)
118 {
119     if (!sequence)
120     {
121         sequence_size = 10;
122         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
123     }
124     if (sequence_cnt == sequence_size)
125     {
126         sequence_size *= 2;
127         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
128     }
129     assert(sequence);
130 
131     sequence[sequence_cnt].wParam  = msg->wParam;
132     sequence[sequence_cnt].procnum = msg->procnum;
133 
134     sequence_cnt++;
135 }
136 
137 static void flush_sequence(void)
138 {
139     HeapFree(GetProcessHeap(), 0, sequence);
140     sequence = 0;
141     sequence_cnt = sequence_size = 0;
142 }
143 
144 static void ok_sequence(const struct message *expected, const char *context)
145 {
146     static const struct message end_of_sequence = { 0, 0 };
147     const struct message *actual;
148 
149     add_message(&end_of_sequence);
150 
151     actual = sequence;
152 
153     while(expected->procnum && actual->procnum)
154     {
155         ok(expected->procnum == actual->procnum,
156             "%s: the procnum %d was expected, but got procnum %d instead\n",
157             context, expected->procnum, actual->procnum);
158         ok(expected->wParam == actual->wParam,
159             "%s: in procnum %d expecting wParam 0x%lx got 0x%lx\n",
160             context, expected->procnum, expected->wParam, actual->wParam);
161         expected++;
162         actual++;
163     }
164     ok(!expected->procnum, "Received fewer messages than expected\n");
165     ok(!actual->procnum, "Received more messages than expected\n");
166     flush_sequence();
167 }
168 
169 static LRESULT WINAPI WndProc1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
170 {
171     struct message msg;
172     
173     if(message == WM_USER) {
174         msg.wParam = wParam;
175         msg.procnum = 1;
176         add_message(&msg);
177     }
178     return DefWindowProc(hwnd, message, wParam, lParam);
179 }
180 
181 
182 static WNDPROC origProc3;
183 static LRESULT WINAPI WndProc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
184 {
185     struct message msg;
186     
187     if(message == WM_USER) {
188         msg.wParam = wParam;
189         msg.procnum = 3;
190         add_message(&msg);
191     }
192     return CallWindowProc(origProc3, hwnd, message, wParam, lParam);
193 }
194 
195 static LRESULT WINAPI WndProcSub(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uldSubclass, DWORD_PTR dwRefData)
196 {
197     struct message msg;
198     
199     if(message == WM_USER) {
200         msg.wParam = wParam;
201         msg.procnum = uldSubclass;
202         add_message(&msg);
203         
204         if(lParam) {
205             if(dwRefData & DELETE_SELF) {
206                 pRemoveWindowSubclass(hwnd, WndProcSub, uldSubclass);
207                 pRemoveWindowSubclass(hwnd, WndProcSub, uldSubclass);
208             }
209             if(dwRefData & DELETE_PREV)
210                 pRemoveWindowSubclass(hwnd, WndProcSub, uldSubclass-1);
211             if(dwRefData & SEND_NEST)
212                 SendMessage(hwnd, WM_USER, wParam+1, 0);
213         }
214     }
215     return pDefSubclassProc(hwnd, message, wParam, lParam);
216 }
217 
218 static void test_subclass(void)
219 {
220     HWND hwnd = CreateWindowExA(0, "TestSubclass", "Test subclass", WS_OVERLAPPEDWINDOW,
221                            100, 100, 200, 200, 0, 0, 0, NULL);
222     assert(hwnd);
223 
224     pSetWindowSubclass(hwnd, WndProcSub, 2, 0);
225     SendMessage(hwnd, WM_USER, 1, 0);
226     SendMessage(hwnd, WM_USER, 2, 0);
227     ok_sequence(Sub_BasicTest, "Basic");
228 
229     pSetWindowSubclass(hwnd, WndProcSub, 2, DELETE_SELF);
230     SendMessage(hwnd, WM_USER, 1, 1);
231     ok_sequence(Sub_DeletedTest, "Deleted");
232 
233     SendMessage(hwnd, WM_USER, 1, 0);
234     ok_sequence(Sub_AfterDeletedTest, "After Deleted");
235 
236     pSetWindowSubclass(hwnd, WndProcSub, 2, 0);
237     origProc3 = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG)WndProc3);
238     SendMessage(hwnd, WM_USER, 1, 0);
239     SendMessage(hwnd, WM_USER, 2, 0);
240     ok_sequence(Sub_OldAfterNewTest, "Old after New");
241 
242     pSetWindowSubclass(hwnd, WndProcSub, 4, 0);
243     SendMessage(hwnd, WM_USER, 1, 0);
244     ok_sequence(Sub_MixTest, "Mix");
245 
246     /* Now the fun starts */
247     pSetWindowSubclass(hwnd, WndProcSub, 4, SEND_NEST);
248     SendMessage(hwnd, WM_USER, 1, 1);
249     ok_sequence(Sub_MixAndNestTest, "Mix and nest");
250 
251     pSetWindowSubclass(hwnd, WndProcSub, 4, SEND_NEST | DELETE_SELF);
252     SendMessage(hwnd, WM_USER, 1, 1);
253     ok_sequence(Sub_MixNestDelTest, "Mix, nest, del");
254 
255     pSetWindowSubclass(hwnd, WndProcSub, 4, 0);
256     pSetWindowSubclass(hwnd, WndProcSub, 5, DELETE_PREV);
257     SendMessage(hwnd, WM_USER, 1, 1);
258     ok_sequence(Sub_MixDelPrevTest, "Mix and del prev");
259 
260     DestroyWindow(hwnd);
261 }
262 
263 static BOOL RegisterWindowClasses(void)
264 {
265     WNDCLASSA cls;
266 
267     cls.style = 0;
268     cls.lpfnWndProc = WndProc1;
269     cls.cbClsExtra = 0;
270     cls.cbWndExtra = 0;
271     cls.hInstance = GetModuleHandleA(0);
272     cls.hIcon = 0;
273     cls.hCursor = NULL;
274     cls.hbrBackground = NULL;
275     cls.lpszMenuName = NULL;
276     cls.lpszClassName = "TestSubclass";
277     if(!RegisterClassA(&cls)) return FALSE;
278     
279     return TRUE;
280 }
281 
282 START_TEST(subclass)
283 {
284     HMODULE hdll;
285     
286     hdll = GetModuleHandleA("comctl32.dll");
287     assert(hdll);
288     /* Functions have to be loaded by ordinal. Only XP and W2K3 export
289      * them by name.
290      */
291     pSetWindowSubclass = (void*)GetProcAddress(hdll, (LPSTR)410);
292     pRemoveWindowSubclass = (void*)GetProcAddress(hdll, (LPSTR)412);
293     pDefSubclassProc = (void*)GetProcAddress(hdll, (LPSTR)413);
294     
295     if(!pSetWindowSubclass || !pRemoveWindowSubclass || !pDefSubclassProc)
296         return;
297 
298     if(!RegisterWindowClasses()) assert(0);
299 
300     test_subclass();
301 }
302 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.