1 /* Unit tests for the syslink control.
3 * Copyright 2011 Francois Gouget for CodeWeavers
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.
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.
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
23 #include "wine/test.h"
27 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
28 #define NUM_MSG_SEQUENCE 2
29 #define PARENT_SEQ_INDEX 0
30 #define SYSLINK_SEQ_INDEX 1
32 static HWND hWndParent
;
34 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCE
];
36 static const struct message empty_wnd_seq
[] = {
40 static const struct message parent_create_syslink_wnd_seq
[] = {
41 { WM_GETFONT
, sent
|optional
}, /* Only on XP */
42 { WM_QUERYUISTATE
, sent
|optional
},
43 { WM_CTLCOLORSTATIC
, sent
},
44 { WM_NOTIFY
, sent
|wparam
, 0},
45 { WM_PARENTNOTIFY
, sent
|wparam
, WM_CREATE
},
49 static const struct message visible_syslink_wnd_seq
[] = {
50 { WM_STYLECHANGING
, sent
|wparam
, GWL_STYLE
},
51 { WM_STYLECHANGED
, sent
|wparam
, GWL_STYLE
},
56 static const struct message parent_visible_syslink_wnd_seq
[] = {
57 { WM_CTLCOLORSTATIC
, sent
},
58 { WM_NOTIFY
, sent
|wparam
, 0},
62 /* Try to make sure pending X events have been processed before continuing */
63 static void flush_events(void)
67 int min_timeout
= 100;
68 DWORD time
= GetTickCount() + diff
;
72 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
73 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
74 diff
= time
- GetTickCount();
78 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
80 static LONG defwndproc_counter
= 0;
84 /* log system messages, except for painting */
85 if (message
< WM_USER
&&
86 message
!= WM_PAINT
&&
87 message
!= WM_ERASEBKGND
&&
88 message
!= WM_NCPAINT
&&
89 message
!= WM_NCHITTEST
&&
90 message
!= WM_GETTEXT
&&
91 message
!= WM_GETICON
&&
92 message
!= WM_DEVICECHANGE
)
94 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
96 msg
.message
= message
;
97 msg
.flags
= sent
|wparam
|lparam
;
98 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
101 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
104 defwndproc_counter
++;
105 ret
= DefWindowProcW(hwnd
, message
, wParam
, lParam
);
106 defwndproc_counter
--;
111 static const WCHAR parentClassW
[] = {'S','y','s','l','i','n','k',' ','t','e','s','t',' ','p','a','r','e','n','t',' ','c','l','a','s','s',0};
113 static BOOL
register_parent_wnd_class(void)
118 cls
.lpfnWndProc
= parent_wnd_proc
;
121 cls
.hInstance
= GetModuleHandleW(NULL
);
123 cls
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
124 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
125 cls
.lpszMenuName
= NULL
;
126 cls
.lpszClassName
= parentClassW
;
127 return RegisterClassW(&cls
);
130 static HWND
create_parent_window(void)
132 static const WCHAR titleW
[] = {'S','y','s','l','i','n','k',' ','t','e','s','t',' ','p','a','r','e','n','t',' ','w','i','n','d','o','w',0};
133 if (!register_parent_wnd_class())
136 return CreateWindowExW(0, parentClassW
, titleW
,
137 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
138 WS_MAXIMIZEBOX
| WS_VISIBLE
,
139 0, 0, 200, 100, GetDesktopWindow(),
140 NULL
, GetModuleHandleW(NULL
), NULL
);
143 static WNDPROC syslink_oldproc
;
145 static LRESULT WINAPI
syslink_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
147 static LONG defwndproc_counter
= 0;
151 trace("syslink: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
153 msg
.message
= message
;
154 msg
.flags
= sent
|wparam
|lparam
;
155 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
159 add_message(sequences
, SYSLINK_SEQ_INDEX
, &msg
);
161 defwndproc_counter
++;
162 ret
= CallWindowProcW(syslink_oldproc
, hwnd
, message
, wParam
, lParam
);
163 defwndproc_counter
--;
168 static HWND
create_syslink(DWORD style
, HWND parent
)
171 static const WCHAR linkW
[] = {'H','e','a','d',' ','<','a',' ','h','r','e','f','=','"','l','i','n','k','1','"','>','N','a','m','e','1','<','/','a','>',' ','M','i','d','d','l','e',' ','<','a',' ','h','r','e','f','=','"','l','i','n','k','2','"','>','N','a','m','e','2','<','/','a','>',' ','T','a','i','l',0};
173 /* Only Unicode will do here */
174 hWndSysLink
= CreateWindowExW(0, WC_LINK
, linkW
,
175 style
, 0, 0, 150, 50,
176 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
177 if (!hWndSysLink
) return NULL
;
179 if (GetWindowLongPtrW(hWndSysLink
, GWLP_USERDATA
))
180 /* On Windows XP SysLink takes GWLP_USERDATA for itself! */
181 trace("SysLink makes use of GWLP_USERDATA\n");
183 syslink_oldproc
= (WNDPROC
)SetWindowLongPtrW(hWndSysLink
, GWLP_WNDPROC
, (LONG_PTR
)syslink_subclass_proc
);
191 ULONG_PTR ctx_cookie
;
194 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
195 INITCOMMONCONTROLSEX iccex
;
200 if (!load_v6_module(&ctx_cookie
, &hCtx
))
203 /* LoadLibrary is needed. This file has no reference to functions in comctl32 */
204 hComctl32
= LoadLibraryA("comctl32.dll");
205 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
206 if (!pInitCommonControlsEx
)
208 win_skip("InitCommonControlsEx() is missing. Skipping the tests\n");
211 iccex
.dwSize
= sizeof(iccex
);
212 iccex
.dwICC
= ICC_LINK_CLASS
;
213 rc
= pInitCommonControlsEx(&iccex
);
214 ok(rc
, "InitCommonControlsEx failed (le %u)\n", GetLastError());
217 skip("Could not register ICC_LINK_CLASS\n");
221 init_msg_sequences(sequences
, NUM_MSG_SEQUENCE
);
223 /* Create parent window */
224 hWndParent
= create_parent_window();
225 ok(hWndParent
!= NULL
, "Failed to create parent Window!\n");
228 skip("Parent window not present\n");
233 /* Create an invisible SysLink control */
234 flush_sequences(sequences
, NUM_MSG_SEQUENCE
);
235 hWndSysLink
= create_syslink(WS_CHILD
| WS_TABSTOP
, hWndParent
);
236 ok(hWndSysLink
!= NULL
, "Expected non NULL value (le %u)\n", GetLastError());
239 skip("SysLink control not present?\n");
243 ok_sequence(sequences
, SYSLINK_SEQ_INDEX
, empty_wnd_seq
, "create SysLink", FALSE
);
244 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_create_syslink_wnd_seq
, "create SysLink (parent)", TRUE
);
246 /* Make the SysLink control visible */
247 flush_sequences(sequences
, NUM_MSG_SEQUENCE
);
248 oldstyle
= GetWindowLong(hWndSysLink
, GWL_STYLE
);
249 SetWindowLong(hWndSysLink
, GWL_STYLE
, oldstyle
| WS_VISIBLE
);
250 RedrawWindow(hWndSysLink
, NULL
, NULL
, RDW_INVALIDATE
);
252 ok_sequence(sequences
, SYSLINK_SEQ_INDEX
, visible_syslink_wnd_seq
, "visible SysLink", TRUE
);
253 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_visible_syslink_wnd_seq
, "visible SysLink (parent)", TRUE
);
255 DestroyWindow(hWndSysLink
);
256 DestroyWindow(hWndParent
);
257 unload_v6_module(ctx_cookie
, hCtx
);