2 lib/vfs - test vfs_split() functionality
4 Copyright (C) 2011-2017
5 Free Software Foundation, Inc.
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/vfs"
28 #include "tests/mctest.h"
30 #include "lib/strutil.h"
31 #include "lib/vfs/xdirentry.h"
32 #include "lib/vfs/path.c" /* for testing static methods */
34 #include "src/vfs/local/local.c"
36 struct vfs_s_subclass test_subclass1
, test_subclass2
, test_subclass3
;
37 struct vfs_class vfs_test_ops1
, vfs_test_ops2
, vfs_test_ops3
;
39 /* --------------------------------------------------------------------------------------------- */
45 str_init_strings (NULL
);
49 vfs_setup_work_dir ();
52 test_subclass1
.flags
= VFS_S_REMOTE
;
53 vfs_s_init_class (&vfs_test_ops1
, &test_subclass1
);
55 vfs_test_ops1
.name
= "testfs1";
56 vfs_test_ops1
.flags
= VFSF_NOLINKS
;
57 vfs_test_ops1
.prefix
= "test1:";
58 vfs_register_class (&vfs_test_ops1
);
60 vfs_s_init_class (&vfs_test_ops2
, &test_subclass2
);
61 vfs_test_ops2
.name
= "testfs2";
62 vfs_test_ops2
.prefix
= "test2:";
63 vfs_register_class (&vfs_test_ops2
);
65 vfs_s_init_class (&vfs_test_ops3
, &test_subclass3
);
66 vfs_test_ops3
.name
= "testfs3";
67 vfs_test_ops3
.prefix
= "test3:";
68 vfs_register_class (&vfs_test_ops3
);
71 /* --------------------------------------------------------------------------------------------- */
78 str_uninit_strings ();
81 /* --------------------------------------------------------------------------------------------- */
83 /* @DataSource("test_vfs_split_ds") */
85 static const struct test_vfs_split_ds
87 const char *input_string
;
88 const char *expected_path
;
89 const char *expected_local
;
90 const char *expected_op
;
91 const struct vfs_class
*expected_result
;
92 } test_vfs_split_ds
[] =
95 "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr",
96 "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
102 "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
103 "#test1:/bla-bla/some/path/",
104 "bla-bla/some/path2/",
109 "#test1:/bla-bla/some/path/",
111 "bla-bla/some/path/",
122 { /* 4. split with local */
123 "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr",
124 "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
129 { /* 5. split with local */
130 "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
131 "/local/path/#test1:/bla-bla/some/path/",
132 "bla-bla/some/path2",
136 { /* 6. split with local */
137 "/local/path/#test1:/bla-bla/some/path/",
139 "bla-bla/some/path/",
143 { /* 7. split with local */
150 { /* 8. split with URL */
151 "#test2:username:passwd@somehost.net/bla-bla/some/path2",
153 "bla-bla/some/path2",
154 "test2:username:passwd@somehost.net",
157 { /* 9. split URL with semi */
158 "/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/some/path2",
159 "/local/path/#test1:/bla-bla/some/path/",
160 "bla-bla/some/path2",
161 "test2:username:p!a@s#s$w%d@somehost.net",
164 { /* 10. split with semi in path */
165 "#test2:/bl#a-bl#a/so#me/pa#th2",
167 "bl#a-bl#a/so#me/pa#th2",
174 /* @Test(dataSource = "test_vfs_split_ds") */
176 START_PARAMETRIZED_TEST (test_vfs_split
, test_vfs_split_ds
)
180 const char *local
= NULL
, *op
= NULL
;
181 struct vfs_class
*actual_result
;
184 path
= g_strdup (data
->input_string
);
187 actual_result
= _vfs_split_with_semi_skip_count (path
, &local
, &op
, 0);
190 mctest_assert_ptr_eq (actual_result
, data
->expected_result
);
191 mctest_assert_str_eq (path
, data
->expected_path
);
192 mctest_assert_str_eq (local
, data
->expected_local
);
193 mctest_assert_str_eq (op
, data
->expected_op
);
197 END_PARAMETRIZED_TEST
200 /* --------------------------------------------------------------------------------------------- */
207 Suite
*s
= suite_create (TEST_SUITE_NAME
);
208 TCase
*tc_core
= tcase_create ("Core");
211 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
213 /* Add new tests here: *************** */
214 mctest_add_parameterized_test (tc_core
, test_vfs_split
, test_vfs_split_ds
);
215 /* *********************************** */
217 suite_add_tcase (s
, tc_core
);
218 sr
= srunner_create (s
);
219 srunner_set_log (sr
, "vfs_split.log");
220 srunner_run_all (sr
, CK_ENV
);
221 number_failed
= srunner_ntests_failed (sr
);
223 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
226 /* --------------------------------------------------------------------------------------------- */