user32: Static controls should have a clipping region set while sending the WM_CTLCOL...
[wine] / dlls / user32 / tests / static.c
1 /* Unit test suite for static controls.
2  *
3  * Copyright 2007 Google (Mikolaj Zalewski)
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <assert.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define STRICT
25 #define WIN32_LEAN_AND_MEAN
26 #include <windows.h>
27
28 #include "wine/test.h"
29
30 #define TODO_COUNT 1
31
32 #define CTRL_ID 1995
33
34 static HWND hMainWnd;
35
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);
40
41 int g_nReceivedColorStatic = 0;
42
43 static HWND build_static(DWORD style)
44 {
45     return CreateWindow("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
46 }
47
48 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
49 {
50     switch (msg)
51     {
52     case WM_CTLCOLORSTATIC:
53         {
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");
57             DeleteObject(hrgn);
58             g_nReceivedColorStatic++;
59         }
60         break;
61     }
62
63     return DefWindowProc(hwnd, msg, wparam, lparam);
64 }
65
66 void test_updates(int style, int flags)
67 {
68     RECT r1 = {20, 20, 30, 30};
69     HWND hStatic = build_static(style);
70     int exp;
71
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);
83
84
85     if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
86         exp = 4;
87     else
88         exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
89
90     if (flags & TODO_COUNT)
91         todo_wine { expect_eq(g_nReceivedColorStatic, exp, int, "%d"); }
92     else
93         expect_eq(g_nReceivedColorStatic, exp, int, "%d");
94     DestroyWindow(hStatic);
95 }
96
97 START_TEST(static)
98 {
99     static char szClassName[] = "testclass";
100     WNDCLASSEX  wndclass;
101
102     wndclass.cbSize         = sizeof(wndclass);
103     wndclass.style          = CS_HREDRAW | CS_VREDRAW;
104     wndclass.lpfnWndProc    = WndProc;
105     wndclass.cbClsExtra     = 0;
106     wndclass.cbWndExtra     = 0;
107     wndclass.hInstance      = GetModuleHandle(NULL);
108     wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
109     wndclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
110     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
111     wndclass.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
112     wndclass.lpszClassName  = szClassName;
113     wndclass.lpszMenuName   = NULL;
114     RegisterClassEx(&wndclass);
115
116     hMainWnd = CreateWindow(szClassName, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, GetModuleHandle(NULL), NULL);
117     ShowWindow(hMainWnd, SW_SHOW);
118     UpdateWindow(hMainWnd);
119
120     test_updates(0, 0);
121     test_updates(SS_SIMPLE, 0);
122     test_updates(SS_ICON, 0);
123     test_updates(SS_BITMAP, 0);
124     test_updates(SS_BLACKRECT, TODO_COUNT);
125     test_updates(SS_WHITERECT, TODO_COUNT);
126     test_updates(SS_ETCHEDHORZ, TODO_COUNT);
127     test_updates(SS_ETCHEDVERT, TODO_COUNT);
128
129     DestroyWindow(hMainWnd);
130 }