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 https://www.betaarchive.com/wiki/index.php?title=Microsoft_KB_Archive/108497 */
13 #define DIB_PAL_INDICES 2
14
Test_CreateDIBPatternBrush()15 void Test_CreateDIBPatternBrush()
16 {
17
18 }
19
Test_CreateDIBPatternBrushPt()20 void Test_CreateDIBPatternBrushPt()
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);
38 ok_hdl(CreateDIBPatternBrushPt(NULL, 0), NULL);
39 ok_hdl(CreateDIBPatternBrushPt(NULL, DIB_PAL_COLORS), NULL);
40 ok_hdl(CreateDIBPatternBrushPt(NULL, 2), NULL);
41 ok_hdl(CreateDIBPatternBrushPt(NULL, 3), NULL);
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");
54 ok_err(ERROR_INVALID_PARAMETER);
55 SetLastError(0);
56 hbr = CreateDIBPatternBrushPt(&PackedDIB, 10);
57 ok(hbr == 0, "Expected failure\n");
58 ok_err(ERROR_INVALID_PARAMETER);
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 */
83 hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE);
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
Test_CreateDIBPatternBrushPt_RLE8()154 void Test_CreateDIBPatternBrushPt_RLE8()
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
169 HDC hdc = CreateCompatibleDC(0);
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
START_TEST(CreateDIBPatternBrush)181 START_TEST(CreateDIBPatternBrush)
182 {
183 InitStuff();
184
185 Test_CreateDIBPatternBrush();
186 Test_CreateDIBPatternBrushPt();
187 //Test_CreateDIBPatternBrushPt_RLE8(); broken
188 }
189
190