Ticket 1551: Update GPL version from 2 to 3
[midnight-commander.git] / tests / lib / vfs / canonicalize_pathname.c
blob4d221443acd6ac35f7e3baf2cd0fe22146fd00c9
1 /*
2 lib - canonicalize path
4 Copyright (C) 2011
5 The Free Software Foundation, Inc.
7 Written by:
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"
28 #include <config.h>
30 #include <check.h>
32 #include "lib/global.h"
33 #include "lib/strutil.h"
34 #include "lib/util.h"
35 #include "lib/vfs/xdirentry.h"
37 #include "src/vfs/local/local.c"
39 static void
40 setup (void)
42 str_init_strings (NULL);
44 vfs_init ();
45 init_localfs ();
46 vfs_setup_work_dir ();
49 static void
50 teardown (void)
52 vfs_shut ();
53 str_uninit_strings ();
56 /* --------------------------------------------------------------------------------------------- */
58 #define check_canonicalize( input, etalon ) { \
59 path = g_strdup(input); \
60 canonicalize_pathname (path); \
61 fail_unless ( \
62 strcmp(path, etalon) == 0, \
63 "\nactual value (%s)\nnot equal to etalon (%s)", path, etalon \
64 ); \
65 g_free(path); \
68 START_TEST (test_canonicalize_path)
70 char *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);
82 /* UNC path */
83 check_canonicalize ("//some_server/ww", "//some_server/ww");
85 /* join slashes */
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");
94 /* some/.. -> . */
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");
100 /* URI style */
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/../../", "..");
109 END_TEST
111 /* --------------------------------------------------------------------------------------------- */
114 main (void)
116 int number_failed;
118 Suite *s = suite_create (TEST_SUITE_NAME);
119 TCase *tc_core = tcase_create ("Core");
120 SRunner *sr;
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);
133 srunner_free (sr);
134 return (number_failed == 0) ? 0 : 1;
137 /* --------------------------------------------------------------------------------------------- */