18832f19b488e6de2eaa1b6380748703f78997ef
[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 <stdio.h>
9 #include <wine/test.h>
10 #include <wingdi.h>
11
12 HBITMAP ghbmpTarget;
13 PULONG gpulTargetBits;
14 HDC hdcTarget;
15
16 void Test_PatBlt_Params()
17 {
18 BOOL ret;
19 ULONG i, rop;
20 HDC hdc;
21
22 /* Test a rop that contains only the operation index */
23 ret = PatBlt(hdcTarget, 0, 0, 1, 1, PATCOPY & 0x00FF0000);
24 ok_long(ret, 1);
25
26 /* Test an invalid rop */
27 SetLastError(0);
28 ok_long(PatBlt(hdcTarget, 0, 0, 1, 1, SRCCOPY) , 0);
29 ok_err(0);
30
31 /* Test all rops */
32 for (i = 0; i < 256; i++)
33 {
34 rop = i << 16;
35 ret = PatBlt(hdcTarget, 0, 0, 1, 1, rop);
36
37 /* Only these should succeed (they use no source) */
38 if ((i == 0) || (i == 5) || (i == 10) || (i == 15) || (i == 80) ||
39 (i == 85) || (i == 90) || (i == 95) || (i == 160) || (i == 165) ||
40 (i == 170) || (i == 175) || (i == 240) || (i == 245) ||
41 (i == 250) || (i == 255))
42 {
43 ok(ret == 1, "index %ld failed, but should succeed\n", i);
44 }
45 else
46 {
47 ok(ret == 0, "index %ld succeeded, but should fail\n", i);
48 }
49 }
50
51 /* Test quaternary rop, the background part is simply ignored */
52 ret = PatBlt(hdcTarget, 0, 0, 1, 1, MAKEROP4(PATCOPY, PATINVERT));
53 ok_long(ret, 1);
54 ret = PatBlt(hdcTarget, 0, 0, 1, 1, MAKEROP4(PATCOPY, SRCCOPY));
55 ok_long(ret, 1);
56 ret = PatBlt(hdcTarget, 0, 0, 1, 1, MAKEROP4(SRCCOPY, PATCOPY));
57 ok_long(ret, 0);
58
59 /* Test an info DC */
60 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
61 ok(hdc != 0, "\n");
62 SetLastError(0);
63 ok_long(PatBlt(hdc, 0, 0, 1, 1, PATCOPY), 1);
64 ok_err(0);
65 DeleteDC(hdc);
66
67 /* Test a mem DC without selecting a bitmap */
68 hdc = CreateCompatibleDC(NULL);
69 ok(hdc != 0, "\n");
70 ok_long(PatBlt(hdc, 0, 0, 1, 1, PATCOPY), 1);
71 ok_err(0);
72 DeleteDC(hdc);
73
74
75
76 }
77
78 void Test_BrushOrigin()
79 {
80 ULONG aulBits[2] = {0x5555AAAA, 0};
81 HBITMAP hbmp;
82 HBRUSH hbr;
83 BOOL ret;
84
85 hbmp = CreateBitmap(2, 2, 1, 1, aulBits);
86 if (!hbmp)
87 {
88 printf("Couln not create a bitmap\n");
89 return;
90 }
91
92 hbr = CreatePatternBrush(hbmp);
93 if (!hbr)
94 {
95 printf("Couln not create a bitmap\n");
96 return;
97 }
98
99 if (!SelectObject(hdcTarget, hbr))
100 {
101 printf("failed to select pattern brush\n");
102 return;
103 }
104
105 ret = PatBlt(hdcTarget, 0, 0, 2, 2, PATCOPY);
106 ok_long(ret, 1);
107 ok_long(gpulTargetBits[0], 0xffffff);
108 ok_long(gpulTargetBits[1], 0);
109 ok_long(gpulTargetBits[16], 0);
110 ok_long(gpulTargetBits[17], 0xffffff);
111 //printf("0x%lx, 0x%lx\n", gpulTargetBits[0], gpulTargetBits[1]);
112
113 ret = PatBlt(hdcTarget, 1, 0, 2, 2, PATCOPY);
114 ok_long(ret, 1);
115 ok_long(gpulTargetBits[0], 0xffffff);
116 ok_long(gpulTargetBits[1], 0);
117 ok_long(gpulTargetBits[2], 0xffffff);
118 ok_long(gpulTargetBits[16], 0);
119 ok_long(gpulTargetBits[17], 0xffffff);
120 ok_long(gpulTargetBits[18], 0);
121
122 }
123
124 START_TEST(PatBlt)
125 {
126 BITMAPINFO bmi;
127
128 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
129 bmi.bmiHeader.biWidth = 16;
130 bmi.bmiHeader.biHeight = -16;
131 bmi.bmiHeader.biPlanes = 1;
132 bmi.bmiHeader.biBitCount = 32;
133 bmi.bmiHeader.biCompression = BI_RGB;
134 bmi.bmiHeader.biSizeImage = 0;
135 bmi.bmiHeader.biXPelsPerMeter = 1;
136 bmi.bmiHeader.biYPelsPerMeter = 1;
137 bmi.bmiHeader.biClrUsed = 0;
138 bmi.bmiHeader.biClrImportant = 0;
139 ghbmpTarget = CreateDIBSection(NULL,
140 &bmi,
141 DIB_RGB_COLORS,
142 (PVOID*)&gpulTargetBits,
143 NULL,
144 0);
145 if (!ghbmpTarget)
146 {
147 printf("Couln not create target bitmap\n");
148 return;
149 }
150
151 hdcTarget = CreateCompatibleDC(0);
152 if (!hdcTarget)
153 {
154 printf("Couln not create target dc\n");
155 return;
156 }
157
158
159 if (!SelectObject(hdcTarget, ghbmpTarget))
160 {
161 printf("Failed to select bitmap\n");
162 return;
163 }
164
165 Test_PatBlt_Params();
166
167 Test_BrushOrigin();
168
169
170 }
171