diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-05-29 20:16:38 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-05-30 14:47:14 +0200 |
commit | 50b67940c793e72656787469ced6e0245bb580b4 (patch) | |
tree | a35e728c1b5193867bba61747b4410898fd40ce2 /lib/fstree/test | |
parent | 926987f338f7b3aba99dc25afd442ddd3e70d16d (diff) |
libfstree: accept dir_entry_t instead of path and struct stat
Because the dir_entry_t also has a flag for had links, the regular
node and hard-link node interface can be unified. This simplifies
the users of libfstree (gensquashfs, tar2sqfs) since we can simply
hose the entries from an iterator directly into the tree.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/test')
-rw-r--r-- | lib/fstree/test/add_by_path.c | 107 | ||||
-rw-r--r-- | lib/fstree/test/fstree_sort.c | 38 | ||||
-rw-r--r-- | lib/fstree/test/gen_inode_numbers.c | 12 | ||||
-rw-r--r-- | lib/fstree/test/get_path.c | 35 | ||||
-rw-r--r-- | lib/fstree/test/mknode_dir.c | 41 | ||||
-rw-r--r-- | lib/fstree/test/mknode_reg.c | 47 | ||||
-rw-r--r-- | lib/fstree/test/mknode_simple.c | 148 | ||||
-rw-r--r-- | lib/fstree/test/mknode_slink.c | 60 |
8 files changed, 246 insertions, 242 deletions
diff --git a/lib/fstree/test/add_by_path.c b/lib/fstree/test/add_by_path.c index 7df1e55..7fb9d37 100644 --- a/lib/fstree/test/add_by_path.c +++ b/lib/fstree/test/add_by_path.c @@ -10,11 +10,24 @@ #include "common.h" #include "util/test.h" +static dir_entry_t *mkentry(const char *name, sqfs_u16 mode, sqfs_u32 uid, + sqfs_u32 gid) +{ + dir_entry_t *ent = calloc(1, sizeof(*ent) + strlen(name) + 1); + + TEST_NOT_NULL(ent); + strcpy(ent->name, name); + ent->mode = mode; + ent->uid = uid; + ent->gid = gid; + return ent; +} + int main(int argc, char **argv) { fstree_defaults_t fsd; tree_node_t *a, *b; - struct stat sb; + dir_entry_t *ent; fstree_t fs; char *opts; (void)argc; (void)argv; @@ -23,20 +36,16 @@ int main(int argc, char **argv) TEST_ASSERT(parse_fstree_defaults(&fsd, opts) == 0); free(opts); TEST_ASSERT(fstree_init(&fs, &fsd) == 0); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0750; - sb.st_uid = 1000; - sb.st_gid = 100; - TEST_EQUAL_UI(fs.root->link_count, 2); - a = fstree_add_generic(&fs, "dir", &sb, NULL); + ent = mkentry("dir", S_IFDIR | 0750, 1000, 100); + a = fstree_add_generic(&fs, ent, NULL); + free(ent); 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_EQUAL_UI(a->mode, (S_IFDIR | 0750)); + TEST_EQUAL_UI(a->uid, 1000); + TEST_EQUAL_UI(a->gid, 100); TEST_ASSERT(a->parent == fs.root); TEST_EQUAL_UI(a->link_count, 2); TEST_NULL(a->next); @@ -44,61 +53,68 @@ int main(int argc, char **argv) TEST_EQUAL_UI(fs.root->link_count, 3); TEST_ASSERT(!(a->flags & FLAG_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); + ent = mkentry("blkdev", S_IFBLK | 0640, 0, 0); + ent->rdev = 1234; + b = fstree_add_generic(&fs, ent, NULL); + free(ent); 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_EQUAL_UI(b->mode, (S_IFBLK | 0640)); + TEST_EQUAL_UI(b->uid, 0); + TEST_EQUAL_UI(b->gid, 0); TEST_ASSERT(b->parent == fs.root); TEST_EQUAL_UI(b->link_count, 1); - TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_EQUAL_UI(b->data.devno, 1234); TEST_ASSERT(b->next == a); TEST_EQUAL_UI(fs.root->link_count, 4); TEST_ASSERT(fs.root->data.children == b); - TEST_NULL(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL)); + ent = mkentry("blkdev/foo", S_IFBLK | 0640, 0, 0); + TEST_NULL(fstree_add_generic(&fs, ent, NULL)); TEST_EQUAL_UI(errno, ENOTDIR); + free(ent); - TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); + ent = mkentry("dir", S_IFBLK | 0640, 0, 0); + TEST_NULL(fstree_add_generic(&fs, ent, NULL)); TEST_EQUAL_UI(errno, EEXIST); + free(ent); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0755; - TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); + ent = mkentry("dir", S_IFDIR | 0755, 0, 0); + TEST_NULL(fstree_add_generic(&fs, ent, NULL)); TEST_EQUAL_UI(errno, EEXIST); + free(ent); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFCHR | 0444; - b = fstree_add_generic(&fs, "dir/chrdev", &sb, NULL); + ent = mkentry("dir/chrdev", S_IFCHR | 0444, 0, 0); + ent->rdev = 5678; + b = fstree_add_generic(&fs, ent, NULL); + free(ent); 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->mode, (S_IFCHR | 0444)); + TEST_EQUAL_UI(b->uid, 0); + TEST_EQUAL_UI(b->gid, 0); TEST_EQUAL_UI(b->link_count, 1); TEST_ASSERT(b->parent == a); - TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_EQUAL_UI(b->data.devno, 5678); TEST_NULL(b->next); TEST_ASSERT(a->data.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); + ent = mkentry("dir/foo/chrdev", S_IFCHR | 0444, 0, 0); + ent->rdev = 91011; + b = fstree_add_generic(&fs, ent, NULL); + free(ent); 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->mode, (S_IFCHR | 0444)); + TEST_EQUAL_UI(b->uid, 0); + TEST_EQUAL_UI(b->gid, 0); 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_EQUAL_UI(b->data.devno, 91011); TEST_NULL(b->next); TEST_EQUAL_UI(a->link_count, 4); @@ -112,25 +128,22 @@ int main(int argc, char **argv) TEST_EQUAL_UI(b->gid, 42); TEST_EQUAL_UI(b->link_count, 3); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0750; - sb.st_uid = 1000; - sb.st_gid = 100; - - a = fstree_add_generic(&fs, "dir/foo", &sb, NULL); + ent = mkentry("dir/foo", S_IFDIR | 0755, 1000, 100); + a = fstree_add_generic(&fs, ent, NULL); TEST_NOT_NULL(a); TEST_ASSERT(a == b); TEST_ASSERT(!(a->flags & FLAG_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->mode, (S_IFDIR | 0755)); + TEST_EQUAL_UI(a->uid, 1000); + TEST_EQUAL_UI(a->gid, 100); 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_NULL(fstree_add_generic(&fs, ent, NULL)); TEST_EQUAL_UI(errno, EEXIST); + free(ent); fstree_cleanup(&fs); return EXIT_SUCCESS; diff --git a/lib/fstree/test/fstree_sort.c b/lib/fstree/test/fstree_sort.c index 135976d..82d6e9d 100644 --- a/lib/fstree/test/fstree_sort.c +++ b/lib/fstree/test/fstree_sort.c @@ -10,43 +10,55 @@ #include "common.h" #include "util/test.h" +static tree_node_t *mkentry(fstree_t *fs, const char *name) +{ + dir_entry_t *ent = calloc(1, sizeof(*ent) + strlen(name) + 1); + tree_node_t *out; + + TEST_NOT_NULL(ent); + strcpy(ent->name, name); + ent->mode = S_IFBLK | 0600; + ent->rdev = 1337; + + out = fstree_add_generic(fs, ent, NULL); + free(ent); + TEST_NOT_NULL(out); + + return out; +} + int main(int argc, char **argv) { tree_node_t *a, *b, *c, *d; fstree_defaults_t fsd; - struct stat sb; fstree_t fs; int ret; (void)argc; (void)argv; - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFBLK | 0600; - sb.st_rdev = 1337; - /* in order */ TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0); ret = fstree_init(&fs, &fsd); TEST_EQUAL_I(ret, 0); - a = fstree_add_generic(&fs, "a", &sb, NULL); + a = mkentry(&fs, "a"); TEST_NOT_NULL(a); TEST_ASSERT(fs.root->data.children == a); TEST_NULL(a->next); - b = fstree_add_generic(&fs, "b", &sb, NULL); + b = mkentry(&fs, "b"); TEST_NOT_NULL(a); TEST_ASSERT(fs.root->data.children == a); TEST_ASSERT(a->next == b); TEST_NULL(b->next); - c = fstree_add_generic(&fs, "c", &sb, NULL); + c = mkentry(&fs, "c"); TEST_NOT_NULL(c); TEST_ASSERT(fs.root->data.children == a); TEST_ASSERT(a->next == b); TEST_ASSERT(b->next == c); TEST_NULL(c->next); - d = fstree_add_generic(&fs, "d", &sb, NULL); + d = mkentry(&fs, "d"); TEST_NOT_NULL(d); TEST_ASSERT(fs.root->data.children == a); TEST_ASSERT(a->next == b); @@ -60,25 +72,25 @@ int main(int argc, char **argv) ret = fstree_init(&fs, &fsd); TEST_EQUAL_I(ret, 0); - d = fstree_add_generic(&fs, "d", &sb, NULL); + d = mkentry(&fs, "d"); TEST_NOT_NULL(d); TEST_ASSERT(fs.root->data.children == d); TEST_NULL(d->next); - c = fstree_add_generic(&fs, "c", &sb, NULL); + c = mkentry(&fs, "c"); TEST_NOT_NULL(c); TEST_ASSERT(fs.root->data.children == c); TEST_ASSERT(c->next == d); TEST_NULL(d->next); - b = fstree_add_generic(&fs, "b", &sb, NULL); + b = mkentry(&fs, "b"); TEST_NOT_NULL(b); TEST_ASSERT(fs.root->data.children == b); TEST_ASSERT(b->next == c); TEST_ASSERT(c->next == d); TEST_NULL(d->next); - a = fstree_add_generic(&fs, "a", &sb, NULL); + a = mkentry(&fs, "a"); TEST_NOT_NULL(a); TEST_ASSERT(fs.root->data.children == a); TEST_ASSERT(a->next == b); diff --git a/lib/fstree/test/gen_inode_numbers.c b/lib/fstree/test/gen_inode_numbers.c index 9e046a8..ae7198e 100644 --- a/lib/fstree/test/gen_inode_numbers.c +++ b/lib/fstree/test/gen_inode_numbers.c @@ -12,12 +12,16 @@ static tree_node_t *gen_node(fstree_t *fs, const char *path) { - struct stat sb; + dir_entry_t *ent = calloc(1, sizeof(*ent) + strlen(path) + 1); + tree_node_t *ret; - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0755; + TEST_NOT_NULL(ent); + strcpy(ent->name, path); + ent->mode = S_IFDIR | 0755; - return fstree_add_generic(fs, path, &sb, NULL); + ret = fstree_add_generic(fs, ent, NULL); + free(ent); + return ret; } static void check_children_before_root(tree_node_t *root) diff --git a/lib/fstree/test/get_path.c b/lib/fstree/test/get_path.c index 572cde7..a158764 100644 --- a/lib/fstree/test/get_path.c +++ b/lib/fstree/test/get_path.c @@ -10,11 +10,23 @@ #include "common.h" #include "util/test.h" +static dir_entry_t *mkentry(const char *name) +{ + dir_entry_t *ent = calloc(1, sizeof(*ent) + strlen(name) + 1); + TEST_NOT_NULL(ent); + + strcpy(ent->name, name); + ent->mode = S_IFDIR | 0750; + ent->uid = 1000; + ent->gid = 100; + return ent; +} + int main(int argc, char **argv) { tree_node_t *a, *b, *c, *d; fstree_defaults_t fsd; - struct stat sb; + dir_entry_t *ent; fstree_t fs; char *str; (void)argc; (void)argv; @@ -22,15 +34,18 @@ int main(int argc, char **argv) TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0); TEST_ASSERT(fstree_init(&fs, &fsd) == 0); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0750; - sb.st_uid = 1000; - sb.st_gid = 100; - - a = fstree_add_generic(&fs, "foo", &sb, NULL); - b = fstree_add_generic(&fs, "foo/bar", &sb, NULL); - c = fstree_add_generic(&fs, "foo/bar/baz", &sb, NULL); - d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL); + ent = mkentry("foo"); + a = fstree_add_generic(&fs, ent, NULL); + free(ent); + ent = mkentry("foo/bar"); + b = fstree_add_generic(&fs, ent, NULL); + free(ent); + ent = mkentry("foo/bar/baz"); + c = fstree_add_generic(&fs, ent, NULL); + free(ent); + ent = mkentry("foo/bar/baz/dir"); + d = fstree_add_generic(&fs, ent, NULL); + free(ent); str = fstree_get_path(fs.root); TEST_NOT_NULL(str); diff --git a/lib/fstree/test/mknode_dir.c b/lib/fstree/test/mknode_dir.c index c2812ac..20cba45 100644 --- a/lib/fstree/test/mknode_dir.c +++ b/lib/fstree/test/mknode_dir.c @@ -9,11 +9,25 @@ #include "fstree.h" #include "util/test.h" +static dir_entry_t *mkentry(const char *name) +{ + dir_entry_t *ent = calloc(1, sizeof(*ent) + strlen(name) + 1); + + TEST_NOT_NULL(ent); + strcpy(ent->name, name); + ent->mode = S_IFDIR | 0654; + ent->uid = 123; + ent->gid = 456; + ent->rdev = 789; + ent->size = 4096; + return ent; +} + int main(int argc, char **argv) { fstree_defaults_t defaults; tree_node_t *root, *a, *b; - struct stat sb; + dir_entry_t *ent; fstree_t fs; int ret; (void)argc; (void)argv; @@ -22,26 +36,23 @@ int main(int argc, char **argv) ret = fstree_init(&fs, &defaults); TEST_EQUAL_I(ret, 0); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 4096; - - root = fstree_add_generic(&fs, "rootdir", &sb, NULL); + ent = mkentry("rootdir"); + root = fstree_add_generic(&fs, ent, NULL); + free(ent); TEST_NOT_NULL(root); TEST_ASSERT(root->parent == fs.root); - TEST_EQUAL_UI(root->uid, sb.st_uid); - TEST_EQUAL_UI(root->gid, sb.st_gid); - TEST_EQUAL_UI(root->mode, sb.st_mode); + TEST_EQUAL_UI(root->uid, 123); + TEST_EQUAL_UI(root->gid, 456); + TEST_EQUAL_UI(root->mode, (S_IFDIR | 0654)); TEST_EQUAL_UI(root->link_count, 2); TEST_ASSERT(root->name >= (char *)root->payload); TEST_STR_EQUAL(root->name, "rootdir"); TEST_NULL(root->data.children); TEST_NULL(root->next); - a = fstree_add_generic(&fs, "rootdir/adir", &sb, NULL); + ent = mkentry("rootdir/adir"); + a = fstree_add_generic(&fs, ent, NULL); + free(ent); TEST_NOT_NULL(a); TEST_ASSERT(a->parent == root); TEST_NULL(a->next); @@ -51,7 +62,9 @@ int main(int argc, char **argv) TEST_ASSERT(root->parent == fs.root); TEST_NULL(root->next); - b = fstree_add_generic(&fs, "rootdir/bdir", &sb, NULL); + ent = mkentry("rootdir/bdir"); + b = fstree_add_generic(&fs, ent, NULL); + free(ent); TEST_NOT_NULL(b); TEST_ASSERT(a->parent == root); TEST_ASSERT(b->parent == root); diff --git a/lib/fstree/test/mknode_reg.c b/lib/fstree/test/mknode_reg.c deleted file mode 100644 index 3dc6eb3..0000000 --- a/lib/fstree/test/mknode_reg.c +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * mknode_reg.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" -#include "util/test.h" - -int main(int argc, char **argv) -{ - fstree_defaults_t defaults; - tree_node_t *node; - struct stat sb; - fstree_t fs; - int ret; - (void)argc; (void)argv; - - memset(&defaults, 0, sizeof(defaults)); - ret = fstree_init(&fs, &defaults); - TEST_EQUAL_I(ret, 0); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFREG | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 4096; - - node = fstree_add_generic(&fs, "filename", &sb, "input"); - TEST_NOT_NULL(node); - TEST_ASSERT(node->parent == fs.root); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); - TEST_EQUAL_UI(node->link_count, 1); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_ASSERT(node->data.file.input_file >= (char *)node->payload); - TEST_ASSERT(node->data.file.input_file >= node->name + 8); - TEST_STR_EQUAL(node->name, "filename"); - TEST_STR_EQUAL(node->data.file.input_file, "input"); - - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} diff --git a/lib/fstree/test/mknode_simple.c b/lib/fstree/test/mknode_simple.c index a96ee42..2a18121 100644 --- a/lib/fstree/test/mknode_simple.c +++ b/lib/fstree/test/mknode_simple.c @@ -9,11 +9,25 @@ #include "fstree.h" #include "util/test.h" +static dir_entry_t *mkentry(const char *name, sqfs_u16 mode) +{ + dir_entry_t *ent = calloc(1, sizeof(*ent) + strlen(name) + 1); + + TEST_NOT_NULL(ent); + strcpy(ent->name, name); + ent->mode = mode | 0654; + ent->uid = 123; + ent->gid = 456; + ent->rdev = 789; + ent->size = 1337; + return ent; +} + int main(int argc, char **argv) { fstree_defaults_t defaults; tree_node_t *node; - struct stat sb; + dir_entry_t *ent; fstree_t fs; int ret; (void)argc; (void)argv; @@ -22,21 +36,16 @@ int main(int argc, char **argv) ret = fstree_init(&fs, &defaults); TEST_EQUAL_I(ret, 0); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFSOCK | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_add_generic(&fs, "/sockfile", &sb, "target"); + ent = mkentry("/sockfile", S_IFSOCK); + node = fstree_add_generic(&fs, ent, "target"); + free(ent); TEST_NOT_NULL(node); TEST_ASSERT(node->parent == fs.root); TEST_ASSERT((char *)node->name >= (char *)node->payload); TEST_STR_EQUAL(node->name, "sockfile"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFSOCK | 0654)); TEST_EQUAL_UI(node->link_count, 1); TEST_NULL(node->data.target); TEST_EQUAL_UI(node->data.devno, 0); @@ -45,21 +54,16 @@ int main(int argc, char **argv) ret = fstree_init(&fs, &defaults); TEST_EQUAL_I(ret, 0); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFIFO | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_add_generic(&fs, "/fifo", &sb, "target"); + ent = mkentry("/fifo", S_IFIFO); + node = fstree_add_generic(&fs, ent, "target"); + free(ent); TEST_NOT_NULL(node); TEST_ASSERT(node->parent == fs.root); TEST_ASSERT((char *)node->name >= (char *)node->payload); TEST_STR_EQUAL(node->name, "fifo"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFIFO | 0654)); TEST_EQUAL_UI(node->link_count, 1); TEST_NULL(node->data.target); TEST_EQUAL_UI(node->data.devno, 0); @@ -68,45 +72,95 @@ int main(int argc, char **argv) ret = fstree_init(&fs, &defaults); TEST_EQUAL_I(ret, 0); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFBLK | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_add_generic(&fs, "/blkdev", &sb, NULL); + ent = mkentry("/blkdev", S_IFBLK); + node = fstree_add_generic(&fs, ent, NULL); + free(ent); TEST_NOT_NULL(node); TEST_ASSERT(node->parent == fs.root); TEST_ASSERT((char *)node->name >= (char *)node->payload); TEST_STR_EQUAL(node->name, "blkdev"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFBLK | 0654)); TEST_EQUAL_UI(node->link_count, 1); - TEST_EQUAL_UI(node->data.devno, sb.st_rdev); + TEST_EQUAL_UI(node->data.devno, 789); fstree_cleanup(&fs); ret = fstree_init(&fs, &defaults); TEST_EQUAL_I(ret, 0); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFCHR | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_add_generic(&fs, "/chardev", &sb, NULL); + ent = mkentry("/chardev", S_IFCHR); + node = fstree_add_generic(&fs, ent, NULL); + free(ent); TEST_NOT_NULL(node); TEST_ASSERT(node->parent == fs.root); TEST_ASSERT((char *)node->name >= (char *)node->payload); TEST_STR_EQUAL(node->name, "chardev"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFCHR | 0654)); + TEST_EQUAL_UI(node->link_count, 1); + TEST_EQUAL_UI(node->data.devno, 789); + fstree_cleanup(&fs); + + memset(&defaults, 0, sizeof(defaults)); + ret = fstree_init(&fs, &defaults); + TEST_EQUAL_I(ret, 0); + + ent = mkentry("/symlink", S_IFLNK); + node = fstree_add_generic(&fs, ent, "target"); + free(ent); + TEST_NOT_NULL(node); + TEST_ASSERT(node->parent == fs.root); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFLNK | 0777)); + TEST_EQUAL_UI(node->link_count, 1); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.target >= (char *)node->payload); + TEST_ASSERT(node->data.target >= node->name + 8); + TEST_STR_EQUAL(node->name, "symlink"); + TEST_STR_EQUAL(node->data.target, "target"); + fstree_cleanup(&fs); + + memset(&defaults, 0, sizeof(defaults)); + ret = fstree_init(&fs, &defaults); + TEST_EQUAL_I(ret, 0); + + ent = mkentry("/foo", S_IFLNK); + node = fstree_add_generic(&fs, ent, ""); + free(ent); + TEST_NOT_NULL(node); + TEST_ASSERT(node->parent == fs.root); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFLNK | 0777)); TEST_EQUAL_UI(node->link_count, 1); - TEST_EQUAL_UI(node->data.devno, sb.st_rdev); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.target >= (char *)node->payload); + TEST_ASSERT(node->data.target >= node->name + 3); + TEST_STR_EQUAL(node->name, "foo"); + TEST_STR_EQUAL(node->data.target, ""); + fstree_cleanup(&fs); + + memset(&defaults, 0, sizeof(defaults)); + ret = fstree_init(&fs, &defaults); + TEST_EQUAL_I(ret, 0); + + ent = mkentry("/filename", S_IFREG); + node = fstree_add_generic(&fs, ent, "input"); + free(ent); + TEST_NOT_NULL(node); + TEST_ASSERT(node->parent == fs.root); + TEST_EQUAL_UI(node->uid, 123); + TEST_EQUAL_UI(node->gid, 456); + TEST_EQUAL_UI(node->mode, (S_IFREG | 0654)); + TEST_EQUAL_UI(node->link_count, 1); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.file.input_file >= (char *)node->payload); + TEST_ASSERT(node->data.file.input_file >= node->name + 8); + TEST_STR_EQUAL(node->name, "filename"); + TEST_STR_EQUAL(node->data.file.input_file, "input"); fstree_cleanup(&fs); return EXIT_SUCCESS; diff --git a/lib/fstree/test/mknode_slink.c b/lib/fstree/test/mknode_slink.c deleted file mode 100644 index d741746..0000000 --- a/lib/fstree/test/mknode_slink.c +++ /dev/null @@ -1,60 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * mknode_slink.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" -#include "util/test.h" - -int main(int argc, char **argv) -{ - fstree_defaults_t defaults; - tree_node_t *node; - struct stat sb; - fstree_t fs; - int ret; - (void)argc; (void)argv; - - memset(&defaults, 0, sizeof(defaults)); - ret = fstree_init(&fs, &defaults); - TEST_EQUAL_I(ret, 0); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFLNK | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_add_generic(&fs, "/symlink", &sb, "target"); - TEST_NOT_NULL(node); - TEST_ASSERT(node->parent == fs.root); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); - TEST_EQUAL_UI(node->link_count, 1); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_ASSERT(node->data.target >= (char *)node->payload); - TEST_ASSERT(node->data.target >= node->name + 8); - TEST_STR_EQUAL(node->name, "symlink"); - TEST_STR_EQUAL(node->data.target, "target"); - - node = fstree_add_generic(&fs, "/foo", &sb, ""); - TEST_NOT_NULL(node); - TEST_ASSERT(node->parent == fs.root); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); - TEST_EQUAL_UI(node->link_count, 1); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_ASSERT(node->data.target >= (char *)node->payload); - TEST_ASSERT(node->data.target >= node->name + 3); - TEST_STR_EQUAL(node->name, "foo"); - TEST_STR_EQUAL(node->data.target, ""); - - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} |