push d1f5df181c120dbe494f7c89b454752c2e0dcc04
[wine/hacks.git] / dlls / comctl32 / tests / status.c
blobf47d3ea06f217bf392f494461038639e5592abe4
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
21 #include <assert.h>
22 #include <windows.h>
23 #include <commctrl.h>
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;
43 static DWORD g_height;
45 static HWND create_status_control(DWORD style, DWORD exstyle)
47 HWND hWndStatus;
49 /* make the control */
50 hWndStatus = CreateWindowEx(exstyle, STATUSCLASSNAME, NULL, style,
51 /* placement */
52 0, 0, 300, 20,
53 /* parent, etc */
54 NULL, NULL, hinst, NULL);
55 assert (hWndStatus);
56 return hWndStatus;
59 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
61 LRESULT ret;
63 if (msg == WM_CREATE)
65 CREATESTRUCT *cs = (CREATESTRUCT *)lParam;
66 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
67 GetWindowRect(hwnd, &g_rcCreated);
68 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
69 ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
70 ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
71 } else if (msg == WM_SIZE)
73 g_wmsize_count++;
74 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
76 else
77 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
79 return ret;
82 static void register_subclass(void)
84 WNDCLASSEX cls;
86 cls.cbSize = sizeof(WNDCLASSEX);
87 GetClassInfoEx(NULL, STATUSCLASSNAME, &cls);
88 g_status_wndproc = cls.lpfnWndProc;
89 cls.lpfnWndProc = create_test_wndproc;
90 cls.lpszClassName = SUBCLASS_NAME;
91 cls.hInstance = NULL;
92 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
95 static void test_create(void)
97 RECT rc;
98 HWND hwnd;
100 ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
101 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
102 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
103 GetWindowRect(hwnd, &rc);
104 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
105 expect_rect(0, 0, 100, 100, g_rcCreated);
106 expect(0, rc.left);
107 expect(672, rc.right);
108 expect(226, rc.bottom);
109 /* we don't check rc.top as this may depend on user font settings */
110 DestroyWindow(hwnd);
113 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam)
115 HWND hwndStatus = (HWND)lParam;
116 HDC hdc = GetDC(NULL);
117 static const int sizes[] = { 6, 7, 8, 9, 10, 11, 12, 13, 15, 16,
118 20, 22, 28, 36, 48, 72};
119 DWORD i;
120 DWORD y;
121 LPSTR facename = (CHAR *)enumlf->elfFullName;
123 /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
124 if (type != TRUETYPE_FONTTYPE)
125 facename = enumlf->elfLogFont.lfFaceName;
127 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
129 HFONT hFont;
130 TEXTMETRIC tm;
131 HFONT hCtrlFont;
132 HFONT hOldFont;
133 RECT rcCtrl;
135 enumlf->elfLogFont.lfHeight = sizes[i];
136 hFont = CreateFontIndirect(&enumlf->elfLogFont);
137 hCtrlFont = (HFONT)SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
138 hOldFont = SelectObject(hdc, hFont);
140 GetClientRect(hwndStatus, &rcCtrl);
141 GetTextMetrics(hdc, &tm);
142 y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4;
144 ok( rcCtrl.bottom == max(y, g_height),
145 "got %d (expected %d) for %s #%d\n",
146 rcCtrl.bottom, max(y, g_height), facename, sizes[i]);
148 SelectObject(hdc, hOldFont);
149 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
150 DeleteObject(hFont);
152 ReleaseDC(NULL, hdc);
153 return 1;
156 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam)
158 HDC hdc = GetDC(NULL);
159 enumlf->elfLogFont.lfHeight = 0;
160 EnumFontFamiliesEx(hdc, &enumlf->elfLogFont, (FONTENUMPROC)check_height_font_enumproc, lParam, 0);
161 ReleaseDC(NULL, hdc);
162 return 1;
165 static void test_height(void)
167 LOGFONT lf;
168 HFONT hFont, hFontSm;
169 RECT rc1, rc2;
170 HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
171 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
172 HDC hdc;
174 GetClientRect(hwndStatus, &rc1);
175 hFont = CreateFont(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
176 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
178 g_wmsize_count = 0;
179 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
180 if (!g_wmsize_count)
182 skip("Status control not resized in win95, skipping broken tests.\n");
183 return;
185 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
187 GetClientRect(hwndStatus, &rc2);
188 expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
190 g_wmsize_count = 0;
191 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
192 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
194 GetClientRect(hwndStatus, &rc2);
195 expect_rect(0, 0, 672, 42, rc2);
197 /* minheight < fontsize - no effects*/
198 SendMessage(hwndStatus, SB_SETMINHEIGHT, 12, 0);
199 SendMessage(hwndStatus, WM_SIZE, 0, 0);
200 GetClientRect(hwndStatus, &rc2);
201 expect_rect(0, 0, 672, 42, rc2);
203 /* minheight > fontsize - has an effect after WM_SIZE */
204 SendMessage(hwndStatus, SB_SETMINHEIGHT, 60, 0);
205 GetClientRect(hwndStatus, &rc2);
206 expect_rect(0, 0, 672, 42, rc2);
207 SendMessage(hwndStatus, WM_SIZE, 0, 0);
208 GetClientRect(hwndStatus, &rc2);
209 expect_rect(0, 0, 672, 62, rc2);
211 /* font changed to smaller than minheight - has an effect */
212 SendMessage(hwndStatus, SB_SETMINHEIGHT, 30, 0);
213 expect_rect(0, 0, 672, 62, rc2);
214 SendMessage(hwndStatus, WM_SIZE, 0, 0);
215 GetClientRect(hwndStatus, &rc2);
216 expect_rect(0, 0, 672, 42, rc2);
217 hFontSm = CreateFont(9, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
218 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
219 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFontSm, TRUE);
220 GetClientRect(hwndStatus, &rc2);
221 expect_rect(0, 0, 672, 32, rc2);
223 /* test the height formula */
224 ZeroMemory(&lf, sizeof(lf));
225 SendMessage(hwndStatus, SB_SETMINHEIGHT, 0, 0);
226 hdc = GetDC(NULL);
228 g_height = GetSystemMetrics(SM_CYSIZE) + 2;
229 if (g_height & 1) g_height--; /* The height is always even */
231 trace("dpi=%d (min height: %d)\n", GetDeviceCaps(hdc, LOGPIXELSY), g_height);
232 EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
233 ReleaseDC(NULL, hdc);
235 DestroyWindow(hwndStatus);
236 DeleteObject(hFont);
237 DeleteObject(hFontSm);
240 static void test_status_control(void)
242 HWND hWndStatus;
243 int r;
244 int nParts[] = {50, 150, -1};
245 int checkParts[] = {0, 0, 0};
246 int borders[] = {0, 0, 0};
247 RECT rc;
248 CHAR charArray[20];
249 HICON hIcon;
251 hWndStatus = create_status_control(WS_VISIBLE, 0);
253 /* Divide into parts and set text */
254 r = SendMessage(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
255 expect(TRUE,r);
256 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First");
257 expect(TRUE,r);
258 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"Second");
259 expect(TRUE,r);
260 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"Third");
261 expect(TRUE,r);
263 /* Get RECT Information */
264 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
265 expect(TRUE,r);
266 expect(2,rc.top);
267 /* The rc.bottom test is system dependent
268 expect(22,rc.bottom); */
269 expect(0,rc.left);
270 expect(50,rc.right);
271 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
272 expect(FALSE,r);
273 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
274 expect(FALSE,r);
275 /* Get text length and text */
276 r = SendMessage(hWndStatus, SB_GETTEXTLENGTH, 2, 0);
277 expect(5,LOWORD(r));
278 expect(0,HIWORD(r));
279 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
280 ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
281 expect(5,LOWORD(r));
282 expect(0,HIWORD(r));
284 /* Get parts and borders */
285 r = SendMessage(hWndStatus, SB_GETPARTS, 3, (LPARAM)checkParts);
286 ok(r == 3, "Expected 3, got %d\n", r);
287 expect(50,checkParts[0]);
288 expect(150,checkParts[1]);
289 expect(-1,checkParts[2]);
290 r = SendMessage(hWndStatus, SB_GETBORDERS, 0, (LPARAM)borders);
291 ok(r == TRUE, "Expected TRUE, got %d\n", r);
292 expect(0,borders[0]);
293 expect(2,borders[1]);
294 expect(2,borders[2]);
296 /* Test resetting text with different characters */
297 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First@Again");
298 expect(TRUE,r);
299 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"InvalidChars\\7\7");
300 expect(TRUE,r);
301 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"InvalidChars\\n\n");
302 expect(TRUE,r);
304 /* Get text again */
305 r = SendMessage(hWndStatus, SB_GETTEXT, 0, (LPARAM) charArray);
306 ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
307 expect(11,LOWORD(r));
308 expect(0,HIWORD(r));
309 r = SendMessage(hWndStatus, SB_GETTEXT, 1, (LPARAM) charArray);
310 todo_wine
312 ok(strcmp(charArray,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray);
314 expect(15,LOWORD(r));
315 expect(0,HIWORD(r));
316 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
317 todo_wine
319 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
321 expect(15,LOWORD(r));
322 expect(0,HIWORD(r));
324 /* Set background color */
325 r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
326 ok(r == CLR_DEFAULT ||
327 broken(r == 0), /* win95 */
328 "Expected %d, got %d\n", CLR_DEFAULT, r);
329 r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
330 ok(r == RGB(255,0,0) ||
331 broken(r == 0), /* win95 */
332 "Expected %d, got %d\n", RGB(255,0,0), r);
334 /* Add an icon to the status bar */
335 hIcon = LoadIcon(NULL, IDI_QUESTION);
336 r = SendMessage(hWndStatus, SB_SETICON, 1, 0);
337 ok(r != 0 ||
338 broken(r == 0), /* win95 */
339 "Expected non-zero, got %d\n", r);
340 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
341 ok(r != 0 ||
342 broken(r == 0), /* win95 */
343 "Expected non-zero, got %d\n", r);
344 r = SendMessage(hWndStatus, SB_SETICON, 1, 0);
345 ok(r != 0 ||
346 broken(r == 0), /* win95 */
347 "Expected non-zero, got %d\n", r);
349 /* Set the Unicode format */
350 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
351 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
352 expect(FALSE,r);
353 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
354 expect(FALSE,r);
355 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
356 ok(r == TRUE ||
357 broken(r == FALSE), /* win95 */
358 "Expected TRUE, got %d\n", r);
360 /* Reset number of parts */
361 r = SendMessage(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
362 expect(TRUE,r);
364 /* Set the minimum height and get rectangle information again */
365 SendMessage(hWndStatus, SB_SETMINHEIGHT, 50, 0);
366 r = SendMessage(hWndStatus, WM_SIZE, 0, 0);
367 expect(0,r);
368 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
369 expect(TRUE,r);
370 expect(2,rc.top);
371 /* The rc.bottom test is system dependent
372 expect(22,rc.bottom); */
373 expect(0,rc.left);
374 expect(50,rc.right);
375 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
376 expect(FALSE,r);
377 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
378 expect(FALSE,r);
380 /* Set the ToolTip text */
381 todo_wine
383 SendMessage(hWndStatus, SB_SETTIPTEXT, 0,(LPARAM) "Tooltip Text");
384 lstrcpyA(charArray, "apple");
385 SendMessage(hWndStatus, SB_GETTIPTEXT, MAKEWPARAM (0, 20),(LPARAM) charArray);
386 ok(strcmp(charArray,"Tooltip Text") == 0 ||
387 broken(!strcmp(charArray, "apple")), /* win95 */
388 "Expected Tooltip Text, got %s\n", charArray);
391 /* Make simple */
392 SendMessage(hWndStatus, SB_SIMPLE, TRUE, 0);
393 r = SendMessage(hWndStatus, SB_ISSIMPLE, 0, 0);
394 ok(r == TRUE ||
395 broken(r == FALSE), /* win95 */
396 "Expected TRUE, got %d\n", r);
398 DestroyWindow(hWndStatus);
401 START_TEST(status)
403 hinst = GetModuleHandleA(NULL);
405 g_hMainWnd = CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW,
406 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
407 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
408 NULL, NULL, GetModuleHandleA(NULL), 0);
410 InitCommonControls();
412 register_subclass();
414 test_status_control();
415 test_create();
416 test_height();