2 lib - canonicalize path
4 Copyright (C) 2011-2024
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define TEST_SUITE_NAME "/lib/vfs"
28 #include "tests/mctest.h"
31 #include "lib/charsets.h"
34 #include "lib/strutil.h"
36 #include "lib/vfs/xdirentry.h"
38 #include "src/vfs/local/local.c"
40 static struct vfs_class vfs_test_ops
;
42 /* --------------------------------------------------------------------------------------------- */
48 str_init_strings (NULL
);
52 vfs_setup_work_dir ();
55 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
56 load_codepages_list ();
59 vfs_init_class (&vfs_test_ops
, "testfs", VFSF_NOLINKS
| VFSF_REMOTE
, "ftp");
60 vfs_register_class (&vfs_test_ops
);
63 /* --------------------------------------------------------------------------------------------- */
70 free_codepages_list ();
75 str_uninit_strings ();
78 /* --------------------------------------------------------------------------------------------- */
80 /* @DataSource("test_canonicalize_path_ds") */
82 static const struct test_canonicalize_path_ds
84 const char *input_path
;
85 const char *expected_path
;
86 } test_canonicalize_path_ds
[] =
92 { /* 1. join slashes */
93 "///some_server/////////ww",
96 { /* 2. Collapse "/./" -> "/" */
97 "//some_server//.///////ww/./././.",
100 {/* 3. Remove leading "./" */
104 { /* 4. some/.. -> . */
108 { /* 5. Collapse "/.." with the previous part of path */
109 "/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww",
110 "/some_server/ww/ww/some_server/ww"
113 "/some_server/ww/ftp://user:pass@host.net/path/",
114 "/some_server/ww/ftp://user:pass@host.net/path"
117 "/some_server/ww/ftp://user:pass@host.net/path/../../",
121 "ftp://user:pass@host.net/path/../../",
129 { /* 10. Supported encoding */
130 "/b/#enc:utf-8/../c",
133 { /* 11. Unsupported encoding */
137 { /* 12. Supported encoding */
138 "/b/../#enc:utf-8/c",
141 { /* 13. Unsupported encoding */
145 { /* 14. Supported encoding */
146 "/b/c/#enc:utf-8/..",
149 { /* 15. Unsupported encoding */
153 { /* 16. Supported encoding */
154 "/b/c/../#enc:utf-8",
157 { /* 17. Unsupported encoding */
161 #endif /* HAVE_CHARSET */
165 /* @Test(dataSource = "test_canonicalize_path_ds") */
167 START_PARAMETRIZED_TEST (test_canonicalize_path
, test_canonicalize_path_ds
)
173 actual_path
= g_strdup (data
->input_path
);
176 canonicalize_pathname (actual_path
);
179 mctest_assert_str_eq (actual_path
, data
->expected_path
) g_free (actual_path
);
182 END_PARAMETRIZED_TEST
185 /* --------------------------------------------------------------------------------------------- */
192 tc_core
= tcase_create ("Core");
194 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
196 /* Add new tests here: *************** */
197 mctest_add_parameterized_test (tc_core
, test_canonicalize_path
, test_canonicalize_path_ds
);
198 /* *********************************** */
200 return mctest_run_all (tc_core
);
203 /* --------------------------------------------------------------------------------------------- */