1 /* Unit test suite for status control.
3 * Copyright 2007 Google (Lei Zhang)
4 * Copyright 2007 Alex Arazi
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 #define SUBCLASS_NAME "MyStatusBar"
29 #define expect(expected,got) ok (expected == got,"Expected %d, got %d\n",expected,got)
30 #define expect_rect(_left,_top,_right,_bottom,got) do { \
31 RECT exp = {abs(got.left - _left), abs(got.top - _top), \
32 abs(got.right - _right), abs(got.bottom - _bottom)}; \
33 ok(exp.left <= 2 && exp.top <= 2 && exp.right <= 2 && exp.bottom <= 2, \
34 "Expected rect {%d,%d, %d,%d}, got {%d,%d, %d,%d}\n", \
35 _left, _top, _right, _bottom, \
36 (got).left, (got).top, (got).right, (got).bottom); } while (0)
38 static HINSTANCE hinst
;
39 static WNDPROC g_status_wndproc
;
40 static RECT g_rcCreated
;
41 static HWND g_hMainWnd
;
42 static int g_wmsize_count
= 0;
44 static HWND
create_status_control(DWORD style
, DWORD exstyle
)
48 /* make the control */
49 hWndStatus
= CreateWindowEx(exstyle
, STATUSCLASSNAME
, NULL
, style
,
53 NULL
, NULL
, hinst
, NULL
);
58 static LRESULT WINAPI
create_test_wndproc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
64 CREATESTRUCT
*cs
= (CREATESTRUCT
*)lParam
;
65 ret
= CallWindowProc(g_status_wndproc
, hwnd
, msg
, wParam
, lParam
);
66 GetWindowRect(hwnd
, &g_rcCreated
);
67 MapWindowPoints(HWND_DESKTOP
, g_hMainWnd
, (LPPOINT
)&g_rcCreated
, 2);
68 ok(cs
->x
== g_rcCreated
.left
, "CREATESTRUCT.x modified\n");
69 ok(cs
->y
== g_rcCreated
.top
, "CREATESTRUCT.y modified\n");
70 } else if (msg
== WM_SIZE
)
73 ret
= CallWindowProc(g_status_wndproc
, hwnd
, msg
, wParam
, lParam
);
76 ret
= CallWindowProc(g_status_wndproc
, hwnd
, msg
, wParam
, lParam
);
81 static void register_subclass()
85 cls
.cbSize
= sizeof(WNDCLASSEX
);
86 GetClassInfoEx(NULL
, STATUSCLASSNAME
, &cls
);
87 g_status_wndproc
= cls
.lpfnWndProc
;
88 cls
.lpfnWndProc
= create_test_wndproc
;
89 cls
.lpszClassName
= SUBCLASS_NAME
;
91 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
94 static void test_create()
99 ok((hwnd
= CreateWindowA(SUBCLASS_NAME
, "", WS_CHILD
|WS_VISIBLE
|SBARS_SIZEGRIP
, 0, 0, 100, 100,
100 g_hMainWnd
, NULL
, NULL
, 0)) != NULL
, "CreateWindowA failed\n");
101 MapWindowPoints(HWND_DESKTOP
, g_hMainWnd
, (LPPOINT
)&rc
, 2);
102 GetWindowRect(hwnd
, &rc
);
103 MapWindowPoints(HWND_DESKTOP
, g_hMainWnd
, (LPPOINT
)&rc
, 2);
104 expect_rect(0, 0, 100, 100, g_rcCreated
);
106 expect(672, rc
.right
);
107 expect(226, rc
.bottom
);
108 /* we don't check rc.top as this may depend on user font settings */
112 static int CALLBACK
check_height_font_enumproc(ENUMLOGFONTEX
*enumlf
, NEWTEXTMETRICEX
*ntm
, DWORD type
, LPARAM lParam
)
114 HWND hwndStatus
= (HWND
)lParam
;
115 HDC hdc
= GetDC(NULL
);
116 static const int sizes
[] = {8, 9, 10, 12, 16, 22, 28, 36, 48, 72};
119 trace("Font %s\n", enumlf
->elfFullName
);
120 for (i
= 0; i
< sizeof(sizes
)/sizeof(sizes
[0]); i
++)
128 enumlf
->elfLogFont
.lfHeight
= sizes
[i
];
129 hFont
= CreateFontIndirect(&enumlf
->elfLogFont
);
130 hCtrlFont
= (HFONT
)SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
131 hOldFont
= SelectObject(hdc
, hFont
);
133 GetClientRect(hwndStatus
, &rcCtrl
);
134 GetTextMetrics(hdc
, &tm
);
135 expect(max(tm
.tmHeight
+ (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2) + 4, 20), rcCtrl
.bottom
);
137 SelectObject(hdc
, hOldFont
);
138 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hCtrlFont
, TRUE
);
141 ReleaseDC(NULL
, hdc
);
145 static int CALLBACK
check_height_family_enumproc(ENUMLOGFONTEX
*enumlf
, NEWTEXTMETRICEX
*ntm
, DWORD type
, LPARAM lParam
)
147 HDC hdc
= GetDC(NULL
);
148 enumlf
->elfLogFont
.lfHeight
= 0;
149 EnumFontFamiliesEx(hdc
, &enumlf
->elfLogFont
, (FONTENUMPROC
)check_height_font_enumproc
, lParam
, 0);
150 ReleaseDC(NULL
, hdc
);
154 static void test_height(void)
157 HFONT hFont
, hFontSm
;
159 HWND hwndStatus
= CreateWindow(SUBCLASS_NAME
, NULL
, WS_CHILD
|WS_VISIBLE
,
160 0, 0, 300, 20, g_hMainWnd
, NULL
, NULL
, NULL
);
163 GetClientRect(hwndStatus
, &rc1
);
164 hFont
= CreateFont(32, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
165 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, "Tahoma");
168 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
171 skip("Status control not resized in win95, skipping broken tests.\n");
174 ok(g_wmsize_count
> 0, "WM_SETFONT should issue WM_SIZE\n");
176 GetClientRect(hwndStatus
, &rc2
);
177 expect_rect(0, 0, 672, 42, rc2
); /* GetTextMetrics returns invalid tmInternalLeading for this font */
180 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
181 ok(g_wmsize_count
> 0, "WM_SETFONT should issue WM_SIZE\n");
183 GetClientRect(hwndStatus
, &rc2
);
184 expect_rect(0, 0, 672, 42, rc2
);
186 /* minheight < fontsize - no effects*/
187 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 12, 0);
188 SendMessage(hwndStatus
, WM_SIZE
, 0, 0);
189 GetClientRect(hwndStatus
, &rc2
);
190 expect_rect(0, 0, 672, 42, rc2
);
192 /* minheight > fontsize - has an effect after WM_SIZE */
193 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 60, 0);
194 GetClientRect(hwndStatus
, &rc2
);
195 expect_rect(0, 0, 672, 42, rc2
);
196 SendMessage(hwndStatus
, WM_SIZE
, 0, 0);
197 GetClientRect(hwndStatus
, &rc2
);
198 expect_rect(0, 0, 672, 62, rc2
);
200 /* font changed to smaller than minheight - has an effect */
201 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 30, 0);
202 expect_rect(0, 0, 672, 62, rc2
);
203 SendMessage(hwndStatus
, WM_SIZE
, 0, 0);
204 GetClientRect(hwndStatus
, &rc2
);
205 expect_rect(0, 0, 672, 42, rc2
);
206 hFontSm
= CreateFont(9, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
207 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, "Tahoma");
208 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFontSm
, TRUE
);
209 GetClientRect(hwndStatus
, &rc2
);
210 expect_rect(0, 0, 672, 32, rc2
);
212 /* test the height formula */
213 ZeroMemory(&lf
, sizeof(lf
));
214 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 0, 0);
216 trace("dpi=%d\n", GetDeviceCaps(hdc
, LOGPIXELSY
));
217 EnumFontFamiliesEx(hdc
, &lf
, (FONTENUMPROC
)check_height_family_enumproc
, (LPARAM
)hwndStatus
, 0);
218 ReleaseDC(NULL
, hdc
);
220 DestroyWindow(hwndStatus
);
222 DeleteObject(hFontSm
);
225 static void test_status_control(void)
229 int nParts
[] = {50, 150, -1};
230 int checkParts
[] = {0, 0, 0};
231 int borders
[] = {0, 0, 0};
236 hWndStatus
= create_status_control(WS_VISIBLE
, 0);
238 /* Divide into parts and set text */
239 r
= SendMessage(hWndStatus
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
241 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 0, (LPARAM
)"First");
243 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 1, (LPARAM
)"Second");
245 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 2, (LPARAM
)"Third");
248 /* Get RECT Information */
249 r
= SendMessage(hWndStatus
, SB_GETRECT
, 0, (LPARAM
)&rc
);
252 /* The rc.bottom test is system dependent
253 expect(22,rc.bottom); */
256 r
= SendMessage(hWndStatus
, SB_GETRECT
, -1, (LPARAM
)&rc
);
258 r
= SendMessage(hWndStatus
, SB_GETRECT
, 3, (LPARAM
)&rc
);
260 /* Get text length and text */
261 r
= SendMessage(hWndStatus
, SB_GETTEXTLENGTH
, 2, 0);
264 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 2, (LPARAM
) charArray
);
265 ok(strcmp(charArray
,"Third") == 0, "Expected Third, got %s\n", charArray
);
269 /* Get parts and borders */
270 r
= SendMessage(hWndStatus
, SB_GETPARTS
, 3, (LPARAM
)checkParts
);
271 ok(r
== 3, "Expected 3, got %d\n", r
);
272 expect(50,checkParts
[0]);
273 expect(150,checkParts
[1]);
274 expect(-1,checkParts
[2]);
275 r
= SendMessage(hWndStatus
, SB_GETBORDERS
, 0, (LPARAM
)borders
);
276 ok(r
== TRUE
, "Expected TRUE, got %d\n", r
);
277 expect(0,borders
[0]);
278 expect(2,borders
[1]);
279 expect(2,borders
[2]);
281 /* Test resetting text with different characters */
282 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 0, (LPARAM
)"First@Again");
284 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 1, (LPARAM
)"InvalidChars\\7\7");
286 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 2, (LPARAM
)"InvalidChars\\n\n");
290 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 0, (LPARAM
) charArray
);
291 ok(strcmp(charArray
,"First@Again") == 0, "Expected First@Again, got %s\n", charArray
);
292 expect(11,LOWORD(r
));
294 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 1, (LPARAM
) charArray
);
297 ok(strcmp(charArray
,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray
);
299 expect(15,LOWORD(r
));
301 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 2, (LPARAM
) charArray
);
304 ok(strcmp(charArray
,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray
);
306 expect(15,LOWORD(r
));
309 /* Set background color */
310 r
= SendMessage(hWndStatus
, SB_SETBKCOLOR
, 0, RGB(255,0,0));
311 ok(r
== CLR_DEFAULT
||
312 broken(r
== 0), /* win95 */
313 "Expected %d, got %d\n", CLR_DEFAULT
, r
);
314 r
= SendMessage(hWndStatus
, SB_SETBKCOLOR
, 0, CLR_DEFAULT
);
315 ok(r
== RGB(255,0,0) ||
316 broken(r
== 0), /* win95 */
317 "Expected %d, got %d\n", RGB(255,0,0), r
);
319 /* Add an icon to the status bar */
320 hIcon
= LoadIcon(NULL
, IDI_QUESTION
);
321 r
= SendMessage(hWndStatus
, SB_SETICON
, 1, (LPARAM
) NULL
);
323 broken(r
== 0), /* win95 */
324 "Expected non-zero, got %d\n", r
);
325 r
= SendMessage(hWndStatus
, SB_SETICON
, 1, (LPARAM
) hIcon
);
327 broken(r
== 0), /* win95 */
328 "Expected non-zero, got %d\n", r
);
329 r
= SendMessage(hWndStatus
, SB_SETICON
, 1, (LPARAM
) NULL
);
331 broken(r
== 0), /* win95 */
332 "Expected non-zero, got %d\n", r
);
334 /* Set the Unicode format */
335 r
= SendMessage(hWndStatus
, SB_SETUNICODEFORMAT
, FALSE
, 0);
336 r
= SendMessage(hWndStatus
, SB_GETUNICODEFORMAT
, 0, 0);
338 r
= SendMessage(hWndStatus
, SB_SETUNICODEFORMAT
, TRUE
, 0);
340 r
= SendMessage(hWndStatus
, SB_GETUNICODEFORMAT
, 0, 0);
342 broken(r
== FALSE
), /* win95 */
343 "Expected TRUE, got %d\n", r
);
345 /* Reset number of parts */
346 r
= SendMessage(hWndStatus
, SB_SETPARTS
, 2, (LPARAM
)nParts
);
349 /* Set the minimum height and get rectangle information again */
350 SendMessage(hWndStatus
, SB_SETMINHEIGHT
, 50, (LPARAM
) 0);
351 r
= SendMessage(hWndStatus
, WM_SIZE
, 0, (LPARAM
) 0);
353 r
= SendMessage(hWndStatus
, SB_GETRECT
, 0, (LPARAM
)&rc
);
356 /* The rc.bottom test is system dependent
357 expect(22,rc.bottom); */
360 r
= SendMessage(hWndStatus
, SB_GETRECT
, -1, (LPARAM
)&rc
);
362 r
= SendMessage(hWndStatus
, SB_GETRECT
, 3, (LPARAM
)&rc
);
365 /* Set the ToolTip text */
368 SendMessage(hWndStatus
, SB_SETTIPTEXT
, 0,(LPARAM
) "Tooltip Text");
369 lstrcpyA(charArray
, "apple");
370 SendMessage(hWndStatus
, SB_GETTIPTEXT
, MAKEWPARAM (0, 20),(LPARAM
) charArray
);
371 ok(strcmp(charArray
,"Tooltip Text") == 0 ||
372 broken(!strcmp(charArray
, "apple")), /* win95 */
373 "Expected Tooltip Text, got %s\n", charArray
);
377 SendMessage(hWndStatus
, SB_SIMPLE
, TRUE
, 0);
378 r
= SendMessage(hWndStatus
, SB_ISSIMPLE
, 0, 0);
380 broken(r
== FALSE
), /* win95 */
381 "Expected TRUE, got %d\n", r
);
383 DestroyWindow(hWndStatus
);
388 hinst
= GetModuleHandleA(NULL
);
390 g_hMainWnd
= CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW
,
391 CW_USEDEFAULT
, CW_USEDEFAULT
, 672+2*GetSystemMetrics(SM_CXSIZEFRAME
),
392 226+GetSystemMetrics(SM_CYCAPTION
)+2*GetSystemMetrics(SM_CYSIZEFRAME
),
393 NULL
, NULL
, GetModuleHandleA(NULL
), 0);
395 InitCommonControls();
399 test_status_control();