ReactOS 0.4.16-dev-340-g0540c21
CreateDIBPatternBrush.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for CreateDIBPatternBrush
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8#include "precomp.h"
9
10#include "init.h"
11
12/* New color use parameter. See support.microsoft.com/kb/kbview/108497 */
13#define DIB_PAL_INDICES 2
14
16{
17
18}
19
21{
22 struct
23 {
24 BITMAPINFOHEADER bmiHeader;
25 WORD wColors[4];
26 BYTE ajBuffer[16];
27 } PackedDIB =
28 {
29 {sizeof(BITMAPINFOHEADER), 4, -4, 1, 8, BI_RGB, 0, 1, 1, 4, 0},
30 {0, 1, 2, 7},
31 {0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2},
32 };
33 HBRUSH hbr, hbrOld;
34 HPALETTE hpalOld;
35 LOGBRUSH logbrush;
36
37 SetLastError(0);
42 ok_err(0);
43
44 hbr = CreateDIBPatternBrushPt(&PackedDIB, 0);
45 ok(hbr != 0, "Expected success\n");
46 DeleteObject(hbr);
47 hbr = CreateDIBPatternBrushPt(&PackedDIB, 2);
48 ok(hbr != 0, "Expected success\n");
49 DeleteObject(hbr);
50
51 SetLastError(0);
52 hbr = CreateDIBPatternBrushPt(&PackedDIB, 3);
53 ok(hbr == 0, "Expected failure\n");
55 SetLastError(0);
56 hbr = CreateDIBPatternBrushPt(&PackedDIB, 10);
57 ok(hbr == 0, "Expected failure\n");
59
60 /* Create a DIB brush with palette indices */
61 hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
62 ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
63 if (!hbr) return;
64
65 /* Check the logbrush */
66 ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
67 ok_int(logbrush.lbStyle, BS_DIBPATTERN);
68 ok_hex(logbrush.lbColor, 0);
69 ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
70 "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
71
72 /* Select the brush into the dc */
73 hbrOld = SelectObject(ghdcDIB32, hbr);
74
75 /* Copy it on the dib section */
76 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
77 ok_long((*gpDIB32)[0][0], 0x000000); // 0
78 ok_long((*gpDIB32)[0][1], 0x800000); // 1
79 ok_long((*gpDIB32)[0][2], 0x008000); // 2
80 ok_long((*gpDIB32)[0][3], 0xc0c0c0); // 7
81
82 /* Select a logical palette into the DC */
84 ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError());
85
86 /* Copy it on the dib section */
87 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
88 ok_long((*gpDIB32)[0][0], 0x102030); // 0
89 ok_long((*gpDIB32)[0][1], 0x203040); // 1
90 ok_long((*gpDIB32)[0][2], 0x304050); // 2
91 ok_long((*gpDIB32)[0][3], 0x8090a0); // 7
92
93 /* Select back old palette and destroy the DIB data */
94 SelectPalette(ghdcDIB32, hpalOld, FALSE);
95 memset(gpDIB32, 0x77, sizeof(*gpDIB32));
96
97 /* Copy it on the dib section */
98 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
99 ok_long((*gpDIB32)[0][0], 0x000000); // 0
100 ok_long((*gpDIB32)[0][1], 0x800000); // 1
101 ok_long((*gpDIB32)[0][2], 0x008000); // 2
102 ok_long((*gpDIB32)[0][3], 0xc0c0c0); // 7
103
104 SelectObject(ghdcDIB32, hbrOld);
105 DeleteObject(hbr);
106
107 /* Set some different values */
108 PackedDIB.ajBuffer[0] = 3;
109 PackedDIB.ajBuffer[1] = 2;
110 PackedDIB.ajBuffer[2] = 1;
111 PackedDIB.ajBuffer[3] = 0;
112
113 /* Create a DIB brush with DIB_PAL_INDICES */
114 hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_INDICES);
115 ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n");
116 if (!hbr) return;
117
118 /* Check the logbrush */
119 ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
120 ok_int(logbrush.lbStyle, BS_DIBPATTERN);
121 ok_hex(logbrush.lbColor, 0);
122 ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
123 "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
124
125 /* Select the brush into the dc */
126 hbrOld = SelectObject(ghdcDIB32, hbr);
127 ok(hbrOld != 0, "CreateSolidBrush failed, skipping tests.\n");
128
129 /* Copy it on a dib section */
130 memset(gpDIB32, 0x77, sizeof(*gpDIB32));
131 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
132 ok_long((*gpDIB32)[0][0], 0x77777777);
133 ok_long((*gpDIB32)[0][1], 0x77777777);
134 ok_long((*gpDIB32)[0][2], 0x77777777);
135 ok_long((*gpDIB32)[0][3], 0x77777777);
136
137 /* Select a logical palette into the DC */
138 hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE);
139 ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError());
140
141 /* Copy it on a dib section */
142 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
143 ok_long((*gpDIB32)[0][0], 0x77777777);
144 ok_long((*gpDIB32)[0][1], 0x77777777);
145 ok_long((*gpDIB32)[0][2], 0x77777777);
146 ok_long((*gpDIB32)[0][3], 0x77777777);
147
148 SelectPalette(ghdcDIB32, hpalOld, FALSE);
149 SelectObject(ghdcDIB32, hbrOld);
150 DeleteObject(hbr);
151
152}
153
155{
156 struct
157 {
158 BITMAPINFOHEADER bmiHeader;
159 WORD wColors[4];
160 BYTE ajBuffer[20];
161 } PackedDIB =
162 {
163 {sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
164 {0, 1, 2, 7},
165 {4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, },
166 };
167 HBRUSH hbr;
168
170 HBITMAP hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
171 ok(hbmp != 0, "CreateDIBitmap failed, skipping tests.\n");
172
173 /* Create a DIB brush with palette indices */
174 hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
175 ok(hbr == 0, "CreateDIBPatternBrushPt should fail.\n");
176
177
178}
179
180
182{
183 InitStuff();
184
187 //Test_CreateDIBPatternBrushPt_RLE8(); broken
188}
189
void Test_CreateDIBPatternBrushPt()
#define DIB_PAL_INDICES
void Test_CreateDIBPatternBrush()
void Test_CreateDIBPatternBrushPt_RLE8()
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok_hdl
Definition: atltest.h:136
#define ok(value,...)
Definition: atltest.h:57
#define ok_err(error)
Definition: atltest.h:124
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define BI_RGB
Definition: precomp.h:56
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
ULONG(* gpDIB32)[8][8]
Definition: init.c:10
HDC ghdcDIB32
Definition: init.c:8
HPALETTE ghpal
Definition: init.c:11
BOOL InitStuff(void)
Definition: init.c:95
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
#define memset(x, y, z)
Definition: compat.h:39
UINT lbStyle
Definition: wingdi.h:1747
ULONG_PTR lbHatch
Definition: wingdi.h:1749
COLORREF lbColor
Definition: wingdi.h:1748
uint32_t ULONG_PTR
Definition: typedefs.h:65
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HBRUSH WINAPI CreateDIBPatternBrush(_In_ HGLOBAL hglbDIBPacked, _In_ UINT uUsage)
#define DIB_PAL_COLORS
Definition: wingdi.h:366
#define BS_DIBPATTERN
Definition: wingdi.h:1092
#define PATCOPY
Definition: wingdi.h:335
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define CBM_INIT
Definition: wingdi.h:365
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)
#define BI_RLE8
Definition: wingdi.h:35
#define GetObject
Definition: wingdi.h:4468
HBITMAP WINAPI CreateDIBitmap(_In_ HDC hdc, _In_opt_ const BITMAPINFOHEADER *pbmih, _In_ DWORD fdwInit, _In_opt_ const VOID *pvInit, _In_opt_ const BITMAPINFO *pbmi, _In_ UINT uUsage)
unsigned char BYTE
Definition: xxhash.c:193