1 /* lib - canonicalize path
3 Copyright (C) 2011 Free Software Foundation, Inc.
6 Slava Zanko <slavazanko@gmail.com>, 2011
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #define TEST_SUITE_NAME "/lib"
28 #include "lib/global.h"
41 /* --------------------------------------------------------------------------------------------- */
43 #define check_canonicalize( input, etalon ) { \
44 path = g_strdup(input); \
45 canonicalize_pathname (path); \
47 strcmp(path, etalon) == 0, \
48 "\nactual value (%s)\nnot equal to etalon (%s)", path, etalon \
53 START_TEST (test_canonicalize_path
)
58 check_canonicalize ("//some_server/ww", "//some_server/ww");
61 check_canonicalize ("///some_server/////////ww", "/some_server/ww");
63 /* Collapse "/./" -> "/" */
64 check_canonicalize ("//some_server//.///////ww/./././.", "//some_server/ww");
66 /* Remove leading "./" */
67 check_canonicalize ("./some_server/ww", "some_server/ww");
70 check_canonicalize ("some_server/..", ".");
72 /* Collapse "/.." with the previous part of path */
73 check_canonicalize ("/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww", "/some_server/ww/ww/some_server/ww");
76 check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/", "/some_server/ww/ftp://user:pass@host.net/path");
78 check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/../../", "/some_server/ww");
80 check_canonicalize ("ftp://user:pass@host.net/path/../../", ".");
82 check_canonicalize ("ftp://user/../../", "..");
87 /* --------------------------------------------------------------------------------------------- */
94 Suite
*s
= suite_create (TEST_SUITE_NAME
);
95 TCase
*tc_core
= tcase_create ("Core");
98 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
100 /* Add new tests here: *************** */
101 tcase_add_test (tc_core
, test_canonicalize_path
);
102 /* *********************************** */
104 suite_add_tcase (s
, tc_core
);
105 sr
= srunner_create (s
);
106 srunner_set_log (sr
, "canonicalize_pathname.log");
107 srunner_run_all (sr
, CK_NORMAL
);
108 number_failed
= srunner_ntests_failed (sr
);
110 return (number_failed
== 0) ? 0 : 1;
113 /* --------------------------------------------------------------------------------------------- */