1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010,2011 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"
25 _adg_test_named_pair(void)
29 const AdgPair
*named_pair
;
31 model
= ADG_MODEL(adg_path_new());
35 adg_model_set_named_pair(model
, "Existent", &valid_pair
);
36 named_pair
= adg_model_get_named_pair(model
, "Existent");
37 g_assert(cpml_pair_equal(named_pair
, &valid_pair
));
39 named_pair
= adg_model_get_named_pair(model
, "Not existent");
40 g_assert(named_pair
== NULL
);
42 adg_model_set_named_pair(model
, "Latin1: àèìòù", &valid_pair
);
43 named_pair
= adg_model_get_named_pair(model
, "Latin1: àèìòù");
44 g_assert(cpml_pair_equal(named_pair
, &valid_pair
));
46 g_object_unref(model
);
50 _adg_test_dependency(void)
53 AdgEntity
*valid_entity
, *invalid_entity
;
54 const GSList
*dependencies
;
56 model
= ADG_MODEL(adg_path_new());
57 valid_entity
= ADG_ENTITY(adg_logo_new());
58 invalid_entity
= adg_test_invalid_pointer();
60 /* There is no need to add a reference to keep valid_entity alive:
61 * the AdgModel implementation does not sink the dependencies, so
62 * at least one reference will be left */
64 /* Using the public APIs */
65 adg_model_add_dependency(model
, NULL
);
66 dependencies
= adg_model_get_dependencies(model
);
67 g_assert(dependencies
== NULL
);
69 adg_model_add_dependency(model
, invalid_entity
);
70 dependencies
= adg_model_get_dependencies(model
);
71 g_assert(dependencies
== NULL
);
73 adg_model_add_dependency(model
, valid_entity
);
74 dependencies
= adg_model_get_dependencies(model
);
75 g_assert(dependencies
!= NULL
);
76 g_assert(dependencies
->data
== valid_entity
);
78 adg_model_remove_dependency(model
, valid_entity
);
79 dependencies
= adg_model_get_dependencies(model
);
80 g_assert(dependencies
== NULL
);
82 /* Using GObject property methods */
83 g_object_set(model
, "dependency", NULL
, NULL
);
84 dependencies
= adg_model_get_dependencies(model
);
85 g_assert(dependencies
== NULL
);
87 g_object_set(model
, "dependency", invalid_entity
, NULL
);
88 dependencies
= adg_model_get_dependencies(model
);
89 g_assert(dependencies
== NULL
);
91 g_object_set(model
, "dependency", valid_entity
, NULL
);
92 dependencies
= adg_model_get_dependencies(model
);
93 g_assert(dependencies
!= NULL
);
94 g_assert(dependencies
->data
== valid_entity
);
96 adg_model_remove_dependency(model
, valid_entity
);
97 dependencies
= adg_model_get_dependencies(model
);
98 g_assert(dependencies
== NULL
);
100 g_object_unref(model
);
101 adg_entity_destroy(valid_entity
);
106 main(int argc
, char *argv
[])
108 adg_test_init(&argc
, &argv
);
110 adg_test_add_func("/adg/model/named-pair", _adg_test_named_pair
);
111 adg_test_add_func("/adg/model/dependency", _adg_test_dependency
);