2 lib - canonicalize path
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011
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"
32 #include "lib/global.h"
33 #include "lib/strutil.h"
35 #include "lib/vfs/xdirentry.h"
37 #include "src/vfs/local/local.c"
42 str_init_strings (NULL
);
46 vfs_setup_work_dir ();
53 str_uninit_strings ();
56 /* --------------------------------------------------------------------------------------------- */
58 #define check_canonicalize( input, etalon ) { \
59 path = g_strdup(input); \
60 canonicalize_pathname (path); \
62 strcmp(path, etalon) == 0, \
63 "\nactual value (%s)\nnot equal to etalon (%s)", path, etalon \
68 START_TEST (test_canonicalize_path
)
71 static struct vfs_s_subclass test_subclass
;
72 static struct vfs_class vfs_test_ops
;
74 vfs_s_init_class (&vfs_test_ops
, &test_subclass
);
76 vfs_test_ops
.name
= "testfs";
77 vfs_test_ops
.flags
= VFSF_NOLINKS
;
78 vfs_test_ops
.prefix
= "ftp";
79 test_subclass
.flags
= VFS_S_REMOTE
;
80 vfs_register_class (&vfs_test_ops
);
83 check_canonicalize ("//some_server/ww", "//some_server/ww");
86 check_canonicalize ("///some_server/////////ww", "/some_server/ww");
88 /* Collapse "/./" -> "/" */
89 check_canonicalize ("//some_server//.///////ww/./././.", "//some_server/ww");
91 /* Remove leading "./" */
92 check_canonicalize ("./some_server/ww", "some_server/ww");
95 check_canonicalize ("some_server/..", ".");
97 /* Collapse "/.." with the previous part of path */
98 check_canonicalize ("/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww", "/some_server/ww/ww/some_server/ww");
101 check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/", "/some_server/ww/ftp://user:pass@host.net/path");
103 check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/../../", "/some_server/ww");
105 check_canonicalize ("ftp://user:pass@host.net/path/../../", ".");
107 check_canonicalize ("ftp://user/../../", "..");
111 /* --------------------------------------------------------------------------------------------- */
118 Suite
*s
= suite_create (TEST_SUITE_NAME
);
119 TCase
*tc_core
= tcase_create ("Core");
122 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
124 /* Add new tests here: *************** */
125 tcase_add_test (tc_core
, test_canonicalize_path
);
126 /* *********************************** */
128 suite_add_tcase (s
, tc_core
);
129 sr
= srunner_create (s
);
130 srunner_set_log (sr
, "canonicalize_pathname.log");
131 srunner_run_all (sr
, CK_NORMAL
);
132 number_failed
= srunner_ntests_failed (sr
);
134 return (number_failed
== 0) ? 0 : 1;
137 /* --------------------------------------------------------------------------------------------- */