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_hatch_brush(void)
88 for (i
= 0; i
< 20; i
++)
90 SetLastError( 0xdeadbeef );
91 brush
= CreateHatchBrush( i
, RGB(12,34,56) );
94 ok( brush
!= 0, "%u: CreateHatchBrush failed err %u\n", i
, GetLastError() );
95 size
= GetObject( brush
, sizeof(lb
), &lb
);
96 ok( size
== sizeof(lb
), "wrong size %u\n", size
);
97 ok( lb
.lbColor
== RGB(12,34,56), "wrong color %08x\n", lb
.lbColor
);
98 if (i
<= HS_DIAGCROSS
)
100 ok( lb
.lbStyle
== BS_HATCHED
, "wrong style %u\n", lb
.lbStyle
);
101 ok( lb
.lbHatch
== i
, "wrong hatch %lu/%u\n", lb
.lbHatch
, i
);
105 ok( lb
.lbStyle
== BS_SOLID
, "wrong style %u\n", lb
.lbStyle
);
106 ok( lb
.lbHatch
== 0, "wrong hatch %lu\n", lb
.lbHatch
);
108 DeleteObject( brush
);
112 ok( !brush
, "%u: CreateHatchBrush succeeded\n", i
);
113 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
118 static void test_pattern_brush(void)
120 char buffer
[sizeof(BITMAPINFOHEADER
) + 2 * sizeof(RGBQUAD
) + 32 * 32 / 8];
121 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
130 bitmap
= CreateBitmap( 20, 20, 1, 1, NULL
);
131 ok( bitmap
!= NULL
, "CreateBitmap failed\n" );
132 brush
= CreatePatternBrush( bitmap
);
133 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
134 memset( &br
, 0x55, sizeof(br
) );
135 ret
= GetObjectW( brush
, sizeof(br
), &br
);
136 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
137 ok( br
.lbStyle
== BS_PATTERN
, "wrong style %u\n", br
.lbStyle
);
138 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
139 ok( (HBITMAP
)br
.lbHatch
== bitmap
, "wrong handle %p/%p\n", (HBITMAP
)br
.lbHatch
, bitmap
);
140 DeleteObject( brush
);
142 br
.lbStyle
= BS_PATTERN8X8
;
143 br
.lbColor
= 0x12345;
144 br
.lbHatch
= (ULONG_PTR
)bitmap
;
145 brush
= CreateBrushIndirect( &br
);
146 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
147 memset( &br
, 0x55, sizeof(br
) );
148 ret
= GetObjectW( brush
, sizeof(br
), &br
);
149 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
150 ok( br
.lbStyle
== BS_PATTERN
, "wrong style %u\n", br
.lbStyle
);
151 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
152 ok( (HBITMAP
)br
.lbHatch
== bitmap
, "wrong handle %p/%p\n", (HBITMAP
)br
.lbHatch
, bitmap
);
153 ret
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
154 ok( ret
== sizeof(dib
.dsBm
), "wrong size %u\n", ret
);
155 DeleteObject( bitmap
);
156 ret
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
157 ok( ret
== 0, "wrong size %u\n", ret
);
158 DeleteObject( brush
);
160 memset( info
, 0, sizeof(buffer
) );
161 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
162 info
->bmiHeader
.biHeight
= 32;
163 info
->bmiHeader
.biWidth
= 32;
164 info
->bmiHeader
.biBitCount
= 1;
165 info
->bmiHeader
.biPlanes
= 1;
166 info
->bmiHeader
.biCompression
= BI_RGB
;
167 bitmap
= CreateDIBSection( 0, info
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0 );
168 ok( bitmap
!= NULL
, "CreateDIBSection failed\n" );
170 /* MSDN says a DIB section is not allowed, but it works fine */
171 brush
= CreatePatternBrush( bitmap
);
172 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
173 memset( &br
, 0x55, sizeof(br
) );
174 ret
= GetObjectW( brush
, sizeof(br
), &br
);
175 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
176 ok( br
.lbStyle
== BS_PATTERN
, "wrong style %u\n", br
.lbStyle
);
177 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
178 ok( (HBITMAP
)br
.lbHatch
== bitmap
, "wrong handle %p/%p\n", (HBITMAP
)br
.lbHatch
, bitmap
);
179 ret
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
180 ok( ret
== sizeof(dib
), "wrong size %u\n", ret
);
181 DeleteObject( brush
);
182 DeleteObject( bitmap
);
184 brush
= CreateDIBPatternBrushPt( info
, DIB_RGB_COLORS
);
185 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
186 memset( &br
, 0x55, sizeof(br
) );
187 ret
= GetObjectW( brush
, sizeof(br
), &br
);
188 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
189 ok( br
.lbStyle
== BS_DIBPATTERN
, "wrong style %u\n", br
.lbStyle
);
190 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
191 ok( (BITMAPINFO
*)br
.lbHatch
== info
|| broken(!br
.lbHatch
), /* nt4 */
192 "wrong handle %p/%p\n", (BITMAPINFO
*)br
.lbHatch
, info
);
193 DeleteObject( brush
);
195 br
.lbStyle
= BS_DIBPATTERNPT
;
196 br
.lbColor
= DIB_PAL_COLORS
;
197 br
.lbHatch
= (ULONG_PTR
)info
;
198 brush
= CreateBrushIndirect( &br
);
199 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
200 memset( &br
, 0x55, sizeof(br
) );
201 ret
= GetObjectW( brush
, sizeof(br
), &br
);
202 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
203 ok( br
.lbStyle
== BS_DIBPATTERN
, "wrong style %u\n", br
.lbStyle
);
204 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
205 ok( (BITMAPINFO
*)br
.lbHatch
== info
|| broken(!br
.lbHatch
), /* nt4 */
206 "wrong handle %p/%p\n", (BITMAPINFO
*)br
.lbHatch
, info
);
208 mem
= GlobalAlloc( GMEM_MOVEABLE
, sizeof(buffer
) );
209 memcpy( GlobalLock( mem
), buffer
, sizeof(buffer
) );
211 br
.lbStyle
= BS_DIBPATTERN
;
212 br
.lbColor
= DIB_PAL_COLORS
;
213 br
.lbHatch
= (ULONG_PTR
)mem
;
214 brush
= CreateBrushIndirect( &br
);
215 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
216 memset( &br
, 0x55, sizeof(br
) );
217 ret
= GetObjectW( brush
, sizeof(br
), &br
);
218 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
219 ok( br
.lbStyle
== BS_DIBPATTERN
, "wrong style %u\n", br
.lbStyle
);
220 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
221 ok( (HGLOBAL
)br
.lbHatch
!= mem
, "wrong handle %p/%p\n", (HGLOBAL
)br
.lbHatch
, mem
);
222 bits
= GlobalLock( mem
);
223 ok( (HGLOBAL
)br
.lbHatch
== bits
|| broken(!br
.lbHatch
), /* nt4 */
224 "wrong handle %p/%p\n", (HGLOBAL
)br
.lbHatch
, bits
);
225 ret
= GlobalFlags( mem
);
226 ok( ret
== 2, "wrong flags %x\n", ret
);
227 DeleteObject( brush
);
228 ret
= GlobalFlags( mem
);
229 ok( ret
== 2, "wrong flags %x\n", ret
);
231 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
);
232 ok( brush
!= 0, "CreateDIBPatternBrushPt failed\n" );
233 DeleteObject( brush
);
234 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
+ 1 );
235 ok( brush
!= 0, "CreateDIBPatternBrushPt failed\n" );
236 DeleteObject( brush
);
237 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
+ 2 );
238 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
239 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
+ 3 );
240 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
242 info
->bmiHeader
.biBitCount
= 8;
243 info
->bmiHeader
.biCompression
= BI_RLE8
;
244 brush
= CreateDIBPatternBrushPt( info
, DIB_RGB_COLORS
);
245 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
247 info
->bmiHeader
.biBitCount
= 4;
248 info
->bmiHeader
.biCompression
= BI_RLE4
;
249 brush
= CreateDIBPatternBrushPt( info
, DIB_RGB_COLORS
);
250 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
252 br
.lbStyle
= BS_DIBPATTERN8X8
;
253 br
.lbColor
= DIB_RGB_COLORS
;
254 br
.lbHatch
= (ULONG_PTR
)mem
;
255 brush
= CreateBrushIndirect( &br
);
256 ok( !brush
, "CreatePatternBrush succeeded\n" );
258 br
.lbStyle
= BS_MONOPATTERN
;
259 br
.lbColor
= DIB_RGB_COLORS
;
260 br
.lbHatch
= (ULONG_PTR
)mem
;
261 brush
= CreateBrushIndirect( &br
);
262 ok( !brush
, "CreatePatternBrush succeeded\n" );
264 br
.lbStyle
= BS_INDEXED
;
265 br
.lbColor
= DIB_RGB_COLORS
;
266 br
.lbHatch
= (ULONG_PTR
)mem
;
267 brush
= CreateBrushIndirect( &br
);
268 ok( !brush
, "CreatePatternBrush succeeded\n" );
273 static void test_palette_brush(void)
275 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
) + 16 * 16];
276 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
277 WORD
*indices
= (WORD
*)info
->bmiColors
;
278 char pal_buffer
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
279 LOGPALETTE
*pal
= (LOGPALETTE
*)pal_buffer
;
280 HDC hdc
= CreateCompatibleDC( 0 );
285 HPALETTE palette
, palette2
;
287 memset( info
, 0, sizeof(*info
) );
288 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
289 info
->bmiHeader
.biWidth
= 16;
290 info
->bmiHeader
.biHeight
= 16;
291 info
->bmiHeader
.biPlanes
= 1;
292 info
->bmiHeader
.biBitCount
= 32;
293 info
->bmiHeader
.biCompression
= BI_RGB
;
294 dib
= CreateDIBSection( NULL
, info
, DIB_RGB_COLORS
, (void**)&dib_bits
, NULL
, 0 );
295 ok( dib
!= NULL
, "CreateDIBSection failed\n" );
297 info
->bmiHeader
.biBitCount
= 8;
298 for (i
= 0; i
< 256; i
++) indices
[i
] = 255 - i
;
299 for (i
= 0; i
< 256; i
++) ((BYTE
*)(indices
+ 256))[i
] = i
;
300 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
);
301 ok( brush
!= NULL
, "CreateDIBPatternBrushPt failed\n" );
303 pal
->palVersion
= 0x300;
304 pal
->palNumEntries
= 256;
305 for (i
= 0; i
< 256; i
++)
307 pal
->palPalEntry
[i
].peRed
= i
* 2;
308 pal
->palPalEntry
[i
].peGreen
= i
* 2;
309 pal
->palPalEntry
[i
].peBlue
= i
* 2;
310 pal
->palPalEntry
[i
].peFlags
= 0;
312 palette
= CreatePalette( pal
);
314 ok( SelectObject( hdc
, dib
) != NULL
, "SelectObject failed\n" );
315 ok( SelectPalette( hdc
, palette
, 0 ) != NULL
, "SelectPalette failed\n" );
316 ok( SelectObject( hdc
, brush
) != NULL
, "SelectObject failed\n" );
317 memset( dib_bits
, 0xaa, 16 * 16 * 4 );
318 PatBlt( hdc
, 0, 0, 16, 16, PATCOPY
);
319 for (i
= 0; i
< 256; i
++)
321 DWORD expect
= (pal
->palPalEntry
[255 - i
].peRed
<< 16 |
322 pal
->palPalEntry
[255 - i
].peGreen
<< 8 |
323 pal
->palPalEntry
[255 - i
].peBlue
);
324 ok( dib_bits
[i
] == expect
, "wrong bits %x/%x at %u,%u\n", dib_bits
[i
], expect
, i
% 16, i
/ 16 );
327 for (i
= 0; i
< 256; i
++) pal
->palPalEntry
[i
].peRed
= i
* 3;
328 palette2
= CreatePalette( pal
);
329 ok( SelectPalette( hdc
, palette2
, 0 ) != NULL
, "SelectPalette failed\n" );
330 memset( dib_bits
, 0xaa, 16 * 16 * 4 );
331 PatBlt( hdc
, 0, 0, 16, 16, PATCOPY
);
332 for (i
= 0; i
< 256; i
++)
334 DWORD expect
= (pal
->palPalEntry
[255 - i
].peRed
<< 16 |
335 pal
->palPalEntry
[255 - i
].peGreen
<< 8 |
336 pal
->palPalEntry
[255 - i
].peBlue
);
337 ok( dib_bits
[i
] == expect
, "wrong bits %x/%x at %u,%u\n", dib_bits
[i
], expect
, i
% 16, i
/ 16 );
341 DeleteObject( brush
);
342 DeleteObject( palette
);
343 DeleteObject( palette2
);
350 test_pattern_brush();
351 test_palette_brush();