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
;
35 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCE
];
37 static const struct message empty_wnd_seq
[] = {
41 static const struct message parent_create_syslink_wnd_seq
[] = {
42 { WM_GETFONT
, sent
|optional
}, /* Only on XP */
43 { WM_QUERYUISTATE
, sent
|optional
},
44 { WM_CTLCOLORSTATIC
, sent
},
45 { WM_NOTIFY
, sent
|wparam
, 0},
46 { WM_PARENTNOTIFY
, sent
|wparam
, WM_CREATE
},
50 static const struct message visible_syslink_wnd_seq
[] = {
51 { WM_STYLECHANGING
, sent
|wparam
, GWL_STYLE
},
52 { WM_STYLECHANGED
, sent
|wparam
, GWL_STYLE
},
57 static const struct message parent_visible_syslink_wnd_seq
[] = {
58 { WM_CTLCOLORSTATIC
, sent
},
59 { WM_NOTIFY
, sent
|wparam
, 0},
63 /* Try to make sure pending X events have been processed before continuing */
64 static void flush_events(void)
68 int min_timeout
= 100;
69 DWORD time
= GetTickCount() + diff
;
73 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
74 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
75 diff
= time
- GetTickCount();
79 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
81 static LONG defwndproc_counter
= 0;
85 /* log system messages, except for painting */
86 if (message
< WM_USER
&&
87 message
!= WM_PAINT
&&
88 message
!= WM_ERASEBKGND
&&
89 message
!= WM_NCPAINT
&&
90 message
!= WM_NCHITTEST
&&
91 message
!= WM_GETTEXT
&&
92 message
!= WM_GETICON
&&
93 message
!= WM_DEVICECHANGE
)
95 msg
.message
= message
;
96 msg
.flags
= sent
|wparam
|lparam
;
97 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
100 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
107 NMLINK
*nml
= ((NMLINK
*)lParam
);
108 if (nml
&& NM_CLICK
== nml
->hdr
.code
)
110 g_link_id
= nml
->item
.iLink
;
117 defwndproc_counter
++;
118 ret
= DefWindowProcW(hwnd
, message
, wParam
, lParam
);
119 defwndproc_counter
--;
124 static BOOL
register_parent_wnd_class(void)
129 cls
.lpfnWndProc
= parent_wnd_proc
;
132 cls
.hInstance
= GetModuleHandleW(NULL
);
134 cls
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
135 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
136 cls
.lpszMenuName
= NULL
;
137 cls
.lpszClassName
= L
"Syslink test parent class";
138 return RegisterClassW(&cls
);
141 static HWND
create_parent_window(void)
143 if (!register_parent_wnd_class())
146 return CreateWindowExW(0, L
"Syslink test parent class", L
"Syslink test parent window",
147 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
148 WS_MAXIMIZEBOX
| WS_VISIBLE
,
149 0, 0, 200, 100, GetDesktopWindow(),
150 NULL
, GetModuleHandleW(NULL
), NULL
);
153 static WNDPROC syslink_oldproc
;
155 static LRESULT WINAPI
syslink_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
157 static LONG defwndproc_counter
= 0;
158 struct message msg
= { 0 };
161 msg
.message
= message
;
162 msg
.flags
= sent
|wparam
|lparam
;
163 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
166 add_message(sequences
, SYSLINK_SEQ_INDEX
, &msg
);
168 defwndproc_counter
++;
169 ret
= CallWindowProcW(syslink_oldproc
, hwnd
, message
, wParam
, lParam
);
170 defwndproc_counter
--;
175 static HWND
create_syslink(DWORD style
, HWND parent
)
179 /* Only Unicode will do here */
180 hWndSysLink
= CreateWindowExW(0, WC_LINK
, L
"Head <a href=\"link1\">Name1</a> Middle <a href=\"link2\">Name2</a> Tail",
181 style
, 0, 0, 150, 50,
182 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
183 if (!hWndSysLink
) return NULL
;
185 if (GetWindowLongPtrW(hWndSysLink
, GWLP_USERDATA
))
186 /* On Windows XP SysLink takes GWLP_USERDATA for itself! */
187 trace("SysLink makes use of GWLP_USERDATA\n");
189 syslink_oldproc
= (WNDPROC
)SetWindowLongPtrW(hWndSysLink
, GWLP_WNDPROC
, (LONG_PTR
)syslink_subclass_proc
);
194 static void test_create_syslink(void)
199 /* Create an invisible SysLink control */
200 flush_sequences(sequences
, NUM_MSG_SEQUENCE
);
201 hWndSysLink
= create_syslink(WS_CHILD
| WS_TABSTOP
, hWndParent
);
202 ok(hWndSysLink
!= NULL
, "Expected non NULL value (le %lu)\n", GetLastError());
204 ok_sequence(sequences
, SYSLINK_SEQ_INDEX
, empty_wnd_seq
, "create SysLink", FALSE
);
205 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_create_syslink_wnd_seq
, "create SysLink (parent)", TRUE
);
207 /* Make the SysLink control visible */
208 flush_sequences(sequences
, NUM_MSG_SEQUENCE
);
209 oldstyle
= GetWindowLongA(hWndSysLink
, GWL_STYLE
);
210 SetWindowLongA(hWndSysLink
, GWL_STYLE
, oldstyle
| WS_VISIBLE
);
211 RedrawWindow(hWndSysLink
, NULL
, NULL
, RDW_INVALIDATE
);
213 ok_sequence(sequences
, SYSLINK_SEQ_INDEX
, visible_syslink_wnd_seq
, "visible SysLink", TRUE
);
214 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_visible_syslink_wnd_seq
, "visible SysLink (parent)", TRUE
);
216 DestroyWindow(hWndSysLink
);
219 static void test_LM_GETIDEALHEIGHT(void)
224 hwnd
= create_syslink(WS_CHILD
| WS_TABSTOP
| WS_VISIBLE
, hWndParent
);
225 ok(hwnd
!= NULL
, "Failed to create SysLink window.\n");
227 ret
= SendMessageA(hwnd
, LM_GETIDEALHEIGHT
, 0, 0);
228 ok(ret
> 0, "Unexpected ideal height, %ld.\n", ret
);
233 static void test_LM_GETIDEALSIZE(void)
239 hwnd
= create_syslink(WS_CHILD
| WS_TABSTOP
| WS_VISIBLE
, hWndParent
);
240 ok(hwnd
!= NULL
, "Failed to create SysLink window.\n");
242 memset(&sz
, 0, sizeof(sz
));
243 ret
= SendMessageA(hwnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&sz
);
244 ok(ret
> 0, "Unexpected return value, %ld.\n", ret
);
246 win_skip("LM_GETIDEALSIZE is not supported.\n");
249 ok(sz
.cx
> 5, "Unexpected ideal width, %ld.\n", sz
.cx
);
250 ok(sz
.cy
== ret
, "Unexpected ideal height, %ld.\n", sz
.cy
);
256 static void test_link_id(void)
260 hwnd
= create_syslink(WS_CHILD
| WS_TABSTOP
| WS_VISIBLE
, hWndParent
);
261 ok(hwnd
!= NULL
, "Failed to create SysLink window.\n");
263 /* test link1 at (50, 10) */
265 SendMessageA(hwnd
, WM_LBUTTONDOWN
, 1, MAKELPARAM(50, 10));
266 SendMessageA(hwnd
, WM_LBUTTONUP
, 0, MAKELPARAM(50, 10));
267 ok(g_link_id
== 0, "Got unexpected link id %d.\n", g_link_id
);
269 /* test link2 at (25, 25) */
271 SendMessageA(hwnd
, WM_LBUTTONDOWN
, 1, MAKELPARAM(25, 25));
272 SendMessageA(hwnd
, WM_LBUTTONUP
, 0, MAKELPARAM(25, 25));
273 ok(g_link_id
== 1, "Got unexpected link id %d.\n", g_link_id
);
280 ULONG_PTR ctx_cookie
;
285 if (!load_v6_module(&ctx_cookie
, &hCtx
))
288 /* LoadLibrary is needed. This file has no reference to functions in comctl32 */
289 hComctl32
= LoadLibraryA("comctl32.dll");
290 ok(hComctl32
!= NULL
, "Failed to load comctl32.dll.\n");
292 /* Move the cursor off the parent window */
293 GetCursorPos(&orig_pos
);
294 SetCursorPos(400, 400);
296 init_msg_sequences(sequences
, NUM_MSG_SEQUENCE
);
298 /* Create parent window */
299 hWndParent
= create_parent_window();
300 ok(hWndParent
!= NULL
, "Failed to create parent Window!\n");
303 test_create_syslink();
304 test_LM_GETIDEALHEIGHT();
305 test_LM_GETIDEALSIZE();
308 DestroyWindow(hWndParent
);
309 unload_v6_module(ctx_cookie
, hCtx
);
310 SetCursorPos(orig_pos
.x
, orig_pos
.y
);