2 * Unit test suite for brushes
4 * Copyright 2004 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
29 typedef struct _STOCK_BRUSH {
35 static void test_solidbrush(void)
37 static const STOCK_BRUSH stock[] = {
38 {RGB(255,255,255), WHITE_BRUSH, "white"},
39 {RGB(192,192,192), LTGRAY_BRUSH, "ltgray"},
40 {RGB(128,128,128), GRAY_BRUSH, "gray"},
41 {RGB(0,0,0), BLACK_BRUSH, "black"},
42 {RGB(0,0,255), -1, "blue"}
50 for(i=0; i<sizeof(stock)/sizeof(stock[0]); i++) {
51 solidBrush = CreateSolidBrush(stock[i].color);
53 if(stock[i].stockobj != -1) {
54 stockBrush = GetStockObject(stock[i].stockobj);
55 ok(stockBrush!=solidBrush ||
56 broken(stockBrush==solidBrush), /* win9x does return stock object */
57 "Stock %s brush equals solid %s brush\n", stock[i].name, stock[i].name);
61 memset(&br, 0, sizeof(br));
62 ret = GetObject(solidBrush, sizeof(br), &br);
63 ok( ret !=0, "GetObject on solid %s brush failed, error=%d\n", stock[i].name, GetLastError());
64 ok(br.lbStyle==BS_SOLID, "%s brush has wrong style, got %d expected %d\n", stock[i].name, br.lbStyle, BS_SOLID);
65 ok(br.lbColor==stock[i].color, "%s brush has wrong color, got 0x%08x expected 0x%08x\n", stock[i].name, br.lbColor, stock[i].color);
68 /* Sanity check, make sure the colors being compared do in fact have a stock brush */
69 ret = GetObject(stockBrush, sizeof(br), &br);
70 ok( ret !=0, "GetObject on stock %s brush failed, error=%d\n", stock[i].name, GetLastError());
71 ok(br.lbColor==stock[i].color, "stock %s brush unexpected color, got 0x%08x expected 0x%08x\n", stock[i].name, br.lbColor, stock[i].color);
74 DeleteObject(solidBrush);
75 ret = GetObject(solidBrush, sizeof(br), &br);
77 broken(ret!=0), /* win9x */
78 "GetObject succeeded on a deleted %s brush\n", stock[i].name);
82 static void test_pattern_brush(void)
84 char buffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD) + 32 * 32 / 8];
85 BITMAPINFO *info = (BITMAPINFO *)buffer;
94 bitmap = CreateBitmap( 20, 20, 1, 1, NULL );
95 ok( bitmap != NULL, "CreateBitmap failed\n" );
96 brush = CreatePatternBrush( bitmap );
97 ok( brush != NULL, "CreatePatternBrush failed\n" );
98 memset( &br, 0x55, sizeof(br) );
99 ret = GetObjectW( brush, sizeof(br), &br );
100 ok( ret == sizeof(br), "wrong size %u\n", ret );
101 ok( br.lbStyle == BS_PATTERN, "wrong style %u\n", br.lbStyle );
102 ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
103 ok( (HBITMAP)br.lbHatch == bitmap, "wrong handle %p/%p\n", (HBITMAP)br.lbHatch, bitmap );
104 DeleteObject( brush );
106 br.lbStyle = BS_PATTERN8X8;
107 br.lbColor = 0x12345;
108 br.lbHatch = (ULONG_PTR)bitmap;
109 brush = CreateBrushIndirect( &br );
110 ok( brush != NULL, "CreatePatternBrush failed\n" );
111 memset( &br, 0x55, sizeof(br) );
112 ret = GetObjectW( brush, sizeof(br), &br );
113 ok( ret == sizeof(br), "wrong size %u\n", ret );
114 ok( br.lbStyle == BS_PATTERN, "wrong style %u\n", br.lbStyle );
115 ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
116 ok( (HBITMAP)br.lbHatch == bitmap, "wrong handle %p/%p\n", (HBITMAP)br.lbHatch, bitmap );
117 ret = GetObjectW( bitmap, sizeof(dib), &dib );
118 ok( ret == sizeof(dib.dsBm), "wrong size %u\n", ret );
119 DeleteObject( bitmap );
120 ret = GetObjectW( bitmap, sizeof(dib), &dib );
121 ok( ret == 0, "wrong size %u\n", ret );
122 DeleteObject( brush );
124 memset( info, 0, sizeof(buffer) );
125 info->bmiHeader.biSize = sizeof(info->bmiHeader);
126 info->bmiHeader.biHeight = 32;
127 info->bmiHeader.biWidth = 32;
128 info->bmiHeader.biBitCount = 1;
129 info->bmiHeader.biPlanes = 1;
130 info->bmiHeader.biCompression = BI_RGB;
131 bitmap = CreateDIBSection( 0, info, DIB_RGB_COLORS, (void**)&bits, NULL, 0 );
132 ok( bitmap != NULL, "CreateDIBSection failed\n" );
134 /* MSDN says a DIB section is not allowed, but it works fine */
135 brush = CreatePatternBrush( bitmap );
136 ok( brush != NULL, "CreatePatternBrush failed\n" );
137 memset( &br, 0x55, sizeof(br) );
138 ret = GetObjectW( brush, sizeof(br), &br );
139 ok( ret == sizeof(br), "wrong size %u\n", ret );
140 ok( br.lbStyle == BS_PATTERN, "wrong style %u\n", br.lbStyle );
141 ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
142 ok( (HBITMAP)br.lbHatch == bitmap, "wrong handle %p/%p\n", (HBITMAP)br.lbHatch, bitmap );
143 ret = GetObjectW( bitmap, sizeof(dib), &dib );
144 ok( ret == sizeof(dib), "wrong size %u\n", ret );
145 DeleteObject( brush );
146 DeleteObject( bitmap );
148 brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
149 ok( brush != NULL, "CreatePatternBrush failed\n" );
150 memset( &br, 0x55, sizeof(br) );
151 ret = GetObjectW( brush, sizeof(br), &br );
152 ok( ret == sizeof(br), "wrong size %u\n", ret );
153 ok( br.lbStyle == BS_DIBPATTERN, "wrong style %u\n", br.lbStyle );
154 ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
155 ok( (BITMAPINFO *)br.lbHatch == info || broken(!br.lbHatch), /* nt4 */
156 "wrong handle %p/%p\n", (BITMAPINFO *)br.lbHatch, info );
157 DeleteObject( brush );
159 br.lbStyle = BS_DIBPATTERNPT;
160 br.lbColor = DIB_PAL_COLORS;
161 br.lbHatch = (ULONG_PTR)info;
162 brush = CreateBrushIndirect( &br );
163 ok( brush != NULL, "CreatePatternBrush failed\n" );
164 memset( &br, 0x55, sizeof(br) );
165 ret = GetObjectW( brush, sizeof(br), &br );
166 ok( ret == sizeof(br), "wrong size %u\n", ret );
167 ok( br.lbStyle == BS_DIBPATTERN, "wrong style %u\n", br.lbStyle );
168 ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
169 ok( (BITMAPINFO *)br.lbHatch == info || broken(!br.lbHatch), /* nt4 */
170 "wrong handle %p/%p\n", (BITMAPINFO *)br.lbHatch, info );
172 mem = GlobalAlloc( GMEM_MOVEABLE, sizeof(buffer) );
173 memcpy( GlobalLock( mem ), buffer, sizeof(buffer) );
175 br.lbStyle = BS_DIBPATTERN;
176 br.lbColor = DIB_PAL_COLORS;
177 br.lbHatch = (ULONG_PTR)mem;
178 brush = CreateBrushIndirect( &br );
179 ok( brush != NULL, "CreatePatternBrush failed\n" );
180 memset( &br, 0x55, sizeof(br) );
181 ret = GetObjectW( brush, sizeof(br), &br );
182 ok( ret == sizeof(br), "wrong size %u\n", ret );
183 ok( br.lbStyle == BS_DIBPATTERN, "wrong style %u\n", br.lbStyle );
184 ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
185 ok( (HGLOBAL)br.lbHatch != mem, "wrong handle %p/%p\n", (HGLOBAL)br.lbHatch, mem );
186 bits = GlobalLock( mem );
187 ok( (HGLOBAL)br.lbHatch == bits || broken(!br.lbHatch), /* nt4 */
188 "wrong handle %p/%p\n", (HGLOBAL)br.lbHatch, bits );
189 ret = GlobalFlags( mem );
190 ok( ret == 2, "wrong flags %x\n", ret );
191 DeleteObject( brush );
192 ret = GlobalFlags( mem );
193 ok( ret == 2, "wrong flags %x\n", ret );
195 info->bmiHeader.biBitCount = 8;
196 info->bmiHeader.biCompression = BI_RLE8;
197 brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
198 ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );
200 info->bmiHeader.biBitCount = 4;
201 info->bmiHeader.biCompression = BI_RLE4;
202 brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
203 ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );
205 br.lbStyle = BS_DIBPATTERN8X8;
206 br.lbColor = DIB_RGB_COLORS;
207 br.lbHatch = (ULONG_PTR)mem;
208 brush = CreateBrushIndirect( &br );
209 ok( !brush, "CreatePatternBrush succeeded\n" );
211 br.lbStyle = BS_MONOPATTERN;
212 br.lbColor = DIB_RGB_COLORS;
213 br.lbHatch = (ULONG_PTR)mem;
214 brush = CreateBrushIndirect( &br );
215 ok( !brush, "CreatePatternBrush succeeded\n" );
217 br.lbStyle = BS_INDEXED;
218 br.lbColor = DIB_RGB_COLORS;
219 br.lbHatch = (ULONG_PTR)mem;
220 brush = CreateBrushIndirect( &br );
221 ok( !brush, "CreatePatternBrush succeeded\n" );
226 static void test_palette_brush(void)
228 char buffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD) + 16 * 16];
229 BITMAPINFO *info = (BITMAPINFO *)buffer;
230 WORD *indices = (WORD *)info->bmiColors;
231 char pal_buffer[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
232 LOGPALETTE *pal = (LOGPALETTE *)pal_buffer;
233 HDC hdc = CreateCompatibleDC( 0 );
238 HPALETTE palette, palette2;
240 memset( info, 0, sizeof(*info) );
241 info->bmiHeader.biSize = sizeof(info->bmiHeader);
242 info->bmiHeader.biWidth = 16;
243 info->bmiHeader.biHeight = 16;
244 info->bmiHeader.biPlanes = 1;
245 info->bmiHeader.biBitCount = 32;
246 info->bmiHeader.biCompression = BI_RGB;
247 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
248 ok( dib != NULL, "CreateDIBSection failed\n" );
250 info->bmiHeader.biBitCount = 8;
251 for (i = 0; i < 256; i++) indices[i] = 255 - i;
252 for (i = 0; i < 256; i++) ((BYTE *)(indices + 256))[i] = i;
253 brush = CreateDIBPatternBrushPt( info, DIB_PAL_COLORS );
254 ok( brush != NULL, "CreateDIBPatternBrushPt failed\n" );
256 pal->palVersion = 0x300;
257 pal->palNumEntries = 256;
258 for (i = 0; i < 256; i++)
260 pal->palPalEntry[i].peRed = i * 2;
261 pal->palPalEntry[i].peGreen = i * 2;
262 pal->palPalEntry[i].peBlue = i * 2;
263 pal->palPalEntry[i].peFlags = 0;
265 palette = CreatePalette( pal );
267 ok( SelectObject( hdc, dib ) != NULL, "SelectObject failed\n" );
268 ok( SelectPalette( hdc, palette, 0 ) != NULL, "SelectPalette failed\n" );
269 ok( SelectObject( hdc, brush ) != NULL, "SelectObject failed\n" );
270 memset( dib_bits, 0xaa, 16 * 16 * 4 );
271 PatBlt( hdc, 0, 0, 16, 16, PATCOPY );
272 for (i = 0; i < 256; i++)
274 DWORD expect = (pal->palPalEntry[255 - i].peRed << 16 |
275 pal->palPalEntry[255 - i].peGreen << 8 |
276 pal->palPalEntry[255 - i].peBlue);
277 ok( dib_bits[i] == expect, "wrong bits %x/%x at %u,%u\n", dib_bits[i], expect, i % 16, i / 16 );
280 for (i = 0; i < 256; i++) pal->palPalEntry[i].peRed = i * 3;
281 palette2 = CreatePalette( pal );
282 ok( SelectPalette( hdc, palette2, 0 ) != NULL, "SelectPalette failed\n" );
283 memset( dib_bits, 0xaa, 16 * 16 * 4 );
284 PatBlt( hdc, 0, 0, 16, 16, PATCOPY );
285 for (i = 0; i < 256; i++)
287 DWORD expect = (pal->palPalEntry[255 - i].peRed << 16 |
288 pal->palPalEntry[255 - i].peGreen << 8 |
289 pal->palPalEntry[255 - i].peBlue);
290 ok( dib_bits[i] == expect, "wrong bits %x/%x at %u,%u\n", dib_bits[i], expect, i % 16, i / 16 );
294 DeleteObject( brush );
295 DeleteObject( palette );
296 DeleteObject( palette2 );
302 test_pattern_brush();
303 test_palette_brush();