opengl32: Correctly interpret glMapBuffer() access in wow64 mapping.
[wine.git] / dlls / comctl32 / tests / static.c
blob551aca2720fce04e2db5a818f26c8b51371f7e18
1 /* Unit test suite for static controls.
3 * Copyright 2007 Google (Mikolaj Zalewski)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
21 #include <stdio.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #define OEMRESOURCE
27 #include "winuser.h"
28 #include "commctrl.h"
29 #include "resources.h"
31 #include "wine/test.h"
33 #include "v6util.h"
35 #define CTRL_ID 1995
37 static HWND hMainWnd;
38 static int g_nReceivedColorStatic;
40 /* try to make sure pending X events have been processed before continuing */
41 static void flush_events(void)
43 MSG msg;
44 int diff = 200;
45 int min_timeout = 100;
46 DWORD time = GetTickCount() + diff;
48 while (diff > 0)
50 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
51 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
52 diff = time - GetTickCount();
56 static HWND create_static(DWORD style)
58 return CreateWindowA(WC_STATICA, "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
61 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
63 switch (msg)
65 case WM_CTLCOLORSTATIC:
67 HDC hdc = (HDC)wparam;
68 HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
69 ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
70 DeleteObject(hrgn);
71 g_nReceivedColorStatic++;
72 return (LRESULT) GetStockObject(BLACK_BRUSH);
74 break;
77 return DefWindowProcA(hwnd, msg, wparam, lparam);
80 static void test_updates(int style)
82 HWND hStatic = create_static(style);
83 RECT r1 = {5, 5, 30, 30}, rcClient;
84 int exp;
85 LONG exstyle;
87 flush_events();
88 trace("Testing style 0x%x\n", style);
90 exstyle = GetWindowLongW(hStatic, GWL_EXSTYLE);
91 if (style == SS_ETCHEDHORZ || style == SS_ETCHEDVERT || style == SS_SUNKEN)
92 ok(exstyle == WS_EX_STATICEDGE, "expected WS_EX_STATICEDGE, got %ld\n", exstyle);
93 else
94 ok(exstyle == 0, "expected 0, got %ld\n", exstyle);
96 GetClientRect(hStatic, &rcClient);
97 if (style == SS_ETCHEDVERT)
98 ok(rcClient.right == 0, "expected zero width, got %ld\n", rcClient.right);
99 else
100 ok(rcClient.right > 0, "expected non-zero width, got %ld\n", rcClient.right);
101 if (style == SS_ETCHEDHORZ)
102 ok(rcClient.bottom == 0, "expected zero height, got %ld\n", rcClient.bottom);
103 else
104 ok(rcClient.bottom > 0, "expected non-zero height, got %ld\n", rcClient.bottom);
106 g_nReceivedColorStatic = 0;
107 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
108 InvalidateRect(hMainWnd, NULL, FALSE);
109 UpdateWindow(hMainWnd);
110 InvalidateRect(hMainWnd, &r1, FALSE);
111 UpdateWindow(hMainWnd);
112 InvalidateRect(hStatic, &r1, FALSE);
113 UpdateWindow(hStatic);
114 InvalidateRect(hStatic, NULL, FALSE);
115 UpdateWindow(hStatic);
117 if ((style & SS_TYPEMASK) == SS_BITMAP)
119 HDC hdc = GetDC(hStatic);
120 COLORREF colour = GetPixel(hdc, 10, 10);
121 ok(colour == 0, "Unexpected pixel color.\n");
122 ReleaseDC(hStatic, hdc);
125 if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
126 exp = 4;
127 else
128 exp = 2; /* SS_ETCHEDHORZ/SS_ETCHEDVERT have empty client rect so WM_CTLCOLORSTATIC is sent only when parent window is invalidated */
130 ok(g_nReceivedColorStatic == exp, "expected %u, got %u\n", exp, g_nReceivedColorStatic);
131 DestroyWindow(hStatic);
134 static void test_set_text(void)
136 HWND hStatic = create_static(SS_SIMPLE);
137 char buffA[10];
139 GetWindowTextA(hStatic, buffA, sizeof(buffA));
140 ok(!strcmp(buffA, "Test"), "got wrong text %s\n", buffA);
142 SetWindowTextA(hStatic, NULL);
143 GetWindowTextA(hStatic, buffA, sizeof(buffA));
144 ok(buffA[0] == 0, "got wrong text %s\n", buffA);
146 DestroyWindow(hStatic);
149 static void remove_alpha(HBITMAP hbitmap)
151 BITMAP bm;
152 BYTE *ptr;
153 int i;
155 GetObjectW(hbitmap, sizeof(bm), &bm);
156 ok(bm.bmBits != NULL, "bmBits is NULL\n");
158 for (i = 0, ptr = bm.bmBits; i < bm.bmWidth * bm.bmHeight; i++, ptr += 4)
159 ptr[3] = 0;
162 static void test_image(HBITMAP image, BOOL is_dib, BOOL is_premult, BOOL is_alpha)
164 BITMAP bm;
165 HDC hdc;
166 BITMAPINFO info;
167 BYTE bits[4];
169 GetObjectW(image, sizeof(bm), &bm);
170 ok(bm.bmWidth == 1, "got %d\n", bm.bmWidth);
171 ok(bm.bmHeight == 1, "got %d\n", bm.bmHeight);
172 ok(bm.bmBitsPixel == 32, "got %d\n", bm.bmBitsPixel);
173 if (is_dib)
175 ok(bm.bmBits != NULL, "bmBits is NULL\n");
176 memcpy(bits, bm.bmBits, 4);
177 if (is_premult)
178 ok(bits[0] == 0x05 && bits[1] == 0x09 && bits[2] == 0x0e && bits[3] == 0x44,
179 "bits: %02x %02x %02x %02x\n", bits[0], bits[1], bits[2], bits[3]);
180 else if (is_alpha)
181 ok(bits[0] == 0x11 && bits[1] == 0x22 && bits[2] == 0x33 && bits[3] == 0x44,
182 "bits: %02x %02x %02x %02x\n", bits[0], bits[1], bits[2], bits[3]);
183 else
184 ok(bits[0] == 0x11 && bits[1] == 0x22 && bits[2] == 0x33 && bits[3] == 0,
185 "bits: %02x %02x %02x %02x\n", bits[0], bits[1], bits[2], bits[3]);
187 else
188 ok(bm.bmBits == NULL, "bmBits is not NULL\n");
190 info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
191 info.bmiHeader.biWidth = bm.bmWidth;
192 info.bmiHeader.biHeight = bm.bmHeight;
193 info.bmiHeader.biPlanes = 1;
194 info.bmiHeader.biBitCount = 32;
195 info.bmiHeader.biCompression = BI_RGB;
196 info.bmiHeader.biSizeImage = 4;
197 info.bmiHeader.biXPelsPerMeter = 0;
198 info.bmiHeader.biYPelsPerMeter = 0;
199 info.bmiHeader.biClrUsed = 0;
200 info.bmiHeader.biClrImportant = 0;
202 hdc = CreateCompatibleDC(0);
203 GetDIBits(hdc, image, 0, bm.bmHeight, bits, &info, DIB_RGB_COLORS);
204 DeleteDC(hdc);
206 if (is_premult)
207 ok(bits[0] == 0x05 && bits[1] == 0x09 && bits[2] == 0x0e && bits[3] == 0x44,
208 "bits: %02x %02x %02x %02x\n", bits[0], bits[1], bits[2], bits[3]);
209 else if (is_alpha)
210 ok(bits[0] == 0x11 && bits[1] == 0x22 && bits[2] == 0x33 && bits[3] == 0x44,
211 "bits: %02x %02x %02x %02x\n", bits[0], bits[1], bits[2], bits[3]);
212 else
213 ok(bits[0] == 0x11 && bits[1] == 0x22 && bits[2] == 0x33 && bits[3] == 0,
214 "bits: %02x %02x %02x %02x\n", bits[0], bits[1], bits[2], bits[3]);
217 static void test_set_image(void)
219 char resource[4];
220 WCHAR resource_unicode[3];
221 HWND hwnd = create_static(SS_BITMAP);
222 HBITMAP bmp1, bmp2, image;
224 image = LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP), IMAGE_BITMAP, 0, 0, 0);
225 ok(image != NULL, "LoadImage failed\n");
227 test_image(image, FALSE, FALSE, TRUE);
229 bmp1 = (HBITMAP)SendMessageW(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0);
230 ok(bmp1 == NULL, "got not NULL\n");
232 bmp1 = (HBITMAP)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)image);
233 ok(bmp1 == NULL, "got not NULL\n");
235 bmp1 = (HBITMAP)SendMessageW(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0);
236 ok(bmp1 != NULL, "got NULL\n");
237 ok(bmp1 != image, "bmp == image\n");
238 test_image(bmp1, TRUE, TRUE, TRUE);
240 bmp2 = (HBITMAP)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)image);
241 ok(bmp2 != NULL, "got NULL\n");
242 ok(bmp2 != image, "bmp == image\n");
243 ok(bmp1 == bmp2, "bmp1 != bmp2\n");
244 test_image(bmp2, TRUE, TRUE, TRUE);
246 DeleteObject(image);
248 image = LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
249 ok(image != NULL, "LoadImage failed\n");
251 test_image(image, TRUE, FALSE, TRUE);
252 remove_alpha(image);
253 test_image(image, TRUE, FALSE, FALSE);
255 bmp1 = (HBITMAP)SendMessageW(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0);
256 ok(bmp1 != NULL, "got NULL\n");
257 ok(bmp1 != image, "bmp == image\n");
258 test_image(bmp1, TRUE, TRUE, TRUE);
260 bmp2 = (HBITMAP)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)image);
261 ok(bmp2 != NULL, "got NULL\n");
262 ok(bmp2 != image, "bmp == image\n");
263 ok(bmp1 == bmp2, "bmp1 != bmp2\n");
264 test_image(bmp1, TRUE, TRUE, FALSE);
266 bmp2 = (HBITMAP)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)image);
267 ok(bmp2 != NULL, "got NULL\n");
268 ok(bmp2 == image, "bmp1 != image\n");
269 test_image(bmp2, TRUE, FALSE, FALSE);
271 DestroyWindow(hwnd);
273 test_image(image, TRUE, FALSE, FALSE);
275 resource[0] = '\xff';
276 resource[1] = PtrToUlong(MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP));
277 resource[2] = PtrToUlong(MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP)) >> 8;
278 resource[3] = 0;
280 resource_unicode[0] = 0xffff;
281 resource_unicode[1] = PtrToUlong(MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP));
282 resource_unicode[2] = 0;
284 hwnd = CreateWindowW(L"Static", resource_unicode, WS_VISIBLE|WS_CHILD|SS_BITMAP, 5, 5, 100, 100,
285 hMainWnd, (HMENU)CTRL_ID, GetModuleHandleW(NULL), 0);
287 bmp1 = (HBITMAP)SendMessageW(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0);
288 ok(bmp1 != NULL, "got NULL\n");
289 ok(bmp1 != image, "bmp == image\n");
290 test_image(bmp1, TRUE, TRUE, TRUE);
291 DestroyWindow(hwnd);
293 hwnd = CreateWindowA("Static", resource, WS_VISIBLE|WS_CHILD|SS_BITMAP, 5, 5, 100, 100,
294 hMainWnd, (HMENU)CTRL_ID, GetModuleHandleW(NULL), 0);
296 bmp1 = (HBITMAP)SendMessageA(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0);
297 ok(bmp1 != NULL, "got NULL\n");
298 ok(bmp1 != image, "bmp == image\n");
299 test_image(bmp1, TRUE, TRUE, TRUE);
300 DestroyWindow(hwnd);
302 DeleteObject(image);
305 static void test_STM_SETIMAGE(void)
307 DWORD type;
308 HWND hwnd;
309 HICON icon, old_image;
310 HBITMAP bmp;
311 HENHMETAFILE emf;
312 HDC dc;
314 icon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
315 bmp = LoadBitmapW(0, (LPCWSTR)OBM_CLOSE);
316 dc = CreateEnhMetaFileW(0, NULL, NULL, NULL);
317 LineTo(dc, 1, 1);
318 emf = CloseEnhMetaFile(dc);
319 DeleteDC(dc);
321 for (type = SS_LEFT; type < SS_ETCHEDFRAME; type++)
323 winetest_push_context("%lu", type);
325 hwnd = create_static(type);
326 ok(hwnd != 0, "failed to create static type %#lx\n", type);
328 /* set icon */
329 g_nReceivedColorStatic = 0;
330 old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
331 ok(!old_image, "got %p\n", old_image);
332 if (type == SS_ICON)
333 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
334 else
335 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
337 g_nReceivedColorStatic = 0;
338 old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
339 if (type == SS_ICON)
341 ok(old_image != 0, "got %p\n", old_image);
342 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
344 else
346 ok(!old_image, "got %p\n", old_image);
347 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
350 g_nReceivedColorStatic = 0;
351 old_image = (HICON)SendMessageW(hwnd, STM_SETICON, (WPARAM)icon, 0);
352 if (type == SS_ICON)
354 ok(old_image != 0, "got %p\n", old_image);
355 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
357 else
359 ok(!old_image, "got %p\n", old_image);
360 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
363 /* set bitmap */
364 g_nReceivedColorStatic = 0;
365 old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
366 ok(!old_image, "got %p\n", old_image);
367 if (type == SS_BITMAP)
368 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
369 else
370 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
372 g_nReceivedColorStatic = 0;
373 old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
374 if (type == SS_BITMAP)
376 ok(old_image != 0, "got %p\n", old_image);
377 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
379 else
381 ok(!old_image, "got %p\n", old_image);
382 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
385 /* set EMF */
386 g_nReceivedColorStatic = 0;
387 old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)emf);
388 ok(!old_image, "got %p\n", old_image);
389 if (type == SS_ENHMETAFILE)
390 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
391 else
392 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
394 g_nReceivedColorStatic = 0;
395 old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)emf);
396 if (type == SS_ENHMETAFILE)
398 ok(old_image != 0, "got %p\n", old_image);
399 ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
401 else
403 ok(!old_image, "got %p\n", old_image);
404 ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
407 DestroyWindow(hwnd);
409 winetest_pop_context();
412 DestroyIcon(icon);
413 DeleteObject(bmp);
414 DeleteEnhMetaFile(emf);
417 START_TEST(static)
419 static const char classname[] = "testclass";
420 WNDCLASSEXA wndclass;
421 ULONG_PTR ctx_cookie;
422 HANDLE hCtx;
424 if (!load_v6_module(&ctx_cookie, &hCtx))
425 return;
427 wndclass.cbSize = sizeof(wndclass);
428 wndclass.style = CS_HREDRAW | CS_VREDRAW;
429 wndclass.lpfnWndProc = WndProc;
430 wndclass.cbClsExtra = 0;
431 wndclass.cbWndExtra = 0;
432 wndclass.hInstance = GetModuleHandleA(NULL);
433 wndclass.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
434 wndclass.hIconSm = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
435 wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
436 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
437 wndclass.lpszClassName = classname;
438 wndclass.lpszMenuName = NULL;
439 RegisterClassExA(&wndclass);
441 hMainWnd = CreateWindowA(classname, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL,
442 GetModuleHandleA(NULL), NULL);
443 ShowWindow(hMainWnd, SW_SHOW);
445 test_updates(0);
446 test_updates(SS_ICON);
447 test_updates(SS_BLACKRECT);
448 test_updates(SS_WHITERECT);
449 test_updates(SS_BLACKFRAME);
450 test_updates(SS_WHITEFRAME);
451 test_updates(SS_USERITEM);
452 test_updates(SS_SIMPLE);
453 test_updates(SS_OWNERDRAW);
454 test_updates(SS_BITMAP);
455 test_updates(SS_BITMAP | SS_CENTERIMAGE);
456 test_updates(SS_ETCHEDHORZ);
457 test_updates(SS_ETCHEDVERT);
458 test_updates(SS_ETCHEDFRAME);
459 test_updates(SS_SUNKEN);
460 test_set_text();
461 test_set_image();
462 test_STM_SETIMAGE();
464 DestroyWindow(hMainWnd);
466 unload_v6_module(ctx_cookie, hCtx);