- Sync gdiplus wine tests
[reactos.git] / rostests / winetests / gdiplus / pathiterator.c
1 /*
2 * Unit test suite for pathiterator
3 *
4 * Copyright (C) 2008 Nikolay Sivov
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wine/test.h"
24
25 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
26
27 static void test_constructor_destructor(void)
28 {
29 GpPath *path;
30 GpPathIterator *iter;
31 GpStatus stat;
32
33 GdipCreatePath(FillModeAlternate, &path);
34 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
35
36 /* NULL args */
37 stat = GdipCreatePathIter(NULL, NULL);
38 expect(InvalidParameter, stat);
39 stat = GdipCreatePathIter(&iter, NULL);
40 expect(Ok, stat);
41 stat = GdipCreatePathIter(NULL, path);
42 expect(InvalidParameter, stat);
43 stat = GdipDeletePathIter(NULL);
44 expect(InvalidParameter, stat);
45
46 /* valid args */
47 stat = GdipCreatePathIter(&iter, path);
48 expect(Ok, stat);
49
50 GdipDeletePathIter(iter);
51 GdipDeletePath(path);
52 }
53
54 static void test_hascurve(void)
55 {
56 GpPath *path;
57 GpPathIterator *iter;
58 GpStatus stat;
59 BOOL hasCurve;
60
61 GdipCreatePath(FillModeAlternate, &path);
62 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
63
64 stat = GdipCreatePathIter(&iter, path);
65 expect(Ok, stat);
66
67 /* NULL args
68 BOOL out argument is local in wrapper class method,
69 so it always has not-NULL address */
70 stat = GdipPathIterHasCurve(NULL, &hasCurve);
71 expect(InvalidParameter, stat);
72
73 /* valid args */
74 stat = GdipPathIterHasCurve(iter, &hasCurve);
75 expect(Ok, stat);
76 expect(FALSE, hasCurve);
77
78 GdipDeletePathIter(iter);
79
80 GdipAddPathEllipse(path, 0.0, 0.0, 35.0, 70.0);
81
82 stat = GdipCreatePathIter(&iter, path);
83 expect(Ok, stat);
84
85 stat = GdipPathIterHasCurve(iter, &hasCurve);
86 expect(Ok, stat);
87 expect(TRUE, hasCurve);
88
89 GdipDeletePathIter(iter);
90 GdipDeletePath(path);
91 }
92
93 static void test_nextmarker(void)
94 {
95 GpPath *path;
96 GpPathIterator *iter;
97 GpStatus stat;
98 INT start, end;
99 INT result;
100
101 /* NULL args
102 BOOL out argument is local in wrapper class method,
103 so it always has not-NULL address */
104 stat = GdipPathIterNextMarker(NULL, &result, NULL, NULL);
105 expect(InvalidParameter, stat);
106 stat = GdipPathIterNextMarker(NULL, &result, &start, NULL);
107 expect(InvalidParameter, stat);
108 stat = GdipPathIterNextMarker(NULL, &result, NULL, &end);
109 expect(InvalidParameter, stat);
110
111 GdipCreatePath(FillModeAlternate, &path);
112 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
113
114 /* no markers */
115 GdipCreatePathIter(&iter, path);
116 start = end = result = (INT)0xdeadbeef;
117 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
118 expect(Ok, stat);
119 expect(0, start);
120 expect(3, end);
121 expect(4, result);
122 start = end = result = (INT)0xdeadbeef;
123 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
124 /* start/end remain unchanged */
125 expect((INT)0xdeadbeef, start);
126 expect((INT)0xdeadbeef, end);
127 expect(0, result);
128 GdipDeletePathIter(iter);
129
130 /* one marker */
131 GdipSetPathMarker(path);
132 GdipCreatePathIter(&iter, path);
133 start = end = result = (INT)0xdeadbeef;
134 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
135 expect(Ok, stat);
136 expect(0, start);
137 expect(3, end);
138 expect(4, result);
139 start = end = result = (INT)0xdeadbeef;
140 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
141 expect(Ok, stat);
142 expect((INT)0xdeadbeef, start);
143 expect((INT)0xdeadbeef, end);
144 expect(0, result);
145 GdipDeletePathIter(iter);
146
147 /* two markers */
148 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
149 GdipSetPathMarker(path);
150 GdipCreatePathIter(&iter, path);
151 start = end = result = (INT)0xdeadbeef;
152 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
153 expect(Ok, stat);
154 expect(0, start);
155 expect(3, end);
156 expect(4, result);
157 start = end = result = (INT)0xdeadbeef;
158 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
159 expect(Ok, stat);
160 expect(4, start);
161 expect(5, end);
162 expect(2, result);
163 start = end = result = (INT)0xdeadbeef;
164 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
165 expect(Ok, stat);
166 expect((INT)0xdeadbeef, start);
167 expect((INT)0xdeadbeef, end);
168 expect(0, result);
169 GdipDeletePathIter(iter);
170
171 GdipDeletePath(path);
172 }
173
174 static void test_nextmarkerpath(void)
175 {
176 GpPath *path, *retpath;
177 GpPathIterator *iter;
178 GpStatus stat;
179 INT result, count;
180
181 GdipCreatePath(FillModeAlternate, &path);
182
183 /* NULL */
184 stat = GdipPathIterNextMarkerPath(NULL, NULL, NULL);
185 expect(InvalidParameter, stat);
186 stat = GdipPathIterNextMarkerPath(NULL, &result, NULL);
187 expect(InvalidParameter, stat);
188 stat = GdipPathIterNextMarkerPath(NULL, &result, path);
189 expect(InvalidParameter, stat);
190
191 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
192
193 /* no markers */
194 GdipCreatePath(FillModeAlternate, &retpath);
195 GdipCreatePathIter(&iter, path);
196 result = -1;
197 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
198 expect(Ok, stat);
199 expect(4, result);
200 count = -1;
201 GdipGetPointCount(retpath, &count);
202 expect(4, count);
203 result = -1;
204 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
205 expect(Ok, stat);
206 expect(0, result);
207 count = -1;
208 GdipGetPointCount(retpath, &count);
209 expect(4, count);
210 GdipDeletePathIter(iter);
211 GdipDeletePath(retpath);
212
213 /* one marker */
214 GdipSetPathMarker(path);
215 GdipCreatePath(FillModeAlternate, &retpath);
216 GdipCreatePathIter(&iter, path);
217 result = -1;
218 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
219 expect(Ok, stat);
220 expect(4, result);
221 count = -1;
222 GdipGetPointCount(retpath, &count);
223 expect(4, count);
224 result = -1;
225 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
226 expect(Ok, stat);
227 expect(0, result);
228 count = -1;
229 GdipGetPointCount(retpath, &count);
230 expect(4, count);
231 GdipDeletePathIter(iter);
232 GdipDeletePath(retpath);
233
234 /* two markers */
235 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
236 GdipSetPathMarker(path);
237 GdipCreatePath(FillModeAlternate, &retpath);
238 GdipCreatePathIter(&iter, path);
239 result = -1;
240 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
241 expect(Ok, stat);
242 expect(4, result);
243 result = -1;
244 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
245 expect(Ok, stat);
246 expect(2, result);
247 result = -1;
248 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
249 expect(Ok, stat);
250 expect(0, result);
251 GdipDeletePathIter(iter);
252 GdipDeletePath(retpath);
253
254 GdipDeletePath(path);
255 }
256
257 static void test_getsubpathcount(void)
258 {
259 GpPath *path;
260 GpPathIterator *iter;
261 GpStatus stat;
262 INT count;
263
264 /* NULL args */
265 stat = GdipPathIterGetSubpathCount(NULL, NULL);
266 expect(InvalidParameter, stat);
267 stat = GdipPathIterGetSubpathCount(NULL, &count);
268 expect(InvalidParameter, stat);
269
270 GdipCreatePath(FillModeAlternate, &path);
271
272 /* empty path */
273 GdipCreatePathIter(&iter, path);
274 stat = GdipPathIterGetSubpathCount(iter, &count);
275 expect(Ok, stat);
276 expect(0, count);
277 GdipDeletePathIter(iter);
278
279 GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
280
281 /* open figure */
282 GdipCreatePathIter(&iter, path);
283 stat = GdipPathIterGetSubpathCount(iter, &count);
284 expect(Ok, stat);
285 expect(1, count);
286 GdipDeletePathIter(iter);
287
288 /* manually start new figure */
289 GdipStartPathFigure(path);
290 GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
291 GdipCreatePathIter(&iter, path);
292 stat = GdipPathIterGetSubpathCount(iter, &count);
293 expect(Ok, stat);
294 expect(2, count);
295 GdipDeletePathIter(iter);
296
297 GdipDeletePath(path);
298 }
299
300 static void test_isvalid(void)
301 {
302 GpPath *path;
303 GpPathIterator *iter;
304 GpStatus stat;
305 BOOL isvalid;
306 INT start, end, result;
307
308 GdipCreatePath(FillModeAlternate, &path);
309
310 /* NULL args */
311 GdipCreatePathIter(&iter, path);
312 stat = GdipPathIterIsValid(NULL, NULL);
313 expect(InvalidParameter, stat);
314 stat = GdipPathIterIsValid(iter, NULL);
315 expect(InvalidParameter, stat);
316 stat = GdipPathIterIsValid(NULL, &isvalid);
317 expect(InvalidParameter, stat);
318 GdipDeletePathIter(iter);
319
320 /* on empty path */
321 GdipCreatePathIter(&iter, path);
322 isvalid = FALSE;
323 stat = GdipPathIterIsValid(iter, &isvalid);
324 expect(Ok, stat);
325 expect(TRUE, isvalid);
326 GdipDeletePathIter(iter);
327
328 /* no markers */
329 GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
330 GdipCreatePathIter(&iter, path);
331 GdipPathIterNextMarker(iter, &result, &start, &end);
332 isvalid = FALSE;
333 stat = GdipPathIterIsValid(iter, &isvalid);
334 expect(Ok, stat);
335 expect(TRUE, isvalid);
336 GdipDeletePathIter(iter);
337
338 GdipDeletePath(path);
339 }
340
341 static void test_nextsubpathpath(void)
342 {
343 GpPath *path, *retpath;
344 GpPathIterator *iter;
345 GpStatus stat;
346 BOOL closed;
347 INT count, result;
348
349 GdipCreatePath(FillModeAlternate, &path);
350
351 /* NULL args */
352 GdipCreatePath(FillModeAlternate, &retpath);
353 GdipCreatePathIter(&iter, path);
354 stat = GdipPathIterNextSubpathPath(NULL, NULL, NULL, NULL);
355 expect(InvalidParameter, stat);
356 stat = GdipPathIterNextSubpathPath(iter, NULL, NULL, NULL);
357 expect(InvalidParameter, stat);
358 stat = GdipPathIterNextSubpathPath(NULL, &result, NULL, NULL);
359 expect(InvalidParameter, stat);
360 stat = GdipPathIterNextSubpathPath(iter, &result, NULL, &closed);
361 expect(Ok, stat);
362 stat = GdipPathIterNextSubpathPath(iter, NULL, NULL, &closed);
363 expect(InvalidParameter, stat);
364 stat = GdipPathIterNextSubpathPath(iter, NULL, retpath, NULL);
365 expect(InvalidParameter, stat);
366 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, NULL);
367 expect(InvalidParameter, stat);
368 GdipDeletePathIter(iter);
369 GdipDeletePath(retpath);
370
371 /* empty path */
372 GdipCreatePath(FillModeAlternate, &retpath);
373 GdipCreatePathIter(&iter, path);
374 result = -2;
375 closed = TRUE;
376 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
377 expect(Ok, stat);
378 expect(0, result);
379 expect(TRUE, closed);
380 count = -1;
381 GdipGetPointCount(retpath, &count);
382 expect(0, count);
383 GdipDeletePathIter(iter);
384 GdipDeletePath(retpath);
385
386 /* open figure */
387 GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
388
389 GdipCreatePath(FillModeAlternate, &retpath);
390 GdipCreatePathIter(&iter, path);
391 result = -2;
392 closed = TRUE;
393 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
394 expect(Ok, stat);
395 expect(2, result);
396 expect(FALSE, closed);
397 count = -1;
398 GdipGetPointCount(retpath, &count);
399 expect(2, count);
400 /* subsequent call */
401 result = -2;
402 closed = TRUE;
403 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
404 expect(Ok, stat);
405 expect(0, result);
406 expect(TRUE, closed);
407 count = -1;
408 GdipGetPointCount(retpath, &count);
409 expect(2, count);
410 GdipDeletePathIter(iter);
411
412 /* closed figure, check does it extend retpath or reset it */
413 GdipAddPathLine(retpath, 50.0, 55.0, 200.0, 150.0);
414
415 GdipClosePathFigure(path);
416 GdipAddPathLine(path, 50.0, 55.0, 200.0, 150.0);
417 GdipClosePathFigure(path);
418
419 GdipCreatePathIter(&iter, path);
420 result = -2;
421 closed = FALSE;
422 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
423 expect(Ok, stat);
424 expect(2, result);
425 expect(TRUE, closed);
426 count = -1;
427 GdipGetPointCount(retpath, &count);
428 expect(2, count);
429 /* subsequent call */
430 result = -2;
431 closed = FALSE;
432 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
433 expect(Ok, stat);
434 expect(2, result);
435 expect(TRUE, closed);
436 count = -1;
437 GdipGetPointCount(retpath, &count);
438 expect(2, count);
439 result = -2;
440 closed = FALSE;
441 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
442 expect(Ok, stat);
443 expect(0, result);
444 expect(TRUE, closed);
445 count = -1;
446 GdipGetPointCount(retpath, &count);
447 expect(2, count);
448 GdipDeletePathIter(iter);
449
450 GdipDeletePath(retpath);
451 GdipDeletePath(path);
452 }
453
454 static void test_nextsubpath(void)
455 {
456 GpPath *path;
457 GpPathIterator *iter;
458 GpStatus stat;
459 INT start, end, result;
460 BOOL closed;
461
462 /* empty path */
463 GdipCreatePath(FillModeAlternate, &path);
464 GdipCreatePathIter(&iter, path);
465
466 result = -2;
467 closed = TRUE;
468 stat = GdipPathIterNextSubpath(iter, &result, &start, &end, &closed);
469 expect(Ok, stat);
470 expect(0, result);
471 expect(TRUE, closed);
472
473 GdipDeletePathIter(iter);
474 GdipDeletePath(path);
475 }
476
477 static void test_nextpathtype(void)
478 {
479 GpPath *path;
480 GpPathIterator *iter;
481 GpStatus stat;
482 INT start, end, result;
483 BYTE type;
484
485 GdipCreatePath(FillModeAlternate, &path);
486 GdipCreatePathIter(&iter, path);
487
488 /* NULL arguments */
489 stat = GdipPathIterNextPathType(NULL, NULL, NULL, NULL, NULL);
490 expect(InvalidParameter, stat);
491 stat = GdipPathIterNextPathType(iter, NULL, NULL, NULL, NULL);
492 expect(InvalidParameter, stat);
493 stat = GdipPathIterNextPathType(iter, &result, NULL, NULL, NULL);
494 expect(InvalidParameter, stat);
495 stat = GdipPathIterNextPathType(iter, NULL, &type, NULL, NULL);
496 expect(InvalidParameter, stat);
497 stat = GdipPathIterNextPathType(iter, NULL, NULL, &start, &end);
498 expect(InvalidParameter, stat);
499 stat = GdipPathIterNextPathType(iter, NULL, &type, &start, &end);
500 expect(InvalidParameter, stat);
501 stat = GdipPathIterNextPathType(iter, &result, &type, NULL, NULL);
502 expect(InvalidParameter, stat);
503
504 /* empty path */
505 start = end = result = (INT)0xdeadbeef;
506 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
507 todo_wine expect(Ok, stat);
508 expect((INT)0xdeadbeef, start);
509 expect((INT)0xdeadbeef, end);
510 todo_wine expect(0, result);
511 GdipDeletePathIter(iter);
512
513 /* single figure */
514 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
515 GdipCreatePathIter(&iter, path);
516 start = end = result = (INT)0xdeadbeef;
517 type = 255; /* out of range */
518 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
519 todo_wine expect(Ok, stat);
520 expect((INT)0xdeadbeef, start);
521 expect((INT)0xdeadbeef, end);
522 expect(255, type);
523 todo_wine expect(0, result);
524 GdipDeletePathIter(iter);
525
526 GdipAddPathEllipse(path, 0.0, 0.0, 35.0, 70.0);
527 GdipCreatePathIter(&iter, path);
528 start = end = result = (INT)0xdeadbeef;
529 type = 255; /* out of range */
530 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
531 todo_wine expect(Ok, stat);
532 expect((INT)0xdeadbeef, start);
533 expect((INT)0xdeadbeef, end);
534 expect(255, type);
535 todo_wine expect(0, result);
536 GdipDeletePathIter(iter);
537
538 /* closed */
539 GdipClosePathFigure(path);
540 GdipCreatePathIter(&iter, path);
541 start = end = result = (INT)0xdeadbeef;
542 type = 255; /* out of range */
543 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
544 todo_wine expect(Ok, stat);
545 expect((INT)0xdeadbeef, start);
546 expect((INT)0xdeadbeef, end);
547 expect(255, type);
548 todo_wine expect(0, result);
549 GdipDeletePathIter(iter);
550
551 GdipDeletePath(path);
552 }
553
554 START_TEST(pathiterator)
555 {
556 struct GdiplusStartupInput gdiplusStartupInput;
557 ULONG_PTR gdiplusToken;
558
559 gdiplusStartupInput.GdiplusVersion = 1;
560 gdiplusStartupInput.DebugEventCallback = NULL;
561 gdiplusStartupInput.SuppressBackgroundThread = 0;
562 gdiplusStartupInput.SuppressExternalCodecs = 0;
563
564 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
565
566 test_constructor_destructor();
567 test_hascurve();
568 test_nextmarker();
569 test_nextmarkerpath();
570 test_getsubpathcount();
571 test_isvalid();
572 test_nextsubpathpath();
573 test_nextsubpath();
574 test_nextpathtype();
575
576 GdiplusShutdown(gdiplusToken);
577 }