2 lib - canonicalize path
4 Copyright (C) 2011, 2013
5 The 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"
30 #include "lib/strutil.h"
32 #include "lib/vfs/xdirentry.h"
34 #include "src/vfs/local/local.c"
39 str_init_strings (NULL
);
43 vfs_setup_work_dir ();
50 str_uninit_strings ();
53 /* --------------------------------------------------------------------------------------------- */
55 #define check_canonicalize( input, etalon ) { \
56 path = g_strdup(input); \
57 canonicalize_pathname (path); \
59 strcmp(path, etalon) == 0, \
60 "\nactual value (%s)\nnot equal to etalon (%s)", path, etalon \
66 START_TEST (test_canonicalize_path
)
70 static struct vfs_s_subclass test_subclass
;
71 static struct vfs_class vfs_test_ops
;
73 vfs_s_init_class (&vfs_test_ops
, &test_subclass
);
75 vfs_test_ops
.name
= "testfs";
76 vfs_test_ops
.flags
= VFSF_NOLINKS
;
77 vfs_test_ops
.prefix
= "ftp";
78 test_subclass
.flags
= VFS_S_REMOTE
;
79 vfs_register_class (&vfs_test_ops
);
82 check_canonicalize ("//some_server/ww", "//some_server/ww");
85 check_canonicalize ("///some_server/////////ww", "/some_server/ww");
87 /* Collapse "/./" -> "/" */
88 check_canonicalize ("//some_server//.///////ww/./././.", "//some_server/ww");
90 /* Remove leading "./" */
91 check_canonicalize ("./some_server/ww", "some_server/ww");
94 check_canonicalize ("some_server/..", ".");
96 /* Collapse "/.." with the previous part of path */
97 check_canonicalize ("/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww",
98 "/some_server/ww/ww/some_server/ww");
101 check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/",
102 "/some_server/ww/ftp://user:pass@host.net/path");
104 check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/../../", "/some_server/ww");
106 check_canonicalize ("ftp://user:pass@host.net/path/../../", ".");
108 check_canonicalize ("ftp://user/../../", "..");
114 /* --------------------------------------------------------------------------------------------- */
121 Suite
*s
= suite_create (TEST_SUITE_NAME
);
122 TCase
*tc_core
= tcase_create ("Core");
125 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
127 /* Add new tests here: *************** */
128 tcase_add_test (tc_core
, test_canonicalize_path
);
129 /* *********************************** */
131 suite_add_tcase (s
, tc_core
);
132 sr
= srunner_create (s
);
133 srunner_set_log (sr
, "canonicalize_pathname.log");
134 srunner_run_all (sr
, CK_NORMAL
);
135 number_failed
= srunner_ntests_failed (sr
);
137 return (number_failed
== 0) ? 0 : 1;
140 /* --------------------------------------------------------------------------------------------- */