test-printf-format-fix.c revision 98c59517ebce19556221065e9231f007bbdd0038
/* Copyright (c) 2001-2015 Dovecot authors, see the included COPYING file */
/* Unit tests for printf-format-fix helper */
#include "test-lib.h"
#include "printf-format-fix.h"
#include <string.h>
struct format_fix_rewrites {
const char *input;
const char *output;
};
static void test_unchanged()
{
static const char *tests[] = {
"Hello world",
"Embedded %%, %u, %f, etc. are OK",
"%%doesn't cause confusion in %%m and %%n",
};
unsigned int i;
test_begin("printf_format_fix(safe)");
for (i = 0; i < N_ELEMENTS(tests); ++i) {
unsigned int len;
T_BEGIN {
== tests[i], i);
== tests[i], i);
} T_END;
}
test_end();
}
static void test_ok_changes()
{
static const char *tests[] = {
"OK to have a trailing %m",
"%m can appear at the start too",
"Even %m in the middle with a confusing %%m elsewhere is OK",
};
unsigned int i;
const char *needle;
unsigned int needlen;
test_begin("printf_format_fix(rewrites)");
for (i = 0; i < N_ELEMENTS(tests); ++i) {
unsigned int len;
char const *chgd;
char const *insert;
unsigned int offs;
T_BEGIN {
} T_END;
}
test_end();
}
void test_printf_format_fix()
{
}
/* Want to test the panics too? go for it! */
{
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 %",
};
test_end();
return FATAL_TEST_FINISHED;
}
if(stage == 0)
test_begin("fatal_printf_format_fix");
/* let's crash! */
return FATAL_TEST_FAILURE;
}