Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / user32 / tests / static.c
blob13955aa4cb7f2e616e05a5f44b419b486328bffb
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>
27 #include "wine/test.h"
29 #define TODO_COUNT 1
31 #define CTRL_ID 1995
33 static HWND hMainWnd;
35 #define expect_eq(expr, value, type, fmt) { type val = expr; ok(val == (value), #expr " expected " fmt " got " fmt "\n", (value), val); }
36 #define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
37 r.bottom == _bottom && r.right == _right, "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", \
38 r.left, r.top, r.right, r.bottom, _left, _top, _right, _bottom);
40 static int g_nReceivedColorStatic = 0;
42 /* try to make sure pending X events have been processed before continuing */
43 static void flush_events(void)
45 MSG msg;
46 int diff = 200;
47 int min_timeout = 100;
48 DWORD time = GetTickCount() + diff;
50 while (diff > 0)
52 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
53 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
54 diff = time - GetTickCount();
58 static HWND build_static(DWORD style)
60 return CreateWindow("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
63 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
65 switch (msg)
67 case WM_CTLCOLORSTATIC:
69 HDC hdc = (HDC)wparam;
70 HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
71 ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
72 DeleteObject(hrgn);
73 g_nReceivedColorStatic++;
74 return (LRESULT) GetStockObject(BLACK_BRUSH);
76 break;
79 return DefWindowProc(hwnd, msg, wparam, lparam);
82 static void test_updates(int style, int flags)
84 RECT r1 = {20, 20, 30, 30};
85 HWND hStatic = build_static(style);
86 int exp;
88 flush_events();
89 trace("Testing style 0x%x\n", style);
90 g_nReceivedColorStatic = 0;
91 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
92 InvalidateRect(hMainWnd, NULL, FALSE);
93 UpdateWindow(hMainWnd);
94 InvalidateRect(hMainWnd, &r1, FALSE);
95 UpdateWindow(hMainWnd);
96 InvalidateRect(hStatic, &r1, FALSE);
97 UpdateWindow(hStatic);
98 InvalidateRect(hStatic, NULL, FALSE);
99 UpdateWindow(hStatic);
101 if( (style & SS_TYPEMASK) == SS_BITMAP) {
102 HDC hdc = GetDC( hStatic);
103 COLORREF colour = GetPixel( hdc, 10, 10);
104 ok ( colour != 0, "pixel should NOT be painted black!\n");
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 { expect_eq(g_nReceivedColorStatic, exp, int, "%d"); }
113 else if ((style & SS_TYPEMASK) == SS_ICON || (style & SS_TYPEMASK) == SS_BITMAP)
114 ok( g_nReceivedColorStatic == exp, "expected %u got %u\n", exp, g_nReceivedColorStatic );
115 else
116 expect_eq(g_nReceivedColorStatic, exp, int, "%d");
117 DestroyWindow(hStatic);
120 START_TEST(static)
122 static char szClassName[] = "testclass";
123 WNDCLASSEX wndclass;
125 wndclass.cbSize = sizeof(wndclass);
126 wndclass.style = CS_HREDRAW | CS_VREDRAW;
127 wndclass.lpfnWndProc = WndProc;
128 wndclass.cbClsExtra = 0;
129 wndclass.cbWndExtra = 0;
130 wndclass.hInstance = GetModuleHandle(NULL);
131 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
132 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
133 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
134 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
135 wndclass.lpszClassName = szClassName;
136 wndclass.lpszMenuName = NULL;
137 RegisterClassEx(&wndclass);
139 hMainWnd = CreateWindow(szClassName, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, GetModuleHandle(NULL), NULL);
140 ShowWindow(hMainWnd, SW_SHOW);
142 test_updates(0, 0);
143 test_updates(SS_SIMPLE, 0);
144 test_updates(SS_ICON, 0);
145 test_updates(SS_BITMAP, 0);
146 test_updates(SS_BITMAP | SS_CENTERIMAGE, 0);
147 test_updates(SS_BLACKRECT, TODO_COUNT);
148 test_updates(SS_WHITERECT, TODO_COUNT);
149 test_updates(SS_ETCHEDHORZ, TODO_COUNT);
150 test_updates(SS_ETCHEDVERT, TODO_COUNT);
152 DestroyWindow(hMainWnd);