exec_get_export_variables(): reproduce bug in test
[midnight-commander.git] / tests / src / filemanager / exec_get_export_variables_ext.c
blob44d07c449a82b2b9b48ba6c3299f14884e98fe41
1 /*
2 src/filemanager - filemanager functions
4 Copyright (C) 2011
5 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 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 "lib/global.h"
33 #include "src/vfs/local/local.c"
35 #include "src/filemanager/midnight.c"
37 #include "src/filemanager/ext.c"
39 /* --------------------------------------------------------------------------------------------- */
40 /* mocked functions */
43 /* --------------------------------------------------------------------------------------------- */
45 static void
46 setup (void)
48 str_init_strings (NULL);
50 vfs_init ();
51 init_localfs ();
52 vfs_setup_work_dir ();
54 mc_global.mc_run_mode = MC_RUN_FULL;
55 current_panel = g_new0(struct WPanel, 1);
56 current_panel->cwd_vpath = vfs_path_from_str("/home");
57 current_panel->dir.list = g_new (file_entry, MIN_FILES);
58 current_panel->dir.size = MIN_FILES;
61 static void
62 teardown (void)
64 vfs_shut ();
65 str_uninit_strings ();
68 /* --------------------------------------------------------------------------------------------- */
70 START_TEST (sanitize_variables)
72 // given
73 vfs_path_t * filename_vpath;
74 char *actual_string;
75 const char *expected_string;
77 current_panel->selected = 0;
78 current_panel->dir.list[0].fname = (char*) "selected file.txt";
79 current_panel->dir.list[1].fname = (char*) "tagged file1.txt";
80 current_panel->dir.list[1].f.marked = TRUE;
81 current_panel->dir.list[2].fname = (char*) "tagged file2.txt";
82 current_panel->dir.list[2].f.marked = TRUE;
83 current_panel->count = 3;
85 // when
86 filename_vpath = vfs_path_from_str("/tmp/blabla.txt");
87 actual_string = exec_get_export_variables (filename_vpath);
88 vfs_path_free (filename_vpath);
90 // then
91 expected_string = "\
92 MC_EXT_FILENAME=/tmp/blabla.txt\n\
93 export MC_EXT_FILENAME\n\
94 MC_EXT_BASENAME=selected\\ file.txt\n\
95 export MC_EXT_BASENAME\n\
96 MC_EXT_CURRENTDIR=/home\n\
97 export MC_EXT_CURRENTDIR\n\
98 MC_EXT_SELECTED=selected\\ file.txt\n\
99 export MC_EXT_SELECTED\n\
100 MC_EXT_ONLYTAGGED=\"tagged\\ file1.txt tagged\\ file2.txt \"\n\
101 export MC_EXT_ONLYTAGGED\n";
103 g_assert_cmpstr (actual_string, ==, expected_string);
105 g_free (actual_string);
108 END_TEST
110 /* --------------------------------------------------------------------------------------------- */
113 main (void)
115 int number_failed;
117 Suite *s = suite_create (TEST_SUITE_NAME);
118 TCase *tc_core = tcase_create ("Core");
119 SRunner *sr;
121 tcase_add_checked_fixture (tc_core, setup, teardown);
123 /* Add new tests here: *************** */
124 tcase_add_test (tc_core, sanitize_variables);
125 /* *********************************** */
127 suite_add_tcase (s, tc_core);
128 sr = srunner_create (s);
129 srunner_set_log (sr, "do_panel_cd.log");
130 srunner_run_all (sr, CK_NORMAL);
131 number_failed = srunner_ntests_failed (sr);
132 srunner_free (sr);
133 return (number_failed == 0) ? 0 : 1;
136 /* --------------------------------------------------------------------------------------------- */