aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree/test/fstree_sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fstree/test/fstree_sort.c')
-rw-r--r--lib/fstree/test/fstree_sort.c38
1 files changed, 25 insertions, 13 deletions
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);