mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-11-25 15:15:42 +00:00
Simplify existing tests:
- Set t_malloc_fatal so we don't have to check for allocation failures (the driver will catch the SIGABRT). - Use string_dup_cs() instead of string_new() + string_append_cs().
This commit is contained in:
parent
454603d4f1
commit
4fa82f7c7b
1 changed files with 8 additions and 14 deletions
|
@ -106,12 +106,9 @@ t_compare_test(char **desc CRYB_UNUSED, void *arg)
|
|||
string *s1, *s2;
|
||||
int ret;
|
||||
|
||||
if ((s1 = string_new()) == NULL ||
|
||||
string_append_cs(s1, t->s1, SIZE_MAX) < 0 ||
|
||||
(s2 = string_new()) == NULL ||
|
||||
string_append_cs(s2, t->s2, SIZE_MAX) < 0)
|
||||
return (0);
|
||||
ret = string_compare(s1, s2) == t->cmp;
|
||||
s1 = string_dup_cs(t->s1, SIZE_MAX);
|
||||
s2 = string_dup_cs(t->s2, SIZE_MAX);
|
||||
ret = t_compare_i(t->cmp, string_compare(s1, s2));
|
||||
string_delete(s2);
|
||||
string_delete(s1);
|
||||
return (ret);
|
||||
|
@ -124,12 +121,9 @@ t_equal_test(char **desc CRYB_UNUSED, void *arg)
|
|||
string *s1, *s2;
|
||||
int ret;
|
||||
|
||||
if ((s1 = string_new()) == NULL ||
|
||||
string_append_cs(s1, t->s1, SIZE_MAX) < 0 ||
|
||||
(s2 = string_new()) == NULL ||
|
||||
string_append_cs(s2, t->s2, SIZE_MAX) < 0)
|
||||
return (0);
|
||||
ret = (string_equal(s1, s2) == 0) == (t->cmp != 0);
|
||||
s1 = string_dup_cs(t->s1, SIZE_MAX);
|
||||
s2 = string_dup_cs(t->s2, SIZE_MAX);
|
||||
ret = t_compare_i(t->cmp != 0, string_equal(s1, s2) == 0);
|
||||
string_delete(s2);
|
||||
string_delete(s1);
|
||||
return (ret);
|
||||
|
@ -147,8 +141,7 @@ t_trunc_test(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
|
|||
ssize_t len;
|
||||
int ret;
|
||||
|
||||
if ((s = string_dup_cs(CS("magic ossifrage"), SIZE_MAX)) == NULL)
|
||||
return (0);
|
||||
s = string_dup_cs(CS("magic ossifrage"), SIZE_MAX);
|
||||
if (!t_compare_sz(15, (len = string_len(s))))
|
||||
return (0);
|
||||
ret = t_compare_ssz(len, string_trunc(s, SIZE_MAX)) &
|
||||
|
@ -172,6 +165,7 @@ t_prepare(int argc, char *argv[])
|
|||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
t_malloc_fatal = 1;
|
||||
t_add_test(t_noop, NULL, "no-op");
|
||||
for (i = 0; i < sizeof t_compare_cases / sizeof *t_compare_cases; ++i)
|
||||
t_add_test(t_compare_test, &t_compare_cases[i],
|
||||
|
|
Loading…
Reference in a new issue