Ticket 1551: Update GPL version from 2 to 3
[midnight-commander.git] / tests / lib / vfs / vfs_s_get_path.c
blob32e71d54a630f2870371246114a85d21415d4582
1 /*
2 lib/vfs - test vfs_s_get_path() function
4 Copyright (C) 2011
5 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2011
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 <config.h>
30 #include <check.h>
32 #include "lib/global.h"
33 #include "lib/strutil.h"
34 #include "lib/vfs/direntry.c" /* for testing static methods */
36 #include "src/vfs/local/local.c"
38 #define ARCH_NAME "/path/to/some/file.ext"
39 #define ETALON_PATH "path/to/test1_file.ext"
40 #define ETALON_VFS_NAME "#test2:user:pass@host.net"
41 #define ETALON_VFS_URL_NAME "test2://user:pass@host.net"
43 struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
44 struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
46 static int
47 test1_mock_open_archive(struct vfs_s_super *super, const vfs_path_t *vpath, const vfs_path_element_t *vpath_element)
49 struct vfs_s_inode *root;
50 char *spath = vfs_path_to_str (vpath);
52 fail_unless(strcmp("/" ETALON_VFS_URL_NAME ARCH_NAME, spath) == 0,
53 "etalon(%s) doesn't equal to actual(%s)", "/" ETALON_VFS_URL_NAME ARCH_NAME, spath);
55 super->name = g_strdup (spath);
56 super->data = g_new (char *, 1);
57 root = vfs_s_new_inode (vpath_element->class, super, NULL);
58 super->root = root;
59 g_free(spath);
60 return 0;
63 static int
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)
67 vfs_path_element_t *path_element = vfs_path_get_by_index(vpath, -1);
69 (void) vpath_element;
70 (void) super;
71 (void) cookie;
73 if (strcmp(ARCH_NAME, path_element->path) != 0)
74 return 0;
75 return 1;
78 static void
79 setup (void)
82 str_init_strings (NULL);
84 vfs_init ();
85 init_localfs ();
86 vfs_setup_work_dir ();
89 test_subclass1.flags = VFS_S_REMOTE;
90 vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
92 vfs_test_ops1.name = "testfs1";
93 vfs_test_ops1.flags = VFSF_NOLINKS;
94 vfs_test_ops1.prefix = "test1:";
95 vfs_register_class (&vfs_test_ops1);
96 test_subclass1.open_archive = test1_mock_open_archive;
97 test_subclass1.archive_same = test1_mock_archive_same;
98 test_subclass1.archive_check = NULL;
100 vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
101 vfs_test_ops2.name = "testfs2";
102 vfs_test_ops2.prefix = "test2:";
103 vfs_register_class (&vfs_test_ops2);
105 vfs_s_init_class (&vfs_test_ops3, &test_subclass3);
106 vfs_test_ops3.name = "testfs3";
107 vfs_test_ops3.prefix = "test3:";
108 vfs_register_class (&vfs_test_ops3);
111 static void
112 teardown (void)
114 vfs_shut ();
115 str_uninit_strings ();
119 void
120 vfs_die (const char *m)
122 printf("VFS_DIE: '%s'\n", m);
125 /* --------------------------------------------------------------------------------------------- */
127 START_TEST (test_vfs_s_get_path)
129 struct vfs_s_super *archive;
131 const char *result;
132 vfs_path_t *vpath = 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);
137 fail_unless(strcmp(ETALON_PATH, result) == 0,
138 "expected(%s) doesn't equal to actual(%s)", ETALON_PATH, result);
140 fail_unless(strcmp("/" ETALON_VFS_URL_NAME ARCH_NAME,archive->name) == 0,
141 "expected(%s) doesn't equal to actual(%s)", "/" ETALON_VFS_URL_NAME ARCH_NAME, archive->name);
143 g_free(vpath);
146 END_TEST
148 /* --------------------------------------------------------------------------------------------- */
151 main (void)
153 int number_failed;
155 Suite *s = suite_create (TEST_SUITE_NAME);
156 TCase *tc_core = tcase_create ("Core");
157 SRunner *sr;
159 tcase_add_checked_fixture (tc_core, setup, teardown);
161 /* Add new tests here: *************** */
162 tcase_add_test (tc_core, test_vfs_s_get_path);
163 /* *********************************** */
165 suite_add_tcase (s, tc_core);
166 sr = srunner_create (s);
167 srunner_set_log (sr, "vfs_s_get_path.log");
168 srunner_run_all (sr, CK_NORMAL);
169 number_failed = srunner_ntests_failed (sr);
170 srunner_free (sr);
171 return (number_failed == 0) ? 0 : 1;
174 /* --------------------------------------------------------------------------------------------- */