2 lib/vfs - test vfs_s_get_path() function
4 Copyright (C) 2011-2024
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/direntry.c" /* for testing static methods */
33 #include "src/vfs/local/local.c"
35 #define ARCH_NAME "/path/to/some/file.ext"
36 #define ETALON_PATH "path/to/test1_file.ext"
37 #define ETALON_VFS_NAME "#test2:user:pass@host.net"
38 #define ETALON_VFS_URL_NAME "test2://user:pass@host.net"
40 struct vfs_s_subclass test_subclass1
, test_subclass2
, test_subclass3
;
41 static struct vfs_class
*vfs_test_ops1
= VFS_CLASS (&test_subclass1
);
42 static struct vfs_class
*vfs_test_ops2
= VFS_CLASS (&test_subclass2
);
43 static struct vfs_class
*vfs_test_ops3
= VFS_CLASS (&test_subclass3
);
45 /* --------------------------------------------------------------------------------------------- */
48 test1_mock_open_archive (struct vfs_s_super
*super
, const vfs_path_t
*vpath
,
49 const vfs_path_element_t
*vpath_element
)
51 struct vfs_s_inode
*root
;
53 mctest_assert_str_eq (vfs_path_as_str (vpath
), "/" ETALON_VFS_URL_NAME ARCH_NAME
);
55 super
->name
= g_strdup (vfs_path_as_str (vpath
));
56 root
= vfs_s_new_inode (vpath_element
->class, super
, NULL
);
61 /* --------------------------------------------------------------------------------------------- */
64 test1_mock_archive_same (const vfs_path_element_t
*vpath_element
, struct vfs_s_super
*super
,
65 const vfs_path_t
*vpath
, void *cookie
)
73 path
= vfs_path_get_last_path_str (vpath
);
74 return (strcmp (ARCH_NAME
, path
) != 0 ? 0 : 1);
77 /* --------------------------------------------------------------------------------------------- */
83 str_init_strings (NULL
);
87 vfs_setup_work_dir ();
89 vfs_init_subclass (&test_subclass1
, "testfs1", VFSF_NOLINKS
| VFSF_REMOTE
, "test1");
90 test_subclass1
.open_archive
= test1_mock_open_archive
;
91 test_subclass1
.archive_same
= test1_mock_archive_same
;
92 test_subclass1
.archive_check
= NULL
;
93 vfs_register_class (vfs_test_ops1
);
95 vfs_init_subclass (&test_subclass2
, "testfs2", VFSF_UNKNOWN
, "test2");
96 vfs_register_class (vfs_test_ops2
);
98 vfs_init_subclass (&test_subclass3
, "testfs3", VFSF_UNKNOWN
, "test3");
99 vfs_register_class (vfs_test_ops3
);
102 /* --------------------------------------------------------------------------------------------- */
109 str_uninit_strings ();
114 vfs_die (const char *m
)
116 printf ("VFS_DIE: '%s'\n", m
);
119 /* --------------------------------------------------------------------------------------------- */
123 START_TEST (test_vfs_s_get_path
)
127 struct vfs_s_super
*archive
;
132 vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME
"#test1:/" ETALON_PATH
,
133 VPF_USE_DEPRECATED_PARSER
);
135 result
= vfs_s_get_path (vpath
, &archive
, 0);
138 mctest_assert_str_eq (result
, ETALON_PATH
);
139 mctest_assert_str_eq (archive
->name
, "/" ETALON_VFS_URL_NAME ARCH_NAME
);
148 /* --------------------------------------------------------------------------------------------- */
155 tc_core
= tcase_create ("Core");
157 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
159 /* Add new tests here: *************** */
160 tcase_add_test (tc_core
, test_vfs_s_get_path
);
161 /* *********************************** */
163 return mctest_run_all (tc_core
);
166 /* --------------------------------------------------------------------------------------------- */