Fixed creating string from relative non-local VFS.
[midnight-commander.git] / tests / lib / vfs / relative_cd.c
blob930bb9f588c8764b9f8369c7e584a4255e3c785c
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 #ifndef HAVE_CHARSET
30 #define HAVE_CHARSET 1
31 #endif
33 #include "lib/charsets.h"
35 #include "lib/strutil.h"
36 #include "lib/vfs/xdirentry.h"
37 #include "lib/vfs/path.h"
39 #include "src/vfs/local/local.c"
42 struct vfs_s_subclass test_subclass1;
43 struct vfs_class vfs_test_ops1;
45 static int test_chdir (const vfs_path_t * vpath);
48 static void
49 setup (void)
52 str_init_strings (NULL);
54 vfs_init ();
55 init_localfs ();
56 vfs_setup_work_dir ();
58 test_subclass1.flags = VFS_S_REMOTE;
59 vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
61 vfs_test_ops1.name = "testfs1";
62 vfs_test_ops1.flags = VFSF_NOLINKS;
63 vfs_test_ops1.prefix = "test1";
64 vfs_test_ops1.chdir = test_chdir;
65 vfs_register_class (&vfs_test_ops1);
67 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
68 load_codepages_list ();
71 static void
72 teardown (void)
74 free_codepages_list ();
76 vfs_shut ();
77 str_uninit_strings ();
80 /* --------------------------------------------------------------------------------------------- */
82 static int
83 test_chdir (const vfs_path_t * vpath)
85 char *path = vfs_path_to_str (vpath);
86 printf ("test_chdir: %s\n", path);
87 g_free (path);
88 return 0;
91 /* --------------------------------------------------------------------------------------------- */
93 START_TEST (test_relative_cd)
95 vfs_path_t *vpath;
97 vpath = vfs_path_from_str ("/test1://user:pass@some.host:12345/path/to/dir");
98 fail_if (mc_chdir(vpath) == -1);
99 vfs_path_free (vpath);
101 vpath = vfs_path_from_str_flags ("some-non-exists-dir", VPF_NO_CANON);
102 fail_if (mc_chdir(vpath) == -1);
103 vfs_path_free (vpath);
105 END_TEST
107 /* --------------------------------------------------------------------------------------------- */
109 /* Relative to panel_correct_path_to_show() */
111 START_TEST (test_vpath_to_str_filter)
113 vfs_path_t *vpath, *last_vpath;
114 char *filtered_path;
115 const vfs_path_element_t *path_element;
117 vpath = vfs_path_from_str ("/test1://some.host/dir");
118 path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1));
119 vfs_path_free (vpath);
121 last_vpath = vfs_path_new ();
122 last_vpath->relative = TRUE;
124 vfs_path_add_element (last_vpath, path_element);
126 filtered_path = vfs_path_to_str_flags (last_vpath, 0,
127 VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
128 vfs_path_free (last_vpath);
130 fail_unless (strcmp("test1://some.host/dir", filtered_path) == 0, "actual: %s", filtered_path);
131 g_free (filtered_path);
134 END_TEST
136 /* --------------------------------------------------------------------------------------------- */
139 main (void)
141 int number_failed;
143 Suite *s = suite_create (TEST_SUITE_NAME);
144 TCase *tc_core = tcase_create ("Core");
145 SRunner *sr;
147 tcase_add_checked_fixture (tc_core, setup, teardown);
149 /* Add new tests here: *************** */
150 tcase_add_test (tc_core, test_relative_cd);
151 tcase_add_test (tc_core, test_vpath_to_str_filter);
152 /* *********************************** */
154 suite_add_tcase (s, tc_core);
155 sr = srunner_create (s);
156 srunner_set_log (sr, "relative_cd.log");
157 srunner_run_all (sr, CK_NORMAL);
158 number_failed = srunner_ntests_failed (sr);
159 srunner_free (sr);
160 return (number_failed == 0) ? 0 : 1;
163 /* --------------------------------------------------------------------------------------------- */