1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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.
26 _adg_test_named_pair(void)
30 const CpmlPair
*named_pair
;
32 model
= ADG_MODEL(adg_path_new());
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 adg_model_set_named_pair(model
, "Latin1: àèìòù", &valid_pair
);
44 named_pair
= adg_model_get_named_pair(model
, "Latin1: àèìòù");
45 g_assert_true(cpml_pair_equal(named_pair
, &valid_pair
));
47 g_object_unref(model
);
51 _adg_test_dependency(void)
54 AdgEntity
*valid_entity
, *invalid_entity
;
55 const GSList
*dependencies
;
57 model
= ADG_MODEL(adg_path_new());
58 valid_entity
= ADG_ENTITY(adg_logo_new());
59 invalid_entity
= adg_test_invalid_pointer();
61 /* There is no need to add a reference to keep valid_entity alive:
62 * the AdgModel implementation does not sink the dependencies, so
63 * at least one reference will be left */
65 /* Using the public APIs */
66 adg_model_add_dependency(model
, NULL
);
67 dependencies
= adg_model_get_dependencies(model
);
68 g_assert_null(dependencies
);
70 adg_model_add_dependency(model
, invalid_entity
);
71 dependencies
= adg_model_get_dependencies(model
);
72 g_assert_null(dependencies
);
74 adg_model_add_dependency(model
, valid_entity
);
75 dependencies
= adg_model_get_dependencies(model
);
76 g_assert_nonnull(dependencies
);
77 g_assert_true(dependencies
->data
== valid_entity
);
79 adg_model_remove_dependency(model
, valid_entity
);
80 dependencies
= adg_model_get_dependencies(model
);
81 g_assert_null(dependencies
);
83 /* Using GObject property methods */
84 g_object_set(model
, "dependency", NULL
, NULL
);
85 dependencies
= adg_model_get_dependencies(model
);
86 g_assert_null(dependencies
);
88 g_object_set(model
, "dependency", invalid_entity
, NULL
);
89 dependencies
= adg_model_get_dependencies(model
);
90 g_assert_null(dependencies
);
92 g_object_set(model
, "dependency", valid_entity
, NULL
);
93 dependencies
= adg_model_get_dependencies(model
);
94 g_assert_nonnull(dependencies
);
95 g_assert_true(dependencies
->data
== valid_entity
);
97 adg_model_remove_dependency(model
, valid_entity
);
98 dependencies
= adg_model_get_dependencies(model
);
99 g_assert_null(dependencies
);
101 g_object_unref(model
);
102 adg_entity_destroy(valid_entity
);
107 main(int argc
, char *argv
[])
109 adg_test_init(&argc
, &argv
);
111 adg_test_add_func("/adg/model/named-pair", _adg_test_named_pair
);
112 adg_test_add_func("/adg/model/dependency", _adg_test_dependency
);