diff options
author | dzwdz | 2021-08-08 23:23:27 +0200 |
---|---|---|
committer | dzwdz | 2021-08-08 23:23:27 +0200 |
commit | 0297e9db976aa2c3f17e237c6c5c37f3fde454a9 (patch) | |
tree | 1c2bc574dd78da9dba2a83109a4b45bca31bee29 /src/kernel/tests | |
parent | 9b561ea71ab38e2893e887b8d902e7f8e16bac89 (diff) |
path_simplify now returns int, has better tests
Diffstat (limited to 'src/kernel/tests')
-rw-r--r-- | src/kernel/tests/vfs.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c index a5a6848..017f36d 100644 --- a/src/kernel/tests/vfs.c +++ b/src/kernel/tests/vfs.c @@ -3,31 +3,48 @@ #include <kernel/vfs/path.h> TEST(path_simplify) { - char buf[256]; +#define TEST_WRAPPER(argument, result) do { \ + int len = path_simplify(argument, buf, sizeof(argument) - 1); \ + if (result == 0) { \ + TEST_COND(len < 0); \ + } else { \ + TEST_COND(len > 0); \ + /* TODO check equality */ \ + } \ + } while (0) - // 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)); + char buf[256]; - // .. 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)); + // some easy cases first + TEST_WRAPPER("/", "/"); + TEST_WRAPPER("/asdf", "/asdf"); + TEST_WRAPPER("/asdf/", "/asdf/"); + TEST_WRAPPER("/asdf//", "/asdf/"); + TEST_WRAPPER("/asdf/./", "/asdf/"); + TEST_WRAPPER("/a/./b", "/a/b"); + TEST_WRAPPER("/a/./b/", "/a/b/"); - // 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)); + // some slightly less easy cases + TEST_WRAPPER("/asdf/..", "/"); + TEST_WRAPPER("/asdf/../", "/"); + TEST_WRAPPER("/asdf/.", "/asdf/"); + TEST_WRAPPER("/asdf//.", "/asdf/"); - // this includes empty paths - TEST_COND(!path_simplify("", buf, 1)); + // going under the root or close to it + TEST_WRAPPER("/../asdf", 0); + TEST_WRAPPER("/../asdf/", 0); + TEST_WRAPPER("/./a/../..", 0); + TEST_WRAPPER("/a/a/../..", "/"); + TEST_WRAPPER("/////../..", 0); + TEST_WRAPPER("//a//../..", 0); - // TODO test if the paths are simplified correctly + // relative paths aren't allowed + TEST_WRAPPER("relative", 0); + TEST_WRAPPER("some/stuff", 0); + TEST_WRAPPER("./stuff", 0); + TEST_WRAPPER("../stuff", 0); + TEST_WRAPPER("", 0); +#undef TEST_WRAPPER } void tests_vfs() { |