AdgEntity: added "destroy" signal
[adg.git] / src / adg / tests / test-container.c
blob167f6d7ea05e9b17c39d474a12bfce7efa97dbc0
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"
24 static void
25 _adg_property_child(void)
27 AdgContainer *container;
28 AdgEntity *valid_entity, *invalid_entity;
29 GSList *children;
31 container = adg_container_new();
32 valid_entity = ADG_ENTITY(adg_logo_new());
33 invalid_entity = adg_test_invalid_pointer();
35 /* Keep alive the entity between all the tests */
36 g_object_ref(valid_entity);
38 /* Using the public APIs */
39 adg_container_add(container, NULL);
40 children = adg_container_children(container);
41 g_assert(children == NULL);
43 adg_container_add(container, invalid_entity);
44 children = adg_container_children(container);
45 g_assert(children == NULL);
47 adg_container_add(container, valid_entity);
48 children = adg_container_children(container);
49 g_assert(children != NULL);
50 g_assert(children->data == valid_entity);
51 g_slist_free(children);
53 adg_container_remove(container, invalid_entity);
54 children = adg_container_children(container);
55 g_assert(children != NULL);
56 g_assert(children->data == valid_entity);
57 g_slist_free(children);
59 adg_container_remove(container, valid_entity);
60 children = adg_container_children(container);
61 g_assert(children == NULL);
63 /* Using GObject property methods */
64 g_object_set(container, "child", NULL, NULL);
65 children = adg_container_children(container);
66 g_assert(children == NULL);
68 g_object_set(container, "child", invalid_entity, NULL);
69 children = adg_container_children(container);
70 g_assert(children == NULL);
72 g_object_set(container, "child", valid_entity, NULL);
73 children = adg_container_children(container);
74 g_assert(children != NULL);
75 g_assert(children->data == valid_entity);
76 g_slist_free(children);
78 adg_container_remove(container, valid_entity);
79 children = adg_container_children(container);
80 g_assert(children == NULL);
82 adg_entity_destroy(ADG_ENTITY(container));
83 adg_entity_destroy(valid_entity);
86 static void
87 _adg_misc(void)
89 AdgContainer *container;
90 AdgEntity *entity1, *entity2;
91 GSList *children;
93 container = adg_container_new();
94 entity1 = ADG_ENTITY(adg_toy_text_new("Testing..."));
95 entity2 = ADG_ENTITY(adg_title_block_new());
97 children = adg_container_children(container);
98 g_assert(children == NULL);
100 adg_container_add(container, entity1);
101 children = adg_container_children(container);
102 g_assert(children != NULL);
103 g_assert_cmpint(g_slist_length(children), ==, 1);
104 g_slist_free(children);
106 adg_container_add(container, entity2);
107 children = adg_container_children(container);
108 g_assert(children != NULL);
109 g_assert_cmpint(g_slist_length(children), ==, 2);
110 g_slist_free(children);
112 adg_entity_destroy(entity1);
113 children = adg_container_children(container);
114 g_assert(children != NULL);
115 g_assert_cmpint(g_slist_length(children), ==, 1);
116 g_slist_free(children);
118 adg_entity_destroy(entity2);
119 children = adg_container_children(container);
120 g_assert(children == NULL);
122 adg_entity_destroy(ADG_ENTITY(container));
127 main(int argc, char *argv[])
129 adg_test_init(&argc, &argv);
131 adg_test_add_func("/adg/container/property/child", _adg_property_child);
132 adg_test_add_func("/adg/container/misc", _adg_misc);
134 return g_test_run();