comctl32: rebar[1/5]: add some tests for rebar and change the way the header size is fixed

Mikołaj Zalewski mikolaj at zalewski.pl
Sun Feb 4 16:58:09 CST 2007


Some first unit tests for the rebar control. To avoid using todo_wine 
I've changed the way the bands are marked not to change the header size
-------------- next part --------------
From f813f2940d28bb5518188451825bc77ee30ee70b Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Sat, 27 Jan 2007 15:39:05 +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 deletions(-)

diff --git a/dlls/comctl32/rebar.c b/dlls/comctl32/rebar.c
index b305863..4cf87bb 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 b879575..8a4a55e 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 0000000..5832840
--- /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 <assert.h>
+#include <stdarg.h>
+
+#include <windows.h>
+#include <commctrl.h>
+#include <uxtheme.h>
+
+#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);
+}
-- 
1.4.4.2



More information about the wine-patches mailing list