From 8f3d58868c518424b942a3d59b00e5458b0b7c4d Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Wed, 24 Feb 2010 21:04:04 +0100 Subject: [PATCH] [adg/tests] Added test-table A basic test on AdgTable that checks the "table-dress" and "has-frame" properties and their methods. --- adg/tests/.gitignore | 1 + adg/tests/Makefile.am | 4 ++ adg/tests/test-table.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 adg/tests/test-table.c diff --git a/adg/tests/.gitignore b/adg/tests/.gitignore index 10595a2a..0019b153 100644 --- a/adg/tests/.gitignore +++ b/adg/tests/.gitignore @@ -6,3 +6,4 @@ /test-stroke /test-hatch /test-toy-text +/test-table diff --git a/adg/tests/Makefile.am b/adg/tests/Makefile.am index e980da65..6e928bef 100644 --- a/adg/tests/Makefile.am +++ b/adg/tests/Makefile.am @@ -45,6 +45,10 @@ TEST_PROGS+= test-toy-text test_toy_text_SOURCES= test-toy-text.c \ $(test_internals) +TEST_PROGS+= test-table +test_table_SOURCES= test-table.c \ + $(test_internals) + endif diff --git a/adg/tests/test-table.c b/adg/tests/test-table.c new file mode 100644 index 00000000..902b7216 --- /dev/null +++ b/adg/tests/test-table.c @@ -0,0 +1,102 @@ +/* ADG - Automatic Drawing Generation + * Copyright (C) 2010 Nicola Fontana + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + +#include "test-internal.h" + + +static void _adg_test_table_dress(void) { AdgTable *table; + AdgDress valid_dress, incompatible_dress; + AdgDress table_dress; + + table = adg_table_new(); + valid_dress = ADG_DRESS_TABLE; + incompatible_dress = ADG_DRESS_LINE; + + /* Using the public APIs */ + adg_table_set_table_dress(table, valid_dress); + table_dress = adg_table_get_table_dress(table); + g_assert_cmpint(table_dress, ==, valid_dress); + + adg_table_set_table_dress(table, incompatible_dress); + table_dress = adg_table_get_table_dress(table); + g_assert_cmpint(table_dress, ==, valid_dress); + + /* Using GObject property methods */ + g_object_set(table, "table-dress", valid_dress, NULL); + g_object_get(table, "table-dress", &table_dress, NULL); + g_assert_cmpint(table_dress, ==, valid_dress); + + g_object_set(table, "table-dress", incompatible_dress, NULL); + g_object_get(table, "table-dress", &table_dress, NULL); + g_assert_cmpint(table_dress, ==, valid_dress); + + g_object_unref(table); +} + +static void +_adg_test_has_frame(void) +{ + AdgTable *table; + gboolean invalid_boolean; + gboolean has_frame; + + table = adg_table_new(); + invalid_boolean = (gboolean) 1234; + + /* Using the public APIs */ + adg_table_switch_frame(table, FALSE); + has_frame = adg_table_has_frame(table); + g_assert(!has_frame); + + adg_table_switch_frame(table, invalid_boolean); + has_frame = adg_table_has_frame(table); + g_assert(!has_frame); + + adg_table_switch_frame(table, TRUE); + has_frame = adg_table_has_frame(table); + g_assert(has_frame); + + /* Using GObject property methods */ + g_object_set(table, "has-frame", FALSE, NULL); + g_object_get(table, "has-frame", &has_frame, NULL); + g_assert(!has_frame); + + g_object_set(table, "has-frame", invalid_boolean, NULL); + g_object_get(table, "has-frame", &has_frame, NULL); + g_assert(!has_frame); + + g_object_set(table, "has-frame", TRUE, NULL); + g_object_get(table, "has-frame", &has_frame, NULL); + g_assert(has_frame); + + g_object_unref(table); +} + + +int +main(int argc, char *argv[]) +{ + adg_test_init(&argc, &argv); + + adg_test_add_func("/adg/table/table-dress", _adg_test_table_dress); + adg_test_add_func("/adg/table/has_frame", _adg_test_has_frame); + + return g_test_run(); +} -- 2.11.4.GIT