Line data Source code
1 : /*
2 : Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
3 : Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
4 :
5 : This software was partially supported by the
6 : EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
7 :
8 : This software was partially supported by the
9 : ADA-FS project under the SPPEXA project funded by the DFG.
10 :
11 : This file is part of GekkoFS.
12 :
13 : GekkoFS is free software: you can redistribute it and/or modify
14 : it under the terms of the GNU General Public License as published by
15 : the Free Software Foundation, either version 3 of the License, or
16 : (at your option) any later version.
17 :
18 : GekkoFS is distributed in the hope that it will be useful,
19 : but WITHOUT ANY WARRANTY; without even the implied warranty of
20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 : GNU General Public License for more details.
22 :
23 : You should have received a copy of the GNU General Public License
24 : along with GekkoFS. If not, see <https://www.gnu.org/licenses/>.
25 :
26 : SPDX-License-Identifier: GPL-3.0-or-later
27 : */
28 :
29 : #include <catch2/catch.hpp>
30 : #include <client/path.hpp>
31 : #include <client/preload.hpp>
32 :
33 : #define TEST_PAIR(p, s, s2) \
34 : REQUIRE(p.first == s); \
35 : REQUIRE(p.second == s2);
36 :
37 1 : SCENARIO(" resolve fn should handle empty path ", "[test_path][empty]") {
38 :
39 4 : GIVEN(" a mount path ") {
40 :
41 2 : CTX->mountdir("/home/foo/tmp/gkfs_mount");
42 2 : CTX->cwd("/home/foo");
43 :
44 4 : WHEN(" resolve with empty path ") {
45 4 : THEN("") {
46 7 : TEST_PAIR(gkfs::path::resolve_new("./tmp/gkfs_mount"), true,
47 4 : "/");
48 3 : TEST_PAIR(gkfs::path::resolve_new(""), false, "/");
49 3 : TEST_PAIR(gkfs::path::resolve_new("///"), false, "/");
50 7 : TEST_PAIR(gkfs::path::resolve_new("tmp/../gkfs_mount"), false,
51 5 : "/home/foo/gkfs_mount");
52 : }
53 : }
54 : }
55 1 : }
56 :
57 2 : SCENARIO(" resolve fn should handle internal paths ",
58 : "[test_path][external paths]") {
59 :
60 8 : GIVEN(" a mount path ") {
61 :
62 4 : CTX->mountdir("/home/foo/tmp/gkfs_mount");
63 4 : CTX->cwd("/home/foo");
64 :
65 7 : WHEN(" resolve with absolute path ") {
66 4 : THEN(" ") {
67 7 : TEST_PAIR(gkfs::path::resolve_new(
68 : "/home/foo/../foo//tmp/./gkfs_mount/bar/./"),
69 4 : true, "/bar");
70 7 : TEST_PAIR(gkfs::path::resolve_new(
71 : "/home/foo/tmp/../tmp/gkfs_mount/bar/./"),
72 4 : true, "/bar");
73 7 : TEST_PAIR(gkfs::path::resolve_new(
74 : "/home/foo/tmp/./gkfs_mount/bar/./"),
75 4 : true, "/bar");
76 7 : TEST_PAIR(gkfs::path::resolve_new(
77 : "/home/foo/tmp/gkfs_mount/bar/./"),
78 4 : true, "/bar");
79 7 : TEST_PAIR(gkfs::path::resolve_new(
80 : "/home/foo/../../home/foo/./tmp/gkfs_mount/"),
81 5 : true, "/");
82 : }
83 : }
84 :
85 7 : WHEN(" resolve with relative path ") {
86 4 : THEN(" ") {
87 7 : TEST_PAIR(gkfs::path::resolve_new(
88 : "./sme/blub/../../tmp/./gkfs_mount/bar/./"),
89 4 : true, "/bar");
90 7 : TEST_PAIR(gkfs::path::resolve_new(
91 : "./tmp/../tmp/gkfs_mount/bar/./"),
92 5 : true, "/bar");
93 : }
94 : }
95 : }
96 2 : }
97 :
98 2 : SCENARIO(" resolve fn should handle external paths ",
99 : "[test_path][external paths]") {
100 :
101 8 : GIVEN(" a mount path ") {
102 :
103 4 : CTX->mountdir("/home/foo/tmp/gkfs_mount");
104 4 : CTX->cwd("/home/foo");
105 :
106 7 : WHEN(" resolve with absolute path ") {
107 4 : THEN(" ") {
108 7 : TEST_PAIR(gkfs::path::resolve_new("/home/foo/../bar/."), false,
109 4 : "/home/bar");
110 7 : TEST_PAIR(gkfs::path::resolve_new("/home/foo/../bar/./"), false,
111 4 : "/home/bar");
112 7 : TEST_PAIR(gkfs::path::resolve_new("/home/foo/../bar/../"),
113 4 : false, "/home");
114 7 : TEST_PAIR(gkfs::path::resolve_new("/home/foo/../../"), false,
115 4 : "/");
116 7 : TEST_PAIR(gkfs::path::resolve_new("/home/foo/./bar/../"), false,
117 4 : "/home/foo");
118 7 : TEST_PAIR(gkfs::path::resolve_new("/home/./../tmp/"), false,
119 4 : "/tmp");
120 7 : TEST_PAIR(gkfs::path::resolve_new(
121 : "/home/./../tmp/gkfs_mount/../"),
122 4 : false, "/tmp");
123 7 : TEST_PAIR(gkfs::path::resolve_new("/home/random/device"), false,
124 5 : "/home/random/device");
125 : }
126 : }
127 :
128 7 : WHEN(" resolve with relative path ") {
129 4 : THEN(" ") {
130 7 : TEST_PAIR(gkfs::path::resolve_new(
131 : "./sme/blub/../tmp/./gkfs_mount/bar/./"),
132 4 : false, "/home/foo/sme/tmp/gkfs_mount/bar");
133 7 : TEST_PAIR(gkfs::path::resolve_new("./tmp//bar/./"), false,
134 4 : "/home/foo/tmp/bar");
135 3 : TEST_PAIR(gkfs::path::resolve_new("../../../.."), false, "/");
136 3 : TEST_PAIR(gkfs::path::resolve_new("../../../../foo"), false, "/foo");
137 : }
138 : }
139 : }
140 2 : }
|