1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for PatBlt
5 * PROGRAMMERS: Timo Kreuzer
6 * Katayama Hirofumi MZ
7 */
8
9 #include "precomp.h"
10
11 HBITMAP ghbmpTarget;
12 PULONG gpulTargetBits;
13 HDC hdcTarget;
14
Test_PatBlt_Params()15 void Test_PatBlt_Params()
16 {
17 BOOL ret;
18 ULONG i, rop;
19 HDC hdc;
20 HBITMAP hBitmap;
21 HGDIOBJ hOldBitmap;
22
23 /* Test a rop that contains only the operation index */
24 ret = PatBlt(hdcTarget, 0, 0, 1, 1, PATCOPY & 0x00FF0000);
25 ok_long(ret, 1);
26
27 /* Test a rop that contains arbitrary values outside the operation index */
28 ret = PatBlt(hdcTarget, 0, 0, 1, 1, (PATCOPY & 0x00FF0000) | 0xab00cdef);
29 ok_long(ret, 1);
30
31 /* Test an invalid rop */
32 SetLastError(0);
33 ok_long(PatBlt(hdcTarget, 0, 0, 1, 1, SRCCOPY) , 0);
34 ok_err(0);
35
36 /* Test all rops */
37 for (i = 0; i < 256; i++)
38 {
39 rop = i << 16;
40 ret = PatBlt(hdcTarget, 0, 0, 1, 1, rop);
41
42 /* Only these should succeed (they use no source) */
43 if ((i == 0) || (i == 5) || (i == 10) || (i == 15) || (i == 80) ||
44 (i == 85) || (i == 90) || (i == 95) || (i == 160) || (i == 165) ||
45 (i == 170) || (i == 175) || (i == 240) || (i == 245) ||
46 (i == 250) || (i == 255))
47 {
48 ok(ret == 1, "index %ld failed, but should succeed\n", i);
49 }
50 else
51 {
52 ok(ret == 0, "index %ld succeeded, but should fail\n", i);
53 }
54 }
55
56 /* Test quaternary rop, the background part is simply ignored */
57 ret = PatBlt(hdcTarget, 0, 0, 1, 1, MAKEROP4(PATCOPY, PATINVERT));
58 ok_long(ret, 1);
59 ret = PatBlt(hdcTarget, 0, 0, 1, 1, MAKEROP4(PATCOPY, SRCCOPY));
60 ok_long(ret, 1);
61 ret = PatBlt(hdcTarget, 0, 0, 1, 1, MAKEROP4(SRCCOPY, PATCOPY));
62 ok_long(ret, 0);
63
64 /* Test an info DC */
65 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
66 ok(hdc != 0, "\n");
67 SetLastError(0);
68 ok_long(PatBlt(hdc, 0, 0, 1, 1, PATCOPY), 1);
69 ok_err(0);
70 DeleteDC(hdc);
71
72 /* Test a mem DC without selecting a bitmap */
73 hdc = CreateCompatibleDC(NULL);
74 ok(hdc != 0, "\n");
75 ok_long(PatBlt(hdc, 0, 0, 1, 1, PATCOPY), 1);
76 ok_err(0);
77 DeleteDC(hdc);
78
79 /* Test with bitmap and negative values */
80 hdc = CreateCompatibleDC(NULL);
81 hBitmap = CreateCompatibleBitmap(hdc, 8, 8);
82 hOldBitmap = SelectObject(hdc, hBitmap);
83 SelectObject(hdc, GetStockObject(WHITE_BRUSH));
84 ok_long(PatBlt(hdc, 2, 2, -1, 1, PATCOPY), TRUE);
85 ok_long(GetPixel(hdc, 1, 1), RGB(0, 0, 0));
86 ok_long(GetPixel(hdc, 1, 2), RGB(255, 255, 255));
87 ok_long(GetPixel(hdc, 1, 3), RGB(0, 0, 0));
88 ok_long(GetPixel(hdc, 2, 1), RGB(0, 0, 0));
89 ok_long(GetPixel(hdc, 2, 2), RGB(0, 0, 0));
90 SetPixel(hdc, 1, 2, RGB(0, 0, 0));
91 ok_long(PatBlt(hdc, 2, 2, 1, -1, PATCOPY), TRUE);
92 ok_long(GetPixel(hdc, 1, 2), RGB(0, 0, 0));
93 ok_long(GetPixel(hdc, 1, 3), RGB(0, 0, 0));
94 ok_long(GetPixel(hdc, 2, 1), RGB(255, 255, 255));
95 ok_long(GetPixel(hdc, 2, 2), RGB(0, 0, 0));
96 ok_long(GetPixel(hdc, 2, 3), RGB(0, 0, 0));
97 SetPixel(hdc, 2, 1, RGB(0, 0, 0));
98 ok_long(PatBlt(hdc, 3, 2, -2, -1, PATCOPY), TRUE);
99 ok_long(GetPixel(hdc, 0, 2), RGB(0, 0, 0));
100 ok_long(GetPixel(hdc, 0, 3), RGB(0, 0, 0));
101 ok_long(GetPixel(hdc, 1, 1), RGB(255, 255, 255));
102 ok_long(GetPixel(hdc, 1, 2), RGB(0, 0, 0));
103 ok_long(GetPixel(hdc, 1, 3), RGB(0, 0, 0));
104 ok_long(GetPixel(hdc, 2, 1), RGB(255, 255, 255));
105 ok_long(GetPixel(hdc, 2, 2), RGB(0, 0, 0));
106 ok_long(GetPixel(hdc, 2, 3), RGB(0, 0, 0));
107 DeleteObject(SelectObject(hdc, hOldBitmap));
108 DeleteDC(hdc);
109 }
110
Test_BrushOrigin()111 void Test_BrushOrigin()
112 {
113 ULONG aulBits[2] = {0x5555AAAA, 0};
114 HBITMAP hbmp;
115 HBRUSH hbr;
116 BOOL ret;
117
118 hbmp = CreateBitmap(2, 2, 1, 1, aulBits);
119 if (!hbmp)
120 {
121 printf("Couln not create a bitmap\n");
122 return;
123 }
124
125 hbr = CreatePatternBrush(hbmp);
126 if (!hbr)
127 {
128 printf("Couln not create a bitmap\n");
129 return;
130 }
131
132 if (!SelectObject(hdcTarget, hbr))
133 {
134 printf("failed to select pattern brush\n");
135 return;
136 }
137
138 ret = PatBlt(hdcTarget, 0, 0, 2, 2, PATCOPY);
139 ok_long(ret, 1);
140 ok_long(gpulTargetBits[0], 0xffffff);
141 ok_long(gpulTargetBits[1], 0);
142 ok_long(gpulTargetBits[16], 0);
143 ok_long(gpulTargetBits[17], 0xffffff);
144 //printf("0x%lx, 0x%lx\n", gpulTargetBits[0], gpulTargetBits[1]);
145
146 ret = PatBlt(hdcTarget, 1, 0, 2, 2, PATCOPY);
147 ok_long(ret, 1);
148 ok_long(gpulTargetBits[0], 0xffffff);
149 ok_long(gpulTargetBits[1], 0);
150 ok_long(gpulTargetBits[2], 0xffffff);
151 ok_long(gpulTargetBits[16], 0);
152 ok_long(gpulTargetBits[17], 0xffffff);
153 ok_long(gpulTargetBits[18], 0);
154 }
155
START_TEST(PatBlt)156 START_TEST(PatBlt)
157 {
158 BITMAPINFO bmi;
159
160 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
161 bmi.bmiHeader.biWidth = 16;
162 bmi.bmiHeader.biHeight = -16;
163 bmi.bmiHeader.biPlanes = 1;
164 bmi.bmiHeader.biBitCount = 32;
165 bmi.bmiHeader.biCompression = BI_RGB;
166 bmi.bmiHeader.biSizeImage = 0;
167 bmi.bmiHeader.biXPelsPerMeter = 1;
168 bmi.bmiHeader.biYPelsPerMeter = 1;
169 bmi.bmiHeader.biClrUsed = 0;
170 bmi.bmiHeader.biClrImportant = 0;
171 ghbmpTarget = CreateDIBSection(NULL,
172 &bmi,
173 DIB_RGB_COLORS,
174 (PVOID*)&gpulTargetBits,
175 NULL,
176 0);
177 if (!ghbmpTarget)
178 {
179 printf("Couln not create target bitmap\n");
180 return;
181 }
182
183 hdcTarget = CreateCompatibleDC(0);
184 if (!hdcTarget)
185 {
186 printf("Couln not create target dc\n");
187 return;
188 }
189
190 if (!SelectObject(hdcTarget, ghbmpTarget))
191 {
192 printf("Failed to select bitmap\n");
193 return;
194 }
195
196 Test_PatBlt_Params();
197
198 Test_BrushOrigin();
199 }
200