summaryrefslogtreecommitdiff
path: root/tests/add_by_path.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/add_by_path.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/add_by_path.c')
-rw-r--r--tests/add_by_path.c160
1 files changed, 78 insertions, 82 deletions
diff --git a/tests/add_by_path.c b/tests/add_by_path.c
index 6abf05f..f575011 100644
--- a/tests/add_by_path.c
+++ b/tests/add_by_path.c
@@ -7,11 +7,7 @@
#include "config.h"
#include "fstree.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
+#include "test.h"
int main(void)
{
@@ -21,7 +17,7 @@ int main(void)
char *opts;
opts = strdup("mode=0755,uid=21,gid=42");
- assert(fstree_init(&fs, opts) == 0);
+ TEST_ASSERT(fstree_init(&fs, opts) == 0);
free(opts);
memset(&sb, 0, sizeof(sb));
@@ -29,88 +25,88 @@ int main(void)
sb.st_uid = 1000;
sb.st_gid = 100;
- assert(fs.root->link_count == 2);
+ TEST_EQUAL_UI(fs.root->link_count, 2);
a = fstree_add_generic(&fs, "dir", &sb, NULL);
- assert(a != NULL);
- assert(strcmp(a->name, "dir") == 0);
- assert(a->mode == sb.st_mode);
- assert(a->uid == sb.st_uid);
- assert(a->gid == sb.st_gid);
- assert(a->parent == fs.root);
- assert(a->link_count == 2);
- assert(a->next == NULL);
- assert(fs.root->data.dir.children == a);
- assert(fs.root->link_count == 3);
- assert(!a->data.dir.created_implicitly);
+ TEST_NOT_NULL(a);
+ TEST_STR_EQUAL(a->name, "dir");
+ TEST_EQUAL_UI(a->mode, sb.st_mode);
+ TEST_EQUAL_UI(a->uid, sb.st_uid);
+ TEST_EQUAL_UI(a->gid, sb.st_gid);
+ TEST_ASSERT(a->parent == fs.root);
+ TEST_EQUAL_UI(a->link_count, 2);
+ TEST_NULL(a->next);
+ TEST_ASSERT(fs.root->data.dir.children == a);
+ TEST_EQUAL_UI(fs.root->link_count, 3);
+ TEST_ASSERT(!a->data.dir.created_implicitly);
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFBLK | 0640;
sb.st_rdev = 1234;
b = fstree_add_generic(&fs, "blkdev", &sb, NULL);
- assert(b != NULL);
- assert(b != a);
- assert(strcmp(b->name, "blkdev") == 0);
- assert(b->mode == sb.st_mode);
- assert(b->uid == sb.st_uid);
- assert(b->gid == sb.st_gid);
- assert(b->parent == fs.root);
- assert(b->link_count == 1);
- assert(b->data.devno == sb.st_rdev);
- assert(b->next == a);
- assert(fs.root->link_count == 4);
- assert(fs.root->data.dir.children == b);
-
- assert(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL) == NULL);
- assert(errno == ENOTDIR);
-
- assert(fstree_add_generic(&fs, "dir", &sb, NULL) == NULL);
- assert(errno == EEXIST);
+ TEST_NOT_NULL(b);
+ TEST_ASSERT(b != a);
+ TEST_STR_EQUAL(b->name, "blkdev");
+ TEST_EQUAL_UI(b->mode, sb.st_mode);
+ TEST_EQUAL_UI(b->uid, sb.st_uid);
+ TEST_EQUAL_UI(b->gid, sb.st_gid);
+ TEST_ASSERT(b->parent == fs.root);
+ TEST_EQUAL_UI(b->link_count, 1);
+ TEST_EQUAL_UI(b->data.devno, sb.st_rdev);
+ TEST_ASSERT(b->next == a);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+ TEST_ASSERT(fs.root->data.dir.children == b);
+
+ TEST_NULL(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL));
+ TEST_EQUAL_UI(errno, ENOTDIR);
+
+ TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL));
+ TEST_EQUAL_UI(errno, EEXIST);
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFDIR | 0755;
- assert(fstree_add_generic(&fs, "dir", &sb, NULL) == NULL);
- assert(errno == EEXIST);
+ TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL));
+ TEST_EQUAL_UI(errno, EEXIST);
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFCHR | 0444;
b = fstree_add_generic(&fs, "dir/chrdev", &sb, NULL);
- assert(b != NULL);
- assert(b->mode == sb.st_mode);
- assert(b->uid == sb.st_uid);
- assert(b->gid == sb.st_gid);
- assert(b->link_count == 1);
- assert(b->parent == a);
- assert(b->data.devno == sb.st_rdev);
- assert(b->next == NULL);
- assert(a->data.dir.children == b);
-
- assert(a->link_count == 3);
- assert(fs.root->link_count == 4);
+ TEST_NOT_NULL(b);
+ TEST_EQUAL_UI(b->mode, sb.st_mode);
+ TEST_EQUAL_UI(b->uid, sb.st_uid);
+ TEST_EQUAL_UI(b->gid, sb.st_gid);
+ TEST_EQUAL_UI(b->link_count, 1);
+ TEST_ASSERT(b->parent == a);
+ TEST_EQUAL_UI(b->data.devno, sb.st_rdev);
+ TEST_NULL(b->next);
+ TEST_ASSERT(a->data.dir.children == b);
+
+ TEST_EQUAL_UI(a->link_count, 3);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
b = fstree_add_generic(&fs, "dir/foo/chrdev", &sb, NULL);
- assert(b != NULL);
- assert(b->next == NULL);
- assert(b->mode == sb.st_mode);
- assert(b->uid == sb.st_uid);
- assert(b->gid == sb.st_gid);
- assert(b->link_count == 1);
- assert(b->parent != a);
- assert(b->parent->parent == a);
- assert(b->data.devno == sb.st_rdev);
- assert(b->next == NULL);
-
- assert(a->link_count == 4);
- assert(fs.root->link_count == 4);
- assert(a->data.dir.children != b);
+ TEST_NOT_NULL(b);
+ TEST_NULL(b->next);
+ TEST_EQUAL_UI(b->mode, sb.st_mode);
+ TEST_EQUAL_UI(b->uid, sb.st_uid);
+ TEST_EQUAL_UI(b->gid, sb.st_gid);
+ TEST_EQUAL_UI(b->link_count, 1);
+ TEST_ASSERT(b->parent != a);
+ TEST_ASSERT(b->parent->parent == a);
+ TEST_EQUAL_UI(b->data.devno, sb.st_rdev);
+ TEST_NULL(b->next);
+
+ TEST_EQUAL_UI(a->link_count, 4);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+ TEST_ASSERT(a->data.dir.children != b);
b = b->parent;
- assert(b->data.dir.created_implicitly);
- assert(b->mode == (S_IFDIR | 0755));
- assert(b->uid == 21);
- assert(b->gid == 42);
- assert(b->link_count == 3);
+ TEST_ASSERT(b->data.dir.created_implicitly);
+ TEST_EQUAL_UI(b->mode, S_IFDIR | 0755);
+ TEST_EQUAL_UI(b->uid, 21);
+ TEST_EQUAL_UI(b->gid, 42);
+ TEST_EQUAL_UI(b->link_count, 3);
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFDIR | 0750;
@@ -118,19 +114,19 @@ int main(void)
sb.st_gid = 100;
a = fstree_add_generic(&fs, "dir/foo", &sb, NULL);
- assert(a != NULL);
- assert(a == b);
- assert(!a->data.dir.created_implicitly);
- assert(a->mode == sb.st_mode);
- assert(a->uid == sb.st_uid);
- assert(a->gid == sb.st_gid);
- assert(a->link_count == 3);
-
- assert(a->parent->link_count == 4);
- assert(fs.root->link_count == 4);
-
- assert(fstree_add_generic(&fs, "dir/foo", &sb, NULL) == NULL);
- assert(errno == EEXIST);
+ TEST_NOT_NULL(a);
+ TEST_ASSERT(a == b);
+ TEST_ASSERT(!a->data.dir.created_implicitly);
+ TEST_EQUAL_UI(a->mode, sb.st_mode);
+ TEST_EQUAL_UI(a->uid, sb.st_uid);
+ TEST_EQUAL_UI(a->gid, sb.st_gid);
+ TEST_EQUAL_UI(a->link_count, 3);
+
+ TEST_EQUAL_UI(a->parent->link_count, 4);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+
+ TEST_NULL(fstree_add_generic(&fs, "dir/foo", &sb, NULL));
+ TEST_EQUAL_UI(errno, EEXIST);
fstree_cleanup(&fs);
return EXIT_SUCCESS;