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 DWORD g_dpisize
;
46 static HWND
create_status_control(DWORD style
, DWORD exstyle
)
50 /* make the control */
51 hWndStatus
= CreateWindowEx(exstyle
, STATUSCLASSNAME
, NULL
, style
,
55 NULL
, NULL
, hinst
, NULL
);
60 static LRESULT WINAPI
create_test_wndproc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
66 CREATESTRUCT
*cs
= (CREATESTRUCT
*)lParam
;
67 ret
= CallWindowProc(g_status_wndproc
, hwnd
, msg
, wParam
, lParam
);
68 GetWindowRect(hwnd
, &g_rcCreated
);
69 MapWindowPoints(HWND_DESKTOP
, g_hMainWnd
, (LPPOINT
)&g_rcCreated
, 2);
70 ok(cs
->x
== g_rcCreated
.left
, "CREATESTRUCT.x modified\n");
71 ok(cs
->y
== g_rcCreated
.top
, "CREATESTRUCT.y modified\n");
72 } else if (msg
== WM_SIZE
)
75 ret
= CallWindowProc(g_status_wndproc
, hwnd
, msg
, wParam
, lParam
);
78 ret
= CallWindowProc(g_status_wndproc
, hwnd
, msg
, wParam
, lParam
);
83 static void register_subclass(void)
87 cls
.cbSize
= sizeof(WNDCLASSEX
);
88 GetClassInfoEx(NULL
, STATUSCLASSNAME
, &cls
);
89 g_status_wndproc
= cls
.lpfnWndProc
;
90 cls
.lpfnWndProc
= create_test_wndproc
;
91 cls
.lpszClassName
= SUBCLASS_NAME
;
93 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
96 static void test_create(void)
101 ok((hwnd
= CreateWindowA(SUBCLASS_NAME
, "", WS_CHILD
|WS_VISIBLE
|SBARS_SIZEGRIP
, 0, 0, 100, 100,
102 g_hMainWnd
, NULL
, NULL
, 0)) != NULL
, "CreateWindowA failed\n");
103 MapWindowPoints(HWND_DESKTOP
, g_hMainWnd
, (LPPOINT
)&rc
, 2);
104 GetWindowRect(hwnd
, &rc
);
105 MapWindowPoints(HWND_DESKTOP
, g_hMainWnd
, (LPPOINT
)&rc
, 2);
106 expect_rect(0, 0, 100, 100, g_rcCreated
);
108 expect(672, rc
.right
);
109 expect(226, rc
.bottom
);
110 /* we don't check rc.top as this may depend on user font settings */
114 static int CALLBACK
check_height_font_enumproc(ENUMLOGFONTEX
*enumlf
, NEWTEXTMETRICEX
*ntm
, DWORD type
, LPARAM lParam
)
116 HWND hwndStatus
= (HWND
)lParam
;
117 HDC hdc
= GetDC(NULL
);
118 static const int sizes
[] = { 6, 7, 8, 9, 10, 11, 12, 13, 15, 16,
119 20, 22, 28, 36, 48, 72};
122 LPSTR facename
= (CHAR
*)enumlf
->elfFullName
;
124 /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
125 if (type
!= TRUETYPE_FONTTYPE
)
126 facename
= enumlf
->elfLogFont
.lfFaceName
;
128 for (i
= 0; i
< sizeof(sizes
)/sizeof(sizes
[0]); i
++)
136 enumlf
->elfLogFont
.lfHeight
= sizes
[i
];
137 hFont
= CreateFontIndirect(&enumlf
->elfLogFont
);
138 hCtrlFont
= (HFONT
)SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
139 hOldFont
= SelectObject(hdc
, hFont
);
141 GetClientRect(hwndStatus
, &rcCtrl
);
142 GetTextMetrics(hdc
, &tm
);
143 y
= tm
.tmHeight
+ (tm
.tmInternalLeading
? tm
.tmInternalLeading
: 2) + 4;
145 ok( (rcCtrl
.bottom
== max(y
, g_ysize
)) || (rcCtrl
.bottom
== max(y
, g_dpisize
)),
146 "got %d (expected %d or %d) for %s #%d\n",
147 rcCtrl
.bottom
, max(y
, g_ysize
), max(y
, g_dpisize
), facename
, sizes
[i
]);
149 SelectObject(hdc
, hOldFont
);
150 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hCtrlFont
, TRUE
);
153 ReleaseDC(NULL
, hdc
);
157 static int CALLBACK
check_height_family_enumproc(ENUMLOGFONTEX
*enumlf
, NEWTEXTMETRICEX
*ntm
, DWORD type
, LPARAM lParam
)
159 HDC hdc
= GetDC(NULL
);
160 enumlf
->elfLogFont
.lfHeight
= 0;
161 EnumFontFamiliesEx(hdc
, &enumlf
->elfLogFont
, (FONTENUMPROC
)check_height_font_enumproc
, lParam
, 0);
162 ReleaseDC(NULL
, hdc
);
166 static void test_height(void)
169 HFONT hFont
, hFontSm
;
171 HWND hwndStatus
= CreateWindow(SUBCLASS_NAME
, NULL
, WS_CHILD
|WS_VISIBLE
,
172 0, 0, 300, 20, g_hMainWnd
, NULL
, NULL
, NULL
);
175 GetClientRect(hwndStatus
, &rc1
);
176 hFont
= CreateFont(32, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
177 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, "Tahoma");
180 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
183 skip("Status control not resized in win95, skipping broken tests.\n");
186 ok(g_wmsize_count
> 0, "WM_SETFONT should issue WM_SIZE\n");
188 GetClientRect(hwndStatus
, &rc2
);
189 expect_rect(0, 0, 672, 42, rc2
); /* GetTextMetrics returns invalid tmInternalLeading for this font */
192 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
193 ok(g_wmsize_count
> 0, "WM_SETFONT should issue WM_SIZE\n");
195 GetClientRect(hwndStatus
, &rc2
);
196 expect_rect(0, 0, 672, 42, rc2
);
198 /* minheight < fontsize - no effects*/
199 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 12, 0);
200 SendMessage(hwndStatus
, WM_SIZE
, 0, 0);
201 GetClientRect(hwndStatus
, &rc2
);
202 expect_rect(0, 0, 672, 42, rc2
);
204 /* minheight > fontsize - has an effect after WM_SIZE */
205 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 60, 0);
206 GetClientRect(hwndStatus
, &rc2
);
207 expect_rect(0, 0, 672, 42, rc2
);
208 SendMessage(hwndStatus
, WM_SIZE
, 0, 0);
209 GetClientRect(hwndStatus
, &rc2
);
210 expect_rect(0, 0, 672, 62, rc2
);
212 /* font changed to smaller than minheight - has an effect */
213 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 30, 0);
214 expect_rect(0, 0, 672, 62, rc2
);
215 SendMessage(hwndStatus
, WM_SIZE
, 0, 0);
216 GetClientRect(hwndStatus
, &rc2
);
217 expect_rect(0, 0, 672, 42, rc2
);
218 hFontSm
= CreateFont(9, 0, 0, 0, FW_DONTCARE
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
219 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, "Tahoma");
220 SendMessage(hwndStatus
, WM_SETFONT
, (WPARAM
)hFontSm
, TRUE
);
221 GetClientRect(hwndStatus
, &rc2
);
222 expect_rect(0, 0, 672, 32, rc2
);
224 /* test the height formula */
225 ZeroMemory(&lf
, sizeof(lf
));
226 SendMessage(hwndStatus
, SB_SETMINHEIGHT
, 0, 0);
229 /* used only for some fonts (tahoma as example) */
230 g_ysize
= GetSystemMetrics(SM_CYSIZE
) + 2;
231 if (g_ysize
& 1) g_ysize
--; /* The min height is always even */
233 g_dpisize
= MulDiv(18, GetDeviceCaps(hdc
, LOGPIXELSY
), 96) + 2;
234 if (g_dpisize
& 1) g_dpisize
--; /* The min height is always even */
237 trace("dpi=%d (min height: %d or %d) SM_CYSIZE: %d\n",
238 GetDeviceCaps(hdc
, LOGPIXELSY
), g_ysize
, g_dpisize
,
239 GetSystemMetrics(SM_CYSIZE
));
241 EnumFontFamiliesEx(hdc
, &lf
, (FONTENUMPROC
)check_height_family_enumproc
, (LPARAM
)hwndStatus
, 0);
242 ReleaseDC(NULL
, hdc
);
244 DestroyWindow(hwndStatus
);
246 DeleteObject(hFontSm
);
249 static void test_status_control(void)
253 int nParts
[] = {50, 150, -1};
254 int checkParts
[] = {0, 0, 0};
255 int borders
[] = {0, 0, 0};
260 hWndStatus
= create_status_control(WS_VISIBLE
, 0);
262 /* Divide into parts and set text */
263 r
= SendMessage(hWndStatus
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
265 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 0, (LPARAM
)"First");
267 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 1, (LPARAM
)"Second");
269 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 2, (LPARAM
)"Third");
272 /* Get RECT Information */
273 r
= SendMessage(hWndStatus
, SB_GETRECT
, 0, (LPARAM
)&rc
);
276 /* The rc.bottom test is system dependent
277 expect(22,rc.bottom); */
280 r
= SendMessage(hWndStatus
, SB_GETRECT
, -1, (LPARAM
)&rc
);
282 r
= SendMessage(hWndStatus
, SB_GETRECT
, 3, (LPARAM
)&rc
);
284 /* Get text length and text */
285 r
= SendMessage(hWndStatus
, SB_GETTEXTLENGTH
, 2, 0);
288 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 2, (LPARAM
) charArray
);
289 ok(strcmp(charArray
,"Third") == 0, "Expected Third, got %s\n", charArray
);
293 /* Get parts and borders */
294 r
= SendMessage(hWndStatus
, SB_GETPARTS
, 3, (LPARAM
)checkParts
);
295 ok(r
== 3, "Expected 3, got %d\n", r
);
296 expect(50,checkParts
[0]);
297 expect(150,checkParts
[1]);
298 expect(-1,checkParts
[2]);
299 r
= SendMessage(hWndStatus
, SB_GETBORDERS
, 0, (LPARAM
)borders
);
300 ok(r
== TRUE
, "Expected TRUE, got %d\n", r
);
301 expect(0,borders
[0]);
302 expect(2,borders
[1]);
303 expect(2,borders
[2]);
305 /* Test resetting text with different characters */
306 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 0, (LPARAM
)"First@Again");
308 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 1, (LPARAM
)"InvalidChars\\7\7");
310 r
= SendMessage(hWndStatus
, SB_SETTEXT
, 2, (LPARAM
)"InvalidChars\\n\n");
314 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 0, (LPARAM
) charArray
);
315 ok(strcmp(charArray
,"First@Again") == 0, "Expected First@Again, got %s\n", charArray
);
316 expect(11,LOWORD(r
));
318 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 1, (LPARAM
) charArray
);
321 ok(strcmp(charArray
,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray
);
323 expect(15,LOWORD(r
));
325 r
= SendMessage(hWndStatus
, SB_GETTEXT
, 2, (LPARAM
) charArray
);
328 ok(strcmp(charArray
,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray
);
330 expect(15,LOWORD(r
));
333 /* Set background color */
334 r
= SendMessage(hWndStatus
, SB_SETBKCOLOR
, 0, RGB(255,0,0));
335 ok(r
== CLR_DEFAULT
||
336 broken(r
== 0), /* win95 */
337 "Expected %d, got %d\n", CLR_DEFAULT
, r
);
338 r
= SendMessage(hWndStatus
, SB_SETBKCOLOR
, 0, CLR_DEFAULT
);
339 ok(r
== RGB(255,0,0) ||
340 broken(r
== 0), /* win95 */
341 "Expected %d, got %d\n", RGB(255,0,0), r
);
343 /* Add an icon to the status bar */
344 hIcon
= LoadIcon(NULL
, IDI_QUESTION
);
345 r
= SendMessage(hWndStatus
, SB_SETICON
, 1, 0);
347 broken(r
== 0), /* win95 */
348 "Expected non-zero, got %d\n", r
);
349 r
= SendMessage(hWndStatus
, SB_SETICON
, 1, (LPARAM
) hIcon
);
351 broken(r
== 0), /* win95 */
352 "Expected non-zero, got %d\n", r
);
353 r
= SendMessage(hWndStatus
, SB_SETICON
, 1, 0);
355 broken(r
== 0), /* win95 */
356 "Expected non-zero, got %d\n", r
);
358 /* Set the Unicode format */
359 r
= SendMessage(hWndStatus
, SB_SETUNICODEFORMAT
, FALSE
, 0);
360 r
= SendMessage(hWndStatus
, SB_GETUNICODEFORMAT
, 0, 0);
362 r
= SendMessage(hWndStatus
, SB_SETUNICODEFORMAT
, TRUE
, 0);
364 r
= SendMessage(hWndStatus
, SB_GETUNICODEFORMAT
, 0, 0);
366 broken(r
== FALSE
), /* win95 */
367 "Expected TRUE, got %d\n", r
);
369 /* Reset number of parts */
370 r
= SendMessage(hWndStatus
, SB_SETPARTS
, 2, (LPARAM
)nParts
);
373 /* Set the minimum height and get rectangle information again */
374 SendMessage(hWndStatus
, SB_SETMINHEIGHT
, 50, 0);
375 r
= SendMessage(hWndStatus
, WM_SIZE
, 0, 0);
377 r
= SendMessage(hWndStatus
, SB_GETRECT
, 0, (LPARAM
)&rc
);
380 /* The rc.bottom test is system dependent
381 expect(22,rc.bottom); */
384 r
= SendMessage(hWndStatus
, SB_GETRECT
, -1, (LPARAM
)&rc
);
386 r
= SendMessage(hWndStatus
, SB_GETRECT
, 3, (LPARAM
)&rc
);
389 /* Set the ToolTip text */
392 SendMessage(hWndStatus
, SB_SETTIPTEXT
, 0,(LPARAM
) "Tooltip Text");
393 lstrcpyA(charArray
, "apple");
394 SendMessage(hWndStatus
, SB_GETTIPTEXT
, MAKEWPARAM (0, 20),(LPARAM
) charArray
);
395 ok(strcmp(charArray
,"Tooltip Text") == 0 ||
396 broken(!strcmp(charArray
, "apple")), /* win95 */
397 "Expected Tooltip Text, got %s\n", charArray
);
401 SendMessage(hWndStatus
, SB_SIMPLE
, TRUE
, 0);
402 r
= SendMessage(hWndStatus
, SB_ISSIMPLE
, 0, 0);
404 broken(r
== FALSE
), /* win95 */
405 "Expected TRUE, got %d\n", r
);
407 DestroyWindow(hWndStatus
);
412 hinst
= GetModuleHandleA(NULL
);
414 g_hMainWnd
= CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW
,
415 CW_USEDEFAULT
, CW_USEDEFAULT
, 672+2*GetSystemMetrics(SM_CXSIZEFRAME
),
416 226+GetSystemMetrics(SM_CYCAPTION
)+2*GetSystemMetrics(SM_CYSIZEFRAME
),
417 NULL
, NULL
, GetModuleHandleA(NULL
), 0);
419 InitCommonControls();
423 test_status_control();