msi: Set all folders' source paths to the root directory if the source type is compre...
[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     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_getsubpathcount(void)
175 {
176     GpPath *path;
177     GpPathIterator *iter;
178     GpStatus stat;
179     INT count;
180
181     /* NULL args */
182     stat = GdipPathIterGetSubpathCount(NULL, NULL);
183     expect(InvalidParameter, stat);
184     stat = GdipPathIterGetSubpathCount(NULL, &count);
185     expect(InvalidParameter, stat);
186
187     GdipCreatePath(FillModeAlternate, &path);
188
189     /* empty path */
190     GdipCreatePathIter(&iter, path);
191     stat = GdipPathIterGetSubpathCount(iter, &count);
192     expect(Ok, stat);
193     expect(0, count);
194     GdipDeletePathIter(iter);
195
196     GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
197
198     /* open figure */
199     GdipCreatePathIter(&iter, path);
200     stat = GdipPathIterGetSubpathCount(iter, &count);
201     expect(Ok, stat);
202     expect(1, count);
203     GdipDeletePathIter(iter);
204
205     /* manually start new figure */
206     GdipStartPathFigure(path);
207     GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
208     GdipCreatePathIter(&iter, path);
209     stat = GdipPathIterGetSubpathCount(iter, &count);
210     expect(Ok, stat);
211     expect(2, count);
212     GdipDeletePathIter(iter);
213
214     GdipDeletePath(path);
215 }
216
217 START_TEST(pathiterator)
218 {
219     struct GdiplusStartupInput gdiplusStartupInput;
220     ULONG_PTR gdiplusToken;
221
222     gdiplusStartupInput.GdiplusVersion              = 1;
223     gdiplusStartupInput.DebugEventCallback          = NULL;
224     gdiplusStartupInput.SuppressBackgroundThread    = 0;
225     gdiplusStartupInput.SuppressExternalCodecs      = 0;
226
227     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
228
229     test_constructor_destructor();
230     test_hascurve();
231     test_nextmarker();
232     test_getsubpathcount();
233
234     GdiplusShutdown(gdiplusToken);
235 }