summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Staudinger <robertx.staudinger@intel.com>2009-05-07 14:07:14 +0200
committerRobert Staudinger <robertx.staudinger@intel.com>2009-05-07 14:07:14 +0200
commit92bc59e1d39302c8be500d53cb5dd8b05c2e4a15 (patch)
tree893dc3a06d8d5a280fd2736afb6228a968d207f2
parent3b3c9529f227d3d9fb5935f938979a8db066ee00 (diff)
Add GTest infrastructure.libccss-0.2.0libccss-0.1.0
-rw-r--r--Makefile.am9
-rw-r--r--Makefile.gtest61
-rw-r--r--ccss-tests/Makefile.am22
-rw-r--r--ccss-tests/test-parser.c63
-rw-r--r--configure.in4
5 files changed, 159 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 64f2d4b..ff034ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,7 @@ DIST_SUBDIRS = \
build \
ccss \
ccss-doc \
+ ccss-tests \
ccss-cairo \
ccss-cairo-doc \
ccss-gtk \
@@ -19,6 +20,10 @@ SUBDIRS = \
ccss-doc \
$(NULL)
+if ENABLE_GLIB_TEST
+SUBDIRS += ccss-tests
+endif
+
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libccss-1.pc
@@ -50,6 +55,10 @@ EXTRA_DIST = \
libccss-gtk-1.pc.in \
$(NULL)
+CLEANFILES = \
+ test-report.xml \
+ $(NULL)
+
PREV_RELEASE=$(CCSS_VERSION_MAJOR).$$(echo "$(CCSS_VERSION_MINOR)-1" | bc)
dist-hook:
diff --git a/Makefile.gtest b/Makefile.gtest
new file mode 100644
index 0000000..d0f0e05
--- /dev/null
+++ b/Makefile.gtest
@@ -0,0 +1,61 @@
+# CCSS - C CSS library
+
+GTESTER = gtester
+GTESTER_REPORT = gtester-report
+
+# initialize variables for unconditional += appending
+EXTRA_DIST =
+TEST_PROGS =
+
+### testing rules
+
+# test: run all tests in cwd and subdirs
+test: ${TEST_PROGS}
+ @test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
+ @ for subdir in $(SUBDIRS) . ; do \
+ test "$$subdir" = "." -o "$$subdir" = "po" || \
+ ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+ done
+# test-report: run tests in subdirs and generate report
+# perf-report: run tests in subdirs with -m perf and generate report
+# full-report: like test-report: with -m perf and -m slow
+test-report perf-report full-report: ${TEST_PROGS}
+ @test -z "${TEST_PROGS}" || { \
+ case $@ in \
+ test-report) test_options="-k";; \
+ perf-report) test_options="-k -m=perf";; \
+ full-report) test_options="-k -m=perf -m=slow";; \
+ esac ; \
+ if test -z "$$GTESTER_LOGDIR" ; then \
+ ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
+ elif test -n "${TEST_PROGS}" ; then \
+ ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
+ fi ; \
+ }
+ @ ignore_logdir=true ; \
+ if test -z "$$GTESTER_LOGDIR" ; then \
+ GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
+ ignore_logdir=false ; \
+ fi ; \
+ for subdir in $(SUBDIRS) . ; do \
+ test "$$subdir" = "." -o "$$subdir" = "po" || \
+ ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+ done ; \
+ $$ignore_logdir || { \
+ echo '<?xml version="1.0"?>' > $@.xml ; \
+ echo '<report-collection>' >> $@.xml ; \
+ echo '<info>' >> $@.xml ; \
+ echo ' <package>$(PACKAGE)</package>' >> $@.xml ; \
+ echo ' <version>$(VERSION)</version>' >> $@.xml ; \
+ echo '</info>' >> $@.xml ; \
+ for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
+ sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
+ done ; \
+ echo >> $@.xml ; \
+ echo '</report-collection>' >> $@.xml ; \
+ rm -rf "$$GTESTER_LOGDIR"/ ; \
+ ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
+ }
+.PHONY: test test-report perf-report full-report
+# run make test as part of make check
+check-local: test
diff --git a/ccss-tests/Makefile.am b/ccss-tests/Makefile.am
new file mode 100644
index 0000000..82de12f
--- /dev/null
+++ b/ccss-tests/Makefile.am
@@ -0,0 +1,22 @@
+
+include $(top_srcdir)/Makefile.gtest
+
+NULL =
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ $(CCSS_CFLAGS) \
+ $(NULL)
+
+LDADD = \
+ $(CCSS_LIBS) \
+ $(top_builddir)/ccss/libccss-1.la \
+ $(NULL)
+
+TESTS_ENVIRONMENT = srcdir=$(srcdir)
+
+TEST_PROGS += test-parser
+test_parser_SOURCES = test-parser.c
+
diff --git a/ccss-tests/test-parser.c b/ccss-tests/test-parser.c
new file mode 100644
index 0000000..fd40d5e
--- /dev/null
+++ b/ccss-tests/test-parser.c
@@ -0,0 +1,63 @@
+/* vim: set ts=8 sw=8 noexpandtab: */
+
+#include <stdlib.h>
+#include <ccss/ccss.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+
+static void
+test_generic_property (void)
+{
+ static char const _css[] = "foo { bar: baz; }";
+ ccss_grammar_t *grammar;
+ ccss_stylesheet_t *stylesheet;
+ ccss_style_t *style;
+ /*double dval;*/
+ char *sval;
+ bool ret;
+
+ if (g_test_verbose ()) g_printf ("testing '%s'\n", _css);
+
+ grammar = ccss_grammar_create_generic ();
+ g_assert (grammar);
+
+ if (g_test_verbose ()) g_print ("parsing");
+ stylesheet = ccss_grammar_create_stylesheet_from_buffer (grammar,
+ _css, sizeof (_css) - 1,
+ NULL);
+ g_assert (stylesheet);
+
+ if (g_test_verbose ()) g_print ("querying");
+ style = ccss_stylesheet_query_type (stylesheet, "foo");
+ g_assert (style);
+
+ /* TODO: find out how to rund a test that's supposed to fail.
+ * this issues a warning which aborts
+ if (g_test_verbose ()) g_print ("converting to double");
+ ret = ccss_style_get_double (style, "bar", &dval);
+ g_assert (!ret);
+ */
+
+ if (g_test_verbose ()) g_print ("converting to string");
+ sval = NULL;
+ ret = ccss_style_get_string (style, "bar", &sval);
+ g_assert (ret);
+ g_assert_cmpstr (sval, ==, "baz");
+
+ ccss_style_destroy (style);
+ ccss_stylesheet_destroy (stylesheet);
+ ccss_grammar_destroy (grammar);
+
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/ccss-parser/generic-property", test_generic_property);
+
+ return g_test_run ();
+}
+
diff --git a/configure.in b/configure.in
index 5294409..636d00b 100644
--- a/configure.in
+++ b/configure.in
@@ -95,6 +95,9 @@ gtk_doc_installed=true
GTK_DOC_CHECK([1.0])
AM_CONDITIONAL(GTK_DOC_INSTALLED, $gtk_doc_installed)
+# hardwire-enable testing
+enable_glibtest="yes"
+AM_CONDITIONAL(ENABLE_GLIB_TEST, test "$enable_glibtest" = "yes")
### Checks for libraries. ######################################################
@@ -327,6 +330,7 @@ AC_CONFIG_FILES([
ccss/Makefile
ccss-doc/Makefile
ccss-doc/version.xml
+ ccss-tests/Makefile
libccss-cairo-1.pc
ccss-cairo/Makefile