Ticket #2758: cd command not working in shell link
[midnight-commander.git] / tests / lib / vfs / current_dir.c
blobb56061cbfc3472e274d12cd43f7a4a15ffd9e438
1 /*
2 lib/vfs - manipulate with current directory
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/xdirentry.h"
36 #include "src/vfs/local/local.c"
38 static void
39 setup (void)
41 str_init_strings (NULL);
43 vfs_init ();
44 init_localfs ();
45 vfs_setup_work_dir ();
48 static void
49 teardown (void)
51 vfs_shut ();
52 str_uninit_strings ();
55 static int
56 test_chdir (const vfs_path_t * vpath)
58 #if 0
59 char *path = vfs_path_to_str (vpath);
60 printf ("test_chdir: %s\n", path);
61 g_free (path);
62 #else
63 (void) vpath;
64 #endif
65 return 0;
68 /* --------------------------------------------------------------------------------------------- */
70 #define cd_and_check( cd_dir, etalon ) \
71 vpath = vfs_path_from_str (cd_dir); \
72 mc_chdir(vpath); \
73 vfs_path_free (vpath); \
74 buffer = _vfs_get_cwd (); \
75 fail_unless( \
76 strcmp(etalon, buffer) == 0, \
77 "\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer); \
78 g_free (buffer);
80 START_TEST (set_up_current_dir_url)
82 vfs_path_t *vpath;
83 static struct vfs_s_subclass test_subclass;
84 static struct vfs_class vfs_test_ops;
85 char *buffer;
87 vfs_s_init_class (&vfs_test_ops, &test_subclass);
89 vfs_test_ops.name = "testfs";
90 vfs_test_ops.flags = VFSF_NOLINKS;
91 vfs_test_ops.prefix = "test";
92 vfs_test_ops.chdir = test_chdir;
94 vfs_register_class (&vfs_test_ops);
96 cd_and_check ("/dev/some.file/test://", "/dev/some.file/test://");
98 cd_and_check ("/dev/some.file/test://bla-bla", "/dev/some.file/test://bla-bla");
100 cd_and_check ("..", "/dev/some.file/test://");
102 cd_and_check ("..", "/dev");
104 cd_and_check ("..", "/");
106 cd_and_check ("..", "/");
108 test_subclass.flags = VFS_S_REMOTE;
110 cd_and_check ("/test://user:pass@host.net/path", "/test://user:pass@host.net/path");
111 cd_and_check ("..", "/test://user:pass@host.net");
113 cd_and_check ("..", "/");
117 END_TEST
119 /* --------------------------------------------------------------------------------------------- */
122 main (void)
124 int number_failed;
126 Suite *s = suite_create (TEST_SUITE_NAME);
127 TCase *tc_core = tcase_create ("Core");
128 SRunner *sr;
130 tcase_add_checked_fixture (tc_core, setup, teardown);
132 /* Add new tests here: *************** */
133 tcase_add_test (tc_core, set_up_current_dir_url);
134 /* *********************************** */
136 suite_add_tcase (s, tc_core);
137 sr = srunner_create (s);
138 srunner_set_log (sr, "current_dir.log");
139 srunner_run_all (sr, CK_NORMAL);
140 number_failed = srunner_ntests_failed (sr);
141 srunner_free (sr);
142 return (number_failed == 0) ? 0 : 1;
145 /* --------------------------------------------------------------------------------------------- */