ReactOS 0.4.15-dev-8222-g9164419
subclass.c File Reference
#include <assert.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "commctrl.h"
#include "wine/heap.h"
#include "wine/test.h"
Include dependency graph for subclass.c:

Go to the source code of this file.

Classes

struct  message
 

Macros

#define SEND_NEST   0x01
 
#define DELETE_SELF   0x02
 
#define DELETE_PREV   0x04
 
#define MAKEFUNC_ORD(f, ord)   (p##f = (void*)GetProcAddress(hmod, (LPSTR)(ord)))
 
#define TESTNAMED(f)
 

Functions

static BOOL (WINAPI *pSetWindowSubclass)(HWND
 
static LRESULT (WINAPI *pDefSubclassProc)(HWND
 
static void add_message (const struct message *msg)
 
static void flush_sequence (void)
 
static void ok_sequence (const struct message *expected, const char *context)
 
static LRESULT WINAPI wnd_proc_1 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
static LRESULT WINAPI wnd_proc_3 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
static LRESULT WINAPI wnd_proc_sub (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uldSubclass, DWORD_PTR dwRefData)
 
static void test_subclass (void)
 
static BOOL register_window_classes (void)
 
static BOOL init_function_pointers (void)
 
 START_TEST (subclass)
 

Variables

static SUBCLASSPROC
 
static UINT_PTR
 
static DWORD_PTR
 
static UINT
 
static WPARAM
 
static LPARAM
 
static int sequence_cnt
 
static int sequence_size
 
static struct messagesequence
 
static const struct message Sub_BasicTest []
 
static const struct message Sub_DeletedTest []
 
static const struct message Sub_AfterDeletedTest []
 
static const struct message Sub_OldAfterNewTest []
 
static const struct message Sub_MixTest []
 
static const struct message Sub_MixAndNestTest []
 
static const struct message Sub_MixNestDelTest []
 
static const struct message Sub_MixDelPrevTest []
 
static WNDPROC orig_proc_3
 

Macro Definition Documentation

◆ DELETE_PREV

#define DELETE_PREV   0x04

Definition at line 38 of file subclass.c.

◆ DELETE_SELF

#define DELETE_SELF   0x02

Definition at line 37 of file subclass.c.

◆ MAKEFUNC_ORD

#define MAKEFUNC_ORD (   f,
  ord 
)    (p##f = (void*)GetProcAddress(hmod, (LPSTR)(ord)))

◆ SEND_NEST

#define SEND_NEST   0x01

Definition at line 36 of file subclass.c.

◆ TESTNAMED

#define TESTNAMED (   f)
Value:
ptr = (void*)GetProcAddress(hmod, #f); \
ok(ptr != 0, "expected named export for " #f "\n");
#define GetProcAddress(x, y)
Definition: compat.h:753
GLfloat f
Definition: glext.h:7540
static PVOID ptr
Definition: dispmode.c:27
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143

Function Documentation

◆ add_message()

static void add_message ( const struct message msg)
static

Definition at line 116 of file subclass.c.

117{
118 if (!sequence)
119 {
120 sequence_size = 10;
121 sequence = heap_alloc( sequence_size * sizeof (struct message) );
122 }
124 {
125 sequence_size *= 2;
126 sequence = heap_realloc( sequence, sequence_size * sizeof (struct message) );
127 }
129
130 sequence[sequence_cnt].wParam = msg->wParam;
131 sequence[sequence_cnt].procnum = msg->procnum;
132
133 sequence_cnt++;
134}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define msg(x)
Definition: auth_time.c:54
#define assert(x)
Definition: debug.h:53
Definition: tftpd.h:60
static struct message * sequence
Definition: subclass.c:46
static int sequence_size
Definition: subclass.c:45
static int sequence_cnt
Definition: subclass.c:45

◆ BOOL()

static BOOL ( WINAPI pSetWindowSubclass)
static

◆ flush_sequence()

static void flush_sequence ( void  )
static

Definition at line 136 of file subclass.c.

137{
139 sequence = NULL;
141}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define NULL
Definition: types.h:112

Referenced by ok_sequence().

◆ init_function_pointers()

static BOOL init_function_pointers ( void  )
static

Definition at line 301 of file subclass.c.

302{
304 void *ptr;
305
306 hmod = LoadLibraryA("comctl32.dll");
307 ok(hmod != NULL, "got %p\n", hmod);
308
309 /* Functions have to be loaded by ordinal. Only XP and W2K3 export
310 * them by name.
311 */
312#define MAKEFUNC_ORD(f, ord) (p##f = (void*)GetProcAddress(hmod, (LPSTR)(ord)))
316#undef MAKEFUNC_ORD
317
318 if(!pSetWindowSubclass || !pRemoveWindowSubclass || !pDefSubclassProc)
319 {
320 win_skip("SetWindowSubclass and friends are not available\n");
321 return FALSE;
322 }
323
324 /* test named exports */
325 ptr = GetProcAddress(hmod, "SetWindowSubclass");
326 ok(broken(ptr == 0) || ptr != 0, "expected named export for SetWindowSubclass\n");
327 if(ptr)
328 {
329#define TESTNAMED(f) \
330 ptr = (void*)GetProcAddress(hmod, #f); \
331 ok(ptr != 0, "expected named export for " #f "\n");
334 /* GetWindowSubclass exported for V6 only */
335#undef TESTNAMED
336 }
337
338 return TRUE;
339}
#define broken(x)
Definition: _sntprintf.h:21
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI SetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uIDSubclass, DWORD_PTR dwRef)
Definition: commctrl.c:1261
BOOL WINAPI RemoveWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uID)
Definition: commctrl.c:1390
LRESULT WINAPI DefSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: commctrl.c:1496
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define win_skip
Definition: test.h:163
#define TESTNAMED(f)
#define MAKEFUNC_ORD(f, ord)

Referenced by START_TEST().

◆ LRESULT()

static LRESULT ( WINAPI pDefSubclassProc)
static

◆ ok_sequence()

static void ok_sequence ( const struct message expected,
const char context 
)
static

Definition at line 143 of file subclass.c.

144{
145 static const struct message end_of_sequence = { 0, 0 };
146 const struct message *actual;
147
148 add_message(&end_of_sequence);
149
150 actual = sequence;
151
152 while(expected->procnum && actual->procnum)
153 {
154 ok(expected->procnum == actual->procnum,
155 "%s: the procnum %d was expected, but got procnum %d instead\n",
156 context, expected->procnum, actual->procnum);
157 ok(expected->wParam == actual->wParam,
158 "%s: in procnum %d expecting wParam 0x%lx got 0x%lx\n",
159 context, expected->procnum, expected->wParam, actual->wParam);
160 expected++;
161 actual++;
162 }
163 ok(!expected->procnum, "Received fewer messages than expected\n");
164 ok(!actual->procnum, "Received more messages than expected\n");
166}
#define add_message(msg)
Definition: SystemMenu.c:98
BOOL expected
Definition: store.c:2063
Definition: http.c:7252
int procnum
Definition: subclass.c:41
static void flush_sequence(void)
Definition: subclass.c:136

◆ register_window_classes()

static BOOL register_window_classes ( void  )
static

Definition at line 280 of file subclass.c.

281{
282 WNDCLASSA cls;
283 ATOM atom;
284
285 cls.style = 0;
287 cls.cbClsExtra = 0;
288 cls.cbWndExtra = 0;
290 cls.hIcon = 0;
291 cls.hCursor = NULL;
292 cls.hbrBackground = NULL;
293 cls.lpszMenuName = NULL;
294 cls.lpszClassName = "TestSubclass";
295 atom = RegisterClassA(&cls);
296 ok(atom, "failed to register test class\n");
297
298 return atom != 0;
299}
WORD ATOM
Definition: dimm.idl:113
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
static LRESULT WINAPI wnd_proc_1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: subclass.c:168
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( subclass  )

Definition at line 341 of file subclass.c.

342{
343 if(!init_function_pointers()) return;
344
345 if(!register_window_classes()) return;
346
348}
static void test_subclass(void)
Definition: subclass.c:217
static BOOL init_function_pointers(void)
Definition: subclass.c:301
static BOOL register_window_classes(void)
Definition: subclass.c:280

◆ test_subclass()

static void test_subclass ( void  )
static

Definition at line 217 of file subclass.c.

218{
219 BOOL ret;
220 HWND hwnd = CreateWindowExA(0, "TestSubclass", "Test subclass", WS_OVERLAPPEDWINDOW,
221 100, 100, 200, 200, 0, 0, 0, NULL);
222 ok(hwnd != NULL, "failed to create test subclass wnd\n");
223
224 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 2, 0);
225 ok(ret == TRUE, "Expected TRUE\n");
226 SendMessageA(hwnd, WM_USER, 1, 0);
227 SendMessageA(hwnd, WM_USER, 2, 0);
228 ok_sequence(Sub_BasicTest, "Basic");
229
230 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 2, DELETE_SELF);
231 ok(ret == TRUE, "Expected TRUE\n");
232 SendMessageA(hwnd, WM_USER, 1, 1);
233 ok_sequence(Sub_DeletedTest, "Deleted");
234
235 SendMessageA(hwnd, WM_USER, 1, 0);
236 ok_sequence(Sub_AfterDeletedTest, "After Deleted");
237
238 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 2, 0);
239 ok(ret == TRUE, "Expected TRUE\n");
241 SendMessageA(hwnd, WM_USER, 1, 0);
242 SendMessageA(hwnd, WM_USER, 2, 0);
243 ok_sequence(Sub_OldAfterNewTest, "Old after New");
244
245 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, 0);
246 ok(ret == TRUE, "Expected TRUE\n");
247 SendMessageA(hwnd, WM_USER, 1, 0);
248 ok_sequence(Sub_MixTest, "Mix");
249
250 /* Now the fun starts */
251 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, SEND_NEST);
252 ok(ret == TRUE, "Expected TRUE\n");
253 SendMessageA(hwnd, WM_USER, 1, 1);
254 ok_sequence(Sub_MixAndNestTest, "Mix and nest");
255
256 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, SEND_NEST | DELETE_SELF);
257 ok(ret == TRUE, "Expected TRUE\n");
258 SendMessageA(hwnd, WM_USER, 1, 1);
259 ok_sequence(Sub_MixNestDelTest, "Mix, nest, del");
260
261 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, 0);
262 ok(ret == TRUE, "Expected TRUE\n");
263 ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 5, DELETE_PREV);
264 ok(ret == TRUE, "Expected TRUE\n");
265 SendMessageA(hwnd, WM_USER, 1, 1);
266 ok_sequence(Sub_MixDelPrevTest, "Mix and del prev");
267
268 ret = pSetWindowSubclass(NULL, wnd_proc_sub, 1, 0);
269 ok(ret == FALSE, "Expected FALSE\n");
270
271 ret = pSetWindowSubclass(hwnd, NULL, 1, 0);
272 ok(ret == FALSE, "Expected FALSE\n");
273
274 pRemoveWindowSubclass(hwnd, wnd_proc_sub, 2);
275 pRemoveWindowSubclass(hwnd, wnd_proc_sub, 5);
276
278}
#define ok_sequence(exp, contx, todo)
Definition: SystemMenu.c:275
unsigned int BOOL
Definition: ntddk_ex.h:94
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define GWLP_WNDPROC
Definition: treelist.c:66
int ret
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
static const struct message Sub_MixDelPrevTest[]
Definition: subclass.c:108
static const struct message Sub_BasicTest[]
Definition: subclass.c:48
static const struct message Sub_MixTest[]
Definition: subclass.c:77
static const struct message Sub_MixNestDelTest[]
Definition: subclass.c:97
#define DELETE_PREV
Definition: subclass.c:38
static const struct message Sub_DeletedTest[]
Definition: subclass.c:56
#define DELETE_SELF
Definition: subclass.c:37
static WNDPROC orig_proc_3
Definition: subclass.c:181
static const struct message Sub_OldAfterNewTest[]
Definition: subclass.c:67
#define SEND_NEST
Definition: subclass.c:36
static const struct message Sub_AfterDeletedTest[]
Definition: subclass.c:62
static LRESULT WINAPI wnd_proc_3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: subclass.c:182
static LRESULT WINAPI wnd_proc_sub(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uldSubclass, DWORD_PTR dwRefData)
Definition: subclass.c:194
static const struct message Sub_MixAndNestTest[]
Definition: subclass.c:85
#define SetWindowLongPtrA
Definition: winuser.h:5354
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_USER
Definition: winuser.h:1895
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

