1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetPixel
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include "precomp.h"
9
10 #include <mmsystem.h>
11
12 static struct
13 {
14 WORD palVersion;
15 WORD palNumEntries;
16 PALETTEENTRY logpalettedata[8];
17 } gpal =
18 {
19 0x300, 8,
20 {
21 { 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
22 { 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
23 { 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
24 { 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
25 { 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
26 { 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
27 { 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
28 { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
29 }
30 };
31
Test_SetPixel_Params()32 void Test_SetPixel_Params()
33 {
34 HDC hdc;
35
36 SetLastError(0);
37 ok_long(SetPixel(0, 0, 0, RGB(255,255,255)), -1);
38 ok_err(ERROR_INVALID_HANDLE);
39
40 /* Test an info DC */
41 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
42 ok(hdc != 0, "\n");
43 SetLastError(0);
44 ok_long(SetPixel(hdc, 0, 0, 0), -1);
45 ok_long(SetPixel(hdc, 0, 0, RGB(255,255,255)), -1);
46 ok_err(0);
47 DeleteDC(hdc);
48
49 /* Test a mem DC without selecting a bitmap */
50 hdc = CreateCompatibleDC(NULL);
51 ok(hdc != 0, "\n");
52 SetLastError(0);
53 ok_long(SetPixel(hdc, 0, 0, 0), -1);
54 ok_err(0);
55 DeleteDC(hdc);
56
57 /* Test deleted DC */
58 ok_long(SetPixel(hdc, 0, 0, 0), -1);
59
60 }
61
Test_SetPixel_PAL()62 void Test_SetPixel_PAL()
63 {
64 struct
65 {
66 BITMAPINFOHEADER bmiHeader;
67 WORD bmiColors[8];
68 } bmibuffer;
69 BITMAPINFO *pbmi = (PVOID)&bmibuffer;
70 HBITMAP hbmp;
71 HDC hdc;
72 HPALETTE hpal, hpalOld;
73 PULONG pulBits;
74 USHORT i;
75
76 /* Initialize the BITMAPINFO */
77 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
78 pbmi->bmiHeader.biWidth = 1;
79 pbmi->bmiHeader.biHeight = 1;
80 pbmi->bmiHeader.biPlanes = 1;
81 pbmi->bmiHeader.biBitCount = 8;
82 pbmi->bmiHeader.biCompression = BI_RGB;
83 pbmi->bmiHeader.biSizeImage = 0;
84 pbmi->bmiHeader.biXPelsPerMeter = 1;
85 pbmi->bmiHeader.biYPelsPerMeter = 1;
86 pbmi->bmiHeader.biClrUsed = 8;
87 pbmi->bmiHeader.biClrImportant = 0;
88 for( i = 0; i < 8; i++ )
89 {
90 bmibuffer.bmiColors[i] = i + 1;
91 }
92
93 /* Create a memory DC */
94 hdc = CreateCompatibleDC(0);
95 ok(hdc != 0, "failed\n");
96
97 /* Create a DIB section and select it */
98 hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pulBits, 0, 0 );
99 ok(hbmp != NULL, "CreateDIBSection failed with error %ld\n", GetLastError());
100 ok(SelectObject(hdc, hbmp) != 0, "SelectObject failed\n");
101
102 ok_long(SetPixel(hdc, 0, 0, 0), 0);
103 ok_long(pulBits[0], 8);
104 ok_long(SetPixel(hdc, 0, 0, 1), 0);
105 ok_long(pulBits[0], 8);
106 ok_long(SetPixel(hdc, 0, 0, RGB(255,255,255)), 0xc0dcc0);
107 ok_long(pulBits[0], 7);
108
109 ok_long(SetPixel(hdc, 0, 0, RGB(255,0,0)), 0x80);
110 ok_long(pulBits[0], 0);
111
112 /* Test DIBINDEX */
113 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0)), 0x80);
114 ok_long(pulBits[0], 0);
115 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(1)), 0x8000);
116 ok_long(pulBits[0], 1);
117 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(7)), 0xc0dcc0);
118 ok_long(pulBits[0], 7);
119 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(8)), 0);
120 ok_long(pulBits[0], 8);
121 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(126)), 0);
122 ok_long(pulBits[0], 126);
123 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0x123456)), 0);
124 ok_long(pulBits[0], 0x56);
125
126 /* Test PALETTEINDEX */
127 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(0)), 0);
128 ok_long(pulBits[0], 8);
129 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(1)), 0x80);
130 ok_long(pulBits[0], 0);
131 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(2)), 0x8000);
132 ok_long(pulBits[0], 1);
133
134 /* Delete the DIB section */
135 DeleteObject(hbmp);
136
137
138 /* Initialize the logical palette and select it */
139 hpal = CreatePalette((LOGPALETTE*)&gpal);
140 hpalOld = SelectPalette(hdc, hpal, FALSE);
141 ok(hpalOld != NULL, "error=%ld\n", GetLastError());
142
143
144 /* Create a DIB section and select it */
145 hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pulBits, 0, 0 );
146 ok(hbmp != NULL, "CreateDIBSection failed with error %ld\n", GetLastError());
147 ok(SelectObject(hdc, hbmp) != 0, "SelectObject failed\n");
148
149 ok_long(SetPixel(hdc, 0, 0, 0), 0);
150 ok_long(pulBits[0], 8);
151
152 ok_long(SetPixel(hdc, 0, 0, RGB(255,0,0)), 0x605040);
153 ok_long(pulBits[0], 2);
154
155 /* Test DIBINDEX */
156 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0)), 0x403020);
157 ok_long(pulBits[0], 0);
158 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(1)), 0x504030);
159 ok_long(pulBits[0], 1);
160 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(7)), 0x302010);
161 ok_long(pulBits[0], 7);
162 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(8)), 0);
163 ok_long(pulBits[0], 8);
164 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(126)), 0);
165 ok_long(pulBits[0], 126);
166 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0x123456)), 0);
167 ok_long(pulBits[0], 0x56);
168
169 /* Test PALETTEINDEX */
170 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(0)), 0x302010);
171 ok_long(pulBits[0], 7);
172 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(1)), 0x403020);
173 ok_long(pulBits[0], 0);
174 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(253)), 0x302010);
175 ok_long(pulBits[0], 7);
176 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(254)), 0x302010);
177 ok_long(pulBits[0], 7);
178
179
180 }
181
START_TEST(SetPixel)182 START_TEST(SetPixel)
183 {
184 Test_SetPixel_Params();
185 Test_SetPixel_PAL();
186 }
187
188