ReactOS  0.4.13-dev-650-g34bf247
NtGdiDoPalette.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for NtGdiDoPalette
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 HPALETTE
12 {
13  struct
14  {
15  LOGPALETTE logpal;
17  } palstruct =
18  { {0x300,5,
19  { {1,2,3,0} }},
20  { {22,33,44,PC_RESERVED},
21  {11,55,77,PC_EXPLICIT},
22  {00,77,66,PC_RESERVED | PC_NOCOLLAPSE},
23  {12,34,56,78}} };
24 
25  return CreatePalette((LOGPALETTE*)&palstruct);
26 }
27 
28 void
30 {
31  HPALETTE hPal;
32  PALETTEENTRY palEntries[5] = {
33  {0,0,0,0},
34  {0xff,0xff,0xff,0},
35  {0x33,0x66,0x99,0},
36  {0x25,0x84,0x14,0},
37  {0x12,0x34,0x56,0x11}};
38  PALETTEENTRY palEntries2[5];
39 
40  /* Test stock palette */
44 
45 
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);
50  DeleteObject(hPal);
51 
52  /* Test PC_RESERVED */
53  hPal = CreateTestPalette();
54  ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, TRUE), 2);
55  DeleteObject(hPal);
56 
57  hPal = CreateTestPalette();
58  ok_long(NtGdiDoPalette(hPal, 1, 5, palEntries, GdiPalAnimate, TRUE), 2);
59  DeleteObject(hPal);
60 
61  hPal = CreateTestPalette();
62  ok_long(NtGdiDoPalette(hPal, 2, 5, palEntries, GdiPalAnimate, TRUE), 1);
63  DeleteObject(hPal);
64 
65  hPal = CreateTestPalette();
66  ok_long(NtGdiDoPalette(hPal, 3, 5, palEntries, GdiPalAnimate, TRUE), 1);
67  DeleteObject(hPal);
68 
69  hPal = CreateTestPalette();
70  ok_long(NtGdiDoPalette(hPal, 4, 5, palEntries, GdiPalAnimate, TRUE), 0);
71  DeleteObject(hPal);
72 
73  hPal = CreateTestPalette();
74  ok_long(NtGdiDoPalette(hPal, 5, 5, palEntries, GdiPalAnimate, TRUE), 0);
75  DeleteObject(hPal);
76 
77  hPal = CreateTestPalette();
78  ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, FALSE), 2);
79  DeleteObject(hPal);
80 
81  hPal = CreateTestPalette();
82  ok_long(NtGdiDoPalette(hPal, 3, 5, palEntries, GdiPalAnimate, FALSE), 1);
83  DeleteObject(hPal);
84 
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);
105  DeleteObject(hPal);
106 
107 }
108 
109 void
111 {
112  HDC hDC;
113  HPALETTE hPal, hOldPal;
114  PALETTEENTRY palEntries[5] = {
115  {0,0,0,0},
116  {0xff,0xff,0xff,0},
117  {0x33,0x66,0x99,0},
118  {0x25,0x84,0x14,0},
119  {0x12,0x34,0x56,0x11}};
120  PALETTEENTRY palEntries2[5];
121 
122  hPal = CreateTestPalette();
123 
124  /* Test invalid handle */
126  ok_long(NtGdiDoPalette((HPALETTE)23, 0, 1, palEntries, GdiPalSetEntries, TRUE), 0);
128 
129  /* Test system palette */
132 
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);
140 
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);
147 
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);
152 
153  ok_long(NtGdiDoPalette(hPal, 0, 4, palEntries2, GdiPalSetEntries, TRUE), 4);
155 
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);
164 
165  /* Test that the buffer was not changed */
166 
167 
168  /* Test with palette selected into dc */
170  hOldPal = SelectPalette(hDC, hPal, 0);
171  ok_long(NtGdiDoPalette(hPal, 0, 4, palEntries, GdiPalSetEntries, TRUE), 4);
172  SelectPalette(hDC, hOldPal, 0);
173 
174  /* Test pEntries = NULL */
175  ok_long(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, TRUE), 0);
176 
177 }
178 
179 void
181 {
182  HPALETTE hPal;
183 
184  hPal = CreateTestPalette();
185 
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);
193 
194 
195 // Test flags 0xf0
196 
197 }
198 
199 void
201 {
202 
203 }
204 
205 void
207 {
208 
209 }
210 
211 void
213 {
214  HDC hdc;
215  HBITMAP hbmp;
216  BYTE *pjBits;
217 
218  struct
219  {
220  BITMAPINFOHEADER bmiHeader;
221  ULONG bmiColors[10];
222  } bmi;
223 
224  hdc = CreateCompatibleDC(0);
225  ok(hdc != NULL, "hdc was NULL.\n");
226 
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");
250 
252 
253  pjBits[0] = 8;
254  pjBits[1] = 1;
255  pjBits[2] = 2;
256  pjBits[3] = 3;
257 
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;
268 
269  SetDCPenColor(hdc, 0xE0E0E0);
270  SetDCBrushColor(hdc, 0x202020);
271  Rectangle(hdc, 0, 0, 10, 10);
272 
273  DeleteDC(hdc);
275 }
276 
278 {
285 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
void Test_NtGdiDoPalette_GdiPalSetEntries(void)
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DIB_PAL_COLORS
Definition: wingdi.h:365
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
void Test_NtGdiDoPalette_GetBIBColorTable(void)
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define ok_int(x, y)
Definition: sprintf.c:21
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
__kernel_entry W32KAPI LONG APIENTRY NtGdiDoPalette(_In_ HGDIOBJ hObj, _In_ WORD iStart, _In_ WORD cEntries, _When_(bInbound!=0, _In_reads_bytes_(cEntries *sizeof(PALETTEENTRY))) _When_(bInbound==0, _Out_writes_bytes_(cEntries *sizeof(PALETTEENTRY))) LPVOID pEntries, _In_ DWORD iFunc, _In_ BOOL bInbound)
Definition: palette.c:1074
void Test_NtGdiDoPalette_GdiPalGetEntries(void)
void Test_NtGdiDoPalette_GetSystemPalette(void)
void Test_NtGdiDoPalette_GdiPalAnimate(void)
COLORREF WINAPI SetDCBrushColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: dc.c:881
#define ok(value,...)
void Test_NtGdiDoPalette_SetDIBColorTable(void)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
HBITMAP hbmp
#define DEFAULT_PALETTE
Definition: wingdi.h:912
RGBQUAD bmiColors[1]
Definition: wingdi.h:1455
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HPALETTE CreateTestPalette()
#define SetLastError(x)
Definition: compat.h:409
#define PC_NOCOLLAPSE
Definition: wingdi.h:880
HDC hdc
Definition: main.c:9
uint32_t entry
Definition: isohybrid.c:63
unsigned char BYTE
Definition: mem.h:68
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
#define PC_RESERVED
Definition: wingdi.h:881
#define ok_long(expression, result)
Definition: test.h:798
unsigned int ULONG
Definition: retypes.h:1
START_TEST(NtGdiDoPalette)
static HBITMAP
Definition: button.c:44
COLORREF WINAPI SetDCPenColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: dc.c:917
#define PC_EXPLICIT
Definition: wingdi.h:879
#define BI_RGB
Definition: precomp.h:34