◆ wnd_proc_1()

static LRESULT WINAPI wnd_proc_1 ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 168 of file subclass.c.

169{
170 struct message msg;
171
172 if(message == WM_USER) {
173 msg.wParam = wParam;
174 msg.procnum = 1;
176 }
178}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by register_window_classes().

◆ wnd_proc_3()

static LRESULT WINAPI wnd_proc_3 ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 182 of file subclass.c.

183{
184 struct message msg;
185
186 if(message == WM_USER) {
187 msg.wParam = wParam;
188 msg.procnum = 3;
190 }
192}
LRESULT WINAPI CallWindowProcA(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by test_subclass().

◆ wnd_proc_sub()

static LRESULT WINAPI wnd_proc_sub ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam,
UINT_PTR  uldSubclass,
DWORD_PTR  dwRefData 
)
static

Definition at line 194 of file subclass.c.

195{
196 struct message msg;
197
198 if(message == WM_USER) {
199 msg.wParam = wParam;
200 msg.procnum = uldSubclass;
202
203 if(lParam) {
204 if(dwRefData & DELETE_SELF) {
205 pRemoveWindowSubclass(hwnd, wnd_proc_sub, uldSubclass);
206 pRemoveWindowSubclass(hwnd, wnd_proc_sub, uldSubclass);
207 }
209 pRemoveWindowSubclass(hwnd, wnd_proc_sub, uldSubclass-1);
210 if(dwRefData & SEND_NEST)
212 }
213 }
214 return pDefSubclassProc(hwnd, message, wParam, lParam);
215}
_In_ SUBCLASSPROC _In_ UINT_PTR _In_ DWORD_PTR dwRefData
Definition: commctrl.h:5058

