ReactOS 0.4.15-dev-7918-g2a2556c
pathiterator.c
Go to the documentation of this file.
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 "objbase.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
28{
29 GpPath *path;
30 GpPathIterator *iter;
32
34 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
35
36 /* NULL args */
39 iter = NULL;
41 expect(Ok, stat);
42 ok(iter != NULL, "Expected iterator to be created\n");
48
49 /* valid args */
51 expect(Ok, stat);
52
55}
56
57static void test_hascurve(void)
58{
59 GpPath *path;
60 GpPathIterator *iter;
62 BOOL hasCurve;
63
65 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
66
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);
75
76 /* valid args */
77 stat = GdipPathIterHasCurve(iter, &hasCurve);
78 expect(Ok, stat);
79 expect(FALSE, hasCurve);
80
82
83 stat = GdipAddPathEllipse(path, 0.0, 0.0, 35.0, 70.0);
84 expect(Ok, stat);
85
87 expect(Ok, stat);
88
89 stat = GdipPathIterHasCurve(iter, &hasCurve);
90 expect(Ok, stat);
91 expect(TRUE, hasCurve);
92
95}
96
97static void test_nextmarker(void)
98{
99 GpPath *path;
100 GpPathIterator *iter;
102 INT start, end;
103 INT result;
104
105 /* NULL args
106 BOOL out argument is local in wrapper class method,
107 so it always has not-NULL address */
114
116 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
117
118 /* no markers */
119 GdipCreatePathIter(&iter, path);
120 start = end = result = (INT)0xdeadbeef;
122 expect(Ok, stat);
123 expect(0, start);
124 expect(3, end);
125 expect(4, result);
126 start = end = result = (INT)0xdeadbeef;
128 expect(Ok, stat);
129 /* start/end remain unchanged */
130 expect((INT)0xdeadbeef, start);
131 expect((INT)0xdeadbeef, end);
132 expect(0, result);
133 GdipDeletePathIter(iter);
134
135 /* one marker */
137 GdipCreatePathIter(&iter, path);
138 start = end = result = (INT)0xdeadbeef;
140 expect(Ok, stat);
141 expect(0, start);
142 expect(3, end);
143 expect(4, result);
144 start = end = result = (INT)0xdeadbeef;
146 expect(Ok, stat);
147 expect((INT)0xdeadbeef, start);
148 expect((INT)0xdeadbeef, end);
149 expect(0, result);
150 GdipDeletePathIter(iter);
151
152 /* two markers */
153 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
155 GdipCreatePathIter(&iter, path);
156 start = end = result = (INT)0xdeadbeef;
158 expect(Ok, stat);
159 expect(0, start);
160 expect(3, end);
161 expect(4, result);
162 start = end = result = (INT)0xdeadbeef;
164 expect(Ok, stat);
165 expect(4, start);
166 expect(5, end);
167 expect(2, result);
168 start = end = result = (INT)0xdeadbeef;
170 expect(Ok, stat);
171 expect((INT)0xdeadbeef, start);
172 expect((INT)0xdeadbeef, end);
173 expect(0, result);
174 GdipDeletePathIter(iter);
175
177}
178
179static void test_nextmarkerpath(void)
180{
181 GpPath *path, *retpath;
182 GpPathIterator *iter;
185
187
188 /* NULL */
195
196 GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
197
198 /* no markers */
200 GdipCreatePathIter(&iter, path);
201 result = -1;
202 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
203 expect(Ok, stat);
204 expect(4, result);
205 count = -1;
206 GdipGetPointCount(retpath, &count);
207 expect(4, count);
208 result = -1;
209 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
210 expect(Ok, stat);
211 expect(0, result);
212 count = -1;
213 GdipGetPointCount(retpath, &count);
214 expect(4, count);
215 GdipDeletePathIter(iter);
216 GdipDeletePath(retpath);
217
218 /* one marker */
221 GdipCreatePathIter(&iter, path);
222 result = -1;
223 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
224 expect(Ok, stat);
225 expect(4, result);
226 count = -1;
227 GdipGetPointCount(retpath, &count);
228 expect(4, count);
229 result = -1;
230 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
231 expect(Ok, stat);
232 expect(0, result);
233 count = -1;
234 GdipGetPointCount(retpath, &count);
235 expect(4, count);
236 GdipDeletePathIter(iter);
237 GdipDeletePath(retpath);
238
239 /* two markers */
240 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
243 GdipCreatePathIter(&iter, path);
244 result = -1;
245 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
246 expect(Ok, stat);
247 expect(4, result);
248 result = -1;
249 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
250 expect(Ok, stat);
251 expect(2, result);
252 result = -1;
253 stat = GdipPathIterNextMarkerPath(iter, &result, retpath);
254 expect(Ok, stat);
255 expect(0, result);
256 GdipDeletePathIter(iter);
257 GdipDeletePath(retpath);
258
260}
261
262static void test_getsubpathcount(void)
263{
264 GpPath *path;
265 GpPathIterator *iter;
267 INT count;
268
269 /* NULL args */
274
276
277 /* empty path */
278 GdipCreatePathIter(&iter, path);
280 expect(Ok, stat);
281 expect(0, count);
282 GdipDeletePathIter(iter);
283
284 GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
285
286 /* open figure */
287 GdipCreatePathIter(&iter, path);
289 expect(Ok, stat);
290 expect(1, count);
291 GdipDeletePathIter(iter);
292
293 /* manually start new figure */
295 GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
296 GdipCreatePathIter(&iter, path);
298 expect(Ok, stat);
299 expect(2, count);
300 GdipDeletePathIter(iter);
301
303}
304
305static void test_isvalid(void)
306{
307 GpPath *path;
308 GpPathIterator *iter;
310 BOOL isvalid;
312
314
315 /* NULL args */
316 GdipCreatePathIter(&iter, path);
321 stat = GdipPathIterIsValid(NULL, &isvalid);
323 GdipDeletePathIter(iter);
324
325 /* on empty path */
326 GdipCreatePathIter(&iter, path);
327 isvalid = FALSE;
328 stat = GdipPathIterIsValid(iter, &isvalid);
329 expect(Ok, stat);
330 expect(TRUE, isvalid);
331 GdipDeletePathIter(iter);
332
333 /* no markers */
334 stat = GdipAddPathLine(path, 50.0, 50.0, 110.0, 40.0);
335 expect(Ok, stat);
336 stat = GdipCreatePathIter(&iter, path);
337 expect(Ok, stat);
339 expect(Ok, stat);
340 isvalid = FALSE;
341 stat = GdipPathIterIsValid(iter, &isvalid);
342 expect(Ok, stat);
343 expect(TRUE, isvalid);
344 GdipDeletePathIter(iter);
345
347}
348
349static void test_nextsubpathpath(void)
350{
351 GpPath *path, *retpath;
352 GpPathIterator *iter;
354 BOOL closed;
356
358
359 /* NULL args */
361 GdipCreatePathIter(&iter, path);
368 stat = GdipPathIterNextSubpathPath(iter, &result, NULL, &closed);
369 expect(Ok, stat);
370 stat = GdipPathIterNextSubpathPath(iter, NULL, NULL, &closed);
372 stat = GdipPathIterNextSubpathPath(iter, NULL, retpath, NULL);
374 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, NULL);
376 GdipDeletePathIter(iter);
377 GdipDeletePath(retpath);
378
379 /* empty path */
381 GdipCreatePathIter(&iter, path);
382 result = -2;
383 closed = TRUE;
384 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
385 expect(Ok, stat);
386 expect(0, result);
387 expect(TRUE, closed);
388 count = -1;
389 GdipGetPointCount(retpath, &count);
390 expect(0, count);
391 GdipDeletePathIter(iter);
392 GdipDeletePath(retpath);
393
394 /* open figure */
395 GdipAddPathLine(path, 5.0, 5.0, 100.0, 50.0);
396
398 GdipCreatePathIter(&iter, path);
399 result = -2;
400 closed = TRUE;
401 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
402 expect(Ok, stat);
403 expect(2, result);
404 expect(FALSE, closed);
405 count = -1;
406 GdipGetPointCount(retpath, &count);
407 expect(2, count);
408 /* subsequent call */
409 result = -2;
410 closed = TRUE;
411 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
412 expect(Ok, stat);
413 expect(0, result);
414 expect(TRUE, closed);
415 count = -1;
416 GdipGetPointCount(retpath, &count);
417 expect(2, count);
418 GdipDeletePathIter(iter);
419
420 /* closed figure, check does it extend retpath or reset it */
421 GdipAddPathLine(retpath, 50.0, 55.0, 200.0, 150.0);
422
424 GdipAddPathLine(path, 50.0, 55.0, 200.0, 150.0);
426
427 GdipCreatePathIter(&iter, path);
428 result = -2;
429 closed = FALSE;
430 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
431 expect(Ok, stat);
432 expect(2, result);
433 expect(TRUE, closed);
434 count = -1;
435 GdipGetPointCount(retpath, &count);
436 expect(2, count);
437 /* subsequent call */
438 result = -2;
439 closed = FALSE;
440 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
441 expect(Ok, stat);
442 expect(2, result);
443 expect(TRUE, closed);
444 count = -1;
445 GdipGetPointCount(retpath, &count);
446 expect(2, count);
447 result = -2;
448 closed = FALSE;
449 stat = GdipPathIterNextSubpathPath(iter, &result, retpath, &closed);
450 expect(Ok, stat);
451 expect(0, result);
452 expect(TRUE, closed);
453 count = -1;
454 GdipGetPointCount(retpath, &count);
455 expect(2, count);
456 GdipDeletePathIter(iter);
457
458 GdipDeletePath(retpath);
460}
461
462static void test_nextsubpath(void)
463{
464 GpPath *path;
465 GpPathIterator *iter;
468 BOOL closed;
469
470 /* empty path */
472 GdipCreatePathIter(&iter, path);
473
474 result = -2;
475 closed = TRUE;
476 stat = GdipPathIterNextSubpath(iter, &result, &start, &end, &closed);
477 expect(Ok, stat);
478 expect(0, result);
479 expect(TRUE, closed);
480
481 GdipDeletePathIter(iter);
483}
484
485static void test_nextpathtype(void)
486{
487 GpPath *path;
488 GpPathIterator *iter;
491 BYTE type;
492
494 GdipCreatePathIter(&iter, path);
495
496 /* NULL arguments */
511
512 /* empty path */
513 start = end = result = (INT)0xdeadbeef;
516 expect((INT)0xdeadbeef, start);
517 expect((INT)0xdeadbeef, end);
519 GdipDeletePathIter(iter);
520
521 /* single figure */
522 GdipAddPathLine(path, 0.0, 0.0, 10.0, 30.0);
523 GdipCreatePathIter(&iter, path);
524 start = end = result = (INT)0xdeadbeef;
525 type = 255; /* out of range */
528 expect((INT)0xdeadbeef, start);
529 expect((INT)0xdeadbeef, end);
530 expect(255, type);
532 GdipDeletePathIter(iter);
533
534 stat = GdipAddPathEllipse(path, 0.0, 0.0, 35.0, 70.0);
535 expect(Ok, stat);
536 GdipCreatePathIter(&iter, path);
537 start = end = result = (INT)0xdeadbeef;
538 type = 255; /* out of range */
541 expect((INT)0xdeadbeef, start);
542 expect((INT)0xdeadbeef, end);
543 expect(255, type);
545 GdipDeletePathIter(iter);
546
547 /* closed */
549 GdipCreatePathIter(&iter, path);
550 start = end = result = (INT)0xdeadbeef;
551 type = 255; /* out of range */
554 expect((INT)0xdeadbeef, start);
555 expect((INT)0xdeadbeef, end);
556 expect(255, type);
558 GdipDeletePathIter(iter);
559
561}
562
563START_TEST(pathiterator)
564{
565 struct GdiplusStartupInput gdiplusStartupInput;
566 ULONG_PTR gdiplusToken;
567 HMODULE hmsvcrt;
568 int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask);
569
570 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
571 hmsvcrt = LoadLibraryA("msvcrt");
572 _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s");
573 if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e);
574
575 gdiplusStartupInput.GdiplusVersion = 1;
576 gdiplusStartupInput.DebugEventCallback = NULL;
577 gdiplusStartupInput.SuppressBackgroundThread = 0;
578 gdiplusStartupInput.SuppressExternalCodecs = 0;
579
580 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
581
587 test_isvalid();
591
592 GdiplusShutdown(gdiplusToken);
593}
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
Definition: _controlfp_s.c:19
#define stat
Definition: acwin.h:99
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CDECL
Definition: compat.h:29
#define GetProcAddress(x, y)
Definition: compat.h:753
GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
Definition: graphicspath.c:704
GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y, REAL width, REAL height)
GpStatus WINGDIPAPI GdipClosePathFigure(GpPath *path)
GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width, REAL height)
Definition: graphicspath.c:583
GpStatus WINGDIPAPI GdipSetPathMarker(GpPath *path)
GpStatus WINGDIPAPI GdipPathIterNextMarkerPath(GpPathIterator *iterator, INT *result, GpPath *path)
Definition: pathiterator.c:173
GpStatus WINGDIPAPI GdipPathIterGetSubpathCount(GpPathIterator *iterator, INT *count)
Definition: pathiterator.c:127
GpStatus WINGDIPAPI GdipDeletePathIter(GpPathIterator *iter)
Definition: pathiterator.c:69
GpStatus WINGDIPAPI GdipPathIterHasCurve(GpPathIterator *iterator, BOOL *hasCurve)
Definition: pathiterator.c:107
GpStatus WINGDIPAPI GdipPathIterNextSubpath(GpPathIterator *iterator, INT *resultCount, INT *startIndex, INT *endIndex, BOOL *isClosed)
Definition: pathiterator.c:199
GpStatus WINGDIPAPI GdipCreatePathIter(GpPathIterator **iterator, GpPath *path)
Definition: pathiterator.c:34
GpStatus WINGDIPAPI GdipPathIterNextSubpathPath(GpPathIterator *iter, INT *result, GpPath *path, BOOL *closed)
Definition: pathiterator.c:306
GpStatus WINGDIPAPI GdipPathIterIsValid(GpPathIterator *iterator, BOOL *valid)
Definition: pathiterator.c:283
GpStatus WINGDIPAPI GdipPathIterNextPathType(GpPathIterator *iter, INT *result, BYTE *type, INT *start, INT *end)
Definition: pathiterator.c:295
GpStatus WINGDIPAPI GdipPathIterNextMarker(GpPathIterator *iterator, INT *resultCount, INT *startIndex, INT *endIndex)
Definition: pathiterator.c:145
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned int BOOL
Definition: ntddk_ex.h:94
FxCollectionEntry * cur
Status WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input, struct GdiplusStartupOutput *output)
Definition: gdiplus.c:81
@ FillModeAlternate
Definition: gdiplusenums.h:55
void WINAPI GdiplusShutdown(ULONG_PTR)
Status
Definition: gdiplustypes.h:25
@ Ok
Definition: gdiplustypes.h:26
@ InvalidParameter
Definition: gdiplustypes.h:28
GLuint start
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLint GLuint mask
Definition: glext.h:6028
GLuint64EXT * result
Definition: glext.h:11304
static void test_nextsubpathpath(void)
Definition: pathiterator.c:349
static void test_nextmarkerpath(void)
Definition: pathiterator.c:179
static void test_nextsubpath(void)
Definition: pathiterator.c:462
static void test_nextmarker(void)
Definition: pathiterator.c:97
#define expect(expected, got)
Definition: pathiterator.c:25
static void test_hascurve(void)
Definition: pathiterator.c:57
static void test_getsubpathcount(void)
Definition: pathiterator.c:262
static void test_isvalid(void)
Definition: pathiterator.c:305
static void test_nextpathtype(void)
Definition: pathiterator.c:485
static void test_constructor_destructor(void)
Definition: pathiterator.c:27
#define todo_wine
Definition: custom.c:79
#define INT
Definition: polytest.cpp:20
BOOL SuppressBackgroundThread
Definition: gdiplusinit.h:36
DebugEventProc DebugEventCallback
Definition: gdiplusinit.h:35
Definition: stat.h:55
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char BYTE
Definition: xxhash.c:193