dovecot-2.2: lib: test-failures - tests get/set handlers and the...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 15 11:40:24 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/6d965c726810
changeset: 18854:6d965c726810
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 15 14:31:19 2015 +0300
description:
lib: test-failures - tests get/set handlers and the various log levels
Also indirectoy tests the new lib-test test_expect* family.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/Makefile.am     |   1 +
 src/lib/test-failures.c |  71 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/test-lib.c      |   1 +
 src/lib/test-lib.h      |   1 +
 4 files changed, 74 insertions(+), 0 deletions(-)

diffs (108 lines):

diff -r 8739d201898c -r 6d965c726810 src/lib/Makefile.am
--- a/src/lib/Makefile.am	Mon Jun 15 14:31:19 2015 +0300
+++ b/src/lib/Makefile.am	Mon Jun 15 14:31:19 2015 +0300
@@ -294,6 +294,7 @@
 	test-buffer.c \
 	test-crc32.c \
 	test-data-stack.c \
+	test-failures.c \
 	test-guid.c \
 	test-hash.c \
 	test-hash-format.c \
diff -r 8739d201898c -r 6d965c726810 src/lib/test-failures.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-failures.c	Mon Jun 15 14:31:19 2015 +0300
@@ -0,0 +1,71 @@
+/* Copyright (c) 2001-2015 Dovecot authors, see the included COPYING file */
+
+/* Unit tests for failure helpers */
+
+#include "test-lib.h"
+#include "failures.h"
+
+static int handlers_set_me;
+
+static void test_failures_handler(const struct failure_context *ctx,
+				  const char *format ATTR_UNUSED,
+				  va_list args ATTR_UNUSED)
+{
+	handlers_set_me = ctx->type;
+}
+static void test_get_set_handlers(void)
+{
+	failure_callback_t *handlers[4];
+	test_begin("get_handlers");
+	i_get_failure_handlers(handlers, handlers+1, handlers+2, handlers+3);
+	test_end();
+
+	test_begin("set_handlers");
+
+	i_set_debug_handler(&test_failures_handler);
+	i_debug("If you see this debug, something's gone wrong");
+	test_assert(handlers_set_me == LOG_TYPE_DEBUG);
+	i_set_debug_handler(handlers[3]);
+
+	i_set_info_handler(&test_failures_handler);
+	i_info("If you see this info, something's gone wrong");
+	test_assert(handlers_set_me == LOG_TYPE_INFO);
+	i_set_info_handler(handlers[2]);
+
+	i_set_error_handler(&test_failures_handler);
+	i_warning("If you see this warning, something's gone wrong");
+	test_assert(handlers_set_me == LOG_TYPE_WARNING);
+	i_error("If you see this error, something's gone wrong");
+	test_assert(handlers_set_me == LOG_TYPE_ERROR);
+	i_set_error_handler(handlers[1]);
+
+	//i_set_fatal_handler(&test_failures_handler);
+	//i_fatal("If you see this fatal, something's gone wrong");
+	//test_assert(handlers_set_me == LOG_TYPE_FATAL);
+	//i_set_fatal_handler(handlers[0]);
+
+	test_end();
+}
+static void test_expected(void)
+{
+	test_begin("expected messages");
+	test_expect_errors(1);
+	i_warning("deliberate warning - be happy you're seeing this");
+	test_expect_no_more_errors();
+	test_end();
+}
+static void test_expected_str(void)
+{
+	test_begin("expected strings in messages");
+	test_expect_error_string("be happy");
+	i_error("deliberate error - be happy you're seeing this");
+	test_expect_no_more_errors();
+	test_end();
+}
+
+void test_failures(void)
+{
+	test_get_set_handlers();
+	test_expected();
+	test_expected_str();
+}
diff -r 8739d201898c -r 6d965c726810 src/lib/test-lib.c
--- a/src/lib/test-lib.c	Mon Jun 15 14:31:19 2015 +0300
+++ b/src/lib/test-lib.c	Mon Jun 15 14:31:19 2015 +0300
@@ -14,6 +14,7 @@
 		test_buffer,
 		test_crc32,
 		test_data_stack,
+		test_failures,
 		test_guid,
 		test_hash,
 		test_hash_format,
diff -r 8739d201898c -r 6d965c726810 src/lib/test-lib.h
--- a/src/lib/test-lib.h	Mon Jun 15 14:31:19 2015 +0300
+++ b/src/lib/test-lib.h	Mon Jun 15 14:31:19 2015 +0300
@@ -15,6 +15,7 @@
 void test_crc32(void);
 void test_data_stack(void);
 enum fatal_test_state fatal_data_stack(int);
+void test_failures(void);
 void test_guid(void);
 void test_hash(void);
 void test_hash_format(void);


More information about the dovecot-cvs mailing list