Referenced by test_subclass(), and wnd_proc_sub().

Variable Documentation

◆ DWORD_PTR

Definition at line 32 of file subclass.c.

◆ LPARAM

Definition at line 34 of file subclass.c.

◆ orig_proc_3

WNDPROC orig_proc_3
static

Definition at line 181 of file subclass.c.

Referenced by test_subclass(), and wnd_proc_3().

◆ sequence

struct message* sequence
static

Definition at line 46 of file subclass.c.

Referenced by add_message(), flush_sequence(), and ok_sequence().

◆ sequence_cnt

int sequence_cnt
static

Definition at line 45 of file subclass.c.

Referenced by add_message(), and flush_sequence().

◆ sequence_size

int sequence_size
static

Definition at line 45 of file subclass.c.

Referenced by add_message(), and flush_sequence().

◆ Sub_AfterDeletedTest

const struct message Sub_AfterDeletedTest[]
static
Initial value:
= {
{ 1, 1 },
{ 0 }
}

Definition at line 62 of file subclass.c.

Referenced by test_subclass().

◆ Sub_BasicTest

const struct message Sub_BasicTest[]
static
Initial value:
= {
{ 2, 1 },
{ 1, 1 },
{ 2, 2 },
{ 1, 2 },
{ 0 }
}

