aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/test
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-09 18:00:03 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-15 21:48:47 +0200
commitc1e8ef8975458c1c814e85d1e3abe3b94c1fc65e (patch)
treea57886b4e6ccc767748994b05a85c45ef1491070 /lib/sqfs/test
parent7f2fc2fc3942cfb47bd532b787c5c32ecfe45bcd (diff)
Move directory tree related code from libsquashfs to libcommon
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/test')
-rw-r--r--lib/sqfs/test/get_node_path.c132
1 files changed, 0 insertions, 132 deletions
diff --git a/lib/sqfs/test/get_node_path.c b/lib/sqfs/test/get_node_path.c
deleted file mode 100644
index c76cc1c..0000000
--- a/lib/sqfs/test/get_node_path.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * get_node_path.c
- *
- * Copyright (C) 2022 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "compat.h"
-#include "util/test.h"
-
-#include "sqfs/dir_reader.h"
-#include "sqfs/error.h"
-
-int main(int argc, char **argv)
-{
- sqfs_tree_node_t *n0, *n1, *n2;
- char *str;
- int ret;
- (void)argc;
- (void)argv;
-
- n0 = calloc(1, sizeof(*n0) + 16);
- TEST_NOT_NULL(n0);
-
- n1 = calloc(1, sizeof(*n1) + 16);
- TEST_NOT_NULL(n1);
-
- n2 = calloc(1, sizeof(*n2) + 16);
- TEST_NOT_NULL(n2);
-
- /* no parent -> must return "/" */
- ret = sqfs_tree_node_get_path(n0, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/");
- sqfs_free(str);
-
- /* hiearchy levels */
- n1->parent = n0;
- n0->children = n1;
- strcpy((char *)n1->name, "bar");
-
- n2->parent = n1;
- n1->children = n2;
- strcpy((char *)n2->name, "baz");
-
- ret = sqfs_tree_node_get_path(n1, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/bar");
- sqfs_free(str);
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/bar/baz");
- sqfs_free(str);
-
- /* root node must not have a name */
- strcpy((char *)n0->name, "foo");
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, SQFS_ERROR_ARG_INVALID);
- TEST_NULL(str);
- n0->name[0] = '\0';
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/bar/baz");
- sqfs_free(str);
-
- /* non-root nodes must have names */
- n1->name[0] = '\0';
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, SQFS_ERROR_CORRUPTED);
- TEST_NULL(str);
- n1->name[0] = 'b';
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/bar/baz");
- sqfs_free(str);
-
- /* some names are illegal */
- strcpy((char *)n1->name, "..");
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, SQFS_ERROR_CORRUPTED);
- TEST_NULL(str);
-
- strcpy((char *)n1->name, ".");
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, SQFS_ERROR_CORRUPTED);
- TEST_NULL(str);
-
- strcpy((char *)n1->name, "a/b");
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, SQFS_ERROR_CORRUPTED);
- TEST_NULL(str);
-
- strcpy((char *)n1->name, "bar");
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/bar/baz");
- sqfs_free(str);
-
- /* link loops must be detected */
- n0->parent = n2;
- strcpy((char *)n0->name, "foo");
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, SQFS_ERROR_LINK_LOOP);
- TEST_NULL(str);
-
- n0->parent = NULL;
- n0->name[0] = '\0';
-
- ret = sqfs_tree_node_get_path(n2, &str);
- TEST_EQUAL_I(ret, 0);
- TEST_NOT_NULL(str);
- TEST_STR_EQUAL(str, "/bar/baz");
- sqfs_free(str);
-
- /* cleanup */
- free(n0);
- free(n1);
- free(n2);
- return EXIT_SUCCESS;
-}