Zero struct stat tv_nsec (if supported) whenever st is filled manually
[midnight-commander.git] / tests / lib / vfs / vfs_split.c
blobba0d2ac90c5c4616c5d346f0e7ab7d149ae4d407
1 /*
2 lib/vfs - test vfs_split() functionality
4 Copyright (C) 2011-2017
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/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 /* --------------------------------------------------------------------------------------------- */
41 /* @Before */
42 static void
43 setup (void)
45 str_init_strings (NULL);
47 vfs_init ();
48 init_localfs ();
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 /* --------------------------------------------------------------------------------------------- */
73 /* @After */
74 static void
75 teardown (void)
77 vfs_shut ();
78 str_uninit_strings ();
81 /* --------------------------------------------------------------------------------------------- */
83 /* @DataSource("test_vfs_split_ds") */
84 /* *INDENT-OFF* */
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[] =
94 { /* 0. */
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/",
97 "qqq/www/eee.rr",
98 "test3:",
99 &vfs_test_ops3
101 { /* 1. */
102 "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
103 "#test1:/bla-bla/some/path/",
104 "bla-bla/some/path2/",
105 "test2:",
106 &vfs_test_ops2
108 { /* 2. */
109 "#test1:/bla-bla/some/path/",
111 "bla-bla/some/path/",
112 "test1:",
113 &vfs_test_ops1
115 { /* 3. */
118 NULL,
119 NULL,
120 NULL
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",
125 "qqq/www/eee.rr",
126 "test3:",
127 &vfs_test_ops3
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",
133 "test2:",
134 &vfs_test_ops2,
136 { /* 6. split with local */
137 "/local/path/#test1:/bla-bla/some/path/",
138 "/local/path/",
139 "bla-bla/some/path/",
140 "test1:",
141 &vfs_test_ops1
143 { /* 7. split with local */
144 "/local/path/",
145 "/local/path/",
146 NULL,
147 NULL,
148 NULL
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",
155 &vfs_test_ops2
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",
162 &vfs_test_ops2
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",
168 "test2:",
169 &vfs_test_ops2
172 /* *INDENT-ON* */
174 /* @Test(dataSource = "test_vfs_split_ds") */
175 /* *INDENT-OFF* */
176 START_PARAMETRIZED_TEST (test_vfs_split, test_vfs_split_ds)
177 /* *INDENT-ON* */
179 /* given */
180 const char *local = NULL, *op = NULL;
181 struct vfs_class *actual_result;
182 char *path;
184 path = g_strdup (data->input_string);
186 /* when */
187 actual_result = _vfs_split_with_semi_skip_count (path, &local, &op, 0);
189 /* then */
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);
194 g_free (path);
196 /* *INDENT-OFF* */
197 END_PARAMETRIZED_TEST
198 /* *INDENT-ON* */
200 /* --------------------------------------------------------------------------------------------- */
203 main (void)
205 int number_failed;
207 Suite *s = suite_create (TEST_SUITE_NAME);
208 TCase *tc_core = tcase_create ("Core");
209 SRunner *sr;
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);
222 srunner_free (sr);
223 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
226 /* --------------------------------------------------------------------------------------------- */