Definition at line 48 of file subclass.c.

Referenced by test_subclass().

◆ Sub_DeletedTest

const struct message Sub_DeletedTest[]
static
Initial value:
= {
{ 2, 1 },
{ 1, 1 },
{ 0 }
}

Definition at line 56 of file subclass.c.

Referenced by test_subclass().

◆ Sub_MixAndNestTest

const struct message Sub_MixAndNestTest[]
static
Initial value:
= {
{ 3, 1 },
{ 4, 1 },
{ 3, 2 },
{ 4, 2 },
{ 2, 2 },
{ 1, 2 },
{ 2, 1 },
{ 1, 1 },
{ 0 }
}

Definition at line 85 of file subclass.c.

Referenced by test_subclass().

◆ Sub_MixDelPrevTest

const struct message Sub_MixDelPrevTest[]
static
Initial value:
= {
{ 3, 1 },
{ 5, 1 },
{ 2, 1 },
{ 1, 1 },
{ 0 }
}

Definition at line 108 of file subclass.c.

Referenced by test_subclass().

◆ Sub_MixNestDelTest

const struct message Sub_MixNestDelTest[]
static
Initial value:
= {
{ 3, 1 },
{ 4, 1 },
{ 3, 2 },
{ 2, 2 },
{ 1, 2 },
{ 2, 1 },
{ 1, 1 },
{ 0 }
}

Definition at line 97 of file subclass.c.

Referenced by test_subclass().

◆ Sub_MixTest

const struct message Sub_MixTest[]
static
Initial value:
= {
{ 3, 1 },
{ 4, 1 },
{ 2, 1 },
{ 1, 1 },
{ 0 }
}

Definition at line 77 of file subclass.c.

Referenced by test_subclass().

◆ Sub_OldAfterNewTest

const struct message Sub_OldAfterNewTest[]
static
Initial value:
= {
{ 3, 1 },
{ 2, 1 },
{ 1, 1 },
{ 3, 2 },
{ 2, 2 },
{ 1, 2 },
{ 0 }
}

Definition at line 67 of file subclass.c.

Referenced by test_subclass().

◆ SUBCLASSPROC

SUBCLASSPROC

Definition at line 32 of file subclass.c.

◆ UINT

Definition at line 34 of file subclass.c.

◆ UINT_PTR

Definition at line 32 of file subclass.c.

◆ WPARAM

Definition at line 34 of file subclass.c.