1 /* lib/vfs - manipulate with current directory
3 Copyright (C) 2011 Free Software Foundation, Inc.
6 Slava Zanko <slavazanko@gmail.com>, 2011
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #define TEST_SUITE_NAME "/lib/vfs"
28 #include "lib/global.h"
29 #include "lib/strutil.h"
30 #include "lib/vfs/xdirentry.h"
32 #include "src/vfs/local/local.c"
37 str_init_strings (NULL
);
41 vfs_setup_work_dir ();
48 str_uninit_strings ();
52 test_chdir(const vfs_path_t
* vpath
)
55 char *path
= vfs_path_to_str(vpath
);
56 printf("test_chdir: %s\n", path
);
64 /* --------------------------------------------------------------------------------------------- */
66 #define cd_and_check( cd_dir, etalon ) \
69 strcmp(etalon, mc_get_current_wd(buffer,MC_MAXPATHLEN)) == 0, \
70 "\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer);
72 START_TEST (set_up_current_dir
)
74 static struct vfs_s_subclass test_subclass
;
75 static struct vfs_class vfs_test_ops
;
76 char buffer
[MC_MAXPATHLEN
];
78 vfs_s_init_class (&vfs_test_ops
, &test_subclass
);
80 vfs_test_ops
.name
= "testfs";
81 vfs_test_ops
.flags
= VFSF_NOLINKS
;
82 vfs_test_ops
.prefix
= "test";
83 vfs_test_ops
.chdir
= test_chdir
;
85 vfs_register_class (&vfs_test_ops
);
87 cd_and_check ("/dev/some.file#test", "/dev/some.file/test://");
89 cd_and_check ("/dev/some.file#test/bla-bla", "/dev/some.file/test://bla-bla");
91 cd_and_check ("..", "/dev/some.file/test://");
93 cd_and_check ("..", "/dev");
95 cd_and_check ("..", "/");
97 cd_and_check ("..", "/");
99 cd_and_check ("/dev/some.file/#test/bla-bla", "/dev/some.file/test://bla-bla");
101 cd_and_check ("..", "/dev/some.file/test://");
103 cd_and_check ("..", "/dev");
105 cd_and_check ("..", "/");
107 cd_and_check ("..", "/");
111 /* --------------------------------------------------------------------------------------------- */
113 START_TEST (set_up_current_dir_url
)
115 static struct vfs_s_subclass test_subclass
;
116 static struct vfs_class vfs_test_ops
;
117 char buffer
[MC_MAXPATHLEN
];
119 vfs_s_init_class (&vfs_test_ops
, &test_subclass
);
121 vfs_test_ops
.name
= "testfs";
122 vfs_test_ops
.flags
= VFSF_NOLINKS
;
123 vfs_test_ops
.prefix
= "test";
124 vfs_test_ops
.chdir
= test_chdir
;
126 vfs_register_class (&vfs_test_ops
);
128 cd_and_check ("/dev/some.file/test://", "/dev/some.file/test://");
130 cd_and_check ("/dev/some.file/test://bla-bla", "/dev/some.file/test://bla-bla");
132 cd_and_check ("..", "/dev/some.file/test://");
134 cd_and_check ("..", "/dev");
136 cd_and_check ("..", "/");
138 cd_and_check ("..", "/");
140 test_subclass
.flags
= VFS_S_REMOTE
;
142 cd_and_check ("/test://user:pass@host.net/path", "/test://user:pass@host.net/path");
143 cd_and_check ("..", "/test://user:pass@host.net");
145 cd_and_check ("..", "/");
150 /* --------------------------------------------------------------------------------------------- */
157 Suite
*s
= suite_create (TEST_SUITE_NAME
);
158 TCase
*tc_core
= tcase_create ("Core");
161 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
163 /* Add new tests here: *************** */
164 tcase_add_test (tc_core
, set_up_current_dir
);
165 tcase_add_test (tc_core
, set_up_current_dir_url
);
166 /* *********************************** */
168 suite_add_tcase (s
, tc_core
);
169 sr
= srunner_create (s
);
170 srunner_set_log (sr
, "current_dir.log");
171 srunner_run_all (sr
, CK_NORMAL
);
172 number_failed
= srunner_ntests_failed (sr
);
174 return (number_failed
== 0) ? 0 : 1;
177 /* --------------------------------------------------------------------------------------------- */