1 /* lib/vfs - test vfs_path_from_str_flags() function
2
3 Copyright (C) 2013-2025
4 Free Software Foundation, Inc.
5
6 Written by:
7 Slava Zanko <slavazanko@gmail.com>, 2013
8
9 This file is part of the Midnight Commander.
10
11 The Midnight Commander is free software: you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation, either version 3 of the License,
14 or (at your option) any later version.
15
16 The Midnight Commander is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25 #define TEST_SUITE_NAME "/lib/vfs"
26
27 #include "tests/mctest.h"
28
29 #include "lib/strutil.h"
30 #include "lib/vfs/xdirentry.h"
31 #include "lib/vfs/path.h"
32
33 #include "src/vfs/local/local.c"
34
35 /* --------------------------------------------------------------------------------------------- */
36
37 /* @Mock */
38 const char *
39 mc_config_get_home_dir (void)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
40 {
41 return "/mock/test";
42 }
43
44 /* --------------------------------------------------------------------------------------------- */
45 /* @Before */
46 static void
47 setup (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
48 {
49 str_init_strings (NULL);
50
51 vfs_init ();
52 vfs_init_localfs ();
53 vfs_setup_work_dir ();
54 }
55
56 /* --------------------------------------------------------------------------------------------- */
57
58 /* @After */
59 static void
60 teardown (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
61 {
62 vfs_shut ();
63 str_uninit_strings ();
64 }
65
66 /* --------------------------------------------------------------------------------------------- */
67
68 /* @DataSource("test_from_to_string_ds") */
69 static const struct test_strip_home_ds
70 {
71 const char *input_string;
72 const char *expected_result;
73 } test_strip_home_ds[] = {
74 {
75 // 0.
76 "/mock/test/some/path",
77 "~/some/path",
78 },
79 {
80 // 1.
81 "/mock/testttt/some/path",
82 "/mock/testttt/some/path",
83 },
84 };
85
86 /* @Test */
87 START_PARAMETRIZED_TEST (test_strip_home, test_strip_home_ds)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
88 {
89 // given
90 vfs_path_t *actual_result;
91
92 // when
93 actual_result = vfs_path_from_str_flags (data->input_string, VPF_STRIP_HOME);
94
95 // then
96 mctest_assert_str_eq (actual_result->str, data->expected_result);
97
98 vfs_path_free (actual_result, TRUE);
99 }
100 END_PARAMETRIZED_TEST
101
102 /* --------------------------------------------------------------------------------------------- */
103
104 int
105 main (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
106 {
107 TCase *tc_core;
108
109 tc_core = tcase_create ("Core");
110
111 tcase_add_checked_fixture (tc_core, setup, teardown);
112
113 // Add new tests here: ***************
114 mctest_add_parameterized_test (tc_core, test_strip_home, test_strip_home_ds);
115 // ***********************************
116
117 return mctest_run_all (tc_core);
118 }
119
120 /* --------------------------------------------------------------------------------------------- */