comctl32/toolbar: Test that toolbar shouldn't use outside theme handles.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2021-06-22 16:21:09 +08:00 committed by Alexandre Julliard
parent a769679113
commit 677c459b86

View file

@ -46,7 +46,10 @@ static INT (WINAPI *pImageList_GetImageCount)(HIMAGELIST);
static BOOL (WINAPI *pImageList_GetIconSize)(HIMAGELIST, int *, int *);
static HIMAGELIST (WINAPI *pImageList_LoadImageA)(HINSTANCE, LPCSTR, int, int, COLORREF, UINT, UINT);
static HRESULT (WINAPI *pCloseThemeData)(HTHEME);
static BOOL (WINAPI *pIsThemeActive)(VOID);
static HTHEME (WINAPI *pGetWindowTheme)(HWND);
static HTHEME (WINAPI *pOpenThemeData)(HWND, LPCWSTR);
static BOOL is_theme_active;
@ -139,6 +142,40 @@ static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
p->iString = nString;
}
/* 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;
while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
DispatchMessageA(&msg);
diff = time - GetTickCount();
}
}
static BOOL equal_dc(HDC hdc1, HDC hdc2, int width, int height)
{
int x, y;
for (x = 0; x < width; ++x)
{
for (y = 0; y < height; ++y)
{
if (GetPixel(hdc1, x, y) != GetPixel(hdc2, x, y))
return FALSE;
}
}
return TRUE;
}
static void *alloced_str;
static LRESULT parent_wnd_notify(LPARAM lParam)
@ -2574,6 +2611,79 @@ static void test_imagelist(void)
DestroyWindow(hwnd);
}
static void test_visual(void)
{
HBITMAP mem_bitmap1, mem_bitmap2;
HDC mem_dc1, mem_dc2, toolbar_dc;
TBBUTTON tbbutton;
int width, height;
HTHEME theme;
HWND toolbar;
RECT rect;
BOOL ret;
if (!is_theme_active)
{
skip("Theming is not active, skipping visual tests.\n");
return;
}
/* Test that toolbar shouldn't use outside theme handles */
toolbar = CreateWindowA(TOOLBARCLASSNAMEA, "", WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hMainWnd, 0, 0, NULL);
ok(!!toolbar, "Failed to create a toolbar window.\n");
/* Toolbar needs data for it to show */
memset(&tbbutton, 0, sizeof(tbbutton));
tbbutton.fsState = TBSTATE_ENABLED;
tbbutton.iString = (INT_PTR)"test";
SendMessageA(toolbar, TB_BUTTONSTRUCTSIZE, sizeof(tbbutton), 0);
ret = SendMessageA(toolbar, TB_ADDBUTTONSA, 1, (LPARAM)&tbbutton);
ok(ret, "TB_ADDBUTTONSA failed.\n");
theme = pGetWindowTheme(toolbar);
todo_wine
ok(!theme, "Expected theme not opened by window.\n");
toolbar_dc = GetDC(toolbar);
GetClientRect(toolbar, &rect);
width = rect.right - rect.left;
height = rect.bottom - rect.top;
ret = RedrawWindow(toolbar, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW | RDW_UPDATENOW);
ok(ret, "RedrawWindow failed.\n");
flush_events();
mem_dc1 = CreateCompatibleDC(toolbar_dc);
mem_bitmap1 = CreateCompatibleBitmap(toolbar_dc, width, height);
SelectObject(mem_dc1, mem_bitmap1);
BitBlt(mem_dc1, 0, 0, width, height, toolbar_dc, 0, 0, SRCCOPY);
if (theme)
pCloseThemeData(theme);
theme = pOpenThemeData(toolbar, L"Rebar");
ok(!!theme, "OpenThemeData failed.\n");
ret = RedrawWindow(toolbar, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW | RDW_UPDATENOW);
ok(ret, "RedrawWindow failed.\n");
mem_dc2 = CreateCompatibleDC(toolbar_dc);
mem_bitmap2 = CreateCompatibleBitmap(toolbar_dc, width, height);
SelectObject(mem_dc2, mem_bitmap2);
BitBlt(mem_dc2, 0, 0, width, height, toolbar_dc, 0, 0, SRCCOPY);
ret = equal_dc(mem_dc1, mem_dc2, width, height);
todo_wine
ok(ret, "Expected same content.\n");
pCloseThemeData(theme);
DeleteObject(mem_bitmap2);
DeleteObject(mem_bitmap1);
DeleteDC(mem_dc2);
DeleteDC(mem_dc1);
ReleaseDC(toolbar, toolbar_dc);
DestroyWindow(toolbar);
}
static void init_functions(void)
{
HMODULE hComCtl32, hUxtheme;
@ -2590,7 +2700,10 @@ static void init_functions(void)
#undef X
#define X(f) p##f = (void*)GetProcAddress(hUxtheme, #f)
X(GetWindowTheme);
X(IsThemeActive);
X(OpenThemeData);
X(CloseThemeData);
#undef X
}
@ -2649,6 +2762,7 @@ START_TEST(toolbar)
return;
test_create(TRUE);
test_visual();
PostQuitMessage(0);
while(GetMessageA(&msg,0,0,0)) {