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
);
70 status
= GdipGetRegionDataSize(region
, &needed
);
71 ok(status
== Ok
, "status %08x\n", status
);
75 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
76 ok(status
== Ok
, "status %08x\n", status
);
81 expect_dword(buf
, 12);
82 trace("buf[1] = %08x\n", buf
[1]);
83 expect_magic((DWORD
*)(buf
+ 2));
84 expect_dword(buf
+ 3, 0);
85 expect_dword(buf
+ 4, RGNDATA_INFINITE_RECT
);
87 status
= GdipSetEmpty(region
);
89 ok(status
== Ok
, "status %08x\n", status
);
92 status
= GdipGetRegionDataSize(region
, &needed
);
94 ok(status
== Ok
, "status %08x\n", status
);
96 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
98 ok(status
== Ok
, "status %08x\n", status
);
102 expect_dword(buf
, 12);
103 trace("buf[1] = %08x\n", buf
[1]);
104 expect_magic((DWORD
*)(buf
+ 2));
105 expect_dword(buf
+ 3, 0);
106 expect_dword(buf
+ 4, RGNDATA_EMPTY_RECT
);
109 status
= GdipSetInfinite(region
);
110 ok(status
== Ok
, "status %08x\n", status
);
111 status
= GdipGetRegionDataSize(region
, &needed
);
112 ok(status
== Ok
, "status %08x\n", status
);
114 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
116 ok(status
== Ok
, "status %08x\n", status
);
120 expect_dword(buf
, 12);
121 trace("buf[1] = %08x\n", buf
[1]);
122 expect_magic((DWORD
*)(buf
+ 2));
123 expect_dword(buf
+ 3, 0);
124 expect_dword(buf
+ 4, RGNDATA_INFINITE_RECT
);
127 status
= GdipDeleteRegion(region
);
128 ok(status
== Ok
, "status %08x\n", status
);
136 status
= GdipCreateRegionRectI(&rect
, ®ion
);
137 ok(status
== Ok
, "status %08x\n", status
);
138 status
= GdipGetRegionDataSize(region
, &needed
);
139 ok(status
== Ok
, "status %08x\n", status
);
141 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
142 ok(status
== Ok
, "status %08x\n", status
);
144 expect_dword(buf
, 28);
145 trace("buf[1] = %08x\n", buf
[1]);
146 expect_magic((DWORD
*)(buf
+ 2));
147 expect_dword(buf
+ 3, 0);
148 expect_dword(buf
+ 4, RGNDATA_RECT
);
149 expect_float(buf
+ 5, 10.0);
150 expect_float(buf
+ 6, 20.0);
151 expect_float(buf
+ 7, 100.0);
152 expect_float(buf
+ 8, 200.0);
158 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeIntersect
);
159 ok(status
== Ok
, "status %08x\n", status
);
164 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeXor
);
165 ok(status
== Ok
, "status %08x\n", status
);
171 status
= GdipCreateRegionRectI(&rect
, ®ion2
);
172 ok(status
== Ok
, "status %08x\n", status
);
177 status
= GdipCombineRegionRectI(region2
, &rect
, CombineModeUnion
);
178 ok(status
== Ok
, "status %08x\n", status
);
180 status
= GdipCombineRegionRegion(region
, region2
, CombineModeComplement
);
181 ok(status
== Ok
, "status %08x\n", status
);
187 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeExclude
);
188 ok(status
== Ok
, "status %08x\n", status
);
190 status
= GdipGetRegionDataSize(region
, &needed
);
191 ok(status
== Ok
, "status %08x\n", status
);
193 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
194 ok(status
== Ok
, "status %08x\n", status
);
196 expect_dword(buf
, 148);
197 trace("buf[1] = %08x\n", buf
[1]);
198 expect_magic((DWORD
*)(buf
+ 2));
199 expect_dword(buf
+ 3, 10);
200 expect_dword(buf
+ 4, CombineModeExclude
);
201 expect_dword(buf
+ 5, CombineModeComplement
);
202 expect_dword(buf
+ 6, CombineModeXor
);
203 expect_dword(buf
+ 7, CombineModeIntersect
);
204 expect_dword(buf
+ 8, RGNDATA_RECT
);
205 expect_float(buf
+ 9, 10.0);
206 expect_float(buf
+ 10, 20.0);
207 expect_float(buf
+ 11, 100.0);
208 expect_float(buf
+ 12, 200.0);
209 expect_dword(buf
+ 13, RGNDATA_RECT
);
210 expect_float(buf
+ 14, 50.0);
211 expect_float(buf
+ 15, 30.0);
212 expect_float(buf
+ 16, 10.0);
213 expect_float(buf
+ 17, 20.0);
214 expect_dword(buf
+ 18, RGNDATA_RECT
);
215 expect_float(buf
+ 19, 100.0);
216 expect_float(buf
+ 20, 300.0);
217 expect_float(buf
+ 21, 30.0);
218 expect_float(buf
+ 22, 50.0);
219 expect_dword(buf
+ 23, CombineModeUnion
);
220 expect_dword(buf
+ 24, RGNDATA_RECT
);
221 expect_float(buf
+ 25, 200.0);
222 expect_float(buf
+ 26, 100.0);
223 expect_float(buf
+ 27, 133.0);
224 expect_float(buf
+ 28, 266.0);
225 expect_dword(buf
+ 29, RGNDATA_RECT
);
226 expect_float(buf
+ 30, 20.0);
227 expect_float(buf
+ 31, 10.0);
228 expect_float(buf
+ 32, 40.0);
229 expect_float(buf
+ 33, 66.0);
230 expect_dword(buf
+ 34, RGNDATA_RECT
);
231 expect_float(buf
+ 35, 400.0);
232 expect_float(buf
+ 36, 500.0);
233 expect_float(buf
+ 37, 22.0);
234 expect_float(buf
+ 38, 55.0);
236 status
= GdipDeleteRegion(region2
);
237 ok(status
== Ok
, "status %08x\n", status
);
238 status
= GdipDeleteRegion(region
);
239 ok(status
== Ok
, "status %08x\n", status
);
244 status
= GdipCreatePath(FillModeAlternate
, &path
);
245 ok(status
== Ok
, "status %08x\n", status
);
248 GdipAddPathRectangle(path
, 12.5, 13.0, 14.0, 15.0);
250 status
= GdipCreateRegionPath(path
, ®ion
);
251 ok(status
== Ok
, "status %08x\n", status
);
252 status
= GdipGetRegionDataSize(region
, &needed
);
253 ok(status
== Ok
, "status %08x\n", status
);
255 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
256 ok(status
== Ok
, "status %08x\n", status
);
258 expect_dword(buf
, 64);
259 trace("buf[1] = %08x\n", buf
[1]);
260 expect_magic((DWORD
*)(buf
+ 2));
261 expect_dword(buf
+ 3, 0);
262 expect_dword(buf
+ 4, RGNDATA_PATH
);
263 expect_dword(buf
+ 5, 0x00000030);
264 expect_magic((DWORD
*)(buf
+ 6));
265 expect_dword(buf
+ 7, 0x00000004);
266 expect_dword(buf
+ 8, 0x00000000);
267 expect_float(buf
+ 9, 12.5);
268 expect_float(buf
+ 10, 13.0);
269 expect_float(buf
+ 11, 26.5);
270 expect_float(buf
+ 12, 13.0);
271 expect_float(buf
+ 13, 26.5);
272 expect_float(buf
+ 14, 28.0);
273 expect_float(buf
+ 15, 12.5);
274 expect_float(buf
+ 16, 28.0);
275 expect_dword(buf
+ 17, 0x81010100);
282 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeIntersect
);
283 ok(status
== Ok
, "status %08x\n", status
);
284 status
= GdipGetRegionDataSize(region
, &needed
);
285 ok(status
== Ok
, "status %08x\n", status
);
287 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
288 ok(status
== Ok
, "status %08x\n", status
);
290 expect_dword(buf
, 88);
291 trace("buf[1] = %08x\n", buf
[1]);
292 expect_magic((DWORD
*)(buf
+ 2));
293 expect_dword(buf
+ 3, 2);
294 expect_dword(buf
+ 4, CombineModeIntersect
);
295 expect_dword(buf
+ 5, RGNDATA_PATH
);
296 expect_dword(buf
+ 6, 0x00000030);
297 expect_magic((DWORD
*)(buf
+ 7));
298 expect_dword(buf
+ 8, 0x00000004);
299 expect_dword(buf
+ 9, 0x00000000);
300 expect_float(buf
+ 10, 12.5);
301 expect_float(buf
+ 11, 13.0);
302 expect_float(buf
+ 12, 26.5);
303 expect_float(buf
+ 13, 13.0);
304 expect_float(buf
+ 14, 26.5);
305 expect_float(buf
+ 15, 28.0);
306 expect_float(buf
+ 16, 12.5);
307 expect_float(buf
+ 17, 28.0);
308 expect_dword(buf
+ 18, 0x81010100);
309 expect_dword(buf
+ 19, RGNDATA_RECT
);
310 expect_float(buf
+ 20, 50.0);
311 expect_float(buf
+ 21, 30.0);
312 expect_float(buf
+ 22, 10.0);
313 expect_float(buf
+ 23, 20.0);
315 status
= GdipDeleteRegion(region
);
316 ok(status
== Ok
, "status %08x\n", status
);
318 status
= GdipDeletePath(path
);
319 ok(status
== Ok
, "status %08x\n", status
);
321 /* Test an empty path */
322 status
= GdipCreatePath(FillModeAlternate
, &path
);
326 status
= GdipCreateRegionPath(path
, ®ion
);
328 status
= GdipGetRegionDataSize(region
, &needed
);
331 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
334 expect_dword(buf
, 28);
335 trace("buf[1] = %08x\n", buf
[1]);
336 expect_magic((DWORD
*)(buf
+ 2));
337 expect_dword(buf
+ 3, 0);
338 expect_dword(buf
+ 4, RGNDATA_PATH
);
340 /* Second signature for pathdata */
341 expect_dword(buf
+ 5, 12);
342 expect_magic((DWORD
*)(buf
+ 6));
343 expect_dword(buf
+ 7, 0);
344 expect_dword(buf
+ 8, 0x00004000);
346 status
= GdipDeleteRegion(region
);
350 /* Test a simple triangle of INTs */
351 status
= GdipAddPathLine(path
, 5, 6, 7, 8);
353 status
= GdipAddPathLine(path
, 8, 1, 5, 6);
355 status
= GdipClosePathFigure(path
);
359 status
= GdipCreateRegionPath(path
, ®ion
);
361 status
= GdipGetRegionDataSize(region
, &needed
);
364 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
367 expect_dword(buf
, 48);
368 trace("buf[1] = %08x\n", buf
[1]);
369 expect_magic((DWORD
*)(buf
+ 2));
370 expect_dword(buf
+ 3 , 0);
371 expect_dword(buf
+ 4 , RGNDATA_PATH
);
373 expect_dword(buf
+ 5, 32);
374 expect_magic((DWORD
*)(buf
+ 6));
375 expect_dword(buf
+ 7, 4);
376 expect_dword(buf
+ 8, 0x00004000); /* ?? */
378 point
= (RegionDataPoint
*)buf
+ 9;
379 expect(5, point
[0].X
);
380 expect(6, point
[0].Y
);
381 expect(7, point
[1].X
); /* buf + 10 */
382 expect(8, point
[1].Y
);
383 expect(8, point
[2].X
); /* buf + 11 */
384 expect(1, point
[2].Y
);
385 expect(5, point
[3].X
); /* buf + 12 */
386 expect(6, point
[3].Y
);
387 expect_dword(buf
+ 13, 0x81010100); /* 0x01010100 if we don't close the path */
389 status
= GdipDeletePath(path
);
391 status
= GdipDeleteRegion(region
);
395 /* Test a floating-point triangle */
396 status
= GdipCreatePath(FillModeAlternate
, &path
);
398 status
= GdipAddPathLine(path
, 5.6, 6.2, 7.2, 8.9);
400 status
= GdipAddPathLine(path
, 8.1, 1.6, 5.6, 6.2);
404 status
= GdipCreateRegionPath(path
, ®ion
);
406 status
= GdipGetRegionDataSize(region
, &needed
);
409 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
412 expect_dword(buf
, 64);
413 trace("buf[1] = %08x\n", buf
[1]);
414 expect_magic((DWORD
*)(buf
+ 2));
415 expect_dword(buf
+ 3, 0);
416 expect_dword(buf
+ 4, RGNDATA_PATH
);
418 expect_dword(buf
+ 5, 48);
419 expect_magic((DWORD
*)(buf
+ 6));
420 expect_dword(buf
+ 7, 4);
421 expect_dword(buf
+ 8, 0);
422 expect_float(buf
+ 9, 5.6);
423 expect_float(buf
+ 10, 6.2);
424 expect_float(buf
+ 11, 7.2);
425 expect_float(buf
+ 12, 8.9);
426 expect_float(buf
+ 13, 8.1);
427 expect_float(buf
+ 14, 1.6);
428 expect_float(buf
+ 15, 5.6);
429 expect_float(buf
+ 16, 6.2);
432 status
= GdipDeletePath(path
);
434 status
= GdipDeleteRegion(region
);
441 struct GdiplusStartupInput gdiplusStartupInput
;
442 ULONG_PTR gdiplusToken
;
444 gdiplusStartupInput
.GdiplusVersion
= 1;
445 gdiplusStartupInput
.DebugEventCallback
= NULL
;
446 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
447 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
449 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
451 test_getregiondata();
453 GdiplusShutdown(gdiplusToken
);