File: testreversepath.c

package info (click to toggle)
libgdiplus 2.10-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 12,636 kB
  • sloc: ansic: 102,856; sh: 13,336; makefile: 870
file content (254 lines) | stat: -rw-r--r-- 8,434 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifdef WIN32
#ifndef __cplusplus
#error Please compile with a C++ compiler.
#endif
#include <windows.h>
#include <GdiPlus.h>
#else
#include <GdiPlusFlat.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define C(func) assert(func == Ok)

#ifdef WIN32
using namespace Gdiplus;
using namespace DllExports;
#endif


static void check_reverse_points(const GpPointF *p1, const GpPointF *p2, int count)
{
	p2 += count;
	while (count--) {
		p2--;
		assert (p1->X == p2->X);
		assert (p1->Y == p2->Y);
		p1++;
	}
}

static void
test_gdip_reversepath()
{
	GpPath *path;
	int count;
	int reverse_count;
	BYTE types[100];
	GpPointF points[100];
	BYTE reverse_types[100];
	GpPointF reverse_points[100];

	// Create a path
	C (GdipCreatePath (FillModeAlternate, &path));

	C (GdipGetPointCount (path, &count));
	assert (count == 0);

	// Reverse an empty path
	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == 0);

	// Path with one line
	C (GdipAddPathLine (path, 0, 10, 1, 11));
	C (GdipGetPointCount (path, &count));
	assert (count == 2);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[0] == PathPointTypeStart);
	assert (types[1] == PathPointTypeLine);

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == PathPointTypeStart);
	assert (reverse_types[1] == PathPointTypeLine);

	GdipResetPath (path);

	// Closed path with one line
	C (GdipAddPathLine (path, 0, 10, 1, 11));
	C (GdipClosePathFigure (path));
	C (GdipGetPointCount (path, &count));
	assert (count == 2);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[0] == PathPointTypeStart);
	assert (types[1] == (PathPointTypeLine | PathPointTypeCloseSubpath));

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == PathPointTypeStart);
	assert (reverse_types[1] == (PathPointTypeLine | PathPointTypeCloseSubpath));

	GdipResetPath (path);

	// Rectangle
	C (GdipAddPathRectangle (path, 200, 201, 60, 61));
	C (GdipGetPointCount (path, &count));
	assert (count == 4);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[0] == PathPointTypeStart);
	assert (types[1] == PathPointTypeLine);
	assert (types[2] == PathPointTypeLine);
	assert (types[3] == (PathPointTypeLine | PathPointTypeCloseSubpath));

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == PathPointTypeStart);
	assert (reverse_types[1] == PathPointTypeLine);
	assert (reverse_types[2] == PathPointTypeLine);
	assert (reverse_types[3] == (PathPointTypeLine | PathPointTypeCloseSubpath));

	GdipResetPath (path);

	// Rectangle, marker
	C (GdipAddPathRectangle (path, 200, 201, 60, 61));
	C (GdipSetPathMarker (path));
	C (GdipGetPointCount (path, &count));
	assert (count == 4);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[0] == PathPointTypeStart);
	assert (types[1] == PathPointTypeLine);
	assert (types[2] == PathPointTypeLine);
	assert (types[3] == (PathPointTypeLine | PathPointTypeCloseSubpath | PathPointTypePathMarker));

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == PathPointTypeStart);
	assert (reverse_types[1] == PathPointTypeLine);
	assert (reverse_types[2] == PathPointTypeLine);
	assert (reverse_types[3] == (PathPointTypeLine | PathPointTypeCloseSubpath));

	GdipResetPath (path);


	// Elipse and rectangle 
	C (GdipAddPathEllipse (path, 50, 51, 50, 100));
	C (GdipAddPathRectangle (path, 200, 201, 60, 61));
	C (GdipGetPointCount (path, &count));
	assert (count == 17);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[13] == PathPointTypeStart);
	assert (types[14] == PathPointTypeLine);
	assert (types[15] == PathPointTypeLine);
	assert (types[16] == (PathPointTypeLine | PathPointTypeCloseSubpath));

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == types[13]);
	assert (reverse_types[1] == (types[16] & ~PathPointTypeCloseSubpath));
	assert (reverse_types[2] == types[15]);
	assert (reverse_types[3] == (types[14] | PathPointTypeCloseSubpath));

	GdipResetPath (path);

	// Line, marker, bezier
	C (GdipAddPathLine (path, 0, 1, 2, 3));
	C (GdipSetPathMarker (path));
	C (GdipClosePathFigure (path));
	C (GdipAddPathBezier (path, 5, 6, 7, 8, 9, 10, 11, 12));
	C (GdipClosePathFigure (path));
	C (GdipGetPointCount (path, &count));
	assert (count == 6);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[0] == PathPointTypeStart);
	assert (types[1] == (PathPointTypeLine | PathPointTypePathMarker | PathPointTypeCloseSubpath));
	assert (types[2] == PathPointTypeStart);
	assert (types[3] == PathPointTypeBezier);
	assert (types[4] == PathPointTypeBezier);
	assert (types[5] == (PathPointTypeBezier | PathPointTypeCloseSubpath));

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == types[2]);
	assert (reverse_types[1] == types[4]);
	assert (reverse_types[2] == types[3]);
	assert (reverse_types[3] == (types[5] | PathPointTypePathMarker));
	assert (reverse_types[4] == types[0]);
	assert (reverse_types[5] == (types[1] & ~PathPointTypePathMarker));

	GdipResetPath (path);

	// Line, marker, line, bezier
	C (GdipAddPathLine (path, 0, 1, 2, 3));
	C (GdipSetPathMarker (path));
	C (GdipStartPathFigure (path));
	C (GdipAddPathLine (path, 20, 21, 22, 23));
	C (GdipAddPathBezier (path, 5, 6, 7, 8, 9, 10, 11, 12));
	C (GdipGetPointCount (path, &count));
	assert (count == 8);
	C (GdipGetPathTypes (path, types, count));
	C (GdipGetPathPoints (path, points, count));
	assert (types[0] == PathPointTypeStart);
	assert (types[1] == (PathPointTypeLine | PathPointTypePathMarker));
	assert (types[2] == PathPointTypeStart);
	assert (types[3] == PathPointTypeLine);
	assert (types[4] == PathPointTypeLine);
	assert (types[5] == PathPointTypeBezier);
	assert (types[6] == PathPointTypeBezier);
	assert (types[7] == PathPointTypeBezier);

	C (GdipReversePath (path));
	C (GdipGetPointCount (path, &reverse_count));
	assert (reverse_count == count);
	C (GdipGetPathTypes (path, reverse_types, count));
	C (GdipGetPathPoints (path, reverse_points, count));
	check_reverse_points (points, reverse_points, count);
	assert (reverse_types[0] == PathPointTypeStart);
	assert (reverse_types[1] == PathPointTypeBezier);
	assert (reverse_types[2] == PathPointTypeBezier);
	assert (reverse_types[3] == PathPointTypeBezier);
	assert (reverse_types[4] == PathPointTypeLine);
	assert (reverse_types[5] == (PathPointTypeLine | PathPointTypePathMarker));
	assert (reverse_types[6] == PathPointTypeStart);
	assert (reverse_types[7] == PathPointTypeLine);
	

	C (GdipDeletePath (path));
}


int
main(int argc, char**argv)
{
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	test_gdip_reversepath();

	GdiplusShutdown(gdiplusToken);
	return 0;
}