Patch by Jerome Gardou: add a bunch of tests for NtGdiBitBlt
[reactos.git] / rostests / apitests / w32knapi / ntgdi / NtGdiBitBlt.c
1
2 INT
3 Test_NtGdiBitBlt(PTESTINFO pti)
4 {
5 BOOL bRet;
6 HDC hdc1, hdc2;
7 HBITMAP hbmp1, hOldBmp1, hbmp2, hOldBmp2;
8 DWORD bytes1[4] = {0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff};
9 DWORD bytes2[4] = {0x00000000, 0x0000000, 0x0000000, 0x00000000};
10
11 /* Test NULL dc */
12 SetLastError(ERROR_SUCCESS);
13 bRet = NtGdiBitBlt((HDC)0, 0, 0, 10, 10, (HDC)0, 10, 10, SRCCOPY, 0, 0);
14 TEST(bRet == FALSE);
15 TEST(GetLastError() == ERROR_SUCCESS);
16
17 /* Test invalid dc */
18 SetLastError(ERROR_SUCCESS);
19 bRet = NtGdiBitBlt((HDC)0x123456, 0, 0, 10, 10, (HDC)0x123456, 10, 10, SRCCOPY, 0, 0);
20 TEST(bRet == FALSE);
21 TEST(GetLastError() == ERROR_SUCCESS);
22
23 hdc1 = NtGdiCreateCompatibleDC(0);
24 TEST(hdc1 != NULL);
25
26 hdc2 = NtGdiCreateCompatibleDC(0);
27 TEST(hdc2 != NULL);
28
29 hbmp1 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes1 );
30 TEST(hbmp1 != NULL);
31 hOldBmp1 = SelectObject(hdc1, hbmp1);
32
33 hbmp2 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes2 );
34 TEST(hbmp2 != NULL);
35 hOldBmp2 = SelectObject(hdc2, hbmp2);
36
37 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0);
38 TEST(bRet == TRUE);
39 TEST(GetLastError() == ERROR_SUCCESS);
40 TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
41 TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
42 TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
43 TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
44
45 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 1, 1, SRCCOPY, 0, 0);
46 TEST(bRet == TRUE);
47 TEST(GetLastError() == ERROR_SUCCESS);
48 TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
49 TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
50 TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
51 TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
52
53 NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
54
55 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0);
56 TEST(bRet == TRUE);
57 TEST(GetLastError() == ERROR_SUCCESS);
58 TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
59 TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
60 TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
61 TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
62
63 bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0);
64 TEST(bRet == TRUE);
65 TEST(GetLastError() == ERROR_SUCCESS);
66 TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00ffffff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
67 TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
68 TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
69 TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
70
71 bRet = NtGdiBitBlt(hdc2, 2, 2, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0);
72 TEST(bRet == TRUE);
73 TEST(GetLastError() == ERROR_SUCCESS);
74 TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
75 TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
76 TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
77 TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
78
79 SelectObject(hdc2, hOldBmp2);
80 SelectObject(hdc1, hOldBmp1);
81
82 DeleteObject(hbmp2);
83 DeleteObject(hbmp1);
84
85 DeleteDC(hdc1);
86 DeleteDC(hdc2);
87
88 return APISTATUS_NORMAL;
89 }