summaryrefslogtreecommitdiff
path: root/tests/fstree_sort.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 09:38:43 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 09:38:43 +0200
commit15250710c63a2c3d230304e46a03532f787759fb (patch)
tree9fda47ad94248d133b7b48c67eba20d357c6694e /tests/fstree_sort.c
parent6b3e6d299d5298a5936dbba57f67cdfc4a406789 (diff)
tests: improve diagnostics output & make "release builds" work
This commit adds a few macros and helper functions for the unit test programs. Those are used instead of asserts to provide more fine grained diagnostics on the one hand and on the other hand because they also work if NDEBUG is defined, unlike asserts that get eliminated in that case. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/fstree_sort.c')
-rw-r--r--tests/fstree_sort.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/tests/fstree_sort.c b/tests/fstree_sort.c
index 5557678..40a270f 100644
--- a/tests/fstree_sort.c
+++ b/tests/fstree_sort.c
@@ -8,10 +8,7 @@
#include "fstree.h"
#include "internal.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
+#include "test.h"
int main(void)
{
@@ -28,41 +25,41 @@ int main(void)
b = fstree_mknode(NULL, "b", 1, NULL, &sb);
c = fstree_mknode(NULL, "c", 1, NULL, &sb);
d = fstree_mknode(NULL, "d", 1, NULL, &sb);
- assert(a != NULL && b != NULL && c != NULL && d != NULL);
+ TEST_ASSERT(a != NULL && b != NULL && c != NULL && d != NULL);
/* empty list */
- assert(tree_node_list_sort(NULL) == NULL);
+ TEST_NULL(tree_node_list_sort(NULL));
/* single element */
- assert(tree_node_list_sort(a) == a);
- assert(a->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(a) == a);
+ TEST_NULL(a->next);
/* two elements, reverse order */
b->next = a;
- assert(tree_node_list_sort(b) == a);
- assert(a->next == b);
- assert(b->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(b) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_NULL(b->next);
/* two elements, sorted order */
- assert(tree_node_list_sort(a) == a);
- assert(a->next == b);
- assert(b->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(a) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_NULL(b->next);
/* three elements, reverse order */
c->next = b;
b->next = a;
a->next = NULL;
- assert(tree_node_list_sort(c) == a);
- assert(a->next == b);
- assert(b->next == c);
- assert(c->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(c) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_ASSERT(b->next == c);
+ TEST_NULL(c->next);
/* three elements, ordered */
- assert(tree_node_list_sort(a) == a);
- assert(a->next == b);
- assert(b->next == c);
- assert(c->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(a) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_ASSERT(b->next == c);
+ TEST_NULL(c->next);
/* four elements, reverse order */
d->next = c;
@@ -70,18 +67,18 @@ int main(void)
b->next = a;
a->next = NULL;
- assert(tree_node_list_sort(d) == a);
- assert(a->next == b);
- assert(b->next == c);
- assert(c->next == d);
- assert(d->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(d) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_ASSERT(b->next == c);
+ TEST_ASSERT(c->next == d);
+ TEST_NULL(d->next);
/* four elements, sorted order */
- assert(tree_node_list_sort(a) == a);
- assert(a->next == b);
- assert(b->next == c);
- assert(c->next == d);
- assert(d->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(a) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_ASSERT(b->next == c);
+ TEST_ASSERT(c->next == d);
+ TEST_NULL(d->next);
/* force merge sort to go through LRLR pattern */
b->next = a;
@@ -89,11 +86,11 @@ int main(void)
d->next = c;
c->next = NULL;
- assert(tree_node_list_sort(b) == a);
- assert(a->next == b);
- assert(b->next == c);
- assert(c->next == d);
- assert(d->next == NULL);
+ TEST_ASSERT(tree_node_list_sort(b) == a);
+ TEST_ASSERT(a->next == b);
+ TEST_ASSERT(b->next == c);
+ TEST_ASSERT(c->next == d);
+ TEST_NULL(d->next);
/* cleanup and done */
free(a);