]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: Change test_fatal_func_t to take unsigned int stage as parameter.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 12 Dec 2016 13:21:13 +0000 (15:21 +0200)
committerGitLab <gitlab@git.dovecot.net>
Wed, 14 Dec 2016 15:31:30 +0000 (17:31 +0200)
It could never be -1, so this makes it clearer. It also removes annoying
casts when comparing stage to e.g. N_ELEMENTS().

src/lib-test/test-common.c
src/lib-test/test-common.h
src/lib/test-array.c
src/lib/test-data-stack.c
src/lib/test-mempool-alloconly.c
src/lib/test-printf-format-fix.c

index 1c677a7356f64ddc08516044658f4ddacb21c620..51acaa7555af9bdfdad5df78c95b872e3cda265e 100644 (file)
@@ -250,7 +250,7 @@ static void test_run_named_funcs(struct named_test tests[], const char *match)
 
 static void run_one_fatal(test_fatal_func_t *fatal_function)
 {
-       static int index = 0;
+       static unsigned int index = 0;
        for (;;) {
                volatile int jumped = setjmp(fatal_jmpbuf);
                if (jumped == 0) {
index 057f7e287a5503bcb8318737db6ce58d9de2f684..5746707d91e1eb916d63ac75b3ce2e98357a301f 100644 (file)
@@ -72,7 +72,7 @@ enum fatal_test_state {
    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);
+typedef enum fatal_test_state test_fatal_func_t(unsigned int stage);
 
 struct named_fatal {
        const char *name;
@@ -83,7 +83,7 @@ int test_run_with_fatals(void (*test_functions[])(void),
 int test_run_named_with_fatals(const char *match, struct named_test tests[],
                               struct named_fatal fatals[]);
 
-#define FATAL_DECL(x) enum fatal_test_state x(int);
+#define FATAL_DECL(x) enum fatal_test_state x(unsigned int);
 #define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */
 #define FATAL_NAMED(x) { .name = #x , .func = x },
 
index 05751c30c7eca7e7c8a459b636cf4deaefa38096..d399c42ae0316bfaf19f28b79edba75d29e8df20 100644 (file)
@@ -292,7 +292,7 @@ void test_array(void)
        test_array_swap();
 }
 
-enum fatal_test_state fatal_array(int stage)
+enum fatal_test_state fatal_array(unsigned int stage)
 {
        double tmpd[2] = { 42., -42. };
        short tmps[8] = {1,2,3,4,5,6,7,8};
@@ -330,7 +330,7 @@ enum fatal_test_state fatal_array(int stage)
        test_end();
        /* Forces the compiler to check the value of useless_ptr, so that it
           must call array_idx (which is marked as pure, and gcc was desperate
-          to optimise out. Of course, gcc is unaware stage is never -1.*/
-       return (useless_ptr != NULL && stage == -1)
+          to optimise out. Of course, gcc is unaware stage is never UINT_MAX.*/
+       return (useless_ptr != NULL && stage == UINT_MAX)
                ? FATAL_TEST_FAILURE : FATAL_TEST_FINISHED;
 }
index 4f063ce351a348ab19d133ab09bdbbb37501eab5..94996b5ff684eeb5da9a5e90463e00e44ccc4bde 100644 (file)
@@ -145,7 +145,7 @@ void test_data_stack(void)
        test_ds_recursive(20, 80);
 }
 
-enum fatal_test_state fatal_data_stack(int stage)
+enum fatal_test_state fatal_data_stack(unsigned int stage)
 {
 #ifdef DEBUG
 #define NONEXISTENT_STACK_FRAME_ID (data_stack_frame_t)999999999
index 5658e202b5257ac477bed021a215839f03b6935b..3fa122e9a50fd4e54cde34acbf04807251bd693f 100644 (file)
@@ -53,7 +53,7 @@ void test_mempool_alloconly(void)
        test_end();
 }
 
-enum fatal_test_state fatal_mempool(int stage)
+enum fatal_test_state fatal_mempool(unsigned int stage)
 {
        static pool_t pool;
 
index 2dc685d1b9a258cfb44adb7f2bc5ed190e0ece61..26fb5b7eb21e670d94853ffafbc1a64ec3ebfa27 100644 (file)
@@ -95,7 +95,7 @@ void test_printf_format_fix()
 }
 
 /* Want to test the panics too? go for it! */
-enum fatal_test_state fatal_printf_format_fix(int stage)
+enum fatal_test_state fatal_printf_format_fix(unsigned int stage)
 {
        static const char *fatals[] = {
                "no no no %n's",
@@ -104,7 +104,7 @@ enum fatal_test_state fatal_printf_format_fix(int stage)
                "definitely can't have a tailing %",
        };
 
-       if((unsigned int)stage >= N_ELEMENTS(fatals)) {
+       if(stage >= N_ELEMENTS(fatals)) {
                test_end();
                return FATAL_TEST_FINISHED;
        }