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 "precomp.h" 21 22 #define TODO_COUNT 1 23 24 #define CTRL_ID 1995 25 26 static HWND hMainWnd; 27 static int g_nReceivedColorStatic; 28 29 /* try to make sure pending X events have been processed before continuing */ 30 static void flush_events(void) 31 { 32 MSG msg; 33 int diff = 200; 34 int min_timeout = 100; 35 DWORD time = GetTickCount() + diff; 36 37 while (diff > 0) 38 { 39 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break; 40 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg ); 41 diff = time - GetTickCount(); 42 } 43 } 44 45 static HWND create_static(DWORD style) 46 { 47 return CreateWindowA("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0); 48 } 49 50 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 51 { 52 switch (msg) 53 { 54 case WM_CTLCOLORSTATIC: 55 { 56 HDC hdc = (HDC)wparam; 57 HRGN hrgn = CreateRectRgn(0, 0, 1, 1); 58 ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n"); 59 DeleteObject(hrgn); 60 g_nReceivedColorStatic++; 61 return (LRESULT) GetStockObject(BLACK_BRUSH); 62 } 63 break; 64 } 65 66 return DefWindowProcA(hwnd, msg, wparam, lparam); 67 } 68 69 static void test_updates(int style, int flags) 70 { 71 HWND hStatic = create_static(style); 72 RECT r1 = {20, 20, 30, 30}; 73 int exp; 74 75 flush_events(); 76 g_nReceivedColorStatic = 0; 77 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */ 78 InvalidateRect(hMainWnd, NULL, FALSE); 79 UpdateWindow(hMainWnd); 80 InvalidateRect(hMainWnd, &r1, FALSE); 81 UpdateWindow(hMainWnd); 82 InvalidateRect(hStatic, &r1, FALSE); 83 UpdateWindow(hStatic); 84 InvalidateRect(hStatic, NULL, FALSE); 85 UpdateWindow(hStatic); 86 87 if ((style & SS_TYPEMASK) == SS_BITMAP) 88 { 89 HDC hdc = GetDC(hStatic); 90 COLORREF colour = GetPixel(hdc, 10, 10); 91 todo_wine 92 ok(colour == 0, "Unexpected pixel color.\n"); 93 ReleaseDC(hStatic, hdc); 94 } 95 96 if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT) 97 exp = 4; 98 else 99 exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */ 100 101 if (flags & TODO_COUNT) 102 todo_wine 103 ok(g_nReceivedColorStatic == exp, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic); 104 else if ((style & SS_TYPEMASK) == SS_ICON || (style & SS_TYPEMASK) == SS_BITMAP) 105 ok(g_nReceivedColorStatic == exp, "Unexpected %u got %u\n", exp, g_nReceivedColorStatic); 106 else 107 ok(g_nReceivedColorStatic == exp, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic); 108 DestroyWindow(hStatic); 109 } 110 111 static void test_set_text(void) 112 { 113 HWND hStatic = create_static(SS_SIMPLE); 114 char buffA[10]; 115 116 GetWindowTextA(hStatic, buffA, sizeof(buffA)); 117 ok(!strcmp(buffA, "Test"), "got wrong text %s\n", buffA); 118 119 SetWindowTextA(hStatic, NULL); 120 GetWindowTextA(hStatic, buffA, sizeof(buffA)); 121 ok(buffA[0] == 0, "got wrong text %s\n", buffA); 122 123 DestroyWindow(hStatic); 124 } 125 126 START_TEST(static) 127 { 128 static const char classname[] = "testclass"; 129 WNDCLASSEXA wndclass; 130 ULONG_PTR ctx_cookie; 131 HANDLE hCtx; 132 133 if (!load_v6_module(&ctx_cookie, &hCtx)) 134 return; 135 136 wndclass.cbSize = sizeof(wndclass); 137 wndclass.style = CS_HREDRAW | CS_VREDRAW; 138 wndclass.lpfnWndProc = WndProc; 139 wndclass.cbClsExtra = 0; 140 wndclass.cbWndExtra = 0; 141 wndclass.hInstance = GetModuleHandleA(NULL); 142 wndclass.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION); 143 wndclass.hIconSm = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION); 144 wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW); 145 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 146 wndclass.lpszClassName = classname; 147 wndclass.lpszMenuName = NULL; 148 RegisterClassExA(&wndclass); 149 150 hMainWnd = CreateWindowA(classname, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, 151 GetModuleHandleA(NULL), NULL); 152 ShowWindow(hMainWnd, SW_SHOW); 153 154 test_updates(0, 0); 155 test_updates(SS_SIMPLE, 0); 156 test_updates(SS_ICON, 0); 157 test_updates(SS_BITMAP, 0); 158 test_updates(SS_BITMAP | SS_CENTERIMAGE, 0); 159 test_updates(SS_BLACKRECT, TODO_COUNT); 160 test_updates(SS_WHITERECT, TODO_COUNT); 161 test_updates(SS_ETCHEDHORZ, TODO_COUNT); 162 test_updates(SS_ETCHEDVERT, TODO_COUNT); 163 test_set_text(); 164 165 DestroyWindow(hMainWnd); 166 167 unload_v6_module(ctx_cookie, hCtx); 168 } 169