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
25 #define WIN32_LEAN_AND_MEAN
28 #include "wine/test.h"
36 #define expect_eq(expr, value, type, fmt) { type val = expr; ok(val == (value), #expr " expected " fmt " got " fmt "\n", (value), val); }
37 #define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
38 r.bottom == _bottom && r.right == _right, "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", \
39 r.left, r.top, r.right, r.bottom, _left, _top, _right, _bottom);
41 static int g_nReceivedColorStatic = 0;
43 static HWND build_static(DWORD style)
45 return CreateWindow("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
48 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
52 case WM_CTLCOLORSTATIC:
54 HDC hdc = (HDC)wparam;
55 HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
56 ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
58 g_nReceivedColorStatic++;
63 return DefWindowProc(hwnd, msg, wparam, lparam);
66 static void test_updates(int style, int flags)
68 RECT r1 = {20, 20, 30, 30};
69 HWND hStatic = build_static(style);
72 trace("Testing style 0x%x\n", style);
73 g_nReceivedColorStatic = 0;
74 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
75 InvalidateRect(hMainWnd, NULL, FALSE);
76 UpdateWindow(hMainWnd);
77 InvalidateRect(hMainWnd, &r1, FALSE);
78 UpdateWindow(hMainWnd);
79 InvalidateRect(hStatic, &r1, FALSE);
80 UpdateWindow(hStatic);
81 InvalidateRect(hStatic, NULL, FALSE);
82 UpdateWindow(hStatic);
85 if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
88 exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
90 if (flags & TODO_COUNT)
91 todo_wine { expect_eq(g_nReceivedColorStatic, exp, int, "%d"); }
92 else if (style == SS_ICON || style == SS_BITMAP)
93 ok( g_nReceivedColorStatic == exp ||
94 broken(g_nReceivedColorStatic == 0), /* win9x */
95 "expected %u got %u\n", exp, g_nReceivedColorStatic );
97 expect_eq(g_nReceivedColorStatic, exp, int, "%d");
98 DestroyWindow(hStatic);
103 static char szClassName[] = "testclass";
106 wndclass.cbSize = sizeof(wndclass);
107 wndclass.style = CS_HREDRAW | CS_VREDRAW;
108 wndclass.lpfnWndProc = WndProc;
109 wndclass.cbClsExtra = 0;
110 wndclass.cbWndExtra = 0;
111 wndclass.hInstance = GetModuleHandle(NULL);
112 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
113 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
114 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
115 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
116 wndclass.lpszClassName = szClassName;
117 wndclass.lpszMenuName = NULL;
118 RegisterClassEx(&wndclass);
120 hMainWnd = CreateWindow(szClassName, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, GetModuleHandle(NULL), NULL);
121 ShowWindow(hMainWnd, SW_SHOW);
122 UpdateWindow(hMainWnd);
125 test_updates(SS_SIMPLE, 0);
126 test_updates(SS_ICON, 0);
127 test_updates(SS_BITMAP, 0);
128 test_updates(SS_BLACKRECT, TODO_COUNT);
129 test_updates(SS_WHITERECT, TODO_COUNT);
130 test_updates(SS_ETCHEDHORZ, TODO_COUNT);
131 test_updates(SS_ETCHEDVERT, TODO_COUNT);
133 DestroyWindow(hMainWnd);