~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/comctl32/tests/status.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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 { \
 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)
 37 
 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;
 45 
 46 static HWND create_status_control(DWORD style, DWORD exstyle)
 47 {
 48     HWND hWndStatus;
 49 
 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;
 58 }
 59 
 60 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 61 {
 62     LRESULT ret;
 63 
 64     if (msg == WM_CREATE)
 65     {
 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)
 73     {
 74         g_wmsize_count++;
 75         ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
 76     }
 77     else
 78         ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
 79 
 80     return ret;
 81 }
 82 
 83 static void register_subclass(void)
 84 {
 85     WNDCLASSEX cls;
 86 
 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");
 94 }
 95 
 96 static void test_create(void)
 97 {
 98     RECT rc;
 99     HWND hwnd;
100 
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);
112 }
113 
114 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam)
115 {
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;
123 
124     /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
125     if (type != TRUETYPE_FONTTYPE)
126         facename = enumlf->elfLogFont.lfFaceName;
127 
128     for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
129     {
130         HFONT hFont;
131         TEXTMETRIC tm;
132         HFONT hCtrlFont;
133         HFONT hOldFont;
134         RECT rcCtrl;
135 
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);
140 
141         GetClientRect(hwndStatus, &rcCtrl);
142         GetTextMetrics(hdc, &tm);
143         y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4;
144 
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]);
148 
149         SelectObject(hdc, hOldFont);
150         SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
151         DeleteObject(hFont);
152     }
153     ReleaseDC(NULL, hdc);
154     return 1;
155 }
156 
157 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam)
158 {
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;
164 }
165 
166 static void test_height(void)
167 {
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;
174 
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");
178 
179     g_wmsize_count = 0;
180     SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
181     if (!g_wmsize_count)
182     {
183         skip("Status control not resized in win95, skipping broken tests.\n");
184         return;
185     }
186     ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
187 
188     GetClientRect(hwndStatus, &rc2);
189     expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
190 
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");
194 
195     GetClientRect(hwndStatus, &rc2);
196     expect_rect(0, 0, 672, 42, rc2);
197 
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);
203 
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);
211 
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);
223 
224     /* test the height formula */
225     ZeroMemory(&lf, sizeof(lf));
226     SendMessage(hwndStatus, SB_SETMINHEIGHT, 0, 0);
227     hdc = GetDC(NULL);
228 
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 */
232 
233     g_dpisize = MulDiv(18, GetDeviceCaps(hdc, LOGPIXELSY), 96) + 2;
234     if (g_dpisize & 1) g_dpisize--; /* The min height is always even */
235 
236 
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));
240 
241     EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
242     ReleaseDC(NULL, hdc);
243 
244     DestroyWindow(hwndStatus);
245     DeleteObject(hFont);
246     DeleteObject(hFontSm);
247 }
248 
249 static void test_status_control(void)
250 {
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;
259 
260     hWndStatus = create_status_control(WS_VISIBLE, 0);
261 
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);
271 
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));
292 
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]);
304 
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);
312 
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
320     {
321         ok(strcmp(charArray,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray);
322     }
323     expect(15,LOWORD(r));
324     expect(0,HIWORD(r));
325     r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
326     todo_wine
327     {
328         ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
329     }
330     expect(15,LOWORD(r));
331     expect(0,HIWORD(r));
332 
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);
342 
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);
357 
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);
368 
369     /* Reset number of parts */
370     r = SendMessage(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
371     expect(TRUE,r);
372 
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);
388 
389     /* Set the ToolTip text */
390     todo_wine
391     {
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);
398     }
399 
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);
406 
407     DestroyWindow(hWndStatus);
408 }
409 
410 START_TEST(status)
411 {
412     hinst = GetModuleHandleA(NULL);
413 
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);
418 
419     InitCommonControls();
420 
421     register_subclass();
422 
423     test_status_control();
424     test_create();
425     test_height();
426 }
427 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.