wined3d: texturefactor-> fragment states.
[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(InvalidParameter, 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, result;
99
100     /* NULL args
101        BOOL out argument is local in wrapper class method,
102        so it always has not-NULL address */
103     stat = GdipPathIterNextMarker(NULL, &result, NULL, NULL);
104     expect(InvalidParameter, stat);
105     stat = GdipPathIterNextMarker(NULL, &result, &start, NULL);
106     expect(InvalidParameter, stat);
107     stat = GdipPathIterNextMarker(NULL, &result, NULL, &end);
108     expect(InvalidParameter, stat);
109
110     GdipCreatePath(FillModeAlternate, &path);
111     GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
112
113     /* no markers */
114     GdipCreatePathIter(&iter, path);
115     stat = GdipPathIterNextMarker(iter, &result, &start, &end);
116     expect(Ok, stat);
117     expect(0, result);
118     GdipDeletePathIter(iter);
119
120     /* one marker */
121     GdipSetPathMarker(path);
122     GdipCreatePathIter(&iter, path);
123     stat = GdipPathIterNextMarker(iter, &result, &start, &end);
124     expect(Ok, stat);
125     expect(TRUE, (start == 0) && (end == 3) && (result == 4));
126     stat = GdipPathIterNextMarker(iter, &result, &start, &end);
127     expect(Ok, stat);
128     expect(0, result);
129     GdipDeletePathIter(iter);
130
131     /* two markers */
132     GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
133     GdipSetPathMarker(path);
134     GdipCreatePathIter(&iter, path);
135     stat = GdipPathIterNextMarker(iter, &result, &start, &end);
136     expect(Ok, stat);
137     expect(TRUE, (start == 0) && (end == 3) && (result == 4));
138     stat = GdipPathIterNextMarker(iter, &result, &start, &end);
139     expect(Ok, stat);
140     expect(TRUE, (start == 4) && (end == 5) && (result == 2));
141     stat = GdipPathIterNextMarker(iter, &result, &start, &end);
142     expect(Ok, stat);
143     expect(0, result);
144     GdipDeletePathIter(iter);
145
146     GdipDeletePath(path);
147 }
148
149 static void test_getsubpathcount(void)
150 {
151     GpPath *path;
152     GpPathIterator *iter;
153     GpStatus stat;
154     INT count;
155
156     /* NULL args */
157     stat = GdipPathIterGetSubpathCount(NULL, NULL);
158     expect(InvalidParameter, stat);
159     stat = GdipPathIterGetSubpathCount(NULL, &count);
160     expect(InvalidParameter, stat);
161
162     GdipCreatePath(FillModeAlternate, &path);
163
164     /* empty path */
165     GdipCreatePathIter(&iter, path);
166     stat = GdipPathIterGetSubpathCount(iter, &count);
167     expect(Ok, stat);
168     expect(0, count);
169     GdipDeletePathIter(iter);
170
171     GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
172
173     /* open figure */
174     GdipCreatePathIter(&iter, path);
175     stat = GdipPathIterGetSubpathCount(iter, &count);
176     expect(Ok, stat);
177     expect(1, count);
178     GdipDeletePathIter(iter);
179
180     /* manually start new figure */
181     GdipStartPathFigure(path);
182     GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
183     GdipCreatePathIter(&iter, path);
184     stat = GdipPathIterGetSubpathCount(iter, &count);
185     expect(Ok, stat);
186     expect(2, count);
187     GdipDeletePathIter(iter);
188
189     GdipDeletePath(path);
190 }
191
192 START_TEST(pathiterator)
193 {
194     struct GdiplusStartupInput gdiplusStartupInput;
195     ULONG_PTR gdiplusToken;
196
197     gdiplusStartupInput.GdiplusVersion              = 1;
198     gdiplusStartupInput.DebugEventCallback          = NULL;
199     gdiplusStartupInput.SuppressBackgroundThread    = 0;
200     gdiplusStartupInput.SuppressExternalCodecs      = 0;
201
202     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
203
204     test_constructor_destructor();
205     test_hascurve();
206     test_nextmarker();
207     test_getsubpathcount();
208
209     GdiplusShutdown(gdiplusToken);
210 }