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
32 #define RGNDATA_MAGIC2 0xdbc01002
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
36 #define expect_magic(value) ok(*value == RGNDATA_MAGIC || *value == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *value)
38 static inline void expect_dword(DWORD *value, DWORD expected)
40 ok(*value == expected, "expected %08x got %08x\n", expected, *value);
43 static inline void expect_float(DWORD *value, FLOAT expected)
45 FLOAT valuef = *(FLOAT*)value;
46 ok(valuef == expected, "expected %f got %f\n", expected, valuef);
49 /* We get shorts back, not INTs like a GpPoint */
50 typedef struct RegionDataPoint
55 static void test_getregiondata(void)
58 GpRegion *region, *region2;
59 RegionDataPoint *point;
65 status = GdipCreateRegion(®ion);
67 ok(status == Ok, "status %08x\n", status);
69 if(status != Ok) return;
71 status = GdipGetRegionDataSize(region, &needed);
72 ok(status == Ok, "status %08x\n", status);
73 ok(needed == 20, "got %d\n", needed);
74 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
75 ok(status == Ok, "status %08x\n", status);
76 ok(needed == 20, "got %d\n", needed);
77 expect_dword(buf, 12);
78 trace("buf[1] = %08x\n", buf[1]);
79 expect_magic((DWORD*)(buf + 2));
80 expect_dword(buf + 3, 0);
81 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
83 status = GdipSetEmpty(region);
84 ok(status == Ok, "status %08x\n", status);
85 status = GdipGetRegionDataSize(region, &needed);
86 ok(status == Ok, "status %08x\n", status);
87 ok(needed == 20, "got %d\n", needed);
88 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
89 ok(status == Ok, "status %08x\n", status);
90 ok(needed == 20, "got %d\n", needed);
91 expect_dword(buf, 12);
92 trace("buf[1] = %08x\n", buf[1]);
93 expect_magic((DWORD*)(buf + 2));
94 expect_dword(buf + 3, 0);
95 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
97 status = GdipSetInfinite(region);
98 ok(status == Ok, "status %08x\n", status);
99 status = GdipGetRegionDataSize(region, &needed);
100 ok(status == Ok, "status %08x\n", status);
101 ok(needed == 20, "got %d\n", needed);
102 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
103 ok(status == Ok, "status %08x\n", status);
104 ok(needed == 20, "got %d\n", needed);
105 expect_dword(buf, 12);
106 trace("buf[1] = %08x\n", buf[1]);
107 expect_magic((DWORD*)(buf + 2));
108 expect_dword(buf + 3, 0);
109 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
111 status = GdipDeleteRegion(region);
112 ok(status == Ok, "status %08x\n", status);
118 status = GdipCreateRegionRectI(&rect, ®ion);
119 ok(status == Ok, "status %08x\n", status);
120 status = GdipGetRegionDataSize(region, &needed);
121 ok(status == Ok, "status %08x\n", status);
122 ok(needed == 36, "got %d\n", needed);
123 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
124 ok(status == Ok, "status %08x\n", status);
125 ok(needed == 36, "got %d\n", needed);
126 expect_dword(buf, 28);
127 trace("buf[1] = %08x\n", buf[1]);
128 expect_magic((DWORD*)(buf + 2));
129 expect_dword(buf + 3, 0);
130 expect_dword(buf + 4, RGNDATA_RECT);
131 expect_float(buf + 5, 10.0);
132 expect_float(buf + 6, 20.0);
133 expect_float(buf + 7, 100.0);
134 expect_float(buf + 8, 200.0);
140 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
141 ok(status == Ok, "status %08x\n", status);
146 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
147 ok(status == Ok, "status %08x\n", status);
153 status = GdipCreateRegionRectI(&rect, ®ion2);
154 ok(status == Ok, "status %08x\n", status);
159 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
160 ok(status == Ok, "status %08x\n", status);
162 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
163 ok(status == Ok, "status %08x\n", status);
169 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
170 ok(status == Ok, "status %08x\n", status);
172 status = GdipGetRegionDataSize(region, &needed);
173 ok(status == Ok, "status %08x\n", status);
174 ok(needed == 156, "got %d\n", needed);
175 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
176 ok(status == Ok, "status %08x\n", status);
177 ok(needed == 156, "got %d\n", needed);
178 expect_dword(buf, 148);
179 trace("buf[1] = %08x\n", buf[1]);
180 expect_magic((DWORD*)(buf + 2));
181 expect_dword(buf + 3, 10);
182 expect_dword(buf + 4, CombineModeExclude);
183 expect_dword(buf + 5, CombineModeComplement);
184 expect_dword(buf + 6, CombineModeXor);
185 expect_dword(buf + 7, CombineModeIntersect);
186 expect_dword(buf + 8, RGNDATA_RECT);
187 expect_float(buf + 9, 10.0);
188 expect_float(buf + 10, 20.0);
189 expect_float(buf + 11, 100.0);
190 expect_float(buf + 12, 200.0);
191 expect_dword(buf + 13, RGNDATA_RECT);
192 expect_float(buf + 14, 50.0);
193 expect_float(buf + 15, 30.0);
194 expect_float(buf + 16, 10.0);
195 expect_float(buf + 17, 20.0);
196 expect_dword(buf + 18, RGNDATA_RECT);
197 expect_float(buf + 19, 100.0);
198 expect_float(buf + 20, 300.0);
199 expect_float(buf + 21, 30.0);
200 expect_float(buf + 22, 50.0);
201 expect_dword(buf + 23, CombineModeUnion);
202 expect_dword(buf + 24, RGNDATA_RECT);
203 expect_float(buf + 25, 200.0);
204 expect_float(buf + 26, 100.0);
205 expect_float(buf + 27, 133.0);
206 expect_float(buf + 28, 266.0);
207 expect_dword(buf + 29, RGNDATA_RECT);
208 expect_float(buf + 30, 20.0);
209 expect_float(buf + 31, 10.0);
210 expect_float(buf + 32, 40.0);
211 expect_float(buf + 33, 66.0);
212 expect_dword(buf + 34, RGNDATA_RECT);
213 expect_float(buf + 35, 400.0);
214 expect_float(buf + 36, 500.0);
215 expect_float(buf + 37, 22.0);
216 expect_float(buf + 38, 55.0);
219 status = GdipDeleteRegion(region2);
220 ok(status == Ok, "status %08x\n", status);
221 status = GdipDeleteRegion(region);
222 ok(status == Ok, "status %08x\n", status);
226 status = GdipCreatePath(FillModeAlternate, &path);
227 ok(status == Ok, "status %08x\n", status);
228 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
230 status = GdipCreateRegionPath(path, ®ion);
231 ok(status == Ok, "status %08x\n", status);
232 status = GdipGetRegionDataSize(region, &needed);
233 ok(status == Ok, "status %08x\n", status);
234 ok(needed == 72, "got %d\n", needed);
235 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
236 ok(status == Ok, "status %08x\n", status);
237 ok(needed == 72, "got %d\n", needed);
238 expect_dword(buf, 64);
239 trace("buf[1] = %08x\n", buf[1]);
240 expect_magic((DWORD*)(buf + 2));
241 expect_dword(buf + 3, 0);
242 expect_dword(buf + 4, RGNDATA_PATH);
243 expect_dword(buf + 5, 0x00000030);
244 expect_magic((DWORD*)(buf + 6));
245 expect_dword(buf + 7, 0x00000004);
246 expect_dword(buf + 8, 0x00000000);
247 expect_float(buf + 9, 12.5);
248 expect_float(buf + 10, 13.0);
249 expect_float(buf + 11, 26.5);
250 expect_float(buf + 12, 13.0);
251 expect_float(buf + 13, 26.5);
252 expect_float(buf + 14, 28.0);
253 expect_float(buf + 15, 12.5);
254 expect_float(buf + 16, 28.0);
255 expect_dword(buf + 17, 0x81010100);
262 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
263 ok(status == Ok, "status %08x\n", status);
264 status = GdipGetRegionDataSize(region, &needed);
265 ok(status == Ok, "status %08x\n", status);
266 ok(needed == 96, "got %d\n", needed);
267 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
268 ok(status == Ok, "status %08x\n", status);
269 ok(needed == 96, "got %d\n", needed);
270 expect_dword(buf, 88);
271 trace("buf[1] = %08x\n", buf[1]);
272 expect_magic((DWORD*)(buf + 2));
273 expect_dword(buf + 3, 2);
274 expect_dword(buf + 4, CombineModeIntersect);
275 expect_dword(buf + 5, RGNDATA_PATH);
276 expect_dword(buf + 6, 0x00000030);
277 expect_magic((DWORD*)(buf + 7));
278 expect_dword(buf + 8, 0x00000004);
279 expect_dword(buf + 9, 0x00000000);
280 expect_float(buf + 10, 12.5);
281 expect_float(buf + 11, 13.0);
282 expect_float(buf + 12, 26.5);
283 expect_float(buf + 13, 13.0);
284 expect_float(buf + 14, 26.5);
285 expect_float(buf + 15, 28.0);
286 expect_float(buf + 16, 12.5);
287 expect_float(buf + 17, 28.0);
288 expect_dword(buf + 18, 0x81010100);
289 expect_dword(buf + 19, RGNDATA_RECT);
290 expect_float(buf + 20, 50.0);
291 expect_float(buf + 21, 30.0);
292 expect_float(buf + 22, 10.0);
293 expect_float(buf + 23, 20.0);
295 status = GdipDeleteRegion(region);
296 ok(status == Ok, "status %08x\n", status);
297 status = GdipDeletePath(path);
298 ok(status == Ok, "status %08x\n", status);
300 /* Test an empty path */
301 status = GdipCreatePath(FillModeAlternate, &path);
303 status = GdipCreateRegionPath(path, ®ion);
305 status = GdipGetRegionDataSize(region, &needed);
307 ok(needed == 36, "got %d\n", needed);
308 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
310 ok(needed == 36, "got %d\n", needed);
311 expect_dword(buf, 28);
312 trace("buf[1] = %08x\n", buf[1]);
313 expect_magic((DWORD*)(buf + 2));
314 expect_dword(buf + 3, 0);
315 expect_dword(buf + 4, RGNDATA_PATH);
317 /* Second signature for pathdata */
318 expect_dword(buf + 5, 12);
319 expect_magic((DWORD*)(buf + 6));
320 expect_dword(buf + 7, 0);
321 expect_dword(buf + 8, 0x00004000);
323 status = GdipDeleteRegion(region);
326 /* Test a simple triangle of INTs */
327 status = GdipAddPathLine(path, 5, 6, 7, 8);
329 status = GdipAddPathLine(path, 7, 8, 8, 1);
331 status = GdipAddPathLine(path, 8, 1, 5, 6);
333 status = GdipClosePathFigure(path);
335 status = GdipCreateRegionPath(path, ®ion);
337 status = GdipGetRegionDataSize(region, &needed);
339 ok(needed == 56, "Expected 56, got %d\n", needed);
340 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
342 expect_dword(buf, 48);
343 trace("buf[1] = %08x\n", buf[1]);
344 expect_magic((DWORD*)(buf + 2));
345 expect_dword(buf + 3 , 0);
346 expect_dword(buf + 4 , RGNDATA_PATH);
348 expect_dword(buf + 5, 32);
349 expect_magic((DWORD*)(buf + 6));
350 expect_dword(buf + 7, 4);
351 expect_dword(buf + 8, 0x00004000); /* ?? */
353 point = (RegionDataPoint*)buf + 9;
354 expect(5, point[0].X);
355 expect(6, point[0].Y);
356 expect(7, point[1].X); /* buf + 10 */
357 expect(8, point[1].Y);
358 expect(8, point[2].X); /* buf + 11 */
359 expect(1, point[2].Y);
360 expect(5, point[3].X); /* buf + 12 */
361 expect(6, point[3].Y);
362 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
363 status = GdipDeletePath(path);
365 status = GdipDeleteRegion(region);
368 /* Test a floating-point triangle */
369 status = GdipCreatePath(FillModeAlternate, &path);
371 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
373 status = GdipAddPathLine(path, 7.2, 8.9, 8.1, 1.6);
375 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
377 status = GdipCreateRegionPath(path, ®ion);
379 status = GdipGetRegionDataSize(region, &needed);
381 ok(needed == 72, "Expected 72, got %d\n", needed);
382 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
384 expect_dword(buf, 64);
385 trace("buf[1] = %08x\n", buf[1]);
386 expect_magic((DWORD*)(buf + 2));
387 expect_dword(buf + 3, 0);
388 expect_dword(buf + 4, RGNDATA_PATH);
390 expect_dword(buf + 5, 48);
391 expect_magic((DWORD*)(buf + 6));
392 expect_dword(buf + 7, 4);
393 expect_dword(buf + 8, 0);
394 expect_float(buf + 9, 5.6);
395 expect_float(buf + 10, 6.2);
396 expect_float(buf + 11, 7.2);
397 expect_float(buf + 12, 8.9);
398 expect_float(buf + 13, 8.1);
399 expect_float(buf + 14, 1.6);
400 expect_float(buf + 15, 5.6);
401 expect_float(buf + 16, 6.2);
403 status = GdipDeleteRegion(region);
409 struct GdiplusStartupInput gdiplusStartupInput;
410 ULONG_PTR gdiplusToken;
412 gdiplusStartupInput.GdiplusVersion = 1;
413 gdiplusStartupInput.DebugEventCallback = NULL;
414 gdiplusStartupInput.SuppressBackgroundThread = 0;
415 gdiplusStartupInput.SuppressExternalCodecs = 0;
417 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
419 test_getregiondata();
421 GdiplusShutdown(gdiplusToken);