2 lib - canonicalize path
4 Copyright (C) 2011-2016
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_s_subclass test_subclass
;
41 static struct vfs_class vfs_test_ops
;
43 /* --------------------------------------------------------------------------------------------- */
49 str_init_strings (NULL
);
53 vfs_setup_work_dir ();
56 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
57 load_codepages_list ();
60 vfs_s_init_class (&vfs_test_ops
, &test_subclass
);
62 vfs_test_ops
.name
= "testfs";
63 vfs_test_ops
.flags
= VFSF_NOLINKS
;
64 vfs_test_ops
.prefix
= "ftp";
65 test_subclass
.flags
= VFS_S_REMOTE
;
66 vfs_register_class (&vfs_test_ops
);
69 /* --------------------------------------------------------------------------------------------- */
76 free_codepages_list ();
80 str_uninit_strings ();
83 /* --------------------------------------------------------------------------------------------- */
85 /* @DataSource("test_canonicalize_path_ds") */
87 static const struct test_canonicalize_path_ds
89 const char *input_path
;
90 const char *expected_path
;
91 } test_canonicalize_path_ds
[] =
97 { /* 1. join slashes */
98 "///some_server/////////ww",
101 { /* 2. Collapse "/./" -> "/" */
102 "//some_server//.///////ww/./././.",
105 {/* 3. Remove leading "./" */
109 { /* 4. some/.. -> . */
113 { /* 5. Collapse "/.." with the previous part of path */
114 "/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww",
115 "/some_server/ww/ww/some_server/ww"
118 "/some_server/ww/ftp://user:pass@host.net/path/",
119 "/some_server/ww/ftp://user:pass@host.net/path"
122 "/some_server/ww/ftp://user:pass@host.net/path/../../",
126 "ftp://user:pass@host.net/path/../../",
134 { /* 10. Supported encoding */
135 "/b/#enc:utf-8/../c",
138 { /* 11. Unsupported encoding */
142 { /* 12. Supported encoding */
143 "/b/../#enc:utf-8/c",
146 { /* 13. Unsupported encoding */
150 { /* 14. Supported encoding */
151 "/b/c/#enc:utf-8/..",
154 { /* 15. Unsupported encoding */
158 { /* 16. Supported encoding */
159 "/b/c/../#enc:utf-8",
162 { /* 17. Unsupported encoding */
166 #endif /* HAVE_CHARSET */
170 /* @Test(dataSource = "test_canonicalize_path_ds") */
172 START_PARAMETRIZED_TEST (test_canonicalize_path
, test_canonicalize_path_ds
)
178 actual_path
= g_strdup (data
->input_path
);
181 canonicalize_pathname (actual_path
);
184 mctest_assert_str_eq (actual_path
, data
->expected_path
) g_free (actual_path
);
187 END_PARAMETRIZED_TEST
190 /* --------------------------------------------------------------------------------------------- */
197 Suite
*s
= suite_create (TEST_SUITE_NAME
);
198 TCase
*tc_core
= tcase_create ("Core");
201 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
203 /* Add new tests here: *************** */
204 mctest_add_parameterized_test (tc_core
, test_canonicalize_path
, test_canonicalize_path_ds
);
205 /* *********************************** */
207 suite_add_tcase (s
, tc_core
);
208 sr
= srunner_create (s
);
209 srunner_set_log (sr
, "canonicalize_pathname.log");
210 srunner_run_all (sr
, CK_ENV
);
211 number_failed
= srunner_ntests_failed (sr
);
213 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
216 /* --------------------------------------------------------------------------------------------- */