2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for Button window class v6
5 * PROGRAMMERS: Giannis Adamopoulos
13 #define ok_rect(rc, l,r,t,b) ok((rc.left == (l)) && (rc.right == (r)) && (rc.top == (t)) && (rc.bottom == (b)), "Wrong rect. expected %d, %d, %d, %d got %ld, %ld, %ld, %ld\n", l,t,r,b, rc.left, rc.top, rc.right, rc.bottom)
14 #define ok_size(s, width, height) ok((s.cx == (width) && s.cy == (height)), "Expected size (%lu,%lu) got (%lu,%lu)\n", width, height, s.cx, s.cy)
16 void Test_TextMargin()
22 hwnd1
= CreateWindowW(L
"Button", L
"Test1", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
23 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
24 SetWindowTheme(hwnd1
, L
"", L
"");
26 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
27 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
28 ok_rect(rc
, 1, 1, 1, 1);
30 SetRect(&rc
, 0,0,0,0);
31 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
32 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
34 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
35 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
36 ok_rect(rc
, 0, 0, 0, 0);
38 SetRect(&rc
, -1,-1,-1,-1);
39 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
40 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
42 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
43 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
44 ok_rect(rc
, -1, -1, -1, -1);
46 SetRect(&rc
, 1000,1000,1000,1000);
47 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
48 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
50 ret
= SendMessageW(hwnd1
, BCM_GETTEXTMARGIN
, 0, (LPARAM
)&rc
);
51 ok (ret
== TRUE
, "Expected BCM_GETTEXTMARGIN to succeed\n");
52 ok_rect(rc
, 1000, 1000, 1000, 1000);
61 BUTTON_IMAGELIST imlData
;
63 hwnd1
= CreateWindowW(L
"Button", L
"Test2", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
64 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
66 ret
= SendMessageW(hwnd1
, BCM_GETIMAGELIST
, 0, (LPARAM
)&imlData
);
67 ok (ret
== TRUE
, "Expected BCM_GETIMAGELIST to succeed\n");
68 ok (imlData
.himl
== 0, "Expected 0 himl\n");
69 ok (imlData
.uAlign
== 0, "Expected 0 uAlign\n");
70 ok_rect(imlData
.margin
, 0, 0, 0, 0);
72 SetRect(&imlData
.margin
, 0,0,0,1);
73 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
74 ok (ret
== FALSE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
76 imlData
.himl
= (HIMAGELIST
)0xdead;
77 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
78 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n");
80 ret
= SendMessageW(hwnd1
, BCM_GETIMAGELIST
, 0, (LPARAM
)&imlData
);
81 ok (ret
== TRUE
, "Expected BCM_GETIMAGELIST to succeed\n");
82 ok (imlData
.himl
== (HIMAGELIST
)0xdead, "Expected 0 himl\n");
83 ok (imlData
.uAlign
== 0, "Expected 0 uAlign\n");
84 ok_rect(imlData
.margin
, 0, 0, 0, 1);
87 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
88 ok (ret
== FALSE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
93 void Test_GetIdealSizeNoThemes()
102 BUTTON_IMAGELIST imlData
;
106 hwnd1
= CreateWindowW(L
"Button", L
" ", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
107 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
108 SetWindowTheme(hwnd1
, L
"", L
"");
110 font
= (HFONT
)SendMessageW(hwnd1
, WM_GETFONT
, 0, 0);
112 SelectObject(hdc
, font
);
113 GetTextExtentPoint32W(hdc
, L
" ", 1, &textent
);
115 memset(&s
, 0, sizeof(s
));
116 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
117 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
118 ok_size(s
, textent
.cx
+ 5 + 2,
119 textent
.cy
+ 7 + 2); /* the last +2 is the text margin */
121 DestroyWindow(hwnd1
);
126 hwnd1
= CreateWindowW(L
"Button", L
"", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
127 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
128 SetWindowTheme(hwnd1
, L
"", L
"");
130 memset(&s
, 0, sizeof(s
));
131 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
132 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
133 ok (s
.cx
> 80, "Expected big cx\n");
134 ok (s
.cy
> 80, "Expected big cy\n");
138 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
139 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
140 ok (s
.cx
> 80, "Expected big cx\n");
141 ok (s
.cy
> 80, "Expected big cy\n");
143 hbmp
= LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(5), IMAGE_BITMAP
, 0, 0, 0);
144 ok (hbmp
!= 0, "Expected LoadImage to succeed\n");
146 SendMessageW(hwnd1
, BM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
)hbmp
);
148 memset(&s
, 0, sizeof(s
));
149 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
150 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
151 ok (s
.cx
> 80, "Expected big cx\n");
152 ok (s
.cy
> 80, "Expected big cy\n");
154 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(5), 1, 1, 0, IMAGE_BITMAP
, 0);
155 ok (himl
!= 0, "Expected ImageList_LoadImage to succeed\n");
157 memset(&imlData
, 0, sizeof(imlData
));
159 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
160 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */
162 memset(&s
, 0, sizeof(s
));
163 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
164 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
165 ok (s
.cx
> 80, "Expected big cx\n");
166 ok (s
.cy
> 80, "Expected big cy\n");
168 DestroyWindow(hwnd1
);
173 hwnd1
= CreateWindowW(L
"Button", L
" ", BS_BITMAP
, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
174 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
175 SetWindowTheme(hwnd1
, L
"", L
"");
177 SendMessageW(hwnd1
, BM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
)hbmp
);
179 memset(&s
, 0, sizeof(s
));
180 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
181 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
183 /* In xp and 2k3 the image is ignored, in vista+ its width is added to the text width */
184 ok_size(s
, textent
.cx
+ 5 + 2,
185 textent
.cy
+ 7 + 2); /* the last +2 is the text margin */
187 DestroyWindow(hwnd1
);
191 hwnd1
= CreateWindowW(L
"Button", L
" ", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
192 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
193 SetWindowTheme(hwnd1
, L
"", L
"");
195 SetRect(&rc
, 0,0,0,0);
196 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
197 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
199 memset(&s
, 0, sizeof(s
));
200 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
201 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
202 ok_size(s
, textent
.cx
+ 5,
205 SetRect(&rc
, 50,50,50,50);
206 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
207 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
209 memset(&s
, 0, sizeof(s
));
210 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
211 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
212 ok_size(s
, textent
.cx
+ 5 + 100,
213 textent
.cy
+ 7 + 100);
215 SetRect(&rc
, 1,1,1,1);
216 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
217 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
219 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
220 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n");
222 memset(&s
, 0, sizeof(s
));
223 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
224 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
225 ok_size(s
, textent
.cx
+ 5 + 2 + 1, /* we get an extra pixel due to the iml */
230 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
231 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
232 ok_size(s
, textent
.cx
+ 5 + 2 + 1,
237 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
238 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
239 ok_size(s
, textent
.cx
+ 5 + 2 + 1,
242 SetRect(&imlData
.margin
, 1,1,1,1);
243 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
244 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n");
246 memset(&s
, 0, sizeof(s
));
247 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
248 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
249 /* expected width = text width + hardcoded value + text margins + image width + image margins */
250 ok_size(s
, textent
.cx
+ 5 + 2 + 1 + 2,
253 SetRect(&imlData
.margin
, 50,50,50,50);
254 ret
= SendMessageW(hwnd1
, BCM_SETIMAGELIST
, 0, (LPARAM
)&imlData
);
255 ok (ret
== TRUE
, "Expected BCM_SETIMAGELIST to fail\n");
257 memset(&s
, 0, sizeof(s
));
258 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
259 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
260 /* image + its margins is so big that the height is dictated by them */
261 ok_size(s
, textent
.cx
+ 5 + 2 + 1 + 100, (LONG
)101);
263 DestroyWindow(hwnd1
);
270 hwnd1
= CreateWindowW(L
"Button", L
"Start", BS_VCENTER
, 0, 0, 0, 0, 0, NULL
, NULL
, NULL
);
271 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
272 SetWindowTheme(hwnd1
, L
"", L
"");
274 font
= (HFONT
)SendMessageW(hwnd1
, WM_GETFONT
, 0, 0);
276 SelectObject(hdc
, font
);
277 GetTextExtentPoint32W(hdc
, L
"Start", 5, &textent
);
279 SetRect(&rc
, 0,0,0,0);
280 ret
= SendMessageW(hwnd1
, BCM_SETTEXTMARGIN
, 0, (LPARAM
)&rc
);
281 ok (ret
== TRUE
, "Expected BCM_SETTEXTMARGIN to succeed\n");
283 memset(&s
, 0, sizeof(s
));
284 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
285 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
286 ok_size(s
, textent
.cx
+ 5, textent
.cy
+ 7);
288 DestroyWindow(hwnd1
);
293 /* Test again with some real text to see if the formula is correct */
294 hwnd1
= CreateWindowW(L
"Button", L
"Some test text", 0, 10, 10, 100, 100, 0, NULL
, NULL
, NULL
);
295 ok (hwnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
296 SetWindowTheme(hwnd1
, L
"", L
"");
298 font
= (HFONT
)SendMessageW(hwnd1
, WM_GETFONT
, 0, 0);
300 SelectObject(hdc
, font
);
301 GetTextExtentPoint32W(hdc
, L
"Some test text", 14, &textent
);
303 memset(&s
, 0, sizeof(s
));
304 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
305 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
306 ok_size(s
, textent
.cx
+ 5 + 2, /* the last +2 is the text margin */
309 /* The hardcoded values are independent of the margin */
312 lf
.lfWeight
= FW_BOLD
;
313 wcscpy(lf
.lfFaceName
, L
"Arial");
314 font
= CreateFontIndirectW(&lf
);
315 ok(font
!= NULL
, "\n");
316 SendMessageW(hwnd1
, WM_SETFONT
, (WPARAM
)font
, FALSE
);
318 SelectObject(hdc
, font
);
319 GetTextExtentPoint32W(hdc
, L
"Some test text", 14, &textent
);
321 memset(&s
, 0, sizeof(s
));
322 ret
= SendMessageW(hwnd1
, BCM_GETIDEALSIZE
, 0, (LPARAM
)&s
);
323 ok (ret
== TRUE
, "Expected BCM_GETIDEALSIZE to succeed\n");
324 ok_size(s
, textent
.cx
+ 5 + 2, /* the last +2 is the text margin */
327 DestroyWindow(hwnd1
);
336 LoadLibraryW(L
"comctl32.dll"); /* same as statically linking to comctl32 and doing InitCommonControls */
339 Test_GetIdealSizeNoThemes();