1 /* Unit test suite for status control.
2 *
3 * Copyright 2007 Google (Lei Zhang)
4 * Copyright 2007 Alex Arazi
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <assert.h>
22 #include <windows.h>
23 #include <commctrl.h>
24
25 #include "wine/test.h"
26
27 #define SUBCLASS_NAME "MyStatusBar"
28
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 { RECT _rcExp = {_left, _top, _right, _bottom}; \
31 ok(memcmp(&_rcExp, &(got), sizeof(RECT)) == 0, "Expected rect {%d,%d, %d,%d}, got {%d,%d, %d,%d}\n", \
32 _rcExp.left, _rcExp.top, _rcExp.right, _rcExp.bottom, \
33 (got).left, (got).top, (got).right, (got).bottom); } while (0)
34
35 static HINSTANCE hinst;
36 static WNDPROC g_status_wndproc;
37 static RECT g_rcCreated;
38 static HWND g_hMainWnd;
39 static int g_wmsize_count = 0;
40
41 static HWND create_status_control(DWORD style, DWORD exstyle)
42 {
43 HWND hWndStatus;
44
45 /* make the control */
46 hWndStatus = CreateWindowEx(exstyle, STATUSCLASSNAME, NULL, style,
47 /* placement */
48 0, 0, 300, 20,
49 /* parent, etc */
50 NULL, NULL, hinst, NULL);
51 assert (hWndStatus);
52 return hWndStatus;
53 }
54
55 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
56 {
57 LRESULT ret;
58
59 if (msg == WM_CREATE)
60 {
61 CREATESTRUCT *cs = (CREATESTRUCT *)lParam;
62 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
63 GetWindowRect(hwnd, &g_rcCreated);
64 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
65 ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
66 ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
67 } else if (msg == WM_SIZE)
68 {
69 g_wmsize_count++;
70 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
71 }
72 else
73 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
74
75 return ret;
76 }
77
78 static void register_subclass()
79 {
80 WNDCLASSEX cls;
81
82 cls.cbSize = sizeof(WNDCLASSEX);
83 GetClassInfoEx(NULL, STATUSCLASSNAME, &cls);
84 g_status_wndproc = cls.lpfnWndProc;
85 cls.lpfnWndProc = create_test_wndproc;
86 cls.lpszClassName = SUBCLASS_NAME;
87 cls.hInstance = NULL;
88 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
89 }
90
91 static void test_create()
92 {
93 RECT rc;
94 HWND hwnd;
95
96 ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
97 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
98 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
99 GetWindowRect(hwnd, &rc);
100 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
101 expect_rect(0, 0, 100, 100, g_rcCreated);
102 expect(0, rc.left);
103 expect(672, rc.right);
104 expect(226, rc.bottom);
105 /* we don't check rc.top as this may depend on user font settings */
106 DestroyWindow(hwnd);
107 }
108
109 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam)
110 {
111 HWND hwndStatus = (HWND)lParam;
112 HDC hdc = GetDC(NULL);
113 static const int sizes[] = {8, 9, 10, 12, 16, 22, 28, 36, 48, 72};
114 int i;
115
116 trace("Font %s\n", enumlf->elfFullName);
117 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
118 {
119 HFONT hFont;
120 TEXTMETRIC tm;
121 HFONT hCtrlFont;
122 HFONT hOldFont;
123 RECT rcCtrl;
124
125 enumlf->elfLogFont.lfHeight = sizes[i];
126 hFont = CreateFontIndirect(&enumlf->elfLogFont);
127 hCtrlFont = (HFONT)SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
128 hOldFont = SelectObject(hdc, hFont);
129
130 GetClientRect(hwndStatus, &rcCtrl);
131 GetTextMetrics(hdc, &tm);
132 expect(max(tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4, 20), rcCtrl.bottom);
133
134 SelectObject(hdc, hOldFont);
135 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
136 DeleteObject(hFont);
137 }
138 ReleaseDC(NULL, hdc);
139 return 1;
140 }
141
142 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam)
143 {
144 HDC hdc = GetDC(NULL);
145 enumlf->elfLogFont.lfHeight = 0;
146 EnumFontFamiliesEx(hdc, &enumlf->elfLogFont, (FONTENUMPROC)check_height_font_enumproc, lParam, 0);
147 ReleaseDC(NULL, hdc);
148 return 1;
149 }
150
151 static void test_height(void)
152 {
153 LOGFONT lf;
154 HFONT hFont, hFontSm;
155 RECT rc1, rc2;
156 HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
157 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
158 HDC hdc;
159
160 GetClientRect(hwndStatus, &rc1);
161 hFont = CreateFont(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
162 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
163
164 g_wmsize_count = 0;
165 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
166 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
167
168 GetClientRect(hwndStatus, &rc2);
169 todo_wine expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
170
171 g_wmsize_count = 0;
172 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
173 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
174
175 GetClientRect(hwndStatus, &rc2);
176 todo_wine expect_rect(0, 0, 672, 42, rc2);
177
178 /* minheight < fontsize - no effects*/
179 SendMessage(hwndStatus, SB_SETMINHEIGHT, 12, 0);
180 SendMessage(hwndStatus, WM_SIZE, 0, 0);
181 GetClientRect(hwndStatus, &rc2);
182 todo_wine expect_rect(0, 0, 672, 42, rc2);
183
184 /* minheight > fontsize - has an effect after WM_SIZE */
185 SendMessage(hwndStatus, SB_SETMINHEIGHT, 60, 0);
186 GetClientRect(hwndStatus, &rc2);
187 todo_wine expect_rect(0, 0, 672, 42, rc2);
188 SendMessage(hwndStatus, WM_SIZE, 0, 0);
189 GetClientRect(hwndStatus, &rc2);
190 expect_rect(0, 0, 672, 62, rc2);
191
192 /* font changed to smaller than minheight - has an effect */
193 SendMessage(hwndStatus, SB_SETMINHEIGHT, 30, 0);
194 expect_rect(0, 0, 672, 62, rc2);
195 SendMessage(hwndStatus, WM_SIZE, 0, 0);
196 GetClientRect(hwndStatus, &rc2);
197 todo_wine expect_rect(0, 0, 672, 42, rc2);
198 hFontSm = CreateFont(9, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
199 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
200 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFontSm, TRUE);
201 GetClientRect(hwndStatus, &rc2);
202 expect_rect(0, 0, 672, 32, rc2);
203
204 /* test the height formula */
205 ZeroMemory(&lf, sizeof(lf));
206 SendMessage(hwndStatus, SB_SETMINHEIGHT, 0, 0);
207 hdc = GetDC(NULL);
208 trace("dpi=%d\n", GetDeviceCaps(hdc, LOGPIXELSY));
209 EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
210 ReleaseDC(NULL, hdc);
211
212 DestroyWindow(hwndStatus);
213 DeleteObject(hFont);
214 DeleteObject(hFontSm);
215 }
216
217 static void test_status_control(void)
218 {
219 HWND hWndStatus;
220 int r;
221 int nParts[] = {50, 150, -1};
222 int checkParts[] = {0, 0, 0};
223 int borders[] = {0, 0, 0};
224 RECT rc;
225 CHAR charArray[20];
226 HICON hIcon;
227
228 hWndStatus = create_status_control(WS_VISIBLE, 0);
229
230 /* Divide into parts and set text */
231 r = SendMessage(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
232 expect(TRUE,r);
233 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First");
234 expect(TRUE,r);
235 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"Second");
236 expect(TRUE,r);
237 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"Third");
238 expect(TRUE,r);
239
240 /* Get RECT Information */
241 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
242 expect(TRUE,r);
243 expect(2,rc.top);
244 /* The rc.bottom test is system dependent
245 expect(22,rc.bottom); */
246 expect(0,rc.left);
247 expect(50,rc.right);
248 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
249 expect(FALSE,r);
250 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
251 expect(FALSE,r);
252 /* Get text length and text */
253 r = SendMessage(hWndStatus, SB_GETTEXTLENGTH, 2, 0);
254 expect(5,LOWORD(r));
255 expect(0,HIWORD(r));
256 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
257 ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
258 expect(5,LOWORD(r));
259 expect(0,HIWORD(r));
260
261 /* Get parts and borders */
262 r = SendMessage(hWndStatus, SB_GETPARTS, 3, (LPARAM)checkParts);
263 ok(r == 3, "Expected 3, got %d\n", r);
264 expect(50,checkParts[0]);
265 expect(150,checkParts[1]);
266 expect(-1,checkParts[2]);
267 r = SendMessage(hWndStatus, SB_GETBORDERS, 0, (LPARAM)borders);
268 ok(r == TRUE, "Expected TRUE, got %d\n", r);
269 expect(0,borders[0]);
270 expect(2,borders[1]);
271 expect(2,borders[2]);
272
273 /* Test resetting text with different characters */
274 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First@Again");
275 expect(TRUE,r);
276 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"InvalidChars\\7\7");
277 expect(TRUE,r);
278 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"InvalidChars\\n\n");
279 expect(TRUE,r);
280
281 /* Get text again */
282 r = SendMessage(hWndStatus, SB_GETTEXT, 0, (LPARAM) charArray);
283 ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
284 expect(11,LOWORD(r));
285 expect(0,HIWORD(r));
286 r = SendMessage(hWndStatus, SB_GETTEXT, 1, (LPARAM) charArray);
287 todo_wine
288 {
289 ok(strcmp(charArray,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray);
290 }
291 expect(15,LOWORD(r));
292 expect(0,HIWORD(r));
293 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
294 todo_wine
295 {
296 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
297 }
298 expect(15,LOWORD(r));
299 expect(0,HIWORD(r));
300
301 /* Set background color */
302 r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
303 expect(CLR_DEFAULT,r);
304 r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
305 expect(RGB(255,0,0),r);
306
307 /* Add an icon to the status bar */
308 hIcon = LoadIcon(NULL, IDI_QUESTION);
309 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) NULL);
310 ok(r != 0, "Expected non-zero, got %d\n", r);
311 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
312 ok(r != 0, "Expected non-zero, got %d\n", r);
313 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) NULL);
314 ok(r != 0, "Expected non-zero, got %d\n", r);
315
316 /* Set the Unicode format */
317 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
318 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
319 expect(FALSE,r);
320 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
321 expect(FALSE,r);
322 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
323 expect(TRUE,r);
324
325 /* Reset number of parts */
326 r = SendMessage(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
327 expect(TRUE,r);
328
329 /* Set the minimum height and get rectangle information again */
330 SendMessage(hWndStatus, SB_SETMINHEIGHT, 50, (LPARAM) 0);
331 r = SendMessage(hWndStatus, WM_SIZE, 0, (LPARAM) 0);
332 expect(0,r);
333 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
334 expect(TRUE,r);
335 expect(2,rc.top);
336 /* The rc.bottom test is system dependent
337 expect(22,rc.bottom); */
338 expect(0,rc.left);
339 expect(50,rc.right);
340 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
341 expect(FALSE,r);
342 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
343 expect(FALSE,r);
344
345 /* Set the ToolTip text */
346 todo_wine
347 {
348 SendMessage(hWndStatus, SB_SETTIPTEXT, 0,(LPARAM) "Tooltip Text");
349 SendMessage(hWndStatus, SB_GETTIPTEXT, MAKEWPARAM (0, 20),(LPARAM) charArray);
350 ok(strcmp(charArray,"Tooltip Text") == 0, "Expected Tooltip Text, got %s\n", charArray);
351 }
352
353 /* Make simple */
354 SendMessage(hWndStatus, SB_SIMPLE, TRUE, 0);
355 r = SendMessage(hWndStatus, SB_ISSIMPLE, 0, 0);
356 expect(TRUE,r);
357
358 DestroyWindow(hWndStatus);
359 }
360
361 START_TEST(status)
362 {
363 hinst = GetModuleHandleA(NULL);
364
365 g_hMainWnd = CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW,
366 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
367 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
368 NULL, NULL, GetModuleHandleA(NULL), 0);
369
370 InitCommonControls();
371
372 register_subclass();
373
374 test_status_control();
375 test_create();
376 test_height();
377 }
378
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.