[KMTESTS:MM]
[reactos.git] / rostests / apitests / gdi32 / CreateDIBPatternBrush.c
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 <apitest.h>
9
10 #include <wingdi.h>
11 #include "init.h"
12
13 /* New color use parameter. See support.microsoft.com/kb/kbview/108497 */
14 #define DIB_PAL_INDICES 2
15
16 void Test_CreateDIBPatternBrush()
17 {
18
19 }
20
21 void Test_CreateDIBPatternBrushPt()
22 {
23 struct
24 {
25 BITMAPINFOHEADER bmiHeader;
26 WORD wColors[4];
27 BYTE ajBuffer[16];
28 } PackedDIB =
29 {
30 {sizeof(BITMAPINFOHEADER), 4, -4, 1, 8, BI_RGB, 0, 1, 1, 4, 0},
31 {0, 1, 2, 7},
32 {0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2},
33 };
34 HBRUSH hbr, hbrOld;
35 HPALETTE hpalOld;
36 LOGBRUSH logbrush;
37
38 SetLastError(0);
39 ok_hdl(CreateDIBPatternBrushPt(NULL, 0), NULL);
40 ok_hdl(CreateDIBPatternBrushPt(NULL, DIB_PAL_COLORS), NULL);
41 ok_hdl(CreateDIBPatternBrushPt(NULL, 2), NULL);
42 ok_hdl(CreateDIBPatternBrushPt(NULL, 3), NULL);
43 ok_err(0);
44
45 hbr = CreateDIBPatternBrushPt(&PackedDIB, 0);
46 ok(hbr != 0, "Expected success\n");
47 DeleteObject(hbr);
48 hbr = CreateDIBPatternBrushPt(&PackedDIB, 2);
49 ok(hbr != 0, "Expected success\n");
50 DeleteObject(hbr);
51
52 SetLastError(0);
53 hbr = CreateDIBPatternBrushPt(&PackedDIB, 3);
54 ok(hbr == 0, "Expected failure\n");
55 ok_err(ERROR_INVALID_PARAMETER);
56 SetLastError(0);
57 hbr = CreateDIBPatternBrushPt(&PackedDIB, 10);
58 ok(hbr == 0, "Expected failure\n");
59 ok_err(ERROR_INVALID_PARAMETER);
60
61 /* Create a DIB brush with palette indices */
62 hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
63 ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
64 if (!hbr) return;
65
66 /* Check the logbrush */
67 ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
68 ok_int(logbrush.lbStyle, BS_DIBPATTERN);
69 ok_hex(logbrush.lbColor, 0);
70 ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
71 "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
72
73 /* Select the brush into the dc */
74 hbrOld = SelectObject(ghdcDIB32, hbr);
75
76 /* Copy it on the dib section */
77 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
78 ok_long((*gpDIB32)[0][0], 0x000000); // 0
79 ok_long((*gpDIB32)[0][1], 0x800000); // 1
80 ok_long((*gpDIB32)[0][2], 0x008000); // 2
81 ok_long((*gpDIB32)[0][3], 0xc0c0c0); // 7
82
83 /* Select a logical palette into the DC */
84 hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE);
85 ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError());
86
87 /* Copy it on the dib section */
88 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
89 ok_long((*gpDIB32)[0][0], 0x102030); // 0
90 ok_long((*gpDIB32)[0][1], 0x203040); // 1
91 ok_long((*gpDIB32)[0][2], 0x304050); // 2
92 ok_long((*gpDIB32)[0][3], 0x8090a0); // 7
93
94 /* Select back old palette and destroy the DIB data */
95 SelectPalette(ghdcDIB32, hpalOld, FALSE);
96 memset(gpDIB32, 0x77, sizeof(*gpDIB32));
97
98 /* Copy it on the dib section */
99 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
100 ok_long((*gpDIB32)[0][0], 0x000000); // 0
101 ok_long((*gpDIB32)[0][1], 0x800000); // 1
102 ok_long((*gpDIB32)[0][2], 0x008000); // 2
103 ok_long((*gpDIB32)[0][3], 0xc0c0c0); // 7
104
105 SelectObject(ghdcDIB32, hbrOld);
106 DeleteObject(hbr);
107
108 /* Set some different values */
109 PackedDIB.ajBuffer[0] = 3;
110 PackedDIB.ajBuffer[1] = 2;
111 PackedDIB.ajBuffer[2] = 1;
112 PackedDIB.ajBuffer[3] = 0;
113
114 /* Create a DIB brush with DIB_PAL_INDICES */
115 hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_INDICES);
116 ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n");
117 if (!hbr) return;
118
119 /* Check the logbrush */
120 ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
121 ok_int(logbrush.lbStyle, BS_DIBPATTERN);
122 ok_hex(logbrush.lbColor, 0);
123 ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
124 "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
125
126 /* Select the brush into the dc */
127 hbrOld = SelectObject(ghdcDIB32, hbr);
128 ok(hbrOld != 0, "CreateSolidBrush failed, skipping tests.\n");
129
130 /* Copy it on a dib section */
131 memset(gpDIB32, 0x77, sizeof(*gpDIB32));
132 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
133 ok_long((*gpDIB32)[0][0], 0x77777777);
134 ok_long((*gpDIB32)[0][1], 0x77777777);
135 ok_long((*gpDIB32)[0][2], 0x77777777);
136 ok_long((*gpDIB32)[0][3], 0x77777777);
137
138 /* Select a logical palette into the DC */
139 hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE);
140 ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError());
141
142 /* Copy it on a dib section */
143 ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
144 ok_long((*gpDIB32)[0][0], 0x77777777);
145 ok_long((*gpDIB32)[0][1], 0x77777777);
146 ok_long((*gpDIB32)[0][2], 0x77777777);
147 ok_long((*gpDIB32)[0][3], 0x77777777);
148
149 SelectPalette(ghdcDIB32, hpalOld, FALSE);
150 SelectObject(ghdcDIB32, hbrOld);
151 DeleteObject(hbr);
152
153 }
154
155 void Test_CreateDIBPatternBrushPt_RLE8()
156 {
157 struct
158 {
159 BITMAPINFOHEADER bmiHeader;
160 WORD wColors[4];
161 BYTE ajBuffer[20];
162 } PackedDIB =
163 {
164 {sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
165 {0, 1, 2, 7},
166 {4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, },
167 };
168 HBRUSH hbr;
169
170 HDC hdc = CreateCompatibleDC(0);
171 HBITMAP hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
172 ok(hbmp != 0, "CreateDIBitmap failed, skipping tests.\n");
173
174 /* Create a DIB brush with palette indices */
175 hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
176 ok(hbr == 0, "CreateDIBPatternBrushPt should fail.\n");
177
178
179 }
180
181
182 START_TEST(CreateDIBPatternBrush)
183 {
184 InitStuff();
185
186 Test_CreateDIBPatternBrush();
187 Test_CreateDIBPatternBrushPt();
188 //Test_CreateDIBPatternBrushPt_RLE8(); broken
189 }
190