diff options
author | dzwdz | 2021-08-04 12:27:02 +0200 |
---|---|---|
committer | dzwdz | 2021-08-04 12:27:02 +0200 |
commit | 6e5a5a3b27257f212fcd10a3580cfca3ea224fab (patch) | |
tree | cb9dc8962b9c6bb46ef7b05ffaa2d01652f24c46 /src/kernel/tests/vfs.c | |
parent | 0a695a33e4e23fb5a0d70c7a3500224cce931ccf (diff) |
partial path_simplify implementation
it currently only checks if the path is valid, it's the bare minimum
needed to write tests
Diffstat (limited to 'src/kernel/tests/vfs.c')
-rw-r--r-- | src/kernel/tests/vfs.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c new file mode 100644 index 0000000..a5a6848 --- /dev/null +++ b/src/kernel/tests/vfs.c @@ -0,0 +1,35 @@ +#include <kernel/tests/base.h> +#include <kernel/util.h> +#include <kernel/vfs/path.h> + +TEST(path_simplify) { + char buf[256]; + + // some easy valid cases + TEST_COND( path_simplify("/asdf", buf, 5)); + TEST_COND( path_simplify("/asd/", buf, 5)); + TEST_COND( path_simplify("/a/./", buf, 5)); + TEST_COND( path_simplify("/a/..", buf, 5)); + TEST_COND( path_simplify("/a//.", buf, 5)); + + // .. going under the root or close to it + TEST_COND(!path_simplify("/../123456", buf, 10)); + TEST_COND(!path_simplify("/./a/../..", buf, 10)); + TEST_COND( path_simplify("/a/a/../..", buf, 10)); + TEST_COND(!path_simplify("/////../..", buf, 10)); + TEST_COND(!path_simplify("//a//../..", buf, 10)); + + // relative paths aren't allowed + TEST_COND(!path_simplify("apath", buf, 5)); + TEST_COND(!path_simplify("a/pth", buf, 5)); + TEST_COND(!path_simplify("../th", buf, 5)); + + // this includes empty paths + TEST_COND(!path_simplify("", buf, 1)); + + // TODO test if the paths are simplified correctly +} + +void tests_vfs() { + TEST_RUN(path_simplify); +} |