8b36866fbe429dff9994e9f706a0d8db71b3761e
[reactos.git] / rostests / apitests / gdi32 / SetDIBitsToDevice.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetDIBitsToDevice
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include "init.h"
12
13 static void
14 Test_SetDIBitsToDevice_Params()
15 {
16 UCHAR ajBmiBuffer[sizeof(BITMAPINFO) + 4];
17 PBITMAPINFO pbmi = (PBITMAPINFO)ajBmiBuffer;
18 ULONG aulBits[16];
19 INT ret;
20
21 /* Setup the bitmap info */
22 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
23 pbmi->bmiHeader.biWidth = 2;
24 pbmi->bmiHeader.biHeight = -2;
25 pbmi->bmiHeader.biPlanes = 1;
26 pbmi->bmiHeader.biBitCount = 32;
27 pbmi->bmiHeader.biCompression = BI_RGB;
28 pbmi->bmiHeader.biSizeImage = 0;
29 pbmi->bmiHeader.biXPelsPerMeter = 0;
30 pbmi->bmiHeader.biYPelsPerMeter = 0;
31 pbmi->bmiHeader.biClrUsed = 0;
32 pbmi->bmiHeader.biClrImportant = 0;
33
34 SetLastError(0xdeadc0de);
35 ret = SetDIBitsToDevice(ghdcDIB32,
36 0, // XDest,
37 0, // YDest,
38 2, // dwWidth,
39 2, // dwHeight,
40 0, // XSrc,
41 0, // YSrc,
42 0, // uStartScan,
43 2, // cScanLines,
44 aulBits, // lpvBits,
45 pbmi,
46 DIB_RGB_COLORS);
47 ok_dec(ret, 2);
48 ok_err(0xdeadc0de);
49
50 SetLastError(0xdeadc0de);
51 ret = SetDIBitsToDevice(ghdcDIB32,
52 0, // XDest,
53 0, // YDest,
54 2, // dwWidth,
55 2, // dwHeight,
56 0, // XSrc,
57 0, // YSrc,
58 0, // uStartScan,
59 2, // cScanLines,
60 NULL, // lpvBits,
61 pbmi,
62 DIB_RGB_COLORS);
63 ok_dec(ret, 0);
64 ok_err(0xdeadc0de);
65
66 /* test unaligned buffer */
67 SetLastError(0xdeadc0de);
68 ret = SetDIBitsToDevice(ghdcDIB32,
69 0, // XDest,
70 0, // YDest,
71 2, // dwWidth,
72 2, // dwHeight,
73 0, // XSrc,
74 0, // YSrc,
75 0, // uStartScan,
76 2, // cScanLines,
77 (BYTE*)aulBits + 1, // lpvBits,
78 pbmi,
79 DIB_RGB_COLORS);
80 ok_dec(ret, 2);
81 ok_err(0xdeadc0de);
82
83 /* test unaligned and huge scanline buffer */
84 SetLastError(0xdeadc0de);
85 ret = SetDIBitsToDevice(ghdcDIB32,
86 0, // XDest,
87 0, // YDest,
88 2, // dwWidth,
89 2, // dwHeight,
90 0, // XSrc,
91 0, // YSrc,
92 0, // uStartScan,
93 2000000, // cScanLines,
94 (BYTE*)aulBits + 1, // lpvBits,
95 pbmi,
96 DIB_RGB_COLORS);
97 ok_dec(ret, 0);
98 ok_err(0xdeadc0de);
99
100 /* test unaligned illegal buffer */
101 SetLastError(0xdeadc0de);
102 ret = SetDIBitsToDevice(ghdcDIB32,
103 0, // XDest,
104 0, // YDest,
105 2, // dwWidth,
106 2, // dwHeight,
107 0, // XSrc,
108 0, // YSrc,
109 0, // uStartScan,
110 2, // cScanLines,
111 (BYTE*)0x7fffffff, // lpvBits,
112 pbmi,
113 DIB_RGB_COLORS);
114 ok_dec(ret, 0);
115 ok_err(0xdeadc0de);
116
117 SetLastError(0xdeadc0de);
118 ret = SetDIBitsToDevice(ghdcDIB32,
119 -100, // XDest,
120 0, // YDest,
121 2, // dwWidth,
122 2, // dwHeight,
123 0, // XSrc,
124 0, // YSrc,
125 0, // uStartScan,
126 2, // cScanLines,
127 aulBits, // lpvBits,
128 pbmi,
129 DIB_RGB_COLORS);
130 ok_dec(ret, 2);
131 ok_err(0xdeadc0de);
132
133 SetLastError(0xdeadc0de);
134 ret = SetDIBitsToDevice(ghdcDIB32,
135 LONG_MAX, // XDest,
136 0, // YDest,
137 2, // dwWidth,
138 2, // dwHeight,
139 0, // XSrc,
140 0, // YSrc,
141 0, // uStartScan,
142 2, // cScanLines,
143 aulBits, // lpvBits,
144 pbmi,
145 DIB_RGB_COLORS);
146 ok_dec(ret, 2);
147 ok_err(0xdeadc0de);
148
149 SetLastError(0xdeadc0de);
150 ret = SetDIBitsToDevice(ghdcDIB32,
151 0, // XDest,
152 0, // YDest,
153 2, // dwWidth,
154 2, // dwHeight,
155 100, // XSrc,
156 0, // YSrc,
157 0, // uStartScan,
158 2, // cScanLines,
159 aulBits, // lpvBits,
160 pbmi,
161 DIB_RGB_COLORS);
162 ok_dec(ret, 2);
163 ok_err(0xdeadc0de);
164
165 SetLastError(0xdeadc0de);
166 ret = SetDIBitsToDevice(ghdcDIB32,
167 0, // XDest,
168 0, // YDest,
169 2, // dwWidth,
170 2, // dwHeight,
171 0, // XSrc,
172 100, // YSrc,
173 0, // uStartScan,
174 2, // cScanLines,
175 aulBits, // lpvBits,
176 pbmi,
177 DIB_RGB_COLORS);
178 ok_dec(ret, 2);
179 ok_err(0xdeadc0de);
180
181 SetLastError(0xdeadc0de);
182 ret = SetDIBitsToDevice(ghdcDIB32,
183 0, // XDest,
184 0, // YDest,
185 2, // dwWidth,
186 2, // dwHeight,
187 0, // XSrc,
188 0, // YSrc,
189 0, // uStartScan,
190 66, // cScanLines,
191 aulBits, // lpvBits,
192 pbmi,
193 DIB_RGB_COLORS);
194 ok_dec(ret, 66);
195 ok_err(0xdeadc0de);
196
197 SetLastError(0xdeadc0de);
198 ret = SetDIBitsToDevice(ghdcDIB32,
199 0, // XDest,
200 0, // YDest,
201 2, // dwWidth,
202 2, // dwHeight,
203 0, // XSrc,
204 0, // YSrc,
205 0, // uStartScan,
206 200, // cScanLines,
207 aulBits, // lpvBits,
208 pbmi,
209 DIB_RGB_COLORS);
210 ok_dec(ret, 0);
211 ok_err(0xdeadc0de);
212
213 SetLastError(0xdeadc0de);
214 ret = SetDIBitsToDevice(ghdcDIB32,
215 0, // XDest,
216 0, // YDest,
217 2, // dwWidth,
218 2, // dwHeight,
219 0, // XSrc,
220 0, // YSrc,
221 2000, // uStartScan,
222 66, // cScanLines,
223 aulBits, // lpvBits,
224 pbmi,
225 DIB_RGB_COLORS);
226 ok_dec(ret, 66);
227 ok_err(0xdeadc0de);
228
229 /* Test pbmi == NULL */
230 SetLastError(0xdeadc0de);
231 ret = SetDIBitsToDevice(ghdcDIB32,
232 0, // XDest,
233 0, // YDest,
234 2, // dwWidth,
235 2, // dwHeight,
236 0, // XSrc,
237 0, // YSrc,
238 0, // uStartScan,
239 2, // cScanLines,
240 aulBits, // lpvBits,
241 NULL,
242 DIB_RGB_COLORS);
243 ok_dec(ret, 0);
244 ok_err(0xdeadc0de);
245
246 /* Test illegal bitmap info */
247 pbmi->bmiHeader.biSize = 0;
248 SetLastError(0xdeadc0de);
249 ret = SetDIBitsToDevice(ghdcDIB32,
250 0, // XDest,
251 0, // YDest,
252 2, // dwWidth,
253 2, // dwHeight,
254 0, // XSrc,
255 0, // YSrc,
256 0, // uStartScan,
257 2, // cScanLines,
258 aulBits, // lpvBits,
259 pbmi,
260 DIB_RGB_COLORS);
261 ok_dec(ret, 0);
262 ok_err(0xdeadc0de);
263
264 }
265
266
267 static void
268 Test_SetDIBitsToDevice()
269 {
270 UCHAR ajBmiBuffer[sizeof(BITMAPINFO) + 4];
271 PBITMAPINFO pbmi = (PBITMAPINFO)ajBmiBuffer;
272 ULONG aulBits[16];
273 INT ret;
274
275 /* Setup the bitmap info */
276 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
277 pbmi->bmiHeader.biWidth = 2;
278 pbmi->bmiHeader.biHeight = -2;
279 pbmi->bmiHeader.biPlanes = 1;
280 pbmi->bmiHeader.biBitCount = 32;
281 pbmi->bmiHeader.biCompression = BI_RGB;
282 pbmi->bmiHeader.biSizeImage = 0;
283 pbmi->bmiHeader.biXPelsPerMeter = 0;
284 pbmi->bmiHeader.biYPelsPerMeter = 0;
285 pbmi->bmiHeader.biClrUsed = 0;
286 pbmi->bmiHeader.biClrImportant = 0;
287
288 /* Set pixels */
289 aulBits[0] = 0x11000000;
290 aulBits[1] = 0x00000011;
291 aulBits[2] = 0xFF000000;
292 aulBits[3] = 0x000000FF;
293
294
295 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
296 ret = SetDIBitsToDevice(ghdcDIB32,
297 0, // XDest,
298 0, // YDest,
299 2, // dwWidth,
300 2, // dwHeight,
301 0, // XSrc,
302 0, // YSrc,
303 0, // uStartScan,
304 2, // cScanLines,
305 aulBits, // lpvBits,
306 pbmi,
307 DIB_RGB_COLORS);
308
309 ok_dec(ret, 2);
310 ok_hex(pulDIB32Bits[0], 0x11000000);
311 ok_hex(pulDIB32Bits[1], 0x00000011);
312 ok_hex(pulDIB32Bits[2], 0x00000000);
313 ok_hex(pulDIB32Bits[3], 0x00000000);
314 ok_hex(pulDIB32Bits[4], 0xFF000000);
315 ok_hex(pulDIB32Bits[5], 0x000000FF);
316 ok_hex(pulDIB32Bits[6], 0x00000000);
317 ok_hex(pulDIB32Bits[7], 0x00000000);
318
319 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
320 ret = SetDIBitsToDevice(ghdcDIB32,
321 0, // XDest,
322 1, // YDest,
323 2, // dwWidth,
324 2, // dwHeight,
325 0, // XSrc,
326 0, // YSrc,
327 0, // uStartScan,
328 2, // cScanLines,
329 aulBits, // lpvBits,
330 pbmi,
331 DIB_RGB_COLORS);
332
333 ok_dec(ret, 2);
334 ok_hex(pulDIB32Bits[0], 0x00000000);
335 ok_hex(pulDIB32Bits[1], 0x00000000);
336 ok_hex(pulDIB32Bits[2], 0x00000000);
337 ok_hex(pulDIB32Bits[3], 0x00000000);
338 ok_hex(pulDIB32Bits[4], 0x11000000);
339 ok_hex(pulDIB32Bits[5], 0x00000011);
340 ok_hex(pulDIB32Bits[6], 0x00000000);
341 ok_hex(pulDIB32Bits[7], 0x00000000);
342 ok_hex(pulDIB32Bits[8], 0xFF000000);
343 ok_hex(pulDIB32Bits[9], 0x000000FF);
344 ok_hex(pulDIB32Bits[10], 0x00000000);
345 ok_hex(pulDIB32Bits[11], 0x00000000);
346
347 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
348 ret = SetDIBitsToDevice(ghdcDIB32,
349 0, // XDest,
350 0, // YDest,
351 2, // dwWidth,
352 2, // dwHeight,
353 0, // XSrc,
354 0, // YSrc,
355 0, // uStartScan,
356 1, // cScanLines,
357 aulBits, // lpvBits,
358 pbmi,
359 DIB_RGB_COLORS);
360
361 ok_dec(ret, 1);
362 ok_hex(pulDIB32Bits[0], 0x00000000);
363 ok_hex(pulDIB32Bits[1], 0x00000000);
364 ok_hex(pulDIB32Bits[2], 0x00000000);
365 ok_hex(pulDIB32Bits[3], 0x00000000);
366 ok_hex(pulDIB32Bits[4], 0x11000000);
367 ok_hex(pulDIB32Bits[5], 0x00000011);
368 ok_hex(pulDIB32Bits[6], 0x00000000);
369 ok_hex(pulDIB32Bits[7], 0x00000000);
370
371
372 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
373 ret = SetDIBitsToDevice(ghdcDIB32,
374 0, // XDest,
375 0, // YDest,
376 2, // dwWidth,
377 2, // dwHeight,
378 0, // XSrc,
379 0, // YSrc,
380 1, // uStartScan,
381 1, // cScanLines,
382 aulBits, // lpvBits,
383 pbmi,
384 DIB_RGB_COLORS);
385
386 ok_dec(ret, 1);
387 ok_hex(pulDIB32Bits[0], 0x11000000);
388 ok_hex(pulDIB32Bits[1], 0x00000011);
389 ok_hex(pulDIB32Bits[2], 0x00000000);
390 ok_hex(pulDIB32Bits[3], 0x00000000);
391 ok_hex(pulDIB32Bits[4], 0x00000000);
392 ok_hex(pulDIB32Bits[5], 0x00000000);
393 ok_hex(pulDIB32Bits[6], 0x00000000);
394 ok_hex(pulDIB32Bits[7], 0x00000000);
395
396 /*****************/
397
398 /* Use bottom-up bitmap */
399 pbmi->bmiHeader.biHeight = 2;
400
401 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
402 ret = SetDIBitsToDevice(ghdcDIB32,
403 0, // XDest,
404 0, // YDest,
405 2, // dwWidth,
406 2, // dwHeight,
407 0, // XSrc,
408 0, // YSrc,
409 0, // uStartScan,
410 2, // cScanLines,
411 aulBits, // lpvBits,
412 pbmi,
413 DIB_RGB_COLORS);
414
415 ok_dec(ret, 2);
416 ok_hex(pulDIB32Bits[0], 0xFF000000);
417 ok_hex(pulDIB32Bits[1], 0x000000FF);
418 ok_hex(pulDIB32Bits[2], 0x00000000);
419 ok_hex(pulDIB32Bits[3], 0x00000000);
420 ok_hex(pulDIB32Bits[4], 0x11000000);
421 ok_hex(pulDIB32Bits[5], 0x00000011);
422 ok_hex(pulDIB32Bits[6], 0x00000000);
423 ok_hex(pulDIB32Bits[7], 0x00000000);
424
425 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
426 ret = SetDIBitsToDevice(ghdcDIB32,
427 0, // XDest,
428 1, // YDest,
429 2, // dwWidth,
430 2, // dwHeight,
431 0, // XSrc,
432 0, // YSrc,
433 0, // uStartScan,
434 2, // cScanLines,
435 aulBits, // lpvBits,
436 pbmi,
437 DIB_RGB_COLORS);
438
439 ok_dec(ret, 2);
440 ok_hex(pulDIB32Bits[0], 0x00000000);
441 ok_hex(pulDIB32Bits[1], 0x00000000);
442 ok_hex(pulDIB32Bits[2], 0x00000000);
443 ok_hex(pulDIB32Bits[3], 0x00000000);
444 ok_hex(pulDIB32Bits[4], 0xFF000000);
445 ok_hex(pulDIB32Bits[5], 0x000000FF);
446 ok_hex(pulDIB32Bits[6], 0x00000000);
447 ok_hex(pulDIB32Bits[7], 0x00000000);
448 ok_hex(pulDIB32Bits[8], 0x11000000);
449 ok_hex(pulDIB32Bits[9], 0x00000011);
450 ok_hex(pulDIB32Bits[10], 0x00000000);
451 ok_hex(pulDIB32Bits[11], 0x00000000);
452
453 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
454 ret = SetDIBitsToDevice(ghdcDIB32,
455 0, // XDest,
456 0, // YDest,
457 2, // dwWidth,
458 2, // dwHeight,
459 0, // XSrc,
460 0, // YSrc,
461 0, // uStartScan,
462 1, // cScanLines,
463 aulBits, // lpvBits,
464 pbmi,
465 DIB_RGB_COLORS);
466
467 ok_dec(ret, 1);
468 ok_hex(pulDIB32Bits[0], 0x00000000);
469 ok_hex(pulDIB32Bits[1], 0x00000000);
470 ok_hex(pulDIB32Bits[2], 0x00000000);
471 ok_hex(pulDIB32Bits[3], 0x00000000);
472 ok_hex(pulDIB32Bits[4], 0x11000000);
473 ok_hex(pulDIB32Bits[5], 0x00000011);
474 ok_hex(pulDIB32Bits[6], 0x00000000);
475 ok_hex(pulDIB32Bits[7], 0x00000000);
476
477
478 memset(pulDIB32Bits, 0, 4 * 4 * sizeof(ULONG));
479 ret = SetDIBitsToDevice(ghdcDIB32,
480 0, // XDest,
481 0, // YDest,
482 2, // dwWidth,
483 2, // dwHeight,
484 0, // XSrc,
485 0, // YSrc,
486 1, // uStartScan,
487 1, // cScanLines,
488 aulBits, // lpvBits,
489 pbmi,
490 DIB_RGB_COLORS);
491
492 ok_dec(ret, 1);
493 ok_hex(pulDIB32Bits[0], 0x11000000);
494 ok_hex(pulDIB32Bits[1], 0x00000011);
495 ok_hex(pulDIB32Bits[2], 0x00000000);
496 ok_hex(pulDIB32Bits[3], 0x00000000);
497 ok_hex(pulDIB32Bits[4], 0x00000000);
498 ok_hex(pulDIB32Bits[5], 0x00000000);
499 ok_hex(pulDIB32Bits[6], 0x00000000);
500 ok_hex(pulDIB32Bits[7], 0x00000000);
501
502 }
503
504
505 START_TEST(SetDIBitsToDevice)
506 {
507 InitStuff();
508
509 Test_SetDIBitsToDevice_Params();
510 Test_SetDIBitsToDevice();
511
512
513 }