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