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
24 #define WIN32_LEAN_AND_MEAN
27 #include "wine/test.h"
35 #define expect_eq(expr, value, type, fmt) { type val = expr; ok(val == (value), #expr " expected " fmt " got " fmt "\n", (value), val); }
37 static int g_nReceivedColorStatic
= 0;
39 /* try to make sure pending X events have been processed before continuing */
40 static void flush_events(void)
44 int min_timeout
= 100;
45 DWORD time
= GetTickCount() + diff
;
49 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
50 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
51 diff
= time
- GetTickCount();
55 static HWND
build_static(DWORD style
)
57 return CreateWindowA("static", "Test", WS_VISIBLE
|WS_CHILD
|style
, 5, 5, 100, 100, hMainWnd
, (HMENU
)CTRL_ID
, NULL
, 0);
60 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
64 case WM_CTLCOLORSTATIC
:
66 HDC hdc
= (HDC
)wparam
;
67 HRGN hrgn
= CreateRectRgn(0, 0, 1, 1);
68 ok(GetClipRgn(hdc
, hrgn
) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
70 g_nReceivedColorStatic
++;
71 return (LRESULT
) GetStockObject(BLACK_BRUSH
);
76 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
79 static void test_updates(int style
, int flags
)
81 RECT r1
= {20, 20, 30, 30};
82 HWND hStatic
= build_static(style
);
86 trace("Testing style 0x%x\n", style
);
87 g_nReceivedColorStatic
= 0;
88 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
89 InvalidateRect(hMainWnd
, NULL
, FALSE
);
90 UpdateWindow(hMainWnd
);
91 InvalidateRect(hMainWnd
, &r1
, FALSE
);
92 UpdateWindow(hMainWnd
);
93 InvalidateRect(hStatic
, &r1
, FALSE
);
94 UpdateWindow(hStatic
);
95 InvalidateRect(hStatic
, NULL
, FALSE
);
96 UpdateWindow(hStatic
);
98 if( (style
& SS_TYPEMASK
) == SS_BITMAP
) {
99 HDC hdc
= GetDC( hStatic
);
100 COLORREF colour
= GetPixel( hdc
, 10, 10);
101 ok ( colour
!= 0, "pixel should NOT be painted black!\n");
102 ReleaseDC(hStatic
, hdc
);
104 if (style
!= SS_ETCHEDHORZ
&& style
!= SS_ETCHEDVERT
)
107 exp
= 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
109 if (flags
& TODO_COUNT
)
110 todo_wine
{ expect_eq(g_nReceivedColorStatic
, exp
, int, "%d"); }
111 else if ((style
& SS_TYPEMASK
) == SS_ICON
|| (style
& SS_TYPEMASK
) == SS_BITMAP
)
112 ok( g_nReceivedColorStatic
== exp
, "expected %u got %u\n", exp
, g_nReceivedColorStatic
);
114 expect_eq(g_nReceivedColorStatic
, exp
, int, "%d");
115 DestroyWindow(hStatic
);
118 static void test_set_text(void)
120 HWND hStatic
= build_static(SS_SIMPLE
);
123 GetWindowTextA(hStatic
, buffA
, sizeof(buffA
));
124 ok(!strcmp(buffA
, "Test"), "got wrong text %s\n", buffA
);
126 SetWindowTextA(hStatic
, NULL
);
127 GetWindowTextA(hStatic
, buffA
, sizeof(buffA
));
128 ok(buffA
[0] == 0, "got wrong text %s\n", buffA
);
130 DestroyWindow(hStatic
);
133 static void test_image(HBITMAP image
)
140 GetObjectW(image
, sizeof(bm
), &bm
);
141 ok(bm
.bmWidth
== 1, "got %d\n", bm
.bmWidth
);
142 ok(bm
.bmHeight
== 1, "got %d\n", bm
.bmHeight
);
143 ok(bm
.bmBitsPixel
== 32, "got %d\n", bm
.bmBitsPixel
);
144 ok(bm
.bmBits
== NULL
, "bmBits is not NULL\n");
146 info
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
147 info
.bmiHeader
.biWidth
= bm
.bmWidth
;
148 info
.bmiHeader
.biHeight
= bm
.bmHeight
;
149 info
.bmiHeader
.biPlanes
= 1;
150 info
.bmiHeader
.biBitCount
= 32;
151 info
.bmiHeader
.biCompression
= BI_RGB
;
152 info
.bmiHeader
.biSizeImage
= 4;
153 info
.bmiHeader
.biXPelsPerMeter
= 0;
154 info
.bmiHeader
.biYPelsPerMeter
= 0;
155 info
.bmiHeader
.biClrUsed
= 0;
156 info
.bmiHeader
.biClrImportant
= 0;
158 hdc
= CreateCompatibleDC(0);
159 GetDIBits(hdc
, image
, 0, bm
.bmHeight
, bits
, &info
, DIB_RGB_COLORS
);
162 ok(bits
[0] == 0x11 && bits
[1] == 0x22 && bits
[2] == 0x33 && bits
[3] == 0x44,
163 "bits: %02x %02x %02x %02x\n", bits
[0], bits
[1], bits
[2], bits
[3]);
166 static void test_set_image(void)
168 HWND hwnd
= build_static(SS_BITMAP
);
171 image
= LoadImageW(GetModuleHandleW(NULL
), MAKEINTRESOURCEW(101), IMAGE_BITMAP
, 0, 0, 0);
172 ok(image
!= NULL
, "LoadImage failed\n");
176 bmp
= (HBITMAP
)SendMessageW(hwnd
, STM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
)image
);
177 ok(bmp
== NULL
, "got not NULL\n");
179 bmp
= (HBITMAP
)SendMessageW(hwnd
, STM_GETIMAGE
, IMAGE_BITMAP
, 0);
180 ok(bmp
!= NULL
, "got NULL\n");
181 ok(bmp
== image
, "bmp != image\n");
183 bmp
= (HBITMAP
)SendMessageW(hwnd
, STM_SETIMAGE
, IMAGE_BITMAP
, (LPARAM
)image
);
184 ok(bmp
!= NULL
, "got NULL\n");
185 ok(bmp
== image
, "bmp != image\n");
194 static const char szClassName
[] = "testclass";
195 WNDCLASSEXA wndclass
;
197 wndclass
.cbSize
= sizeof(wndclass
);
198 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
199 wndclass
.lpfnWndProc
= WndProc
;
200 wndclass
.cbClsExtra
= 0;
201 wndclass
.cbWndExtra
= 0;
202 wndclass
.hInstance
= GetModuleHandleA(NULL
);
203 wndclass
.hIcon
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
204 wndclass
.hIconSm
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
205 wndclass
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
206 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
207 wndclass
.lpszClassName
= szClassName
;
208 wndclass
.lpszMenuName
= NULL
;
209 RegisterClassExA(&wndclass
);
211 hMainWnd
= CreateWindowA(szClassName
, "Test", WS_OVERLAPPEDWINDOW
, 0, 0, 500, 500, NULL
, NULL
, GetModuleHandleA(NULL
), NULL
);
212 ShowWindow(hMainWnd
, SW_SHOW
);
215 test_updates(SS_SIMPLE
, 0);
216 test_updates(SS_ICON
, 0);
217 test_updates(SS_BITMAP
, 0);
218 test_updates(SS_BITMAP
| SS_CENTERIMAGE
, 0);
219 test_updates(SS_BLACKRECT
, TODO_COUNT
);
220 test_updates(SS_WHITERECT
, TODO_COUNT
);
221 test_updates(SS_ETCHEDHORZ
, TODO_COUNT
);
222 test_updates(SS_ETCHEDVERT
, TODO_COUNT
);
226 DestroyWindow(hMainWnd
);