From 8909419b55703eba8c0f724182805a4ab100e11e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Miko=C5=82aj=20Zalewski?= Date: Sun, 4 Feb 2007 23:58:09 +0100 Subject: [PATCH] comctl32: rebar: Add some tests for rebar and change the way the header size is fixed. --- dlls/comctl32/rebar.c | 6 +- dlls/comctl32/tests/Makefile.in | 1 + dlls/comctl32/tests/rebar.c | 175 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 dlls/comctl32/tests/rebar.c diff --git a/dlls/comctl32/rebar.c b/dlls/comctl32/rebar.c index b3058634cb9..4cf87bb7f2f 100644 --- a/dlls/comctl32/rebar.c +++ b/dlls/comctl32/rebar.c @@ -216,6 +216,9 @@ typedef struct #define BAND_NEEDS_REDRAW 0x00000020 #define CREATE_RUNNING 0x00000040 +/* used by Windows to mark that the header size has been set by the user and shouldn't be changed */ +#define RBBS_UNDOC_FIXEDHEADER 0x40000000 + /* ---- REBAR layout constants. Mostly determined by ---- */ /* ---- experiment on WIN 98. ---- */ @@ -2049,7 +2052,7 @@ REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand) } /* check if user overrode the header value */ - if (!(lpBand->fMask & RBBIM_HEADERSIZE)) + if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER)) lpBand->cxHeader = header; @@ -2210,6 +2213,7 @@ REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand) (lpBand->cxHeader != lprbbi->cxHeader ) ) { lpBand->cxHeader = lprbbi->cxHeader; + lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER; bChanged = TRUE; } } diff --git a/dlls/comctl32/tests/Makefile.in b/dlls/comctl32/tests/Makefile.in index b879575cb40..8a4a55e460d 100644 --- a/dlls/comctl32/tests/Makefile.in +++ b/dlls/comctl32/tests/Makefile.in @@ -15,6 +15,7 @@ CTESTS = \ mru.c \ progress.c \ propsheet.c \ + rebar.c \ status.c \ string.c \ subclass.c \ diff --git a/dlls/comctl32/tests/rebar.c b/dlls/comctl32/tests/rebar.c new file mode 100644 index 00000000000..4cc6a4e288c --- /dev/null +++ b/dlls/comctl32/tests/rebar.c @@ -0,0 +1,175 @@ +/* Unit tests for rebar. + * + * Copyright 2007 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 +#include + +#include +#include +#include + +#include "wine/test.h" + +static HWND hMainWnd; +static HWND hRebar; + +#define expect_eq(expr, value, type, format) { type ret = expr; ok((value) == ret, #expr " expected " format " got " format "\n", (value), (ret)); } + +static void rebuild_rebar(HWND *hRebar) +{ + if (hRebar) + DestroyWindow(*hRebar); + + *hRebar = CreateWindow(REBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, + hMainWnd, (HMENU)17, GetModuleHandle(NULL), NULL); + SendMessageA(*hRebar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0); +} + +static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + return DefWindowProcA(hWnd, msg, wParam, lParam); +} + +static void expect_band_content(UINT uBand, UINT fStyle, COLORREF clrFore, + COLORREF clrBack, LPCSTR lpText, int iImage, HWND hwndChild, + UINT cxMinChild, UINT cyMinChild, UINT cx, HBITMAP hbmBack, UINT wID, + /*UINT cyChild, UINT cyMaxChild, UINT cyIntegral,*/ UINT cxIdeal, LPARAM lParam, + UINT cxHeader) +{ + CHAR buf[MAX_PATH] = "abc"; + REBARBANDINFO rb; + + memset(&rb, 0xdd, sizeof(rb)); + rb.cbSize = sizeof(rb); + rb.fMask = RBBIM_BACKGROUND | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_COLORS + | RBBIM_HEADERSIZE | RBBIM_ID | RBBIM_IDEALSIZE | RBBIM_IMAGE | RBBIM_LPARAM + | RBBIM_SIZE | RBBIM_STYLE | RBBIM_TEXT; + rb.lpText = buf; + rb.cch = MAX_PATH; + ok(SendMessageA(hRebar, RB_GETBANDINFOA, uBand, (LPARAM)&rb), "RB_GETBANDINFO failed\n"); + expect_eq(rb.fStyle, fStyle, int, "%x"); + todo_wine expect_eq(rb.clrFore, clrFore, COLORREF, "%x"); + todo_wine expect_eq(rb.clrBack, clrBack, int, "%x"); + expect_eq(strcmp(rb.lpText, lpText), 0, int, "%d"); + expect_eq(rb.iImage, iImage, int, "%x"); + expect_eq(rb.hwndChild, hwndChild, HWND, "%p"); + expect_eq(rb.cxMinChild, cxMinChild, int, "%d"); + expect_eq(rb.cyMinChild, cyMinChild, int, "%d"); + expect_eq(rb.cx, cx, int, "%d"); + expect_eq(rb.hbmBack, hbmBack, HBITMAP, "%p"); + expect_eq(rb.wID, wID, int, "%d"); + /* in Windows the values of cyChild, cyMaxChild and cyIntegral can't be read */ + todo_wine expect_eq(rb.cyChild, 0xdddddddd, int, "%x"); + todo_wine expect_eq(rb.cyMaxChild, 0xdddddddd, int, "%x"); + todo_wine expect_eq(rb.cyIntegral, 0xdddddddd, int, "%x"); + expect_eq(rb.cxIdeal, cxIdeal, int, "%d"); + expect_eq(rb.lParam, lParam, LPARAM, "%lx"); + expect_eq(rb.cxHeader, cxHeader, int, "%d"); +} + +static void bandinfo_test() +{ + REBARBANDINFOA rb; + CHAR szABC[] = "ABC"; + CHAR szABCD[] = "ABCD"; + + rebuild_rebar(&hRebar); + rb.cbSize = sizeof(REBARBANDINFO); + rb.fMask = 0; + ok(SendMessageA(hRebar, RB_INSERTBANDA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "", -1, NULL, 0, 0, 0, NULL, 0, 0, 0, 0); + + rb.fMask = RBBIM_CHILDSIZE; + rb.cxMinChild = 15; + rb.cyMinChild = 20; + rb.cyChild = 30; + rb.cyMaxChild = 20; + rb.cyIntegral = 10; + ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 0); + + rb.fMask = RBBIM_TEXT; + rb.lpText = szABC; + ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 35); + + rb.cbSize = sizeof(REBARBANDINFO); + rb.fMask = 0; + ok(SendMessageA(hRebar, RB_INSERTBANDA, 1, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(1, 0, 0, GetSysColor(COLOR_3DFACE), "", -1, NULL, 0, 0, 0, NULL, 0, 0, 0, 9); + expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 40); + + rb.fMask = RBBIM_HEADERSIZE; + rb.cxHeader = 50; + ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0x40000000, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 50); + + rb.cxHeader = 5; + ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0x40000000, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 5); + + rb.fMask = RBBIM_TEXT; + rb.lpText = szABCD; + ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0x40000000, 0, GetSysColor(COLOR_3DFACE), "ABCD", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 5); + rb.fMask = RBBIM_STYLE | RBBIM_TEXT; + rb.fStyle = 0; + rb.lpText = szABC; + ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n"); + expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 40); + + DestroyWindow(hRebar); +} + +START_TEST(rebar) +{ + INITCOMMONCONTROLSEX icc; + WNDCLASSA wc; + MSG msg; + RECT rc; + + icc.dwSize = sizeof(icc); + icc.dwICC = ICC_COOL_CLASSES; + InitCommonControlsEx(&icc); + + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = GetModuleHandleA(NULL); + wc.hIcon = NULL; + wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM)); + wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW); + wc.lpszMenuName = NULL; + wc.lpszClassName = "MyTestWnd"; + wc.lpfnWndProc = MyWndProc; + RegisterClassA(&wc); + + hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0); + GetClientRect(hMainWnd, &rc); + ShowWindow(hMainWnd, SW_SHOW); + + bandinfo_test(); + PostQuitMessage(0); + while(GetMessageA(&msg,0,0,0)) { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + DestroyWindow(hMainWnd); +} -- 2.11.4.GIT