1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 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.
26 _adg_behavior_misc(void)
33 path
= adg_path_new();
34 adg_path_move_to_explicit(path
, 0, 5);
35 adg_path_line_to_explicit(path
, 1, 6);
36 adg_path_line_to_explicit(path
, 2, 3);
37 adg_path_line_to_explicit(path
, 3, 1);
38 adg_path_reflect(path
, NULL
);
40 edges
= adg_edges_new_with_source(ADG_TRAIL(path
));
42 /* Check repetition gives the same results */
43 for (n
= 0; n
< 2; ++n
) {
44 g_assert_true(adg_trail_put_segment(ADG_TRAIL(edges
), 1, &segment
));
45 g_assert_nonnull(segment
.data
);
46 g_assert_cmpint(segment
.num_data
, ==, 4);
47 g_assert_cmpint(segment
.data
[0].header
.type
, ==, CPML_MOVE
);
48 adg_assert_isapprox(segment
.data
[1].point
.x
, 1);
49 adg_assert_isapprox(segment
.data
[1].point
.y
, 6);
50 g_assert_cmpint(segment
.data
[2].header
.type
, ==, CPML_LINE
);
51 adg_assert_isapprox(segment
.data
[3].point
.x
, 1);
52 adg_assert_isapprox(segment
.data
[3].point
.y
, -6);
54 g_assert_true(cpml_segment_next(&segment
));
55 g_assert_nonnull(segment
.data
);
56 g_assert_cmpint(segment
.num_data
, ==, 4);
57 g_assert_cmpint(segment
.data
[0].header
.type
, ==, CPML_MOVE
);
58 adg_assert_isapprox(segment
.data
[1].point
.x
, 2);
59 adg_assert_isapprox(segment
.data
[1].point
.y
, 3);
60 g_assert_cmpint(segment
.data
[2].header
.type
, ==, CPML_LINE
);
61 adg_assert_isapprox(segment
.data
[3].point
.x
, 2);
62 adg_assert_isapprox(segment
.data
[3].point
.y
, -3);
64 g_assert_false(cpml_segment_next(&segment
));
67 /* Check that destroying path unsets the source property */
69 g_assert_null(adg_edges_get_source(edges
));
71 g_object_unref(edges
);
75 _adg_property_source(void)
78 AdgTrail
*valid_trail
, *invalid_trail
;
81 edges
= adg_edges_new();
82 valid_trail
= ADG_TRAIL(adg_path_new());
83 invalid_trail
= adg_test_invalid_pointer();
85 /* Using the public APIs */
86 adg_edges_set_source(edges
, valid_trail
);
87 source
= adg_edges_get_source(edges
);
88 g_assert_true(source
== valid_trail
);
90 adg_edges_set_source(edges
, invalid_trail
);
91 source
= adg_edges_get_source(edges
);
92 g_assert_true(source
== valid_trail
);
94 adg_edges_set_source(edges
, NULL
);
95 source
= adg_edges_get_source(edges
);
96 g_assert_null(source
);
98 /* Using GObject property methods */
99 g_object_set(edges
, "source", valid_trail
, NULL
);
100 g_object_get(edges
, "source", &source
, NULL
);
101 g_assert_true(source
== valid_trail
);
102 g_object_unref(source
);
104 g_object_set(edges
, "source", invalid_trail
, NULL
);
105 g_object_get(edges
, "source", &source
, NULL
);
106 g_assert_true(source
== valid_trail
);
107 g_object_unref(source
);
109 g_object_set(edges
, "source", NULL
, NULL
);
110 g_object_get(edges
, "source", &source
, NULL
);
111 g_assert_null(source
);
113 g_object_unref(edges
);
114 g_object_unref(valid_trail
);
118 _adg_property_axis_angle(void)
121 gdouble valid_value
, invalid_value
;
124 edges
= adg_edges_new();
125 valid_value
= G_PI
/ 10;
126 invalid_value
= G_PI
+ 1;
128 /* Using the public APIs */
129 adg_edges_set_axis_angle(edges
, valid_value
);
130 axis_angle
= adg_edges_get_axis_angle(edges
);
131 adg_assert_isapprox(axis_angle
, valid_value
);
133 adg_edges_set_axis_angle(edges
, invalid_value
);
134 axis_angle
= adg_edges_get_axis_angle(edges
);
135 g_assert_cmpfloat(axis_angle
, !=, invalid_value
);
137 /* Using GObject property methods */
138 g_object_set(edges
, "axis-angle", valid_value
, NULL
);
139 g_object_get(edges
, "axis-angle", &axis_angle
, NULL
);
140 adg_assert_isapprox(axis_angle
, valid_value
);
142 g_object_set(edges
, "axis-angle", invalid_value
, NULL
);
143 g_object_get(edges
, "axis-angle", &axis_angle
, NULL
);
144 g_assert_cmpfloat(axis_angle
, !=, invalid_value
);
146 g_object_unref(edges
);
150 _adg_property_critical_angle(void)
153 gdouble valid_value
, invalid_value
;
154 gdouble critical_angle
;
156 edges
= adg_edges_new();
157 valid_value
= G_PI
/ 10;
158 invalid_value
= G_PI
+ 1;
160 /* Using the public APIs */
161 adg_edges_set_critical_angle(edges
, valid_value
);
162 critical_angle
= adg_edges_get_critical_angle(edges
);
163 adg_assert_isapprox(critical_angle
, valid_value
);
165 adg_edges_set_critical_angle(edges
, invalid_value
);
166 critical_angle
= adg_edges_get_critical_angle(edges
);
167 g_assert_cmpfloat(critical_angle
, !=, invalid_value
);
169 /* Using GObject property methods */
170 g_object_set(edges
, "critical-angle", valid_value
, NULL
);
171 g_object_get(edges
, "critical-angle", &critical_angle
, NULL
);
172 adg_assert_isapprox(critical_angle
, valid_value
);
174 g_object_set(edges
, "critical-angle", invalid_value
, NULL
);
175 g_object_get(edges
, "critical-angle", &critical_angle
, NULL
);
176 g_assert_cmpfloat(critical_angle
, !=, invalid_value
);
178 g_object_unref(edges
);
183 main(int argc
, char *argv
[])
185 adg_test_init(&argc
, &argv
);
187 adg_test_add_object_checks("/adg/edges/type/object", ADG_TYPE_EDGES
);
188 adg_test_add_model_checks("/adg/edges/type/model", ADG_TYPE_EDGES
);
190 g_test_add_func("/adg/edges/behavior/misc", _adg_behavior_misc
);
192 g_test_add_func("/adg/edges/property/source", _adg_property_source
);
193 g_test_add_func("/adg/edges/property/axis-angle", _adg_property_axis_angle
);
194 g_test_add_func("/adg/edges/property/critical-angle", _adg_property_critical_angle
);