ReactOS 0.4.16-dev-91-g764881a
SetDIBitsToDevice.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 SetDIBitsToDevice
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8#include "precomp.h"
9
10#include "init.h"
11
12static void
14{
15 UCHAR ajBmiBuffer[sizeof(BITMAPINFO) + 4];
16 PBITMAPINFO pbmi = (PBITMAPINFO)ajBmiBuffer;
17 ULONG aulBits[16];
18 INT ret;
19
20 /* Setup the bitmap info */
32
33 /* Test a normal operation */
34 SetLastError(0xdeadc0de);
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,
47 ok_dec(ret, 2);
48 ok_err(0xdeadc0de);
49
50 /* Test hdc == NULL */
51 SetLastError(0xdeadc0de);
53 0, // XDest,
54 0, // YDest,
55 2, // dwWidth,
56 2, // dwHeight,
57 0, // XSrc,
58 0, // YSrc,
59 0, // uStartScan,
60 2, // cScanLines,
61 aulBits, // lpvBits,
62 pbmi,
64 ok_dec(ret, 0);
66
67 /* Test truncated hdc */
68 SetLastError(0xdeadc0de);
70 0, // XDest,
71 0, // YDest,
72 2, // dwWidth,
73 2, // dwHeight,
74 0, // XSrc,
75 0, // YSrc,
76 0, // uStartScan,
77 2, // cScanLines,
78 aulBits, // lpvBits,
79 pbmi,
81 ok_dec(ret, 0);
83
84 /* Test invalid ColorUse */
85 SetLastError(0xdeadc0de);
87 0, // XDest,
88 0, // YDest,
89 2, // dwWidth,
90 2, // dwHeight,
91 0, // XSrc,
92 0, // YSrc,
93 0, // uStartScan,
94 2, // cScanLines,
95 aulBits, // lpvBits,
96 pbmi,
97 7);
98 ok_dec(ret, 0);
99 ok_err(0xdeadc0de);
100
101 /* test unaligned buffer */
102 SetLastError(0xdeadc0de);
104 0, // XDest,
105 0, // YDest,
106 2, // dwWidth,
107 2, // dwHeight,
108 0, // XSrc,
109 0, // YSrc,
110 0, // uStartScan,
111 2, // cScanLines,
112 (BYTE*)aulBits + 1, // lpvBits,
113 pbmi,
115 ok_dec(ret, 2);
116 ok_err(0xdeadc0de);
117
118 /* test unaligned and huge scanline buffer */
119 SetLastError(0xdeadc0de);
121 0, // XDest,
122 0, // YDest,
123 2, // dwWidth,
124 2, // dwHeight,
125 0, // XSrc,
126 0, // YSrc,
127 0, // uStartScan,
128 20000000, // cScanLines,
129 (BYTE*)aulBits + 1, // lpvBits,
130 pbmi,
132 ok_dec(ret, 0);
133 ok_err(0xdeadc0de);
134
135 /* test unaligned illegal buffer */
136 SetLastError(0xdeadc0de);
138 0, // XDest,
139 0, // YDest,
140 2, // dwWidth,
141 2, // dwHeight,
142 0, // XSrc,
143 0, // YSrc,
144 0, // uStartScan,
145 2, // cScanLines,
146 (BYTE*)0x7fffffff, // lpvBits,
147 pbmi,
149 ok_dec(ret, 0);
150 ok_err(0xdeadc0de);
151
152 /* Test negative XDest */
153 SetLastError(0xdeadc0de);
155 -100, // XDest,
156 0, // YDest,
157 2, // dwWidth,
158 2, // dwHeight,
159 0, // XSrc,
160 0, // YSrc,
161 0, // uStartScan,
162 2, // cScanLines,
163 aulBits, // lpvBits,
164 pbmi,
166 ok_dec(ret, 2);
167 ok_err(0xdeadc0de);
168
169 /* Test huge XDest */
170 SetLastError(0xdeadc0de);
172 LONG_MAX, // XDest,
173 0, // YDest,
174 2, // dwWidth,
175 2, // dwHeight,
176 0, // XSrc,
177 0, // YSrc,
178 0, // uStartScan,
179 2, // cScanLines,
180 aulBits, // lpvBits,
181 pbmi,
183 ok_dec(ret, 2);
184 ok_err(0xdeadc0de);
185
186 /* Test XSrc outside of the DIB */
187 SetLastError(0xdeadc0de);
189 0, // XDest,
190 0, // YDest,
191 2, // dwWidth,
192 2, // dwHeight,
193 100, // XSrc,
194 0, // YSrc,
195 0, // uStartScan,
196 2, // cScanLines,
197 aulBits, // lpvBits,
198 pbmi,
200 ok_dec(ret, 2);
201 ok_err(0xdeadc0de);
202
203 /* Test YSrc outside of the DIB */
204 SetLastError(0xdeadc0de);
206 0, // XDest,
207 0, // YDest,
208 2, // dwWidth,
209 2, // dwHeight,
210 0, // XSrc,
211 100, // YSrc,
212 0, // uStartScan,
213 2, // cScanLines,
214 aulBits, // lpvBits,
215 pbmi,
217 ok_dec(ret, 2);
218 ok_err(0xdeadc0de);
219
220 /* Test uStartScan outside of the DIB */
221 SetLastError(0xdeadc0de);
223 0, // XDest,
224 0, // YDest,
225 2, // dwWidth,
226 2, // dwHeight,
227 0, // XSrc,
228 0, // YSrc,
229 100, // uStartScan,
230 5, // cScanLines,
231 aulBits, // lpvBits,
232 pbmi,
234 ok_dec(ret, 5);
235 ok_err(0xdeadc0de);
236
237 /* Test cScanLines larger than the DIB */
238 SetLastError(0xdeadc0de);
240 0, // XDest,
241 0, // YDest,
242 2, // dwWidth,
243 2, // dwHeight,
244 0, // XSrc,
245 0, // YSrc,
246 0, // uStartScan,
247 7, // cScanLines,
248 aulBits, // lpvBits,
249 pbmi,
251 ok_dec(ret, 7);
252 ok_err(0xdeadc0de);
253
254 /* Test large cScanlines */
255 SetLastError(0xdeadc0de);
257 0, // XDest,
258 0, // YDest,
259 2, // dwWidth,
260 2, // dwHeight,
261 0, // XSrc,
262 0, // YSrc,
263 0, // uStartScan,
264 2000, // cScanLines,
265 aulBits, // lpvBits,
266 pbmi,
268 ok_dec(ret, 0);
269 ok_err(0xdeadc0de);
270
271 /* Test uStartScan and cScanLines larger than the DIB */
272 SetLastError(0xdeadc0de);
274 0, // XDest,
275 0, // YDest,
276 2, // dwWidth,
277 2, // dwHeight,
278 0, // XSrc,
279 0, // YSrc,
280 100, // uStartScan,
281 7, // cScanLines,
282 aulBits, // lpvBits,
283 pbmi,
285 ok_dec(ret, 7);
286 ok_err(0xdeadc0de);
287
288 /* Test lpvBits == NULL */
289 SetLastError(0xdeadc0de);
291 0, // XDest,
292 0, // YDest,
293 2, // dwWidth,
294 2, // dwHeight,
295 0, // XSrc,
296 0, // YSrc,
297 0, // uStartScan,
298 2, // cScanLines,
299 NULL, // lpvBits,
300 pbmi,
302 ok_dec(ret, 0);
303 ok_err(0xdeadc0de);
304
305 /* Test pbmi == NULL */
306 SetLastError(0xdeadc0de);
308 0, // XDest,
309 0, // YDest,
310 2, // dwWidth,
311 2, // dwHeight,
312 0, // XSrc,
313 0, // YSrc,
314 0, // uStartScan,
315 2, // cScanLines,
316 aulBits, // lpvBits,
317 NULL,
319 ok_dec(ret, 0);
320 ok_err(0xdeadc0de);
321
322 /* Test huge positive DIB height, result is limited to dwHeight */
323 pbmi->bmiHeader.biHeight = 10000;
324 SetLastError(0xdeadc0de);
326 0, // XDest,
327 1, // YDest,
328 2, // dwWidth,
329 3, // dwHeight,
330 0, // XSrc,
331 1, // YSrc,
332 0, // uStartScan,
333 7, // cScanLines,
334 aulBits, // lpvBits,
335 pbmi,
337 ok_dec(ret, 4);
338 ok_err(0xdeadc0de);
339
340 /* Test huge negative DIB height */
341 pbmi->bmiHeader.biHeight = -10000;
342 SetLastError(0xdeadc0de);
344 0, // XDest,
345 0, // YDest,
346 2, // dwWidth,
347 2, // dwHeight,
348 0, // XSrc,
349 0, // YSrc,
350 0, // uStartScan,
351 7, // cScanLines,
352 aulBits, // lpvBits,
353 pbmi,
355 ok_dec(ret, 7);
356 ok_err(0xdeadc0de);
357
358 /* Test what happens when we cause an integer overflow */
360 SetLastError(0xdeadc0de);
362 0, // XDest,
363 0, // YDest,
364 2, // dwWidth,
365 2, // dwHeight,
366 0, // XSrc,
367 0, // YSrc,
368 0, // uStartScan,
369 2, // cScanLines,
370 aulBits, // lpvBits,
371 pbmi,
373 ok_dec(ret, 2);
374 ok_err(0xdeadc0de);
375
376 /* Now also test a huge value of uStartScan */
377 SetLastError(0xdeadc0de);
379 0, // XDest,
380 0, // YDest,
381 2, // dwWidth,
382 2, // dwHeight,
383 0, // XSrc,
384 0, // YSrc,
385 abs(pbmi->bmiHeader.biHeight) - 3, // uStartScan,
386 9, // cScanLines,
387 aulBits, // lpvBits,
388 pbmi,
390 ok_dec(ret, 3);
391 ok_err(0xdeadc0de);
392
393 /* Now also test a huge value of uStartScan */
395 SetLastError(0xdeadc0de);
397 0, // XDest,
398 0, // YDest,
399 2, // dwWidth,
400 2, // dwHeight,
401 0, // XSrc,
402 0, // YSrc,
403 abs(pbmi->bmiHeader.biHeight) - 3, // uStartScan,
404 9, // cScanLines,
405 aulBits, // lpvBits,
406 pbmi,
408 ok_dec(ret, 5);
409 ok_err(0xdeadc0de);
410
411 /* Now also test a huge value of uStartScan */
413 SetLastError(0xdeadc0de);
415 0, // XDest,
416 0, // YDest,
417 2, // dwWidth,
418 2, // dwHeight,
419 0, // XSrc,
420 0, // YSrc,
421 abs(pbmi->bmiHeader.biHeight) - 3, // uStartScan,
422 32, // cScanLines,
423 aulBits, // lpvBits,
424 pbmi,
426 ok_dec(ret, 17);
427 ok_err(0xdeadc0de);
428
429 /* Test invalid bitmap info header */
430 pbmi->bmiHeader.biSize = 0;
431 SetLastError(0xdeadc0de);
433 0, // XDest,
434 0, // YDest,
435 2, // dwWidth,
436 2, // dwHeight,
437 0, // XSrc,
438 0, // YSrc,
439 0, // uStartScan,
440 2, // cScanLines,
441 aulBits, // lpvBits,
442 pbmi,
444 ok_dec(ret, 0);
445 ok_err(0xdeadc0de);
446
447}
448
449
450static void
452{
453 UCHAR ajBmiBuffer[sizeof(BITMAPINFO) + 4];
454 PBITMAPINFO pbmi = (PBITMAPINFO)ajBmiBuffer;
455 ULONG aulBits[16];
456 INT ret;
457
458 /* Setup the bitmap info */
461 pbmi->bmiHeader.biHeight = -2;
470
471 /* Set pixels */
472 aulBits[0] = 0x11000000;
473 aulBits[1] = 0x00000011;
474 aulBits[2] = 0xFF000000;
475 aulBits[3] = 0x000000FF;
476
477
478 memset(gpDIB32, 0, sizeof(*gpDIB32));
480 0, // XDest,
481 0, // YDest,
482 2, // dwWidth,
483 2, // dwHeight,
484 0, // XSrc,
485 0, // YSrc,
486 0, // uStartScan,
487 2, // cScanLines,
488 aulBits, // lpvBits,
489 pbmi,
491
492 ok_dec(ret, 2);
493 ok_hex((*gpDIB32)[0][0], 0x11000000);
494 ok_hex((*gpDIB32)[0][1], 0x00000011);
495 ok_hex((*gpDIB32)[0][2], 0x00000000);
496 ok_hex((*gpDIB32)[0][3], 0x00000000);
497 ok_hex((*gpDIB32)[1][0], 0xFF000000);
498 ok_hex((*gpDIB32)[1][1], 0x000000FF);
499 ok_hex((*gpDIB32)[1][2], 0x00000000);
500 ok_hex((*gpDIB32)[1][3], 0x00000000);
501
502 memset(gpDIB32, 0, sizeof(*gpDIB32));
504 0, // XDest,
505 1, // YDest,
506 2, // dwWidth,
507 2, // dwHeight,
508 0, // XSrc,
509 0, // YSrc,
510 0, // uStartScan,
511 2, // cScanLines,
512 aulBits, // lpvBits,
513 pbmi,
515
516 ok_dec(ret, 2);
517 ok_hex((*gpDIB32)[0][0], 0x00000000);
518 ok_hex((*gpDIB32)[0][1], 0x00000000);
519 ok_hex((*gpDIB32)[0][2], 0x00000000);
520 ok_hex((*gpDIB32)[0][3], 0x00000000);
521 ok_hex((*gpDIB32)[1][0], 0x11000000);
522 ok_hex((*gpDIB32)[1][1], 0x00000011);
523 ok_hex((*gpDIB32)[1][2], 0x00000000);
524 ok_hex((*gpDIB32)[1][3], 0x00000000);
525 ok_hex((*gpDIB32)[2][0], 0xFF000000);
526 ok_hex((*gpDIB32)[2][1], 0x000000FF);
527 ok_hex((*gpDIB32)[2][2], 0x00000000);
528 ok_hex((*gpDIB32)[2][3], 0x00000000);
529
530 memset(gpDIB32, 0, sizeof(*gpDIB32));
532 0, // XDest,
533 0, // YDest,
534 2, // dwWidth,
535 2, // dwHeight,
536 0, // XSrc,
537 0, // YSrc,
538 0, // uStartScan,
539 1, // cScanLines,
540 aulBits, // lpvBits,
541 pbmi,
543
544 ok_dec(ret, 1);
545 ok_hex((*gpDIB32)[0][0], 0x00000000);
546 ok_hex((*gpDIB32)[0][1], 0x00000000);
547 ok_hex((*gpDIB32)[0][2], 0x00000000);
548 ok_hex((*gpDIB32)[0][3], 0x00000000);
549 todo_ros ok_hex((*gpDIB32)[1][0], 0x11000000);
550 todo_ros ok_hex((*gpDIB32)[1][1], 0x00000011);
551 ok_hex((*gpDIB32)[1][2], 0x00000000);
552 ok_hex((*gpDIB32)[1][3], 0x00000000);
553#if 0
554
555 memset(gpDIB32, 0, sizeof(*gpDIB32));
557 0, // XDest,
558 0, // YDest,
559 2, // dwWidth,
560 2, // dwHeight,
561 0, // XSrc,
562 0, // YSrc,
563 1, // uStartScan,
564 1, // cScanLines,
565 aulBits, // lpvBits,
566 pbmi,
568
569 ok_dec(ret, 1);
570 todo_ros ok_hex(pulDIB32Bits[0], 0x11000000);
571 todo_ros ok_hex(pulDIB32Bits[1], 0x00000011);
572 ok_hex(pulDIB32Bits[2], 0x00000000);
573 ok_hex(pulDIB32Bits[3], 0x00000000);
574 todo_ros ok_hex(pulDIB32Bits[4], 0x00000000);
575 todo_ros ok_hex(pulDIB32Bits[5], 0x00000000);
576 ok_hex(pulDIB32Bits[6], 0x00000000);
577 ok_hex(pulDIB32Bits[7], 0x00000000);
578
579 /*****************/
580
581 /* Use bottom-up bitmap */
583
584 memset(gpDIB32, 0, sizeof(*gpDIB32));
586 0, // XDest,
587 0, // YDest,
588 2, // dwWidth,
589 2, // dwHeight,
590 0, // XSrc,
591 0, // YSrc,
592 0, // uStartScan,
593 2, // cScanLines,
594 aulBits, // lpvBits,
595 pbmi,
597
598 ok_dec(ret, 2);
599 ok_hex(pulDIB32Bits[0], 0xFF000000);
600 ok_hex(pulDIB32Bits[1], 0x000000FF);
601 ok_hex(pulDIB32Bits[2], 0x00000000);
602 ok_hex(pulDIB32Bits[3], 0x00000000);
603 ok_hex(pulDIB32Bits[4], 0x11000000);
604 ok_hex(pulDIB32Bits[5], 0x00000011);
605 ok_hex(pulDIB32Bits[6], 0x00000000);
606 ok_hex(pulDIB32Bits[7], 0x00000000);
607
608 memset(gpDIB32, 0, sizeof(*gpDIB32));
610 0, // XDest,
611 1, // YDest,
612 2, // dwWidth,
613 2, // dwHeight,
614 0, // XSrc,
615 0, // YSrc,
616 0, // uStartScan,
617 2, // cScanLines,
618 aulBits, // lpvBits,
619 pbmi,
621
622 ok_dec(ret, 2);
623 ok_hex(pulDIB32Bits[0], 0x00000000);
624 ok_hex(pulDIB32Bits[1], 0x00000000);
625 ok_hex(pulDIB32Bits[2], 0x00000000);
626 ok_hex(pulDIB32Bits[3], 0x00000000);
627 ok_hex(pulDIB32Bits[4], 0xFF000000);
628 ok_hex(pulDIB32Bits[5], 0x000000FF);
629 ok_hex(pulDIB32Bits[6], 0x00000000);
630 ok_hex(pulDIB32Bits[7], 0x00000000);
631 ok_hex(pulDIB32Bits[8], 0x11000000);
632 ok_hex(pulDIB32Bits[9], 0x00000011);
633 ok_hex(pulDIB32Bits[10], 0x00000000);
634 ok_hex(pulDIB32Bits[11], 0x00000000);
635
636 memset(gpDIB32, 0, sizeof(*gpDIB32));
638 0, // XDest,
639 0, // YDest,
640 2, // dwWidth,
641 2, // dwHeight,
642 0, // XSrc,
643 0, // YSrc,
644 0, // uStartScan,
645 1, // cScanLines,
646 aulBits, // lpvBits,
647 pbmi,
649
650 ok_dec(ret, 1);
651 todo_ros ok_hex(pulDIB32Bits[0], 0x00000000);
652 todo_ros ok_hex(pulDIB32Bits[1], 0x00000000);
653 ok_hex(pulDIB32Bits[2], 0x00000000);
654 ok_hex(pulDIB32Bits[3], 0x00000000);
655 todo_ros ok_hex(pulDIB32Bits[4], 0x11000000);
656 todo_ros ok_hex(pulDIB32Bits[5], 0x00000011);
657 ok_hex(pulDIB32Bits[6], 0x00000000);
658 ok_hex(pulDIB32Bits[7], 0x00000000);
659
660
661 memset(gpDIB32, 0, sizeof(*gpDIB32));
663 0, // XDest,
664 0, // YDest,
665 2, // dwWidth,
666 2, // dwHeight,
667 0, // XSrc,
668 0, // YSrc,
669 1, // uStartScan,
670 1, // cScanLines,
671 aulBits, // lpvBits,
672 pbmi,
674
675 ok_dec(ret, 1);
676 todo_ros ok_hex(pulDIB32Bits[0], 0x11000000);
677 todo_ros ok_hex(pulDIB32Bits[1], 0x00000011);
678 ok_hex(pulDIB32Bits[2], 0x00000000);
679 ok_hex(pulDIB32Bits[3], 0x00000000);
680 todo_ros ok_hex(pulDIB32Bits[4], 0x00000000);
681 todo_ros ok_hex(pulDIB32Bits[5], 0x00000000);
682 ok_hex(pulDIB32Bits[6], 0x00000000);
683 ok_hex(pulDIB32Bits[7], 0x00000000);
684#endif
685}
686
687
689{
690 InitStuff();
691
694
695
696}
static void Test_SetDIBitsToDevice()
static void Test_SetDIBitsToDevice_Params()
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok_dec(expression, result)
Definition: atltest.h:101
#define ok_err(error)
Definition: atltest.h:124
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define BI_RGB
Definition: precomp.h:56
#define abs(i)
Definition: fconv.c:206
#define LONG_MAX
Definition: limits.h:43
#define LONG_MIN
Definition: limits.h:42
ULONG(* gpDIB32)[8][8]
Definition: init.c:10
HDC ghdcDIB32
Definition: init.c:8
BOOL InitStuff(void)
Definition: init.c:95
static HDC
Definition: imagelist.c:88
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
#define todo_ros
Definition: test.h:170
#define memset(x, y, z)
Definition: compat.h:39
ULONG biClrImportant
Definition: precomp.h:52
USHORT biBitCount
Definition: precomp.h:46
LONG biYPelsPerMeter
Definition: precomp.h:50
ULONG biCompression
Definition: precomp.h:47
LONG biXPelsPerMeter
Definition: precomp.h:49
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI SetDIBitsToDevice(_In_ HDC, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ int, _In_ int, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
struct tagBITMAPINFO BITMAPINFO
struct tagBITMAPINFO * PBITMAPINFO
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned char BYTE
Definition: xxhash.c:193