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