fixed x_basename function for handle URL-like paths
[midnight-commander.git] / lib / tests / x_basename.c
blob1eb710e5fae188264b21ea427723bb6a4e88f7e6
1 /* lib/vfs - x_basename() function testing
3 Copyright (C) 2011 Free Software Foundation, Inc.
5 Written by:
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"
25 #include <check.h>
27 #include <stdio.h>
29 #include "lib/global.h"
30 #include "lib/strutil.h"
31 #include "lib/util.h"
34 static void
35 setup (void)
39 static void
40 teardown (void)
44 /* --------------------------------------------------------------------------------------------- */
45 #define check_x_basename( input, etalon ) \
46 { \
47 result = x_basename ( input ); \
48 fail_unless(strcmp(result, etalon) == 0, \
49 "\ninput (%s)\nactial (%s) not equal to\netalon (%s)", input, result, etalon); \
52 START_TEST (test_x_basename)
54 const char *result;
55 check_x_basename ("/test/path/test2/path2", "path2");
57 check_x_basename ("/test/path/test2/path2#vfsprefix", "path2#vfsprefix");
59 check_x_basename ("/test/path/test2/path2/vfsprefix://", "path2/vfsprefix://");
62 check_x_basename ("/test/path/test2/path2/vfsprefix://subdir", "subdir");
64 check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/", "subdir/");
66 check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/subdir2", "subdir2");
68 check_x_basename ("/test/path/test2/path2/vfsprefix:///", "/");
70 END_TEST
72 /* --------------------------------------------------------------------------------------------- */
74 int
75 main (void)
77 int number_failed;
79 Suite *s = suite_create (TEST_SUITE_NAME);
80 TCase *tc_core = tcase_create ("Core");
81 SRunner *sr;
83 tcase_add_checked_fixture (tc_core, setup, teardown);
85 /* Add new tests here: *************** */
86 tcase_add_test (tc_core, test_x_basename);
87 /* *********************************** */
89 suite_add_tcase (s, tc_core);
90 sr = srunner_create (s);
91 srunner_set_log (sr, "x_basename.log");
92 srunner_run_all (sr, CK_NORMAL);
93 number_failed = srunner_ntests_failed (sr);
94 srunner_free (sr);
95 return (number_failed == 0) ? 0 : 1;
98 /* --------------------------------------------------------------------------------------------- */