diff options
author | Gergely Nagy <algernon@madhouse-project.org> | 2012-04-29 00:52:05 +0200 |
---|---|---|
committer | Gergely Nagy <algernon@madhouse-project.org> | 2012-04-29 00:52:05 +0200 |
commit | 36847dcdae8abb9239dcbcdc2446cfb7042302d0 (patch) | |
tree | dccf0aa043d8367ac4bd2ac49fe774189b3abf67 /t | |
parent | cf66dbeb8820ef935045813598aa5a48be00526a (diff) | |
download | libumberlog-36847dcdae8abb9239dcbcdc2446cfb7042302d0.tar.gz libumberlog-36847dcdae8abb9239dcbcdc2446cfb7042302d0.tar.xz libumberlog-36847dcdae8abb9239dcbcdc2446cfb7042302d0.zip |
Convert the test suite to Check
While assert() is a neat tool, it is not really suitable for testing,
as it gives hardly any indication on what part of the test suite
failed, and why.
For this purpose, an existing testing library, such as Check is a much
better option, so lets use that!
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 't')
-rw-r--r-- | t/Makefile.am | 4 | ||||
-rw-r--r-- | t/test_umberlog.c | 79 |
2 files changed, 51 insertions, 32 deletions
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; } |