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 memset(buf
, 0xee, sizeof(buf
));
67 status
= GdipCreateRegion(®ion
);
68 ok(status
== Ok
, "status %08x\n", status
);
72 status
= GdipGetRegionDataSize(region
, &needed
);
73 ok(status
== Ok
, "status %08x\n", status
);
75 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
76 ok(status
== Ok
, "status %08x\n", status
);
78 expect_dword(buf
, 12);
79 trace("buf[1] = %08x\n", buf
[1]);
80 expect_magic((DWORD
*)(buf
+ 2));
81 expect_dword(buf
+ 3, 0);
82 expect_dword(buf
+ 4, RGNDATA_INFINITE_RECT
);
84 status
= GdipSetEmpty(region
);
86 ok(status
== Ok
, "status %08x\n", status
);
89 status
= GdipGetRegionDataSize(region
, &needed
);
90 ok(status
== Ok
, "status %08x\n", status
);
92 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
93 ok(status
== Ok
, "status %08x\n", status
);
95 expect_dword(buf
, 12);
96 trace("buf[1] = %08x\n", buf
[1]);
97 expect_magic((DWORD
*)(buf
+ 2));
98 expect_dword(buf
+ 3, 0);
99 expect_dword(buf
+ 4, RGNDATA_EMPTY_RECT
);
101 status
= GdipSetInfinite(region
);
102 ok(status
== Ok
, "status %08x\n", status
);
103 status
= GdipGetRegionDataSize(region
, &needed
);
104 ok(status
== Ok
, "status %08x\n", status
);
106 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
107 ok(status
== Ok
, "status %08x\n", status
);
109 expect_dword(buf
, 12);
110 trace("buf[1] = %08x\n", buf
[1]);
111 expect_magic((DWORD
*)(buf
+ 2));
112 expect_dword(buf
+ 3, 0);
113 expect_dword(buf
+ 4, RGNDATA_INFINITE_RECT
);
116 status
= GdipDeleteRegion(region
);
117 ok(status
== Ok
, "status %08x\n", status
);
125 status
= GdipCreateRegionRectI(&rect
, ®ion
);
126 ok(status
== Ok
, "status %08x\n", status
);
127 status
= GdipGetRegionDataSize(region
, &needed
);
128 ok(status
== Ok
, "status %08x\n", status
);
130 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
131 ok(status
== Ok
, "status %08x\n", status
);
133 expect_dword(buf
, 28);
134 trace("buf[1] = %08x\n", buf
[1]);
135 expect_magic((DWORD
*)(buf
+ 2));
136 expect_dword(buf
+ 3, 0);
137 expect_dword(buf
+ 4, RGNDATA_RECT
);
138 expect_float(buf
+ 5, 10.0);
139 expect_float(buf
+ 6, 20.0);
140 expect_float(buf
+ 7, 100.0);
141 expect_float(buf
+ 8, 200.0);
147 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeIntersect
);
148 ok(status
== Ok
, "status %08x\n", status
);
153 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeXor
);
154 ok(status
== Ok
, "status %08x\n", status
);
160 status
= GdipCreateRegionRectI(&rect
, ®ion2
);
161 ok(status
== Ok
, "status %08x\n", status
);
166 status
= GdipCombineRegionRectI(region2
, &rect
, CombineModeUnion
);
167 ok(status
== Ok
, "status %08x\n", status
);
169 status
= GdipCombineRegionRegion(region
, region2
, CombineModeComplement
);
170 ok(status
== Ok
, "status %08x\n", status
);
176 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeExclude
);
177 ok(status
== Ok
, "status %08x\n", status
);
179 status
= GdipGetRegionDataSize(region
, &needed
);
180 ok(status
== Ok
, "status %08x\n", status
);
182 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
183 ok(status
== Ok
, "status %08x\n", status
);
185 expect_dword(buf
, 148);
186 trace("buf[1] = %08x\n", buf
[1]);
187 expect_magic((DWORD
*)(buf
+ 2));
188 expect_dword(buf
+ 3, 10);
189 expect_dword(buf
+ 4, CombineModeExclude
);
190 expect_dword(buf
+ 5, CombineModeComplement
);
191 expect_dword(buf
+ 6, CombineModeXor
);
192 expect_dword(buf
+ 7, CombineModeIntersect
);
193 expect_dword(buf
+ 8, RGNDATA_RECT
);
194 expect_float(buf
+ 9, 10.0);
195 expect_float(buf
+ 10, 20.0);
196 expect_float(buf
+ 11, 100.0);
197 expect_float(buf
+ 12, 200.0);
198 expect_dword(buf
+ 13, RGNDATA_RECT
);
199 expect_float(buf
+ 14, 50.0);
200 expect_float(buf
+ 15, 30.0);
201 expect_float(buf
+ 16, 10.0);
202 expect_float(buf
+ 17, 20.0);
203 expect_dword(buf
+ 18, RGNDATA_RECT
);
204 expect_float(buf
+ 19, 100.0);
205 expect_float(buf
+ 20, 300.0);
206 expect_float(buf
+ 21, 30.0);
207 expect_float(buf
+ 22, 50.0);
208 expect_dword(buf
+ 23, CombineModeUnion
);
209 expect_dword(buf
+ 24, RGNDATA_RECT
);
210 expect_float(buf
+ 25, 200.0);
211 expect_float(buf
+ 26, 100.0);
212 expect_float(buf
+ 27, 133.0);
213 expect_float(buf
+ 28, 266.0);
214 expect_dword(buf
+ 29, RGNDATA_RECT
);
215 expect_float(buf
+ 30, 20.0);
216 expect_float(buf
+ 31, 10.0);
217 expect_float(buf
+ 32, 40.0);
218 expect_float(buf
+ 33, 66.0);
219 expect_dword(buf
+ 34, RGNDATA_RECT
);
220 expect_float(buf
+ 35, 400.0);
221 expect_float(buf
+ 36, 500.0);
222 expect_float(buf
+ 37, 22.0);
223 expect_float(buf
+ 38, 55.0);
225 status
= GdipDeleteRegion(region2
);
226 ok(status
== Ok
, "status %08x\n", status
);
227 status
= GdipDeleteRegion(region
);
228 ok(status
== Ok
, "status %08x\n", status
);
233 status
= GdipCreatePath(FillModeAlternate
, &path
);
234 ok(status
== Ok
, "status %08x\n", status
);
237 GdipAddPathRectangle(path
, 12.5, 13.0, 14.0, 15.0);
239 status
= GdipCreateRegionPath(path
, ®ion
);
240 ok(status
== Ok
, "status %08x\n", status
);
241 status
= GdipGetRegionDataSize(region
, &needed
);
242 ok(status
== Ok
, "status %08x\n", status
);
244 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
245 ok(status
== Ok
, "status %08x\n", status
);
247 expect_dword(buf
, 64);
248 trace("buf[1] = %08x\n", buf
[1]);
249 expect_magic((DWORD
*)(buf
+ 2));
250 expect_dword(buf
+ 3, 0);
251 expect_dword(buf
+ 4, RGNDATA_PATH
);
252 expect_dword(buf
+ 5, 0x00000030);
253 expect_magic((DWORD
*)(buf
+ 6));
254 expect_dword(buf
+ 7, 0x00000004);
255 expect_dword(buf
+ 8, 0x00000000);
256 expect_float(buf
+ 9, 12.5);
257 expect_float(buf
+ 10, 13.0);
258 expect_float(buf
+ 11, 26.5);
259 expect_float(buf
+ 12, 13.0);
260 expect_float(buf
+ 13, 26.5);
261 expect_float(buf
+ 14, 28.0);
262 expect_float(buf
+ 15, 12.5);
263 expect_float(buf
+ 16, 28.0);
264 expect_dword(buf
+ 17, 0x81010100);
271 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeIntersect
);
272 ok(status
== Ok
, "status %08x\n", status
);
273 status
= GdipGetRegionDataSize(region
, &needed
);
274 ok(status
== Ok
, "status %08x\n", status
);
276 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
277 ok(status
== Ok
, "status %08x\n", status
);
279 expect_dword(buf
, 88);
280 trace("buf[1] = %08x\n", buf
[1]);
281 expect_magic((DWORD
*)(buf
+ 2));
282 expect_dword(buf
+ 3, 2);
283 expect_dword(buf
+ 4, CombineModeIntersect
);
284 expect_dword(buf
+ 5, RGNDATA_PATH
);
285 expect_dword(buf
+ 6, 0x00000030);
286 expect_magic((DWORD
*)(buf
+ 7));
287 expect_dword(buf
+ 8, 0x00000004);
288 expect_dword(buf
+ 9, 0x00000000);
289 expect_float(buf
+ 10, 12.5);
290 expect_float(buf
+ 11, 13.0);
291 expect_float(buf
+ 12, 26.5);
292 expect_float(buf
+ 13, 13.0);
293 expect_float(buf
+ 14, 26.5);
294 expect_float(buf
+ 15, 28.0);
295 expect_float(buf
+ 16, 12.5);
296 expect_float(buf
+ 17, 28.0);
297 expect_dword(buf
+ 18, 0x81010100);
298 expect_dword(buf
+ 19, RGNDATA_RECT
);
299 expect_float(buf
+ 20, 50.0);
300 expect_float(buf
+ 21, 30.0);
301 expect_float(buf
+ 22, 10.0);
302 expect_float(buf
+ 23, 20.0);
304 status
= GdipDeleteRegion(region
);
305 ok(status
== Ok
, "status %08x\n", status
);
307 status
= GdipDeletePath(path
);
308 ok(status
== Ok
, "status %08x\n", status
);
310 /* Test an empty path */
311 status
= GdipCreatePath(FillModeAlternate
, &path
);
315 status
= GdipCreateRegionPath(path
, ®ion
);
317 status
= GdipGetRegionDataSize(region
, &needed
);
320 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
323 expect_dword(buf
, 28);
324 trace("buf[1] = %08x\n", buf
[1]);
325 expect_magic((DWORD
*)(buf
+ 2));
326 expect_dword(buf
+ 3, 0);
327 expect_dword(buf
+ 4, RGNDATA_PATH
);
329 /* Second signature for pathdata */
330 expect_dword(buf
+ 5, 12);
331 expect_magic((DWORD
*)(buf
+ 6));
332 expect_dword(buf
+ 7, 0);
333 expect_dword(buf
+ 8, 0x00004000);
335 status
= GdipDeleteRegion(region
);
339 /* Test a simple triangle of INTs */
340 status
= GdipAddPathLine(path
, 5, 6, 7, 8);
342 status
= GdipAddPathLine(path
, 8, 1, 5, 6);
344 status
= GdipClosePathFigure(path
);
348 status
= GdipCreateRegionPath(path
, ®ion
);
350 status
= GdipGetRegionDataSize(region
, &needed
);
353 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
356 expect_dword(buf
, 48);
357 trace("buf[1] = %08x\n", buf
[1]);
358 expect_magic((DWORD
*)(buf
+ 2));
359 expect_dword(buf
+ 3 , 0);
360 expect_dword(buf
+ 4 , RGNDATA_PATH
);
362 expect_dword(buf
+ 5, 32);
363 expect_magic((DWORD
*)(buf
+ 6));
364 expect_dword(buf
+ 7, 4);
365 expect_dword(buf
+ 8, 0x00004000); /* ?? */
367 point
= (RegionDataPoint
*)buf
+ 9;
368 expect(5, point
[0].X
);
369 expect(6, point
[0].Y
);
370 expect(7, point
[1].X
); /* buf + 10 */
371 expect(8, point
[1].Y
);
372 expect(8, point
[2].X
); /* buf + 11 */
373 expect(1, point
[2].Y
);
374 expect(5, point
[3].X
); /* buf + 12 */
375 expect(6, point
[3].Y
);
376 expect_dword(buf
+ 13, 0x81010100); /* 0x01010100 if we don't close the path */
378 status
= GdipDeletePath(path
);
380 status
= GdipDeleteRegion(region
);
384 /* Test a floating-point triangle */
385 status
= GdipCreatePath(FillModeAlternate
, &path
);
387 status
= GdipAddPathLine(path
, 5.6, 6.2, 7.2, 8.9);
389 status
= GdipAddPathLine(path
, 8.1, 1.6, 5.6, 6.2);
393 status
= GdipCreateRegionPath(path
, ®ion
);
395 status
= GdipGetRegionDataSize(region
, &needed
);
398 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
401 expect_dword(buf
, 64);
402 trace("buf[1] = %08x\n", buf
[1]);
403 expect_magic((DWORD
*)(buf
+ 2));
404 expect_dword(buf
+ 3, 0);
405 expect_dword(buf
+ 4, RGNDATA_PATH
);
407 expect_dword(buf
+ 5, 48);
408 expect_magic((DWORD
*)(buf
+ 6));
409 expect_dword(buf
+ 7, 4);
410 expect_dword(buf
+ 8, 0);
411 expect_float(buf
+ 9, 5.6);
412 expect_float(buf
+ 10, 6.2);
413 expect_float(buf
+ 11, 7.2);
414 expect_float(buf
+ 12, 8.9);
415 expect_float(buf
+ 13, 8.1);
416 expect_float(buf
+ 14, 1.6);
417 expect_float(buf
+ 15, 5.6);
418 expect_float(buf
+ 16, 6.2);
421 status
= GdipDeletePath(path
);
423 status
= GdipDeleteRegion(region
);
430 struct GdiplusStartupInput gdiplusStartupInput
;
431 ULONG_PTR gdiplusToken
;
433 gdiplusStartupInput
.GdiplusVersion
= 1;
434 gdiplusStartupInput
.DebugEventCallback
= NULL
;
435 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
436 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
438 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
440 test_getregiondata();
442 GdiplusShutdown(gdiplusToken
);