From 6a25c8d0973b62fb505ce618f86fe661fae6bb53 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 12 Aug 2012 22:09:50 +0200 Subject: Fix a few test cases The test_overrides() test must be run first, otherwise we'll already likely not have a clean environment to test in. Furthermore, when testing discovery, make sure that NOIMPLICIT is not set. Signed-off-by: Gergely Nagy --- t/test_umberlog.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 't/test_umberlog.c') diff --git a/t/test_umberlog.c b/t/test_umberlog.c index 68b5a95..9184b35 100644 --- a/t/test_umberlog.c +++ b/t/test_umberlog.c @@ -16,16 +16,16 @@ #include /** - * Test the umberlog defaults. + * Test that openlog() is not overridden when using the linkable + * library. This must be the first test! */ -START_TEST (test_defaults) +START_TEST (test_overrides) { char *msg; struct json_object *jo; - char host[_POSIX_HOST_NAME_MAX + 1]; - ul_openlog ("umberlog/test_defaults", 0, LOG_LOCAL0); + openlog ("umberlog/test_overrides", 0, LOG_LOCAL0); msg = ul_format (LOG_DEBUG, "hello, I'm %s!", __FUNCTION__, NULL); jo = parse_msg (msg); @@ -33,10 +33,14 @@ START_TEST (test_defaults) gethostname (host, _POSIX_HOST_NAME_MAX); - verify_value (jo, "msg", "hello, I'm test_defaults!"); - verify_value (jo, "facility", "local0"); + verify_value (jo, "msg", "hello, I'm test_overrides!"); + /* Default facility is user, and since we did not catch openlog, it + should not change. */ + verify_value (jo, "facility", "user"); verify_value (jo, "priority", "debug"); - verify_value (jo, "program", "umberlog/test_defaults"); + /* The program is also caught by openlog(), so we'll get the + default back, unless we use ul_openlog(). */ + verify_value (jo, "program", "test_umberlog"); verify_value_exists (jo, "pid"); verify_value_exists (jo, "uid"); verify_value_exists (jo, "gid"); @@ -45,21 +49,21 @@ START_TEST (test_defaults) json_object_put (jo); - ul_closelog (); + closelog (); } END_TEST /** - * Test that openlog() is not overridden when using the linkable - * library. + * Test the umberlog defaults. */ -START_TEST (test_overrides) +START_TEST (test_defaults) { char *msg; struct json_object *jo; + char host[_POSIX_HOST_NAME_MAX + 1]; - openlog ("umberlog/test_overrides", 0, LOG_LOCAL0); + ul_openlog ("umberlog/test_defaults", 0, LOG_LOCAL0); msg = ul_format (LOG_DEBUG, "hello, I'm %s!", __FUNCTION__, NULL); jo = parse_msg (msg); @@ -67,14 +71,10 @@ START_TEST (test_overrides) gethostname (host, _POSIX_HOST_NAME_MAX); - verify_value (jo, "msg", "hello, I'm test_overrides!"); - /* Default facility is user, and since we did not catch openlog, it - should not change. */ - verify_value (jo, "facility", "user"); + verify_value (jo, "msg", "hello, I'm test_defaults!"); + verify_value (jo, "facility", "local0"); verify_value (jo, "priority", "debug"); - /* The program is also caught by openlog(), so we'll get the - default back, unless we use ul_openlog(). */ - verify_value (jo, "program", "test_umberlog"); + verify_value (jo, "program", "umberlog/test_defaults"); verify_value_exists (jo, "pid"); verify_value_exists (jo, "uid"); verify_value_exists (jo, "gid"); @@ -83,7 +83,7 @@ START_TEST (test_overrides) json_object_put (jo); - closelog (); + ul_closelog (); } END_TEST @@ -286,6 +286,7 @@ START_TEST (test_discover_priority) struct json_object *jo; ul_openlog ("umberlog/test_discover_priority", 0, LOG_LOCAL0); + ul_set_log_flags (LOG_UL_ALL); msg = ul_format (LOG_DEBUG, "testing 1, 2, 3...", "pid", "%d", getpid () + 42, @@ -412,8 +413,8 @@ main (void) s = suite_create ("Umberlog (linkable) functional testsuite"); ft = tcase_create ("Basic tests"); - tcase_add_test (ft, test_defaults); tcase_add_test (ft, test_overrides); + tcase_add_test (ft, test_defaults); tcase_add_test (ft, test_ul_openlog); tcase_add_test (ft, test_ul_openlog_flag_ignore); tcase_add_test (ft, test_closelog); -- cgit