[AdgFontStyle] Returning AdgFontStyle * from constructors
[adg.git] / adg / tests / test-adim.c
blob1d08d9b6bb7ad5430bf646b1e8c8dbc7774fc685
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010 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_org1(void)
27 AdgADim *adim;
28 AdgModel *model;
29 AdgPoint *origin, *explicit_point, *model_point;
30 AdgPoint *org1;
32 adim = adg_adim_new();
33 model = ADG_MODEL(adg_path_new());
34 origin = adg_point_new();
35 explicit_point = adg_point_new();
36 model_point = adg_point_new();
38 adg_point_set_pair_explicit(origin, 0, 0);
39 adg_point_set_pair_explicit(explicit_point, 123, 321);
40 adg_model_set_named_pair(model, "named-pair",
41 adg_point_get_pair(explicit_point));
42 adg_point_set_pair_from_model(model_point, model, "named-pair");
44 /* Ensure ADG does not consider an explicit point equals to
45 * a point bound to a named pair with the same coordinates */
46 g_assert(!adg_point_equal(explicit_point, model_point));
48 org1 = adg_adim_get_org1(adim);
49 g_assert(org1 == NULL);
51 /* Using the public APIs */
52 adg_adim_set_org1_explicit(adim, 0, 0);
53 org1 = adg_adim_get_org1(adim);
54 g_assert(adg_point_equal(org1, origin));
56 adg_adim_set_org1(adim, NULL);
57 org1 = adg_adim_get_org1(adim);
58 g_assert(org1 == NULL);
60 adg_adim_set_org1(adim, explicit_point);
61 org1 = adg_adim_get_org1(adim);
62 g_assert(adg_point_equal(org1, explicit_point));
64 /* Checking the lazy assignment feature */
65 adg_adim_set_org1_from_model(adim, model, "dummy");
66 org1 = adg_adim_get_org1(adim);
67 g_assert(org1 != NULL);
68 g_assert(adg_point_get_pair(org1) == NULL);
70 adg_adim_set_org1_from_model(adim, model, "named-pair");
71 org1 = adg_adim_get_org1(adim);
72 g_assert(adg_point_equal(org1, model_point));
74 /* Using GObject property methods */
75 g_object_set(adim, "org1", origin, NULL);
76 g_object_get(adim, "org1", &org1, NULL);
77 g_assert(adg_point_equal(org1, origin));
78 adg_point_destroy(org1);
80 g_object_set(adim, "org1", NULL, NULL);
81 g_object_get(adim, "org1", &org1, NULL);
82 g_assert(org1 == NULL);
84 g_object_set(adim, "org1", explicit_point, NULL);
85 g_object_get(adim, "org1", &org1, NULL);
86 g_assert(adg_point_equal(org1, explicit_point));
87 adg_point_destroy(org1);
89 /* Checking the lazy assignment feature */
90 adg_adim_set_org1_from_model(adim, model, "dummy");
91 g_object_get(adim, "org1", &org1, NULL);
92 g_assert(org1 != NULL);
93 g_assert(adg_point_get_pair(org1) == NULL);
94 adg_point_destroy(org1);
96 g_object_set(adim, "org1", model_point, NULL);
97 g_object_get(adim, "org1", &org1, NULL);
98 g_assert(adg_point_equal(org1, model_point));
99 adg_point_destroy(org1);
101 adg_point_destroy(origin);
102 adg_point_destroy(explicit_point);
103 adg_point_destroy(model_point);
104 g_object_unref(adim);
105 g_object_unref(model);
108 static void
109 _adg_test_org2(void)
111 AdgADim *adim;
112 AdgModel *model;
113 AdgPoint *origin, *explicit_point, *model_point;
114 AdgPoint *org2;
116 adim = adg_adim_new();
117 model = ADG_MODEL(adg_path_new());
118 origin = adg_point_new();
119 explicit_point = adg_point_new();
120 model_point = adg_point_new();
122 adg_point_set_pair_explicit(origin, 0, 0);
123 adg_point_set_pair_explicit(explicit_point, 123, 321);
124 adg_model_set_named_pair(model, "named-pair",
125 adg_point_get_pair(explicit_point));
126 adg_point_set_pair_from_model(model_point, model, "named-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 org2 = adg_adim_get_org2(adim);
133 g_assert(org2 == NULL);
135 /* Using the public APIs */
136 adg_adim_set_org2_explicit(adim, 0, 0);
137 org2 = adg_adim_get_org2(adim);
138 g_assert(adg_point_equal(org2, origin));
140 adg_adim_set_org2(adim, NULL);
141 org2 = adg_adim_get_org2(adim);
142 g_assert(org2 == NULL);
144 adg_adim_set_org2(adim, explicit_point);
145 org2 = adg_adim_get_org2(adim);
146 g_assert(adg_point_equal(org2, explicit_point));
148 /* Checking the lazy assignment feature */
149 adg_adim_set_org2_from_model(adim, model, "dummy");
150 org2 = adg_adim_get_org2(adim);
151 g_assert(org2 != NULL);
152 g_assert(adg_point_get_pair(org2) == NULL);
154 adg_adim_set_org2_from_model(adim, model, "named-pair");
155 org2 = adg_adim_get_org2(adim);
156 g_assert(adg_point_equal(org2, model_point));
158 /* Using GObject property methods */
159 g_object_set(adim, "org2", origin, NULL);
160 g_object_get(adim, "org2", &org2, NULL);
161 g_assert(adg_point_equal(org2, origin));
162 adg_point_destroy(org2);
164 g_object_set(adim, "org2", NULL, NULL);
165 g_object_get(adim, "org2", &org2, NULL);
166 g_assert(org2 == NULL);
168 g_object_set(adim, "org2", explicit_point, NULL);
169 g_object_get(adim, "org2", &org2, NULL);
170 g_assert(adg_point_equal(org2, explicit_point));
171 adg_point_destroy(org2);
173 /* Checking the lazy assignment feature */
174 adg_adim_set_org2_from_model(adim, model, "dummy");
175 g_object_get(adim, "org2", &org2, NULL);
176 g_assert(org2 != NULL);
177 g_assert(adg_point_get_pair(org2) == NULL);
178 adg_point_destroy(org2);
180 g_object_set(adim, "org2", model_point, NULL);
181 g_object_get(adim, "org2", &org2, NULL);
182 g_assert(adg_point_equal(org2, model_point));
183 adg_point_destroy(org2);
185 adg_point_destroy(origin);
186 adg_point_destroy(explicit_point);
187 adg_point_destroy(model_point);
188 g_object_unref(adim);
189 g_object_unref(model);
194 main(int argc, char *argv[])
196 adg_test_init(&argc, &argv);
198 adg_test_add_func("/adg/adim/org1", _adg_test_org1);
199 adg_test_add_func("/adg/adim/org2", _adg_test_org2);
201 return g_test_run();