diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-09-23 11:16:46 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-24 15:57:18 +0200 |
commit | 9f2d63162e82d423faeda9c7449d6edd819e4591 (patch) | |
tree | fa22cd6a89655ef9726c64336be47a209bac1a15 /lib/io/test | |
parent | ee26abcab9faf037cf87438cca20d54e5b0edd05 (diff) |
Move the directory iterator test to libsquashfs, move the tree
scanning code to libcommon.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/test')
-rw-r--r-- | lib/io/test/dir_iterator.c | 417 | ||||
-rw-r--r-- | lib/io/test/dir_tree_iterator.c | 253 | ||||
-rw-r--r-- | lib/io/test/dir_tree_iterator2.c | 224 | ||||
-rw-r--r-- | lib/io/test/dir_tree_iterator3.c | 107 | ||||
-rw-r--r-- | lib/io/test/testdir/dira/file_a0 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dira/file_a1 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dira/file_a2 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirb/dirx/file_x0 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirb/dirx/file_x1 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirb/dirx/file_x2 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirb/file_b0 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirb/file_b1 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirb/file_b2 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirc/file_c0 | 1 | ||||
-rw-r--r-- | lib/io/test/testdir/dirc/file_c1 | 0 | ||||
-rw-r--r-- | lib/io/test/testdir/dirc/file_c2 | 1 |
16 files changed, 0 insertions, 1003 deletions
diff --git a/lib/io/test/dir_iterator.c b/lib/io/test/dir_iterator.c deleted file mode 100644 index 56610b6..0000000 --- a/lib/io/test/dir_iterator.c +++ /dev/null @@ -1,417 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * dir_iterator.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/dir_iterator.h" -#include "sqfs/error.h" -#include "util/test.h" -#include "sqfs/io.h" -#include "compat.h" - -static int compare_entries(const void *a, const void *b) -{ - const sqfs_dir_entry_t *const *lhs = a; - const sqfs_dir_entry_t *const *rhs = b; - - return strcmp((*lhs)->name, (*rhs)->name); -} - -static int compare_files(const void *a, const void *b) -{ - const sqfs_istream_t *const *lhs = a; - const sqfs_istream_t *const *rhs = b; - - return strcmp((*lhs)->get_filename(*lhs), - (*rhs)->get_filename(*rhs)); -} - -int main(int argc, char **argv) -{ - sqfs_dir_iterator_t *dir, *suba, *subb, *subc, *sub; - sqfs_dir_entry_t *dent, *ent[6]; - sqfs_istream_t *files[3]; - char buffer[128]; - size_t i, j; - int ret; - (void)argc; (void)argv; - - /* scan the top level hierarchy */ - ret = sqfs_dir_iterator_create_native(&dir, TEST_PATH, 0); - TEST_EQUAL_I(ret, 0); - TEST_NOT_NULL(dir); - - ret = dir->next(dir, &ent[0]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[1]); - TEST_NOT_NULL(ent[1]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[2]); - TEST_NOT_NULL(ent[2]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[3]); - TEST_NOT_NULL(ent[3]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[4]); - TEST_NOT_NULL(ent[4]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[5]); - TEST_NULL(ent[5]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 5, sizeof(ent[0]), compare_entries); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dira"); - TEST_ASSERT(S_ISDIR(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "dirb"); - TEST_ASSERT(S_ISDIR(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "dirc"); - TEST_ASSERT(S_ISDIR(ent[4]->mode)); - - for (i = 0; i < 5; ++i) - free(ent[i]); - - /* scan first sub hierarchy */ - ret = sqfs_dir_iterator_create_native(&dir, TEST_PATH "/dira", 0); - TEST_EQUAL_I(ret, 0); - TEST_NOT_NULL(dir); - - ret = dir->next(dir, &ent[0]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[1]); - TEST_NOT_NULL(ent[1]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[2]); - TEST_NOT_NULL(ent[2]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[3]); - TEST_NOT_NULL(ent[3]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[4]); - TEST_NOT_NULL(ent[4]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[5]); - TEST_NULL(ent[5]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 5, sizeof(ent[0]), compare_entries); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "file_a0"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "file_a1"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "file_a2"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - - for (i = 0; i < 5; ++i) - free(ent[i]); - - /* scan second sub hierarchy */ - ret = sqfs_dir_iterator_create_native(&dir, TEST_PATH "/dirb", 0); - TEST_EQUAL_I(ret, 0); - TEST_NOT_NULL(dir); - - ret = dir->next(dir, &ent[0]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[1]); - TEST_NOT_NULL(ent[1]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[2]); - TEST_NOT_NULL(ent[2]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[3]); - TEST_NOT_NULL(ent[3]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[4]); - TEST_NOT_NULL(ent[4]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[5]); - TEST_NOT_NULL(ent[5]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &dent); - TEST_NULL(dent); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 6, sizeof(ent[0]), compare_entries); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dirx"); - TEST_ASSERT(S_ISDIR(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "file_b0"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "file_b1"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - TEST_STR_EQUAL(ent[5]->name, "file_b2"); - TEST_ASSERT(S_ISREG(ent[5]->mode)); - - for (i = 0; i < 6; ++i) - free(ent[i]); - - /* scan first sub hierarchy */ - ret = sqfs_dir_iterator_create_native(&dir, TEST_PATH "/dirc", 0); - TEST_EQUAL_I(ret, 0); - TEST_NOT_NULL(dir); - - ret = dir->next(dir, &ent[0]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[1]); - TEST_NOT_NULL(ent[1]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[2]); - TEST_NOT_NULL(ent[2]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[3]); - TEST_NOT_NULL(ent[3]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[4]); - TEST_NOT_NULL(ent[4]); - TEST_EQUAL_I(ret, 0); - - ret = dir->next(dir, &ent[5]); - TEST_NULL(ent[5]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 5, sizeof(ent[0]), compare_entries); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "file_c0"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "file_c1"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "file_c2"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - - for (i = 0; i < 5; ++i) - free(ent[i]); - - /* test sub directory iterators */ - suba = NULL; - subb = NULL; - subc = NULL; - - ret = sqfs_dir_iterator_create_native(&dir, TEST_PATH, 0); - TEST_EQUAL_I(ret, 0); - TEST_NOT_NULL(dir); - - for (i = 0; i < 5; ++i) { - ret = dir->next(dir, &dent); - TEST_NOT_NULL(dent); - TEST_EQUAL_I(ret, 0); - - if (!strcmp(dent->name, "dira")) { - TEST_NULL(suba); - ret = dir->open_subdir(dir, &suba); - TEST_NOT_NULL(suba); - TEST_EQUAL_I(ret, 0); - } else if (!strcmp(dent->name, "dirb")) { - TEST_NULL(subb); - ret = dir->open_subdir(dir, &subb); - TEST_NOT_NULL(subb); - TEST_EQUAL_I(ret, 0); - } else if (!strcmp(dent->name, "dirc")) { - TEST_NULL(subc); - ret = dir->open_subdir(dir, &subc); - TEST_NOT_NULL(subc); - TEST_EQUAL_I(ret, 0); - } - - free(dent); - } - - ret = dir->next(dir, &dent); - TEST_NULL(dent); - TEST_ASSERT(ret > 0); - dir = sqfs_drop(dir); - - TEST_NOT_NULL(suba); - TEST_NOT_NULL(subb); - TEST_NOT_NULL(subc); - - /* sub iterator a */ - for (i = 0; i < 5; ++i) { - ret = suba->next(suba, &ent[i]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - if (S_ISREG(ent[i]->mode)) { - ret = suba->open_subdir(suba, &sub); - TEST_NULL(sub); - TEST_EQUAL_I(ret, SQFS_ERROR_NOT_DIR); - } - } - - ret = suba->next(suba, &dent); - TEST_NULL(dent); - TEST_ASSERT(ret > 0); - suba = sqfs_drop(suba); - - qsort(ent, 5, sizeof(ent[0]), compare_entries); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "file_a0"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "file_a1"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "file_a2"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - - for (i = 0; i < 5; ++i) - free(ent[i]); - - /* sub iterator b */ - for (i = 0; i < 6; ++i) { - ret = subb->next(subb, &ent[i]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - if (S_ISREG(ent[i]->mode)) { - ret = subb->open_subdir(subb, &sub); - TEST_NULL(sub); - TEST_EQUAL_I(ret, SQFS_ERROR_NOT_DIR); - } - } - - ret = subb->next(subb, &dent); - TEST_NULL(dent); - TEST_ASSERT(ret > 0); - subb = sqfs_drop(subb); - - qsort(ent, 6, sizeof(ent[0]), compare_entries); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dirx"); - TEST_ASSERT(S_ISDIR(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "file_b0"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "file_b1"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - TEST_STR_EQUAL(ent[5]->name, "file_b2"); - TEST_ASSERT(S_ISREG(ent[5]->mode)); - - for (i = 0; i < 6; ++i) - free(ent[i]); - - /* sub iterator c */ - j = 0; - - for (i = 0; i < 5; ++i) { - ret = subc->next(subc, &ent[i]); - TEST_NOT_NULL(ent[0]); - TEST_EQUAL_I(ret, 0); - - if (S_ISREG(ent[i]->mode)) { - ret = subc->open_subdir(subc, &sub); - TEST_NULL(sub); - TEST_EQUAL_I(ret, SQFS_ERROR_NOT_DIR); - - TEST_ASSERT(j < 3); - ret = subc->open_file_ro(subc, &(files[j++])); - TEST_EQUAL_I(ret, 0); - } - } - - TEST_EQUAL_UI(j, 3); - - ret = subc->next(subc, &dent); - TEST_NULL(dent); - TEST_ASSERT(ret > 0); - subc = sqfs_drop(subc); - - qsort(ent, 5, sizeof(ent[0]), compare_entries); - qsort(files, 3, sizeof(files[0]), compare_files); - - TEST_STR_EQUAL(ent[0]->name, "."); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, ".."); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "file_c0"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "file_c1"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "file_c2"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - - for (i = 0; i < 5; ++i) - free(ent[i]); - - TEST_STR_EQUAL(files[0]->get_filename(files[0]), "file_c0"); - TEST_STR_EQUAL(files[1]->get_filename(files[1]), "file_c1"); - TEST_STR_EQUAL(files[2]->get_filename(files[2]), "file_c2"); - - ret = sqfs_istream_read(files[0], buffer, sizeof(buffer)); - TEST_EQUAL_I(ret, 12); - buffer[ret] = '\0'; - TEST_STR_EQUAL(buffer, "test string\n"); - ret = sqfs_istream_read(files[0], buffer, sizeof(buffer)); - TEST_EQUAL_I(ret, 0); - - ret = sqfs_istream_read(files[1], buffer, sizeof(buffer)); - TEST_EQUAL_I(ret, 0); - - ret = sqfs_istream_read(files[2], buffer, sizeof(buffer)); - TEST_EQUAL_I(ret, 10); - buffer[ret] = '\0'; - TEST_STR_EQUAL(buffer, "你好!\n"); - ret = sqfs_istream_read(files[2], buffer, sizeof(buffer)); - TEST_EQUAL_I(ret, 0); - - for (i = 0; i < j; ++i) - sqfs_drop(files[i]); - - return EXIT_SUCCESS; -} diff --git a/lib/io/test/dir_tree_iterator.c b/lib/io/test/dir_tree_iterator.c deleted file mode 100644 index 6c7f1bf..0000000 --- a/lib/io/test/dir_tree_iterator.c +++ /dev/null @@ -1,253 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * dir_tree_iterator.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/dir_iterator.h" -#include "sqfs/error.h" -#include "util/test.h" -#include "sqfs/io.h" -#include "compat.h" - -static int compare_entries(const void *a, const void *b) -{ - const sqfs_dir_entry_t *const *lhs = a; - const sqfs_dir_entry_t *const *rhs = b; - - return strcmp((*lhs)->name, (*rhs)->name); -} - -int main(int argc, char **argv) -{ - sqfs_dir_entry_t *ent[17]; - sqfs_dir_iterator_t *dir; - dir_tree_cfg_t cfg; - size_t i; - int ret; - (void)argc; (void)argv; - - memset(&cfg, 0, sizeof(cfg)); - cfg.def_mtime = 1337; - cfg.def_uid = 42; - cfg.def_gid = 23; - cfg.flags = DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 16; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[16]); - TEST_NULL(ent[16]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 16, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 16; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira"); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_EQUAL_UI(ent[0]->mtime, 1337); - TEST_EQUAL_UI(ent[0]->uid, 42); - TEST_EQUAL_UI(ent[0]->gid, 23); - TEST_STR_EQUAL(ent[1]->name, "dira/file_a0"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_EQUAL_UI(ent[1]->mtime, 1337); - TEST_EQUAL_UI(ent[1]->uid, 42); - TEST_EQUAL_UI(ent[1]->gid, 23); - TEST_STR_EQUAL(ent[2]->name, "dira/file_a1"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_EQUAL_UI(ent[2]->mtime, 1337); - TEST_EQUAL_UI(ent[2]->uid, 42); - TEST_EQUAL_UI(ent[2]->gid, 23); - TEST_STR_EQUAL(ent[3]->name, "dira/file_a2"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_EQUAL_UI(ent[3]->mtime, 1337); - TEST_EQUAL_UI(ent[3]->uid, 42); - TEST_EQUAL_UI(ent[3]->gid, 23); - TEST_STR_EQUAL(ent[4]->name, "dirb"); - TEST_ASSERT(S_ISDIR(ent[4]->mode)); - TEST_EQUAL_UI(ent[4]->mtime, 1337); - TEST_EQUAL_UI(ent[4]->uid, 42); - TEST_EQUAL_UI(ent[4]->gid, 23); - TEST_STR_EQUAL(ent[5]->name, "dirb/dirx"); - TEST_ASSERT(S_ISDIR(ent[5]->mode)); - TEST_EQUAL_UI(ent[5]->mtime, 1337); - TEST_EQUAL_UI(ent[5]->uid, 42); - TEST_EQUAL_UI(ent[5]->gid, 23); - TEST_STR_EQUAL(ent[6]->name, "dirb/dirx/file_x0"); - TEST_ASSERT(S_ISREG(ent[6]->mode)); - TEST_EQUAL_UI(ent[6]->mtime, 1337); - TEST_EQUAL_UI(ent[6]->uid, 42); - TEST_EQUAL_UI(ent[6]->gid, 23); - TEST_STR_EQUAL(ent[7]->name, "dirb/dirx/file_x1"); - TEST_ASSERT(S_ISREG(ent[7]->mode)); - TEST_EQUAL_UI(ent[7]->mtime, 1337); - TEST_EQUAL_UI(ent[7]->uid, 42); - TEST_EQUAL_UI(ent[7]->gid, 23); - TEST_STR_EQUAL(ent[8]->name, "dirb/dirx/file_x2"); - TEST_ASSERT(S_ISREG(ent[8]->mode)); - TEST_EQUAL_UI(ent[8]->mtime, 1337); - TEST_EQUAL_UI(ent[8]->uid, 42); - TEST_EQUAL_UI(ent[8]->gid, 23); - TEST_STR_EQUAL(ent[9]->name, "dirb/file_b0"); - TEST_ASSERT(S_ISREG(ent[9]->mode)); - TEST_EQUAL_UI(ent[9]->mtime, 1337); - TEST_EQUAL_UI(ent[9]->uid, 42); - TEST_EQUAL_UI(ent[9]->gid, 23); - TEST_STR_EQUAL(ent[10]->name, "dirb/file_b1"); - TEST_ASSERT(S_ISREG(ent[10]->mode)); - TEST_EQUAL_UI(ent[10]->mtime, 1337); - TEST_EQUAL_UI(ent[10]->uid, 42); - TEST_EQUAL_UI(ent[10]->gid, 23); - TEST_STR_EQUAL(ent[11]->name, "dirb/file_b2"); - TEST_ASSERT(S_ISREG(ent[11]->mode)); - TEST_EQUAL_UI(ent[11]->mtime, 1337); - TEST_EQUAL_UI(ent[11]->uid, 42); - TEST_EQUAL_UI(ent[11]->gid, 23); - TEST_STR_EQUAL(ent[12]->name, "dirc"); - TEST_ASSERT(S_ISDIR(ent[12]->mode)); - TEST_EQUAL_UI(ent[12]->mtime, 1337); - TEST_EQUAL_UI(ent[12]->uid, 42); - TEST_EQUAL_UI(ent[12]->gid, 23); - TEST_STR_EQUAL(ent[13]->name, "dirc/file_c0"); - TEST_ASSERT(S_ISREG(ent[13]->mode)); - TEST_EQUAL_UI(ent[13]->mtime, 1337); - TEST_EQUAL_UI(ent[13]->uid, 42); - TEST_EQUAL_UI(ent[13]->gid, 23); - TEST_STR_EQUAL(ent[14]->name, "dirc/file_c1"); - TEST_ASSERT(S_ISREG(ent[14]->mode)); - TEST_EQUAL_UI(ent[14]->mtime, 1337); - TEST_EQUAL_UI(ent[14]->uid, 42); - TEST_EQUAL_UI(ent[14]->gid, 23); - TEST_STR_EQUAL(ent[15]->name, "dirc/file_c2"); - TEST_ASSERT(S_ISREG(ent[15]->mode)); - TEST_EQUAL_UI(ent[15]->mtime, 1337); - TEST_EQUAL_UI(ent[15]->uid, 42); - TEST_EQUAL_UI(ent[15]->gid, 23); - - for (i = 0; i < 16; ++i) - free(ent[i]); - - /* retry with skipping */ - printf("**********\n"); - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 13; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - - if (!strcmp(ent[i]->name, "dirb/dirx")) - dir->ignore_subdir(dir); - } - - ret = dir->next(dir, &ent[13]); - TEST_NULL(ent[13]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 13, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 13; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira"); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dira/file_a0"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dira/file_a1"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "dira/file_a2"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "dirb"); - TEST_ASSERT(S_ISDIR(ent[4]->mode)); - TEST_STR_EQUAL(ent[5]->name, "dirb/dirx"); - TEST_ASSERT(S_ISDIR(ent[5]->mode)); - TEST_STR_EQUAL(ent[6]->name, "dirb/file_b0"); - TEST_ASSERT(S_ISREG(ent[6]->mode)); - TEST_STR_EQUAL(ent[7]->name, "dirb/file_b1"); - TEST_ASSERT(S_ISREG(ent[7]->mode)); - TEST_STR_EQUAL(ent[8]->name, "dirb/file_b2"); - TEST_ASSERT(S_ISREG(ent[8]->mode)); - TEST_STR_EQUAL(ent[9]->name, "dirc"); - TEST_ASSERT(S_ISDIR(ent[9]->mode)); - TEST_STR_EQUAL(ent[10]->name, "dirc/file_c0"); - TEST_ASSERT(S_ISREG(ent[10]->mode)); - TEST_STR_EQUAL(ent[11]->name, "dirc/file_c1"); - TEST_ASSERT(S_ISREG(ent[11]->mode)); - TEST_STR_EQUAL(ent[12]->name, "dirc/file_c2"); - TEST_ASSERT(S_ISREG(ent[12]->mode)); - - for (i = 0; i < 13; ++i) - free(ent[i]); - - /* retry with skipping */ - printf("**********\n"); - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 9; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - - if (!strcmp(ent[i]->name, "dirb")) - dir->ignore_subdir(dir); - } - - ret = dir->next(dir, &ent[9]); - TEST_NULL(ent[9]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 9, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 9; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira"); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dira/file_a0"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dira/file_a1"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "dira/file_a2"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "dirb"); - TEST_ASSERT(S_ISDIR(ent[4]->mode)); - TEST_STR_EQUAL(ent[5]->name, "dirc"); - TEST_ASSERT(S_ISDIR(ent[5]->mode)); - TEST_STR_EQUAL(ent[6]->name, "dirc/file_c0"); - TEST_ASSERT(S_ISREG(ent[6]->mode)); - TEST_STR_EQUAL(ent[7]->name, "dirc/file_c1"); - TEST_ASSERT(S_ISREG(ent[7]->mode)); - TEST_STR_EQUAL(ent[8]->name, "dirc/file_c2"); - TEST_ASSERT(S_ISREG(ent[8]->mode)); - - for (i = 0; i < 9; ++i) - free(ent[i]); - - return EXIT_SUCCESS; -} diff --git a/lib/io/test/dir_tree_iterator2.c b/lib/io/test/dir_tree_iterator2.c deleted file mode 100644 index 9184957..0000000 --- a/lib/io/test/dir_tree_iterator2.c +++ /dev/null @@ -1,224 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * dir_tree_iterator2.c - * - * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/dir_iterator.h" -#include "sqfs/error.h" -#include "util/test.h" -#include "sqfs/io.h" -#include "compat.h" - -static int compare_entries(const void *a, const void *b) -{ - const sqfs_dir_entry_t *const *lhs = a; - const sqfs_dir_entry_t *const *rhs = b; - - return strcmp((*lhs)->name, (*rhs)->name); -} - -int main(int argc, char **argv) -{ - sqfs_dir_entry_t *ent[17]; - sqfs_dir_iterator_t *dir; - dir_tree_cfg_t cfg; - size_t i; - int ret; - (void)argc; (void)argv; - - /********** without files **********/ - memset(&cfg, 0, sizeof(cfg)); - cfg.flags |= DIR_SCAN_NO_FILE | DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 4; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[4]); - TEST_NULL(ent[4]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 4, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 4; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira"); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dirb"); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dirb/dirx"); - TEST_ASSERT(S_ISDIR(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "dirc"); - TEST_ASSERT(S_ISDIR(ent[3]->mode)); - - for (i = 0; i < 4; ++i) - free(ent[i]); - - /********** recursive but without dirs **********/ - memset(&cfg, 0, sizeof(cfg)); - cfg.flags |= DIR_SCAN_NO_DIR | DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 12; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[12]); - TEST_NULL(ent[12]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 12, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 12; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira/file_a0"); - TEST_ASSERT(S_ISREG(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dira/file_a1"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dira/file_a2"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "dirb/dirx/file_x0"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "dirb/dirx/file_x1"); - TEST_ASSERT(S_ISREG(ent[4]->mode)); - TEST_STR_EQUAL(ent[5]->name, "dirb/dirx/file_x2"); - TEST_ASSERT(S_ISREG(ent[5]->mode)); - TEST_STR_EQUAL(ent[6]->name, "dirb/file_b0"); - TEST_ASSERT(S_ISREG(ent[6]->mode)); - TEST_STR_EQUAL(ent[7]->name, "dirb/file_b1"); - TEST_ASSERT(S_ISREG(ent[7]->mode)); - TEST_STR_EQUAL(ent[8]->name, "dirb/file_b2"); - TEST_ASSERT(S_ISREG(ent[8]->mode)); - TEST_STR_EQUAL(ent[9]->name, "dirc/file_c0"); - TEST_ASSERT(S_ISREG(ent[9]->mode)); - TEST_STR_EQUAL(ent[10]->name, "dirc/file_c1"); - TEST_ASSERT(S_ISREG(ent[10]->mode)); - TEST_STR_EQUAL(ent[11]->name, "dirc/file_c2"); - TEST_ASSERT(S_ISREG(ent[11]->mode)); - - for (i = 0; i < 12; ++i) - free(ent[i]); - - /********** non-recursive **********/ - memset(&cfg, 0, sizeof(cfg)); - cfg.flags |= DIR_SCAN_NO_RECURSION | DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 3; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[3]); - TEST_NULL(ent[3]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 3, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 3; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira"); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dirb"); - TEST_ASSERT(S_ISDIR(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dirc"); - TEST_ASSERT(S_ISDIR(ent[2]->mode)); - - for (i = 0; i < 3; ++i) - free(ent[i]); - - /********** with prefix inserted **********/ - memset(&cfg, 0, sizeof(cfg)); - cfg.prefix = "foobar"; - cfg.flags = DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 16; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[16]); - TEST_NULL(ent[16]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 16, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 16; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "foobar/dira"); - TEST_ASSERT(S_ISDIR(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "foobar/dira/file_a0"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "foobar/dira/file_a1"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - TEST_STR_EQUAL(ent[3]->name, "foobar/dira/file_a2"); - TEST_ASSERT(S_ISREG(ent[3]->mode)); - TEST_STR_EQUAL(ent[4]->name, "foobar/dirb"); - TEST_ASSERT(S_ISDIR(ent[4]->mode)); - TEST_STR_EQUAL(ent[5]->name, "foobar/dirb/dirx"); - TEST_ASSERT(S_ISDIR(ent[5]->mode)); - TEST_STR_EQUAL(ent[6]->name, "foobar/dirb/dirx/file_x0"); - TEST_ASSERT(S_ISREG(ent[6]->mode)); - TEST_STR_EQUAL(ent[7]->name, "foobar/dirb/dirx/file_x1"); - TEST_ASSERT(S_ISREG(ent[7]->mode)); - TEST_STR_EQUAL(ent[8]->name, "foobar/dirb/dirx/file_x2"); - TEST_ASSERT(S_ISREG(ent[8]->mode)); - TEST_STR_EQUAL(ent[9]->name, "foobar/dirb/file_b0"); - TEST_ASSERT(S_ISREG(ent[9]->mode)); - TEST_STR_EQUAL(ent[10]->name, "foobar/dirb/file_b1"); - TEST_ASSERT(S_ISREG(ent[10]->mode)); - TEST_STR_EQUAL(ent[11]->name, "foobar/dirb/file_b2"); - TEST_ASSERT(S_ISREG(ent[11]->mode)); - TEST_STR_EQUAL(ent[12]->name, "foobar/dirc"); - TEST_ASSERT(S_ISDIR(ent[12]->mode)); - TEST_STR_EQUAL(ent[13]->name, "foobar/dirc/file_c0"); - TEST_ASSERT(S_ISREG(ent[13]->mode)); - TEST_STR_EQUAL(ent[14]->name, "foobar/dirc/file_c1"); - TEST_ASSERT(S_ISREG(ent[14]->mode)); - TEST_STR_EQUAL(ent[15]->name, "foobar/dirc/file_c2"); - TEST_ASSERT(S_ISREG(ent[15]->mode)); - - for (i = 0; i < 16; ++i) - free(ent[i]); - - return EXIT_SUCCESS; -} diff --git a/lib/io/test/dir_tree_iterator3.c b/lib/io/test/dir_tree_iterator3.c deleted file mode 100644 index ccb6bdb..0000000 --- a/lib/io/test/dir_tree_iterator3.c +++ /dev/null @@ -1,107 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * dir_tree_iterator2.c - * - * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/dir_iterator.h" -#include "sqfs/error.h" -#include "util/test.h" -#include "sqfs/io.h" -#include "compat.h" - -static int compare_entries(const void *a, const void *b) -{ - const sqfs_dir_entry_t *const *lhs = a; - const sqfs_dir_entry_t *const *rhs = b; - - return strcmp((*lhs)->name, (*rhs)->name); -} - -int main(int argc, char **argv) -{ - sqfs_dir_entry_t *ent[17]; - sqfs_dir_iterator_t *dir; - dir_tree_cfg_t cfg; - size_t i; - int ret; - (void)argc; (void)argv; - - /********** match name **********/ - memset(&cfg, 0, sizeof(cfg)); - cfg.name_pattern = "file_x*"; - cfg.flags = DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 3; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[3]); - TEST_NULL(ent[3]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 3, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 3; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dirb/dirx/file_x0"); - TEST_ASSERT(S_ISREG(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dirb/dirx/file_x1"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dirb/dirx/file_x2"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - - for (i = 0; i < 3; ++i) - free(ent[i]); - - /********** match path **********/ - memset(&cfg, 0, sizeof(cfg)); - cfg.name_pattern = "dir*/file_*0"; - cfg.flags |= DIR_SCAN_MATCH_FULL_PATH | DIR_SCAN_NO_HARDLINKS; - - dir = dir_tree_iterator_create(TEST_PATH, &cfg); - TEST_NOT_NULL(dir); - - for (i = 0; i < 3; ++i) { - ret = dir->next(dir, &ent[i]); - TEST_NOT_NULL(ent[i]); - TEST_EQUAL_I(ret, 0); - printf("READ %s\n", ent[i]->name); - } - - ret = dir->next(dir, &ent[3]); - TEST_NULL(ent[3]); - TEST_ASSERT(ret > 0); - - dir = sqfs_drop(dir); - - qsort(ent, 3, sizeof(ent[0]), compare_entries); - - printf("After sort:\n"); - for (i = 0; i < 3; ++i) - printf("%s\n", ent[i]->name); - - TEST_STR_EQUAL(ent[0]->name, "dira/file_a0"); - TEST_ASSERT(S_ISREG(ent[0]->mode)); - TEST_STR_EQUAL(ent[1]->name, "dirb/file_b0"); - TEST_ASSERT(S_ISREG(ent[1]->mode)); - TEST_STR_EQUAL(ent[2]->name, "dirc/file_c0"); - TEST_ASSERT(S_ISREG(ent[2]->mode)); - - for (i = 0; i < 3; ++i) - free(ent[i]); - - return EXIT_SUCCESS; -} diff --git a/lib/io/test/testdir/dira/file_a0 b/lib/io/test/testdir/dira/file_a0 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dira/file_a0 +++ /dev/null diff --git a/lib/io/test/testdir/dira/file_a1 b/lib/io/test/testdir/dira/file_a1 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dira/file_a1 +++ /dev/null diff --git a/lib/io/test/testdir/dira/file_a2 b/lib/io/test/testdir/dira/file_a2 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dira/file_a2 +++ /dev/null diff --git a/lib/io/test/testdir/dirb/dirx/file_x0 b/lib/io/test/testdir/dirb/dirx/file_x0 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirb/dirx/file_x0 +++ /dev/null diff --git a/lib/io/test/testdir/dirb/dirx/file_x1 b/lib/io/test/testdir/dirb/dirx/file_x1 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirb/dirx/file_x1 +++ /dev/null diff --git a/lib/io/test/testdir/dirb/dirx/file_x2 b/lib/io/test/testdir/dirb/dirx/file_x2 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirb/dirx/file_x2 +++ /dev/null diff --git a/lib/io/test/testdir/dirb/file_b0 b/lib/io/test/testdir/dirb/file_b0 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirb/file_b0 +++ /dev/null diff --git a/lib/io/test/testdir/dirb/file_b1 b/lib/io/test/testdir/dirb/file_b1 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirb/file_b1 +++ /dev/null diff --git a/lib/io/test/testdir/dirb/file_b2 b/lib/io/test/testdir/dirb/file_b2 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirb/file_b2 +++ /dev/null diff --git a/lib/io/test/testdir/dirc/file_c0 b/lib/io/test/testdir/dirc/file_c0 deleted file mode 100644 index 71c1922..0000000 --- a/lib/io/test/testdir/dirc/file_c0 +++ /dev/null @@ -1 +0,0 @@ -test string diff --git a/lib/io/test/testdir/dirc/file_c1 b/lib/io/test/testdir/dirc/file_c1 deleted file mode 100644 index e69de29..0000000 --- a/lib/io/test/testdir/dirc/file_c1 +++ /dev/null diff --git a/lib/io/test/testdir/dirc/file_c2 b/lib/io/test/testdir/dirc/file_c2 deleted file mode 100644 index efde6ef..0000000 --- a/lib/io/test/testdir/dirc/file_c2 +++ /dev/null @@ -1 +0,0 @@ -你好! |