Ticket #4217: remove OS/distro-specific stuff.
[midnight-commander.git] / tests / lib / vfs / vfs_prefix_to_class.c
blob0f5143176ffc0d91e61061a37f4a65581e0a9286
1 /*
2 lib/vfs - test vfs_prefix_to_class() functionality
4 Copyright (C) 2011-2021
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 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
38 /* --------------------------------------------------------------------------------------------- */
40 static int
41 test_which (struct vfs_class *me, const char *path)
43 (void) me;
45 if ((strcmp (path, "test_1:") == 0) ||
46 (strcmp (path, "test_2:") == 0) ||
47 (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
48 return 1;
49 return -1;
52 /* --------------------------------------------------------------------------------------------- */
54 /* @Before */
55 static void
56 setup (void)
58 str_init_strings (NULL);
60 vfs_init ();
61 vfs_init_localfs ();
62 vfs_setup_work_dir ();
64 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
65 vfs_test_ops1.which = test_which;
66 vfs_register_class (&vfs_test_ops1);
68 vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
69 vfs_register_class (&vfs_test_ops2);
71 vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
72 vfs_register_class (&vfs_test_ops3);
75 /* --------------------------------------------------------------------------------------------- */
77 /* @After */
78 static void
79 teardown (void)
81 vfs_shut ();
82 str_uninit_strings ();
85 /* --------------------------------------------------------------------------------------------- */
87 /* @DataSource("test_vfs_prefix_to_class_ds") */
88 /* *INDENT-OFF* */
89 static const struct test_vfs_prefix_to_class_ds
91 const char *input_string;
92 const struct vfs_class *expected_result;
93 } test_vfs_prefix_to_class_ds[] =
95 { /* 0 */
96 "test_1:",
97 &vfs_test_ops1
99 { /* 1 */
100 "test_2:",
101 &vfs_test_ops1
103 { /* 2 */
104 "test_3:",
105 &vfs_test_ops1
107 { /* 3 */
108 "test_4:",
109 &vfs_test_ops1
111 { /* 4 */
112 "test2:",
113 &vfs_test_ops2
115 { /* 5 */
116 "test3:",
117 &vfs_test_ops3
120 "test1:",
121 NULL
123 { /* 6 */
124 "test_5:",
125 NULL
127 { /* 7 */
128 "test4:",
129 NULL
132 /* *INDENT-ON* */
134 /* @Test(dataSource = "test_vfs_prefix_to_class_ds") */
135 /* *INDENT-OFF* */
136 START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
137 /* *INDENT-ON* */
139 /* given */
140 struct vfs_class *actual_result;
142 /* when */
143 actual_result = vfs_prefix_to_class ((char *) data->input_string);
145 /* then */
146 mctest_assert_ptr_eq (actual_result, data->expected_result);
148 /* *INDENT-OFF* */
149 END_PARAMETRIZED_TEST
150 /* *INDENT-ON* */
152 /* --------------------------------------------------------------------------------------------- */
155 main (void)
157 TCase *tc_core;
159 tc_core = tcase_create ("Core");
161 tcase_add_checked_fixture (tc_core, setup, teardown);
163 /* Add new tests here: *************** */
164 mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds);
165 /* *********************************** */
167 return mctest_run_all (tc_core);
170 /* --------------------------------------------------------------------------------------------- */