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 (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &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 msg
.message
= message
;
95 msg
.flags
= sent
|wparam
|lparam
;
96 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
99 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
102 defwndproc_counter
++;
103 ret
= DefWindowProcW(hwnd
, message
, wParam
, lParam
);
104 defwndproc_counter
--;
109 static BOOL
register_parent_wnd_class(void)
114 cls
.lpfnWndProc
= parent_wnd_proc
;
117 cls
.hInstance
= GetModuleHandleW(NULL
);
119 cls
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
120 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
121 cls
.lpszMenuName
= NULL
;
122 cls
.lpszClassName
= L
"Syslink test parent class";
123 return RegisterClassW(&cls
);
126 static HWND
create_parent_window(void)
128 if (!register_parent_wnd_class())
131 return CreateWindowExW(0, L
"Syslink test parent class", L
"Syslink test parent window",
132 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
133 WS_MAXIMIZEBOX
| WS_VISIBLE
,
134 0, 0, 200, 100, GetDesktopWindow(),
135 NULL
, GetModuleHandleW(NULL
), NULL
);
138 static WNDPROC syslink_oldproc
;
140 static LRESULT WINAPI
syslink_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
142 static LONG defwndproc_counter
= 0;
143 struct message msg
= { 0 };
146 msg
.message
= message
;
147 msg
.flags
= sent
|wparam
|lparam
;
148 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
151 add_message(sequences
, SYSLINK_SEQ_INDEX
, &msg
);
153 defwndproc_counter
++;
154 ret
= CallWindowProcW(syslink_oldproc
, hwnd
, message
, wParam
, lParam
);
155 defwndproc_counter
--;
160 static HWND
create_syslink(DWORD style
, HWND parent
)
164 /* Only Unicode will do here */
165 hWndSysLink
= CreateWindowExW(0, WC_LINK
, L
"Head <a href=\"link1\">Name1</a> Middle <a href=\"link2\">Name2</a> Tail",
166 style
, 0, 0, 150, 50,
167 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
168 if (!hWndSysLink
) return NULL
;
170 if (GetWindowLongPtrW(hWndSysLink
, GWLP_USERDATA
))
171 /* On Windows XP SysLink takes GWLP_USERDATA for itself! */
172 trace("SysLink makes use of GWLP_USERDATA\n");
174 syslink_oldproc
= (WNDPROC
)SetWindowLongPtrW(hWndSysLink
, GWLP_WNDPROC
, (LONG_PTR
)syslink_subclass_proc
);
179 static void test_create_syslink(void)
184 /* Create an invisible SysLink control */
185 flush_sequences(sequences
, NUM_MSG_SEQUENCE
);
186 hWndSysLink
= create_syslink(WS_CHILD
| WS_TABSTOP
, hWndParent
);
187 ok(hWndSysLink
!= NULL
, "Expected non NULL value (le %lu)\n", GetLastError());
189 ok_sequence(sequences
, SYSLINK_SEQ_INDEX
, empty_wnd_seq
, "create SysLink", FALSE
);
190 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_create_syslink_wnd_seq
, "create SysLink (parent)", TRUE
);
192 /* Make the SysLink control visible */
193 flush_sequences(sequences
, NUM_MSG_SEQUENCE
);
194 oldstyle
= GetWindowLongA(hWndSysLink
, GWL_STYLE
);
195 SetWindowLongA(hWndSysLink
, GWL_STYLE
, oldstyle
| WS_VISIBLE
);
196 RedrawWindow(hWndSysLink
, NULL
, NULL
, RDW_INVALIDATE
);
198 ok_sequence(sequences
, SYSLINK_SEQ_INDEX
, visible_syslink_wnd_seq
, "visible SysLink", TRUE
);
199 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_visible_syslink_wnd_seq
, "visible SysLink (parent)", TRUE
);
201 DestroyWindow(hWndSysLink
);
204 static void test_LM_GETIDEALHEIGHT(void)
209 hwnd
= create_syslink(WS_CHILD
| WS_TABSTOP
| WS_VISIBLE
, hWndParent
);
210 ok(hwnd
!= NULL
, "Failed to create SysLink window.\n");
212 ret
= SendMessageA(hwnd
, LM_GETIDEALHEIGHT
, 0, 0);
213 ok(ret
> 0, "Unexpected ideal height, %ld.\n", ret
);
218 static void test_LM_GETIDEALSIZE(void)
224 hwnd
= create_syslink(WS_CHILD
| WS_TABSTOP
| WS_VISIBLE
, hWndParent
);
225 ok(hwnd
!= NULL
, "Failed to create SysLink window.\n");
227 memset(&sz
, 0, sizeof(sz
));
228 ret
= SendMessageA(hwnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&sz
);
229 ok(ret
> 0, "Unexpected return value, %ld.\n", ret
);
231 win_skip("LM_GETIDEALSIZE is not supported.\n");
234 ok(sz
.cx
> 5, "Unexpected ideal width, %ld.\n", sz
.cx
);
235 ok(sz
.cy
== ret
, "Unexpected ideal height, %ld.\n", sz
.cy
);
243 ULONG_PTR ctx_cookie
;
248 if (!load_v6_module(&ctx_cookie
, &hCtx
))
251 /* LoadLibrary is needed. This file has no reference to functions in comctl32 */
252 hComctl32
= LoadLibraryA("comctl32.dll");
253 ok(hComctl32
!= NULL
, "Failed to load comctl32.dll.\n");
255 /* Move the cursor off the parent window */
256 GetCursorPos(&orig_pos
);
257 SetCursorPos(400, 400);
259 init_msg_sequences(sequences
, NUM_MSG_SEQUENCE
);
261 /* Create parent window */
262 hWndParent
= create_parent_window();
263 ok(hWndParent
!= NULL
, "Failed to create parent Window!\n");
266 test_create_syslink();
267 test_LM_GETIDEALHEIGHT();
268 test_LM_GETIDEALSIZE();
270 DestroyWindow(hWndParent
);
271 unload_v6_module(ctx_cookie
, hCtx
);
272 SetCursorPos(orig_pos
.x
, orig_pos
.y
);