[tests] Prefixed internal functions with _adg_
[adg.git] / tests / test-model.c
blob1d34f066c95aa64226c47a5e877c24d5acd7d75d
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_named_pair(void)
27 AdgModel *model;
28 AdgPair pair;
29 const AdgPair *got_pair;
31 model = ADG_MODEL(adg_path_new());
32 pair.x = -1234;
33 pair.y = 4321;
35 adg_model_set_named_pair(model, "Existent", &pair);
36 got_pair = adg_model_get_named_pair(model, "Existent");
37 g_assert_cmpint(pair.x, ==, got_pair->x);
38 g_assert_cmpint(pair.y, ==, got_pair->y);
40 got_pair = adg_model_get_named_pair(model, "Not existent");
41 g_assert(got_pair == NULL);
43 adg_model_set_named_pair(model, "Latin1: àèìòù", &pair);
44 got_pair = adg_model_get_named_pair(model, "Latin1: àèìòù");
45 g_assert_cmpint(pair.x, ==, got_pair->x);
46 g_assert_cmpint(pair.y, ==, got_pair->y);
48 g_object_unref(model);
51 static void
52 _adg_test_dependency(void)
54 AdgModel *model;
55 AdgEntity *valid_entity, *invalid_entity;
56 const GSList *dependencies;
58 model = ADG_MODEL(adg_path_new());
59 valid_entity = ADG_ENTITY(adg_logo_new());
60 invalid_entity = adg_test_invalid_pointer();
62 /* Using the public APIs */
63 adg_model_add_dependency(model, NULL);
64 dependencies = adg_model_get_dependencies(model);
65 g_assert(dependencies == NULL);
67 adg_model_add_dependency(model, invalid_entity);
68 dependencies = adg_model_get_dependencies(model);
69 g_assert(dependencies == NULL);
71 adg_model_add_dependency(model, valid_entity);
72 dependencies = adg_model_get_dependencies(model);
73 g_assert(dependencies != NULL);
74 g_assert(dependencies->data == valid_entity);
76 adg_model_remove_dependency(model, valid_entity);
77 dependencies = adg_model_get_dependencies(model);
78 g_assert(dependencies == NULL);
80 /* Using GObject property methods */
81 g_object_set(model, "dependency", NULL, NULL);
82 dependencies = adg_model_get_dependencies(model);
83 g_assert(dependencies == NULL);
85 g_object_set(model, "dependency", invalid_entity, NULL);
86 dependencies = adg_model_get_dependencies(model);
87 g_assert(dependencies == NULL);
89 g_object_set(model, "dependency", valid_entity, NULL);
90 dependencies = adg_model_get_dependencies(model);
91 g_assert(dependencies != NULL);
92 g_assert(dependencies->data == valid_entity);
94 adg_model_remove_dependency(model, valid_entity);
95 dependencies = adg_model_get_dependencies(model);
96 g_assert(dependencies == NULL);
98 g_object_unref(model);
99 g_object_unref(valid_entity);
104 main(int argc, char *argv[])
106 adg_test_init(&argc, &argv);
108 g_test_add_func("/adg/model/named-pair", _adg_test_named_pair);
109 g_test_add_func("/adg/model/dependency", _adg_test_dependency);
111 return g_test_run();