2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtGdiDoPalette
16 PALETTEENTRY entry
[5];
20 { {22,33,44,PC_RESERVED
},
21 {11,55,77,PC_EXPLICIT
},
22 {00,77,66,PC_RESERVED
| PC_NOCOLLAPSE
},
25 return CreatePalette((LOGPALETTE
*)&palstruct
);
29 Test_NtGdiDoPalette_GdiPalAnimate(void)
32 PALETTEENTRY palEntries
[5] = {
37 {0x12,0x34,0x56,0x11}};
38 PALETTEENTRY palEntries2
[5];
40 /* Test stock palette */
41 SetLastError(ERROR_SUCCESS
);
42 ok_long(NtGdiDoPalette(GetStockObject(DEFAULT_PALETTE
), 0, 1, palEntries
, GdiPalAnimate
, FALSE
), 0);
43 ok_long(GetLastError(), ERROR_SUCCESS
);
46 /* Test pEntries = NULL */
47 hPal
= CreateTestPalette();
48 ok_long(NtGdiDoPalette(hPal
, 0, 1, NULL
, GdiPalAnimate
, TRUE
), 0);
49 ok_long(NtGdiDoPalette(hPal
, 0, 1, NULL
, GdiPalAnimate
, FALSE
), 0);
52 /* Test PC_RESERVED */
53 hPal
= CreateTestPalette();
54 ok_long(NtGdiDoPalette(hPal
, 0, 5, palEntries
, GdiPalAnimate
, TRUE
), 2);
57 hPal
= CreateTestPalette();
58 ok_long(NtGdiDoPalette(hPal
, 1, 5, palEntries
, GdiPalAnimate
, TRUE
), 2);
61 hPal
= CreateTestPalette();
62 ok_long(NtGdiDoPalette(hPal
, 2, 5, palEntries
, GdiPalAnimate
, TRUE
), 1);
65 hPal
= CreateTestPalette();
66 ok_long(NtGdiDoPalette(hPal
, 3, 5, palEntries
, GdiPalAnimate
, TRUE
), 1);
69 hPal
= CreateTestPalette();
70 ok_long(NtGdiDoPalette(hPal
, 4, 5, palEntries
, GdiPalAnimate
, TRUE
), 0);
73 hPal
= CreateTestPalette();
74 ok_long(NtGdiDoPalette(hPal
, 5, 5, palEntries
, GdiPalAnimate
, TRUE
), 0);
77 hPal
= CreateTestPalette();
78 ok_long(NtGdiDoPalette(hPal
, 0, 5, palEntries
, GdiPalAnimate
, FALSE
), 2);
81 hPal
= CreateTestPalette();
82 ok_long(NtGdiDoPalette(hPal
, 3, 5, palEntries
, GdiPalAnimate
, FALSE
), 1);
85 /* Test if entries are set correctly */
86 hPal
= CreateTestPalette();
87 NtGdiDoPalette(hPal
, 0, 5, palEntries
, GdiPalAnimate
, TRUE
);
88 NtGdiDoPalette(hPal
, 0, 5, palEntries2
, GdiPalGetEntries
, FALSE
);
89 ok_int(palEntries2
[0].peRed
, 1);
90 ok_int(palEntries2
[0].peGreen
, 2);
91 ok_int(palEntries2
[0].peBlue
, 3);
92 ok_int(palEntries2
[0].peFlags
, 0);
93 ok_int(palEntries2
[1].peRed
, palEntries
[1].peRed
);
94 ok_int(palEntries2
[1].peGreen
, palEntries
[1].peGreen
);
95 ok_int(palEntries2
[1].peBlue
, palEntries
[1].peBlue
);
96 ok_int(palEntries2
[1].peFlags
, palEntries
[1].peFlags
);
97 ok_int(palEntries2
[2].peRed
, 11);
98 ok_int(palEntries2
[2].peGreen
, 55);
99 ok_int(palEntries2
[2].peBlue
, 77);
100 ok_int(palEntries2
[2].peFlags
, PC_EXPLICIT
);
101 ok_int(palEntries2
[3].peRed
, palEntries
[3].peRed
);
102 ok_int(palEntries2
[3].peGreen
, palEntries
[3].peGreen
);
103 ok_int(palEntries2
[3].peBlue
, palEntries
[3].peBlue
);
104 ok_int(palEntries2
[3].peFlags
, palEntries
[3].peFlags
);
110 Test_NtGdiDoPalette_GdiPalSetEntries(void)
113 HPALETTE hPal
, hOldPal
;
114 PALETTEENTRY palEntries
[5] = {
119 {0x12,0x34,0x56,0x11}};
120 PALETTEENTRY palEntries2
[5];
122 hPal
= CreateTestPalette();
124 /* Test invalid handle */
125 SetLastError(ERROR_SUCCESS
);
126 ok_long(NtGdiDoPalette((HPALETTE
)23, 0, 1, palEntries
, GdiPalSetEntries
, TRUE
), 0);
127 ok_long(GetLastError(), ERROR_SUCCESS
);
129 /* Test system palette */
130 ok_long(NtGdiDoPalette(GetStockObject(DEFAULT_PALETTE
), 0, 1, palEntries
, GdiPalSetEntries
, TRUE
), 0);
131 ok_long(GetLastError(), ERROR_SUCCESS
);
133 ok_long(NtGdiDoPalette(hPal
, 0, 1, palEntries
, GdiPalSetEntries
, TRUE
), 1);
134 ok_long(NtGdiDoPalette(hPal
, 0, 2, palEntries
, GdiPalSetEntries
, TRUE
), 2);
135 ok_long(NtGdiDoPalette(hPal
, 0, 3, palEntries
, GdiPalSetEntries
, TRUE
), 3);
136 ok_long(NtGdiDoPalette(hPal
, 0, 5, palEntries
, GdiPalSetEntries
, TRUE
), 5);
137 ok_long(NtGdiDoPalette(hPal
, 0, 6, palEntries
, GdiPalSetEntries
, TRUE
), 5);
138 ok_long(NtGdiDoPalette(hPal
, 3, 6, palEntries
, GdiPalSetEntries
, TRUE
), 2);
139 // TEST(NtGdiDoPalette(hPal, 4, 23247, palEntries, GdiPalSetEntries, TRUE), 0);
141 /* Test bInbound, FALSE */
142 NtGdiDoPalette(hPal
, 0, 5, palEntries
, GdiPalSetEntries
, TRUE
);
143 ZeroMemory(palEntries2
, sizeof(palEntries2
));
144 ok_long(NtGdiDoPalette(hPal
, 0, 5, palEntries2
, GdiPalSetEntries
, FALSE
), 5);
145 /* we should get the old values returned in our buffer! */
146 ok_int(memcmp(palEntries2
, palEntries
, sizeof(palEntries
)), 0);
148 /* check what we have in our palette now */
149 ZeroMemory(palEntries2
, sizeof(palEntries2
));
150 ok_long(NtGdiDoPalette(hPal
, 0, 5, palEntries2
, GdiPalGetEntries
, FALSE
), 5);
151 ok_int(memcmp(palEntries2
, palEntries
, sizeof(palEntries
)), 0);
153 ok_long(NtGdiDoPalette(hPal
, 0, 4, palEntries2
, GdiPalSetEntries
, TRUE
), 4);
154 ok_long(GetLastError(), ERROR_SUCCESS
);
156 /* Test if entries are set correctly */
157 hPal
= CreateTestPalette();
158 NtGdiDoPalette(hPal
, 0, 5, palEntries
, GdiPalSetEntries
, TRUE
);
159 NtGdiDoPalette(hPal
, 0, 5, palEntries2
, GdiPalGetEntries
, FALSE
);
160 ok_int(palEntries2
[0].peRed
, 0);
161 ok_int(palEntries2
[0].peGreen
, 0);
162 ok_int(palEntries2
[0].peBlue
, 0);
163 ok_int(palEntries2
[0].peFlags
, 0);
165 /* Test that the buffer was not changed */
168 /* Test with palette selected into dc */
169 hDC
= CreateCompatibleDC(NULL
);
170 hOldPal
= SelectPalette(hDC
, hPal
, 0);
171 ok_long(NtGdiDoPalette(hPal
, 0, 4, palEntries
, GdiPalSetEntries
, TRUE
), 4);
172 SelectPalette(hDC
, hOldPal
, 0);
174 /* Test pEntries = NULL */
175 ok_long(NtGdiDoPalette(hPal
, 0, 1, NULL
, GdiPalGetEntries
, TRUE
), 0);
180 Test_NtGdiDoPalette_GdiPalGetEntries(void)
184 hPal
= CreateTestPalette();
186 /* Test pEntries = NULL */
187 ok_long(NtGdiDoPalette(hPal
, 0, 1, NULL
, GdiPalGetEntries
, TRUE
), 0);
188 ok_long(NtGdiDoPalette(hPal
, 0, 1, NULL
, GdiPalGetEntries
, FALSE
), 5);
189 ok_long(NtGdiDoPalette(hPal
, 2, 1, NULL
, GdiPalGetEntries
, FALSE
), 5);
190 ok_long(NtGdiDoPalette(hPal
, 20, 1, NULL
, GdiPalGetEntries
, FALSE
), 5);
191 ok_long(NtGdiDoPalette(hPal
, -20, 1, NULL
, GdiPalGetEntries
, FALSE
), 5);
192 ok_long(NtGdiDoPalette(hPal
, 2, 0, NULL
, GdiPalGetEntries
, FALSE
), 5);
200 Test_NtGdiDoPalette_GetSystemPalette(void)
206 Test_NtGdiDoPalette_GetBIBColorTable(void)
212 Test_NtGdiDoPalette_SetDIBColorTable(void)
220 BITMAPINFOHEADER bmiHeader
;
224 hdc
= CreateCompatibleDC(0);
225 ok(hdc
!= NULL
, "hdc was NULL.\n");
227 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
228 bmi
.bmiHeader
.biWidth
= 10;
229 bmi
.bmiHeader
.biHeight
= 10;
230 bmi
.bmiHeader
.biPlanes
= 1;
231 bmi
.bmiHeader
.biBitCount
= 8;
232 bmi
.bmiHeader
.biCompression
= BI_RGB
;
233 bmi
.bmiHeader
.biSizeImage
= 0;
234 bmi
.bmiHeader
.biXPelsPerMeter
= 1;
235 bmi
.bmiHeader
.biYPelsPerMeter
= 1;
236 bmi
.bmiHeader
.biClrUsed
= 9;
237 bmi
.bmiHeader
.biClrImportant
= 9;
238 bmi
.bmiColors
[0] = 0x000000;
239 bmi
.bmiColors
[1] = 0x202020;
240 bmi
.bmiColors
[2] = 0x404040;
241 bmi
.bmiColors
[3] = 0x606060;
242 bmi
.bmiColors
[4] = 0x808080;
243 bmi
.bmiColors
[5] = 0xA0A0A0;
244 bmi
.bmiColors
[6] = 0xC0C0C0;
245 bmi
.bmiColors
[7] = 0xE0E0E0;
246 bmi
.bmiColors
[8] = 0xffffff;
247 hbmp
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bmi
, DIB_PAL_COLORS
, (PVOID
*)&pjBits
, NULL
, 0);
248 ok(hbmp
!= NULL
, "hbmp was NULL.\n");
249 ok(pjBits
!= NULL
, "pjBits was NULL.\n");
251 SelectObject(hdc
, hbmp
);
258 bmi
.bmiColors
[8] = 0x000000;
259 bmi
.bmiColors
[7] = 0x202020;
260 bmi
.bmiColors
[6] = 0x404040;
261 bmi
.bmiColors
[5] = 0x606060;
262 bmi
.bmiColors
[4] = 0x808080;
263 bmi
.bmiColors
[3] = 0xA0A0A0;
264 bmi
.bmiColors
[2] = 0xC0C0C0;
265 bmi
.bmiColors
[1] = 0xE0E0E0;
266 bmi
.bmiColors
[0] = 0xffffff;
267 ok_long(NtGdiDoPalette(hdc
, 0, 9, &bmi
.bmiColors
, GdiPalSetColorTable
, FALSE
), 9);
269 SetDCPenColor(hdc
, 0xE0E0E0);
270 SetDCBrushColor(hdc
, 0x202020);
271 Rectangle(hdc
, 0, 0, 10, 10);
277 START_TEST(NtGdiDoPalette
)
279 Test_NtGdiDoPalette_GdiPalAnimate();
280 Test_NtGdiDoPalette_GdiPalSetEntries();
281 Test_NtGdiDoPalette_GdiPalGetEntries();
282 Test_NtGdiDoPalette_GetSystemPalette();
283 Test_NtGdiDoPalette_GetBIBColorTable();
284 Test_NtGdiDoPalette_SetDIBColorTable();