doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-rdim.c
blob10a6e2d1f6b421476501976a7da7265f0441ea40
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.
21 #include <adg-test.h>
22 #include <adg.h>
25 static void
26 _adg_property_dim_dress(void)
28 AdgRDim *rdim;
30 /* Check that the dimension dress for AdgRDim instances is
31 * ADG_DRESS_DIMENSION by default */
32 rdim = adg_rdim_new();
33 g_assert_cmpint(adg_dim_get_dim_dress(ADG_DIM(rdim)), ==, ADG_DRESS_DIMENSION);
35 adg_entity_destroy(ADG_ENTITY(rdim));
38 static void
39 _adg_method_new_full_from_model(void)
41 AdgModel *model;
42 AdgDim *dim;
43 CpmlPair *pair;
45 model = ADG_MODEL(adg_path_new());
46 adg_model_set_named_pair_explicit(model, "P1", 1, 2);
47 adg_model_set_named_pair_explicit(model, "P2", 3, 4);
48 adg_model_set_named_pair_explicit(model, "P3", 5, 6);
50 /* Sanity check */
51 dim = ADG_DIM(adg_rdim_new_full_from_model(NULL, "P1", "P2", "P3"));
52 g_assert_null(dim);
55 /* The center point corresponds to AdgDim:ref1, the radius to
56 * AdgDim:ref2 and pos to AdgDim:pos */
57 dim = ADG_DIM(adg_rdim_new_full_from_model(model, NULL, NULL, NULL));
58 g_assert_nonnull(dim);
60 pair = (CpmlPair *) adg_dim_get_ref1(dim);
61 g_assert_null(pair);
63 pair = (CpmlPair *) adg_dim_get_ref2(dim);
64 g_assert_null(pair);
66 pair = (CpmlPair *) adg_dim_get_pos(dim);
67 g_assert_null(pair);
69 adg_entity_destroy(ADG_ENTITY(dim));
72 dim = ADG_DIM(adg_rdim_new_full_from_model(model, "P1", "P2", "P3"));
74 pair = (CpmlPair *) adg_dim_get_ref1(dim);
75 g_assert_nonnull(pair);
76 adg_assert_isapprox(pair->x, 0);
77 adg_assert_isapprox(pair->y, 0);
78 g_assert_true(adg_point_update((AdgPoint *) pair));
79 adg_assert_isapprox(pair->x, 1);
80 adg_assert_isapprox(pair->y, 2);
82 pair = (CpmlPair *) adg_dim_get_ref2(dim);
83 g_assert_nonnull(pair);
84 adg_assert_isapprox(pair->x, 0);
85 adg_assert_isapprox(pair->y, 0);
86 g_assert_true(adg_point_update((AdgPoint *) pair));
87 adg_assert_isapprox(pair->x, 3);
88 adg_assert_isapprox(pair->y, 4);
90 pair = (CpmlPair *) adg_dim_get_pos(dim);
91 g_assert_nonnull(pair);
92 adg_assert_isapprox(pair->x, 0);
93 adg_assert_isapprox(pair->y, 0);
94 g_assert_true(adg_point_update((AdgPoint *) pair));
95 adg_assert_isapprox(pair->x, 5);
96 adg_assert_isapprox(pair->y, 6);
98 /* Manually change all the points */
99 adg_dim_set_ref1_from_model(dim, model, "P3");
100 adg_dim_set_ref2_from_model(dim, model, "P1");
101 adg_dim_set_pos_from_model(dim, model, "P2");
103 /* The point will be updated only after an invalidate */
104 pair = (CpmlPair *) adg_dim_get_ref1(dim);
105 g_assert_nonnull(pair);
106 adg_assert_isapprox(pair->x, 0);
107 adg_assert_isapprox(pair->y, 0);
109 pair = (CpmlPair *) adg_dim_get_ref2(dim);
110 g_assert_nonnull(pair);
111 adg_assert_isapprox(pair->x, 0);
112 adg_assert_isapprox(pair->y, 0);
114 pair = (CpmlPair *) adg_dim_get_pos(dim);
115 g_assert_nonnull(pair);
116 adg_assert_isapprox(pair->x, 0);
117 adg_assert_isapprox(pair->y, 0);
119 adg_entity_arrange(ADG_ENTITY(dim));
121 pair = (CpmlPair *) adg_dim_get_ref1(dim);
122 g_assert_nonnull(pair);
123 adg_assert_isapprox(pair->x, 5);
124 adg_assert_isapprox(pair->y, 6);
126 pair = (CpmlPair *) adg_dim_get_ref2(dim);
127 g_assert_nonnull(pair);
128 adg_assert_isapprox(pair->x, 1);
129 adg_assert_isapprox(pair->y, 2);
131 pair = (CpmlPair *) adg_dim_get_pos(dim);
132 g_assert_nonnull(pair);
133 adg_assert_isapprox(pair->x, 3);
134 adg_assert_isapprox(pair->y, 4);
136 adg_entity_destroy(ADG_ENTITY(dim));
138 g_object_unref(model);
143 main(int argc, char *argv[])
145 adg_test_init(&argc, &argv);
147 adg_test_add_object_checks("/adg/rdim/type/object", ADG_TYPE_RDIM);
148 adg_test_add_entity_checks("/adg/rdim/type/entity", ADG_TYPE_RDIM);
150 adg_test_add_global_space_checks("/adg/rdim/behavior/global-space",
151 adg_rdim_new_full_explicit(1, 5, 2, 4, 9, 7));
152 /* Radial dimension does not enlarge on local space changes
153 * adg_test_add_local_space_checks("/adg/rdim/behavior/local-space",
154 * adg_rdim_new_full_explicit(1, 5, 2, 4, 9, 7));
157 g_test_add_func("/adg/adim/property/dim-dress", _adg_property_dim_dress);
159 g_test_add_func("/adg/rdim/method/new-full-from-model", _adg_method_new_full_from_model);
161 return g_test_run();