I had forgotten that t_add_test() is actually a printf()-like variadic

function, which obviates the need for asprintf() in the string comparison
and equality tests.
This commit is contained in:
Dag-Erling Smørgrav 2014-12-29 14:24:08 +00:00 committed by des
parent 3333bd5709
commit 7a09b0638f

View file

@ -100,13 +100,12 @@ static struct t_compare_case {
}; };
static int static int
t_compare_test(char **desc, void *arg) t_compare_test(char **desc CRYB_UNUSED, void *arg)
{ {
struct t_compare_case *t = arg; struct t_compare_case *t = arg;
string *s1, *s2; string *s1, *s2;
int ret; int ret;
asprintf(desc, "%s(%s)", "string_compare", *desc);
if ((s1 = string_new()) == NULL || if ((s1 = string_new()) == NULL ||
string_append_cs(s1, t->s1, SIZE_MAX) < 0 || string_append_cs(s1, t->s1, SIZE_MAX) < 0 ||
(s2 = string_new()) == NULL || (s2 = string_new()) == NULL ||
@ -119,13 +118,12 @@ t_compare_test(char **desc, void *arg)
} }
static int static int
t_equal_test(char **desc, void *arg) t_equal_test(char **desc CRYB_UNUSED, void *arg)
{ {
struct t_compare_case *t = arg; struct t_compare_case *t = arg;
string *s1, *s2; string *s1, *s2;
int ret; int ret;
asprintf(desc, "%s(%s)", "string_equal", *desc);
if ((s1 = string_new()) == NULL || if ((s1 = string_new()) == NULL ||
string_append_cs(s1, t->s1, SIZE_MAX) < 0 || string_append_cs(s1, t->s1, SIZE_MAX) < 0 ||
(s2 = string_new()) == NULL || (s2 = string_new()) == NULL ||
@ -153,10 +151,10 @@ t_prepare(int argc, char *argv[])
t_add_test(t_noop, NULL, "no-op"); t_add_test(t_noop, NULL, "no-op");
for (i = 0; i < sizeof t_compare_cases / sizeof *t_compare_cases; ++i) for (i = 0; i < sizeof t_compare_cases / sizeof *t_compare_cases; ++i)
t_add_test(t_compare_test, &t_compare_cases[i], t_add_test(t_compare_test, &t_compare_cases[i],
t_compare_cases[i].desc); "%s(%s)", "string_compare", t_compare_cases[i].desc);
for (i = 0; i < sizeof t_compare_cases / sizeof *t_compare_cases; ++i) for (i = 0; i < sizeof t_compare_cases / sizeof *t_compare_cases; ++i)
t_add_test(t_equal_test, &t_compare_cases[i], t_add_test(t_equal_test, &t_compare_cases[i],
t_compare_cases[i].desc); "%s(%s)", "string_equal", t_compare_cases[i].desc);
return (0); return (0);
} }