bb23fa09654e6ebb7f829dbcbad316e7bdd0a55a
[reactos.git] / rostests / winetests / gdiplus / region.c
1 /*
2 * Unit test suite for gdiplus regions
3 *
4 * Copyright (C) 2008 Huw Davies
5 * Copyright (C) 2013 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 //#include "windows.h"
27 #include <wine/test.h>
28 #include <wingdi.h>
29 #include <objbase.h>
30 #include <gdiplus.h>
31 #include <math.h>
32
33 #define RGNDATA_RECT 0x10000000
34 #define RGNDATA_PATH 0x10000001
35 #define RGNDATA_EMPTY_RECT 0x10000002
36 #define RGNDATA_INFINITE_RECT 0x10000003
37
38 #define RGNDATA_MAGIC 0xdbc01001
39 #define RGNDATA_MAGIC2 0xdbc01002
40
41 #define expect(expected, got) ok((got) == (expected), "Expected %.8x, got %.8x\n", (expected), (got))
42 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) < (precision), "Expected %f, got %f\n", (expected), (got))
43 #define expectf(expected, got) expectf_((expected), (got), 0.001)
44
45 #define expect_magic(value) ok(*(value) == RGNDATA_MAGIC || *(value) == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *(value))
46 #define expect_dword(value, expected) expect((expected), *(value))
47 #define expect_float(value, expected) expectf((expected), *(FLOAT *)(value))
48
49 /* We get shorts back, not INTs like a GpPoint */
50 typedef struct RegionDataPoint
51 {
52 short X, Y;
53 } RegionDataPoint;
54
55 static void verify_region(HRGN hrgn, const RECT *rc)
56 {
57 union
58 {
59 RGNDATA data;
60 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
61 } rgn;
62 const RECT *rect;
63 DWORD ret;
64
65 ret = GetRegionData(hrgn, 0, NULL);
66 if (IsRectEmpty(rc))
67 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
68 else
69 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
70
71 if (!ret) return;
72
73 ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
74 if (IsRectEmpty(rc))
75 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
76 else
77 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
78
79 trace("size %u, type %u, count %u, rgn size %u, bound %s\n",
80 rgn.data.rdh.dwSize, rgn.data.rdh.iType,
81 rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
82 wine_dbgstr_rect(&rgn.data.rdh.rcBound));
83 if (rgn.data.rdh.nCount != 0)
84 {
85 rect = (const RECT *)rgn.data.Buffer;
86 trace("rect %s\n", wine_dbgstr_rect(rect));
87 ok(EqualRect(rect, rc), "expected %s, got %s\n",
88 wine_dbgstr_rect(rc), wine_dbgstr_rect(rect));
89 }
90
91 ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", rgn.data.rdh.dwSize);
92 ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
93 if (IsRectEmpty(rc))
94 {
95 ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
96 ok(rgn.data.rdh.nRgnSize == 0, "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
97 }
98 else
99 {
100 ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
101 ok(rgn.data.rdh.nRgnSize == sizeof(RECT), "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
102 }
103 ok(EqualRect(&rgn.data.rdh.rcBound, rc), "expected %s, got %s\n",
104 wine_dbgstr_rect(rc), wine_dbgstr_rect(&rgn.data.rdh.rcBound));
105 }
106
107 static void test_region_data(DWORD *data, UINT size, INT line)
108 {
109 GpStatus status;
110 GpRegion *region;
111 DWORD buf[256];
112 UINT needed, i;
113
114 status = GdipCreateRegionRgnData((BYTE *)data, size, &region);
115 /* Windows always fails to create an empty path in a region */
116 if (data[4] == RGNDATA_PATH)
117 {
118 struct path_header
119 {
120 DWORD size;
121 DWORD magic;
122 DWORD count;
123 DWORD flags;
124 } *path_header = (struct path_header *)(data + 5);
125 if (!path_header->count)
126 {
127 ok_(__FILE__, line)(status == GenericError, "expected GenericError, got %d\n", status);
128 return;
129 }
130 }
131
132 ok_(__FILE__, line)(status == Ok, "GdipCreateRegionRgnData error %d\n", status);
133 if (status != Ok) return;
134
135 needed = 0;
136 status = GdipGetRegionDataSize(region, &needed);
137 ok_(__FILE__, line)(status == Ok, "status %d\n", status);
138 ok_(__FILE__, line)(needed == size, "data size mismatch: %u != %u\n", needed, size);
139
140 memset(buf, 0xee, sizeof(buf));
141 needed = 0;
142 status = GdipGetRegionData(region, (BYTE *)buf, sizeof(buf), &needed);
143 ok_(__FILE__, line)(status == Ok, "status %08x\n", status);
144 ok_(__FILE__, line)(needed == size, "data size mismatch: %u != %u\n", needed, size);
145
146 size /= sizeof(DWORD);
147 for (i = 0; i < size - 1; i++)
148 {
149 if (i == 1) continue; /* data[1] never matches */
150 ok_(__FILE__, line)(data[i] == buf[i], "off %u: %#x != %#x\n", i, data[i], buf[i]);
151 }
152 /* some Windows versions fail to properly clear the aligned DWORD */
153 ok_(__FILE__, line)(data[size - 1] == buf[size - 1] || broken(data[size - 1] != buf[size - 1]),
154 "off %u: %#x != %#x\n", size - 1, data[size - 1], buf[size - 1]);
155 }
156
157 static void test_getregiondata(void)
158 {
159 GpStatus status;
160 GpRegion *region, *region2;
161 RegionDataPoint *point;
162 UINT needed;
163 DWORD buf[256];
164 GpRect rect;
165 GpPath *path;
166 GpMatrix *matrix;
167
168 status = GdipCreateRegion(&region);
169 ok(status == Ok, "status %08x\n", status);
170
171 needed = 0;
172 status = GdipGetRegionDataSize(region, &needed);
173 ok(status == Ok, "status %08x\n", status);
174 expect(20, needed);
175
176 needed = 0;
177 status = GdipGetRegionData(region, (BYTE*)buf, 0, &needed);
178 ok(status == InvalidParameter, "status %08x\n", status);
179
180 memset(buf, 0xee, sizeof(buf));
181 needed = 0;
182 status = GdipGetRegionData(region, (BYTE*)buf, 4, &needed);
183 ok(status == InsufficientBuffer, "status %08x\n", status);
184 expect(4, needed);
185 expect_dword(buf, 0xeeeeeeee);
186
187 memset(buf, 0xee, sizeof(buf));
188 needed = 0;
189 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
190 ok(status == Ok, "status %08x\n", status);
191 expect(20, needed);
192 expect_dword(buf, 12);
193 trace("buf[1] = %08x\n", buf[1]);
194 expect_magic(buf + 2);
195 expect_dword(buf + 3, 0);
196 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
197 expect_dword(buf + 6, 0xeeeeeeee);
198 test_region_data(buf, needed, __LINE__);
199
200 status = GdipSetEmpty(region);
201 ok(status == Ok, "status %08x\n", status);
202 status = GdipGetRegionDataSize(region, &needed);
203 ok(status == Ok, "status %08x\n", status);
204 expect(20, needed);
205 memset(buf, 0xee, sizeof(buf));
206 needed = 0;
207 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
208 ok(status == Ok, "status %08x\n", status);
209 expect(20, needed);
210 expect_dword(buf, 12);
211 trace("buf[1] = %08x\n", buf[1]);
212 expect_magic(buf + 2);
213 expect_dword(buf + 3, 0);
214 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
215 expect_dword(buf + 6, 0xeeeeeeee);
216 test_region_data(buf, needed, __LINE__);
217
218 status = GdipSetInfinite(region);
219 ok(status == Ok, "status %08x\n", status);
220 status = GdipGetRegionDataSize(region, &needed);
221 ok(status == Ok, "status %08x\n", status);
222 expect(20, needed);
223 memset(buf, 0xee, sizeof(buf));
224 needed = 0;
225 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
226 ok(status == Ok, "status %08x\n", status);
227 expect(20, needed);
228 expect_dword(buf, 12);
229 trace("buf[1] = %08x\n", buf[1]);
230 expect_magic(buf + 2);
231 expect_dword(buf + 3, 0);
232 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
233 expect_dword(buf + 6, 0xeeeeeeee);
234 test_region_data(buf, needed, __LINE__);
235
236 status = GdipDeleteRegion(region);
237 ok(status == Ok, "status %08x\n", status);
238
239 rect.X = 10;
240 rect.Y = 20;
241 rect.Width = 100;
242 rect.Height = 200;
243 status = GdipCreateRegionRectI(&rect, &region);
244 ok(status == Ok, "status %08x\n", status);
245 status = GdipGetRegionDataSize(region, &needed);
246 ok(status == Ok, "status %08x\n", status);
247 expect(36, needed);
248 memset(buf, 0xee, sizeof(buf));
249 needed = 0;
250 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
251 ok(status == Ok, "status %08x\n", status);
252 expect(36, needed);
253 expect_dword(buf, 28);
254 trace("buf[1] = %08x\n", buf[1]);
255 expect_magic(buf + 2);
256 expect_dword(buf + 3, 0);
257 expect_dword(buf + 4, RGNDATA_RECT);
258 expect_float(buf + 5, 10.0);
259 expect_float(buf + 6, 20.0);
260 expect_float(buf + 7, 100.0);
261 expect_float(buf + 8, 200.0);
262 expect_dword(buf + 10, 0xeeeeeeee);
263 test_region_data(buf, needed, __LINE__);
264
265 rect.X = 50;
266 rect.Y = 30;
267 rect.Width = 10;
268 rect.Height = 20;
269 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
270 ok(status == Ok, "status %08x\n", status);
271 rect.X = 100;
272 rect.Y = 300;
273 rect.Width = 30;
274 rect.Height = 50;
275 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
276 ok(status == Ok, "status %08x\n", status);
277
278 rect.X = 200;
279 rect.Y = 100;
280 rect.Width = 133;
281 rect.Height = 266;
282 status = GdipCreateRegionRectI(&rect, &region2);
283 ok(status == Ok, "status %08x\n", status);
284 rect.X = 20;
285 rect.Y = 10;
286 rect.Width = 40;
287 rect.Height = 66;
288 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
289 ok(status == Ok, "status %08x\n", status);
290
291 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
292 ok(status == Ok, "status %08x\n", status);
293
294 rect.X = 400;
295 rect.Y = 500;
296 rect.Width = 22;
297 rect.Height = 55;
298 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
299 ok(status == Ok, "status %08x\n", status);
300
301 status = GdipGetRegionDataSize(region, &needed);
302 ok(status == Ok, "status %08x\n", status);
303 expect(156, needed);
304 memset(buf, 0xee, sizeof(buf));
305 needed = 0;
306 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
307 ok(status == Ok, "status %08x\n", status);
308 expect(156, needed);
309 expect_dword(buf, 148);
310 trace("buf[1] = %08x\n", buf[1]);
311 expect_magic(buf + 2);
312 expect_dword(buf + 3, 10);
313 expect_dword(buf + 4, CombineModeExclude);
314 expect_dword(buf + 5, CombineModeComplement);
315 expect_dword(buf + 6, CombineModeXor);
316 expect_dword(buf + 7, CombineModeIntersect);
317 expect_dword(buf + 8, RGNDATA_RECT);
318 expect_float(buf + 9, 10.0);
319 expect_float(buf + 10, 20.0);
320 expect_float(buf + 11, 100.0);
321 expect_float(buf + 12, 200.0);
322 expect_dword(buf + 13, RGNDATA_RECT);
323 expect_float(buf + 14, 50.0);
324 expect_float(buf + 15, 30.0);
325 expect_float(buf + 16, 10.0);
326 expect_float(buf + 17, 20.0);
327 expect_dword(buf + 18, RGNDATA_RECT);
328 expect_float(buf + 19, 100.0);
329 expect_float(buf + 20, 300.0);
330 expect_float(buf + 21, 30.0);
331 expect_float(buf + 22, 50.0);
332 expect_dword(buf + 23, CombineModeUnion);
333 expect_dword(buf + 24, RGNDATA_RECT);
334 expect_float(buf + 25, 200.0);
335 expect_float(buf + 26, 100.0);
336 expect_float(buf + 27, 133.0);
337 expect_float(buf + 28, 266.0);
338 expect_dword(buf + 29, RGNDATA_RECT);
339 expect_float(buf + 30, 20.0);
340 expect_float(buf + 31, 10.0);
341 expect_float(buf + 32, 40.0);
342 expect_float(buf + 33, 66.0);
343 expect_dword(buf + 34, RGNDATA_RECT);
344 expect_float(buf + 35, 400.0);
345 expect_float(buf + 36, 500.0);
346 expect_float(buf + 37, 22.0);
347 expect_float(buf + 38, 55.0);
348 expect_dword(buf + 39, 0xeeeeeeee);
349 test_region_data(buf, needed, __LINE__);
350
351 status = GdipDeleteRegion(region2);
352 ok(status == Ok, "status %08x\n", status);
353 status = GdipDeleteRegion(region);
354 ok(status == Ok, "status %08x\n", status);
355
356 /* Try some paths */
357
358 status = GdipCreatePath(FillModeAlternate, &path);
359 ok(status == Ok, "status %08x\n", status);
360 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
361
362 status = GdipCreateRegionPath(path, &region);
363 ok(status == Ok, "status %08x\n", status);
364 status = GdipGetRegionDataSize(region, &needed);
365 ok(status == Ok, "status %08x\n", status);
366 expect(72, needed);
367 memset(buf, 0xee, sizeof(buf));
368 needed = 0;
369 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
370 ok(status == Ok, "status %08x\n", status);
371 expect(72, needed);
372 expect_dword(buf, 64);
373 trace("buf[1] = %08x\n", buf[1]);
374 expect_magic(buf + 2);
375 expect_dword(buf + 3, 0);
376 expect_dword(buf + 4, RGNDATA_PATH);
377 expect_dword(buf + 5, 0x00000030);
378 expect_magic(buf + 6);
379 expect_dword(buf + 7, 0x00000004);
380 expect_dword(buf + 8, 0x00000000);
381 expect_float(buf + 9, 12.5);
382 expect_float(buf + 10, 13.0);
383 expect_float(buf + 11, 26.5);
384 expect_float(buf + 12, 13.0);
385 expect_float(buf + 13, 26.5);
386 expect_float(buf + 14, 28.0);
387 expect_float(buf + 15, 12.5);
388 expect_float(buf + 16, 28.0);
389 expect_dword(buf + 17, 0x81010100);
390 expect_dword(buf + 18, 0xeeeeeeee);
391 test_region_data(buf, needed, __LINE__);
392
393 rect.X = 50;
394 rect.Y = 30;
395 rect.Width = 10;
396 rect.Height = 20;
397 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
398 ok(status == Ok, "status %08x\n", status);
399 status = GdipGetRegionDataSize(region, &needed);
400 ok(status == Ok, "status %08x\n", status);
401 expect(96, needed);
402 memset(buf, 0xee, sizeof(buf));
403 needed = 0;
404 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
405 ok(status == Ok, "status %08x\n", status);
406 expect(96, needed);
407 expect_dword(buf, 88);
408 trace("buf[1] = %08x\n", buf[1]);
409 expect_magic(buf + 2);
410 expect_dword(buf + 3, 2);
411 expect_dword(buf + 4, CombineModeIntersect);
412 expect_dword(buf + 5, RGNDATA_PATH);
413 expect_dword(buf + 6, 0x00000030);
414 expect_magic(buf + 7);
415 expect_dword(buf + 8, 0x00000004);
416 expect_dword(buf + 9, 0x00000000);
417 expect_float(buf + 10, 12.5);
418 expect_float(buf + 11, 13.0);
419 expect_float(buf + 12, 26.5);
420 expect_float(buf + 13, 13.0);
421 expect_float(buf + 14, 26.5);
422 expect_float(buf + 15, 28.0);
423 expect_float(buf + 16, 12.5);
424 expect_float(buf + 17, 28.0);
425 expect_dword(buf + 18, 0x81010100);
426 expect_dword(buf + 19, RGNDATA_RECT);
427 expect_float(buf + 20, 50.0);
428 expect_float(buf + 21, 30.0);
429 expect_float(buf + 22, 10.0);
430 expect_float(buf + 23, 20.0);
431 expect_dword(buf + 24, 0xeeeeeeee);
432 test_region_data(buf, needed, __LINE__);
433
434 status = GdipDeleteRegion(region);
435 ok(status == Ok, "status %08x\n", status);
436 status = GdipDeletePath(path);
437 ok(status == Ok, "status %08x\n", status);
438
439 /* Test an empty path */
440 status = GdipCreatePath(FillModeAlternate, &path);
441 expect(Ok, status);
442 status = GdipCreateRegionPath(path, &region);
443 expect(Ok, status);
444 status = GdipGetRegionDataSize(region, &needed);
445 expect(Ok, status);
446 expect(36, needed);
447 memset(buf, 0xee, sizeof(buf));
448 needed = 0;
449 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
450 expect(Ok, status);
451 expect(36, needed);
452 expect_dword(buf, 28);
453 trace("buf[1] = %08x\n", buf[1]);
454 expect_magic(buf + 2);
455 expect_dword(buf + 3, 0);
456 expect_dword(buf + 4, RGNDATA_PATH);
457 /* Second signature for pathdata */
458 expect_dword(buf + 5, 12);
459 expect_magic(buf + 6);
460 expect_dword(buf + 7, 0);
461 /* flags 0 means that a path is an array of FLOATs */
462 ok(*(buf + 8) == 0x4000 /* before win7 */ || *(buf + 8) == 0,
463 "expected 0x4000 or 0, got %08x\n", *(buf + 8));
464 expect_dword(buf + 10, 0xeeeeeeee);
465 test_region_data(buf, needed, __LINE__);
466
467 /* Transform an empty region */
468 status = GdipCreateMatrix(&matrix);
469 expect(Ok, status);
470 status = GdipTransformRegion(region, matrix);
471 expect(Ok, status);
472 GdipDeleteMatrix(matrix);
473
474 status = GdipDeleteRegion(region);
475 expect(Ok, status);
476
477 /* Test a simple triangle of INTs */
478 status = GdipAddPathLine(path, 5, 6, 7, 8);
479 expect(Ok, status);
480 status = GdipAddPathLine(path, 8, 1, 5, 6);
481 expect(Ok, status);
482 status = GdipClosePathFigure(path);
483 expect(Ok, status);
484 status = GdipCreateRegionPath(path, &region);
485 expect(Ok, status);
486 status = GdipGetRegionDataSize(region, &needed);
487 expect(Ok, status);
488 expect(56, needed);
489 memset(buf, 0xee, sizeof(buf));
490 needed = 0;
491 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
492 expect(Ok, status);
493 expect(56, needed);
494 expect_dword(buf, 48);
495 trace("buf[1] = %08x\n", buf[1]);
496 expect_magic(buf + 2);
497 expect_dword(buf + 3 , 0);
498 expect_dword(buf + 4 , RGNDATA_PATH);
499 expect_dword(buf + 5, 32);
500 expect_magic(buf + 6);
501 expect_dword(buf + 7, 4);
502 /* flags 0x4000 means that a path is an array of shorts instead of FLOATs */
503 expect_dword(buf + 8, 0x4000);
504
505 point = (RegionDataPoint*)(buf + 9);
506 expect(5, point[0].X);
507 expect(6, point[0].Y);
508 expect(7, point[1].X); /* buf + 10 */
509 expect(8, point[1].Y);
510 expect(8, point[2].X); /* buf + 11 */
511 expect(1, point[2].Y);
512 expect(5, point[3].X); /* buf + 12 */
513 expect(6, point[3].Y);
514 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
515 expect_dword(buf + 14, 0xeeeeeeee);
516 test_region_data(buf, needed, __LINE__);
517
518 status = GdipTranslateRegion(region, 0.6, 0.8);
519 expect(Ok, status);
520 memset(buf, 0xee, sizeof(buf));
521 needed = 0;
522 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
523 expect(Ok, status);
524 expect(72, needed);
525 expect_dword(buf, 64);
526 expect_magic(buf + 2);
527 expect_dword(buf + 3 , 0);
528 expect_dword(buf + 4 , RGNDATA_PATH);
529 expect_dword(buf + 5, 48);
530 expect_magic(buf + 6);
531 expect_dword(buf + 7, 4);
532 /* flags 0 means that a path is an array of FLOATs */
533 expect_dword(buf + 8, 0);
534 expect_float(buf + 9, 5.6);
535 expect_float(buf + 10, 6.8);
536 expect_float(buf + 11, 7.6);
537 expect_float(buf + 12, 8.8);
538 expect_float(buf + 13, 8.6);
539 expect_float(buf + 14, 1.8);
540 expect_float(buf + 15, 5.6);
541 expect_float(buf + 16, 6.8);
542 expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */
543 expect_dword(buf + 18, 0xeeeeeeee);
544 test_region_data(buf, needed, __LINE__);
545
546 status = GdipDeletePath(path);
547 expect(Ok, status);
548 status = GdipDeleteRegion(region);
549 expect(Ok, status);
550
551 /* Test a floating-point triangle */
552 status = GdipCreatePath(FillModeAlternate, &path);
553 expect(Ok, status);
554 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
555 expect(Ok, status);
556 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
557 expect(Ok, status);
558 status = GdipCreateRegionPath(path, &region);
559 expect(Ok, status);
560 status = GdipGetRegionDataSize(region, &needed);
561 expect(Ok, status);
562 expect(72, needed);
563 memset(buf, 0xee, sizeof(buf));
564 needed = 0;
565 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
566 expect(Ok, status);
567 expect(72, needed);
568 expect_dword(buf, 64);
569 trace("buf[1] = %08x\n", buf[1]);
570 expect_magic(buf + 2);
571 expect_dword(buf + 3, 0);
572 expect_dword(buf + 4, RGNDATA_PATH);
573 expect_dword(buf + 5, 48);
574 expect_magic(buf + 6);
575 expect_dword(buf + 7, 4);
576 expect_dword(buf + 8, 0);
577 expect_float(buf + 9, 5.6);
578 expect_float(buf + 10, 6.2);
579 expect_float(buf + 11, 7.2);
580 expect_float(buf + 12, 8.9);
581 expect_float(buf + 13, 8.1);
582 expect_float(buf + 14, 1.6);
583 expect_float(buf + 15, 5.6);
584 expect_float(buf + 16, 6.2);
585 expect_dword(buf + 17, 0x01010100);
586 expect_dword(buf + 18, 0xeeeeeeee);
587 test_region_data(buf, needed, __LINE__);
588
589 status = GdipDeletePath(path);
590 expect(Ok, status);
591 status = GdipDeleteRegion(region);
592 expect(Ok, status);
593
594 /* Test for a path with > 4 points, and CombineRegionPath */
595 GdipCreatePath(FillModeAlternate, &path);
596 status = GdipAddPathLine(path, 50, 70.2, 60, 102.8);
597 expect(Ok, status);
598 status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2);
599 expect(Ok, status);
600 status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2);
601 expect(Ok, status);
602 rect.X = 20;
603 rect.Y = 25;
604 rect.Width = 60;
605 rect.Height = 120;
606 status = GdipCreateRegionRectI(&rect, &region);
607 expect(Ok, status);
608 status = GdipCombineRegionPath(region, path, CombineModeUnion);
609 expect(Ok, status);
610
611 status = GdipGetRegionDataSize(region, &needed);
612 expect(Ok, status);
613 expect(116, needed);
614 memset(buf, 0xee, sizeof(buf));
615 needed = 0;
616 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
617 expect(Ok, status);
618 expect(116, needed);
619 expect_dword(buf, 108);
620 trace("buf[1] = %08x\n", buf[1]);
621 expect_magic(buf + 2);
622 expect_dword(buf + 3, 2);
623 expect_dword(buf + 4, CombineModeUnion);
624 expect_dword(buf + 5, RGNDATA_RECT);
625 expect_float(buf + 6, 20.0);
626 expect_float(buf + 7, 25.0);
627 expect_float(buf + 8, 60.0);
628 expect_float(buf + 9, 120.0);
629 expect_dword(buf + 10, RGNDATA_PATH);
630 expect_dword(buf + 11, 68);
631 expect_magic(buf + 12);
632 expect_dword(buf + 13, 6);
633 expect_float(buf + 14, 0.0);
634 expect_float(buf + 15, 50.0);
635 expect_float(buf + 16, 70.2);
636 expect_float(buf + 17, 60.0);
637 expect_float(buf + 18, 102.8);
638 expect_float(buf + 19, 55.4);
639 expect_float(buf + 20, 122.4);
640 expect_float(buf + 21, 40.4);
641 expect_float(buf + 22, 60.2);
642 expect_float(buf + 23, 45.6);
643 expect_float(buf + 24, 20.2);
644 expect_float(buf + 25, 50.0);
645 expect_float(buf + 26, 70.2);
646 expect_dword(buf + 27, 0x01010100);
647 ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */,
648 "expected 00000101 or 43050101 got %08x\n", *(buf + 28));
649 expect_dword(buf + 29, 0xeeeeeeee);
650 test_region_data(buf, needed, __LINE__);
651
652 status = GdipDeletePath(path);
653 expect(Ok, status);
654 status = GdipDeleteRegion(region);
655 expect(Ok, status);
656
657 /* Test how shorts are stored in the region path data */
658 status = GdipCreatePath(FillModeAlternate, &path);
659 ok(status == Ok, "status %08x\n", status);
660 GdipAddPathRectangleI(path, -1969, -1974, 1995, 1997);
661
662 status = GdipCreateRegionPath(path, &region);
663 ok(status == Ok, "status %08x\n", status);
664 needed = 0;
665 status = GdipGetRegionDataSize(region, &needed);
666 ok(status == Ok, "status %08x\n", status);
667 expect(56, needed);
668 memset(buf, 0xee, sizeof(buf));
669 needed = 0;
670 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
671 ok(status == Ok, "status %08x\n", status);
672 expect(56, needed);
673 expect_dword(buf, 48);
674 trace("buf[1] = %08x\n", buf[1]);
675 expect_magic(buf + 2);
676 expect_dword(buf + 3, 0);
677 expect_dword(buf + 4, RGNDATA_PATH);
678 expect_dword(buf + 5, 32);
679 expect_magic(buf + 6);
680 expect_dword(buf + 7, 4);
681 /* flags 0x4000 means that a path is an array of shorts instead of FLOATs */
682 expect_dword(buf + 8, 0x4000);
683 point = (RegionDataPoint*)(buf + 9);
684 expect(-1969, point[0].X);
685 expect(-1974, point[0].Y);
686 expect(26, point[1].X); /* buf + 10 */
687 expect(-1974, point[1].Y);
688 expect(26, point[2].X); /* buf + 11 */
689 expect(23, point[2].Y);
690 expect(-1969, point[3].X); /* buf + 12 */
691 expect(23, point[3].Y);
692 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
693 expect_dword(buf + 14, 0xeeeeeeee);
694 test_region_data(buf, needed, __LINE__);
695
696 status = GdipDeletePath(path);
697 expect(Ok, status);
698 status = GdipDeleteRegion(region);
699 expect(Ok, status);
700
701 /* Test with integers that can't be stored as shorts */
702 status = GdipCreatePath(FillModeAlternate, &path);
703 ok(status == Ok, "status %08x\n", status);
704 GdipAddPathRectangleI(path, -196900, -197400, 199500, 199700);
705
706 status = GdipCreateRegionPath(path, &region);
707 ok(status == Ok, "status %08x\n", status);
708 needed = 0;
709 status = GdipGetRegionDataSize(region, &needed);
710 ok(status == Ok, "status %08x\n", status);
711 expect(72, needed);
712 memset(buf, 0xee, sizeof(buf));
713 needed = 0;
714 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
715 ok(status == Ok, "status %08x\n", status);
716 expect(72, needed);
717 expect_dword(buf, 64);
718 trace("buf[1] = %08x\n", buf[1]);
719 expect_magic(buf + 2);
720 expect_dword(buf + 3, 0);
721 expect_dword(buf + 4, RGNDATA_PATH);
722 expect_dword(buf + 5, 48);
723 expect_magic(buf + 6);
724 expect_dword(buf + 7, 4);
725 /* flags 0 means that a path is an array of FLOATs */
726 expect_dword(buf + 8, 0);
727 expect_float(buf + 9, -196900.0);
728 expect_float(buf + 10, -197400.0);
729 expect_float(buf + 11, 2600.0);
730 expect_float(buf + 12, -197400.0);
731 expect_float(buf + 13, 2600.0);
732 expect_float(buf + 14, 2300.0);
733 expect_float(buf + 15, -196900.0);
734 expect_float(buf + 16, 2300.0);
735 expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */
736 expect_dword(buf + 18, 0xeeeeeeee);
737 test_region_data(buf, needed, __LINE__);
738
739 status = GdipDeletePath(path);
740 expect(Ok, status);
741 status = GdipDeleteRegion(region);
742 expect(Ok, status);
743
744 /* Test beziers */
745 GdipCreatePath(FillModeAlternate, &path);
746 /* Exactly 90 degrees */
747 status = GdipAddPathArc(path, 100.0, 100.0, 500.0, 700.0, 0.0, 90.0);
748 expect(Ok, status);
749 /* Over 90 degrees */
750 status = GdipAddPathArc(path, 100.0, 100.0, 500.0, 700.0, 0.0, 100.0);
751 expect(Ok, status);
752 status = GdipCreateRegionPath(path, &region);
753 ok(status == Ok, "status %08x\n", status);
754 needed = 0;
755 status = GdipGetRegionDataSize(region, &needed);
756 ok(status == Ok, "status %08x\n", status);
757 expect(136, needed);
758 memset(buf, 0xee, sizeof(buf));
759 needed = 0;
760 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
761 ok(status == Ok, "status %08x\n", status);
762 expect(136, needed);
763 expect_dword(buf, 128);
764 trace("buf[1] = %08x\n", buf[1]);
765 expect_magic(buf + 2);
766 expect_dword(buf + 3, 0);
767 expect_dword(buf + 4, RGNDATA_PATH);
768 expect_dword(buf + 5, 112);
769 expect_magic(buf + 6);
770 expect_dword(buf + 7, 11);
771 /* flags 0 means that a path is an array of FLOATs */
772 expect_dword(buf + 8, 0);
773 expect_float(buf + 9, 600.0);
774 expect_float(buf + 10, 450.0);
775 expect_float(buf + 11, 600.0);
776 expect_float(buf + 12, 643.299561);
777 expect_float(buf + 13, 488.071198);
778 expect_float(buf + 14, 800.0);
779 expect_float(buf + 15, 350.0);
780 expect_float(buf + 16, 800.0);
781 expect_float(buf + 17, 600.0);
782 expect_float(buf + 18, 450.0);
783 expect_float(buf + 19, 600.0);
784 expect_float(buf + 20, 643.299622);
785 expect_float(buf + 21, 488.071167);
786 expect_float(buf + 22, 800.0);
787 expect_float(buf + 23, 350.0);
788 expect_float(buf + 24, 800.0);
789 expect_float(buf + 25, 329.807129);
790 expect_float(buf + 26, 800.0);
791 expect_float(buf + 27, 309.688568);
792 expect_float(buf + 28, 796.574890);
793 expect_float(buf + 29, 290.084167);
794 expect_float(buf + 30, 789.799561);
795 expect_dword(buf + 31, 0x03030300);
796 expect_dword(buf + 32, 0x03030301);
797 ok(*(buf + 33) == 0x00030303 /* before win7 */ ||
798 *(buf + 33) == 0x43030303 /* 32-bit win7 */ || *(buf + 33) == 0x4c030303 /* 64-bit win7 */,
799 "expected 0x00030303 or 0x43030303 or 0x4c030303 got %08x\n", *(buf + 33));
800 expect_dword(buf + 34, 0xeeeeeeee);
801 test_region_data(buf, needed, __LINE__);
802
803 status = GdipDeletePath(path);
804 expect(Ok, status);
805 status = GdipDeleteRegion(region);
806 expect(Ok, status);
807 }
808
809 static void test_isinfinite(void)
810 {
811 GpStatus status;
812 GpRegion *region;
813 GpGraphics *graphics = NULL;
814 GpMatrix *m;
815 HDC hdc = GetDC(0);
816 BOOL res;
817
818 status = GdipCreateFromHDC(hdc, &graphics);
819 expect(Ok, status);
820 GdipCreateRegion(&region);
821
822 GdipCreateMatrix2(3.0, 0.0, 0.0, 1.0, 20.0, 30.0, &m);
823
824 /* NULL arguments */
825 status = GdipIsInfiniteRegion(NULL, NULL, NULL);
826 expect(InvalidParameter, status);
827 status = GdipIsInfiniteRegion(region, NULL, NULL);
828 expect(InvalidParameter, status);
829 status = GdipIsInfiniteRegion(NULL, graphics, NULL);
830 expect(InvalidParameter, status);
831 status = GdipIsInfiniteRegion(NULL, NULL, &res);
832 expect(InvalidParameter, status);
833 status = GdipIsInfiniteRegion(region, NULL, &res);
834 expect(InvalidParameter, status);
835
836 res = FALSE;
837 status = GdipIsInfiniteRegion(region, graphics, &res);
838 expect(Ok, status);
839 expect(TRUE, res);
840
841 /* after world transform */
842 status = GdipSetWorldTransform(graphics, m);
843 expect(Ok, status);
844
845 res = FALSE;
846 status = GdipIsInfiniteRegion(region, graphics, &res);
847 expect(Ok, status);
848 expect(TRUE, res);
849
850 GdipDeleteMatrix(m);
851 GdipDeleteRegion(region);
852 GdipDeleteGraphics(graphics);
853 ReleaseDC(0, hdc);
854 }
855
856 static void test_isempty(void)
857 {
858 GpStatus status;
859 GpRegion *region;
860 GpGraphics *graphics = NULL;
861 HDC hdc = GetDC(0);
862 BOOL res;
863
864 status = GdipCreateFromHDC(hdc, &graphics);
865 expect(Ok, status);
866 GdipCreateRegion(&region);
867
868 /* NULL arguments */
869 status = GdipIsEmptyRegion(NULL, NULL, NULL);
870 expect(InvalidParameter, status);
871 status = GdipIsEmptyRegion(region, NULL, NULL);
872 expect(InvalidParameter, status);
873 status = GdipIsEmptyRegion(NULL, graphics, NULL);
874 expect(InvalidParameter, status);
875 status = GdipIsEmptyRegion(NULL, NULL, &res);
876 expect(InvalidParameter, status);
877 status = GdipIsEmptyRegion(region, NULL, &res);
878 expect(InvalidParameter, status);
879
880 /* default is infinite */
881 res = TRUE;
882 status = GdipIsEmptyRegion(region, graphics, &res);
883 expect(Ok, status);
884 expect(FALSE, res);
885
886 status = GdipSetEmpty(region);
887 expect(Ok, status);
888
889 res = FALSE;
890 status = GdipIsEmptyRegion(region, graphics, &res);
891 expect(Ok, status);
892 expect(TRUE, res);
893
894 GdipDeleteRegion(region);
895 GdipDeleteGraphics(graphics);
896 ReleaseDC(0, hdc);
897 }
898
899 static void test_combinereplace(void)
900 {
901 GpStatus status;
902 GpRegion *region, *region2;
903 GpPath *path;
904 GpRectF rectf;
905 UINT needed;
906 DWORD buf[50];
907
908 rectf.X = rectf.Y = 0.0;
909 rectf.Width = rectf.Height = 100.0;
910
911 status = GdipCreateRegionRect(&rectf, &region);
912 expect(Ok, status);
913
914 /* replace with the same rectangle */
915 status = GdipCombineRegionRect(region, &rectf,CombineModeReplace);
916 expect(Ok, status);
917
918 status = GdipGetRegionDataSize(region, &needed);
919 expect(Ok, status);
920 expect(36, needed);
921 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
922 expect(Ok, status);
923 expect(36, needed);
924 expect_dword(buf, 28);
925 trace("buf[1] = %08x\n", buf[1]);
926 expect_magic(buf + 2);
927 expect_dword(buf + 3, 0);
928 expect_dword(buf + 4, RGNDATA_RECT);
929
930 /* replace with path */
931 status = GdipCreatePath(FillModeAlternate, &path);
932 expect(Ok, status);
933 status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
934 expect(Ok, status);
935 status = GdipCombineRegionPath(region, path, CombineModeReplace);
936 expect(Ok, status);
937
938 status = GdipGetRegionDataSize(region, &needed);
939 expect(Ok, status);
940 expect(156, needed);
941 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
942 expect(Ok, status);
943 expect(156, needed);
944 expect_dword(buf, 148);
945 trace("buf[1] = %08x\n", buf[1]);
946 expect_magic(buf + 2);
947 expect_dword(buf + 3, 0);
948 expect_dword(buf + 4, RGNDATA_PATH);
949 GdipDeletePath(path);
950
951 /* replace with infinite rect */
952 status = GdipCreateRegion(&region2);
953 expect(Ok, status);
954 status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
955 expect(Ok, status);
956
957 status = GdipGetRegionDataSize(region, &needed);
958 expect(Ok, status);
959 expect(20, needed);
960 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
961 expect(Ok, status);
962 expect(20, needed);
963 expect_dword(buf, 12);
964 trace("buf[1] = %08x\n", buf[1]);
965 expect_magic(buf + 2);
966 expect_dword(buf + 3, 0);
967 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
968 GdipDeleteRegion(region2);
969
970 /* more complex case : replace with a combined region */
971 status = GdipCreateRegionRect(&rectf, &region2);
972 expect(Ok, status);
973 status = GdipCreatePath(FillModeAlternate, &path);
974 expect(Ok, status);
975 status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
976 expect(Ok, status);
977 status = GdipCombineRegionPath(region2, path, CombineModeUnion);
978 expect(Ok, status);
979 GdipDeletePath(path);
980 status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
981 expect(Ok, status);
982 GdipDeleteRegion(region2);
983
984 status = GdipGetRegionDataSize(region, &needed);
985 expect(Ok, status);
986 expect(180, needed);
987 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
988 expect(Ok, status);
989 expect(180, needed);
990 expect_dword(buf, 172);
991 trace("buf[1] = %08x\n", buf[1]);
992 expect_magic(buf + 2);
993 expect_dword(buf + 3, 2);
994 expect_dword(buf + 4, CombineModeUnion);
995
996 GdipDeleteRegion(region);
997 }
998
999 static void test_fromhrgn(void)
1000 {
1001 GpStatus status;
1002 GpRegion *region = (GpRegion*)0xabcdef01;
1003 HRGN hrgn;
1004 UINT needed;
1005 DWORD buf[220];
1006 RegionDataPoint *point;
1007 GpGraphics *graphics = NULL;
1008 HDC hdc;
1009 BOOL res;
1010
1011 /* NULL */
1012 status = GdipCreateRegionHrgn(NULL, NULL);
1013 expect(InvalidParameter, status);
1014 status = GdipCreateRegionHrgn(NULL, &region);
1015 expect(InvalidParameter, status);
1016 status = GdipCreateRegionHrgn((HRGN)0xdeadbeef, &region);
1017 expect(InvalidParameter, status);
1018 ok(region == (GpRegion*)0xabcdef01, "Expected region not to be created\n");
1019
1020 /* empty rectangle */
1021 hrgn = CreateRectRgn(0, 0, 0, 0);
1022 status = GdipCreateRegionHrgn(hrgn, &region);
1023 expect(Ok, status);
1024 if(status == Ok) {
1025
1026 hdc = GetDC(0);
1027 status = GdipCreateFromHDC(hdc, &graphics);
1028 expect(Ok, status);
1029 res = FALSE;
1030 status = GdipIsEmptyRegion(region, graphics, &res);
1031 expect(Ok, status);
1032 expect(TRUE, res);
1033 GdipDeleteGraphics(graphics);
1034 ReleaseDC(0, hdc);
1035 GdipDeleteRegion(region);
1036
1037 }
1038 DeleteObject(hrgn);
1039
1040 /* rectangle */
1041 hrgn = CreateRectRgn(0, 0, 100, 10);
1042 status = GdipCreateRegionHrgn(hrgn, &region);
1043 expect(Ok, status);
1044
1045 status = GdipGetRegionDataSize(region, &needed);
1046 expect(Ok, status);
1047 expect(56, needed);
1048
1049 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
1050 expect(Ok, status);
1051
1052 if(status == Ok){
1053
1054 expect(56, needed);
1055 expect_dword(buf, 48);
1056 expect_magic(buf + 2);
1057 expect_dword(buf + 3, 0);
1058 expect_dword(buf + 4, RGNDATA_PATH);
1059 expect_dword(buf + 5, 0x00000020);
1060 expect_magic(buf + 6);
1061 expect_dword(buf + 7, 0x00000004);
1062 todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
1063
1064 point = (RegionDataPoint*)buf + 9;
1065
1066 expect(0, point[0].X);
1067 expect(0, point[0].Y);
1068
1069 expect(100,point[1].X); /* buf + 10 */
1070 expect(0, point[1].Y);
1071 expect(100,point[2].X); /* buf + 11 */
1072 expect(10, point[2].Y);
1073
1074 expect(0, point[3].X); /* buf + 12 */
1075
1076 expect(10, point[3].Y);
1077 expect_dword(buf + 13, 0x81010100); /* closed */
1078
1079 }
1080
1081 GdipDeleteRegion(region);
1082 DeleteObject(hrgn);
1083
1084 /* ellipse */
1085 hrgn = CreateEllipticRgn(0, 0, 100, 10);
1086 status = GdipCreateRegionHrgn(hrgn, &region);
1087 expect(Ok, status);
1088
1089 status = GdipGetRegionDataSize(region, &needed);
1090 expect(Ok, status);
1091 ok(needed == 216 ||
1092 needed == 196, /* win98 */
1093 "Got %.8x\n", needed);
1094
1095 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
1096 expect(Ok, status);
1097
1098 if(status == Ok && needed == 216) /* Don't try to test win98 layout */
1099 {
1100 expect(Ok, status);
1101 expect(216, needed);
1102 expect_dword(buf, 208);
1103 expect_magic(buf + 2);
1104 expect_dword(buf + 3, 0);
1105 expect_dword(buf + 4, RGNDATA_PATH);
1106 expect_dword(buf + 5, 0x000000C0);
1107 expect_magic(buf + 6);
1108 expect_dword(buf + 7, 0x00000024);
1109 todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
1110 }
1111
1112 GdipDeleteRegion(region);
1113 DeleteObject(hrgn);
1114 }
1115
1116 static void test_gethrgn(void)
1117 {
1118 GpStatus status;
1119 GpRegion *region, *region2;
1120 GpPath *path;
1121 GpGraphics *graphics;
1122 HRGN hrgn;
1123 HDC hdc=GetDC(0);
1124 static const RECT empty_rect = {0,0,0,0};
1125 static const RECT test_rect = {10, 11, 20, 21};
1126 static const GpRectF test_rectF = {10.0, 11.0, 10.0, 10.0};
1127 static const RECT scaled_rect = {20, 22, 40, 42};
1128 static const RECT test_rect2 = {10, 21, 20, 31};
1129 static const GpRectF test_rect2F = {10.0, 21.0, 10.0, 10.0};
1130 static const RECT test_rect3 = {10, 11, 20, 31};
1131 static const GpRectF test_rect3F = {10.0, 11.0, 10.0, 20.0};
1132
1133 status = GdipCreateFromHDC(hdc, &graphics);
1134 ok(status == Ok, "status %08x\n", status);
1135
1136 status = GdipCreateRegion(&region);
1137 ok(status == Ok, "status %08x\n", status);
1138
1139 status = GdipGetRegionHRgn(NULL, graphics, &hrgn);
1140 ok(status == InvalidParameter, "status %08x\n", status);
1141 status = GdipGetRegionHRgn(region, graphics, NULL);
1142 ok(status == InvalidParameter, "status %08x\n", status);
1143
1144 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1145 ok(status == Ok, "status %08x\n", status);
1146 ok(hrgn == NULL, "hrgn=%p\n", hrgn);
1147
1148 status = GdipGetRegionHRgn(region, graphics, &hrgn);
1149 ok(status == Ok, "status %08x\n", status);
1150 ok(hrgn == NULL, "hrgn=%p\n", hrgn);
1151
1152 status = GdipSetEmpty(region);
1153 ok(status == Ok, "status %08x\n", status);
1154 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1155 ok(status == Ok, "status %08x\n", status);
1156 verify_region(hrgn, &empty_rect);
1157 DeleteObject(hrgn);
1158
1159 status = GdipCreatePath(FillModeAlternate, &path);
1160 ok(status == Ok, "status %08x\n", status);
1161 status = GdipAddPathRectangle(path, 10.0, 11.0, 10.0, 10.0);
1162 ok(status == Ok, "status %08x\n", status);
1163
1164 status = GdipCreateRegionPath(path, &region2);
1165 ok(status == Ok, "status %08x\n", status);
1166 status = GdipGetRegionHRgn(region2, NULL, &hrgn);
1167 ok(status == Ok, "status %08x\n", status);
1168 verify_region(hrgn, &test_rect);
1169 DeleteObject(hrgn);
1170
1171 /* resulting HRGN is in device coordinates */
1172 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1173 ok(status == Ok, "status %08x\n", status);
1174 status = GdipGetRegionHRgn(region2, graphics, &hrgn);
1175 ok(status == Ok, "status %08x\n", status);
1176 verify_region(hrgn, &scaled_rect);
1177 DeleteObject(hrgn);
1178
1179 status = GdipCombineRegionRect(region2, &test_rectF, CombineModeReplace);
1180 ok(status == Ok, "status %08x\n", status);
1181 status = GdipGetRegionHRgn(region2, NULL, &hrgn);
1182 ok(status == Ok, "status %08x\n", status);
1183 verify_region(hrgn, &test_rect);
1184 DeleteObject(hrgn);
1185
1186 status = GdipGetRegionHRgn(region2, graphics, &hrgn);
1187 ok(status == Ok, "status %08x\n", status);
1188 verify_region(hrgn, &scaled_rect);
1189 DeleteObject(hrgn);
1190
1191 status = GdipSetInfinite(region);
1192 ok(status == Ok, "status %08x\n", status);
1193 status = GdipCombineRegionRect(region, &test_rectF, CombineModeIntersect);
1194 ok(status == Ok, "status %08x\n", status);
1195 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1196 ok(status == Ok, "status %08x\n", status);
1197 verify_region(hrgn, &test_rect);
1198 DeleteObject(hrgn);
1199
1200 status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
1201 ok(status == Ok, "status %08x\n", status);
1202 status = GdipCombineRegionRect(region, &test_rect2F, CombineModeUnion);
1203 ok(status == Ok, "status %08x\n", status);
1204 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1205 ok(status == Ok, "status %08x\n", status);
1206 verify_region(hrgn, &test_rect3);
1207 DeleteObject(hrgn);
1208
1209 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
1210 ok(status == Ok, "status %08x\n", status);
1211 status = GdipCombineRegionRect(region, &test_rect2F, CombineModeXor);
1212 ok(status == Ok, "status %08x\n", status);
1213 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1214 ok(status == Ok, "status %08x\n", status);
1215 verify_region(hrgn, &test_rect);
1216 DeleteObject(hrgn);
1217
1218 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
1219 ok(status == Ok, "status %08x\n", status);
1220 status = GdipCombineRegionRect(region, &test_rectF, CombineModeExclude);
1221 ok(status == Ok, "status %08x\n", status);
1222 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1223 ok(status == Ok, "status %08x\n", status);
1224 verify_region(hrgn, &test_rect2);
1225 DeleteObject(hrgn);
1226
1227 status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
1228 ok(status == Ok, "status %08x\n", status);
1229 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeComplement);
1230 ok(status == Ok, "status %08x\n", status);
1231 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1232 ok(status == Ok, "status %08x\n", status);
1233 verify_region(hrgn, &test_rect2);
1234 DeleteObject(hrgn);
1235
1236 status = GdipDeletePath(path);
1237 ok(status == Ok, "status %08x\n", status);
1238 status = GdipDeleteRegion(region);
1239 ok(status == Ok, "status %08x\n", status);
1240 status = GdipDeleteRegion(region2);
1241 ok(status == Ok, "status %08x\n", status);
1242 status = GdipDeleteGraphics(graphics);
1243 ok(status == Ok, "status %08x\n", status);
1244 ReleaseDC(0, hdc);
1245 }
1246
1247 static void test_isequal(void)
1248 {
1249 GpRegion *region1, *region2;
1250 GpGraphics *graphics;
1251 GpRectF rectf;
1252 GpStatus status;
1253 HDC hdc = GetDC(0);
1254 BOOL res;
1255
1256 status = GdipCreateFromHDC(hdc, &graphics);
1257 ok(status == Ok, "status %08x\n", status);
1258
1259 status = GdipCreateRegion(&region1);
1260 ok(status == Ok, "status %08x\n", status);
1261 status = GdipCreateRegion(&region2);
1262 ok(status == Ok, "status %08x\n", status);
1263
1264 /* NULL */
1265 status = GdipIsEqualRegion(NULL, NULL, NULL, NULL);
1266 ok(status == InvalidParameter, "status %08x\n", status);
1267 status = GdipIsEqualRegion(region1, region2, NULL, NULL);
1268 ok(status == InvalidParameter, "status %08x\n", status);
1269 status = GdipIsEqualRegion(region1, region2, graphics, NULL);
1270 ok(status == InvalidParameter, "status %08x\n", status);
1271 status = GdipIsEqualRegion(region1, region2, NULL, &res);
1272 ok(status == InvalidParameter, "status %08x\n", status);
1273
1274 /* infinite regions */
1275 res = FALSE;
1276 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1277 ok(status == Ok, "status %08x\n", status);
1278 ok(res, "Expected to be equal.\n");
1279 /* empty regions */
1280 status = GdipSetEmpty(region1);
1281 ok(status == Ok, "status %08x\n", status);
1282 status = GdipSetEmpty(region2);
1283 ok(status == Ok, "status %08x\n", status);
1284 res = FALSE;
1285 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1286 ok(status == Ok, "status %08x\n", status);
1287 ok(res, "Expected to be equal.\n");
1288 /* empty & infinite */
1289 status = GdipSetInfinite(region1);
1290 ok(status == Ok, "status %08x\n", status);
1291 res = TRUE;
1292 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1293 ok(status == Ok, "status %08x\n", status);
1294 ok(!res, "Expected to be unequal.\n");
1295 /* rect & (inf/empty) */
1296 rectf.X = rectf.Y = 0.0;
1297 rectf.Width = rectf.Height = 100.0;
1298 status = GdipCombineRegionRect(region1, &rectf, CombineModeReplace);
1299 ok(status == Ok, "status %08x\n", status);
1300 res = TRUE;
1301 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1302 ok(status == Ok, "status %08x\n", status);
1303 ok(!res, "Expected to be unequal.\n");
1304 status = GdipSetInfinite(region2);
1305 ok(status == Ok, "status %08x\n", status);
1306 res = TRUE;
1307 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1308 ok(status == Ok, "status %08x\n", status);
1309 ok(!res, "Expected to be unequal.\n");
1310 /* roughly equal rectangles */
1311 rectf.X = rectf.Y = 0.0;
1312 rectf.Width = rectf.Height = 100.001;
1313 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1314 ok(status == Ok, "status %08x\n", status);
1315 res = FALSE;
1316 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1317 ok(status == Ok, "status %08x\n", status);
1318 ok(res, "Expected to be equal.\n");
1319 /* equal rectangles */
1320 rectf.X = rectf.Y = 0.0;
1321 rectf.Width = rectf.Height = 100.0;
1322 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1323 ok(status == Ok, "status %08x\n", status);
1324 res = FALSE;
1325 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1326 ok(status == Ok, "status %08x\n", status);
1327 ok(res, "Expected to be equal.\n");
1328
1329 /* cleanup */
1330 status = GdipDeleteRegion(region1);
1331 ok(status == Ok, "status %08x\n", status);
1332 status = GdipDeleteRegion(region2);
1333 ok(status == Ok, "status %08x\n", status);
1334 status = GdipDeleteGraphics(graphics);
1335 ok(status == Ok, "status %08x\n", status);
1336 ReleaseDC(0, hdc);
1337 }
1338
1339 static void test_translate(void)
1340 {
1341 GpRegion *region, *region2;
1342 GpGraphics *graphics;
1343 GpPath *path;
1344 GpRectF rectf;
1345 GpStatus status;
1346 HDC hdc = GetDC(0);
1347 BOOL res;
1348
1349 status = GdipCreateFromHDC(hdc, &graphics);
1350 ok(status == Ok, "status %08x\n", status);
1351
1352 status = GdipCreatePath(FillModeAlternate, &path);
1353 ok(status == Ok, "status %08x\n", status);
1354
1355 status = GdipCreateRegion(&region);
1356 ok(status == Ok, "status %08x\n", status);
1357 status = GdipCreateRegion(&region2);
1358 ok(status == Ok, "status %08x\n", status);
1359
1360 /* NULL */
1361 status = GdipTranslateRegion(NULL, 0.0, 0.0);
1362 ok(status == InvalidParameter, "status %08x\n", status);
1363
1364 /* infinite */
1365 status = GdipTranslateRegion(region, 10.0, 10.0);
1366 ok(status == Ok, "status %08x\n", status);
1367 /* empty */
1368 status = GdipSetEmpty(region);
1369 ok(status == Ok, "status %08x\n", status);
1370 status = GdipTranslateRegion(region, 10.0, 10.0);
1371 ok(status == Ok, "status %08x\n", status);
1372 /* rect */
1373 rectf.X = 10.0; rectf.Y = 0.0;
1374 rectf.Width = rectf.Height = 100.0;
1375 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1376 ok(status == Ok, "status %08x\n", status);
1377 rectf.X = 15.0; rectf.Y = -2.0;
1378 rectf.Width = rectf.Height = 100.0;
1379 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1380 ok(status == Ok, "status %08x\n", status);
1381 status = GdipTranslateRegion(region, 5.0, -2.0);
1382 ok(status == Ok, "status %08x\n", status);
1383 res = FALSE;
1384 status = GdipIsEqualRegion(region, region2, graphics, &res);
1385 ok(status == Ok, "status %08x\n", status);
1386 ok(res, "Expected to be equal.\n");
1387 /* path */
1388 status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1389 ok(status == Ok, "status %08x\n", status);
1390 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1391 ok(status == Ok, "status %08x\n", status);
1392 status = GdipResetPath(path);
1393 ok(status == Ok, "status %08x\n", status);
1394 status = GdipAddPathEllipse(path, 10.0, 21.0, 100.0, 150.0);
1395 ok(status == Ok, "status %08x\n", status);
1396 status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1397 ok(status == Ok, "status %08x\n", status);
1398 status = GdipTranslateRegion(region, 10.0, 11.0);
1399 ok(status == Ok, "status %08x\n", status);
1400 res = FALSE;
1401 status = GdipIsEqualRegion(region, region2, graphics, &res);
1402 ok(status == Ok, "status %08x\n", status);
1403 ok(res, "Expected to be equal.\n");
1404
1405 status = GdipDeleteRegion(region);
1406 ok(status == Ok, "status %08x\n", status);
1407 status = GdipDeleteRegion(region2);
1408 ok(status == Ok, "status %08x\n", status);
1409 status = GdipDeleteGraphics(graphics);
1410 ok(status == Ok, "status %08x\n", status);
1411 status = GdipDeletePath(path);
1412 ok(status == Ok, "status %08x\n", status);
1413 ReleaseDC(0, hdc);
1414 }
1415
1416 static void test_transform(void)
1417 {
1418 GpRegion *region, *region2;
1419 GpMatrix *matrix;
1420 GpGraphics *graphics;
1421 GpPath *path;
1422 GpRectF rectf;
1423 GpStatus status;
1424 HDC hdc = GetDC(0);
1425 BOOL res;
1426
1427 status = GdipCreateFromHDC(hdc, &graphics);
1428 expect(Ok, status);
1429
1430 status = GdipCreatePath(FillModeAlternate, &path);
1431 expect(Ok, status);
1432
1433 status = GdipCreateRegion(&region);
1434 expect(Ok, status);
1435 status = GdipCreateRegion(&region2);
1436 expect(Ok, status);
1437
1438 status = GdipCreateMatrix(&matrix);
1439 expect(Ok, status);
1440 status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
1441 expect(Ok, status);
1442
1443 /* NULL */
1444 status = GdipTransformRegion(NULL, matrix);
1445 expect(InvalidParameter, status);
1446
1447 status = GdipTransformRegion(region, NULL);
1448 expect(InvalidParameter, status);
1449
1450 /* infinite */
1451 status = GdipTransformRegion(region, matrix);
1452 expect(Ok, status);
1453
1454 res = FALSE;
1455 status = GdipIsEqualRegion(region, region2, graphics, &res);
1456 expect(Ok, status);
1457 ok(res, "Expected to be equal.\n");
1458
1459 /* empty */
1460 status = GdipSetEmpty(region);
1461 expect(Ok, status);
1462 status = GdipTransformRegion(region, matrix);
1463 expect(Ok, status);
1464
1465 status = GdipSetEmpty(region2);
1466 expect(Ok, status);
1467
1468 res = FALSE;
1469 status = GdipIsEqualRegion(region, region2, graphics, &res);
1470 expect(Ok, status);
1471 ok(res, "Expected to be equal.\n");
1472
1473 /* rect */
1474 rectf.X = 10.0;
1475 rectf.Y = 0.0;
1476 rectf.Width = rectf.Height = 100.0;
1477 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1478 expect(Ok, status);
1479 rectf.X = 20.0;
1480 rectf.Y = 0.0;
1481 rectf.Width = 200.0;
1482 rectf.Height = 300.0;
1483 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1484 expect(Ok, status);
1485 status = GdipTransformRegion(region, matrix);
1486 expect(Ok, status);
1487 res = FALSE;
1488 status = GdipIsEqualRegion(region, region2, graphics, &res);
1489 expect(Ok, status);
1490 ok(res, "Expected to be equal.\n");
1491
1492 /* path */
1493 status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1494 expect(Ok, status);
1495 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1496 expect(Ok, status);
1497 status = GdipResetPath(path);
1498 expect(Ok, status);
1499 status = GdipAddPathEllipse(path, 0.0, 30.0, 200.0, 450.0);
1500 expect(Ok, status);
1501 status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1502 expect(Ok, status);
1503 status = GdipTransformRegion(region, matrix);
1504 expect(Ok, status);
1505 res = FALSE;
1506 status = GdipIsEqualRegion(region, region2, graphics, &res);
1507 expect(Ok, status);
1508 ok(res, "Expected to be equal.\n");
1509
1510 status = GdipDeleteRegion(region);
1511 expect(Ok, status);
1512 status = GdipDeleteRegion(region2);
1513 expect(Ok, status);
1514 status = GdipDeleteGraphics(graphics);
1515 expect(Ok, status);
1516 status = GdipDeletePath(path);
1517 expect(Ok, status);
1518 status = GdipDeleteMatrix(matrix);
1519 expect(Ok, status);
1520 ReleaseDC(0, hdc);
1521 }
1522
1523 static void test_scans(void)
1524 {
1525 GpRegion *region;
1526 GpMatrix *matrix;
1527 GpRectF rectf;
1528 GpStatus status;
1529 ULONG count=80085;
1530 INT icount;
1531 GpRectF scans[2];
1532 GpRect scansi[2];
1533
1534 status = GdipCreateRegion(&region);
1535 expect(Ok, status);
1536
1537 status = GdipCreateMatrix(&matrix);
1538 expect(Ok, status);
1539
1540 /* test NULL values */
1541 status = GdipGetRegionScansCount(NULL, &count, matrix);
1542 expect(InvalidParameter, status);
1543
1544 status = GdipGetRegionScansCount(region, NULL, matrix);
1545 expect(InvalidParameter, status);
1546
1547 status = GdipGetRegionScansCount(region, &count, NULL);
1548 expect(InvalidParameter, status);
1549
1550 status = GdipGetRegionScans(NULL, scans, &icount, matrix);
1551 expect(InvalidParameter, status);
1552
1553 status = GdipGetRegionScans(region, scans, NULL, matrix);
1554 expect(InvalidParameter, status);
1555
1556 status = GdipGetRegionScans(region, scans, &icount, NULL);
1557 expect(InvalidParameter, status);
1558
1559 /* infinite */
1560 status = GdipGetRegionScansCount(region, &count, matrix);
1561 expect(Ok, status);
1562 expect(1, count);
1563
1564 status = GdipGetRegionScans(region, NULL, &icount, matrix);
1565 expect(Ok, status);
1566 expect(1, icount);
1567
1568 status = GdipGetRegionScans(region, scans, &icount, matrix);
1569 expect(Ok, status);
1570 expect(1, icount);
1571
1572 status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1573 expect(Ok, status);
1574 expect(1, icount);
1575 expect(-0x400000, scansi[0].X);
1576 expect(-0x400000, scansi[0].Y);
1577 expect(0x800000, scansi[0].Width);
1578 expect(0x800000, scansi[0].Height);
1579
1580 status = GdipGetRegionScans(region, scans, &icount, matrix);
1581 expect(Ok, status);
1582 expect(1, icount);
1583 expectf((double)-0x400000, scans[0].X);
1584 expectf((double)-0x400000, scans[0].Y);
1585 expectf((double)0x800000, scans[0].Width);
1586 expectf((double)0x800000, scans[0].Height);
1587
1588 /* empty */
1589 status = GdipSetEmpty(region);
1590 expect(Ok, status);
1591
1592 status = GdipGetRegionScansCount(region, &count, matrix);
1593 expect(Ok, status);
1594 expect(0, count);
1595
1596 status = GdipGetRegionScans(region, scans, &icount, matrix);
1597 expect(Ok, status);
1598 expect(0, icount);
1599
1600 /* single rectangle */
1601 rectf.X = rectf.Y = 0.0;
1602 rectf.Width = rectf.Height = 5.0;
1603 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1604 expect(Ok, status);
1605
1606 status = GdipGetRegionScansCount(region, &count, matrix);
1607 expect(Ok, status);
1608 expect(1, count);
1609
1610 status = GdipGetRegionScans(region, scans, &icount, matrix);
1611 expect(Ok, status);
1612 expect(1, icount);
1613 expectf(0.0, scans[0].X);
1614 expectf(0.0, scans[0].Y);
1615 expectf(5.0, scans[0].Width);
1616 expectf(5.0, scans[0].Height);
1617
1618 /* two rectangles */
1619 rectf.X = rectf.Y = 5.0;
1620 rectf.Width = rectf.Height = 5.0;
1621 status = GdipCombineRegionRect(region, &rectf, CombineModeUnion);
1622 expect(Ok, status);
1623
1624 status = GdipGetRegionScansCount(region, &count, matrix);
1625 expect(Ok, status);
1626 expect(2, count);
1627
1628 /* Native ignores the initial value of count */
1629 scans[1].X = scans[1].Y = scans[1].Width = scans[1].Height = 8.0;
1630 icount = 1;
1631 status = GdipGetRegionScans(region, scans, &icount, matrix);
1632 expect(Ok, status);
1633 expect(2, icount);
1634 expectf(0.0, scans[0].X);
1635 expectf(0.0, scans[0].Y);
1636 expectf(5.0, scans[0].Width);
1637 expectf(5.0, scans[0].Height);
1638 expectf(5.0, scans[1].X);
1639 expectf(5.0, scans[1].Y);
1640 expectf(5.0, scans[1].Width);
1641 expectf(5.0, scans[1].Height);
1642
1643 status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1644 expect(Ok, status);
1645 expect(2, icount);
1646 expect(0, scansi[0].X);
1647 expect(0, scansi[0].Y);
1648 expect(5, scansi[0].Width);
1649 expect(5, scansi[0].Height);
1650 expect(5, scansi[1].X);
1651 expect(5, scansi[1].Y);
1652 expect(5, scansi[1].Width);
1653 expect(5, scansi[1].Height);
1654
1655 status = GdipDeleteRegion(region);
1656 expect(Ok, status);
1657 status = GdipDeleteMatrix(matrix);
1658 expect(Ok, status);
1659 }
1660
1661 static void test_getbounds(void)
1662 {
1663 GpRegion *region;
1664 GpGraphics *graphics;
1665 GpStatus status;
1666 GpRectF rectf;
1667 HDC hdc = GetDC(0);
1668
1669 status = GdipCreateFromHDC(hdc, &graphics);
1670 ok(status == Ok, "status %08x\n", status);
1671 status = GdipCreateRegion(&region);
1672 ok(status == Ok, "status %08x\n", status);
1673
1674 /* NULL */
1675 status = GdipGetRegionBounds(NULL, NULL, NULL);
1676 ok(status == InvalidParameter, "status %08x\n", status);
1677 status = GdipGetRegionBounds(region, NULL, NULL);
1678 ok(status == InvalidParameter, "status %08x\n", status);
1679 status = GdipGetRegionBounds(region, graphics, NULL);
1680 ok(status == InvalidParameter, "status %08x\n", status);
1681 /* infinite */
1682 rectf.X = rectf.Y = 0.0;
1683 rectf.Height = rectf.Width = 100.0;
1684 status = GdipGetRegionBounds(region, graphics, &rectf);
1685 ok(status == Ok, "status %08x\n", status);
1686 ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1687 ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1688 ok(rectf.Width == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1689 ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1690 /* empty */
1691 rectf.X = rectf.Y = 0.0;
1692 rectf.Height = rectf.Width = 100.0;
1693 status = GdipSetEmpty(region);
1694 ok(status == Ok, "status %08x\n", status);
1695 status = GdipGetRegionBounds(region, graphics, &rectf);
1696 ok(status == Ok, "status %08x\n", status);
1697 ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1698 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1699 ok(rectf.Width == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1700 ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1701 /* rect */
1702 rectf.X = 10.0; rectf.Y = 0.0;
1703 rectf.Width = rectf.Height = 100.0;
1704 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1705 ok(status == Ok, "status %08x\n", status);
1706 rectf.X = rectf.Y = 0.0;
1707 rectf.Height = rectf.Width = 0.0;
1708 status = GdipGetRegionBounds(region, graphics, &rectf);
1709 ok(status == Ok, "status %08x\n", status);
1710 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1711 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1712 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1713 ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1714
1715 /* the world and page transforms are ignored */
1716 GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1717 GdipSetPageUnit(graphics, UnitInch);
1718 GdipSetPageScale(graphics, 2.0);
1719 status = GdipGetRegionBounds(region, graphics, &rectf);
1720 ok(status == Ok, "status %08x\n", status);
1721 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1722 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1723 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1724
1725 rectf.X = 10.0; rectf.Y = 0.0;
1726 rectf.Width = rectf.Height = 100.0;
1727 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1728 ok(status == Ok, "status %08x\n", status);
1729 rectf.X = rectf.Y = 0.0;
1730 rectf.Height = rectf.Width = 0.0;
1731 status = GdipGetRegionBounds(region, graphics, &rectf);
1732 ok(status == Ok, "status %08x\n", status);
1733 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1734 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1735 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1736 ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1737
1738 status = GdipDeleteRegion(region);
1739 ok(status == Ok, "status %08x\n", status);
1740 status = GdipDeleteGraphics(graphics);
1741 ok(status == Ok, "status %08x\n", status);
1742 ReleaseDC(0, hdc);
1743 }
1744
1745 static void test_isvisiblepoint(void)
1746 {
1747 HDC hdc = GetDC(0);
1748 GpGraphics* graphics;
1749 GpRegion* region;
1750 GpPath* path;
1751 GpRectF rectf;
1752 GpStatus status;
1753 BOOL res;
1754 REAL x, y;
1755
1756 status = GdipCreateFromHDC(hdc, &graphics);
1757 expect(Ok, status);
1758
1759 status = GdipCreateRegion(&region);
1760 expect(Ok, status);
1761
1762 /* null parameters */
1763 status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1764 expect(InvalidParameter, status);
1765 status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1766 expect(InvalidParameter, status);
1767
1768 status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1769 expect(Ok, status);
1770 status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1771 expect(Ok, status);
1772
1773 status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1774 expect(InvalidParameter, status);
1775 status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1776 expect(InvalidParameter, status);
1777
1778 /* infinite region */
1779 status = GdipIsInfiniteRegion(region, graphics, &res);
1780 expect(Ok, status);
1781 ok(res == TRUE, "Region should be infinite\n");
1782
1783 x = 10;
1784 y = 10;
1785 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1786 expect(Ok, status);
1787 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1788 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1789 expect(Ok, status);
1790 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1791
1792 x = -10;
1793 y = -10;
1794 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1795 expect(Ok, status);
1796 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1797 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1798 expect(Ok, status);
1799 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1800
1801 /* rectangular region */
1802 rectf.X = 10;
1803 rectf.Y = 20;
1804 rectf.Width = 30;
1805 rectf.Height = 40;
1806
1807 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1808 expect(Ok, status);
1809
1810 x = 0;
1811 y = 0;
1812 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1813 expect(Ok, status);
1814 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1815 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1816 expect(Ok, status);
1817 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1818
1819 x = 9;
1820 y = 19;
1821 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1822 expect(Ok, status);
1823 ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1824
1825 x = 9.25;
1826 y = 19.25;
1827 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1828 expect(Ok, status);
1829 ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1830
1831 x = 9.5;
1832 y = 19.5;
1833 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1834 expect(Ok, status);
1835 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1836
1837 x = 9.75;
1838 y = 19.75;
1839 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1840 expect(Ok, status);
1841 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1842
1843 x = 10;
1844 y = 20;
1845 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1846 expect(Ok, status);
1847 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1848
1849 x = 25;
1850 y = 40;
1851 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1852 expect(Ok, status);
1853 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1854 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1855 expect(Ok, status);
1856 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1857
1858 x = 40;
1859 y = 60;
1860 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1861 expect(Ok, status);
1862 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1863 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1864 expect(Ok, status);
1865 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1866
1867 /* translate into the center of the rectangle */
1868 status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1869 expect(Ok, status);
1870
1871 /* native ignores the world transform, so treat these as if
1872 * no transform exists */
1873 x = -20;
1874 y = -30;
1875 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1876 expect(Ok, status);
1877 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1878 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1879 expect(Ok, status);
1880 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1881
1882 x = 0;
1883 y = 0;
1884 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1885 expect(Ok, status);
1886 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1887 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1888 expect(Ok, status);
1889 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1890
1891 x = 25;
1892 y = 40;
1893 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1894 expect(Ok, status);
1895 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1896 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1897 expect(Ok, status);
1898 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1899
1900 /* translate back to origin */
1901 status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1902 expect(Ok, status);
1903
1904 /* region from path */
1905 status = GdipCreatePath(FillModeAlternate, &path);
1906 expect(Ok, status);
1907
1908 status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1909 expect(Ok, status);
1910
1911 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1912 expect(Ok, status);
1913
1914 x = 11;
1915 y = 21;
1916 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1917 expect(Ok, status);
1918 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1919 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1920 expect(Ok, status);
1921 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1922
1923 x = 25;
1924 y = 40;
1925 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1926 expect(Ok, status);
1927 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1928 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1929 expect(Ok, status);
1930 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1931
1932 x = 40;
1933 y = 60;
1934 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1935 expect(Ok, status);
1936 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1937 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1938 expect(Ok, status);
1939 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1940
1941 GdipDeletePath(path);
1942
1943 GdipDeleteRegion(region);
1944 GdipDeleteGraphics(graphics);
1945 ReleaseDC(0, hdc);
1946 }
1947
1948 static void test_isvisiblerect(void)
1949 {
1950 HDC hdc = GetDC(0);
1951 GpGraphics* graphics;
1952 GpRegion* region;
1953 GpPath* path;
1954 GpRectF rectf;
1955 GpStatus status;
1956 BOOL res;
1957 REAL x, y, w, h;
1958
1959 status = GdipCreateFromHDC(hdc, &graphics);
1960 expect(Ok, status);
1961
1962 status = GdipCreateRegion(&region);
1963 expect(Ok, status);
1964
1965 /* null parameters */
1966 status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
1967 expect(InvalidParameter, status);
1968 status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
1969 expect(InvalidParameter, status);
1970
1971 status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
1972 expect(Ok, status);
1973 status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
1974 expect(Ok, status);
1975
1976 status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
1977 expect(InvalidParameter, status);
1978 status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
1979 expect(InvalidParameter, status);
1980
1981 /* infinite region */
1982 status = GdipIsInfiniteRegion(region, graphics, &res);
1983 expect(Ok, status);
1984 ok(res == TRUE, "Region should be infinite\n");
1985
1986 x = 10; w = 10;
1987 y = 10; h = 10;
1988 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1989 expect(Ok, status);
1990 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1991
1992 x = -10; w = 5;
1993 y = -10; h = 5;
1994 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1995 expect(Ok, status);
1996 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1997
1998 /* rectangular region */
1999 rectf.X = 10;
2000 rectf.Y = 20;
2001 rectf.Width = 30;
2002 rectf.Height = 40;
2003
2004 status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
2005 expect(Ok, status);
2006
2007 /* entirely within the region */
2008 x = 11; w = 10;
2009 y = 12; h = 10;
2010 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2011 expect(Ok, status);
2012 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2013 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2014 expect(Ok, status);
2015 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2016
2017 /* entirely outside of the region */
2018 x = 0; w = 5;
2019 y = 0; h = 5;
2020 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2021 expect(Ok, status);
2022 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2023 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2024 expect(Ok, status);
2025 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2026
2027 /* corner cases */
2028 x = 0; w = 10;
2029 y = 0; h = 20;
2030 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2031 expect(Ok, status);
2032 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2033
2034 x = 0; w = 10.25;
2035 y = 0; h = 20.25;
2036 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2037 expect(Ok, status);
2038 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2039
2040 x = 39; w = 10;
2041 y = 59; h = 10;
2042 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2043 expect(Ok, status);
2044 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2045
2046 x = 39.25; w = 10;
2047 y = 59.25; h = 10;
2048 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2049 expect(Ok, status);
2050 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2051
2052 /* corners outside, but some intersection */
2053 x = 0; w = 100;
2054 y = 0; h = 100;
2055 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2056 expect(Ok, status);
2057 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2058
2059 x = 0; w = 100;
2060 y = 0; h = 40;
2061 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2062 expect(Ok, status);
2063 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2064
2065 x = 0; w = 25;
2066 y = 0; h = 100;
2067 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2068 expect(Ok, status);
2069 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2070
2071 /* translate into the center of the rectangle */
2072 status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2073 expect(Ok, status);
2074
2075 /* native ignores the world transform, so treat these as if
2076 * no transform exists */
2077 x = 0; w = 5;
2078 y = 0; h = 5;
2079 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2080 expect(Ok, status);
2081 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2082 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2083 expect(Ok, status);
2084 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2085
2086 x = 11; w = 10;
2087 y = 12; h = 10;
2088 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2089 expect(Ok, status);
2090 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2091 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2092 expect(Ok, status);
2093 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2094
2095 /* translate back to origin */
2096 status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2097 expect(Ok, status);
2098
2099 /* region from path */
2100 status = GdipCreatePath(FillModeAlternate, &path);
2101 expect(Ok, status);
2102
2103 status = GdipAddPathEllipse(path, 10, 20, 30, 40);
2104 expect(Ok, status);
2105
2106 status = GdipCombineRegionPath(region, path, CombineModeReplace);
2107 expect(Ok, status);
2108
2109 x = 0; w = 12;
2110 y = 0; h = 22;
2111 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2112 expect(Ok, status);
2113 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2114 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2115 expect(Ok, status);
2116 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2117
2118 x = 0; w = 25;
2119 y = 0; h = 40;
2120 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2121 expect(Ok, status);
2122 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2123 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2124 expect(Ok, status);
2125 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2126
2127 x = 38; w = 10;
2128 y = 55; h = 10;
2129 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2130 expect(Ok, status);
2131 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2132 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2133 expect(Ok, status);
2134 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2135
2136 x = 0; w = 100;
2137 y = 0; h = 100;
2138 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2139 expect(Ok, status);
2140 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2141 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2142 expect(Ok, status);
2143 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2144
2145 GdipDeletePath(path);
2146
2147 GdipDeleteRegion(region);
2148 GdipDeleteGraphics(graphics);
2149 ReleaseDC(0, hdc);
2150 }
2151
2152 static void test_excludeinfinite(void)
2153 {
2154 GpStatus status;
2155 GpRegion *region;
2156 UINT count=0xdeadbeef;
2157 GpRectF scans[4];
2158 GpMatrix *identity;
2159 static const RectF rect_exclude = {0.0, 0.0, 1.0, 1.0};
2160
2161 status = GdipCreateMatrix(&identity);
2162 expect(Ok, status);
2163
2164 status = GdipCreateRegion(&region);
2165 expect(Ok, status);
2166
2167 status = GdipCombineRegionRect(region, &rect_exclude, CombineModeExclude);
2168 expect(Ok, status);
2169
2170 status = GdipGetRegionScansCount(region, &count, identity);
2171 expect(Ok, status);
2172 expect(4, count);
2173
2174 count = 4;
2175 status = GdipGetRegionScans(region, scans, (INT*)&count, identity);
2176 expect(Ok, status);
2177
2178 expectf(-4194304.0, scans[0].X);
2179 expectf(-4194304.0, scans[0].Y);
2180 expectf(8388608.0, scans[0].Width);
2181 expectf(4194304.0, scans[0].Height);
2182
2183 expectf(-4194304.0, scans[1].X);
2184 expectf(0.0, scans[1].Y);
2185 expectf(4194304.0, scans[1].Width);
2186 expectf(1.0, scans[1].Height);
2187
2188 expectf(1.0, scans[2].X);
2189 expectf(0.0, scans[2].Y);
2190 expectf(4194303.0, scans[2].Width);
2191 expectf(1.0, scans[2].Height);
2192
2193 expectf(-4194304.0, scans[3].X);
2194 expectf(1.0, scans[3].Y);
2195 expectf(8388608.0, scans[3].Width);
2196 expectf(4194303.0, scans[3].Height);
2197
2198 GdipDeleteRegion(region);
2199 GdipDeleteMatrix(identity);
2200 }
2201
2202 static void test_GdipCreateRegionRgnData(void)
2203 {
2204 GpGraphics *graphics = NULL;
2205 GpRegion *region, *region2;
2206 HDC hdc = GetDC(0);
2207 GpStatus status;
2208 BYTE buf[512];
2209 UINT needed;
2210 BOOL ret;
2211
2212 status = GdipCreateRegionRgnData(NULL, 0, NULL);
2213 ok(status == InvalidParameter, "status %d\n", status);
2214
2215 status = GdipCreateFromHDC(hdc, &graphics);
2216 ok(status == Ok, "status %d\n", status);
2217
2218 status = GdipCreateRegion(&region);
2219 ok(status == Ok, "status %d\n", status);
2220
2221 /* infinite region */
2222 memset(buf, 0xee, sizeof(buf));
2223 needed = 0;
2224 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
2225 ok(status == Ok, "status %d\n", status);
2226 expect(20, needed);
2227
2228 status = GdipCreateRegionRgnData(buf, needed, NULL);
2229 ok(status == InvalidParameter, "status %d\n", status);
2230
2231 status = GdipCreateRegionRgnData(buf, needed, &region2);
2232 ok(status == Ok, "status %d\n", status);
2233
2234 ret = FALSE;
2235 status = GdipIsInfiniteRegion(region2, graphics, &ret);
2236 ok(status == Ok, "status %d\n", status);
2237 ok(ret, "got %d\n", ret);
2238 GdipDeleteRegion(region2);
2239
2240 /* empty region */
2241 status = GdipSetEmpty(region);
2242 ok(status == Ok, "status %d\n", status);
2243
2244 memset(buf, 0xee, sizeof(buf));
2245 needed = 0;
2246 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
2247 ok(status == Ok, "status %d\n", status);
2248 expect(20, needed);
2249
2250 status = GdipCreateRegionRgnData(buf, needed, &region2);
2251 ok(status == Ok, "status %d\n", status);
2252
2253 ret = FALSE;
2254 status = GdipIsEmptyRegion(region2, graphics, &ret);
2255 ok(status == Ok, "status %d\n", status);
2256 ok(ret, "got %d\n", ret);
2257 GdipDeleteRegion(region2);
2258
2259 GdipDeleteGraphics(graphics);
2260 GdipDeleteRegion(region);
2261 ReleaseDC(0, hdc);
2262 }
2263
2264 START_TEST(region)
2265 {
2266 struct GdiplusStartupInput gdiplusStartupInput;
2267 ULONG_PTR gdiplusToken;
2268
2269 gdiplusStartupInput.GdiplusVersion = 1;
2270 gdiplusStartupInput.DebugEventCallback = NULL;
2271 gdiplusStartupInput.SuppressBackgroundThread = 0;
2272 gdiplusStartupInput.SuppressExternalCodecs = 0;
2273
2274 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2275
2276 test_getregiondata();
2277 test_isinfinite();
2278 test_isempty();
2279 test_combinereplace();
2280 test_fromhrgn();
2281 test_gethrgn();
2282 test_isequal();
2283 test_translate();
2284 test_transform();
2285 test_scans();
2286 test_getbounds();
2287 test_isvisiblepoint();
2288 test_isvisiblerect();
2289 test_excludeinfinite();
2290 test_GdipCreateRegionRgnData();
2291
2292 GdiplusShutdown(gdiplusToken);
2293 }