build: depends on cairo-gobject if introspection is enabled
[adg.git] / src / adg / tests / test-point.c
blob3da0d874bb08853557f09b0e0eb647a7fbaec263
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_generic(void)
27 AdgPoint *point, *dup_point;
28 CpmlPair *pair, *dup_pair;
29 CpmlPair dummy_pair = { 3.4, 5.6 };
31 point = adg_point_new();
32 g_assert(point != NULL);
34 adg_point_set_pair_explicit(point, 1, 2);
35 pair = (CpmlPair *) point;
36 g_assert_cmpfloat(pair->x, ==, 1);
37 g_assert_cmpfloat(pair->y, ==, 2);
39 pair = adg_point_get_pair(point);
40 g_assert(pair != NULL);
41 g_assert_cmpfloat(pair->x, ==, 1);
42 g_assert_cmpfloat(pair->y, ==, 2);
44 dup_point = adg_point_dup(point);
45 g_assert(dup_point != NULL);
46 g_assert(dup_point != point);
48 /* Should be a noop with explicit pairs */
49 adg_point_invalidate(point);
51 dup_pair = adg_point_get_pair(dup_point);
52 g_assert(dup_pair != NULL);
53 g_assert(dup_pair != pair);
55 g_assert_cmpfloat(pair->x, ==, dup_pair->x);
56 g_assert_cmpfloat(pair->y, ==, dup_pair->y);
57 g_assert(adg_point_equal(point, dup_point));
59 g_free(dup_pair);
60 adg_point_destroy(dup_point);
62 dup_point = adg_point_new();
63 adg_point_set_pair(dup_point, &dummy_pair);
64 dup_pair = (CpmlPair *) dup_point;
66 /* Should be a noop with explicit pairs */
67 adg_point_invalidate(dup_point);
69 g_assert_cmpfloat(dup_pair->x, ==, 3.4);
70 g_assert_cmpfloat(dup_pair->y, ==, 5.6);
71 g_assert(! adg_point_equal(point, dup_point));
73 adg_point_copy(dup_point, point);
74 dup_pair = adg_point_get_pair(dup_point);
75 g_assert(dup_pair != NULL);
76 g_assert(dup_pair != pair);
78 g_assert_cmpfloat(pair->x, ==, dup_pair->x);
79 g_assert_cmpfloat(pair->y, ==, dup_pair->y);
80 g_assert(adg_point_equal(point, dup_point));
82 g_free(pair);
83 g_free(dup_pair);
84 adg_point_destroy(point);
85 adg_point_destroy(dup_point);
88 static void
89 _adg_test_named_pair(void)
91 CpmlPair p1 = { 123, 456 };
92 AdgPoint *explicit_point, *explicit_point2, *model_point;
93 AdgModel *model;
94 CpmlPair *pair;
96 explicit_point = adg_point_new();
97 g_assert(explicit_point != NULL);
98 adg_point_set_pair(explicit_point, &p1);
100 explicit_point2 = adg_point_new();
101 g_assert(explicit_point2 != NULL);
102 adg_point_set_pair_explicit(explicit_point2, p1.x, p1.y);
104 /* Checking comparison APIs */
105 g_assert(adg_point_equal(explicit_point, explicit_point2));
106 adg_point_set_pair_explicit(explicit_point2, 78, 90);
107 g_assert(! adg_point_equal(explicit_point, explicit_point2));
108 pair = (CpmlPair *) explicit_point2;
109 g_assert_cmpfloat(pair->x, ==, 78);
110 g_assert_cmpfloat(pair->y, ==, 90);
112 pair = adg_point_get_pair(explicit_point);
113 g_assert(cpml_pair_equal(pair, &p1));
114 g_free(pair);
116 model = ADG_MODEL(adg_path_new());
117 g_assert(model != NULL);
118 adg_model_set_named_pair(model, "named-pair", &p1);
120 model_point = adg_point_new();
121 g_assert(model_point != NULL);
122 adg_point_set_pair_from_model(model_point, model, "named-pair");
124 pair = adg_point_get_pair(model_point);
125 g_assert(cpml_pair_equal(pair, &p1));
126 g_free(pair);
128 /* Ensure ADG does not consider an explicit point equals to
129 * a point bound to a named pair with the same coordinates */
130 g_assert(! adg_point_equal(explicit_point, model_point));
132 /* Check for lazy evaluation of named pairs */
133 adg_point_set_pair_from_model(model_point, model, "unexistent-pair");
134 pair = (CpmlPair *) model_point;
135 g_assert_cmpfloat(pair->x, ==, p1.x);
136 g_assert_cmpfloat(pair->y, ==, p1.y);
138 /* Check behavior on undefined named pair */
139 g_assert(! adg_point_update(model_point));
140 g_assert(adg_point_get_pair(model_point) == NULL);
142 adg_point_set_pair_from_model(model_point, model, "named-pair");
143 g_assert(adg_point_update(model_point));
145 /* Check for case sensitiveness */
146 adg_point_set_pair_from_model(model_point, model, "Named-Pair");
147 g_assert(adg_point_get_pair(model_point) == NULL);
148 g_assert(! adg_point_update(model_point));
150 /* Check if adg_point_get_pair() triggers an adg_point_update() */
151 adg_point_set_pair_from_model(model_point, model, "named-pair");
152 pair = adg_point_get_pair(model_point);
153 g_assert(cpml_pair_equal(pair, &p1));
154 g_free(pair);
156 adg_point_destroy(explicit_point);
157 adg_point_destroy(model_point);
158 g_object_unref(model);
163 main(int argc, char *argv[])
165 adg_test_init(&argc, &argv);
167 adg_test_add_func("/adg/point/generic", _adg_test_generic);
168 adg_test_add_func("/adg/point/named-pair", _adg_test_named_pair);
170 return g_test_run();