Tests tweak and cleanup in case of --disable-charset option usage.
[midnight-commander.git] / tests / lib / vfs / relative_cd.c
blob7e6101da26f265065587df294c3eb6e61825a511
1 /* lib/vfs - test vfs_path_t manipulation functions
3 Copyright (C) 2011 Free Software Foundation, Inc.
5 Written by:
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"
25 #include <check.h>
27 #include "lib/global.c"
29 #include "lib/strutil.h"
30 #include "lib/vfs/xdirentry.h"
31 #include "lib/vfs/path.h"
33 #include "src/vfs/local/local.c"
36 struct vfs_s_subclass test_subclass1;
37 struct vfs_class vfs_test_ops1;
39 static int test_chdir (const vfs_path_t * vpath);
42 static void
43 setup (void)
46 str_init_strings (NULL);
48 vfs_init ();
49 init_localfs ();
50 vfs_setup_work_dir ();
52 test_subclass1.flags = VFS_S_REMOTE;
53 vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
55 vfs_test_ops1.name = "testfs1";
56 vfs_test_ops1.flags = VFSF_NOLINKS;
57 vfs_test_ops1.prefix = "test1";
58 vfs_test_ops1.chdir = test_chdir;
59 vfs_register_class (&vfs_test_ops1);
61 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
64 static void
65 teardown (void)
67 vfs_shut ();
68 str_uninit_strings ();
71 /* --------------------------------------------------------------------------------------------- */
73 static int
74 test_chdir (const vfs_path_t * vpath)
76 char *path = vfs_path_to_str (vpath);
77 printf ("test_chdir: %s\n", path);
78 g_free (path);
79 return 0;
82 /* --------------------------------------------------------------------------------------------- */
84 START_TEST (test_relative_cd)
86 vfs_path_t *vpath;
88 vpath = vfs_path_from_str ("/test1://user:pass@some.host:12345/path/to/dir");
89 fail_if (mc_chdir(vpath) == -1);
90 vfs_path_free (vpath);
92 vpath = vfs_path_from_str_flags ("some-non-exists-dir", VPF_NO_CANON);
93 fail_if (mc_chdir(vpath) == -1);
94 vfs_path_free (vpath);
96 END_TEST
98 /* --------------------------------------------------------------------------------------------- */
100 /* Relative to panel_correct_path_to_show() */
102 START_TEST (test_vpath_to_str_filter)
104 vfs_path_t *vpath, *last_vpath;
105 char *filtered_path;
106 const vfs_path_element_t *path_element;
108 vpath = vfs_path_from_str ("/test1://some.host/dir");
109 path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1));
110 vfs_path_free (vpath);
112 last_vpath = vfs_path_new ();
113 last_vpath->relative = TRUE;
115 vfs_path_add_element (last_vpath, path_element);
117 filtered_path = vfs_path_to_str_flags (last_vpath, 0,
118 VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
119 vfs_path_free (last_vpath);
121 fail_unless (strcmp("test1://some.host/dir", filtered_path) == 0, "actual: %s", filtered_path);
122 g_free (filtered_path);
125 END_TEST
127 /* --------------------------------------------------------------------------------------------- */
130 main (void)
132 int number_failed;
134 Suite *s = suite_create (TEST_SUITE_NAME);
135 TCase *tc_core = tcase_create ("Core");
136 SRunner *sr;
138 tcase_add_checked_fixture (tc_core, setup, teardown);
140 /* Add new tests here: *************** */
141 tcase_add_test (tc_core, test_relative_cd);
142 tcase_add_test (tc_core, test_vpath_to_str_filter);
143 /* *********************************** */
145 suite_add_tcase (s, tc_core);
146 sr = srunner_create (s);
147 srunner_set_log (sr, "relative_cd.log");
148 srunner_run_all (sr, CK_NORMAL);
149 number_failed = srunner_ntests_failed (sr);
150 srunner_free (sr);
151 return (number_failed == 0) ? 0 : 1;
154 /* --------------------------------------------------------------------------------------------- */