2 lib/vfs - test vfs_s_get_path() function
4 Copyright (C) 2011, 2013
5 The 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 struct vfs_class vfs_test_ops1
, vfs_test_ops2
, vfs_test_ops3
;
43 /* --------------------------------------------------------------------------------------------- */
46 test1_mock_open_archive (struct vfs_s_super
*super
, const vfs_path_t
* vpath
,
47 const vfs_path_element_t
* vpath_element
)
49 struct vfs_s_inode
*root
;
50 char *spath
= vfs_path_to_str (vpath
);
52 mctest_assert_str_eq (spath
, "/" ETALON_VFS_URL_NAME ARCH_NAME
);
54 super
->name
= g_strdup (spath
);
55 super
->data
= g_new (char *, 1);
56 root
= vfs_s_new_inode (vpath_element
->class, super
, NULL
);
62 /* --------------------------------------------------------------------------------------------- */
65 test1_mock_archive_same (const vfs_path_element_t
* vpath_element
, struct vfs_s_super
*super
,
66 const vfs_path_t
* vpath
, void *cookie
)
68 const vfs_path_element_t
*path_element
;
74 path_element
= vfs_path_get_by_index (vpath
, -1);
75 if (strcmp (ARCH_NAME
, path_element
->path
) != 0)
80 /* --------------------------------------------------------------------------------------------- */
87 str_init_strings (NULL
);
91 vfs_setup_work_dir ();
94 test_subclass1
.flags
= VFS_S_REMOTE
;
95 vfs_s_init_class (&vfs_test_ops1
, &test_subclass1
);
97 vfs_test_ops1
.name
= "testfs1";
98 vfs_test_ops1
.flags
= VFSF_NOLINKS
;
99 vfs_test_ops1
.prefix
= "test1:";
100 vfs_register_class (&vfs_test_ops1
);
101 test_subclass1
.open_archive
= test1_mock_open_archive
;
102 test_subclass1
.archive_same
= test1_mock_archive_same
;
103 test_subclass1
.archive_check
= NULL
;
105 vfs_s_init_class (&vfs_test_ops2
, &test_subclass2
);
106 vfs_test_ops2
.name
= "testfs2";
107 vfs_test_ops2
.prefix
= "test2:";
108 vfs_register_class (&vfs_test_ops2
);
110 vfs_s_init_class (&vfs_test_ops3
, &test_subclass3
);
111 vfs_test_ops3
.name
= "testfs3";
112 vfs_test_ops3
.prefix
= "test3:";
113 vfs_register_class (&vfs_test_ops3
);
116 /* --------------------------------------------------------------------------------------------- */
123 str_uninit_strings ();
128 vfs_die (const char *m
)
130 printf ("VFS_DIE: '%s'\n", m
);
133 /* --------------------------------------------------------------------------------------------- */
137 START_TEST (test_vfs_s_get_path
)
141 struct vfs_s_super
*archive
;
146 vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME
"#test1:/" ETALON_PATH
,
147 VPF_USE_DEPRECATED_PARSER
);
149 result
= vfs_s_get_path (vpath
, &archive
, 0);
152 mctest_assert_str_eq (result
, ETALON_PATH
);
153 mctest_assert_str_eq (archive
->name
, "/" ETALON_VFS_URL_NAME ARCH_NAME
);
162 /* --------------------------------------------------------------------------------------------- */
169 Suite
*s
= suite_create (TEST_SUITE_NAME
);
170 TCase
*tc_core
= tcase_create ("Core");
173 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
175 /* Add new tests here: *************** */
176 tcase_add_test (tc_core
, test_vfs_s_get_path
);
177 /* *********************************** */
179 suite_add_tcase (s
, tc_core
);
180 sr
= srunner_create (s
);
181 srunner_set_log (sr
, "vfs_s_get_path.log");
182 srunner_run_all (sr
, CK_NORMAL
);
183 number_failed
= srunner_ntests_failed (sr
);
185 return (number_failed
== 0) ? 0 : 1;
188 /* --------------------------------------------------------------------------------------------- */