From 8357b854d8a0d7ee9912e73fc6198a17a2cde4f5 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Sun, 24 May 2015 11:29:42 +0200 Subject: [PATCH] Test log --- tests/Makefile.am | 8 +++- tests/check_log.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/check_log.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 244cafc..89bb297 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,8 @@ AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects TESTS = \ check_cfg \ - check_cfg_xmlfile + check_cfg_xmlfile \ + check_log check_PROGRAMS = $(TESTS) check_cfg_SOURCES = \ @@ -15,6 +16,11 @@ check_cfg_xmlfile_SOURCES = \ check_cfg_xmlfile_DEPENDENCIES = $(top_builddir)/src/libezstream.la check_cfg_xmlfile_LDADD = $(check_cfg_xmlfile_DEPENDENCIES) @CHECK_LIBS@ +check_log_SOURCES = \ + check_log.c +check_log_DEPENDENCIES = $(top_builddir)/src/libezstream.la +check_log_LDADD = $(check_cfg_xmlfile_DEPENDENCIES) @CHECK_LIBS@ + AM_CPPFLAGS = @EZ_CPPFLAGS@ \ -I$(top_srcdir)/compat \ -I$(top_srcdir)/src \ diff --git a/tests/check_log.c b/tests/check_log.c new file mode 100644 index 0000000..7e61298 --- /dev/null +++ b/tests/check_log.c @@ -0,0 +1,95 @@ +#include +#include + +#include "cfg.h" +#include "log.h" + +Suite * log_suite(void); +void setup_checked(void); +void teardown_checked(void); + +START_TEST(test_log) +{ + unsigned int verbosity; + + ck_assert_int_eq(log_syserr(ALERT, 0, "alert"), 0); + + verbosity = 0; + ck_assert_int_eq(cfg_set_program_verbosity(verbosity, NULL), 0); + ck_assert_int_ne(log_alert("alert"), 0); + ck_assert_int_ne(log_syserr(ALERT, EINVAL, "alert"), 0); + ck_assert_int_ne(log_syserr(ALERT, EINVAL, NULL), 0); + ck_assert_int_ne(log_error("error"), 0); + ck_assert_int_ne(log_syserr(ERROR, EINVAL, "error"), 0); + ck_assert_int_ne(log_warning("warning"), 0); + ck_assert_int_ne(log_syserr(WARNING, EINVAL, "warning"), 0); + + ck_assert_int_eq(log_notice("notice"), 0); + ck_assert_int_eq(log_syserr(NOTICE, EINVAL, "notice"), 0); + ck_assert_int_eq(cfg_set_program_verbosity(++verbosity, NULL), 0); + ck_assert_int_ne(log_notice("notice"), 0); + ck_assert_int_ne(log_syserr(NOTICE, EINVAL, "notice"), 0); + + ck_assert_int_eq(log_info("info"), 0); + ck_assert_int_eq(log_syserr(INFO, EINVAL, "info"), 0); + ck_assert_int_eq(cfg_set_program_verbosity(++verbosity, NULL), 0); + ck_assert_int_ne(log_info("info"), 0); + ck_assert_int_ne(log_syserr(INFO, EINVAL, "info"), 0); + + ck_assert_int_eq(log_debug("debug"), 0); + ck_assert_int_eq(log_syserr(DEBUG, EINVAL, "debug"), 0); + ck_assert_int_eq(cfg_set_program_verbosity(++verbosity, NULL), 0); + ck_assert_int_ne(log_debug("debug"), 0); + ck_assert_int_ne(log_syserr(DEBUG, EINVAL, "debug"), 0); +} +END_TEST + +Suite * +log_suite(void) +{ + Suite *s; + TCase *tc_core; + + s = suite_create("Log"); + + tc_core = tcase_create("Core"); + tcase_add_checked_fixture(tc_core, setup_checked, teardown_checked); + tcase_add_test(tc_core, test_log); + suite_add_tcase(s, tc_core); + + return (s); +} + +void +setup_checked(void) +{ + if (0 < cfg_init() || + 0 < log_init()) + ck_abort_msg("setup_checked failed"); +} + +void +teardown_checked(void) +{ + log_exit(); + cfg_exit(); +} + +int +main(void) +{ + unsigned int num_failed; + Suite *s; + SRunner *sr; + + s = log_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + num_failed = srunner_ntests_failed(sr); + srunner_free(sr); + + if (num_failed) + return (1); + return (0); +}