Ticket #2758: cd command not working in shell link
[midnight-commander.git] / tests / lib / vfs / relative_cd.c
blobe8acec43c50e0c15d4be79e973b55aca823f7eff
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 (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);
106 /* --------------------------------------------------------------------------------------------- */
108 END_TEST
111 main (void)
113 int number_failed;
115 Suite *s = suite_create (TEST_SUITE_NAME);
116 TCase *tc_core = tcase_create ("Core");
117 SRunner *sr;
119 tcase_add_checked_fixture (tc_core, setup, teardown);
121 /* Add new tests here: *************** */
122 tcase_add_test (tc_core, relative_cd);
123 /* *********************************** */
125 suite_add_tcase (s, tc_core);
126 sr = srunner_create (s);
127 srunner_set_log (sr, "relative_cd.log");
128 srunner_run_all (sr, CK_NORMAL);
129 number_failed = srunner_ntests_failed (sr);
130 srunner_free (sr);
131 return (number_failed == 0) ? 0 : 1;
134 /* --------------------------------------------------------------------------------------------- */