2007-08-29 19:36:41 +02:00
|
|
|
/* Unit test suite for static controls.
|
|
|
|
*
|
|
|
|
* Copyright 2007 Google (Mikolaj Zalewski)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define STRICT
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
#define TODO_COUNT 1
|
|
|
|
|
|
|
|
#define CTRL_ID 1995
|
|
|
|
|
|
|
|
static HWND hMainWnd;
|
|
|
|
|
2008-08-04 23:06:54 +02:00
|
|
|
#define expect_eq(expr, value, type, fmt) { type val = expr; ok(val == (value), #expr " expected " fmt " got " fmt "\n", (value), val); }
|
2007-08-29 19:36:41 +02:00
|
|
|
|
2008-08-04 23:06:54 +02:00
|
|
|
static int g_nReceivedColorStatic = 0;
|
2007-08-29 19:36:41 +02:00
|
|
|
|
2011-09-22 09:35:05 +02:00
|
|
|
/* try to make sure pending X events have been processed before continuing */
|
|
|
|
static void flush_events(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
int diff = 200;
|
|
|
|
int min_timeout = 100;
|
|
|
|
DWORD time = GetTickCount() + diff;
|
|
|
|
|
|
|
|
while (diff > 0)
|
|
|
|
{
|
|
|
|
if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
|
2013-10-23 07:54:13 +02:00
|
|
|
while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
|
2011-09-22 09:35:05 +02:00
|
|
|
diff = time - GetTickCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-29 19:36:41 +02:00
|
|
|
static HWND build_static(DWORD style)
|
|
|
|
{
|
2013-10-23 07:54:13 +02:00
|
|
|
return CreateWindowA("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
|
2007-08-29 19:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_CTLCOLORSTATIC:
|
|
|
|
{
|
|
|
|
HDC hdc = (HDC)wparam;
|
|
|
|
HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
|
|
|
|
ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
g_nReceivedColorStatic++;
|
2009-04-13 19:22:34 +02:00
|
|
|
return (LRESULT) GetStockObject(BLACK_BRUSH);
|
2007-08-29 19:36:41 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-23 07:54:13 +02:00
|
|
|
return DefWindowProcA(hwnd, msg, wparam, lparam);
|
2007-08-29 19:36:41 +02:00
|
|
|
}
|
|
|
|
|
2008-08-04 23:06:54 +02:00
|
|
|
static void test_updates(int style, int flags)
|
2007-08-29 19:36:41 +02:00
|
|
|
{
|
|
|
|
RECT r1 = {20, 20, 30, 30};
|
|
|
|
HWND hStatic = build_static(style);
|
|
|
|
int exp;
|
|
|
|
|
2011-09-22 09:35:05 +02:00
|
|
|
flush_events();
|
2007-08-29 19:36:41 +02:00
|
|
|
trace("Testing style 0x%x\n", style);
|
|
|
|
g_nReceivedColorStatic = 0;
|
|
|
|
/* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
|
|
|
|
InvalidateRect(hMainWnd, NULL, FALSE);
|
|
|
|
UpdateWindow(hMainWnd);
|
|
|
|
InvalidateRect(hMainWnd, &r1, FALSE);
|
|
|
|
UpdateWindow(hMainWnd);
|
|
|
|
InvalidateRect(hStatic, &r1, FALSE);
|
|
|
|
UpdateWindow(hStatic);
|
|
|
|
InvalidateRect(hStatic, NULL, FALSE);
|
|
|
|
UpdateWindow(hStatic);
|
|
|
|
|
2009-04-13 19:22:34 +02:00
|
|
|
if( (style & SS_TYPEMASK) == SS_BITMAP) {
|
|
|
|
HDC hdc = GetDC( hStatic);
|
|
|
|
COLORREF colour = GetPixel( hdc, 10, 10);
|
|
|
|
ok ( colour != 0, "pixel should NOT be painted black!\n");
|
|
|
|
}
|
2007-08-29 19:36:41 +02:00
|
|
|
if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
|
|
|
|
exp = 4;
|
|
|
|
else
|
|
|
|
exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
|
|
|
|
|
|
|
|
if (flags & TODO_COUNT)
|
|
|
|
todo_wine { expect_eq(g_nReceivedColorStatic, exp, int, "%d"); }
|
2009-04-13 19:22:34 +02:00
|
|
|
else if ((style & SS_TYPEMASK) == SS_ICON || (style & SS_TYPEMASK) == SS_BITMAP)
|
2011-07-27 04:11:34 +02:00
|
|
|
ok( g_nReceivedColorStatic == exp, "expected %u got %u\n", exp, g_nReceivedColorStatic );
|
2007-08-29 19:36:41 +02:00
|
|
|
else
|
|
|
|
expect_eq(g_nReceivedColorStatic, exp, int, "%d");
|
|
|
|
DestroyWindow(hStatic);
|
|
|
|
}
|
|
|
|
|
2015-03-23 06:12:29 +01:00
|
|
|
static void test_set_text(void)
|
|
|
|
{
|
|
|
|
HWND hStatic = build_static(SS_SIMPLE);
|
|
|
|
char buffA[10];
|
|
|
|
|
|
|
|
GetWindowTextA(hStatic, buffA, sizeof(buffA));
|
|
|
|
ok(!strcmp(buffA, "Test"), "got wrong text %s\n", buffA);
|
|
|
|
|
|
|
|
SetWindowTextA(hStatic, NULL);
|
|
|
|
GetWindowTextA(hStatic, buffA, sizeof(buffA));
|
|
|
|
ok(buffA[0] == 0, "got wrong text %s\n", buffA);
|
|
|
|
|
|
|
|
DestroyWindow(hStatic);
|
|
|
|
}
|
|
|
|
|
2007-08-29 19:36:41 +02:00
|
|
|
START_TEST(static)
|
|
|
|
{
|
2013-12-31 03:00:44 +01:00
|
|
|
static const char szClassName[] = "testclass";
|
2013-10-23 07:54:13 +02:00
|
|
|
WNDCLASSEXA wndclass;
|
2007-08-29 19:36:41 +02:00
|
|
|
|
|
|
|
wndclass.cbSize = sizeof(wndclass);
|
|
|
|
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wndclass.lpfnWndProc = WndProc;
|
|
|
|
wndclass.cbClsExtra = 0;
|
|
|
|
wndclass.cbWndExtra = 0;
|
2013-10-23 07:54:13 +02:00
|
|
|
wndclass.hInstance = GetModuleHandleA(NULL);
|
|
|
|
wndclass.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
|
|
|
|
wndclass.hIconSm = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
|
|
|
|
wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
|
2008-10-25 23:39:12 +02:00
|
|
|
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
|
2007-08-29 19:36:41 +02:00
|
|
|
wndclass.lpszClassName = szClassName;
|
|
|
|
wndclass.lpszMenuName = NULL;
|
2013-10-23 07:54:13 +02:00
|
|
|
RegisterClassExA(&wndclass);
|
2007-08-29 19:36:41 +02:00
|
|
|
|
2013-10-23 07:54:13 +02:00
|
|
|
hMainWnd = CreateWindowA(szClassName, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, GetModuleHandleA(NULL), NULL);
|
2007-08-29 19:36:41 +02:00
|
|
|
ShowWindow(hMainWnd, SW_SHOW);
|
|
|
|
|
|
|
|
test_updates(0, 0);
|
|
|
|
test_updates(SS_SIMPLE, 0);
|
|
|
|
test_updates(SS_ICON, 0);
|
|
|
|
test_updates(SS_BITMAP, 0);
|
2009-04-13 19:22:34 +02:00
|
|
|
test_updates(SS_BITMAP | SS_CENTERIMAGE, 0);
|
2007-08-29 19:36:41 +02:00
|
|
|
test_updates(SS_BLACKRECT, TODO_COUNT);
|
|
|
|
test_updates(SS_WHITERECT, TODO_COUNT);
|
|
|
|
test_updates(SS_ETCHEDHORZ, TODO_COUNT);
|
|
|
|
test_updates(SS_ETCHEDVERT, TODO_COUNT);
|
2015-03-23 06:12:29 +01:00
|
|
|
test_set_text();
|
2007-08-29 19:36:41 +02:00
|
|
|
|
|
|
|
DestroyWindow(hMainWnd);
|
|
|
|
}
|