summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergely Nagy <algernon@madhouse-project.org>2012-04-29 00:57:46 +0200
committerGergely Nagy <algernon@madhouse-project.org>2012-04-29 00:57:46 +0200
commit4375514b3fdc99bca58894592808948f4b833eff (patch)
treedccf0aa043d8367ac4bd2ac49fe774189b3abf67
parentcf66dbeb8820ef935045813598aa5a48be00526a (diff)
parent36847dcdae8abb9239dcbcdc2446cfb7042302d0 (diff)
downloadlibumberlog-4375514b3fdc99bca58894592808948f4b833eff.tar.gz
libumberlog-4375514b3fdc99bca58894592808948f4b833eff.tar.xz
libumberlog-4375514b3fdc99bca58894592808948f4b833eff.zip
Merge branch 'feature/test-suite/check'
-rw-r--r--README.rst8
-rw-r--r--configure.ac5
-rw-r--r--t/Makefile.am4
-rw-r--r--t/test_umberlog.c79
4 files changed, 60 insertions, 36 deletions
diff --git a/README.rst b/README.rst
index d6e3830..ecf9b36 100644
--- a/README.rst
+++ b/README.rst
@@ -54,11 +54,13 @@ SSH Login::
Requirements
------------
-Apart from the autotools, a C compiler, and `json\-c`_ (for the test
-suite), there are no other hard dependencies when building, except for
-a sufficiently modern system.
+Apart from the autotools, a C compiler, there are no other
+dependencies when building, except for a sufficiently modern system.
+
+The test suite requires `json\-c`_ and `check`_ too.
.. _json\-c: http://oss.metaparadigm.com/json-c/
+.. _check: http://check.sourceforge.net/
Installation
------------
diff --git a/configure.ac b/configure.ac
index f3805c7..84c3a19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,9 +54,12 @@ AC_SEARCH_LIBS([clock_gettime], [rt], [], [
])
dnl ***************************************************************************
-dnl JSON-C headers/libraries
+dnl Libraries for the test suite
dnl ***************************************************************************
PKG_CHECK_MODULES(JSON, json >= $JSON_C_MIN_VERSION,[enable_tests="1"],[enable_tests="0"])
+if test "x$enable_tests" = "x1"; then
+ PKG_CHECK_MODULES(CHECK, check, [enable_tests="1"],[enable_tests="0"])
+fi
dnl ***************************************************************************
dnl misc features to be enabled
diff --git a/t/Makefile.am b/t/Makefile.am
index b07c6f2..91e4b53 100644
--- a/t/Makefile.am
+++ b/t/Makefile.am
@@ -2,6 +2,6 @@ if ENABLE_TESTS
TESTS = test_umberlog test_perf
check_PROGRAMS = ${TESTS}
-AM_CFLAGS = -I$(top_srcdir)/lib @JSON_CFLAGS@
-LDADD = $(top_builddir)/lib/libumberlog.la @JSON_LIBS@
+AM_CFLAGS = -I$(top_srcdir)/lib @JSON_CFLAGS@ @CHECK_CFLAGS@
+LDADD = $(top_builddir)/lib/libumberlog.la @JSON_LIBS@ @CHECK_LIBS@
endif
diff --git a/t/test_umberlog.c b/t/test_umberlog.c
index b0085c6..9818a35 100644
--- a/t/test_umberlog.c
+++ b/t/test_umberlog.c
@@ -10,6 +10,8 @@
#include <stdio.h>
#include <limits.h>
+#include <check.h>
+
static void
verify_value (struct json_object *jo, const char *key,
const char *expected_value)
@@ -19,12 +21,11 @@ verify_value (struct json_object *jo, const char *key,
o = json_object_object_get (jo, key);
- assert (o != NULL);
+ ck_assert (o != NULL);
value = json_object_get_string (o);
- assert (value != NULL);
- assert (strcmp (value, expected_value) == 0);
+ ck_assert_str_eq (value, expected_value);
}
static void
@@ -33,7 +34,7 @@ verify_value_exists (struct json_object *jo, const char *key)
struct json_object *o;
o = json_object_object_get (jo, key);
- assert (o != NULL);
+ ck_assert_msg (o != NULL, "key '%s' does not exist", key);
}
static void
@@ -56,8 +57,7 @@ parse_msg (const char *msg)
return jo;
}
-static void
-test_simple (void)
+START_TEST (test_simple)
{
char *msg;
struct json_object *jo;
@@ -85,9 +85,9 @@ test_simple (void)
closelog ();
}
+END_TEST
-static void
-test_no_discover (void)
+START_TEST (test_no_discover)
{
char *msg;
struct json_object *jo;
@@ -112,9 +112,9 @@ test_no_discover (void)
closelog ();
}
+END_TEST
-static void
-test_additional_fields (void)
+START_TEST (test_additional_fields)
{
char *msg;
struct json_object *jo;
@@ -136,9 +136,9 @@ test_additional_fields (void)
closelog ();
}
+END_TEST
-static void
-test_discover_priority (void)
+START_TEST (test_discover_priority)
{
char *msg, *pid;
struct json_object *jo;
@@ -162,9 +162,9 @@ test_discover_priority (void)
closelog ();
}
+END_TEST
-static void
-test_no_timestamp (void)
+START_TEST (test_no_timestamp)
{
char *msg;
struct json_object *jo;
@@ -189,9 +189,9 @@ test_no_timestamp (void)
closelog ();
}
+END_TEST
-static void
-test_json_escape (void)
+START_TEST (test_json_escape)
{
char *msg;
struct json_object *jo;
@@ -218,9 +218,9 @@ test_json_escape (void)
closelog ();
}
+END_TEST
-static void
-test_facprio (void)
+START_TEST (test_facprio)
{
char *msg;
struct json_object *jo;
@@ -235,9 +235,9 @@ test_facprio (void)
json_object_put (jo);
}
+END_TEST
-static void
-test_closelog (void)
+START_TEST (test_closelog)
{
char *msg;
struct json_object *jo;
@@ -253,18 +253,37 @@ test_closelog (void)
json_object_put (jo);
}
+END_TEST
int
main (void)
{
- test_simple ();
- test_no_discover ();
- test_additional_fields ();
- test_discover_priority ();
- test_no_timestamp ();
- test_json_escape ();
- test_facprio ();
- test_closelog ();
-
- return 0;
+ Suite *s;
+ SRunner *sr;
+ TCase *ft, *bt;
+ int nfailed;
+
+ s = suite_create ("Umberlog functional testsuite");
+
+ ft = tcase_create ("Basic tests");
+ tcase_add_test (ft, test_simple);
+ tcase_add_test (ft, test_no_discover);
+ tcase_add_test (ft, test_additional_fields);
+ tcase_add_test (ft, test_discover_priority);
+ tcase_add_test (ft, test_no_timestamp);
+ suite_add_tcase (s, ft);
+
+ bt = tcase_create ("Bug tests");
+ tcase_add_test (bt, test_json_escape);
+ tcase_add_test (bt, test_facprio);
+ tcase_add_test (bt, test_closelog);
+ suite_add_tcase (s, bt);
+
+ sr = srunner_create (s);
+
+ srunner_run_all (sr, CK_ENV);
+ nfailed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (nfailed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}