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;
|
string *s1, *s2;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((s1 = string_new()) == NULL ||
|
s1 = string_dup_cs(t->s1, SIZE_MAX);
|
||||||
string_append_cs(s1, t->s1, SIZE_MAX) < 0 ||
|
s2 = string_dup_cs(t->s2, SIZE_MAX);
|
||||||
(s2 = string_new()) == NULL ||
|
ret = t_compare_i(t->cmp, string_compare(s1, s2));
|
||||||
string_append_cs(s2, t->s2, SIZE_MAX) < 0)
|
|
||||||
return (0);
|
|
||||||
ret = string_compare(s1, s2) == t->cmp;
|
|
||||||
string_delete(s2);
|
string_delete(s2);
|
||||||
string_delete(s1);
|
string_delete(s1);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
@ -124,12 +121,9 @@ t_equal_test(char **desc CRYB_UNUSED, void *arg)
|
||||||
string *s1, *s2;
|
string *s1, *s2;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((s1 = string_new()) == NULL ||
|
s1 = string_dup_cs(t->s1, SIZE_MAX);
|
||||||
string_append_cs(s1, t->s1, SIZE_MAX) < 0 ||
|
s2 = string_dup_cs(t->s2, SIZE_MAX);
|
||||||
(s2 = string_new()) == NULL ||
|
ret = t_compare_i(t->cmp != 0, string_equal(s1, s2) == 0);
|
||||||
string_append_cs(s2, t->s2, SIZE_MAX) < 0)
|
|
||||||
return (0);
|
|
||||||
ret = (string_equal(s1, s2) == 0) == (t->cmp != 0);
|
|
||||||
string_delete(s2);
|
string_delete(s2);
|
||||||
string_delete(s1);
|
string_delete(s1);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
@ -147,8 +141,7 @@ t_trunc_test(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((s = string_dup_cs(CS("magic ossifrage"), SIZE_MAX)) == NULL)
|
s = string_dup_cs(CS("magic ossifrage"), SIZE_MAX);
|
||||||
return (0);
|
|
||||||
if (!t_compare_sz(15, (len = string_len(s))))
|
if (!t_compare_sz(15, (len = string_len(s))))
|
||||||
return (0);
|
return (0);
|
||||||
ret = t_compare_ssz(len, string_trunc(s, SIZE_MAX)) &
|
ret = t_compare_ssz(len, string_trunc(s, SIZE_MAX)) &
|
||||||
|
@ -172,6 +165,7 @@ t_prepare(int argc, char *argv[])
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
|
t_malloc_fatal = 1;
|
||||||
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],
|
||||||
|
|
Loading…
Reference in a new issue