push d5e2921572bdd1b7f373ca20793c3334c6a25be1
[wine/hacks.git] / dlls / comctl32 / tests / status.c
blobb6c5b7bcb8b7314ec91b53c1c75e2600f7401061
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 { 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)
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;
41 static HWND create_status_control(DWORD style, DWORD exstyle)
43 HWND hWndStatus;
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;
55 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
57 LRESULT ret;
59 if (msg == WM_CREATE)
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)
69 g_wmsize_count++;
70 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
72 else
73 ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
75 return ret;
78 static void register_subclass()
80 WNDCLASSEX cls;
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");
91 static void test_create()
93 RECT rc;
94 HWND hwnd;
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);
109 static void test_setfont()
111 HFONT hFont;
112 RECT rc1, rc2;
113 HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
114 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
116 GetClientRect(hwndStatus, &rc1);
117 hFont = CreateFont(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
118 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
120 g_wmsize_count = 0;
121 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
122 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
124 GetClientRect(hwndStatus, &rc2);
125 todo_wine expect_rect(0, 0, 672, 42, rc2);
127 g_wmsize_count = 0;
128 SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
129 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
131 GetClientRect(hwndStatus, &rc2);
132 todo_wine expect_rect(0, 0, 672, 42, rc2);
134 DestroyWindow(hwndStatus);
135 DeleteObject(hFont);
138 static void test_status_control(void)
140 HWND hWndStatus;
141 int r;
142 int nParts[] = {50, 150, -1};
143 int checkParts[] = {0, 0, 0};
144 int borders[] = {0, 0, 0};
145 RECT rc;
146 CHAR charArray[20];
147 HICON hIcon;
149 hWndStatus = create_status_control(WS_VISIBLE, 0);
151 /* Divide into parts and set text */
152 r = SendMessage(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
153 expect(TRUE,r);
154 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First");
155 expect(TRUE,r);
156 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"Second");
157 expect(TRUE,r);
158 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"Third");
159 expect(TRUE,r);
161 /* Get RECT Information */
162 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
163 expect(TRUE,r);
164 expect(2,rc.top);
165 /* The rc.bottom test is system dependent
166 expect(22,rc.bottom); */
167 expect(0,rc.left);
168 expect(50,rc.right);
169 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
170 expect(FALSE,r);
171 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
172 expect(FALSE,r);
173 /* Get text length and text */
174 r = SendMessage(hWndStatus, SB_GETTEXTLENGTH, 2, 0);
175 expect(5,LOWORD(r));
176 expect(0,HIWORD(r));
177 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
178 ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
179 expect(5,LOWORD(r));
180 expect(0,HIWORD(r));
182 /* Get parts and borders */
183 r = SendMessage(hWndStatus, SB_GETPARTS, 3, (LPARAM)checkParts);
184 ok(r == 3, "Expected 3, got %d\n", r);
185 expect(50,checkParts[0]);
186 expect(150,checkParts[1]);
187 expect(-1,checkParts[2]);
188 r = SendMessage(hWndStatus, SB_GETBORDERS, 0, (LPARAM)borders);
189 ok(r == TRUE, "Expected TRUE, got %d\n", r);
190 expect(0,borders[0]);
191 expect(2,borders[1]);
192 expect(2,borders[2]);
194 /* Test resetting text with different characters */
195 r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First@Again");
196 expect(TRUE,r);
197 r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"InvalidChars\\7\7");
198 expect(TRUE,r);
199 r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"InvalidChars\\n\n");
200 expect(TRUE,r);
202 /* Get text again */
203 r = SendMessage(hWndStatus, SB_GETTEXT, 0, (LPARAM) charArray);
204 ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
205 expect(11,LOWORD(r));
206 expect(0,HIWORD(r));
207 r = SendMessage(hWndStatus, SB_GETTEXT, 1, (LPARAM) charArray);
208 todo_wine
210 ok(strcmp(charArray,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray);
212 expect(15,LOWORD(r));
213 expect(0,HIWORD(r));
214 r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
215 todo_wine
217 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
219 expect(15,LOWORD(r));
220 expect(0,HIWORD(r));
222 /* Set background color */
223 r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
224 expect(CLR_DEFAULT,r);
225 r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
226 expect(RGB(255,0,0),r);
228 /* Add an icon to the status bar */
229 hIcon = LoadIcon(NULL, IDI_QUESTION);
230 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) NULL);
231 ok(r != 0, "Expected non-zero, got %d\n", r);
232 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
233 ok(r != 0, "Expected non-zero, got %d\n", r);
234 r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) NULL);
235 ok(r != 0, "Expected non-zero, got %d\n", r);
237 /* Set the Unicode format */
238 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
239 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
240 expect(FALSE,r);
241 r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
242 expect(FALSE,r);
243 r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
244 expect(TRUE,r);
246 /* Reset number of parts */
247 r = SendMessage(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
248 expect(TRUE,r);
250 /* Set the minimum height and get rectangle information again */
251 SendMessage(hWndStatus, SB_SETMINHEIGHT, 50, (LPARAM) 0);
252 r = SendMessage(hWndStatus, WM_SIZE, 0, (LPARAM) 0);
253 expect(0,r);
254 r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
255 expect(TRUE,r);
256 expect(2,rc.top);
257 /* The rc.bottom test is system dependent
258 expect(22,rc.bottom); */
259 expect(0,rc.left);
260 expect(50,rc.right);
261 r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
262 expect(FALSE,r);
263 r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
264 expect(FALSE,r);
266 /* Set the ToolTip text */
267 todo_wine
269 SendMessage(hWndStatus, SB_SETTIPTEXT, 0,(LPARAM) "Tooltip Text");
270 SendMessage(hWndStatus, SB_GETTIPTEXT, MAKEWPARAM (0, 20),(LPARAM) charArray);
271 ok(strcmp(charArray,"Tooltip Text") == 0, "Expected Tooltip Text, got %s\n", charArray);
274 /* Make simple */
275 SendMessage(hWndStatus, SB_SIMPLE, TRUE, 0);
276 r = SendMessage(hWndStatus, SB_ISSIMPLE, 0, 0);
277 expect(TRUE,r);
279 DestroyWindow(hWndStatus);
282 START_TEST(status)
284 hinst = GetModuleHandleA(NULL);
286 g_hMainWnd = CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW,
287 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
288 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
289 NULL, NULL, GetModuleHandleA(NULL), 0);
291 InitCommonControls();
293 register_subclass();
295 test_status_control();
296 test_create();
297 test_setfont();