build: depends on cairo-gobject if introspection is enabled
[adg.git] / src / adg / tests / test-edges.c
blobbd3905ed687c0364c4ed4f83cada8c671f4a9db3
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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 "test-internal.h"
24 static void
25 _adg_test_source(void)
27 AdgEdges *edges;
28 AdgTrail *valid_trail, *invalid_trail;
29 AdgTrail *source;
31 edges = adg_edges_new();
32 valid_trail = ADG_TRAIL(adg_path_new());
33 invalid_trail = adg_test_invalid_pointer();
35 /* Using the public APIs */
36 adg_edges_set_source(edges, valid_trail);
37 source = adg_edges_get_source(edges);
38 g_assert(source == valid_trail);
40 adg_edges_set_source(edges, invalid_trail);
41 source = adg_edges_get_source(edges);
42 g_assert(source == valid_trail);
44 adg_edges_set_source(edges, NULL);
45 source = adg_edges_get_source(edges);
46 g_assert(source == NULL);
48 /* Using GObject property methods */
49 g_object_set(edges, "source", valid_trail, NULL);
50 g_object_get(edges, "source", &source, NULL);
51 g_assert(source == valid_trail);
52 g_object_unref(source);
54 g_object_set(edges, "source", invalid_trail, NULL);
55 g_object_get(edges, "source", &source, NULL);
56 g_assert(source == valid_trail);
57 g_object_unref(source);
59 g_object_set(edges, "source", NULL, NULL);
60 g_object_get(edges, "source", &source, NULL);
61 g_assert(source == NULL);
63 g_object_unref(edges);
64 g_object_unref(valid_trail);
67 static void
68 _adg_test_axis_angle(void)
70 AdgEdges *edges;
71 gdouble valid_value, invalid_value;
72 gdouble axis_angle;
74 edges = adg_edges_new();
75 valid_value = G_PI / 10;
76 invalid_value = G_PI + 1;
78 /* Using the public APIs */
79 adg_edges_set_axis_angle(edges, valid_value);
80 axis_angle = adg_edges_get_axis_angle(edges);
81 g_assert_cmpfloat(axis_angle, ==, valid_value);
83 adg_edges_set_axis_angle(edges, invalid_value);
84 axis_angle = adg_edges_get_axis_angle(edges);
85 g_assert_cmpfloat(axis_angle, !=, invalid_value);
87 /* Using GObject property methods */
88 g_object_set(edges, "axis-angle", valid_value, NULL);
89 g_object_get(edges, "axis-angle", &axis_angle, NULL);
90 g_assert_cmpfloat(axis_angle, ==, valid_value);
92 g_object_set(edges, "axis-angle", invalid_value, NULL);
93 g_object_get(edges, "axis-angle", &axis_angle, NULL);
94 g_assert_cmpfloat(axis_angle, !=, invalid_value);
96 g_object_unref(edges);
99 static void
100 _adg_test_critical_angle(void)
102 AdgEdges *edges;
103 gdouble valid_value, invalid_value;
104 gdouble critical_angle;
106 edges = adg_edges_new();
107 valid_value = G_PI / 10;
108 invalid_value = G_PI + 1;
110 /* Using the public APIs */
111 adg_edges_set_critical_angle(edges, valid_value);
112 critical_angle = adg_edges_get_critical_angle(edges);
113 g_assert_cmpfloat(critical_angle, ==, valid_value);
115 adg_edges_set_critical_angle(edges, invalid_value);
116 critical_angle = adg_edges_get_critical_angle(edges);
117 g_assert_cmpfloat(critical_angle, !=, invalid_value);
119 /* Using GObject property methods */
120 g_object_set(edges, "critical-angle", valid_value, NULL);
121 g_object_get(edges, "critical-angle", &critical_angle, NULL);
122 g_assert_cmpfloat(critical_angle, ==, valid_value);
124 g_object_set(edges, "critical-angle", invalid_value, NULL);
125 g_object_get(edges, "critical-angle", &critical_angle, NULL);
126 g_assert_cmpfloat(critical_angle, !=, invalid_value);
128 g_object_unref(edges);
133 main(int argc, char *argv[])
135 adg_test_init(&argc, &argv);
137 adg_test_add_func("/adg/edges/source", _adg_test_source);
138 adg_test_add_func("/adg/edges/axis-angle", _adg_test_axis_angle);
139 adg_test_add_func("/adg/edges/critical-angle", _adg_test_critical_angle);
141 return g_test_run();