summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-27 16:43:11 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-27 16:43:11 +0200
commit625368eb5bcb9954ad190af50962e6b7c2fd9c4c (patch)
tree48779d7e54b4fa3df83df39fff76b54d93aacedf /tests
parent720023d968b24fe358fd4cfb002d8572f6cc96e7 (diff)
Cleanup: remove most of the payload pointer magic from libfstree
Now that dir_info_t and file_info_t have reasonably small, use them in tree_node_t directly instead of doing pointer arithmetic magic on the payload area. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/add_by_path.c14
-rw-r--r--tests/fstree_from_file.c20
-rw-r--r--tests/gen_inode_table.c8
-rw-r--r--tests/mknode_dir.c15
-rw-r--r--tests/mknode_reg.c7
-rw-r--r--tests/mknode_simple.c12
-rw-r--r--tests/mknode_slink.c4
7 files changed, 37 insertions, 43 deletions
diff --git a/tests/add_by_path.c b/tests/add_by_path.c
index 610cb79..afed438 100644
--- a/tests/add_by_path.c
+++ b/tests/add_by_path.c
@@ -37,8 +37,8 @@ int main(void)
assert(a->gid == sb.st_gid);
assert(a->parent == fs.root);
assert(a->next == NULL);
- assert(fs.root->data.dir->children == a);
- assert(!a->data.dir->created_implicitly);
+ assert(fs.root->data.dir.children == a);
+ assert(!a->data.dir.created_implicitly);
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFBLK | 0640;
@@ -54,7 +54,7 @@ int main(void)
assert(b->parent == fs.root);
assert(b->data.devno == sb.st_rdev);
assert(b->next == a);
- assert(fs.root->data.dir->children == b);
+ assert(fs.root->data.dir.children == b);
assert(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL) == NULL);
assert(errno == ENOTDIR);
@@ -77,7 +77,7 @@ int main(void)
assert(b->parent == a);
assert(b->data.devno == sb.st_rdev);
assert(b->next == NULL);
- assert(a->data.dir->children == b);
+ assert(a->data.dir.children == b);
b = fstree_add_generic(&fs, "dir/foo/chrdev", &sb, NULL);
assert(b != NULL);
@@ -89,10 +89,10 @@ int main(void)
assert(b->parent->parent == a);
assert(b->data.devno == sb.st_rdev);
assert(b->next == NULL);
- assert(a->data.dir->children != b);
+ assert(a->data.dir.children != b);
b = b->parent;
- assert(b->data.dir->created_implicitly);
+ assert(b->data.dir.created_implicitly);
assert(b->mode == (S_IFDIR | 0755));
assert(b->uid == 21);
assert(b->gid == 42);
@@ -105,7 +105,7 @@ int main(void)
a = fstree_add_generic(&fs, "dir/foo", &sb, NULL);
assert(a != NULL);
assert(a == b);
- assert(!a->data.dir->created_implicitly);
+ assert(!a->data.dir.created_implicitly);
assert(a->mode == sb.st_mode);
assert(a->uid == sb.st_uid);
assert(a->gid == sb.st_gid);
diff --git a/tests/fstree_from_file.c b/tests/fstree_from_file.c
index 1b9fd76..a8e05c3 100644
--- a/tests/fstree_from_file.c
+++ b/tests/fstree_from_file.c
@@ -42,7 +42,7 @@ int main(void)
assert(fstree_from_file(&fs, "testfile", fp) == 0);
tree_node_sort_recursive(fs.root);
- n = fs.root->data.dir->children;
+ n = fs.root->data.dir.children;
assert(n->mode == (S_IFBLK | 0600));
assert(n->uid == 8);
@@ -62,21 +62,21 @@ int main(void)
assert(n->uid == 4);
assert(n->gid == 5);
assert(strcmp(n->name, "dir") == 0);
- assert(n->data.dir->children == NULL);
+ assert(n->data.dir.children == NULL);
n = n->next;
assert(n->mode == (S_IFDIR | 0755));
assert(n->uid == 0);
assert(n->gid == 0);
assert(strcmp(n->name, "foo bar") == 0);
- assert(n->data.dir->children != NULL);
-
- assert(n->data.dir->children->next == NULL);
- assert(n->data.dir->children->mode == (S_IFDIR | 0755));
- assert(n->data.dir->children->uid == 0);
- assert(n->data.dir->children->gid == 0);
- assert(strcmp(n->data.dir->children->name, " test \"") == 0);
- assert(n->data.dir->children->data.dir->children == NULL);
+ assert(n->data.dir.children != NULL);
+
+ assert(n->data.dir.children->next == NULL);
+ assert(n->data.dir.children->mode == (S_IFDIR | 0755));
+ assert(n->data.dir.children->uid == 0);
+ assert(n->data.dir.children->gid == 0);
+ assert(strcmp(n->data.dir.children->name, " test \"") == 0);
+ assert(n->data.dir.children->data.dir.children == NULL);
n = n->next;
assert(n->mode == (S_IFIFO | 0644));
diff --git a/tests/gen_inode_table.c b/tests/gen_inode_table.c
index 190f393..cf140c8 100644
--- a/tests/gen_inode_table.c
+++ b/tests/gen_inode_table.c
@@ -26,10 +26,10 @@ static void check_children_before_root(tree_node_t *root)
{
tree_node_t *n;
- for (n = root->data.dir->children; n != NULL; n = n->next)
+ for (n = root->data.dir.children; n != NULL; n = n->next)
assert(n->inode_num < root->inode_num);
- for (n = root->data.dir->children; n != NULL; n = n->next)
+ for (n = root->data.dir.children; n != NULL; n = n->next)
check_children_before_root(n);
}
@@ -37,13 +37,13 @@ static void check_children_continuous(tree_node_t *root)
{
tree_node_t *n;
- for (n = root->data.dir->children; n != NULL; n = n->next) {
+ for (n = root->data.dir.children; n != NULL; n = n->next) {
if (n->next != NULL) {
assert(n->next->inode_num == (n->inode_num + 1));
}
}
- for (n = root->data.dir->children; n != NULL; n = n->next)
+ for (n = root->data.dir.children; n != NULL; n = n->next)
check_children_continuous(n);
}
diff --git a/tests/mknode_dir.c b/tests/mknode_dir.c
index 2ca189d..3b6aeda 100644
--- a/tests/mknode_dir.c
+++ b/tests/mknode_dir.c
@@ -26,29 +26,28 @@ int main(void)
sb.st_rdev = 789;
sb.st_size = 4096;
- root = fstree_mknode(NULL, "rootdir", 7, (void *)0x100, &sb);
+ root = fstree_mknode(NULL, "rootdir", 7, NULL, &sb);
assert(root->uid == sb.st_uid);
assert(root->gid == sb.st_gid);
assert(root->mode == sb.st_mode);
assert((char *)root->name >= (char *)root->payload);
- assert((char *)root->data.dir >= (char *)root->payload);
- assert(root->name >= (char *)(root->data.dir + 1));
+ assert(root->name >= (char *)root->payload);
assert(strcmp(root->name, "rootdir") == 0);
- assert(root->data.dir->children == NULL);
+ assert(root->data.dir.children == NULL);
assert(root->parent == NULL);
assert(root->next == NULL);
- a = fstree_mknode(root, "adir", 4, (void *)0x100, &sb);
+ a = fstree_mknode(root, "adir", 4, NULL, &sb);
assert(a->parent == root);
assert(a->next == NULL);
- assert(root->data.dir->children == a);
+ assert(root->data.dir.children == a);
assert(root->parent == NULL);
assert(root->next == NULL);
- b = fstree_mknode(root, "bdir", 4, (void *)0x100, &sb);
+ b = fstree_mknode(root, "bdir", 4, NULL, &sb);
assert(a->parent == root);
assert(b->parent == root);
- assert(root->data.dir->children == b);
+ assert(root->data.dir.children == b);
assert(b->next == a);
assert(a->next == NULL);
assert(root->parent == NULL);
diff --git a/tests/mknode_reg.c b/tests/mknode_reg.c
index b9c81e0..9d5267f 100644
--- a/tests/mknode_reg.c
+++ b/tests/mknode_reg.c
@@ -34,11 +34,10 @@ int main(void)
assert(node->mode == sb.st_mode);
assert(node->parent == NULL);
assert((char *)node->name >= (char *)node->payload);
- assert((char *)node->data.file >= (char *)node->payload);
- assert(node->data.file->input_file >= (char *)(node->data.file + 1));
- assert(node->name >= node->data.file->input_file + 6);
+ assert(node->data.file.input_file >= (char *)node->payload);
+ assert(node->data.file.input_file >= node->name + 8);
assert(strcmp(node->name, "filename") == 0);
- assert(strcmp(node->data.file->input_file, "input") == 0);
+ assert(strcmp(node->data.file.input_file, "input") == 0);
free(node);
return EXIT_SUCCESS;
diff --git a/tests/mknode_simple.c b/tests/mknode_simple.c
index e872369..e77f4ff 100644
--- a/tests/mknode_simple.c
+++ b/tests/mknode_simple.c
@@ -26,15 +26,13 @@ int main(void)
sb.st_rdev = 789;
sb.st_size = 1337;
- node = fstree_mknode(NULL, "sockfile", 8, (void *)0x1000, &sb);
+ node = fstree_mknode(NULL, "sockfile", 8, NULL, &sb);
assert((char *)node->name >= (char *)node->payload);
assert(strcmp(node->name, "sockfile") == 0);
assert(node->uid == sb.st_uid);
assert(node->gid == sb.st_gid);
assert(node->mode == sb.st_mode);
assert(node->parent == NULL);
- assert(node->data.dir == NULL);
- assert(node->data.file == NULL);
assert(node->data.slink_target == NULL);
assert(node->data.devno == 0);
free(node);
@@ -47,15 +45,13 @@ int main(void)
sb.st_rdev = 789;
sb.st_size = 1337;
- node = fstree_mknode(NULL, "fifo", 4, (void *)0x1000, &sb);
+ node = fstree_mknode(NULL, "fifo", 4, NULL, &sb);
assert((char *)node->name >= (char *)node->payload);
assert(strcmp(node->name, "fifo") == 0);
assert(node->uid == sb.st_uid);
assert(node->gid == sb.st_gid);
assert(node->mode == sb.st_mode);
assert(node->parent == NULL);
- assert(node->data.dir == NULL);
- assert(node->data.file == NULL);
assert(node->data.slink_target == NULL);
assert(node->data.devno == 0);
free(node);
@@ -68,7 +64,7 @@ int main(void)
sb.st_rdev = 789;
sb.st_size = 1337;
- node = fstree_mknode(NULL, "blkdev", 6, (void *)0x1000, &sb);
+ node = fstree_mknode(NULL, "blkdev", 6, NULL, &sb);
assert((char *)node->name >= (char *)node->payload);
assert(strcmp(node->name, "blkdev") == 0);
assert(node->uid == sb.st_uid);
@@ -86,7 +82,7 @@ int main(void)
sb.st_rdev = 789;
sb.st_size = 1337;
- node = fstree_mknode(NULL, "chardev", 7, (void *)0x1000, &sb);
+ node = fstree_mknode(NULL, "chardev", 7, NULL, &sb);
assert((char *)node->name >= (char *)node->payload);
assert(strcmp(node->name, "chardev") == 0);
assert(node->uid == sb.st_uid);
diff --git a/tests/mknode_slink.c b/tests/mknode_slink.c
index bbf7045..20cf38a 100644
--- a/tests/mknode_slink.c
+++ b/tests/mknode_slink.c
@@ -33,7 +33,7 @@ int main(void)
assert(node->parent == NULL);
assert((char *)node->name >= (char *)node->payload);
assert(node->data.slink_target >= (char *)node->payload);
- assert(node->name >= node->data.slink_target + 7);
+ assert(node->data.slink_target >= node->name + 8);
assert(strcmp(node->name, "symlink") == 0);
assert(strcmp(node->data.slink_target, "target") == 0);
free(node);
@@ -45,7 +45,7 @@ int main(void)
assert(node->parent == NULL);
assert((char *)node->name >= (char *)node->payload);
assert(node->data.slink_target >= (char *)node->payload);
- assert(node->name >= node->data.slink_target + 1);
+ assert(node->data.slink_target >= node->name + 8);
assert(strcmp(node->name, "symlink") == 0);
assert(node->data.slink_target[0] == '\0');
free(node);