]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 15 Dec 2016 14:20:39 +0000 (16:20 +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-lib.c
src/lib/test-lib.h
src/lib/test-mempool-alloconly.c
src/lib/test-printf-format-fix.c

index 01ce0526fe92bd6d35fa9497970e7c8bce4bca7d..96b9daa7c1ef6e757eb21158c7577d148bb38e29 100644 (file)
@@ -258,7 +258,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 c3fd7b3012993a2b9d27aaee1c3a445a74db92c0..2dd1c0e68682281014c705e2902ad7d0d92ea5d4 100644 (file)
@@ -238,7 +238,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};
@@ -276,7 +276,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 055ac3d57a86812bb4bf3274de5d72596043c484..2da1ac48baba8aa553d3b68bb272725b5c8d000a 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
        /* If we abort, then we'll be left with a dangling t_push()
index 58911c09376848088ef746736cd0a098dcbe05dd..bfb3bdbd3ce6186679e3e9bf0ffc639c1382005b 100644 (file)
@@ -63,7 +63,7 @@ int main(void)
                test_wildcard_match,
                NULL
        };
-       static enum fatal_test_state (*fatal_functions[])(int) = {
+       static enum fatal_test_state (*fatal_functions[])(unsigned int) = {
                fatal_array,
                fatal_data_stack,
                fatal_mempool,
index 5c81fe0c8dddfb349e425c3ca91a12051051622d..e7667d68ce9087b6c931dc5acf13f3ac3d5baf67 100644 (file)
@@ -6,7 +6,7 @@
 
 void test_aqueue(void);
 void test_array(void);
-enum fatal_test_state fatal_array(int);
+enum fatal_test_state fatal_array(unsigned int);
 void test_base32(void);
 void test_base64(void);
 void test_bits(void);
@@ -14,7 +14,7 @@ void test_bsearch_insert_pos(void);
 void test_buffer(void);
 void test_crc32(void);
 void test_data_stack(void);
-enum fatal_test_state fatal_data_stack(int);
+enum fatal_test_state fatal_data_stack(unsigned int);
 void test_failures(void);
 void test_guid(void);
 void test_hash(void);
@@ -39,7 +39,7 @@ void test_json_tree(void);
 void test_llist(void);
 void test_log_throttle(void);
 void test_mempool_alloconly(void);
-enum fatal_test_state fatal_mempool(int);
+enum fatal_test_state fatal_mempool(unsigned int);
 void test_pkcs5_pbkdf2(void);
 void test_net(void);
 void test_numpack(void);
@@ -48,7 +48,7 @@ void test_ostream_failure_at(void);
 void test_ostream_file(void);
 void test_primes(void);
 void test_printf_format_fix(void);
-enum fatal_test_state fatal_printf_format_fix(int);
+enum fatal_test_state fatal_printf_format_fix(unsigned int);
 void test_priorityq(void);
 void test_seq_range_array(void);
 void test_str(void);
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;
        }