2 * Unit test suite for gdiplus regions
4 * Copyright (C) 2008 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 #define RGNDATA_RECT 0x10000000
27 #define RGNDATA_PATH 0x10000001
28 #define RGNDATA_EMPTY_RECT 0x10000002
29 #define RGNDATA_INFINITE_RECT 0x10000003
31 #define RGNDATA_MAGIC 0xdbc01001
33 static inline void expect_dword(DWORD *value, DWORD expected)
35 ok(*value == expected, "expected %08x got %08x\n", expected, *value);
38 static inline void expect_float(DWORD *value, FLOAT expected)
40 FLOAT valuef = *(FLOAT*)value;
41 ok(valuef == expected, "expected %f got %f\n", expected, valuef);
44 static void test_getregiondata(void)
47 GpRegion *region, *region2;
53 status = GdipCreateRegion(®ion);
55 ok(status == Ok, "status %08x\n", status);
57 if(status != Ok) return;
59 status = GdipGetRegionDataSize(region, &needed);
60 ok(status == Ok, "status %08x\n", status);
61 ok(needed == 20, "got %d\n", needed);
62 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
63 ok(status == Ok, "status %08x\n", status);
64 ok(needed == 20, "got %d\n", needed);
65 expect_dword(buf, 12);
66 trace("buf[1] = %08x\n", buf[1]);
67 expect_dword(buf + 2, RGNDATA_MAGIC);
68 expect_dword(buf + 3, 0);
69 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
71 status = GdipSetEmpty(region);
72 ok(status == Ok, "status %08x\n", status);
73 status = GdipGetRegionDataSize(region, &needed);
74 ok(status == Ok, "status %08x\n", status);
75 ok(needed == 20, "got %d\n", needed);
76 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
77 ok(status == Ok, "status %08x\n", status);
78 ok(needed == 20, "got %d\n", needed);
79 expect_dword(buf, 12);
80 trace("buf[1] = %08x\n", buf[1]);
81 expect_dword(buf + 2, RGNDATA_MAGIC);
82 expect_dword(buf + 3, 0);
83 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
85 status = GdipSetInfinite(region);
86 ok(status == Ok, "status %08x\n", status);
87 status = GdipGetRegionDataSize(region, &needed);
88 ok(status == Ok, "status %08x\n", status);
89 ok(needed == 20, "got %d\n", needed);
90 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
91 ok(status == Ok, "status %08x\n", status);
92 ok(needed == 20, "got %d\n", needed);
93 expect_dword(buf, 12);
94 trace("buf[1] = %08x\n", buf[1]);
95 expect_dword(buf + 2, RGNDATA_MAGIC);
96 expect_dword(buf + 3, 0);
97 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
99 status = GdipDeleteRegion(region);
100 ok(status == Ok, "status %08x\n", status);
106 status = GdipCreateRegionRectI(&rect, ®ion);
107 ok(status == Ok, "status %08x\n", status);
108 status = GdipGetRegionDataSize(region, &needed);
109 ok(status == Ok, "status %08x\n", status);
110 ok(needed == 36, "got %d\n", needed);
111 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
112 ok(status == Ok, "status %08x\n", status);
113 ok(needed == 36, "got %d\n", needed);
114 expect_dword(buf, 28);
115 trace("buf[1] = %08x\n", buf[1]);
116 expect_dword(buf + 2, RGNDATA_MAGIC);
117 expect_dword(buf + 3, 0);
118 expect_dword(buf + 4, RGNDATA_RECT);
119 expect_float(buf + 5, 10.0);
120 expect_float(buf + 6, 20.0);
121 expect_float(buf + 7, 100.0);
122 expect_float(buf + 8, 200.0);
128 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
129 ok(status == Ok, "status %08x\n", status);
134 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
135 ok(status == Ok, "status %08x\n", status);
141 status = GdipCreateRegionRectI(&rect, ®ion2);
142 ok(status == Ok, "status %08x\n", status);
147 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
148 ok(status == Ok, "status %08x\n", status);
150 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
151 ok(status == Ok, "status %08x\n", status);
157 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
158 ok(status == Ok, "status %08x\n", status);
160 status = GdipGetRegionDataSize(region, &needed);
161 ok(status == Ok, "status %08x\n", status);
162 ok(needed == 156, "got %d\n", needed);
163 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
164 ok(status == Ok, "status %08x\n", status);
165 ok(needed == 156, "got %d\n", needed);
166 expect_dword(buf, 148);
167 trace("buf[1] = %08x\n", buf[1]);
168 expect_dword(buf + 2, RGNDATA_MAGIC);
169 expect_dword(buf + 3, 10);
170 expect_dword(buf + 4, CombineModeExclude);
171 expect_dword(buf + 5, CombineModeComplement);
172 expect_dword(buf + 6, CombineModeXor);
173 expect_dword(buf + 7, CombineModeIntersect);
174 expect_dword(buf + 8, RGNDATA_RECT);
175 expect_float(buf + 9, 10.0);
176 expect_float(buf + 10, 20.0);
177 expect_float(buf + 11, 100.0);
178 expect_float(buf + 12, 200.0);
179 expect_dword(buf + 13, RGNDATA_RECT);
180 expect_float(buf + 14, 50.0);
181 expect_float(buf + 15, 30.0);
182 expect_float(buf + 16, 10.0);
183 expect_float(buf + 17, 20.0);
184 expect_dword(buf + 18, RGNDATA_RECT);
185 expect_float(buf + 19, 100.0);
186 expect_float(buf + 20, 300.0);
187 expect_float(buf + 21, 30.0);
188 expect_float(buf + 22, 50.0);
189 expect_dword(buf + 23, CombineModeUnion);
190 expect_dword(buf + 24, RGNDATA_RECT);
191 expect_float(buf + 25, 200.0);
192 expect_float(buf + 26, 100.0);
193 expect_float(buf + 27, 133.0);
194 expect_float(buf + 28, 266.0);
195 expect_dword(buf + 29, RGNDATA_RECT);
196 expect_float(buf + 30, 20.0);
197 expect_float(buf + 31, 10.0);
198 expect_float(buf + 32, 40.0);
199 expect_float(buf + 33, 66.0);
200 expect_dword(buf + 34, RGNDATA_RECT);
201 expect_float(buf + 35, 400.0);
202 expect_float(buf + 36, 500.0);
203 expect_float(buf + 37, 22.0);
204 expect_float(buf + 38, 55.0);
207 status = GdipDeleteRegion(region2);
208 ok(status == Ok, "status %08x\n", status);
209 status = GdipDeleteRegion(region);
210 ok(status == Ok, "status %08x\n", status);
214 status = GdipCreatePath(FillModeAlternate, &path);
215 ok(status == Ok, "status %08x\n", status);
216 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
218 status = GdipCreateRegionPath(path, ®ion);
219 ok(status == Ok, "status %08x\n", status);
220 status = GdipGetRegionDataSize(region, &needed);
221 ok(status == Ok, "status %08x\n", status);
222 ok(needed == 72, "got %d\n", needed);
223 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
224 ok(status == Ok, "status %08x\n", status);
225 ok(needed == 72, "got %d\n", needed);
226 expect_dword(buf, 64);
227 trace("buf[1] = %08x\n", buf[1]);
228 expect_dword(buf + 2, RGNDATA_MAGIC);
229 expect_dword(buf + 3, 0);
230 expect_dword(buf + 4, RGNDATA_PATH);
231 expect_dword(buf + 5, 0x00000030);
232 expect_dword(buf + 6, RGNDATA_MAGIC);
233 expect_dword(buf + 7, 0x00000004);
234 expect_dword(buf + 8, 0x00000000);
235 expect_float(buf + 9, 12.5);
236 expect_float(buf + 10, 13.0);
237 expect_float(buf + 11, 26.5);
238 expect_float(buf + 12, 13.0);
239 expect_float(buf + 13, 26.5);
240 expect_float(buf + 14, 28.0);
241 expect_float(buf + 15, 12.5);
242 expect_float(buf + 16, 28.0);
243 expect_dword(buf + 17, 0x81010100);
250 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
251 ok(status == Ok, "status %08x\n", status);
252 status = GdipGetRegionDataSize(region, &needed);
253 ok(status == Ok, "status %08x\n", status);
254 ok(needed == 96, "got %d\n", needed);
255 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
256 ok(status == Ok, "status %08x\n", status);
257 ok(needed == 96, "got %d\n", needed);
258 expect_dword(buf, 88);
259 trace("buf[1] = %08x\n", buf[1]);
260 expect_dword(buf + 2, RGNDATA_MAGIC);
261 expect_dword(buf + 3, 2);
262 expect_dword(buf + 4, CombineModeIntersect);
263 expect_dword(buf + 5, RGNDATA_PATH);
264 expect_dword(buf + 6, 0x00000030);
265 expect_dword(buf + 7, RGNDATA_MAGIC);
266 expect_dword(buf + 8, 0x00000004);
267 expect_dword(buf + 9, 0x00000000);
268 expect_float(buf + 10, 12.5);
269 expect_float(buf + 11, 13.0);
270 expect_float(buf + 12, 26.5);
271 expect_float(buf + 13, 13.0);
272 expect_float(buf + 14, 26.5);
273 expect_float(buf + 15, 28.0);
274 expect_float(buf + 16, 12.5);
275 expect_float(buf + 17, 28.0);
276 expect_dword(buf + 18, 0x81010100);
277 expect_dword(buf + 19, RGNDATA_RECT);
278 expect_float(buf + 20, 50.0);
279 expect_float(buf + 21, 30.0);
280 expect_float(buf + 22, 10.0);
281 expect_float(buf + 23, 20.0);
283 status = GdipDeleteRegion(region);
284 ok(status == Ok, "status %08x\n", status);
285 status = GdipDeletePath(path);
286 ok(status == Ok, "status %08x\n", status);
292 struct GdiplusStartupInput gdiplusStartupInput;
293 ULONG_PTR gdiplusToken;
295 gdiplusStartupInput.GdiplusVersion = 1;
296 gdiplusStartupInput.DebugEventCallback = NULL;
297 gdiplusStartupInput.SuppressBackgroundThread = 0;
298 gdiplusStartupInput.SuppressExternalCodecs = 0;
300 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
302 test_getregiondata();
304 GdiplusShutdown(gdiplusToken);