tests: include adg_rdim_new_full_from_model()
[adg.git] / src / adg / tests / test-rdim.c
blobf90d284746fbfaa2424c6630e42dd49713f834a2
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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 <adg.h>
25 static void
26 _adg_property_value(void)
28 AdgDim *dim;
29 const gchar *value;
31 dim = ADG_DIM(adg_rdim_new());
33 /* Check the default value (other options are checked by test-dim */
34 value = adg_dim_get_value(dim);
35 g_assert_cmpstr(value, ==, "R <>");
37 adg_entity_destroy(ADG_ENTITY(dim));
40 static void
41 _adg_method_new_full_from_model(void)
43 AdgModel *model;
44 AdgDim *dim;
45 CpmlPair *pair;
47 model = ADG_MODEL(adg_path_new());
48 adg_model_set_named_pair_explicit(model, "P1", 1, 2);
49 adg_model_set_named_pair_explicit(model, "P2", 3, 4);
50 adg_model_set_named_pair_explicit(model, "P3", 5, 6);
52 /* Sanity check */
53 dim = ADG_DIM(adg_rdim_new_full_from_model(NULL, "P1", "P2", "P3"));
54 g_assert_null(dim);
57 /* The center point corresponds to AdgDim:ref1, the radius to
58 * AdgDim:ref2 and pos to AdgDim:pos */
59 dim = ADG_DIM(adg_rdim_new_full_from_model(model, NULL, NULL, NULL));
60 g_assert_nonnull(dim);
62 pair = (CpmlPair *) adg_dim_get_ref1(dim);
63 g_assert_null(pair);
65 pair = (CpmlPair *) adg_dim_get_ref2(dim);
66 g_assert_null(pair);
68 pair = (CpmlPair *) adg_dim_get_pos(dim);
69 g_assert_null(pair);
71 adg_entity_destroy(ADG_ENTITY(dim));
74 dim = ADG_DIM(adg_rdim_new_full_from_model(model, "P1", "P2", "P3"));
76 pair = (CpmlPair *) adg_dim_get_ref1(dim);
77 g_assert_nonnull(pair);
78 adg_assert_isapprox(pair->x, 0);
79 adg_assert_isapprox(pair->y, 0);
80 g_assert_true(adg_point_update((AdgPoint *) pair));
81 adg_assert_isapprox(pair->x, 1);
82 adg_assert_isapprox(pair->y, 2);
84 pair = (CpmlPair *) adg_dim_get_ref2(dim);
85 g_assert_nonnull(pair);
86 adg_assert_isapprox(pair->x, 0);
87 adg_assert_isapprox(pair->y, 0);
88 g_assert_true(adg_point_update((AdgPoint *) pair));
89 adg_assert_isapprox(pair->x, 3);
90 adg_assert_isapprox(pair->y, 4);
92 pair = (CpmlPair *) adg_dim_get_pos(dim);
93 g_assert_nonnull(pair);
94 adg_assert_isapprox(pair->x, 0);
95 adg_assert_isapprox(pair->y, 0);
96 g_assert_true(adg_point_update((AdgPoint *) pair));
97 adg_assert_isapprox(pair->x, 5);
98 adg_assert_isapprox(pair->y, 6);
100 /* Manually change all the points */
101 adg_dim_set_ref1_from_model(dim, model, "P3");
102 adg_dim_set_ref2_from_model(dim, model, "P1");
103 adg_dim_set_pos_from_model(dim, model, "P2");
105 /* The point will be updated only after an invalidate */
106 pair = (CpmlPair *) adg_dim_get_ref1(dim);
107 g_assert_nonnull(pair);
108 adg_assert_isapprox(pair->x, 0);
109 adg_assert_isapprox(pair->y, 0);
111 pair = (CpmlPair *) adg_dim_get_ref2(dim);
112 g_assert_nonnull(pair);
113 adg_assert_isapprox(pair->x, 0);
114 adg_assert_isapprox(pair->y, 0);
116 pair = (CpmlPair *) adg_dim_get_pos(dim);
117 g_assert_nonnull(pair);
118 adg_assert_isapprox(pair->x, 0);
119 adg_assert_isapprox(pair->y, 0);
121 adg_entity_arrange(ADG_ENTITY(dim));
123 pair = (CpmlPair *) adg_dim_get_ref1(dim);
124 g_assert_nonnull(pair);
125 adg_assert_isapprox(pair->x, 5);
126 adg_assert_isapprox(pair->y, 6);
128 pair = (CpmlPair *) adg_dim_get_ref2(dim);
129 g_assert_nonnull(pair);
130 adg_assert_isapprox(pair->x, 1);
131 adg_assert_isapprox(pair->y, 2);
133 pair = (CpmlPair *) adg_dim_get_pos(dim);
134 g_assert_nonnull(pair);
135 adg_assert_isapprox(pair->x, 3);
136 adg_assert_isapprox(pair->y, 4);
138 adg_entity_destroy(ADG_ENTITY(dim));
140 g_object_unref(model);
145 main(int argc, char *argv[])
147 adg_test_init(&argc, &argv);
149 adg_test_add_object_checks("/adg/rdim/type/object", ADG_TYPE_RDIM);
150 adg_test_add_entity_checks("/adg/rdim/type/entity", ADG_TYPE_RDIM);
152 adg_test_add_global_space_checks("/adg/rdim/behavior/global-space",
153 adg_rdim_new_full_explicit(1, 5, 2, 4, 9, 7));
154 /* Radial dimension does not enlarge on local space changes
155 * adg_test_add_local_space_checks("/adg/rdim/behavior/local-space",
156 * adg_rdim_new_full_explicit(1, 5, 2, 4, 9, 7));
159 g_test_add_func("/adg/rdim/property/value", _adg_property_value);
161 g_test_add_func("/adg/rdim/method/new-full-from-model", _adg_method_new_full_from_model);
163 return g_test_run();