krnl386.exe16: Update a comment.
[wine/testsucceed.git] / dlls / gdiplus / tests / pathiterator.c
blob3e1c287f3263a5d0486318c1d18ffdfecb7672ac
1 /*
2 * Unit test suite for pathiterator
4 * Copyright (C) 2008 Nikolay Sivov
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.
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.
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
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wine/test.h"
25 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
27 static void test_constructor_destructor(void)
29 GpPath *path;
30 GpPathIterator *iter;
31 GpStatus stat;
33 GdipCreatePath(FillModeAlternate, &path);
34 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
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);
49 /* valid args */
50 stat = GdipCreatePathIter(&iter, path);
51 expect(Ok, stat);
53 GdipDeletePathIter(iter);
54 GdipDeletePath(path);
57 static void test_hascurve(void)
59 GpPath *path;
60 GpPathIterator *iter;
61 GpStatus stat;
62 BOOL hasCurve;
64 GdipCreatePath(FillModeAlternate, &path);
65 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
67 stat = GdipCreatePathIter(&iter, path);
68 expect(Ok, stat);
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);
76 /* valid args */
77 stat = GdipPathIterHasCurve(iter, &hasCurve);
78 expect(Ok, stat);
79 expect(FALSE, hasCurve);
81 GdipDeletePathIter(iter);
83 GdipAddPathEllipse(path, 0.0, 0.0, 35.0, 70.0);
85 stat = GdipCreatePathIter(&iter, path);
86 expect(Ok, stat);
88 stat = GdipPathIterHasCurve(iter, &hasCurve);
89 expect(Ok, stat);
90 expect(TRUE, hasCurve);
92 GdipDeletePathIter(iter);
93 GdipDeletePath(path);
96 static void test_nextmarker(void)
98 GpPath *path;
99 GpPathIterator *iter;
100 GpStatus stat;
101 INT start, end;
102 INT result;
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);
114 GdipCreatePath(FillModeAlternate, &path);
115 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
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 /* start/end remain unchanged */
128 expect((INT)0xdeadbeef, start);
129 expect((INT)0xdeadbeef, end);
130 expect(0, result);
131 GdipDeletePathIter(iter);
133 /* one marker */
134 GdipSetPathMarker(path);
135 GdipCreatePathIter(&iter, path);
136 start = end = result = (INT)0xdeadbeef;
137 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
138 expect(Ok, stat);
139 expect(0, start);
140 expect(3, end);
141 expect(4, result);
142 start = end = result = (INT)0xdeadbeef;
143 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
144 expect(Ok, stat);
145 expect((INT)0xdeadbeef, start);
146 expect((INT)0xdeadbeef, end);
147 expect(0, result);
148 GdipDeletePathIter(iter);
150 /* two markers */
151 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
152 GdipSetPathMarker(path);
153 GdipCreatePathIter(&iter, path);
154 start = end = result = (INT)0xdeadbeef;
155 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
156 expect(Ok, stat);
157 expect(0, start);
158 expect(3, end);
159 expect(4, result);
160 start = end = result = (INT)0xdeadbeef;
161 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
162 expect(Ok, stat);
163 expect(4, start);
164 expect(5, end);
165 expect(2, result);
166 start = end = result = (INT)0xdeadbeef;
167 stat = GdipPathIterNextMarker(iter, &result, &start, &end);
168 expect(Ok, stat);
169 expect((INT)0xdeadbeef, start);
170 expect((INT)0xdeadbeef, end);
171 expect(0, result);
172 GdipDeletePathIter(iter);
174 GdipDeletePath(path);
177 static void test_nextmarkerpath(void)
179 GpPath *path, *retpath;
180 GpPathIterator *iter;
181 GpStatus stat;
182 INT result, count;
184 GdipCreatePath(FillModeAlternate, &path);
186 /* NULL */
187 stat = GdipPathIterNextMarkerPath(NULL, NULL, NULL);
188 expect(InvalidParameter, stat);
189 stat = GdipPathIterNextMarkerPath(NULL, &result, NULL);
190 expect(InvalidParameter, stat);
191 stat = GdipPathIterNextMarkerPath(NULL, &result, path);
192 expect(InvalidParameter, stat);
194 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
196 /* no markers */
197 GdipCreatePath(FillModeAlternate, &retpath);
198 GdipCreatePathIter(&iter, path);
199 result = -1;
200 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
201 expect(Ok, stat);
202 expect(4, result);
203 count = -1;
204 GdipGetPointCount(retpath, &count);
205 expect(4, count);
206 result = -1;
207 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
208 expect(Ok, stat);
209 expect(0, result);
210 count = -1;
211 GdipGetPointCount(retpath, &count);
212 expect(4, count);
213 GdipDeletePathIter(iter);
214 GdipDeletePath(retpath);
216 /* one marker */
217 GdipSetPathMarker(path);
218 GdipCreatePath(FillModeAlternate, &retpath);
219 GdipCreatePathIter(&iter, path);
220 result = -1;
221 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
222 expect(Ok, stat);
223 expect(4, result);
224 count = -1;
225 GdipGetPointCount(retpath, &count);
226 expect(4, count);
227 result = -1;
228 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
229 expect(Ok, stat);
230 expect(0, result);
231 count = -1;
232 GdipGetPointCount(retpath, &count);
233 expect(4, count);
234 GdipDeletePathIter(iter);
235 GdipDeletePath(retpath);
237 /* two markers */
238 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
239 GdipSetPathMarker(path);
240 GdipCreatePath(FillModeAlternate, &retpath);
241 GdipCreatePathIter(&iter, path);
242 result = -1;
243 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
244 expect(Ok, stat);
245 expect(4, result);
246 result = -1;
247 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
248 expect(Ok, stat);
249 expect(2, result);
250 result = -1;
251 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
252 expect(Ok, stat);
253 expect(0, result);
254 GdipDeletePathIter(iter);
255 GdipDeletePath(retpath);
257 GdipDeletePath(path);
260 static void test_getsubpathcount(void)
262 GpPath *path;
263 GpPathIterator *iter;
264 GpStatus stat;
265 INT count;
267 /* NULL args */
268 stat = GdipPathIterGetSubpathCount(NULL, NULL);
269 expect(InvalidParameter, stat);
270 stat = GdipPathIterGetSubpathCount(NULL, &count);
271 expect(InvalidParameter, stat);
273 GdipCreatePath(FillModeAlternate, &path);
275 /* empty path */
276 GdipCreatePathIter(&iter, path);
277 stat = GdipPathIterGetSubpathCount(iter, &count);
278 expect(Ok, stat);
279 expect(0, count);
280 GdipDeletePathIter(iter);
282 GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
284 /* open figure */
285 GdipCreatePathIter(&iter, path);
286 stat = GdipPathIterGetSubpathCount(iter, &count);
287 expect(Ok, stat);
288 expect(1, count);
289 GdipDeletePathIter(iter);
291 /* manually start new figure */
292 GdipStartPathFigure(path);
293 GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
294 GdipCreatePathIter(&iter, path);
295 stat = GdipPathIterGetSubpathCount(iter, &count);
296 expect(Ok, stat);
297 expect(2, count);
298 GdipDeletePathIter(iter);
300 GdipDeletePath(path);
303 static void test_isvalid(void)
305 GpPath *path;
306 GpPathIterator *iter;
307 GpStatus stat;
308 BOOL isvalid;
309 INT start, end, result;
311 GdipCreatePath(FillModeAlternate, &path);
313 /* NULL args */
314 GdipCreatePathIter(&iter, path);
315 stat = GdipPathIterIsValid(NULL, NULL);
316 expect(InvalidParameter, stat);
317 stat = GdipPathIterIsValid(iter, NULL);
318 expect(InvalidParameter, stat);
319 stat = GdipPathIterIsValid(NULL, &isvalid);
320 expect(InvalidParameter, stat);
321 GdipDeletePathIter(iter);
323 /* on empty path */
324 GdipCreatePathIter(&iter, path);
325 isvalid = FALSE;
326 stat = GdipPathIterIsValid(iter, &isvalid);
327 expect(Ok, stat);
328 expect(TRUE, isvalid);
329 GdipDeletePathIter(iter);
331 /* no markers */
332 GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
333 GdipCreatePathIter(&iter, path);
334 GdipPathIterNextMarker(iter, &result, &start, &end);
335 isvalid = FALSE;
336 stat = GdipPathIterIsValid(iter, &isvalid);
337 expect(Ok, stat);
338 expect(TRUE, isvalid);
339 GdipDeletePathIter(iter);
341 GdipDeletePath(path);
344 static void test_nextsubpathpath(void)
346 GpPath *path, *retpath;
347 GpPathIterator *iter;
348 GpStatus stat;
349 BOOL closed;
350 INT count, result;
352 GdipCreatePath(FillModeAlternate, &path);
354 /* NULL args */
355 GdipCreatePath(FillModeAlternate, &retpath);
356 GdipCreatePathIter(&iter, path);
357 stat = GdipPathIterNextSubpathPath(NULL, NULL, NULL, NULL);
358 expect(InvalidParameter, stat);
359 stat = GdipPathIterNextSubpathPath(iter, NULL, NULL, NULL);
360 expect(InvalidParameter, stat);
361 stat = GdipPathIterNextSubpathPath(NULL, &result, NULL, NULL);
362 expect(InvalidParameter, stat);
363 stat = GdipPathIterNextSubpathPath(iter, &result, NULL, &closed);
364 expect(Ok, stat);
365 stat = GdipPathIterNextSubpathPath(iter, NULL, NULL, &closed);
366 expect(InvalidParameter, stat);
367 stat = GdipPathIterNextSubpathPath(iter, NULL, retpath, NULL);
368 expect(InvalidParameter, stat);
369 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, NULL);
370 expect(InvalidParameter, stat);
371 GdipDeletePathIter(iter);
372 GdipDeletePath(retpath);
374 /* empty path */
375 GdipCreatePath(FillModeAlternate, &retpath);
376 GdipCreatePathIter(&iter, path);
377 result = -2;
378 closed = TRUE;
379 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
380 expect(Ok, stat);
381 expect(0, result);
382 expect(TRUE, closed);
383 count = -1;
384 GdipGetPointCount(retpath, &count);
385 expect(0, count);
386 GdipDeletePathIter(iter);
387 GdipDeletePath(retpath);
389 /* open figure */
390 GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
392 GdipCreatePath(FillModeAlternate, &retpath);
393 GdipCreatePathIter(&iter, path);
394 result = -2;
395 closed = TRUE;
396 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
397 expect(Ok, stat);
398 expect(2, result);
399 expect(FALSE, closed);
400 count = -1;
401 GdipGetPointCount(retpath, &count);
402 expect(2, count);
403 /* subsequent call */
404 result = -2;
405 closed = TRUE;
406 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
407 expect(Ok, stat);
408 expect(0, result);
409 expect(TRUE, closed);
410 count = -1;
411 GdipGetPointCount(retpath, &count);
412 expect(2, count);
413 GdipDeletePathIter(iter);
415 /* closed figure, check does it extend retpath or reset it */
416 GdipAddPathLine(retpath, 50.0, 55.0, 200.0, 150.0);
418 GdipClosePathFigure(path);
419 GdipAddPathLine(path, 50.0, 55.0, 200.0, 150.0);
420 GdipClosePathFigure(path);
422 GdipCreatePathIter(&iter, path);
423 result = -2;
424 closed = FALSE;
425 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
426 expect(Ok, stat);
427 expect(2, result);
428 expect(TRUE, closed);
429 count = -1;
430 GdipGetPointCount(retpath, &count);
431 expect(2, count);
432 /* subsequent call */
433 result = -2;
434 closed = FALSE;
435 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
436 expect(Ok, stat);
437 expect(2, result);
438 expect(TRUE, closed);
439 count = -1;
440 GdipGetPointCount(retpath, &count);
441 expect(2, count);
442 result = -2;
443 closed = FALSE;
444 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
445 expect(Ok, stat);
446 expect(0, result);
447 expect(TRUE, closed);
448 count = -1;
449 GdipGetPointCount(retpath, &count);
450 expect(2, count);
451 GdipDeletePathIter(iter);
453 GdipDeletePath(retpath);
454 GdipDeletePath(path);
457 static void test_nextsubpath(void)
459 GpPath *path;
460 GpPathIterator *iter;
461 GpStatus stat;
462 INT start, end, result;
463 BOOL closed;
465 /* empty path */
466 GdipCreatePath(FillModeAlternate, &path);
467 GdipCreatePathIter(&iter, path);
469 result = -2;
470 closed = TRUE;
471 stat = GdipPathIterNextSubpath(iter, &result, &start, &end, &closed);
472 expect(Ok, stat);
473 expect(0, result);
474 expect(TRUE, closed);
476 GdipDeletePathIter(iter);
477 GdipDeletePath(path);
480 static void test_nextpathtype(void)
482 GpPath *path;
483 GpPathIterator *iter;
484 GpStatus stat;
485 INT start, end, result;
486 BYTE type;
488 GdipCreatePath(FillModeAlternate, &path);
489 GdipCreatePathIter(&iter, path);
491 /* NULL arguments */
492 stat = GdipPathIterNextPathType(NULL, NULL, NULL, NULL, NULL);
493 expect(InvalidParameter, stat);
494 stat = GdipPathIterNextPathType(iter, NULL, NULL, NULL, NULL);
495 expect(InvalidParameter, stat);
496 stat = GdipPathIterNextPathType(iter, &result, NULL, NULL, NULL);
497 expect(InvalidParameter, stat);
498 stat = GdipPathIterNextPathType(iter, NULL, &type, NULL, NULL);
499 expect(InvalidParameter, stat);
500 stat = GdipPathIterNextPathType(iter, NULL, NULL, &start, &end);
501 expect(InvalidParameter, stat);
502 stat = GdipPathIterNextPathType(iter, NULL, &type, &start, &end);
503 expect(InvalidParameter, stat);
504 stat = GdipPathIterNextPathType(iter, &result, &type, NULL, NULL);
505 expect(InvalidParameter, stat);
507 /* empty path */
508 start = end = result = (INT)0xdeadbeef;
509 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
510 todo_wine expect(Ok, stat);
511 expect((INT)0xdeadbeef, start);
512 expect((INT)0xdeadbeef, end);
513 todo_wine expect(0, result);
514 GdipDeletePathIter(iter);
516 /* single figure */
517 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
518 GdipCreatePathIter(&iter, path);
519 start = end = result = (INT)0xdeadbeef;
520 type = 255; /* out of range */
521 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
522 todo_wine expect(Ok, stat);
523 expect((INT)0xdeadbeef, start);
524 expect((INT)0xdeadbeef, end);
525 expect(255, type);
526 todo_wine expect(0, result);
527 GdipDeletePathIter(iter);
529 GdipAddPathEllipse(path, 0.0, 0.0, 35.0, 70.0);
530 GdipCreatePathIter(&iter, path);
531 start = end = result = (INT)0xdeadbeef;
532 type = 255; /* out of range */
533 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
534 todo_wine expect(Ok, stat);
535 expect((INT)0xdeadbeef, start);
536 expect((INT)0xdeadbeef, end);
537 expect(255, type);
538 todo_wine expect(0, result);
539 GdipDeletePathIter(iter);
541 /* closed */
542 GdipClosePathFigure(path);
543 GdipCreatePathIter(&iter, path);
544 start = end = result = (INT)0xdeadbeef;
545 type = 255; /* out of range */
546 stat = GdipPathIterNextPathType(iter, &result, &type, &start, &end);
547 todo_wine expect(Ok, stat);
548 expect((INT)0xdeadbeef, start);
549 expect((INT)0xdeadbeef, end);
550 expect(255, type);
551 todo_wine expect(0, result);
552 GdipDeletePathIter(iter);
554 GdipDeletePath(path);
557 START_TEST(pathiterator)
559 struct GdiplusStartupInput gdiplusStartupInput;
560 ULONG_PTR gdiplusToken;
562 gdiplusStartupInput.GdiplusVersion = 1;
563 gdiplusStartupInput.DebugEventCallback = NULL;
564 gdiplusStartupInput.SuppressBackgroundThread = 0;
565 gdiplusStartupInput.SuppressExternalCodecs = 0;
567 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
569 test_constructor_destructor();
570 test_hascurve();
571 test_nextmarker();
572 test_nextmarkerpath();
573 test_getsubpathcount();
574 test_isvalid();
575 test_nextsubpathpath();
576 test_nextsubpath();
577 test_nextpathtype();
579 GdiplusShutdown(gdiplusToken);