Disable some misleading service tests because a test cannot determine wheter or not...
[reactos.git] / apitests / w32knapi / ntgdi / NtGdiDoPalette.c
1 HPALETTE
2 CreateTestPalette()
3 {
4 struct
5 {
6 LOGPALETTE logpal;
7 PALETTEENTRY entry[5];
8 } palstruct =
9 { {0x300,5,
10 { {1,2,3,0} }},
11 { {22,33,44,PC_RESERVED},
12 {11,55,77,PC_EXPLICIT},
13 {00,77,66,PC_RESERVED | PC_NOCOLLAPSE},
14 {12,34,56,78}} };
15
16 return CreatePalette((LOGPALETTE*)&palstruct);
17 }
18
19 INT
20 Test_NtGdiDoPalette_GdiPalAnimate(PTESTINFO pti)
21 {
22 HPALETTE hPal;
23 PALETTEENTRY palEntries[5] = {
24 {0,0,0,0},
25 {0xff,0xff,0xff,0},
26 {0x33,0x66,0x99,0},
27 {0x25,0x84,0x14,0},
28 {0x12,0x34,0x56,0x11}};
29 PALETTEENTRY palEntries2[5];
30
31 /* Test stock palette */
32 SetLastError(ERROR_SUCCESS);
33 RTEST(NtGdiDoPalette(GetStockObject(DEFAULT_PALETTE), 0, 1, palEntries, GdiPalAnimate, FALSE) == 0);
34 RTEST(GetLastError() == ERROR_SUCCESS);
35
36
37 /* Test pEntries = NULL */
38 hPal = CreateTestPalette();
39 RTEST(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalAnimate, TRUE) == 0);
40 RTEST(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalAnimate, FALSE) == 0);
41 DeleteObject(hPal);
42
43 /* Test PC_RESERVED */
44 hPal = CreateTestPalette();
45 RTEST(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, TRUE) == 2);
46 DeleteObject(hPal);
47
48 hPal = CreateTestPalette();
49 RTEST(NtGdiDoPalette(hPal, 1, 5, palEntries, GdiPalAnimate, TRUE) == 2);
50 DeleteObject(hPal);
51
52 hPal = CreateTestPalette();
53 RTEST(NtGdiDoPalette(hPal, 2, 5, palEntries, GdiPalAnimate, TRUE) == 1);
54 DeleteObject(hPal);
55
56 hPal = CreateTestPalette();
57 RTEST(NtGdiDoPalette(hPal, 3, 5, palEntries, GdiPalAnimate, TRUE) == 1);
58 DeleteObject(hPal);
59
60 hPal = CreateTestPalette();
61 RTEST(NtGdiDoPalette(hPal, 4, 5, palEntries, GdiPalAnimate, TRUE) == 0);
62 DeleteObject(hPal);
63
64 hPal = CreateTestPalette();
65 RTEST(NtGdiDoPalette(hPal, 5, 5, palEntries, GdiPalAnimate, TRUE) == 0);
66 DeleteObject(hPal);
67
68 hPal = CreateTestPalette();
69 RTEST(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, FALSE) == 2);
70 DeleteObject(hPal);
71
72 hPal = CreateTestPalette();
73 RTEST(NtGdiDoPalette(hPal, 3, 5, palEntries, GdiPalAnimate, FALSE) == 1);
74 DeleteObject(hPal);
75
76 /* Test if entries are set correctly */
77 hPal = CreateTestPalette();
78 NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, TRUE);
79 NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalGetEntries, FALSE);
80 RTEST(palEntries2[0].peRed == 1);
81 RTEST(palEntries2[0].peGreen == 2);
82 RTEST(palEntries2[0].peBlue == 3);
83 RTEST(palEntries2[0].peFlags == 0);
84 RTEST(palEntries2[1].peRed == palEntries[1].peRed);
85 RTEST(palEntries2[1].peGreen == palEntries[1].peGreen);
86 RTEST(palEntries2[1].peBlue == palEntries[1].peBlue);
87 RTEST(palEntries2[1].peFlags == palEntries[1].peFlags);
88 RTEST(palEntries2[2].peRed == 11);
89 RTEST(palEntries2[2].peGreen == 55);
90 RTEST(palEntries2[2].peBlue == 77);
91 TEST(palEntries2[2].peFlags == PC_EXPLICIT);
92 RTEST(palEntries2[3].peRed == palEntries[3].peRed);
93 RTEST(palEntries2[3].peGreen == palEntries[3].peGreen);
94 RTEST(palEntries2[3].peBlue == palEntries[3].peBlue);
95 RTEST(palEntries2[3].peFlags == palEntries[3].peFlags);
96 DeleteObject(hPal);
97
98
99 return APISTATUS_NORMAL;
100 }
101
102 INT
103 Test_NtGdiDoPalette_GdiPalSetEntries(PTESTINFO pti)
104 {
105 HDC hDC;
106 HPALETTE hPal, hOldPal;
107 PALETTEENTRY palEntries[5] = {
108 {0,0,0,0},
109 {0xff,0xff,0xff,0},
110 {0x33,0x66,0x99,0},
111 {0x25,0x84,0x14,0},
112 {0x12,0x34,0x56,0x11}};
113 PALETTEENTRY palEntries2[5];
114
115 hPal = CreateTestPalette();
116
117 /* Test invalid handle */
118 SetLastError(ERROR_SUCCESS);
119 RTEST(NtGdiDoPalette((HPALETTE)23, 0, 1, palEntries, GdiPalSetEntries, TRUE) == 0);
120 RTEST(GetLastError() == ERROR_SUCCESS);
121
122 /* Test system palette */
123 RTEST(NtGdiDoPalette(GetStockObject(DEFAULT_PALETTE), 0, 1, palEntries, GdiPalSetEntries, TRUE) == 0);
124 RTEST(GetLastError() == ERROR_SUCCESS);
125
126 RTEST(NtGdiDoPalette(hPal, 0, 1, palEntries, GdiPalSetEntries, TRUE) == 1);
127 RTEST(NtGdiDoPalette(hPal, 0, 2, palEntries, GdiPalSetEntries, TRUE) == 2);
128 RTEST(NtGdiDoPalette(hPal, 0, 3, palEntries, GdiPalSetEntries, TRUE) == 3);
129 RTEST(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalSetEntries, TRUE) == 5);
130 RTEST(NtGdiDoPalette(hPal, 0, 6, palEntries, GdiPalSetEntries, TRUE) == 5);
131 RTEST(NtGdiDoPalette(hPal, 3, 6, palEntries, GdiPalSetEntries, TRUE) == 2);
132 // TEST(NtGdiDoPalette(hPal, 4, 23247, palEntries, GdiPalSetEntries, TRUE) == 0);
133
134 /* Test bInbound == FALSE */
135 NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalSetEntries, TRUE);
136 ZeroMemory(palEntries2, sizeof(palEntries2));
137 RTEST(NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalSetEntries, FALSE) == 5);
138 /* we should get the old values returned in our buffer! */
139 TEST(memcmp(palEntries2, palEntries, sizeof(palEntries)) == 0);
140
141 /* check what we have in our palette now */
142 ZeroMemory(palEntries2, sizeof(palEntries2));
143 RTEST(NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalGetEntries, FALSE) == 5);
144 TEST(memcmp(palEntries2, palEntries, sizeof(palEntries)) == 0);
145
146 RTEST(NtGdiDoPalette(hPal, 0, 4, palEntries2, GdiPalSetEntries, TRUE) == 4);
147 RTEST(GetLastError() == ERROR_SUCCESS);
148
149 /* Test if entries are set correctly */
150 hPal = CreateTestPalette();
151 NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalSetEntries, TRUE);
152 NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalGetEntries, FALSE);
153 RTEST(palEntries2[0].peRed == 0);
154 RTEST(palEntries2[0].peGreen == 0);
155 RTEST(palEntries2[0].peBlue == 0);
156 RTEST(palEntries2[0].peFlags == 0);
157
158 /* Test that the buffer was not changed */
159
160
161 /* Test with palette selected into dc */
162 hDC = CreateCompatibleDC(NULL);
163 hOldPal = SelectPalette(hDC, hPal, 0);
164 RTEST(NtGdiDoPalette(hPal, 0, 4, palEntries, GdiPalSetEntries, TRUE) == 4);
165 SelectPalette(hDC, hOldPal, 0);
166
167 /* Test pEntries = NULL */
168 RTEST(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, TRUE) == 0);
169
170 return APISTATUS_NORMAL;
171 }
172
173 INT
174 Test_NtGdiDoPalette_GdiPalGetEntries(PTESTINFO pti)
175 {
176 HPALETTE hPal;
177
178 hPal = CreateTestPalette();
179
180 /* Test pEntries = NULL */
181 RTEST(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, TRUE) == 0);
182 RTEST(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, FALSE) == 5);
183 RTEST(NtGdiDoPalette(hPal, 2, 1, NULL, GdiPalGetEntries, FALSE) == 5);
184 RTEST(NtGdiDoPalette(hPal, 20, 1, NULL, GdiPalGetEntries, FALSE) == 5);
185 RTEST(NtGdiDoPalette(hPal, -20, 1, NULL, GdiPalGetEntries, FALSE) == 5);
186 RTEST(NtGdiDoPalette(hPal, 2, 0, NULL, GdiPalGetEntries, FALSE) == 5);
187
188
189 // Test flags 0xf0
190
191 return APISTATUS_NORMAL;
192 }
193
194 INT
195 Test_NtGdiDoPalette_GetSystemPalette(PTESTINFO pti)
196 {
197 return APISTATUS_NORMAL;
198 }
199
200 INT
201 Test_NtGdiDoPalette_GetBIBColorTable(PTESTINFO pti)
202 {
203 return APISTATUS_NORMAL;
204 }
205
206 INT
207 Test_NtGdiDoPalette_SetDIBColorTable(PTESTINFO pti)
208 {
209 HDC hdc;
210 HBITMAP hbmp;
211 BYTE *pjBits;
212
213 struct
214 {
215 BITMAPINFOHEADER bmiHeader;
216 ULONG bmiColors[10];
217 } bmi;
218
219 hdc = CreateCompatibleDC(0);
220 ASSERT(hdc);
221
222 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
223 bmi.bmiHeader.biWidth = 10;
224 bmi.bmiHeader.biHeight = 10;
225 bmi.bmiHeader.biPlanes = 1;
226 bmi.bmiHeader.biBitCount = 8;
227 bmi.bmiHeader.biCompression = BI_RGB;
228 bmi.bmiHeader.biSizeImage = 0;
229 bmi.bmiHeader.biXPelsPerMeter = 1;
230 bmi.bmiHeader.biYPelsPerMeter = 1;
231 bmi.bmiHeader.biClrUsed = 9;
232 bmi.bmiHeader.biClrImportant = 9;
233 bmi.bmiColors[0] = 0x000000;
234 bmi.bmiColors[1] = 0x202020;
235 bmi.bmiColors[2] = 0x404040;
236 bmi.bmiColors[3] = 0x606060;
237 bmi.bmiColors[4] = 0x808080;
238 bmi.bmiColors[5] = 0xA0A0A0;
239 bmi.bmiColors[6] = 0xC0C0C0;
240 bmi.bmiColors[7] = 0xE0E0E0;
241 bmi.bmiColors[8] = 0xffffff;
242 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmi, DIB_PAL_COLORS, (PVOID*)&pjBits, NULL, 0);
243 ASSERT(hbmp);
244 ASSERT(pjBits);
245
246 SelectObject(hdc, hbmp);
247
248
249 pjBits[0] = 8;
250 pjBits[1] = 1;
251 pjBits[2] = 2;
252 pjBits[3] = 3;
253
254 bmi.bmiColors[8] = 0x000000;
255 bmi.bmiColors[7] = 0x202020;
256 bmi.bmiColors[6] = 0x404040;
257 bmi.bmiColors[5] = 0x606060;
258 bmi.bmiColors[4] = 0x808080;
259 bmi.bmiColors[3] = 0xA0A0A0;
260 bmi.bmiColors[2] = 0xC0C0C0;
261 bmi.bmiColors[1] = 0xE0E0E0;
262 bmi.bmiColors[0] = 0xffffff;
263 TEST(NtGdiDoPalette(hdc, 0, 9, &bmi.bmiColors, GdiPalSetColorTable, FALSE) == 9);
264
265 SetDCPenColor(hdc, 0xE0E0E0);
266 SetDCBrushColor(hdc, 0x202020);
267 Rectangle(hdc, 0, 0, 10, 10);
268
269 DeleteDC(hdc);
270 DeleteObject(hbmp);
271
272 return APISTATUS_NORMAL;
273 }
274
275
276 INT
277 Test_NtGdiDoPalette(PTESTINFO pti)
278 {
279 INT ret;
280
281 ret = Test_NtGdiDoPalette_GdiPalAnimate(pti);
282 if (ret != APISTATUS_NORMAL)
283 {
284 return ret;
285 }
286
287 ret = Test_NtGdiDoPalette_GdiPalSetEntries(pti);
288 if (ret != APISTATUS_NORMAL)
289 {
290 return ret;
291 }
292
293 ret = Test_NtGdiDoPalette_GdiPalGetEntries(pti);
294 if (ret != APISTATUS_NORMAL)
295 {
296 return ret;
297 }
298
299 ret = Test_NtGdiDoPalette_GetSystemPalette(pti);
300 if (ret != APISTATUS_NORMAL)
301 {
302 return ret;
303 }
304
305 ret = Test_NtGdiDoPalette_GetBIBColorTable(pti);
306 if (ret != APISTATUS_NORMAL)
307 {
308 return ret;
309 }
310
311 ret = Test_NtGdiDoPalette_SetDIBColorTable(pti);
312 if (ret != APISTATUS_NORMAL)
313 {
314 return ret;
315 }
316
317 return APISTATUS_NORMAL;
318 }