[APITESTS][WIN32KNT_APITEST] Improve NtGdiBitBlt testcase (#1277)
[reactos.git] / modules / rostests / apitests / win32nt / ntgdi / NtGdiBitBlt.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtGdiBitBlt
5 * PROGRAMMERS:
6 */
7
8 #include <win32nt.h>
9
10 START_TEST(NtGdiBitBlt)
11 {
12 BOOL bRet;
13 HDC hdc1, hdc2;
14 HBITMAP hbmp1, hOldBmp1, hbmp2, hOldBmp2;
15 DWORD bytes1[4] = {0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff};
16 DWORD bytes2[4] = {0x00000000, 0x0000000, 0x0000000, 0x00000000};
17
18 /* Test NULL dc */
19 SetLastError(ERROR_SUCCESS);
20 bRet = NtGdiBitBlt((HDC)0, 0, 0, 10, 10, (HDC)0, 10, 10, SRCCOPY, 0, 0);
21 ok_int(bRet, FALSE);
22 ok_long(GetLastError(), ERROR_SUCCESS);
23
24 /* Test invalid dc */
25 SetLastError(ERROR_SUCCESS);
26 bRet = NtGdiBitBlt((HDC)0x123456, 0, 0, 10, 10, (HDC)0x123456, 10, 10, SRCCOPY, 0, 0);
27 ok_int(bRet, FALSE);
28 ok_long(GetLastError(), ERROR_SUCCESS);
29
30 hdc1 = NtGdiCreateCompatibleDC(0);
31 ok(hdc1 != NULL, "hdc1 was NULL.\n");
32
33 hdc2 = NtGdiCreateCompatibleDC(0);
34 ok(hdc2 != NULL, "hdc2 was NULL.\n");
35
36 hbmp1 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes1 );
37 ok(hbmp1 != NULL, "hbmp1 was NULL.\n");
38 hOldBmp1 = SelectObject(hdc1, hbmp1);
39
40 ok(NtGdiGetPixel(hdc1, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
41 ok(NtGdiGetPixel(hdc1, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
42 ok(NtGdiGetPixel(hdc1, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
43 ok(NtGdiGetPixel(hdc1, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
44
45 hbmp2 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes2 );
46 ok(hbmp2 != NULL, "hbmp2 was NULL.\n");
47 hOldBmp2 = SelectObject(hdc2, hbmp2);
48
49 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0);
50 ok_int(bRet, TRUE);
51 ok_long(GetLastError(), ERROR_SUCCESS);
52 ok(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
53 ok(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
54 ok(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
55 ok(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
56
57 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 1, 1, SRCCOPY, 0, 0);
58 ok_int(bRet, TRUE);
59 ok_long(GetLastError(), ERROR_SUCCESS);
60 ok(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
61 ok(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
62 ok(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
63 ok(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
64
65 NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
66
67 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0);
68 ok_int(bRet, TRUE);
69 ok_long(GetLastError(), ERROR_SUCCESS);
70 ok(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
71 ok(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
72 ok(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
73 ok(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
74
75 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0);
76 ok_int(bRet, TRUE);
77 ok_long(GetLastError(), ERROR_SUCCESS);
78 ok(NtGdiGetPixel(hdc2, 0, 0) == 0x00ffffff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
79 ok(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
80 ok(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
81 ok(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
82
83 NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
84
85 bRet = NtGdiBitBlt(hdc2, 2, 2, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0);
86 ok_int(bRet, TRUE);
87 ok_long(GetLastError(), ERROR_SUCCESS);
88 ok(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
89 ok(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
90 ok(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
91 ok(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
92
93 NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
94 NtGdiSetPixel(hdc2, 1, 0, 0x00000000);
95 NtGdiSetPixel(hdc2, 0, 1, 0x00000000);
96 NtGdiSetPixel(hdc2, 1, 1, 0x00000000);
97
98 bRet = NtGdiBitBlt(hdc2, 0, 0, 2, 2, hdc1, 0, 0, SRCCOPY, 0, 0);
99 ok_int(bRet, TRUE);
100 ok_long(GetLastError(), ERROR_SUCCESS);
101 ok(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
102 ok(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
103 ok(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
104 ok(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
105
106 SelectObject(hdc2, hOldBmp2);
107 SelectObject(hdc1, hOldBmp1);
108
109 DeleteObject(hbmp2);
110 DeleteObject(hbmp1);
111
112 DeleteDC(hdc1);
113 DeleteDC(hdc2);
114 }