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