comctl32/tests: Avoid a structure initialization warning.
[wine.git] / dlls / comctl32 / tests / static.c
bloba65e35272821f21e7589e0d6a56b495f94c43235
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 #define STRICT
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #include "commctrl.h"
28 #include "wine/test.h"
30 #include "v6util.h"
32 #define TODO_COUNT 1
34 #define CTRL_ID 1995
36 static HWND hMainWnd;
37 static int g_nReceivedColorStatic;
39 /* try to make sure pending X events have been processed before continuing */
40 static void flush_events(void)
42 MSG msg;
43 int diff = 200;
44 int min_timeout = 100;
45 DWORD time = GetTickCount() + diff;
47 while (diff > 0)
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 create_static(DWORD style)
57 return CreateWindowA(WC_STATICA, "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)
62 switch (msg)
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");
69 DeleteObject(hrgn);
70 g_nReceivedColorStatic++;
71 return (LRESULT) GetStockObject(BLACK_BRUSH);
73 break;
76 return DefWindowProcA(hwnd, msg, wparam, lparam);
79 static void test_updates(int style, int flags)
81 HWND hStatic = create_static(style);
82 RECT r1 = {20, 20, 30, 30};
83 int exp;
85 flush_events();
86 g_nReceivedColorStatic = 0;
87 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
88 InvalidateRect(hMainWnd, NULL, FALSE);
89 UpdateWindow(hMainWnd);
90 InvalidateRect(hMainWnd, &r1, FALSE);
91 UpdateWindow(hMainWnd);
92 InvalidateRect(hStatic, &r1, FALSE);
93 UpdateWindow(hStatic);
94 InvalidateRect(hStatic, NULL, FALSE);
95 UpdateWindow(hStatic);
97 if ((style & SS_TYPEMASK) == SS_BITMAP)
99 HDC hdc = GetDC(hStatic);
100 COLORREF colour = GetPixel(hdc, 10, 10);
101 todo_wine
102 ok(colour == 0, "Unexpected pixel color.\n");
103 ReleaseDC(hStatic, hdc);
106 if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
107 exp = 4;
108 else
109 exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
111 if (flags & TODO_COUNT)
112 todo_wine
113 ok(g_nReceivedColorStatic == exp, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
114 else if ((style & SS_TYPEMASK) == SS_ICON || (style & SS_TYPEMASK) == SS_BITMAP)
115 ok(g_nReceivedColorStatic == exp, "Unexpected %u got %u\n", exp, g_nReceivedColorStatic);
116 else
117 ok(g_nReceivedColorStatic == exp, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
118 DestroyWindow(hStatic);
121 static void test_set_text(void)
123 HWND hStatic = create_static(SS_SIMPLE);
124 char buffA[10];
126 GetWindowTextA(hStatic, buffA, sizeof(buffA));
127 ok(!strcmp(buffA, "Test"), "got wrong text %s\n", buffA);
129 SetWindowTextA(hStatic, NULL);
130 GetWindowTextA(hStatic, buffA, sizeof(buffA));
131 ok(buffA[0] == 0, "got wrong text %s\n", buffA);
133 DestroyWindow(hStatic);
136 START_TEST(static)
138 static const char classname[] = "testclass";
139 WNDCLASSEXA wndclass;
140 ULONG_PTR ctx_cookie;
141 HANDLE hCtx;
143 if (!load_v6_module(&ctx_cookie, &hCtx))
144 return;
146 wndclass.cbSize = sizeof(wndclass);
147 wndclass.style = CS_HREDRAW | CS_VREDRAW;
148 wndclass.lpfnWndProc = WndProc;
149 wndclass.cbClsExtra = 0;
150 wndclass.cbWndExtra = 0;
151 wndclass.hInstance = GetModuleHandleA(NULL);
152 wndclass.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
153 wndclass.hIconSm = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
154 wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
155 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
156 wndclass.lpszClassName = classname;
157 wndclass.lpszMenuName = NULL;
158 RegisterClassExA(&wndclass);
160 hMainWnd = CreateWindowA(classname, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL,
161 GetModuleHandleA(NULL), NULL);
162 ShowWindow(hMainWnd, SW_SHOW);
164 test_updates(0, 0);
165 test_updates(SS_SIMPLE, 0);
166 test_updates(SS_ICON, 0);
167 test_updates(SS_BITMAP, 0);
168 test_updates(SS_BITMAP | SS_CENTERIMAGE, 0);
169 test_updates(SS_BLACKRECT, TODO_COUNT);
170 test_updates(SS_WHITERECT, TODO_COUNT);
171 test_updates(SS_ETCHEDHORZ, TODO_COUNT);
172 test_updates(SS_ETCHEDVERT, TODO_COUNT);
173 test_set_text();
175 DestroyWindow(hMainWnd);
177 unload_v6_module(ctx_cookie, hCtx);