tests: add basic CpmlArc testing
[adg.git] / src / cpml / tests / test-arc.c
blob962a97e017fb35354e537f0b477451087d90d5df
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2017 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include <adg-test.h>
22 #include <cpml.h>
23 #include <math.h>
26 static cairo_path_data_t arc_data[] = {
27 { .header = { CPML_MOVE, 2 }},
28 { .point = { 0, 3 }},
30 { .header = { CPML_ARC, 3 }},
31 { .point = { 3, 0 }},
32 { .point = { 0, -3 }}
35 CpmlPrimitive arc = {
36 NULL,
37 &arc_data[1],
38 &arc_data[2]
42 static void
43 _cpml_sanity_info(gint i)
45 switch (i) {
46 case 1:
47 cpml_arc_info(NULL, NULL, NULL, NULL, NULL);
48 break;
49 default:
50 g_test_trap_assert_failed();
51 break;
55 static void
56 _cpml_sanity_to_cairo(gint i)
58 cairo_t *cr;
60 cr = adg_test_cairo_context();
62 switch (i) {
63 case 1:
64 cpml_arc_to_cairo(NULL, cr);
65 break;
66 case 2:
67 cpml_arc_to_cairo(&arc, NULL);
68 break;
69 default:
70 g_test_trap_assert_failed();
71 break;
74 cairo_destroy(cr);
77 static void
78 _cpml_sanity_to_curves(int i)
80 CpmlSegment segment;
82 switch (i) {
83 case 1:
84 cpml_arc_to_curves(NULL, &segment, 1);
85 break;
86 case 2:
87 cpml_arc_to_curves(&arc, NULL, 1);
88 break;
89 case 3:
90 cpml_arc_to_curves(&arc, &segment, 0);
91 break;
92 default:
93 g_test_trap_assert_failed();
94 break;
98 static void
99 _cpml_method_info(void)
101 CpmlPair center;
102 double r, start, end;
104 /* Passing NULL to the output arguments is valid */
105 g_assert_true(cpml_arc_info(&arc, NULL, NULL, NULL, NULL));
107 g_assert_true(cpml_arc_info(&arc, &center, &r, &start, &end));
109 adg_assert_isapprox(center.x, 0);
110 adg_assert_isapprox(center.y, 0);
111 adg_assert_isapprox(r, 3);
112 adg_assert_isapprox(start, M_PI_2);
113 adg_assert_isapprox(end, -M_PI_2);
119 main(int argc, char *argv[])
121 adg_test_init(&argc, &argv);
123 adg_test_add_traps("/cpml/arc/sanity/info", _cpml_sanity_info, 1);
124 adg_test_add_traps("/cpml/arc/sanity/to-cairo", _cpml_sanity_to_cairo, 2);
125 adg_test_add_traps("/cpml/arc/sanity/to-curves", _cpml_sanity_to_curves, 3);
127 g_test_add_func("/cpml/arc/method/info", _cpml_method_info);
129 return g_test_run();