Sync with gnulib 1ff0e9684bb83a8277ffe22ac125ce7e90f6702b.
[midnight-commander.git] / tests / lib / x_basename.c
blob249a3e94b6553b12655b5352121875b4d4afedd1
1 /*
2 lib - x_basename() function testing
4 Copyright (C) 2011-2018
5 Free Software Foundation, Inc.
7 Written by:
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"
28 #include "tests/mctest.h"
30 #include <stdio.h>
32 #include "lib/strutil.h"
33 #include "lib/util.h"
35 /* --------------------------------------------------------------------------------------------- */
37 /* @Before */
38 static void
39 setup (void)
43 /* --------------------------------------------------------------------------------------------- */
45 /* @After */
46 static void
47 teardown (void)
51 /* --------------------------------------------------------------------------------------------- */
53 /* @DataSource("test_x_basename_ds") */
54 /* *INDENT-OFF* */
55 static const struct test_x_basename_ds
57 const char *input_value;
58 const char *expected_result;
59 } test_x_basename_ds[] =
62 "/test/path/test2/path2",
63 "path2"
66 "/test/path/test2/path2#vfsprefix",
67 "path2#vfsprefix"
70 "/test/path/test2/path2/vfsprefix://",
71 "path2/vfsprefix://"
74 "/test/path/test2/path2/vfsprefix://subdir",
75 "subdir"
78 "/test/path/test2/path2/vfsprefix://subdir/",
79 "subdir/"
82 "/test/path/test2/path2/vfsprefix://subdir/subdir2",
83 "subdir2"
86 "/test/path/test2/path2/vfsprefix:///",
87 "/"
90 /* *INDENT-ON* */
92 /* @Test(dataSource = "test_x_basename_ds") */
93 /* *INDENT-OFF* */
94 START_PARAMETRIZED_TEST (test_x_basename, test_x_basename_ds)
95 /* *INDENT-ON* */
97 /* given */
98 const char *actual_result;
100 /* when */
101 actual_result = x_basename (data->input_value);
103 /* then */
104 mctest_assert_str_eq (actual_result, data->expected_result);
106 /* *INDENT-OFF* */
107 END_PARAMETRIZED_TEST
108 /* *INDENT-ON* */
110 /* --------------------------------------------------------------------------------------------- */
113 main (void)
115 int number_failed;
117 Suite *s = suite_create (TEST_SUITE_NAME);
118 TCase *tc_core = tcase_create ("Core");
119 SRunner *sr;
121 tcase_add_checked_fixture (tc_core, setup, teardown);
123 /* Add new tests here: *************** */
124 mctest_add_parameterized_test (tc_core, test_x_basename, test_x_basename_ds);
125 /* *********************************** */
127 suite_add_tcase (s, tc_core);
128 sr = srunner_create (s);
129 srunner_set_log (sr, "x_basename.log");
130 srunner_run_all (sr, CK_ENV);
131 number_failed = srunner_ntests_failed (sr);
132 srunner_free (sr);
133 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
136 /* --------------------------------------------------------------------------------------------- */