Added tests for examine_cd() function.
[midnight-commander.git] / tests / src / filemanager / examine_cd.c
blob4e758f8ab3e59a9e32ad17220a3bb3e6cd77eddc
1 /*
2 src/filemanager - examine_cd() function testing
4 Copyright (C) 2012
5 The Free Software Foundation, Inc.
7 Written by:
8 Andrew Borodin <aborodin@vmail.ru>, 2012
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 "/src/filemanager"
28 #include <config.h>
30 #include <check.h>
32 #include <stdio.h>
34 #include "src/filemanager/layout.h"
35 #include "src/filemanager/midnight.h"
36 #include "src/filemanager/tree.h"
37 #ifdef HAVE_SUBSHELL_SUPPORT
38 #include "src/subshell.h"
39 #endif /* HAVE_SUBSHELL_SUPPORT */
41 #include "src/filemanager/command.c"
43 /* --------------------------------------------------------------------------------------------- */
45 gboolean command_prompt = FALSE;
46 #ifdef HAVE_SUBSHELL_SUPPORT
47 enum subshell_state_enum subshell_state = INACTIVE;
48 #endif /* HAVE_SUBSHELL_SUPPORT */
49 int quit = 0;
50 WPanel *current_panel = NULL;
52 panel_view_mode_t
53 get_current_type (void)
55 return view_listing;
58 gboolean
59 do_cd (const char *new_dir, enum cd_enum cd_type)
61 (void) new_dir;
62 (void) cd_type;
64 return TRUE;
67 gboolean
68 quiet_quit_cmd (void)
70 return FALSE;
73 char *
74 expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
76 (void) edit_widget;
77 (void) c;
78 (void) do_quote;
80 return NULL;
83 #ifdef HAVE_SUBSHELL_SUPPORT
84 void
85 init_subshell (void)
89 gboolean
90 do_load_prompt (void)
92 return TRUE;
94 #endif /* HAVE_SUBSHELL_SUPPORT */
96 void
97 shell_execute (const char *command, int flags)
99 (void) command;
100 (void) flags;
103 void
104 sync_tree (const char *pathname)
106 (void) pathname;
109 /* --------------------------------------------------------------------------------------------- */
111 static void
112 setup (void)
116 static void
117 teardown (void)
121 /* --------------------------------------------------------------------------------------------- */
122 #define check_examine_cd(input, etalon) \
124 result = examine_cd (input); \
125 fail_unless (strcmp (result, etalon) == 0, \
126 "\ninput (%s)\nactial (%s) not equal to\netalon (%s)", input, result, etalon); \
127 g_free (result); \
130 START_TEST (test_examine_cd)
132 char *result;
134 g_setenv ("AAA", "aaa", TRUE);
136 check_examine_cd ("/test/path", "/test/path");
138 check_examine_cd ("/test/path/$AAA", "/test/path/aaa");
139 check_examine_cd ("/test/path/$AAA/test2", "/test/path/aaa/test2");
140 check_examine_cd ("/test/path/test1$AAA/test2", "/test/path/test1aaa/test2");
142 check_examine_cd ("/test/path/${AAA}", "/test/path/aaa");
143 check_examine_cd ("/test/path/${AAA}/test2", "/test/path/aaa/test2");
144 check_examine_cd ("/test/path/${AAA}test2", "/test/path/aaatest2");
145 check_examine_cd ("/test/path/test1${AAA}", "/test/path/test1aaa");
146 check_examine_cd ("/test/path/test1${AAA}test2", "/test/path/test1aaatest2");
148 check_examine_cd ("/test/path/\\$AAA", "/test/path/$AAA");
149 check_examine_cd ("/test/path/\\$AAA/test2", "/test/path/$AAA/test2");
150 check_examine_cd ("/test/path/test1\\$AAA", "/test/path/test1$AAA");
152 check_examine_cd ("/test/path/\\${AAA}", "/test/path/${AAA}");
153 check_examine_cd ("/test/path/\\${AAA}/test2", "/test/path/${AAA}/test2");
154 check_examine_cd ("/test/path/\\${AAA}test2", "/test/path/${AAA}test2");
155 check_examine_cd ("/test/path/test1\\${AAA}test2", "/test/path/test1${AAA}test2");
157 END_TEST
159 /* --------------------------------------------------------------------------------------------- */
162 main (void)
164 int number_failed;
166 Suite *s = suite_create (TEST_SUITE_NAME);
167 TCase *tc_core = tcase_create ("Core");
168 SRunner *sr;
170 tcase_add_checked_fixture (tc_core, setup, teardown);
172 /* Add new tests here: *************** */
173 tcase_add_test (tc_core, test_examine_cd);
174 /* *********************************** */
176 suite_add_tcase (s, tc_core);
177 sr = srunner_create (s);
178 srunner_set_log (sr, "examine_cd.log");
179 srunner_run_all (sr, CK_NORMAL);
180 number_failed = srunner_ntests_failed (sr);
181 srunner_free (sr);
183 return (number_failed == 0) ? 0 : 1;
186 /* --------------------------------------------------------------------------------------------- */