doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-table-cell.c
blobe1bf974dc84597414eedb5010aba0e702aff85e4
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 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_behavior_misc(void)
28 AdgTable *table;
29 AdgTableRow *row;
30 AdgTableCell *cell;
32 table = adg_table_new();
33 row = adg_table_row_new(table);
35 /* Sanity check */
36 g_assert_null(adg_table_cell_dup(NULL));
37 g_assert_null(adg_table_cell_new(NULL));
38 g_assert_null(adg_table_cell_new_before(NULL));
39 g_assert_null(adg_table_cell_new_with_width(NULL, 123));
40 g_assert_null(adg_table_cell_new_full(NULL, 123, NULL, NULL, FALSE));
41 g_assert_null(adg_table_cell_get_row(NULL));
42 g_assert_null(adg_table_cell_get_table(NULL));
43 adg_table_cell_dispose(NULL);
44 adg_table_cell_free(NULL);
46 /* Check default constructor */
47 cell = adg_table_cell_new(row);
48 g_assert_nonnull(cell);
49 g_assert_true(adg_table_cell_get_row(cell) == row);
50 g_assert_true(adg_table_cell_get_table(cell) == table);
52 /* Check dependent construction */
53 g_assert_nonnull(adg_table_cell_dup(cell));
54 g_assert_nonnull(adg_table_cell_new_before(cell));
56 /* Check default destructor: other AdgTableCell instances will be
57 * implicitely destroyed when the parent AdgTable is destroyed */
58 adg_table_cell_free(cell);
60 /* Check alternative valid construction conditions */
61 g_assert_nonnull(adg_table_cell_new_with_width(row, 0));
62 g_assert_nonnull(adg_table_cell_new_with_width(row, 123));
63 g_assert_nonnull(adg_table_cell_new_full(row, 12, "name", "title", FALSE));
64 g_assert_nonnull(adg_table_cell_new_full(row, 34, NULL, "title", TRUE));
65 g_assert_nonnull(adg_table_cell_new_full(row, 56, "name", NULL, FALSE));
66 g_assert_nonnull(adg_table_cell_new_full(row, 78, NULL, NULL, TRUE));
67 g_assert_nonnull(adg_table_cell_new_full(row, 0, NULL, NULL, TRUE));
69 /* Check invalid conditions */
70 g_assert_null(adg_table_cell_new_with_width(row, -1));
71 g_assert_null(adg_table_cell_new_full(row, -1, NULL, NULL, TRUE));
73 adg_entity_destroy(ADG_ENTITY(table));
76 static void
77 _adg_property_title(void)
79 AdgTable *table;
80 AdgTableRow *row;
81 AdgTableCell *cell;
82 AdgEntity *entity;
84 table = adg_table_new();
85 row = adg_table_row_new(table);
86 cell = adg_table_cell_new(row);
87 entity = ADG_ENTITY(adg_logo_new());
89 /* Sanity check */
90 g_assert_null(adg_table_cell_title(NULL));
91 adg_table_cell_set_title(NULL, NULL);
92 adg_table_cell_set_title(NULL, entity);
94 /* A newly created cell should not have any content */
95 g_assert_null(adg_table_cell_title(cell));
97 /* Check explicit setting */
98 adg_table_cell_set_title(cell, entity);
99 g_assert_nonnull(adg_table_cell_title(cell));
100 g_assert_true(adg_table_cell_title(cell) == entity);
102 /* Check explicit unsetting */
103 adg_table_cell_set_title(cell, NULL);
104 g_assert_null(adg_table_cell_title(cell));
106 /* Check implicit setting during construction */
107 cell = adg_table_cell_new_full(row, 12, NULL, "title", FALSE);
108 g_assert_nonnull(adg_table_cell_title(cell));
110 /* Check the content is not set implicitely */
111 cell = adg_table_cell_new_full(row, 12, NULL, NULL, FALSE);
112 g_assert_null(adg_table_cell_title(cell));
114 adg_entity_destroy(ADG_ENTITY(table));
115 adg_entity_destroy(entity);
118 static void
119 _adg_property_value(void)
121 AdgTable *table;
122 AdgTableRow *row;
123 AdgTableCell *cell;
124 AdgEntity *entity;
126 table = adg_table_new();
127 row = adg_table_row_new(table);
128 cell = adg_table_cell_new(row);
129 entity = ADG_ENTITY(adg_logo_new());
131 /* Sanity check */
132 g_assert_null(adg_table_cell_value(NULL));
133 adg_table_cell_set_value(NULL, NULL);
134 adg_table_cell_set_value(NULL, entity);
136 /* A newly created cell should not have any content */
137 g_assert_null(adg_table_cell_value(cell));
139 /* Check explicit setting */
140 adg_table_cell_set_value(cell, entity);
141 g_assert_nonnull(adg_table_cell_value(cell));
142 g_assert_true(adg_table_cell_value(cell) == entity);
144 /* Check explicit unsetting */
145 adg_table_cell_set_value(cell, NULL);
146 g_assert_null(adg_table_cell_value(cell));
148 /* Check text setting */
149 adg_table_cell_set_text_value(cell, "value");
150 g_assert_nonnull(adg_table_cell_value(cell));
152 /* Check text unsetting */
153 adg_table_cell_set_text_value(cell, NULL);
154 g_assert_null(adg_table_cell_value(cell));
156 adg_entity_destroy(ADG_ENTITY(table));
157 adg_entity_destroy(entity);
160 static void
161 _adg_property_width(void)
163 AdgTable *table;
164 AdgTableRow *row;
165 AdgTableCell *cell;
167 table = adg_table_new();
168 row = adg_table_row_new(table);
169 cell = adg_table_cell_new(row);
171 /* Sanity check */
172 g_assert_cmpint(adg_table_cell_get_width(NULL), ==, 0);
173 adg_table_cell_set_width(NULL, 123);
175 /* Check explicit setting */
176 g_assert_cmpint(adg_table_cell_get_width(cell), ==, 0);
177 adg_table_cell_set_width(cell, 321);
178 g_assert_cmpint(adg_table_cell_get_width(cell), ==, 321);
179 adg_table_cell_set_width(cell, 0);
180 g_assert_cmpint(adg_table_cell_get_width(cell), ==, 0);
182 /* Check implicit setting during construction */
183 cell = adg_table_cell_new_with_width(row, 456);
184 g_assert_cmpint(adg_table_cell_get_width(cell), ==, 456);
185 cell = adg_table_cell_new_with_width(row, 0);
186 g_assert_cmpint(adg_table_cell_get_width(cell), ==, 0);
188 adg_entity_destroy(ADG_ENTITY(table));
191 static void
192 _adg_property_frame(void)
194 AdgTable *table;
195 AdgTableRow *row;
196 AdgTableCell *cell;
198 table = adg_table_new();
199 row = adg_table_row_new(table);
200 cell = adg_table_cell_new(row);
202 /* Sanity check */
203 g_assert_false(adg_table_cell_has_frame(NULL));
204 adg_table_cell_switch_frame(NULL, FALSE);
206 /* Check setting and unsetting */
207 g_assert_false(adg_table_cell_has_frame(cell));
208 adg_table_cell_switch_frame(cell, TRUE);
209 g_assert_true(adg_table_cell_has_frame(cell));
210 adg_table_cell_switch_frame(cell, FALSE);
211 g_assert_false(adg_table_cell_has_frame(cell));
213 adg_entity_destroy(ADG_ENTITY(table));
218 main(int argc, char *argv[])
220 AdgTable *table;
221 AdgTableRow *row;
222 int result;
224 adg_test_init(&argc, &argv);
226 /* Create a dummy table row, otherwise no cell would be instantiable */
227 table = adg_table_new();
228 row = adg_table_row_new(table);
230 adg_test_add_boxed_checks("/adg/table-cell/type/boxed", ADG_TYPE_TABLE_CELL,
231 adg_table_cell_new(row));
233 g_test_add_func("/adg/table-cell/behavior/misc", _adg_behavior_misc);
234 g_test_add_func("/adg/table-cell/property/title", _adg_property_title);
235 g_test_add_func("/adg/table-cell/property/value", _adg_property_value);
236 g_test_add_func("/adg/table-cell/property/width", _adg_property_width);
237 g_test_add_func("/adg/table-cell/property/frame", _adg_property_frame);
239 result = g_test_run();
240 adg_entity_destroy(ADG_ENTITY(table));
242 return result;