doc: update copyright line for 2019
[adg.git] / src / adg / tests / test-model.c
blobb8a72529ebc15dd41d64ae59bce1200eaa4cce8e
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2019 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_named_pair(void)
28 AdgModel *model;
29 CpmlPair valid_pair;
30 const CpmlPair *named_pair;
32 model = ADG_MODEL(adg_path_new());
33 valid_pair.x = -1234;
34 valid_pair.y = 4321;
36 adg_model_set_named_pair(model, "Existent", &valid_pair);
37 named_pair = adg_model_get_named_pair(model, "Existent");
38 g_assert_true(cpml_pair_equal(named_pair, &valid_pair));
40 named_pair = adg_model_get_named_pair(model, "Not existent");
41 g_assert_null(named_pair);
43 /* Using \u UTF-8 encoded "aeiou" with grave accents */
44 adg_model_set_named_pair(model, "UTF-8 name: \xc3\xa0\xc3\xa8\xc3\xac\xc3\xb2\xc3\xb9", &valid_pair);
46 named_pair = adg_model_get_named_pair(model, "UTF-8 name: \xc3\xa0\xc3\xa8\xc3\xac\xc3\xb2\xc3\xb9");
47 g_assert_true(cpml_pair_equal(named_pair, &valid_pair));
49 g_object_unref(model);
52 static void
53 _adg_property_dependency(void)
55 AdgModel *model;
56 AdgEntity *valid_entity, *invalid_entity;
57 const GSList *dependencies;
59 model = ADG_MODEL(adg_path_new());
60 valid_entity = ADG_ENTITY(adg_logo_new());
61 invalid_entity = adg_test_invalid_pointer();
63 /* There is no need to add a reference to keep valid_entity alive:
64 * the AdgModel implementation does not sink the dependencies, so
65 * at least one reference will be left */
67 /* Using the public APIs */
68 adg_model_add_dependency(model, NULL);
69 dependencies = adg_model_get_dependencies(model);
70 g_assert_null(dependencies);
72 adg_model_add_dependency(model, invalid_entity);
73 dependencies = adg_model_get_dependencies(model);
74 g_assert_null(dependencies);
76 adg_model_add_dependency(model, valid_entity);
77 dependencies = adg_model_get_dependencies(model);
78 g_assert_nonnull(dependencies);
79 g_assert_true(dependencies->data == valid_entity);
81 adg_model_remove_dependency(model, valid_entity);
82 dependencies = adg_model_get_dependencies(model);
83 g_assert_null(dependencies);
85 /* Using GObject property methods */
86 g_object_set(model, "dependency", NULL, NULL);
87 dependencies = adg_model_get_dependencies(model);
88 g_assert_null(dependencies);
90 g_object_set(model, "dependency", invalid_entity, NULL);
91 dependencies = adg_model_get_dependencies(model);
92 g_assert_null(dependencies);
94 g_object_set(model, "dependency", valid_entity, NULL);
95 dependencies = adg_model_get_dependencies(model);
96 g_assert_nonnull(dependencies);
97 g_assert_true(dependencies->data == valid_entity);
99 adg_model_remove_dependency(model, valid_entity);
100 dependencies = adg_model_get_dependencies(model);
101 g_assert_null(dependencies);
103 g_object_unref(model);
104 adg_entity_destroy(valid_entity);
109 main(int argc, char *argv[])
111 adg_test_init(&argc, &argv);
113 adg_test_add_object_checks("/adg/model/type/object", ADG_TYPE_MODEL);
114 adg_test_add_model_checks("/adg/model/type/model", ADG_TYPE_MODEL);
116 g_test_add_func("/adg/model/named-pair", _adg_property_named_pair);
117 g_test_add_func("/adg/model/dependency", _adg_property_dependency);
119 return g_test_run();