Code refactoring in tests.
[midnight-commander.git] / tests / lib / vfs / current_dir.c
blobfe35203d029e8bf498722b13f4411162fe9b40d8
1 /*
2 lib/vfs - manipulate with current directory
4 Copyright (C) 2011, 2013
5 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
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 "tests/mctest.h"
30 #include "lib/global.h"
31 #include "lib/strutil.h"
32 #include "lib/vfs/xdirentry.h"
34 #include "src/vfs/local/local.c"
36 static void
37 setup (void)
39 str_init_strings (NULL);
41 vfs_init ();
42 init_localfs ();
43 vfs_setup_work_dir ();
46 static void
47 teardown (void)
49 vfs_shut ();
50 str_uninit_strings ();
53 static int
54 test_chdir (const vfs_path_t * vpath)
56 #if 0
57 char *path = vfs_path_to_str (vpath);
58 printf ("test_chdir: %s\n", path);
59 g_free (path);
60 #else
61 (void) vpath;
62 #endif
63 return 0;
66 /* --------------------------------------------------------------------------------------------- */
68 #define cd_and_check( cd_dir, etalon ) \
69 vpath = vfs_path_from_str (cd_dir); \
70 mc_chdir(vpath); \
71 vfs_path_free (vpath); \
72 buffer = _vfs_get_cwd (); \
73 fail_unless( \
74 strcmp(etalon, buffer) == 0, \
75 "\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer); \
76 g_free (buffer);
78 /* *INDENT-OFF* */
79 START_TEST (set_up_current_dir_url)
80 /* *INDENT-ON* */
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 ("..", "/");
116 /* *INDENT-OFF* */
117 END_TEST
118 /* *INDENT-ON* */
120 /* --------------------------------------------------------------------------------------------- */
123 main (void)
125 int number_failed;
127 Suite *s = suite_create (TEST_SUITE_NAME);
128 TCase *tc_core = tcase_create ("Core");
129 SRunner *sr;
131 tcase_add_checked_fixture (tc_core, setup, teardown);
133 /* Add new tests here: *************** */
134 tcase_add_test (tc_core, set_up_current_dir_url);
135 /* *********************************** */
137 suite_add_tcase (s, tc_core);
138 sr = srunner_create (s);
139 srunner_set_log (sr, "current_dir.log");
140 srunner_run_all (sr, CK_NORMAL);
141 number_failed = srunner_ntests_failed (sr);
142 srunner_free (sr);
143 return (number_failed == 0) ? 0 : 1;
146 /* --------------------------------------------------------------------------------------------- */