]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test fatal cases for printf_format_fix
authorPhil Carmody <phil@dovecot.fi>
Wed, 30 Jul 2014 12:01:29 +0000 (15:01 +0300)
committerPhil Carmody <phil@dovecot.fi>
Wed, 30 Jul 2014 12:01:29 +0000 (15:01 +0300)
Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/test-lib.c
src/lib/test-lib.h
src/lib/test-printf-format-fix.c

index 98e419077d57d9a33c6746affe0203bbbadea2ae..05fae909f71953a800d082fc1468c6c9770441a9 100644 (file)
@@ -49,6 +49,7 @@ int main(void)
        };
        static enum fatal_test_state (*fatal_functions[])(int) = {
                fatal_mempool,
+               fatal_printf_format_fix,
                NULL
        };
        return test_run_with_fatals(test_functions, fatal_functions);
index 07549078fccb79c8ea9a97555ff6f89c7e94de36..b389b4f49f97a924293d150a90accea17707961d 100644 (file)
@@ -33,6 +33,7 @@ void test_numpack(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);
 void test_priorityq(void);
 void test_seq_range_array(void);
 void test_str(void);
index 480f657d87c90185733de5de399539c57433994b..3e5ecc25eef73ea71996a9327cbbbc49b263a978 100644 (file)
@@ -92,5 +92,27 @@ void test_printf_format_fix()
 {
        test_unchanged();
        test_ok_changes();
-       /* want to test the panics too */
+}
+
+/* Want to test the panics too? go for it! */
+enum fatal_test_state fatal_printf_format_fix(int stage)
+{
+       static const char *fatals[] = {
+               "no no no %n's",
+               "%m allowed once, but not twice: %m",
+               "%m must not obscure a later %n",
+               "definitely can't have a tailing %",
+       };
+
+       if((unsigned int)stage >= N_ELEMENTS(fatals)) {
+               test_end();
+               return FATAL_TEST_FINISHED;
+       }
+
+       if(stage == 0)
+               test_begin("fatal_printf_format_fix");
+
+       /* let's crash! */
+       (void)printf_format_fix(fatals[stage]);
+       return FATAL_TEST_FAILURE;
 }