From 1e2e00aff031457f98c555c87a44cab5f5e6db21 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Tue, 9 Feb 2010 17:20:21 +0100 Subject: [PATCH] [tests] Initial (not working) test Added support for the GLib test framework and implemented first (not working) test. configure.ac must be updated to make the test framework optional because it is based on a feature introduced by glib-2.16.0 (still too young). --- Makefile.am | 3 ++- tests/.gitignore | 1 + tests/Makefile.am | 14 +++++++++++ tests/properties.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/.gitignore create mode 100644 tests/Makefile.am create mode 100644 tests/properties.c diff --git a/Makefile.am b/Makefile.am index caa19774..961ec5af 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,8 @@ SUBDIRS= cpml \ demo \ docs \ po \ - po-properties + po-properties \ + tests pkgconfigdir= $(libdir)/pkgconfig pkgconfig_DATA = cpml.pc \ diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..26995fdf --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +/properties diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 00000000..54c2b4df --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,14 @@ +AM_CFLAGS= -g @ADG_CFLAGS@ \ + -I$(top_srcdir) \ + -I$(top_builddir) +AM_LDFLAGS= @ADG_LIBS@ +LDADD= $(top_builddir)/adg/libadg.la + + +# file groups +test_programs= properties + + +# targets +check_PROGRAMS= $(test_programs) +TESTS= $(test_programs) diff --git a/tests/properties.c b/tests/properties.c new file mode 100644 index 00000000..831cee73 --- /dev/null +++ b/tests/properties.c @@ -0,0 +1,69 @@ +/* ADG - Automatic Drawing Generation + * Copyright (C) 2007,2008,2009 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 +#include + + +typedef struct { + AdgPath *path; +} FixtureAdg; + + +static void +adg_setup(FixtureAdg *fixture, gconstpointer test_data) +{ + g_assert(test_data == (void*) 0xfeedcafe); + + fixture->path = adg_path_new(); +} + +static void +adg_teardown(FixtureAdg *fixture, gconstpointer test_data) +{ + g_assert(test_data == (void*) 0xfeedcafe); + + g_object_unref(fixture->path); + fixture->path = NULL; +} + + +static void +test_model(FixtureAdg *fixture, gconstpointer test_data) +{ + if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) { + g_object_set(fixture->path, "dependency", NULL, NULL); + exit(0); + } + g_test_trap_assert_passed(); +} + + +int +main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + g_type_init(); + + g_test_add("/adg/AdgModel", FixtureAdg, (void*) 0xfeedcafe, + adg_setup, test_model, adg_teardown); + + return g_test_run(); +} -- 2.11.4.GIT