Zero struct stat tv_nsec (if supported) whenever st is filled manually
[midnight-commander.git] / tests / lib / vfs / vfs_prefix_to_class.c
blobdf5f962c8349a818cae78c0930ff8edad0957f0e
1 /*
2 lib/vfs - test vfs_prefix_to_class() 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/vfs.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 static int
42 test_which (struct vfs_class *me, const char *path)
44 (void) me;
46 if ((strcmp (path, "test_1:") == 0) ||
47 (strcmp (path, "test_2:") == 0) ||
48 (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
49 return 1;
50 return -1;
53 /* --------------------------------------------------------------------------------------------- */
55 /* @Before */
56 static void
57 setup (void)
59 str_init_strings (NULL);
61 vfs_init ();
62 init_localfs ();
63 vfs_setup_work_dir ();
65 test_subclass1.flags = VFS_S_REMOTE;
66 vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
67 vfs_test_ops1.name = "testfs1";
68 vfs_test_ops1.flags = VFSF_NOLINKS;
69 vfs_test_ops1.prefix = "test1:";
70 vfs_test_ops1.which = test_which;
71 vfs_register_class (&vfs_test_ops1);
73 vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
74 vfs_test_ops2.name = "testfs2";
75 vfs_test_ops2.prefix = "test2:";
76 vfs_register_class (&vfs_test_ops2);
78 vfs_s_init_class (&vfs_test_ops3, &test_subclass3);
79 vfs_test_ops3.name = "testfs3";
80 vfs_test_ops3.prefix = "test3:";
81 vfs_register_class (&vfs_test_ops3);
85 /* --------------------------------------------------------------------------------------------- */
87 /* @After */
88 static void
89 teardown (void)
91 vfs_shut ();
92 str_uninit_strings ();
95 /* --------------------------------------------------------------------------------------------- */
97 /* @DataSource("test_vfs_prefix_to_class_ds") */
98 /* *INDENT-OFF* */
99 static const struct test_vfs_prefix_to_class_ds
101 const char *input_string;
102 const struct vfs_class *expected_result;
103 } test_vfs_prefix_to_class_ds[] =
105 { /* 0 */
106 "test_1:",
107 &vfs_test_ops1
109 { /* 1 */
110 "test_2:",
111 &vfs_test_ops1
113 { /* 2 */
114 "test_3:",
115 &vfs_test_ops1
117 { /* 3 */
118 "test_4:",
119 &vfs_test_ops1
121 { /* 4 */
122 "test2:",
123 &vfs_test_ops2
125 { /* 5 */
126 "test3:",
127 &vfs_test_ops3
130 "test1:",
131 NULL
133 { /* 6 */
134 "test_5:",
135 NULL
137 { /* 7 */
138 "test4:",
139 NULL
142 /* *INDENT-ON* */
144 /* @Test(dataSource = "test_vfs_prefix_to_class_ds") */
145 /* *INDENT-OFF* */
146 START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
147 /* *INDENT-ON* */
149 /* given */
150 struct vfs_class *actual_result;
152 /* when */
153 actual_result = vfs_prefix_to_class ((char *) data->input_string);
155 /* then */
156 mctest_assert_ptr_eq (actual_result, data->expected_result);
158 /* *INDENT-OFF* */
159 END_PARAMETRIZED_TEST
160 /* *INDENT-ON* */
162 /* --------------------------------------------------------------------------------------------- */
165 main (void)
167 int number_failed;
169 Suite *s = suite_create (TEST_SUITE_NAME);
170 TCase *tc_core = tcase_create ("Core");
171 SRunner *sr;
173 tcase_add_checked_fixture (tc_core, setup, teardown);
175 /* Add new tests here: *************** */
176 mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds);
177 /* *********************************** */
179 suite_add_tcase (s, tc_core);
180 sr = srunner_create (s);
181 srunner_set_log (sr, "vfs_prefix_to_class.log");
182 srunner_run_all (sr, CK_ENV);
183 number_failed = srunner_ntests_failed (sr);
184 srunner_free (sr);
185 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
188 /* --------------------------------------------------------------------------------------------- */