[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / PatBlt.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for ...
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <stdio.h>
11 #include <wingdi.h>
12
13 HBITMAP ghbmpTarget;
14 PULONG gpulTargetBits;
15 HDC hdcTarget;
16
17 void Test_PatBlt_Params()
18 {
19 BOOL ret;
20 ULONG i, rop;
21 HDC hdc;
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
80
81 }
82
83 void Test_BrushOrigin()
84 {
85 ULONG aulBits[2] = {0x5555AAAA, 0};
86 HBITMAP hbmp;
87 HBRUSH hbr;
88 BOOL ret;
89
90 hbmp = CreateBitmap(2, 2, 1, 1, aulBits);
91 if (!hbmp)
92 {
93 printf("Couln not create a bitmap\n");
94 return;
95 }
96
97 hbr = CreatePatternBrush(hbmp);
98 if (!hbr)
99 {
100 printf("Couln not create a bitmap\n");
101 return;
102 }
103
104 if (!SelectObject(hdcTarget, hbr))
105 {
106 printf("failed to select pattern brush\n");
107 return;
108 }
109
110 ret = PatBlt(hdcTarget, 0, 0, 2, 2, PATCOPY);
111 ok_long(ret, 1);
112 ok_long(gpulTargetBits[0], 0xffffff);
113 ok_long(gpulTargetBits[1], 0);
114 ok_long(gpulTargetBits[16], 0);
115 ok_long(gpulTargetBits[17], 0xffffff);
116 //printf("0x%lx, 0x%lx\n", gpulTargetBits[0], gpulTargetBits[1]);
117
118 ret = PatBlt(hdcTarget, 1, 0, 2, 2, PATCOPY);
119 ok_long(ret, 1);
120 ok_long(gpulTargetBits[0], 0xffffff);
121 ok_long(gpulTargetBits[1], 0);
122 ok_long(gpulTargetBits[2], 0xffffff);
123 ok_long(gpulTargetBits[16], 0);
124 ok_long(gpulTargetBits[17], 0xffffff);
125 ok_long(gpulTargetBits[18], 0);
126
127 }
128
129 START_TEST(PatBlt)
130 {
131 BITMAPINFO bmi;
132
133 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
134 bmi.bmiHeader.biWidth = 16;
135 bmi.bmiHeader.biHeight = -16;
136 bmi.bmiHeader.biPlanes = 1;
137 bmi.bmiHeader.biBitCount = 32;
138 bmi.bmiHeader.biCompression = BI_RGB;
139 bmi.bmiHeader.biSizeImage = 0;
140 bmi.bmiHeader.biXPelsPerMeter = 1;
141 bmi.bmiHeader.biYPelsPerMeter = 1;
142 bmi.bmiHeader.biClrUsed = 0;
143 bmi.bmiHeader.biClrImportant = 0;
144 ghbmpTarget = CreateDIBSection(NULL,
145 &bmi,
146 DIB_RGB_COLORS,
147 (PVOID*)&gpulTargetBits,
148 NULL,
149 0);
150 if (!ghbmpTarget)
151 {
152 printf("Couln not create target bitmap\n");
153 return;
154 }
155
156 hdcTarget = CreateCompatibleDC(0);
157 if (!hdcTarget)
158 {
159 printf("Couln not create target dc\n");
160 return;
161 }
162
163
164 if (!SelectObject(hdcTarget, ghbmpTarget))
165 {
166 printf("Failed to select bitmap\n");
167 return;
168 }
169
170 Test_PatBlt_Params();
171
172 Test_BrushOrigin();
173
174
175 }
176