changeset 21297:083846b77c3b

lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 12 Dec 2016 15:16:34 +0200
parents aa676841ed89
children e99464c82e52
files src/lib-test/test-common.c src/lib-test/test-common.h
diffstat 2 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-test/test-common.c	Mon Dec 12 09:41:02 2016 +0200
+++ b/src/lib-test/test-common.c	Mon Dec 12 15:16:34 2016 +0200
@@ -256,7 +256,7 @@
 	}
 }
 
-static void run_one_fatal(enum fatal_test_state (*fatal_function)(int))
+static void run_one_fatal(test_fatal_func_t *fatal_function)
 {
 	static int index = 0;
 	for (;;) {
@@ -287,7 +287,7 @@
 		}
 	}
 }
-static void test_run_fatals(enum fatal_test_state (*fatal_functions[])(int index))
+static void test_run_fatals(test_fatal_func_t *fatal_functions[])
 {
 	unsigned int i;
 
@@ -321,7 +321,7 @@
 	return test_deinit();
 }
 int test_run_with_fatals(void (*test_functions[])(void),
-			 enum fatal_test_state (*fatal_functions[])(int))
+			 test_fatal_func_t *fatal_functions[])
 {
 	test_init();
 	test_run_funcs(test_functions);
--- a/src/lib-test/test-common.h	Mon Dec 12 09:41:02 2016 +0200
+++ b/src/lib-test/test-common.h	Mon Dec 12 15:16:34 2016 +0200
@@ -68,12 +68,18 @@
 	FATAL_TEST_FAILURE,  /* single stage has failed, continue */
 	FATAL_TEST_ABORT,    /* something's gone horrifically wrong */
 };
+/* The fatal function is called first with stage=0. After each call the stage
+   is increased by 1. The idea is that each stage would be running an
+   individual test that is supposed to crash. The function is called until
+   FATAL_TEST_FINISHED or FATAL_TEST_ABORT is returned. */
+typedef enum fatal_test_state test_fatal_func_t(int stage);
+
 struct named_fatal {
 	const char *name;
-	enum fatal_test_state (*func)(int);
+	test_fatal_func_t *func;
 };
 int test_run_with_fatals(void (*test_functions[])(void),
-			 enum fatal_test_state (*fatal_functions[])(int));
+			 test_fatal_func_t *fatal_functions[]);
 int test_run_named_with_fatals(const char *match, struct named_test tests[],
 			       struct named_fatal fatals[]);