push 98299ad1251baa2727aab065c47e9d935978c732
[wine/hacks.git] / dlls / comctl32 / tests / status.c
blob4fe624989f20953cddb34edbfd2284c7b2adac2c
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_ysize;
44 static DWORD g_dpisize;
46 static HWND create_status_control(DWORD style, DWORD exstyle)
48 HWND hWndStatus;
50 /* make the control */
51 hWndStatus = CreateWindowEx(exstyle, STATUSCLASSNAME, NULL, style,
52 /* placement */
53 0, 0, 300, 20,
54 /* parent, etc */
55 NULL, NULL, hinst, NULL);
56 assert (hWndStatus);
57 return hWndStatus;
60 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
62 LRESULT ret;
64 if (msg == WM_CREATE)
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)
74 g_wmsize_count++;
75 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
77 else
78 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
80 return ret;
83 static void register_subclass(void)
85 WNDCLASSEX cls;
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;
92 cls.hInstance = NULL;
93 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
96 static void test_create(void)
98 RECT rc;
99 HWND hwnd;
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);
107 expect(0, rc.left);
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 */
111 DestroyWindow(hwnd);
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};
120 DWORD i;
121 DWORD y;
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++)
130 HFONT hFont;
131 TEXTMETRIC tm;
132 HFONT hCtrlFont;
133 HFONT hOldFont;
134 RECT rcCtrl;
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);
151 DeleteObject(hFont);
153 ReleaseDC(NULL, hdc);
154 return 1;
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);
163 return 1;
166 static void test_height(void)
168 LOGFONT lf;
169 HFONT hFont, hFontSm;
170 RECT rc1, rc2;
171 HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
172 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
173 HDC hdc;
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");
179 g_wmsize_count = 0;
180 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
181 if (!g_wmsize_count)
183 skip("Status control not resized in win95, skipping broken tests.\n");
184 return;
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 */
191 g_wmsize_count = 0;
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);
227 hdc = GetDC(NULL);
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);
245 DeleteObject(hFont);
246 DeleteObject(hFontSm);
249 static void test_status_control(void)
251 HWND hWndStatus;
252 int r;
253 int nParts[] = {50, 150, -1};
254 int checkParts[] = {0, 0, 0};
255 int borders[] = {0, 0, 0};
256 RECT rc;
257 CHAR charArray[20];
258 HICON hIcon;
260 hWndStatus = create_status_control(WS_VISIBLE, 0);
262 /* Divide into parts and set text */
263 r = SendMessage(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
264 expect(TRUE,r);
265 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First");
266 expect(TRUE,r);
267 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"Second");
268 expect(TRUE,r);
269 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"Third");
270 expect(TRUE,r);
272 /* Get RECT Information */
273 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
274 expect(TRUE,r);
275 expect(2,rc.top);
276 /* The rc.bottom test is system dependent
277 expect(22,rc.bottom); */
278 expect(0,rc.left);
279 expect(50,rc.right);
280 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
281 expect(FALSE,r);
282 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
283 expect(FALSE,r);
284 /* Get text length and text */
285 r = SendMessage(hWndStatus, SB_GETTEXTLENGTH, 2, 0);
286 expect(5,LOWORD(r));
287 expect(0,HIWORD(r));
288 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
289 ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
290 expect(5,LOWORD(r));
291 expect(0,HIWORD(r));
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");
307 expect(TRUE,r);
308 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"InvalidChars\\7\7");
309 expect(TRUE,r);
310 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"InvalidChars\\n\n");
311 expect(TRUE,r);
313 /* Get text again */
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));
317 expect(0,HIWORD(r));
318 r = SendMessage(hWndStatus, SB_GETTEXT, 1, (LPARAM) charArray);
319 todo_wine
321 ok(strcmp(charArray,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray);
323 expect(15,LOWORD(r));
324 expect(0,HIWORD(r));
325 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
326 todo_wine
328 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
330 expect(15,LOWORD(r));
331 expect(0,HIWORD(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);
346 ok(r != 0 ||
347 broken(r == 0), /* win95 */
348 "Expected non-zero, got %d\n", r);
349 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
350 ok(r != 0 ||
351 broken(r == 0), /* win95 */
352 "Expected non-zero, got %d\n", r);
353 r = SendMessage(hWndStatus, SB_SETICON, 1, 0);
354 ok(r != 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);
361 expect(FALSE,r);
362 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
363 expect(FALSE,r);
364 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
365 ok(r == TRUE ||
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);
371 expect(TRUE,r);
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);
376 expect(0,r);
377 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
378 expect(TRUE,r);
379 expect(2,rc.top);
380 /* The rc.bottom test is system dependent
381 expect(22,rc.bottom); */
382 expect(0,rc.left);
383 expect(50,rc.right);
384 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
385 expect(FALSE,r);
386 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
387 expect(FALSE,r);
389 /* Set the ToolTip text */
390 todo_wine
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);
400 /* Make simple */
401 SendMessage(hWndStatus, SB_SIMPLE, TRUE, 0);
402 r = SendMessage(hWndStatus, SB_ISSIMPLE, 0, 0);
403 ok(r == TRUE ||
404 broken(r == FALSE), /* win95 */
405 "Expected TRUE, got %d\n", r);
407 DestroyWindow(hWndStatus);
410 START_TEST(status)
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();
421 register_subclass();
423 test_status_control();
424 test_create();
425 test_height();