Debian Codegraph @

test/curve.c

raw symbols SCIP
1 /*
2 *
3 * Copyright 2002 Robert Krawitz ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <limits.h>
28 #ifdef __GNU_LIBRARY__
29 #include <getopt.h>
30 #endif
31
32 #pragma GCC diagnostic ignored "-Woverlength-strings"
33
34 #define DEBUG_SIGNAL
35 #define MIN(x, y) ((x) <= (y) ? (x) : (y))
36 #include <gutenprint/gutenprint.h>
37
38 int global_test_count = 0;
39 int global_error_count = 0;
40 int verbose = 0;
41 int quiet = 0;
42
43 #ifdef __GNU_LIBRARY__
44
45 struct option optlist[] =
46 {
47 { "quiet", 0, NULL, (int) 'q' },
48 { "verbose", 0, NULL, (int) 'v' },
49 { NULL, 0, NULL, 0 }
50 };
51 #endif
52
53 struct test_failure
54 {
55 int test_number;
56 struct test_failure *next;
57 };
58
59 static struct test_failure *test_failure_head = NULL;
60 static struct test_failure *test_failure_tail = NULL;
61
62 static const char *current_test_name;
63 static int current_test_line;
64
65 static void
66 TEST_internal(const char *name, int line)
67 {
68 global_test_count++;
69 current_test_name = name;
70 current_test_line = line;
71 }
72
73 #define TEST(name) TEST_internal(name, __LINE__)
74
75 static void
76 TEST_PASS(void)
77 {
78 if (verbose)
79 printf("%d.%d: Checking %s... PASS\n", global_test_count, current_test_line,
80 current_test_name);
81 fflush(stdout);
82 }
83
84 static void
85 TEST_FAIL(void)
86 {
87 struct test_failure *test_failure_tmp = malloc(sizeof(struct test_failure));
88 test_failure_tmp->next = NULL;
89 test_failure_tmp->test_number = global_test_count;
90
91 if (!test_failure_head)
92 {
93 test_failure_head = test_failure_tmp;
94 test_failure_tail = test_failure_head;
95 }
96 else
97 {
98 test_failure_tail->next = test_failure_tmp;
99 test_failure_tail = test_failure_tmp;
100 }
101
102 global_error_count++;
103 printf("%d.%d: Checking %s... FAIL\n", global_test_count, current_test_line,
104 current_test_name);
105 fflush(stdout);
106 }
107
108 #define SIMPLE_TEST_CHECK(conditional) \
109 do { \
110 if ((conditional)) \
111 TEST_PASS(); \
112 else \
113 TEST_FAIL(); \
114 } while (0)
115
116 static const double standard_sat_adjustment[] =
117 {
118 0.50, 0.6, 0.7, 0.8, 0.9, 0.86, 0.82, 0.79, /* C */
119 0.78, 0.8, 0.83, 0.87, 0.9, 0.95, 1.05, 1.15, /* B */
120 1.3, 1.25, 1.2, 1.15, 1.12, 1.09, 1.06, 1.03, /* M */
121 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, /* R */
122 1.0, 0.9, 0.8, 0.7, 0.65, 0.6, 0.55, 0.52, /* Y */
123 0.48, 0.47, 0.47, 0.49, 0.49, 0.49, 0.52, 0.51, /* G */
124 };
125
126 static const double reverse_sat_adjustment[] =
127 {
128 0.50, 0.51, 0.52, 0.49, 0.49, 0.49, 0.47, 0.47,
129 0.48, 0.52, 0.55, 0.6, 0.65, 0.7, 0.8, 0.9,
130 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
131 1.0, 1.03, 1.06, 1.09, 1.12, 1.15, 1.2, 1.25,
132 1.3, 1.15, 1.05, 0.95, 0.9, 0.87, 0.83, 0.8,
133 0.78, 0.79, 0.82, 0.86, 0.9 , 0.8, 0.7, 0.6,
134 };
135
136 static const stp_curve_point_t standard_piecewise_sat_adjustment[] =
137 {
138 { 0.00, 0.50},
139 { 0.02, 0.6},
140 { 0.04, 0.7},
141 { 0.06, 0.8},
142 { 0.08, 0.9},
143 { 0.10, 0.86},
144 { 0.12, 0.82},
145 { 0.14, 0.79},
146 { 0.16, 0.78},
147 { 0.18, 0.8},
148 { 0.20, 0.83},
149 { 0.22, 0.87},
150 { 0.24, 0.9},
151 { 0.26, 0.95},
152 { 0.28, 1.05},
153 { 0.30, 1.15},
154 { 0.32, 0.05},
155 { 0.34, 3.95},
156 { 0.36, 0.05},
157 { 0.38, 1.15},
158 { 0.40, 1.12},
159 { 0.42, 1.09},
160 { 0.44, 1.06},
161 { 0.46, 1.03},
162 { 0.48, 1.0},
163 { 0.50, 1.0},
164 { 0.52, 1.0},
165 { 0.54, 1.0},
166 { 0.56, 1.0},
167 { 0.58, 1.0},
168 { 0.60, 1.0},
169 { 0.62, 1.0},
170 { 0.64, 1.0},
171 { 0.66, 0.9},
172 { 0.68, 0.8},
173 { 0.70, 0.7},
174 { 0.72, 0.65},
175 { 0.74, 0.6},
176 { 0.76, 0.55},
177 { 0.78, 0.52},
178 { 0.80, 0.48},
179 { 0.82, 0.47},
180 { 0.84, 0.47},
181 { 0.86, 0.49},
182 { 0.88, 0.49},
183 { 0.90, 0.49},
184 { 0.93, 0.52},
185 { 0.96, 0.51},
186 { 1.00, 2},
187 };
188
189 static const stp_curve_point_t reverse_piecewise_sat_adjustment[] =
190 {
191 { 0.00, 0.50},
192 { 0.02, 0.6},
193 { 0.04, 0.7},
194 { 0.06, 0.8},
195 { 0.08, 0.9},
196 { 0.10, 0.86},
197 { 0.12, 0.82},
198 { 0.14, 0.79},
199 { 0.16, 0.78},
200 { 0.18, 0.8},
201 { 0.20, 0.83},
202 { 0.22, 0.87},
203 { 0.24, 0.9},
204 { 0.26, 0.95},
205 { 0.28, 1.05},
206 { 0.30, 1.15},
207 { 0.32, 0.05},
208 { 0.34, 3.95},
209 { 0.36, 0.05},
210 { 0.38, 1.15},
211 { 0.40, 1.12},
212 { 0.42, 1.09},
213 { 0.44, 1.06},
214 { 0.46, 1.03},
215 { 0.48, 1.0},
216 { 0.50, 1.0},
217 { 0.52, 1.0},
218 { 0.54, 1.0},
219 { 0.56, 1.0},
220 { 0.58, 1.0},
221 { 0.60, 1.0},
222 { 0.62, 1.0},
223 { 0.64, 1.0},
224 { 0.66, 0.9},
225 { 0.68, 0.8},
226 { 0.70, 0.7},
227 { 0.72, 0.65},
228 { 0.74, 0.6},
229 { 0.76, 0.55},
230 { 0.78, 0.52},
231 { 0.80, 0.48},
232 { 0.82, 0.47},
233 { 0.84, 0.47},
234 { 0.86, 0.49},
235 { 0.88, 0.49},
236 { 0.90, 0.49},
237 { 0.93, 0.52},
238 { 0.96, 0.51},
239 { 1.00, 2},
240 };
241
242 const char *small_piecewise_curve =
243 "<?xml version=\"1.0\"?>\n"
244 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
245 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
246 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
247 "<curve wrap=\"nowrap\" type=\"linear\" gamma=\"0\" piecewise=\"true\">\n"
248 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"4\">\n"
249 "0 0.5 0.1 0.6 1.00 0.51\n"
250 "</sequence>\n"
251 "</curve>\n"
252 "</gutenprint>\n";
253
254 const char *good_curves[] =
255 {
256 /* Space separated, in same layout as output for comparison */
257 "<?xml version=\"1.0\"?>\n"
258 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
259 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
260 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
261 "<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
262 "<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
263 "0.5 0.6 0.7 0.8 0.9 0.86 0.82 0.79 0.78 0.8 0.83 0.87 0.9 0.95 1.05 1.15\n"
264 "1.3 1.25 1.2 1.15 1.12 1.09 1.06 1.03 1 1 1 1 1 1 1 1 1 0.9 0.8 0.7 0.65\n"
265 "0.6 0.55 0.52 0.48 0.47 0.47 0.49 0.49 0.49 0.52 0.51\n"
266 "</sequence>\n"
267 "</curve>\n"
268 "</gutenprint>\n",
269
270 /* Space separated, in same layout as output for comparison */
271 "<?xml version=\"1.0\"?>\n"
272 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
273 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
274 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
275 "<curve wrap=\"nowrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
276 "<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
277 "0.5 0.6 0.7 0.8 0.9 0.86 0.82 0.79 0.78 0.8 0.83 0.87 0.9 0.95 1.05 1.15\n"
278 "1.3 1.25 1.2 1.15 1.12 1.09 1.06 1.03 1 1 1 1 1 1 1 1 1 0.9 0.8 0.7 0.65\n"
279 "0.6 0.55 0.52 0.48 0.47 0.47 0.49 0.49 0.49 0.52 0.51\n"
280 "</sequence>\n"
281 "</curve>\n"
282 "</gutenprint>\n",
283
284 /* Space separated, in same layout as output for comparison */
285 "<?xml version=\"1.0\"?>\n"
286 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
287 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
288 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
289 "<curve wrap=\"wrap\" type=\"spline\" gamma=\"0\" piecewise=\"false\">\n"
290 "<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
291 "0.5 0.6 0.7 0.8 0.9 0.86 0.82 0.79 0.78 0.8 0.83 0.87 0.9 0.95 1.05 1.15\n"
292 "1.3 1.25 1.2 1.15 1.12 1.09 1.06 1.03 1 1 1 1 1 1 1 1 1 0.9 0.8 0.7 0.65\n"
293 "0.6 0.55 0.52 0.48 0.47 0.47 0.49 0.49 0.49 0.52 0.51\n"
294 "</sequence>\n"
295 "</curve>\n"
296 "</gutenprint>\n",
297
298 /* Space separated, in same layout as output for comparison */
299 "<?xml version=\"1.0\"?>\n"
300 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
301 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
302 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
303 "<curve wrap=\"nowrap\" type=\"spline\" gamma=\"0\" piecewise=\"false\">\n"
304 "<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
305 "0.5 0.6 0.7 0.8 0.9 0.86 0.82 0.79 0.78 0.8 0.83 0.87 0.9 0.95 1.05 1.15\n"
306 "1.3 1.25 1.2 1.15 1.12 1.09 1.06 1.03 1 1 1 1 1 1 1 1 1 0.9 0.8 0.7 0.65\n"
307 "0.6 0.55 0.52 0.48 0.47 0.47 0.49 0.49 0.49 0.52 0.51\n"
308 "</sequence>\n"
309 "</curve>\n"
310 "</gutenprint>\n",
311
312 "<?xml version=\"1.0\"?>\n"
313 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
314 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
315 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
316 "<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"true\">\n"
317 "<sequence count=\"96\" lower-bound=\"0\" upper-bound=\"4\">\n"
318 "0 0.5 0.02 0.6 0.04 0.7 0.06 0.8 0.08 0.9 0.1 0.86 0.12 0.82 0.14 0.79 0.16\n"
319 "0.78 0.18 0.8 0.2 0.83 0.22 0.87 0.24 0.9 0.26 0.95 0.28 1.05 0.3 1.15 0.32\n"
320 "1.3 0.34 1.25 0.36 1.2 0.38 1.15 0.4 1.12 0.42 1.09 0.44 1.06 0.46 1.03\n"
321 "0.48 1 0.5 1 0.52 1 0.54 1 0.56 1 0.58 1 0.6 1 0.62 1 0.64 1 0.66 0.9 0.68\n"
322 "0.8 0.7 0.7 0.72 0.65 0.74 0.6 0.76 0.55 0.78 0.52 0.8 0.48 0.82 0.47 0.84\n"
323 "0.47 0.86 0.49 0.88 0.49 0.9 0.49 0.93 0.52 0.96 0.51\n"
324 "</sequence>\n"
325 "</curve>\n"
326 "</gutenprint>\n",
327
328 "<?xml version=\"1.0\"?>\n"
329 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
330 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
331 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
332 "<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"true\">\n"
333 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"4\">\n"
334 "0 0.5 0.02 0.6 0.96 0.51\n"
335 "</sequence>\n"
336 "</curve>\n"
337 "</gutenprint>\n",
338
339 /* Gamma curve 1 */
340 "<?xml version=\"1.0\"?>\n"
341 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
342 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
343 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
344 "<curve wrap=\"nowrap\" type=\"linear\" gamma=\"1\" piecewise=\"false\">\n"
345 "<sequence count=\"0\" lower-bound=\"0\" upper-bound=\"4\"/>\n"
346 "</curve>\n"
347 "</gutenprint>\n",
348
349 /* Gamma curve 2 */
350 "<?xml version=\"1.0\"?>\n"
351 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
352 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
353 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
354 "<curve wrap=\"nowrap\" type=\"linear\" gamma=\"1\" piecewise=\"false\">\n"
355 "<sequence count=\"0\" lower-bound=\"0\" upper-bound=\"4\"/>\n"
356 "</curve>\n"
357 "</gutenprint>\n"
358 };
359
360 static const int good_curve_count = sizeof(good_curves) / sizeof(const char *);
361
362 const char *bad_curves[] =
363 {
364 /* Bad point count */
365 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
366 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
367 "<sequence count=\"-1\" lower-bound=\"0\" upper-bound=\"4\">\n"
368 "0.5 0.6 0.7 0.8 0.9 0.86 0.82 0.79 0.78 0.8\n"
369 "0.83 0.87 0.9 0.95 1.05 1.15 1.3 1.25 1.2 1.15\n"
370 "1.12 1.09 1.06 1.03 1 1 1 1 1 1\n"
371 "1 1 1 0.9 0.8 0.7 0.65 0.6 0.55 0.52\n"
372 "0.48 0.47 0.47 0.49 0.49 0.49 0.52 0.51\n"
373 "</sequence></curve></gutenprint>\n",
374
375 /* Bad point count */
376 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
377 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
378 "<sequence count=\"200\" lower-bound=\"0\" upper-bound=\"4\">\n"
379 "0.5 0.6 0.7 0.8 0.9 0.86 0.82 0.79 0.78 0.8\n"
380 "0.83 0.87 0.9 0.95 1.05 1.15 1.3 1.25 1.2 1.15\n"
381 "1.12 1.09 1.06 1.03 1 1 1 1 1 1\n"
382 "1 1 1 0.9 0.8 0.7 0.65 0.6 0.55 0.52\n"
383 "0.48 0.47 0.47 0.49 0.49 0.49 0.52 0.51\n"
384 "</sequence></curve></gutenprint>\n",
385
386 "<?xml version=\"1.0\"?>\n"
387 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
388 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
389 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
390 "<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"true\">\n"
391 "<sequence count=\"5\" lower-bound=\"0\" upper-bound=\"4\">\n"
392 "0 0.5 0.02 0.6 0.96\n"
393 "</sequence>\n"
394 "</curve>\n"
395 "</gutenprint>\n",
396
397 "<?xml version=\"1.0\"?>\n"
398 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
399 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
400 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
401 "<curve wrap=\"nowrap\" type=\"linear\" gamma=\"0\" piecewise=\"true\">\n"
402 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"4\">\n"
403 "0 0.5 0.02 0.6 0.96 0.51\n"
404 "</sequence>\n"
405 "</curve>\n"
406 "</gutenprint>\n",
407
408 "<?xml version=\"1.0\"?>\n"
409 "<gutenprint xmlns=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0\"\n"
410 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
411 "xsi:schemaLocation=\"http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gutenprint.xsd\">\n"
412 "<curve wrap=\"nowrap\" type=\"linear\" gamma=\"0\" piecewise=\"true\">\n"
413 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"4\">\n"
414 "0.01 0.5 0.02 0.6 1.0 0.51\n"
415 "</sequence>\n"
416 "</curve>\n"
417 "</gutenprint>\n",
418
419 /* Gamma curves */
420 /* Incorrect wrap mode */
421 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
422 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"1.0\" piecewise=\"false\">\n"
423 "<sequence count=\"-1\" lower-bound=\"0\" upper-bound=\"4\">\n"
424 "</sequence></curve></gutenprint>\n",
425
426 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
427 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"1.0\" piecewise=\"false\">\n"
428 "<sequence count=\"1\" lower-bound=\"0\" upper-bound=\"4\">\n"
429 "</sequence></curve></gutenprint>\n",
430
431 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
432 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"1.0\" piecewise=\"false\">\n"
433 "<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
434 "</sequence></curve></gutenprint>\n",
435
436 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
437 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"1.0\" piecewise=\"false\">\n"
438 "<sequence count=\"0\" lower-bound=\"0\" upper-bound=\"4\">\n"
439 "</sequence></curve></gutenprint>\n"
440 };
441
442 static const int bad_curve_count = sizeof(bad_curves) / sizeof(const char *);
443
444 const char *linear_curve_1 =
445 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
446 "<gutenprint><curve wrap=\"nowrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
447 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"1\">\n"
448 "0 0 0 1 1 1"
449 "</sequence></curve></gutenprint>";
450
451 const char *linear_curve_2 =
452 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
453 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
454 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"1\">\n"
455 "0 0 0 1 1 1"
456 "</sequence></curve></gutenprint>";
457
458 const char *linear_curve_3 =
459 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
460 "<gutenprint><curve wrap=\"nowrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
461 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"1\">\n"
462 "0 0 0 1 1 1"
463 "</sequence></curve></gutenprint>";
464
465 const char *linear_curve_4 =
466 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
467 "<gutenprint><curve wrap=\"wrap\" type=\"linear\" gamma=\"0\" piecewise=\"false\">\n"
468 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"1\">\n"
469 "0 0 0 1 1 1"
470 "</sequence></curve></gutenprint>";
471
472 const char *spline_curve_1 =
473 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
474 "<gutenprint><curve wrap=\"nowrap\" type=\"spline\" gamma=\"0\" piecewise=\"false\">\n"
475 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"1\">\n"
476 "0 0 0 1 1 1"
477 "</sequence></curve></gutenprint>";
478
479 const char *spline_curve_2 =
480 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
481 "<gutenprint><curve wrap=\"wrap\" type=\"spline\" gamma=\"0\" piecewise=\"false\">\n"
482 "<sequence count=\"6\" lower-bound=\"0\" upper-bound=\"1\">\n"
483 "0 0 0 1 1 1"
484 "</sequence></curve></gutenprint>";
485
486 static void
487 piecewise_curve_checks(stp_curve_t *curve1, int resample_points, size_t expected)
488 {
489 stp_curve_t *curve2;
490 const stp_curve_point_t *curve_points;
491 size_t count;
492 size_t i;
493 double low;
494
495 TEST("get data points of piecewise curve");
496 curve_points = stp_curve_get_data_points(curve1, &count);
497 if (curve_points)
498 {
499 int bad_compare = 0;
500 TEST_PASS();
501 TEST("Checking count of curve points");
502 if (count == expected)
503 TEST_PASS();
504 else
505 {
506 TEST_FAIL();
507 if (!quiet)
508 printf("Expected %zu points, got %lu\n", expected, count);
509 }
510 TEST("Comparing data");
511 for (i = 0; i < count; i++)
512 {
513 if (curve_points[i].x != standard_piecewise_sat_adjustment[i].x ||
514 curve_points[i].y - .0000001 > standard_piecewise_sat_adjustment[i].y ||
515 curve_points[i].y + .0000001 < standard_piecewise_sat_adjustment[i].y)
516 {
517 bad_compare = 1;
518 if (!quiet)
519 printf("Miscompare at element %zu: (%f, %f) (%f, %f)\n", i,
520 standard_piecewise_sat_adjustment[i].x,
521 standard_piecewise_sat_adjustment[i].y,
522 curve_points[i].x, curve_points[i].y);
523 }
524 }
525 SIMPLE_TEST_CHECK(!bad_compare);
526 }
527 else
528 TEST_FAIL();
529
530 TEST("get sequence of piecewise curve (PASS is an expected failure)");
531 SIMPLE_TEST_CHECK(!stp_curve_get_sequence(curve1));
532
533 TEST("get data of piecewise curve (PASS is an expected failure)");
534 SIMPLE_TEST_CHECK(!stp_curve_get_data(curve1, &count));
535
536 TEST("set data point of piecewise curve (PASS is an expected failure)");
537 SIMPLE_TEST_CHECK(!stp_curve_set_point(curve1, 2, 1.0));
538
539 TEST("get data point of piecewise curve (PASS is an expected failure)");
540 SIMPLE_TEST_CHECK(!stp_curve_get_point(curve1, 2, &low));
541
542 TEST("interpolate piecewise curve (PASS is an expected failure)");
543 SIMPLE_TEST_CHECK(!stp_curve_interpolate_value(curve1, .5, &low));
544
545 TEST("rescale piecewise curve");
546 SIMPLE_TEST_CHECK(stp_curve_rescale(curve1, .5, STP_CURVE_COMPOSE_ADD,
547 STP_CURVE_BOUNDS_RESCALE));
548
549 TEST("get float data of piecewise curve (PASS is an expected failure)");
550 SIMPLE_TEST_CHECK(!stp_curve_get_float_data(curve1, &count));
551
552 TEST("get subrange on piecewise curve (PASS is an expected failure)");
553 SIMPLE_TEST_CHECK(!(curve2 = stp_curve_get_subrange(curve1, 0, 2)));
554 if (!quiet && curve2)
555 stp_curve_write(stdout, curve2);
556
557 TEST("set subrange on piecewise curve (PASS is an expected failure)");
558 curve2 = stp_curve_create_from_string(linear_curve_2);
559 if (stp_curve_set_subrange(curve1, curve2, 1))
560 {
561 TEST_FAIL();
562 if (!quiet)
563 stp_curve_write(stdout, curve2);
564 }
565 else
566 TEST_PASS();
567 stp_curve_destroy(curve2);
568
569 if (resample_points > 0)
570 {
571 char tmpbuf[64];
572 sprintf(tmpbuf, "resample piecewise curve to %d points", resample_points);
573 TEST(tmpbuf);
574 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, resample_points));
575
576 TEST("resampled curve is not piecewise");
577 SIMPLE_TEST_CHECK(!stp_curve_is_piecewise(curve1));
578
579 TEST("get data points of piecewise copy (PASS is an expected failure)");
580 SIMPLE_TEST_CHECK(!stp_curve_get_data_points(curve1, &count));
581
582 TEST("get sequence of piecewise copy");
583 SIMPLE_TEST_CHECK(stp_curve_get_sequence(curve1));
584
585 TEST("get data of piecewise copy");
586 SIMPLE_TEST_CHECK(stp_curve_get_data(curve1, &count));
587
588 TEST("set data point of piecewise copy");
589 SIMPLE_TEST_CHECK(stp_curve_set_point(curve1, 2, 0.51));
590
591 TEST("get data point of piecewise copy");
592 SIMPLE_TEST_CHECK(stp_curve_get_point(curve1, 2, &low));
593
594 TEST("interpolate piecewise copy");
595 SIMPLE_TEST_CHECK(stp_curve_interpolate_value(curve1, .5, &low));
596
597 TEST("rescale piecewise copy");
598 SIMPLE_TEST_CHECK(stp_curve_rescale(curve1, 2,
599 STP_CURVE_COMPOSE_MULTIPLY,
600 STP_CURVE_BOUNDS_RESCALE));
601
602 TEST("get float data of piecewise copy");
603 SIMPLE_TEST_CHECK(stp_curve_get_float_data(curve1, &count));
604
605 TEST("get subrange on piecewise copy");
606 SIMPLE_TEST_CHECK((curve2 = stp_curve_get_subrange(curve1, 0, 2)));
607 if (verbose && curve2)
608 stp_curve_write(stdout, curve2);
609 if (curve2)
610 stp_curve_destroy(curve2);
611
612 if (resample_points > 10)
613 {
614 TEST("set subrange on piecewise copy");
615 curve2 = stp_curve_create_from_string(linear_curve_2);
616 if (verbose)
617 stp_curve_write(stdout, curve1);
618 if (stp_curve_set_subrange(curve1, curve2, 4))
619 {
620 TEST_PASS();
621 if (verbose)
622 stp_curve_write(stdout, curve1);
623 }
624 else
625 TEST_FAIL();
626 if (curve2)
627 stp_curve_destroy(curve2);
628 }
629 }
630 }
631
632 int
633 main(int argc, char **argv)
634 {
635 char *tmp;
636 int i;
637 size_t count;
638 double low, high;
639
640 stp_curve_t *curve1;
641 stp_curve_t *curve2;
642 stp_curve_t *curve3;
643 const stp_curve_point_t *curve_points;
644
645 while (1)
646 {
647 #ifdef __GNU_LIBRARY__
648 int option_index = 0;
649 int c = getopt_long(argc, argv, "qv", optlist, &option_index);
650 #else
651 int c = getopt(argc, argv, "qv");
652 #endif
653 if (c == -1)
654 break;
655 switch (c)
656 {
657 case 'q':
658 quiet = 1;
659 verbose = 0;
660 break;
661 case 'v':
662 quiet = 0;
663 verbose = 1;
664 break;
665 default:
666 break;
667 }
668 }
669 stp_init();
670
671 TEST("creation of XML string from curve");
672 curve1 = stp_curve_create(STP_CURVE_WRAP_AROUND);
673 stp_curve_set_bounds(curve1, 0.0, 4.0);
674 stp_curve_set_data(curve1, 48, reverse_sat_adjustment);
675 tmp = stp_curve_write_string(curve1);
676 stp_curve_destroy(curve1);
677 curve1 = NULL;
678 SIMPLE_TEST_CHECK(tmp);
679 if (verbose)
680 printf("%s\n", tmp);
681
682
683 TEST("creation of curve from XML string (stp_curve_create_from_string)");
684 SIMPLE_TEST_CHECK((curve2 = stp_curve_create_from_string(tmp)));
685 free(tmp);
686
687 TEST("stp_curve_resample");
688 if (curve2 != NULL && stp_curve_resample(curve2, 95) == 0)
689 {
690 TEST_FAIL();
691 }
692 else
693 {
694 TEST_PASS();
695 if (verbose)
696 stp_curve_write(stdout, curve2);
697 }
698 if (curve2)
699 {
700 stp_curve_destroy(curve2);
701 curve2 = NULL;
702 }
703
704 if (!quiet)
705 printf("Testing known bad curves... (expect messages)\n");
706 for (i = 0; i < bad_curve_count; i++)
707 {
708 stp_curve_t *bad = NULL;
709 TEST("BAD curve (PASS is an expected failure)");
710 if ((bad = stp_curve_create_from_string(bad_curves[i])) != NULL)
711 {
712 TEST_FAIL();
713 if (!quiet)
714 {
715 stp_curve_write(stdout, bad);
716 printf("\n");
717 }
718 stp_curve_destroy(bad);
719 bad = NULL;
720 }
721 else
722 TEST_PASS();
723 }
724
725 if (!quiet)
726 printf("Testing known good curves...\n");
727 for (i = 0; i < good_curve_count; i++)
728 {
729 if (curve2)
730 {
731 stp_curve_destroy(curve2);
732 curve2 = NULL;
733 }
734 TEST("GOOD curve");
735 if ((curve2 = stp_curve_create_from_string(good_curves[i])) != NULL)
736 {
737 TEST_PASS();
738 tmp = stp_curve_write_string(curve2);
739 TEST("whether XML curve is identical to original");
740 if (tmp && strcmp((const char *) tmp, good_curves[i]))
741 {
742 TEST_FAIL();
743 if (!quiet)
744 {
745 printf("XML:\n");
746 printf("%s", tmp);
747 printf("Original:\n");
748 printf("%s", good_curves[i]);
749 printf("End:\n");
750 }
751 }
752 else
753 {
754 TEST_PASS();
755 if (verbose)
756 printf("%s", tmp);
757 }
758 free(tmp);
759 }
760 else
761 TEST_FAIL();
762 }
763 if (curve2)
764 {
765 stp_curve_destroy(curve2);
766 curve2 = NULL;
767 }
768 if (verbose)
769 printf("Allocate 1\n");
770 curve1 = stp_curve_create(STP_CURVE_WRAP_NONE);
771 if (verbose)
772 printf("Allocate 2\n");
773 curve2 = stp_curve_create(STP_CURVE_WRAP_NONE);
774 TEST("set curve 1 gamma");
775 SIMPLE_TEST_CHECK(stp_curve_set_gamma(curve1, 1.2));
776 if (verbose)
777 stp_curve_write(stdout, curve1);
778 TEST("set curve 2 gamma");
779 SIMPLE_TEST_CHECK(stp_curve_set_gamma(curve2, -1.2));
780 if (verbose)
781 stp_curve_write(stdout, curve2);
782
783 TEST("compose add from gamma curves");
784 SIMPLE_TEST_CHECK(stp_curve_compose(&curve3, curve1, curve2,
785 STP_CURVE_COMPOSE_ADD, 64));
786 if (verbose && curve3)
787 stp_curve_write(stdout, curve3);
788
789 TEST("resample curve 1");
790 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 64));
791 if (verbose && curve1)
792 stp_curve_write(stdout, curve1);
793 if (curve3)
794 {
795 stp_curve_destroy(curve3);
796 curve3 = NULL;
797 }
798 TEST("compose multiply from gamma curves");
799 if (!stp_curve_compose(&curve3, curve1, curve2, STP_CURVE_COMPOSE_MULTIPLY, 64))
800 TEST_FAIL();
801 else
802 {
803 TEST_PASS();
804 if (verbose)
805 {
806 stp_curve_write(stdout, curve1);
807 stp_curve_write(stdout, curve2);
808 stp_curve_write(stdout, curve3);
809 }
810 }
811
812 TEST("compose add from non-gamma curves");
813 stp_curve_destroy(curve1);
814 stp_curve_destroy(curve2);
815 stp_curve_destroy(curve3);
816 curve1 = stp_curve_create_from_string(good_curves[0]);
817 curve2 = stp_curve_create_from_string(linear_curve_2);
818 SIMPLE_TEST_CHECK(stp_curve_compose(&curve3, curve1, curve2,
819 STP_CURVE_COMPOSE_ADD, 64));
820 if (verbose && curve3)
821 stp_curve_write(stdout, curve3);
822
823 TEST("resample curve 1");
824 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 64));
825 if (verbose && curve1)
826 stp_curve_write(stdout, curve1);
827 if (curve3)
828 {
829 stp_curve_destroy(curve3);
830 curve3 = NULL;
831 }
832 TEST("compose multiply from non-gamma curves");
833 if (!stp_curve_compose(&curve3, curve1, curve2, STP_CURVE_COMPOSE_MULTIPLY, 64))
834 TEST_FAIL();
835 else
836 {
837 TEST_PASS();
838 if (verbose)
839 {
840 stp_curve_write(stdout, curve1);
841 stp_curve_write(stdout, curve2);
842 stp_curve_write(stdout, curve3);
843 }
844 }
845 if (curve3)
846 {
847 stp_curve_destroy(curve3);
848 curve3 = NULL;
849 }
850
851 TEST("multiply rescale");
852 SIMPLE_TEST_CHECK(stp_curve_rescale(curve2, -1, STP_CURVE_COMPOSE_MULTIPLY,
853 STP_CURVE_BOUNDS_RESCALE));
854 if (verbose && curve2)
855 stp_curve_write(stdout, curve2);
856 TEST("subtract compose");
857 SIMPLE_TEST_CHECK(stp_curve_compose(&curve3, curve1, curve2,
858 STP_CURVE_COMPOSE_ADD, 64));
859 if (verbose && curve3)
860 stp_curve_write(stdout, curve3);
861
862 if (curve3)
863 {
864 stp_curve_destroy(curve3);
865 curve3 = NULL;
866 }
867 if (curve1)
868 {
869 stp_curve_destroy(curve1);
870 curve1 = NULL;
871 }
872 if (curve2)
873 {
874 stp_curve_destroy(curve2);
875 curve2 = NULL;
876 }
877
878 TEST("spline curve 1 creation");
879 SIMPLE_TEST_CHECK((curve1 = stp_curve_create_from_string(spline_curve_1)));
880 TEST("spline curve 2 creation");
881 SIMPLE_TEST_CHECK((curve2 = stp_curve_create_from_string(spline_curve_2)));
882 if (curve1)
883 {
884 if (verbose)
885 stp_curve_write(stdout, curve1);
886 TEST("spline curve 1 resample 1");
887 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 41));
888 if (verbose && curve1)
889 stp_curve_write(stdout, curve1);
890 TEST("spline curve 1 resample 2");
891 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 83));
892 if (verbose && curve1)
893 stp_curve_write(stdout, curve1);
894 }
895 if (curve2)
896 {
897 if (verbose)
898 stp_curve_write(stdout, curve2);
899 TEST("spline curve 2 resample");
900 SIMPLE_TEST_CHECK(stp_curve_resample(curve2, 48));
901 if (verbose && curve2)
902 stp_curve_write(stdout, curve2);
903 }
904 TEST("compose add (PASS is an expected failure)");
905 if (curve1 && curve2 &&
906 stp_curve_compose(&curve3, curve1, curve2, STP_CURVE_COMPOSE_MULTIPLY, -1))
907 {
908 TEST_FAIL();
909 if (!quiet)
910 printf("compose with different wrap mode should fail!\n");
911 }
912 else
913 TEST_PASS();
914 if (curve1)
915 {
916 stp_curve_destroy(curve1);
917 curve1 = NULL;
918 }
919 if (curve2)
920 {
921 stp_curve_destroy(curve2);
922 curve2 = NULL;
923 }
924
925 TEST("linear curve 1 creation");
926 SIMPLE_TEST_CHECK((curve1 = stp_curve_create_from_string(linear_curve_1)));
927 TEST("linear curve 2 creation");
928 SIMPLE_TEST_CHECK((curve2 = stp_curve_create_from_string(linear_curve_2)));
929
930 TEST("get data points of dense curve (PASS is an expected failure)");
931 curve_points = stp_curve_get_data_points(curve2, &count);
932 SIMPLE_TEST_CHECK(!curve_points);
933
934 if (curve1)
935 {
936 if (verbose)
937 stp_curve_write(stdout, curve1);
938 TEST("linear curve 1 resample");
939 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 41));
940 if (verbose && curve1)
941 stp_curve_write(stdout, curve1);
942 stp_curve_destroy(curve1);
943 curve1 = NULL;
944 }
945 if (curve2)
946 {
947 if (verbose)
948 stp_curve_write(stdout, curve2);
949 TEST("linear curve 2 resample");
950 SIMPLE_TEST_CHECK(stp_curve_resample(curve2, 48));
951 if (verbose && curve2)
952 stp_curve_write(stdout, curve2);
953 stp_curve_destroy(curve2);
954 curve2 = NULL;
955 }
956
957 curve1 = stp_curve_create(STP_CURVE_WRAP_AROUND);
958 stp_curve_set_interpolation_type(curve1, STP_CURVE_TYPE_SPLINE);
959 stp_curve_set_bounds(curve1, 0.0, 4.0);
960 stp_curve_set_data(curve1, 48, standard_sat_adjustment);
961 TEST("setting curve data");
962 SIMPLE_TEST_CHECK(curve1 && (stp_curve_count_points(curve1) == 48));
963 if (verbose)
964 stp_curve_write(stdout, curve1);
965 TEST("curve resample");
966 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 384));
967 if (verbose)
968 stp_curve_write(stdout, curve1);
969 TEST("very large curve resample");
970 SIMPLE_TEST_CHECK(stp_curve_resample(curve1, 65535));
971 TEST("offsetting large curve");
972 #if 0
973 stp_curve_get_range(curve1, &low, &high);
974 fprintf(stderr, "Result original max %f min %f\n", high, low);
975 stp_curve_get_bounds(curve1, &low, &high);
976 fprintf(stderr, "Bounds original max %f min %f\n", high, low);
977 #endif
978 SIMPLE_TEST_CHECK(stp_curve_rescale(curve1, 2.0, STP_CURVE_COMPOSE_ADD,
979 STP_CURVE_BOUNDS_RESCALE));
980
981 stp_curve_rescale(curve1, 1.0, STP_CURVE_COMPOSE_ADD,
982 STP_CURVE_BOUNDS_RESCALE);
983 stp_curve_get_bounds(curve1, &low, &high);
984 stp_curve_rescale(curve1, 0.0, STP_CURVE_COMPOSE_ADD,
985 STP_CURVE_BOUNDS_RESCALE);
986 stp_curve_get_bounds(curve1, &low, &high);
987 stp_curve_rescale(curve1, 0.0, STP_CURVE_COMPOSE_ADD,
988 STP_CURVE_BOUNDS_RESCALE);
989 stp_curve_get_bounds(curve1, &low, &high);
990 stp_curve_rescale(curve1, 0.0, STP_CURVE_COMPOSE_ADD,
991 STP_CURVE_BOUNDS_RESCALE);
992 stp_curve_get_bounds(curve1, &low, &high);
993 TEST("writing very large curve to string");
994 tmp = stp_curve_write_string(curve1);
995 if (tmp == NULL)
996 TEST_FAIL();
997 else
998 TEST_PASS();
999 if (tmp)
1000 {
1001 TEST("reading back very large curve");
1002 curve2 = stp_curve_create_from_string(tmp);
1003 SIMPLE_TEST_CHECK(stp_curve_count_points(curve2) == 65535);
1004
1005 free(tmp);
1006 TEST("Rescaling readback");
1007 SIMPLE_TEST_CHECK(stp_curve_rescale(curve2, -1.0,
1008 STP_CURVE_COMPOSE_MULTIPLY,
1009 STP_CURVE_BOUNDS_RESCALE));
1010 TEST("Adding curves");
1011 SIMPLE_TEST_CHECK(stp_curve_compose(&curve3, curve1, curve2,
1012 STP_CURVE_COMPOSE_ADD, 65535));
1013
1014 stp_curve_get_range(curve3, &low, &high);
1015 TEST("Comparing results");
1016 SIMPLE_TEST_CHECK(low < .00001 && low > -.00001 &&
1017 high < .00001 && high > -.00001);
1018
1019 if (curve1)
1020 {
1021 stp_curve_destroy(curve1);
1022 curve1 = NULL;
1023 }
1024 if (curve2)
1025 {
1026 stp_curve_destroy(curve2);
1027 curve2 = NULL;
1028 }
1029 }
1030
1031 TEST("Creating piecewise wrap-around curve");
1032 curve1 = stp_curve_create(STP_CURVE_WRAP_AROUND);
1033 stp_curve_set_bounds(curve1, 0.0, 4.0);
1034
1035 SIMPLE_TEST_CHECK(stp_curve_set_data_points
1036 (curve1, 48, reverse_piecewise_sat_adjustment));
1037
1038 TEST("Writing piecewise wrap-around curve to string");
1039 tmp = stp_curve_write_string(curve1);
1040 SIMPLE_TEST_CHECK(tmp);
1041 if (verbose)
1042 printf("%s\n", tmp);
1043 stp_free(tmp);
1044
1045 TEST("Check curve is piecewise");
1046 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1));
1047
1048 TEST("Create copy of piecewise curve");
1049 curve2 = stp_curve_create_copy(curve1);
1050 SIMPLE_TEST_CHECK(curve2);
1051
1052 TEST("Check copy is piecewise");
1053 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve2));
1054
1055 piecewise_curve_checks(curve1, 0, 48);
1056 stp_curve_rescale(curve1, -.5, STP_CURVE_COMPOSE_ADD,
1057 STP_CURVE_BOUNDS_RESCALE);
1058 piecewise_curve_checks(curve2, 3, 48);
1059
1060 TEST("Copy in place piecewise curve");
1061 stp_curve_copy(curve2, curve1);
1062 SIMPLE_TEST_CHECK(curve1 != NULL);
1063 piecewise_curve_checks(curve2, 10, 48);
1064 stp_curve_copy(curve2, curve1);
1065 piecewise_curve_checks(curve2, 15, 48);
1066 stp_curve_copy(curve2, curve1);
1067 piecewise_curve_checks(curve2, 47, 48);
1068 stp_curve_copy(curve2, curve1);
1069 piecewise_curve_checks(curve2, 48, 48);
1070 stp_curve_copy(curve2, curve1);
1071 piecewise_curve_checks(curve2, 49, 48);
1072 stp_curve_copy(curve2, curve1);
1073 piecewise_curve_checks(curve2, 50, 48);
1074 stp_curve_copy(curve2, curve1);
1075 piecewise_curve_checks(curve2, 100, 48);
1076 stp_curve_destroy(curve1);
1077 stp_curve_destroy(curve2);
1078
1079 TEST("Creating piecewise no-wrap curve with not enough data (PASS is an expected failure)");
1080 curve1 = stp_curve_create(STP_CURVE_WRAP_NONE);
1081 stp_curve_set_bounds(curve1, 0.0, 4.0);
1082 SIMPLE_TEST_CHECK(!stp_curve_set_data_points
1083 (curve1, 48, standard_piecewise_sat_adjustment));
1084
1085 TEST("Creating piecewise no-wrap curve correctly");
1086 SIMPLE_TEST_CHECK(stp_curve_set_data_points
1087 (curve1, 49, standard_piecewise_sat_adjustment));
1088
1089 TEST("Writing piecewise no-wrap curve to string");
1090 tmp = stp_curve_write_string(curve1);
1091 SIMPLE_TEST_CHECK(tmp);
1092 if (verbose)
1093 printf("%s\n", tmp);
1094 stp_free(tmp);
1095
1096 TEST("Check curve is piecewise");
1097 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1));
1098
1099 TEST("Create copy of piecewise curve");
1100 curve2 = stp_curve_create_copy(curve1);
1101 SIMPLE_TEST_CHECK(curve2);
1102 TEST("Check copy is piecewise");
1103 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve2));
1104
1105 piecewise_curve_checks(curve1, 0, 49);
1106 stp_curve_rescale(curve1, -.5, STP_CURVE_COMPOSE_ADD,
1107 STP_CURVE_BOUNDS_RESCALE);
1108 piecewise_curve_checks(curve2, 3, 49);
1109
1110 TEST("Copy in place piecewise curve");
1111 stp_curve_copy(curve2, curve1);
1112 SIMPLE_TEST_CHECK(curve1 != NULL);
1113 piecewise_curve_checks(curve2, 10, 49);
1114 stp_curve_copy(curve2, curve1);
1115 piecewise_curve_checks(curve2, 15, 49);
1116 stp_curve_copy(curve2, curve1);
1117 piecewise_curve_checks(curve2, 47, 49);
1118 stp_curve_copy(curve2, curve1);
1119 piecewise_curve_checks(curve2, 48, 49);
1120 stp_curve_copy(curve2, curve1);
1121 piecewise_curve_checks(curve2, 49, 49);
1122 stp_curve_copy(curve2, curve1);
1123 piecewise_curve_checks(curve2, 50, 49);
1124 stp_curve_copy(curve2, curve1);
1125 piecewise_curve_checks(curve2, 100, 49);
1126 stp_curve_destroy(curve2);
1127 stp_curve_destroy(curve1);
1128
1129 TEST("Creating piecewise spline wrap-around curve");
1130 curve1 = stp_curve_create(STP_CURVE_WRAP_AROUND);
1131 stp_curve_set_interpolation_type(curve1, STP_CURVE_TYPE_SPLINE);
1132 stp_curve_set_bounds(curve1, 0.0, 4.0);
1133
1134 SIMPLE_TEST_CHECK(stp_curve_set_data_points
1135 (curve1, 48, standard_piecewise_sat_adjustment));
1136
1137 TEST("Writing piecewise wrap-around curve to string");
1138 tmp = stp_curve_write_string(curve1);
1139 SIMPLE_TEST_CHECK(tmp);
1140 if (verbose)
1141 printf("%s\n", tmp);
1142 stp_free(tmp);
1143
1144 TEST("Check curve is piecewise");
1145 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1));
1146
1147 TEST("Create copy of piecewise curve");
1148 curve2 = stp_curve_create_copy(curve1);
1149 SIMPLE_TEST_CHECK(curve2);
1150 TEST("Check copy is piecewise");
1151 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve2));
1152
1153 piecewise_curve_checks(curve1, 0, 48);
1154 stp_curve_rescale(curve1, -.5, STP_CURVE_COMPOSE_ADD,
1155 STP_CURVE_BOUNDS_RESCALE);
1156 piecewise_curve_checks(curve2, 3, 48);
1157
1158 TEST("Copy in place piecewise curve");
1159 stp_curve_copy(curve2, curve1);
1160 SIMPLE_TEST_CHECK(curve1 != NULL);
1161 piecewise_curve_checks(curve2, 10, 48);
1162 stp_curve_copy(curve2, curve1);
1163 piecewise_curve_checks(curve2, 15, 48);
1164 stp_curve_copy(curve2, curve1);
1165 piecewise_curve_checks(curve2, 47, 48);
1166 stp_curve_copy(curve2, curve1);
1167 piecewise_curve_checks(curve2, 48, 48);
1168 stp_curve_copy(curve2, curve1);
1169 piecewise_curve_checks(curve2, 49, 48);
1170 stp_curve_copy(curve2, curve1);
1171 piecewise_curve_checks(curve2, 50, 48);
1172 stp_curve_copy(curve2, curve1);
1173 piecewise_curve_checks(curve2, 100, 48);
1174 stp_curve_destroy(curve1);
1175
1176 TEST("Creating piecewise spline wrap-around curve");
1177 curve1 = stp_curve_create(STP_CURVE_WRAP_NONE);
1178 stp_curve_set_interpolation_type(curve1, STP_CURVE_TYPE_SPLINE);
1179 stp_curve_set_bounds(curve1, 0.0, 4.0);
1180
1181 SIMPLE_TEST_CHECK(stp_curve_set_data_points
1182 (curve1, 49, standard_piecewise_sat_adjustment));
1183
1184 TEST("Writing piecewise no-wrap curve to string");
1185 tmp = stp_curve_write_string(curve1);
1186 SIMPLE_TEST_CHECK(tmp);
1187 if (verbose)
1188 printf("%s\n", tmp);
1189 stp_free(tmp);
1190
1191 TEST("Check curve is piecewise");
1192 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1));
1193
1194 if (curve2)
1195 {
1196 stp_curve_destroy(curve2);
1197 curve2 = NULL;
1198 }
1199 TEST("Create copy of piecewise curve");
1200 curve2 = stp_curve_create_copy(curve1);
1201 SIMPLE_TEST_CHECK(curve2);
1202 TEST("Check copy is piecewise");
1203 SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve2));
1204
1205 piecewise_curve_checks(curve1, 0, 49);
1206 stp_curve_rescale(curve1, -.5, STP_CURVE_COMPOSE_ADD,
1207 STP_CURVE_BOUNDS_RESCALE);
1208 piecewise_curve_checks(curve2, 3, 49);
1209
1210 TEST("Copy in place piecewise curve");
1211 stp_curve_copy(curve2, curve1);
1212 SIMPLE_TEST_CHECK(curve1 != NULL);
1213 piecewise_curve_checks(curve2, 10, 49);
1214 stp_curve_copy(curve2, curve1);
1215 piecewise_curve_checks(curve2, 15, 49);
1216 stp_curve_copy(curve2, curve1);
1217 piecewise_curve_checks(curve2, 47, 49);
1218 stp_curve_copy(curve2, curve1);
1219 piecewise_curve_checks(curve2, 48, 49);
1220 stp_curve_copy(curve2, curve1);
1221 piecewise_curve_checks(curve2, 49, 49);
1222 stp_curve_copy(curve2, curve1);
1223 piecewise_curve_checks(curve2, 50, 49);
1224 stp_curve_copy(curve2, curve1);
1225 piecewise_curve_checks(curve2, 100, 49);
1226 stp_curve_destroy(curve1);
1227
1228 TEST("Create small piecewise curve");
1229 curve1 = stp_curve_create_from_string(small_piecewise_curve);
1230 SIMPLE_TEST_CHECK(curve1);
1231
1232 stp_curve_destroy(curve1);
1233 curve1 = NULL;
1234 stp_curve_destroy(curve2);
1235 curve2 = NULL;
1236 stp_curve_destroy(curve3);
1237 curve3 = NULL;
1238
1239 if (global_error_count)
1240 {
1241 printf("%d/%d tests FAILED.\n", global_error_count, global_test_count);
1242 printf("Failures:\n");
1243 while (test_failure_head)
1244 {
1245 printf(" %3d\n", test_failure_head->test_number);
1246 test_failure_head = test_failure_head->next;
1247 }
1248 }
1249 else
1250 printf("All %d tests passed successfully.\n", global_test_count);
1251 return global_error_count ? 1 : 0;
1252 }