Reactos
at master 180 lines 5.6 kB view raw
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 38static HWND hMainWnd; 39static int g_nReceivedColorStatic; 40 41/* try to make sure pending X events have been processed before continuing */ 42static 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 57static HWND create_static(DWORD style) 58{ 59 return CreateWindowA(WC_STATICA, "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0); 60} 61 62static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 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"); 71 DeleteObject(hrgn); 72 g_nReceivedColorStatic++; 73 return (LRESULT) GetStockObject(BLACK_BRUSH); 74 } 75 break; 76 } 77 78 return DefWindowProcA(hwnd, msg, wparam, lparam); 79} 80 81static 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(); 88 g_nReceivedColorStatic = 0; 89 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */ 90 InvalidateRect(hMainWnd, NULL, FALSE); 91 UpdateWindow(hMainWnd); 92 InvalidateRect(hMainWnd, &r1, FALSE); 93 UpdateWindow(hMainWnd); 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 123static 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 138START_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); 155 wndclass.hIconSm = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION); 156 wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW); 157 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 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, 163 GetModuleHandleA(NULL), NULL); 164 ShowWindow(hMainWnd, SW_SHOW); 165 166 test_updates(0, 0); 167 test_updates(SS_SIMPLE, 0); 168 test_updates(SS_ICON, 0); 169 test_updates(SS_BITMAP, 0); 170 test_updates(SS_BITMAP | SS_CENTERIMAGE, 0); 171 test_updates(SS_BLACKRECT, TODO_COUNT); 172 test_updates(SS_WHITERECT, TODO_COUNT); 173 test_updates(SS_ETCHEDHORZ, TODO_COUNT); 174 test_updates(SS_ETCHEDVERT, TODO_COUNT); 175 test_set_text(); 176 177 DestroyWindow(hMainWnd); 178 179 unload_v6_module(ctx_cookie, hCtx); 180}