msi: Only insert entries into listbox if property value matches.
[wine] / dlls / comctl32 / tests / rebar.c
1 /* Unit tests for rebar.
2  *
3  * Copyright 2007 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 <assert.h>
21 #include <stdarg.h>
22
23 #include <windows.h>
24 #include <commctrl.h>
25 #include <uxtheme.h>
26
27 #include "wine/test.h"
28
29 static HWND hMainWnd;
30 static HWND hRebar;
31
32 #define expect_eq(expr, value, type, format) { type ret = expr; ok((value) == ret, #expr " expected " format "  got " format "\n", (value), (ret)); }
33
34 static void rebuild_rebar(HWND *hRebar)
35 {
36     if (hRebar)
37         DestroyWindow(*hRebar);
38
39     *hRebar = CreateWindow(REBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
40         hMainWnd, (HMENU)17, GetModuleHandle(NULL), NULL);
41     SendMessageA(*hRebar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
42 }
43
44 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
45 {
46     return DefWindowProcA(hWnd, msg, wParam, lParam);
47 }
48
49 static void expect_band_content(UINT uBand, UINT fStyle, COLORREF clrFore,
50     COLORREF clrBack, LPCSTR lpText, int iImage, HWND hwndChild,
51     UINT cxMinChild, UINT cyMinChild, UINT cx, HBITMAP hbmBack, UINT wID,
52     /*UINT cyChild, UINT cyMaxChild, UINT cyIntegral,*/ UINT cxIdeal, LPARAM lParam,
53     UINT cxHeader)
54 {
55     CHAR buf[MAX_PATH] = "abc";
56     REBARBANDINFO rb;
57
58     memset(&rb, 0xdd, sizeof(rb));
59     rb.cbSize = sizeof(rb);
60     rb.fMask = RBBIM_BACKGROUND | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_COLORS
61         | RBBIM_HEADERSIZE | RBBIM_ID | RBBIM_IDEALSIZE | RBBIM_IMAGE | RBBIM_LPARAM
62         | RBBIM_SIZE | RBBIM_STYLE | RBBIM_TEXT;
63     rb.lpText = buf;
64     rb.cch = MAX_PATH;
65     ok(SendMessageA(hRebar, RB_GETBANDINFOA, uBand, (LPARAM)&rb), "RB_GETBANDINFO failed\n");
66     expect_eq(rb.fStyle, fStyle, int, "%x");
67     todo_wine expect_eq(rb.clrFore, clrFore, COLORREF, "%x");
68     todo_wine expect_eq(rb.clrBack, clrBack, int, "%x");
69     expect_eq(strcmp(rb.lpText, lpText), 0, int, "%d");
70     expect_eq(rb.iImage, iImage, int, "%x");
71     expect_eq(rb.hwndChild, hwndChild, HWND, "%p");
72     expect_eq(rb.cxMinChild, cxMinChild, int, "%d");
73     expect_eq(rb.cyMinChild, cyMinChild, int, "%d");
74     expect_eq(rb.cx, cx, int, "%d");
75     expect_eq(rb.hbmBack, hbmBack, HBITMAP, "%p");
76     expect_eq(rb.wID, wID, int, "%d");
77     /* in Windows the values of cyChild, cyMaxChild and cyIntegral can't be read */
78     todo_wine expect_eq(rb.cyChild, 0xdddddddd, int, "%x");
79     todo_wine expect_eq(rb.cyMaxChild, 0xdddddddd, int, "%x");
80     todo_wine expect_eq(rb.cyIntegral, 0xdddddddd, int, "%x");
81     expect_eq(rb.cxIdeal, cxIdeal, int, "%d");
82     expect_eq(rb.lParam, lParam, LPARAM, "%lx");
83     expect_eq(rb.cxHeader, cxHeader, int, "%d");
84 }
85
86 static void bandinfo_test()
87 {
88     REBARBANDINFOA rb;
89     CHAR szABC[] = "ABC";
90     CHAR szABCD[] = "ABCD";
91
92     rebuild_rebar(&hRebar);
93     rb.cbSize = sizeof(REBARBANDINFO);
94     rb.fMask = 0;
95     ok(SendMessageA(hRebar, RB_INSERTBANDA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
96     expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "", -1, NULL, 0, 0, 0, NULL, 0, 0, 0, 0);
97
98     rb.fMask = RBBIM_CHILDSIZE;
99     rb.cxMinChild = 15;
100     rb.cyMinChild = 20;
101     rb.cyChild = 30;
102     rb.cyMaxChild = 20;
103     rb.cyIntegral = 10;
104     ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
105     expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 0);
106
107     rb.fMask = RBBIM_TEXT;
108     rb.lpText = szABC;
109     ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
110     expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 35);
111
112     rb.cbSize = sizeof(REBARBANDINFO);
113     rb.fMask = 0;
114     ok(SendMessageA(hRebar, RB_INSERTBANDA, 1, (LPARAM)&rb), "RB_INSERTBAND failed\n");
115     expect_band_content(1, 0, 0, GetSysColor(COLOR_3DFACE), "", -1, NULL, 0, 0, 0, NULL, 0, 0, 0, 9);
116     expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 40);
117
118     rb.fMask = RBBIM_HEADERSIZE;
119     rb.cxHeader = 50;
120     ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
121     expect_band_content(0, 0x40000000, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 50);
122
123     rb.cxHeader = 5;
124     ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
125     expect_band_content(0, 0x40000000, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 5);
126
127     rb.fMask = RBBIM_TEXT;
128     rb.lpText = szABCD;
129     ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
130     expect_band_content(0, 0x40000000, 0, GetSysColor(COLOR_3DFACE), "ABCD", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 5);
131     rb.fMask = RBBIM_STYLE | RBBIM_TEXT;
132     rb.fStyle = 0;
133     rb.lpText = szABC;
134     ok(SendMessageA(hRebar, RB_SETBANDINFOA, 0, (LPARAM)&rb), "RB_INSERTBAND failed\n");
135     expect_band_content(0, 0, 0, GetSysColor(COLOR_3DFACE), "ABC", -1, NULL, 15, 20, 0, NULL, 0, 0, 0, 40);
136
137     DestroyWindow(hRebar);
138 }
139
140 START_TEST(rebar)
141 {
142     INITCOMMONCONTROLSEX icc;
143     WNDCLASSA wc;
144     MSG msg;
145     RECT rc;
146
147     icc.dwSize = sizeof(icc);
148     icc.dwICC = ICC_COOL_CLASSES;
149     InitCommonControlsEx(&icc);
150
151     wc.style = CS_HREDRAW | CS_VREDRAW;
152     wc.cbClsExtra = 0;
153     wc.cbWndExtra = 0;
154     wc.hInstance = GetModuleHandleA(NULL);
155     wc.hIcon = NULL;
156     wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
157     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
158     wc.lpszMenuName = NULL;
159     wc.lpszClassName = "MyTestWnd";
160     wc.lpfnWndProc = MyWndProc;
161     RegisterClassA(&wc);
162
163     hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
164       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
165     GetClientRect(hMainWnd, &rc);
166     ShowWindow(hMainWnd, SW_SHOW);
167
168     bandinfo_test();
169     PostQuitMessage(0);
170     while(GetMessageA(&msg,0,0,0)) {
171         TranslateMessage(&msg);
172         DispatchMessageA(&msg);
173     }
174     DestroyWindow(hMainWnd);
175 }