74209953169e07d059a81bb88bc4518a3dec9f1c
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
23 typedef struct _STOCK_BRUSH
{
29 static void test_solidbrush(void)
31 static const STOCK_BRUSH stock
[] = {
32 {RGB(255,255,255), WHITE_BRUSH
, "white"},
33 {RGB(192,192,192), LTGRAY_BRUSH
, "ltgray"},
34 {RGB(128,128,128), GRAY_BRUSH
, "gray"},
35 {RGB(0,0,0), BLACK_BRUSH
, "black"},
36 {RGB(0,0,255), -1, "blue"}
44 for(i
=0; i
<sizeof(stock
)/sizeof(stock
[0]); i
++) {
45 solidBrush
= CreateSolidBrush(stock
[i
].color
);
47 if(stock
[i
].stockobj
!= -1) {
48 stockBrush
= GetStockObject(stock
[i
].stockobj
);
49 ok(stockBrush
!=solidBrush
||
50 broken(stockBrush
==solidBrush
), /* win9x does return stock object */
51 "Stock %s brush equals solid %s brush\n", stock
[i
].name
, stock
[i
].name
);
55 memset(&br
, 0, sizeof(br
));
56 ret
= GetObjectW(solidBrush
, sizeof(br
), &br
);
57 ok( ret
!=0, "GetObject on solid %s brush failed, error=%d\n", stock
[i
].name
, GetLastError());
58 ok(br
.lbStyle
==BS_SOLID
, "%s brush has wrong style, got %d expected %d\n", stock
[i
].name
, br
.lbStyle
, BS_SOLID
);
59 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
);
62 /* Sanity check, make sure the colors being compared do in fact have a stock brush */
63 ret
= GetObjectW(stockBrush
, sizeof(br
), &br
);
64 ok( ret
!=0, "GetObject on stock %s brush failed, error=%d\n", stock
[i
].name
, GetLastError());
65 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
);
68 DeleteObject(solidBrush
);
69 ret
= GetObjectW(solidBrush
, sizeof(br
), &br
);
71 broken(ret
!=0), /* win9x */
72 "GetObject succeeded on a deleted %s brush\n", stock
[i
].name
);
76 static void test_hatch_brush(void)
82 for (i
= 0; i
< 20; i
++)
84 SetLastError( 0xdeadbeef );
85 brush
= CreateHatchBrush( i
, RGB(12,34,56) );
88 ok( brush
!= 0, "%u: CreateHatchBrush failed err %u\n", i
, GetLastError() );
89 size
= GetObjectW( brush
, sizeof(lb
), &lb
);
90 ok( size
== sizeof(lb
), "wrong size %u\n", size
);
91 ok( lb
.lbColor
== RGB(12,34,56), "wrong color %08x\n", lb
.lbColor
);
92 if (i
<= HS_DIAGCROSS
)
94 ok( lb
.lbStyle
== BS_HATCHED
, "wrong style %u\n", lb
.lbStyle
);
95 ok( lb
.lbHatch
== i
, "wrong hatch %lu/%u\n", lb
.lbHatch
, i
);
99 ok( lb
.lbStyle
== BS_SOLID
, "wrong style %u\n", lb
.lbStyle
);
100 ok( lb
.lbHatch
== 0, "wrong hatch %lu\n", lb
.lbHatch
);
102 DeleteObject( brush
);
106 ok( !brush
, "%u: CreateHatchBrush succeeded\n", i
);
107 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
112 static void test_pattern_brush(void)
114 char buffer
[sizeof(BITMAPINFOHEADER
) + 2 * sizeof(RGBQUAD
) + 32 * 32 / 8];
115 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
124 bitmap
= CreateBitmap( 20, 20, 1, 1, NULL
);
125 ok( bitmap
!= NULL
, "CreateBitmap failed\n" );
126 brush
= CreatePatternBrush( bitmap
);
127 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
128 memset( &br
, 0x55, sizeof(br
) );
129 ret
= GetObjectW( brush
, sizeof(br
), &br
);
130 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
131 ok( br
.lbStyle
== BS_PATTERN
, "wrong style %u\n", br
.lbStyle
);
132 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
133 ok( (HBITMAP
)br
.lbHatch
== bitmap
, "wrong handle %p/%p\n", (HBITMAP
)br
.lbHatch
, bitmap
);
134 DeleteObject( brush
);
136 br
.lbStyle
= BS_PATTERN8X8
;
137 br
.lbColor
= 0x12345;
138 br
.lbHatch
= (ULONG_PTR
)bitmap
;
139 brush
= CreateBrushIndirect( &br
);
140 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
141 memset( &br
, 0x55, sizeof(br
) );
142 ret
= GetObjectW( brush
, sizeof(br
), &br
);
143 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
144 ok( br
.lbStyle
== BS_PATTERN
, "wrong style %u\n", br
.lbStyle
);
145 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
146 ok( (HBITMAP
)br
.lbHatch
== bitmap
, "wrong handle %p/%p\n", (HBITMAP
)br
.lbHatch
, bitmap
);
147 ret
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
148 ok( ret
== sizeof(dib
.dsBm
), "wrong size %u\n", ret
);
149 DeleteObject( bitmap
);
150 ret
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
151 ok( ret
== 0, "wrong size %u\n", ret
);
152 DeleteObject( brush
);
154 memset( info
, 0, sizeof(buffer
) );
155 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
156 info
->bmiHeader
.biHeight
= 32;
157 info
->bmiHeader
.biWidth
= 32;
158 info
->bmiHeader
.biBitCount
= 1;
159 info
->bmiHeader
.biPlanes
= 1;
160 info
->bmiHeader
.biCompression
= BI_RGB
;
161 bitmap
= CreateDIBSection( 0, info
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0 );
162 ok( bitmap
!= NULL
, "CreateDIBSection failed\n" );
164 /* MSDN says a DIB section is not allowed, but it works fine */
165 brush
= CreatePatternBrush( bitmap
);
166 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
167 memset( &br
, 0x55, sizeof(br
) );
168 ret
= GetObjectW( brush
, sizeof(br
), &br
);
169 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
170 ok( br
.lbStyle
== BS_PATTERN
, "wrong style %u\n", br
.lbStyle
);
171 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
172 ok( (HBITMAP
)br
.lbHatch
== bitmap
, "wrong handle %p/%p\n", (HBITMAP
)br
.lbHatch
, bitmap
);
173 ret
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
174 ok( ret
== sizeof(dib
), "wrong size %u\n", ret
);
175 DeleteObject( brush
);
176 DeleteObject( bitmap
);
178 brush
= CreateDIBPatternBrushPt( info
, DIB_RGB_COLORS
);
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( (BITMAPINFO
*)br
.lbHatch
== info
|| broken(!br
.lbHatch
), /* nt4 */
186 "wrong handle %p/%p\n", (BITMAPINFO
*)br
.lbHatch
, info
);
187 DeleteObject( brush
);
189 br
.lbStyle
= BS_DIBPATTERNPT
;
190 br
.lbColor
= DIB_PAL_COLORS
;
191 br
.lbHatch
= (ULONG_PTR
)info
;
192 brush
= CreateBrushIndirect( &br
);
193 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
194 memset( &br
, 0x55, sizeof(br
) );
195 ret
= GetObjectW( brush
, sizeof(br
), &br
);
196 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
197 ok( br
.lbStyle
== BS_DIBPATTERN
, "wrong style %u\n", br
.lbStyle
);
198 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
199 ok( (BITMAPINFO
*)br
.lbHatch
== info
|| broken(!br
.lbHatch
), /* nt4 */
200 "wrong handle %p/%p\n", (BITMAPINFO
*)br
.lbHatch
, info
);
202 mem
= GlobalAlloc( GMEM_MOVEABLE
, sizeof(buffer
) );
203 memcpy( GlobalLock( mem
), buffer
, sizeof(buffer
) );
205 br
.lbStyle
= BS_DIBPATTERN
;
206 br
.lbColor
= DIB_PAL_COLORS
;
207 br
.lbHatch
= (ULONG_PTR
)mem
;
208 brush
= CreateBrushIndirect( &br
);
209 ok( brush
!= NULL
, "CreatePatternBrush failed\n" );
210 memset( &br
, 0x55, sizeof(br
) );
211 ret
= GetObjectW( brush
, sizeof(br
), &br
);
212 ok( ret
== sizeof(br
), "wrong size %u\n", ret
);
213 ok( br
.lbStyle
== BS_DIBPATTERN
, "wrong style %u\n", br
.lbStyle
);
214 ok( br
.lbColor
== 0, "wrong color %u\n", br
.lbColor
);
215 ok( (HGLOBAL
)br
.lbHatch
!= mem
, "wrong handle %p/%p\n", (HGLOBAL
)br
.lbHatch
, mem
);
216 bits
= GlobalLock( mem
);
217 ok( (HGLOBAL
)br
.lbHatch
== bits
|| broken(!br
.lbHatch
), /* nt4 */
218 "wrong handle %p/%p\n", (HGLOBAL
)br
.lbHatch
, bits
);
219 ret
= GlobalFlags( mem
);
220 ok( ret
== 2, "wrong flags %x\n", ret
);
221 DeleteObject( brush
);
222 ret
= GlobalFlags( mem
);
223 ok( ret
== 2, "wrong flags %x\n", ret
);
225 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
);
226 ok( brush
!= 0, "CreateDIBPatternBrushPt failed\n" );
227 DeleteObject( brush
);
228 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
+ 1 );
229 ok( brush
!= 0, "CreateDIBPatternBrushPt failed\n" );
230 DeleteObject( brush
);
231 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
+ 2 );
232 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
233 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
+ 3 );
234 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
236 info
->bmiHeader
.biBitCount
= 8;
237 info
->bmiHeader
.biCompression
= BI_RLE8
;
238 brush
= CreateDIBPatternBrushPt( info
, DIB_RGB_COLORS
);
239 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
241 info
->bmiHeader
.biBitCount
= 4;
242 info
->bmiHeader
.biCompression
= BI_RLE4
;
243 brush
= CreateDIBPatternBrushPt( info
, DIB_RGB_COLORS
);
244 ok( !brush
, "CreateDIBPatternBrushPt succeeded\n" );
246 br
.lbStyle
= BS_DIBPATTERN8X8
;
247 br
.lbColor
= DIB_RGB_COLORS
;
248 br
.lbHatch
= (ULONG_PTR
)mem
;
249 brush
= CreateBrushIndirect( &br
);
250 ok( !brush
, "CreatePatternBrush succeeded\n" );
252 br
.lbStyle
= BS_MONOPATTERN
;
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_INDEXED
;
259 br
.lbColor
= DIB_RGB_COLORS
;
260 br
.lbHatch
= (ULONG_PTR
)mem
;
261 brush
= CreateBrushIndirect( &br
);
262 ok( !brush
, "CreatePatternBrush succeeded\n" );
267 static void test_palette_brush(void)
269 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
) + 16 * 16];
270 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
271 WORD
*indices
= (WORD
*)info
->bmiColors
;
272 char pal_buffer
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
273 LOGPALETTE
*pal
= (LOGPALETTE
*)pal_buffer
;
274 HDC hdc
= CreateCompatibleDC( 0 );
279 HPALETTE palette
, palette2
;
281 memset( info
, 0, sizeof(*info
) );
282 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
283 info
->bmiHeader
.biWidth
= 16;
284 info
->bmiHeader
.biHeight
= 16;
285 info
->bmiHeader
.biPlanes
= 1;
286 info
->bmiHeader
.biBitCount
= 32;
287 info
->bmiHeader
.biCompression
= BI_RGB
;
288 dib
= CreateDIBSection( NULL
, info
, DIB_RGB_COLORS
, (void**)&dib_bits
, NULL
, 0 );
289 ok( dib
!= NULL
, "CreateDIBSection failed\n" );
291 info
->bmiHeader
.biBitCount
= 8;
292 for (i
= 0; i
< 256; i
++) indices
[i
] = 255 - i
;
293 for (i
= 0; i
< 256; i
++) ((BYTE
*)(indices
+ 256))[i
] = i
;
294 brush
= CreateDIBPatternBrushPt( info
, DIB_PAL_COLORS
);
295 ok( brush
!= NULL
, "CreateDIBPatternBrushPt failed\n" );
297 pal
->palVersion
= 0x300;
298 pal
->palNumEntries
= 256;
299 for (i
= 0; i
< 256; i
++)
301 pal
->palPalEntry
[i
].peRed
= i
* 2;
302 pal
->palPalEntry
[i
].peGreen
= i
* 2;
303 pal
->palPalEntry
[i
].peBlue
= i
* 2;
304 pal
->palPalEntry
[i
].peFlags
= 0;
306 palette
= CreatePalette( pal
);
308 ok( SelectObject( hdc
, dib
) != NULL
, "SelectObject failed\n" );
309 ok( SelectPalette( hdc
, palette
, 0 ) != NULL
, "SelectPalette failed\n" );
310 ok( SelectObject( hdc
, brush
) != NULL
, "SelectObject failed\n" );
311 memset( dib_bits
, 0xaa, 16 * 16 * 4 );
312 PatBlt( hdc
, 0, 0, 16, 16, PATCOPY
);
313 for (i
= 0; i
< 256; i
++)
315 DWORD expect
= (pal
->palPalEntry
[255 - i
].peRed
<< 16 |
316 pal
->palPalEntry
[255 - i
].peGreen
<< 8 |
317 pal
->palPalEntry
[255 - i
].peBlue
);
318 ok( dib_bits
[i
] == expect
, "wrong bits %x/%x at %u,%u\n", dib_bits
[i
], expect
, i
% 16, i
/ 16 );
321 for (i
= 0; i
< 256; i
++) pal
->palPalEntry
[i
].peRed
= i
* 3;
322 palette2
= CreatePalette( pal
);
323 ok( SelectPalette( hdc
, palette2
, 0 ) != NULL
, "SelectPalette failed\n" );
324 memset( dib_bits
, 0xaa, 16 * 16 * 4 );
325 PatBlt( hdc
, 0, 0, 16, 16, PATCOPY
);
326 for (i
= 0; i
< 256; i
++)
328 DWORD expect
= (pal
->palPalEntry
[255 - i
].peRed
<< 16 |
329 pal
->palPalEntry
[255 - i
].peGreen
<< 8 |
330 pal
->palPalEntry
[255 - i
].peBlue
);
331 ok( dib_bits
[i
] == expect
, "wrong bits %x/%x at %u,%u\n", dib_bits
[i
], expect
, i
% 16, i
/ 16 );
335 DeleteObject( brush
);
336 DeleteObject( palette
);
337 DeleteObject( palette2
);
340 static void test_brush_org( void )
342 HDC hdc
= GetDC( 0 );
345 SetBrushOrgEx( hdc
, 0, 0, &old
);
347 SetBrushOrgEx( hdc
, 1, 1, &pt
);
348 ok( pt
.x
== 0 && pt
.y
== 0, "got %d,%d\n", pt
.x
, pt
.y
);
349 SetBrushOrgEx( hdc
, 0x10000, -1, &pt
);
350 ok( pt
.x
== 1 && pt
.y
== 1, "got %d,%d\n", pt
.x
, pt
.y
);
351 SetBrushOrgEx( hdc
, old
.x
, old
.y
, &pt
);
352 ok( pt
.x
== 0x10000 && pt
.y
== -1, "got %d,%d\n", pt
.x
, pt
.y
);
361 test_pattern_brush();
362 test_palette_brush();