mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Ticket #2883: non-portable test
Test has been rewritten for support actuality. Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
177f1dc5ba
commit
5e633c7ca1
@ -18,14 +18,14 @@ endif
|
||||
|
||||
|
||||
TESTS = \
|
||||
do_panel_cd \
|
||||
do_cd_command \
|
||||
examine_cd \
|
||||
exec_get_export_variables_ext
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
do_panel_cd_SOURCES = \
|
||||
do_panel_cd.c
|
||||
do_cd_command_SOURCES = \
|
||||
do_cd_command.c
|
||||
|
||||
examine_cd_SOURCES = \
|
||||
examine_cd.c
|
||||
|
189
tests/src/filemanager/do_cd_command.c
Normal file
189
tests/src/filemanager/do_cd_command.c
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
src/filemanager - tests for do_cd_command() function
|
||||
|
||||
Copyright (C) 2011
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Slava Zanko <slavazanko@gmail.com>, 2011
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander is free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
The Midnight Commander is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define TEST_SUITE_NAME "/src/filemanager"
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "src/vfs/local/local.c"
|
||||
|
||||
#include "src/filemanager/command.c"
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* @ThenReturnValue */
|
||||
static panel_view_mode_t get_current_type__return_value;
|
||||
|
||||
/* @Mock */
|
||||
panel_view_mode_t
|
||||
get_current_type (void)
|
||||
{
|
||||
return get_current_type__return_value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* @CapturedValue */
|
||||
static vfs_path_t *do_cd__new_dir_vpath__captured;
|
||||
/* @CapturedValue */
|
||||
static enum cd_enum do_cd__cd_type__captured;
|
||||
/* @ThenReturnValue */
|
||||
static gboolean do_cd__return_value;
|
||||
|
||||
/* @Mock */
|
||||
gboolean
|
||||
do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type)
|
||||
{
|
||||
do_cd__new_dir_vpath__captured = vfs_path_clone (new_dir_vpath);
|
||||
do_cd__cd_type__captured = cd_type;
|
||||
return do_cd__return_value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* @ThenReturnValue */
|
||||
static const char *mc_config_get_home_dir__return_value;
|
||||
|
||||
/* @Mock */
|
||||
const char *
|
||||
mc_config_get_home_dir (void)
|
||||
{
|
||||
return mc_config_get_home_dir__return_value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* @Before */
|
||||
static void
|
||||
setup (void)
|
||||
{
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
init_localfs ();
|
||||
vfs_setup_work_dir ();
|
||||
do_cd__new_dir_vpath__captured = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* @After */
|
||||
static void
|
||||
teardown (void)
|
||||
{
|
||||
vfs_path_free (do_cd__new_dir_vpath__captured);
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* @DataSource("test_empty_mean_home_ds") */
|
||||
/* *INDENT-OFF* */
|
||||
static const struct test_empty_mean_home_ds
|
||||
{
|
||||
const char *command;
|
||||
} test_empty_mean_home_ds[] =
|
||||
{
|
||||
{
|
||||
"cd"
|
||||
},
|
||||
{
|
||||
"cd "
|
||||
},
|
||||
{
|
||||
"cd\t\t\t\t\t\t\t\t\t\t\t"
|
||||
},
|
||||
{
|
||||
"cd \t \t \t\t \t "
|
||||
},
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* @Test(dataSource = "test_empty_mean_home_ds") */
|
||||
/* *INDENT-OFF* */
|
||||
START_TEST (test_empty_mean_home)
|
||||
/* *INDENT-ON* */
|
||||
{
|
||||
/* given */
|
||||
|
||||
get_current_type__return_value = view_listing;
|
||||
do_cd__return_value = TRUE;
|
||||
mc_config_get_home_dir__return_value = "/home/test";
|
||||
|
||||
/* when */
|
||||
{
|
||||
char *input_command;
|
||||
|
||||
input_command = g_strdup (test_empty_mean_home_ds[_i].command);
|
||||
do_cd_command (input_command);
|
||||
g_free (input_command);
|
||||
}
|
||||
/* then */
|
||||
{
|
||||
char *actual_path;
|
||||
|
||||
actual_path = vfs_path_to_str (do_cd__new_dir_vpath__captured);
|
||||
g_assert_cmpstr (mc_config_get_home_dir__return_value, ==, actual_path);
|
||||
g_free (actual_path);
|
||||
}
|
||||
ck_assert_int_eq (do_cd__cd_type__captured, cd_parse_command);
|
||||
}
|
||||
/* *INDENT-OFF* */
|
||||
END_TEST
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int number_failed;
|
||||
|
||||
Suite *s = suite_create (TEST_SUITE_NAME);
|
||||
TCase *tc_core = tcase_create ("Core");
|
||||
SRunner *sr;
|
||||
|
||||
tcase_add_checked_fixture (tc_core, setup, teardown);
|
||||
|
||||
/* Add new tests here: *************** */
|
||||
tcase_add_loop_test (tc_core, test_empty_mean_home, 0,
|
||||
sizeof (test_empty_mean_home_ds) / sizeof (test_empty_mean_home_ds[0]));
|
||||
/* *********************************** */
|
||||
|
||||
suite_add_tcase (s, tc_core);
|
||||
sr = srunner_create (s);
|
||||
srunner_set_log (sr, "do_cd_command.log");
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
return (number_failed == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
@ -1,166 +0,0 @@
|
||||
/*
|
||||
lib/vfs - manipulate with current directory
|
||||
|
||||
Copyright (C) 2011
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Slava Zanko <slavazanko@gmail.com>, 2011
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander is free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
The Midnight Commander is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define TEST_SUITE_NAME "/src/filemanager"
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "src/vfs/local/local.c"
|
||||
|
||||
#include "src/filemanager/panel.c"
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* mocked functions */
|
||||
#ifdef ENABLE_SUBSHELL
|
||||
void
|
||||
do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean reset_prompt)
|
||||
{
|
||||
(void) vpath;
|
||||
(void) update_prompt;
|
||||
(void) reset_prompt;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
do_load_dir (const vfs_path_t *vpath, dir_list * list, sortfn * sort, gboolean reverse,
|
||||
gboolean case_sensitive, gboolean exec_ff, const char *fltr)
|
||||
{
|
||||
(void) vpath;
|
||||
(void) list;
|
||||
(void) sort;
|
||||
(void) reverse;
|
||||
(void) case_sensitive;
|
||||
(void) exec_ff;
|
||||
(void) fltr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
load_hint (gboolean force)
|
||||
{
|
||||
(void) force;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
setup (void)
|
||||
{
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
init_localfs ();
|
||||
vfs_setup_work_dir ();
|
||||
}
|
||||
|
||||
static void
|
||||
teardown (void)
|
||||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
START_TEST (test_do_panel_cd_empty_mean_home)
|
||||
{
|
||||
char *cwd;
|
||||
char *home_wd;
|
||||
const char *home_directory;
|
||||
struct WPanel *panel;
|
||||
gboolean ret;
|
||||
vfs_path_t *empty_path;
|
||||
|
||||
cmdline = command_new (0, 0, 0);
|
||||
|
||||
panel = g_new0(struct WPanel, 1);
|
||||
panel->cwd_vpath = vfs_path_from_str("/home");
|
||||
panel->lwd_vpath = vfs_path_from_str("/");
|
||||
panel->sort_info.sort_field = g_new0(panel_field_t,1);
|
||||
|
||||
home_directory = mc_config_get_home_dir();
|
||||
if (home_directory == NULL)
|
||||
home_directory = "/home/test";
|
||||
|
||||
empty_path = vfs_path_from_str (home_directory);
|
||||
|
||||
/*
|
||||
* normalize path to handle HOME with trailing slashes:
|
||||
* HOME=/home/slyfox///////// ./do_panel_cd
|
||||
*/
|
||||
home_wd = vfs_path_to_str (empty_path);
|
||||
ret = do_panel_cd (panel, empty_path, cd_parse_command);
|
||||
vfs_path_free (empty_path);
|
||||
|
||||
fail_unless(ret);
|
||||
cwd = vfs_path_to_str (panel->cwd_vpath);
|
||||
|
||||
printf ("mc_config_get_home_dir ()=%s\n", mc_config_get_home_dir ());
|
||||
printf ("cwd=%s\n", cwd);
|
||||
printf ("home_wd=%s\n", home_wd);
|
||||
fail_unless(strcmp(cwd, home_wd) == 0);
|
||||
|
||||
g_free (cwd);
|
||||
g_free (home_wd);
|
||||
vfs_path_free (panel->cwd_vpath);
|
||||
vfs_path_free (panel->lwd_vpath);
|
||||
g_free ((gpointer) panel->sort_info.sort_field);
|
||||
g_free (panel);
|
||||
}
|
||||
|
||||
END_TEST
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int number_failed;
|
||||
|
||||
Suite *s = suite_create (TEST_SUITE_NAME);
|
||||
TCase *tc_core = tcase_create ("Core");
|
||||
SRunner *sr;
|
||||
|
||||
tcase_add_checked_fixture (tc_core, setup, teardown);
|
||||
|
||||
/* Add new tests here: *************** */
|
||||
tcase_add_test (tc_core, test_do_panel_cd_empty_mean_home);
|
||||
/* *********************************** */
|
||||
|
||||
suite_add_tcase (s, tc_core);
|
||||
sr = srunner_create (s);
|
||||
srunner_set_log (sr, "do_panel_cd.log");
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
return (number_failed == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
Loading…
Reference in New Issue
Block a user