ReactOS  0.4.14-dev-599-g2d4d3f5
static.c
Go to the documentation of this file.
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 <stdarg.h>
21 #include <stdio.h>
22 
23 #ifndef __REACTOS__
24 #define STRICT
25 #endif
26 #define WIN32_LEAN_AND_MEAN
27 #include <windows.h>
28 #include "commctrl.h"
29 
30 #include "wine/test.h"
31 
32 #include "v6util.h"
33 
34 #define TODO_COUNT 1
35 
36 #define CTRL_ID 1995
37 
38 static HWND hMainWnd;
40 
41 /* try to make sure pending X events have been processed before continuing */
42 static void flush_events(void)
43 {
44  MSG msg;
45  int diff = 200;
46  int min_timeout = 100;
47  DWORD time = GetTickCount() + diff;
48 
49  while (diff > 0)
50  {
51  if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
52  while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
53  diff = time - GetTickCount();
54  }
55 }
56 
58 {
59  return CreateWindowA(WC_STATICA, "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
60 }
61 
63 {
64  switch (msg)
65  {
66  case WM_CTLCOLORSTATIC:
67  {
68  HDC hdc = (HDC)wparam;
69  HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
70  ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
74  }
75  break;
76  }
77 
78  return DefWindowProcA(hwnd, msg, wparam, lparam);
79 }
80 
81 static void test_updates(int style, int flags)
82 {
83  HWND hStatic = create_static(style);
84  RECT r1 = {20, 20, 30, 30};
85  int exp;
86 
87  flush_events();
89  /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
94  InvalidateRect(hStatic, &r1, FALSE);
95  UpdateWindow(hStatic);
96  InvalidateRect(hStatic, NULL, FALSE);
97  UpdateWindow(hStatic);
98 
99  if ((style & SS_TYPEMASK) == SS_BITMAP)
100  {
101  HDC hdc = GetDC(hStatic);
102  COLORREF colour = GetPixel(hdc, 10, 10);
103  todo_wine
104  ok(colour == 0, "Unexpected pixel color.\n");
105  ReleaseDC(hStatic, hdc);
106  }
107 
108  if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
109  exp = 4;
110  else
111  exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
112 
113  if (flags & TODO_COUNT)
114  todo_wine
115  ok(g_nReceivedColorStatic == exp, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
116  else if ((style & SS_TYPEMASK) == SS_ICON || (style & SS_TYPEMASK) == SS_BITMAP)
117  ok(g_nReceivedColorStatic == exp, "Unexpected %u got %u\n", exp, g_nReceivedColorStatic);
118  else
119  ok(g_nReceivedColorStatic == exp, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
120  DestroyWindow(hStatic);
121 }
122 
123 static void test_set_text(void)
124 {
125  HWND hStatic = create_static(SS_SIMPLE);
126  char buffA[10];
127 
128  GetWindowTextA(hStatic, buffA, sizeof(buffA));
129  ok(!strcmp(buffA, "Test"), "got wrong text %s\n", buffA);
130 
131  SetWindowTextA(hStatic, NULL);
132  GetWindowTextA(hStatic, buffA, sizeof(buffA));
133  ok(buffA[0] == 0, "got wrong text %s\n", buffA);
134 
135  DestroyWindow(hStatic);
136 }
137 
138 START_TEST(static)
139 {
140  static const char classname[] = "testclass";
141  WNDCLASSEXA wndclass;
142  ULONG_PTR ctx_cookie;
143  HANDLE hCtx;
144 
145  if (!load_v6_module(&ctx_cookie, &hCtx))
146  return;
147 
148  wndclass.cbSize = sizeof(wndclass);
149  wndclass.style = CS_HREDRAW | CS_VREDRAW;
150  wndclass.lpfnWndProc = WndProc;
151  wndclass.cbClsExtra = 0;
152  wndclass.cbWndExtra = 0;
153  wndclass.hInstance = GetModuleHandleA(NULL);
154  wndclass.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
156  wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
158  wndclass.lpszClassName = classname;
159  wndclass.lpszMenuName = NULL;
160  RegisterClassExA(&wndclass);
161 
162  hMainWnd = CreateWindowA(classname, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL,
165 
166  test_updates(0, 0);
168  test_updates(SS_ICON, 0);
175  test_set_text();
176 
178 
179  unload_v6_module(ctx_cookie, hCtx);
180 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define WC_STATICA
Definition: commctrl.h:4675
static int g_nReceivedColorStatic
Definition: static.c:39
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
UINT style
Definition: winuser.h:3177
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
LPCSTR lpszMenuName
Definition: winuser.h:3185
int WINAPI GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
Definition: window.c:1326
HCURSOR hCursor
Definition: winuser.h:3183
WNDPROC lpfnWndProc
Definition: winuser.h:3178
HDC WINAPI GetDC(_In_opt_ HWND)
LPCSTR lpszClassName
Definition: winuser.h:3186
#define SS_BLACKRECT
Definition: pedump.c:696
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1754
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define SS_TYPEMASK
Definition: winuser.h:362
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
static DNS_RECORDW r1
Definition: record.c:37
BOOL WINAPI UpdateWindow(_In_ HWND)
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define CS_HREDRAW
Definition: winuser.h:648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
static void unload_v6_module(ULONG_PTR cookie, HANDLE hCtx)
Definition: v6util.h:63
#define WHITE_BRUSH
Definition: wingdi.h:901
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
HICON hIconSm
Definition: winuser.h:3187
WCHAR classname[128]
Definition: startup.c:15
__u16 time
Definition: mkdosfs.c:366
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI PeekMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
BOOL WINAPI DestroyWindow(_In_ HWND)
static void test_updates(int style, int flags)
Definition: static.c:81
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2029
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SS_BITMAP
Definition: pedump.c:704
HINSTANCE hInstance
Definition: winuser.h:3181
static BOOL load_v6_module(ULONG_PTR *pcookie, HANDLE *hCtx)
Definition: v6util.h:71
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
#define CTRL_ID
Definition: static.c:36
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4290
static HWND create_static(DWORD style)
Definition: static.c:57
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UINT cbSize
Definition: winuser.h:3176
const char * LPCSTR
Definition: xmlstorage.h:183
#define SW_SHOW
Definition: winuser.h:769
HBRUSH hbrBackground
Definition: winuser.h:3184
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
#define BLACK_BRUSH
Definition: wingdi.h:895
static void flush_events(void)
Definition: static.c:42
#define CS_VREDRAW
Definition: winuser.h:653
#define SS_ETCHEDHORZ
Definition: winuser.h:343
BOOL WINAPI SetWindowTextA(_In_ HWND, _In_opt_ LPCSTR)
DWORD COLORREF
Definition: windef.h:300
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
unsigned long DWORD
Definition: ntddk_ex.h:95
int cbWndExtra
Definition: winuser.h:3180
#define TODO_COUNT
Definition: static.c:34
GLbitfield flags
Definition: glext.h:7161
#define WAIT_TIMEOUT
Definition: dderror.h:14
static void test_set_text(void)
Definition: static.c:123
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
HICON hIcon
Definition: winuser.h:3182
#define todo_wine
Definition: test.h:163
HDC hdc
Definition: main.c:9
static HRGN hrgn
Definition: win.c:55
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: static.c:62
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
ATOM WINAPI RegisterClassExA(_In_ CONST WNDCLASSEXA *)
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
START_TEST(static)
Definition: static.c:138
#define SS_CENTERIMAGE
Definition: winuser.h:339
#define SS_SIMPLE
Definition: pedump.c:702
int cbClsExtra
Definition: winuser.h:3179
#define QS_ALLINPUT
Definition: winuser.h:874
#define ok(value,...)
Definition: atltest.h:57
#define SS_ETCHEDVERT
Definition: winuser.h:344
unsigned int UINT
Definition: ndis.h:50
static HWND hMainWnd
Definition: static.c:38
DWORD exp
Definition: msg.c:16038
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int WINAPI GetClipRgn(_In_ HDC, _In_ HRGN)
#define PM_REMOVE
Definition: winuser.h:1182
LONG_PTR LRESULT
Definition: windef.h:209
Arabic default style
Definition: afstyles.h:93
#define WS_VISIBLE
Definition: pedump.c:620
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define SS_ICON
Definition: pedump.c:695
#define SS_WHITERECT
Definition: pedump.c:698
static UINT WPARAM wparam
Definition: combo.c:716