dcea8a8f8e67848438ccdbc13837519b001e4387
[reactos.git] / modules / rostests / apitests / win32nt / ntgdi / NtGdiSetBitmapBits.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtGdiSetBitmapBits
5 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8 #include <win32nt.h>
9
10 START_TEST(NtGdiSetBitmapBits)
11 {
12 BYTE Bits[100] = {0,1,2,3,4,5,6,7,8,9};
13 HBITMAP hBitmap;
14 HDC hDC;
15 BITMAPINFO bmi;
16 LPVOID pvBits;
17
18 SetLastError(0xDEADFACE);
19 ok_long(NtGdiSetBitmapBits(0, 0, 0), 0);
20 ok_long(GetLastError(), 0xDEADFACE);
21
22 /* Test NULL bitnap handle */
23 SetLastError(0xDEADFACE);
24 ok_long(NtGdiSetBitmapBits(0, 5, Bits), 0);
25 ok_long(GetLastError(), ERROR_INVALID_HANDLE);
26
27 /* Test invalid bitmap handle */
28 hBitmap = (HBITMAP)CreatePen(PS_SOLID, 1, RGB(1,2,3));
29 SetLastError(0xDEADFACE);
30 ok_long(NtGdiSetBitmapBits(hBitmap, 5, Bits), 0);
31 ok_long(GetLastError(), ERROR_INVALID_HANDLE);
32 DeleteObject(hBitmap);
33
34 hBitmap = CreateBitmap(3, 3, 1, 8, NULL);
35 ok(hBitmap != NULL, "hBitmap was NULL.\n");
36
37 /* test NULL pointer and count buffer size != 0 */
38 SetLastError(0xDEADFACE);
39 ok_long(NtGdiSetBitmapBits(hBitmap, 5, NULL), 0);
40 ok_long(GetLastError(), 0xDEADFACE);
41
42 /* test NULL pointer and buffer size == 0*/
43 SetLastError(0xDEADFACE);
44 ok_long(NtGdiSetBitmapBits(hBitmap, 0, NULL), 0);
45 ok_long(GetLastError(), 0xDEADFACE);
46
47 /* test bad pointer */
48 SetLastError(0xDEADFACE);
49 ok_long(NtGdiSetBitmapBits(hBitmap, 5, (PBYTE)0x500), 0);
50 ok_long(GetLastError(), 0xDEADFACE);
51
52 /* Test if we can set a number of bytes between lines */
53 SetLastError(0xDEADFACE);
54 ok_long(NtGdiSetBitmapBits(hBitmap, 5, Bits), 5);
55 ok_long(GetLastError(), 0xDEADFACE);
56
57 /* Test alignment */
58 SetLastError(0xDEADFACE);
59 ok_long(NtGdiSetBitmapBits(hBitmap, 4, Bits+1), 4);
60 ok_long(GetLastError(), 0xDEADFACE);
61
62 /* Test 1 byte too much */
63 SetLastError(0xDEADFACE);
64 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
65 ok_long(GetLastError(), 0xDEADFACE);
66
67 /* Test one row too much */
68 SetLastError(0xDEADFACE);
69 ok_long(NtGdiSetBitmapBits(hBitmap, 12, Bits), 12);
70 ok_long(GetLastError(), 0xDEADFACE);
71
72 SetLastError(0xDEADFACE);
73 ok_long(NtGdiSetBitmapBits(hBitmap, 13, Bits), 12);
74 ok_long(GetLastError(), 0xDEADFACE);
75
76 SetLastError(0xDEADFACE);
77 ok_long(NtGdiSetBitmapBits(hBitmap, 100, Bits), 12);
78 ok_long(GetLastError(), 0xDEADFACE);
79
80 /* Test huge bytes count */
81 SetLastError(0xDEADFACE);
82 ok_long(NtGdiSetBitmapBits(hBitmap, 12345678, Bits), 0);
83 ok_long(GetLastError(), 0xDEADFACE);
84
85 SetLastError(0xDEADFACE);
86 ok_long(NtGdiSetBitmapBits(hBitmap, 0xFFFF, Bits), 0);
87 ok_long(GetLastError(), 0xDEADFACE);
88
89 SetLastError(0xDEADFACE);
90 ok_long(NtGdiSetBitmapBits(hBitmap, 0x10000, Bits), 0);
91 ok_long(GetLastError(), 0xDEADFACE);
92
93 /* Test negative bytes count */
94 SetLastError(0xDEADFACE);
95 ok_long(NtGdiSetBitmapBits(hBitmap, -5, Bits), 0);
96 ok_long(GetLastError(), 0xDEADFACE);
97
98 DeleteObject(hBitmap);
99
100 /* ------------------------- */
101
102 hBitmap = CreateBitmap(16, 16, 1, 1, NULL);
103 ok(hBitmap != NULL, "hBitmap was NULL.\n");
104
105 FillMemory(Bits, sizeof(Bits), 0x55);
106 SetLastError(0xDEADFACE);
107 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
108 ok_long(GetLastError(), 0xDEADFACE);
109 ok_int(Bits[0], 0x55);
110
111 FillMemory(Bits, sizeof(Bits), 0x55);
112
113 SetLastError(0xDEADFACE);
114 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
115 ok_long(GetLastError(), 0xDEADFACE);
116 ok_int(Bits[0], 0);
117 ok_int(Bits[1], 0x55);
118
119 FillMemory(Bits, sizeof(Bits), 0x55);
120 SetLastError(0xDEADFACE);
121 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
122 ok_long(GetLastError(), 0xDEADFACE);
123 ok_int(Bits[0], 0);
124 ok_int(Bits[1], 0);
125 ok_int(Bits[2], 0x55);
126
127 FillMemory(Bits, sizeof(Bits), 0x33);
128 SetLastError(0xDEADFACE);
129 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
130 ok_long(GetLastError(), 0xDEADFACE);
131
132 FillMemory(Bits, sizeof(Bits), 0xAA);
133 SetLastError(0xDEADFACE);
134 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
135 ok_long(GetLastError(), 0xDEADFACE);
136 FillMemory(Bits, sizeof(Bits), 0x55);
137 SetLastError(0xDEADFACE);
138 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
139 ok_long(GetLastError(), 0xDEADFACE);
140 ok_int(Bits[0], 0xAA);
141 ok_int(Bits[1], 0x55);
142 SetLastError(0xDEADFACE);
143 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
144 ok_long(GetLastError(), 0xDEADFACE);
145 ok_int(Bits[0], 0xAA);
146 ok_int(Bits[1], 0x33);
147 ok_int(Bits[2], 0x55);
148
149 FillMemory(Bits, sizeof(Bits), 0xAA);
150 SetLastError(0xDEADFACE);
151 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
152 ok_long(GetLastError(), 0xDEADFACE);
153 FillMemory(Bits, sizeof(Bits), 0x55);
154 SetLastError(0xDEADFACE);
155 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
156 ok_long(GetLastError(), 0xDEADFACE);
157 ok_int(Bits[0], 0xAA);
158 ok_int(Bits[1], 0xAA);
159 ok_int(Bits[2], 0x55);
160 SetLastError(0xDEADFACE);
161 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
162 ok_long(GetLastError(), 0xDEADFACE);
163 ok_int(Bits[0], 0xAA);
164 ok_int(Bits[1], 0xAA);
165 ok_int(Bits[2], 0x33);
166 ok_int(Bits[3], 0x55);
167
168 FillMemory(Bits, sizeof(Bits), 0xAA);
169 SetLastError(0xDEADFACE);
170 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
171 ok_long(GetLastError(), 0xDEADFACE);
172 FillMemory(Bits, sizeof(Bits), 0x55);
173 SetLastError(0xDEADFACE);
174 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
175 ok_long(GetLastError(), 0xDEADFACE);
176 ok_int(Bits[0], 0xAA);
177 ok_int(Bits[1], 0xAA);
178 ok_int(Bits[2], 0xAA);
179 ok_int(Bits[3], 0x55);
180 SetLastError(0xDEADFACE);
181 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
182 ok_long(GetLastError(), 0xDEADFACE);
183 ok_int(Bits[0], 0xAA);
184 ok_int(Bits[1], 0xAA);
185 ok_int(Bits[2], 0xAA);
186 ok_int(Bits[3], 0x33);
187 ok_int(Bits[4], 0x55);
188
189 DeleteObject(hBitmap);
190
191 /* ------------------------- */
192
193 hDC = CreateCompatibleDC(NULL);
194
195 ZeroMemory(&bmi, sizeof(bmi));
196 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
197 bmi.bmiHeader.biWidth = 15;
198 bmi.bmiHeader.biHeight = 15; /* positive */
199 bmi.bmiHeader.biPlanes = 1;
200 bmi.bmiHeader.biBitCount = 24;
201 hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
202 ok(hBitmap != NULL, "hBitmap was NULL.\n");
203
204 FillMemory(Bits, sizeof(Bits), 0x55);
205 SetLastError(0xDEADFACE);
206 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
207 ok_long(GetLastError(), 0xDEADFACE);
208 ok_int(Bits[0], 0x55);
209
210 FillMemory(Bits, sizeof(Bits), 0x55);
211 SetLastError(0xDEADFACE);
212 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
213 ok_long(GetLastError(), 0xDEADFACE);
214 ok_int(Bits[0], 0);
215 ok_int(Bits[1], 0x55);
216
217 FillMemory(Bits, sizeof(Bits), 0x55);
218 SetLastError(0xDEADFACE);
219 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
220 ok_long(GetLastError(), 0xDEADFACE);
221 ok_int(Bits[0], 0);
222 ok_int(Bits[1], 0);
223 ok_int(Bits[2], 0x55);
224
225 FillMemory(Bits, sizeof(Bits), 0x33);
226 SetLastError(0xDEADFACE);
227 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
228 ok_long(GetLastError(), 0xDEADFACE);
229
230 FillMemory(Bits, sizeof(Bits), 0xAA);
231 SetLastError(0xDEADFACE);
232 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
233 ok_long(GetLastError(), 0xDEADFACE);
234 FillMemory(Bits, sizeof(Bits), 0x55);
235 SetLastError(0xDEADFACE);
236 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
237 ok_long(GetLastError(), 0xDEADFACE);
238 ok_int(Bits[0], 0xAA);
239 ok_int(Bits[1], 0x55);
240 SetLastError(0xDEADFACE);
241 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
242 ok_long(GetLastError(), 0xDEADFACE);
243 ok_int(Bits[0], 0xAA);
244 ok_int(Bits[1], 0x33);
245 ok_int(Bits[2], 0x55);
246
247 FillMemory(Bits, sizeof(Bits), 0xAA);
248 SetLastError(0xDEADFACE);
249 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
250 ok_long(GetLastError(), 0xDEADFACE);
251 FillMemory(Bits, sizeof(Bits), 0x55);
252 SetLastError(0xDEADFACE);
253 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
254 ok_long(GetLastError(), 0xDEADFACE);
255 ok_int(Bits[0], 0xAA);
256 ok_int(Bits[1], 0xAA);
257 ok_int(Bits[2], 0x55);
258 SetLastError(0xDEADFACE);
259 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
260 ok_long(GetLastError(), 0xDEADFACE);
261 ok_int(Bits[0], 0xAA);
262 ok_int(Bits[1], 0xAA);
263 ok_int(Bits[2], 0x33);
264 ok_int(Bits[3], 0x55);
265
266 FillMemory(Bits, sizeof(Bits), 0xAA);
267 SetLastError(0xDEADFACE);
268 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
269 ok_long(GetLastError(), 0xDEADFACE);
270 FillMemory(Bits, sizeof(Bits), 0x55);
271 SetLastError(0xDEADFACE);
272 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
273 ok_long(GetLastError(), 0xDEADFACE);
274 ok_int(Bits[0], 0xAA);
275 ok_int(Bits[1], 0xAA);
276 ok_int(Bits[2], 0xAA);
277 ok_int(Bits[3], 0x55);
278 SetLastError(0xDEADFACE);
279 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
280 ok_long(GetLastError(), 0xDEADFACE);
281 ok_int(Bits[0], 0xAA);
282 ok_int(Bits[1], 0xAA);
283 ok_int(Bits[2], 0xAA);
284 ok_int(Bits[3], 0x33);
285 ok_int(Bits[4], 0x55);
286
287 DeleteObject(hBitmap);
288 DeleteDC(hDC);
289
290 /* ------------------------- */
291
292 hDC = CreateCompatibleDC(NULL);
293
294 ZeroMemory(&bmi, sizeof(bmi));
295 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
296 bmi.bmiHeader.biWidth = 15;
297 bmi.bmiHeader.biHeight = -15; /* negative */
298 bmi.bmiHeader.biPlanes = 1;
299 bmi.bmiHeader.biBitCount = 24;
300 hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
301 ok(hBitmap != NULL, "hBitmap was NULL.\n");
302
303 FillMemory(Bits, sizeof(Bits), 0x55);
304 SetLastError(0xDEADFACE);
305 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
306 ok_long(GetLastError(), 0xDEADFACE);
307 ok_int(Bits[0], 0x55);
308
309 FillMemory(Bits, sizeof(Bits), 0x55);
310 SetLastError(0xDEADFACE);
311 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
312 ok_long(GetLastError(), 0xDEADFACE);
313 ok_int(Bits[0], 0);
314 ok_int(Bits[1], 0x55);
315
316 FillMemory(Bits, sizeof(Bits), 0x55);
317 SetLastError(0xDEADFACE);
318 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
319 ok_long(GetLastError(), 0xDEADFACE);
320 ok_int(Bits[0], 0);
321 ok_int(Bits[1], 0);
322 ok_int(Bits[2], 0x55);
323
324 FillMemory(Bits, sizeof(Bits), 0x33);
325 SetLastError(0xDEADFACE);
326 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
327 ok_long(GetLastError(), 0xDEADFACE);
328
329 FillMemory(Bits, sizeof(Bits), 0xAA);
330 SetLastError(0xDEADFACE);
331 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
332 ok_long(GetLastError(), 0xDEADFACE);
333 FillMemory(Bits, sizeof(Bits), 0x55);
334 SetLastError(0xDEADFACE);
335 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
336 ok_long(GetLastError(), 0xDEADFACE);
337 ok_int(Bits[0], 0xAA);
338 ok_int(Bits[1], 0x55);
339 SetLastError(0xDEADFACE);
340 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
341 ok_long(GetLastError(), 0xDEADFACE);
342 ok_int(Bits[0], 0xAA);
343 ok_int(Bits[1], 0x33);
344 ok_int(Bits[2], 0x55);
345
346 FillMemory(Bits, sizeof(Bits), 0xAA);
347 SetLastError(0xDEADFACE);
348 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
349 ok_long(GetLastError(), 0xDEADFACE);
350 FillMemory(Bits, sizeof(Bits), 0x55);
351 SetLastError(0xDEADFACE);
352 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
353 ok_long(GetLastError(), 0xDEADFACE);
354 ok_int(Bits[0], 0xAA);
355 ok_int(Bits[1], 0xAA);
356 ok_int(Bits[2], 0x55);
357 SetLastError(0xDEADFACE);
358 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
359 ok_long(GetLastError(), 0xDEADFACE);
360 ok_int(Bits[0], 0xAA);
361 ok_int(Bits[1], 0xAA);
362 ok_int(Bits[2], 0x33);
363 ok_int(Bits[3], 0x55);
364
365 FillMemory(Bits, sizeof(Bits), 0xAA);
366 SetLastError(0xDEADFACE);
367 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
368 ok_long(GetLastError(), 0xDEADFACE);
369 FillMemory(Bits, sizeof(Bits), 0x55);
370 SetLastError(0xDEADFACE);
371 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
372 ok_long(GetLastError(), 0xDEADFACE);
373 ok_int(Bits[0], 0xAA);
374 ok_int(Bits[1], 0xAA);
375 ok_int(Bits[2], 0xAA);
376 ok_int(Bits[3], 0x55);
377 SetLastError(0xDEADFACE);
378 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
379 ok_long(GetLastError(), 0xDEADFACE);
380 ok_int(Bits[0], 0xAA);
381 ok_int(Bits[1], 0xAA);
382 ok_int(Bits[2], 0xAA);
383 ok_int(Bits[3], 0x33);
384 ok_int(Bits[4], 0x55);
385
386 DeleteObject(hBitmap);
387 DeleteDC(hDC);
388 }