From 9a7750ca2faf04c47206362add1c3674065c49ca Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 5 Jan 2012 15:46:53 +0300 Subject: [PATCH] Added unit test for do_panel_cd() functions. Check if empty directory is mean 'change current directory to home dir'. Signed-off-by: Slava Zanko --- tests/src/filemanager/Makefile.am | 12 +- tests/src/filemanager/do_panel_cd.c | 114 ++++++++ tests/src/filemanager/do_panel_cd_stub_env.c | 397 +++++++++++++++++++++++++++ 3 files changed, 520 insertions(+), 3 deletions(-) create mode 100644 tests/src/filemanager/do_panel_cd.c create mode 100644 tests/src/filemanager/do_panel_cd_stub_env.c diff --git a/tests/src/filemanager/Makefile.am b/tests/src/filemanager/Makefile.am index 0fafa1c19..f0edfce69 100644 --- a/tests/src/filemanager/Makefile.am +++ b/tests/src/filemanager/Makefile.am @@ -1,10 +1,16 @@ -AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@ -LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la +AM_CFLAGS = -I$(top_srcdir)/lib/vfs $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@ + +AM_LDFLAGS = -Wl,-z,muldefs + +LIBS=@CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la TESTS = \ + do_panel_cd \ examine_cd check_PROGRAMS = $(TESTS) -examine_cd_SOURCES = \ +do_panel_cd_SOURCES = \ + do_panel_cd.c \ examine_cd.c diff --git a/tests/src/filemanager/do_panel_cd.c b/tests/src/filemanager/do_panel_cd.c new file mode 100644 index 000000000..ca6b85cf8 --- /dev/null +++ b/tests/src/filemanager/do_panel_cd.c @@ -0,0 +1,114 @@ +/* + lib/vfs - manipulate with current directory + + Copyright (C) 2011 + The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 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 . +*/ + +#define TEST_SUITE_NAME "/src/filemanager" + +#include + +#include + +#include "lib/global.h" +#include "src/main.h" +#include "src/vfs/local/local.c" + +#include "src/filemanager/panel.c" + +#include "do_panel_cd_stub_env.c" + +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; + struct WPanel *panel; + gboolean ret; + + + 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); + + ret = do_panel_cd (panel, "", cd_parse_command); + + fail_unless(ret); + cwd = vfs_path_to_str (panel->cwd_vpath); + fail_unless(strcmp(cwd, mc_config_get_home_dir ()) == 0); + + + 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; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/filemanager/do_panel_cd_stub_env.c b/tests/src/filemanager/do_panel_cd_stub_env.c new file mode 100644 index 000000000..f12f27b89 --- /dev/null +++ b/tests/src/filemanager/do_panel_cd_stub_env.c @@ -0,0 +1,397 @@ +#include "src/subshell.h" +#include "src/setup.h" + + +panels_options_t panels_options; +struct mc_fhl_struct *mc_filehighlight; +int confirm_execute = 0; +int auto_save_setup = 0; +int free_space = 0; +int horizontal_split = 0; +int first_panel_size = 0; +int default_source_codepage = 0; +int menubar_visible = 1; +WPanel *current_panel; +WInput *cmdline; +WMenuBar *the_menubar; +const global_keymap_t *panel_map; +gboolean command_prompt; +int saving_setup; + +panels_layout_t panels_layout = { + .horizontal_split = 0, + .vertical_equal = 1, + .left_panel_size = 0, + .horizontal_equal = 1, + .top_panel_size = 0 +}; + +WInput * +command_new (int y, int x, int cols) +{ + WInput *cmd; + const input_colors_t command_colors = { + DEFAULT_COLOR, + COMMAND_MARK_COLOR, + DEFAULT_COLOR, + COMMAND_HISTORY_COLOR + }; + + cmd = input_new (y, x, (int *) command_colors, cols, "", "cmdline", + INPUT_COMPLETE_DEFAULT | INPUT_COMPLETE_CD | INPUT_COMPLETE_COMMANDS | + INPUT_COMPLETE_SHELL_ESC); + + /* Add our hooks */ + cmd->widget.callback = NULL; + + return cmd; +} + +int +do_cd (const char *new_dir, enum cd_enum exact) +{ + (void) new_dir; + (void) exact; + + return 0; +} + +void +do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean reset_prompt) +{ + (void) vpath; + (void) update_prompt; + (void) reset_prompt; +} + +void +shell_execute (const char *command, int flags) +{ + (void) command; + (void) flags; +} + +void +panel_load_setup (WPanel * panel, const char *section) +{ + (void) panel; + (void) section; +} + +void +panel_save_setup (WPanel * panel, const char *section) +{ + (void) panel; + (void) section; +} + +void +free_my_statfs (void) +{ + +} + +int +select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay) +{ + (void) center_y; + (void) center_x; + (void) current_charset; + (void) seldisplay; + + return 0; +} + +void +update_xterm_title_path (void) +{ +} + +void +init_my_statfs (void) +{ +} +void +my_statfs (struct my_statfs *myfs_stats, const char *path) +{ + (void) myfs_stats; + (void) path; +} + +void +clean_dir (dir_list * list, int count) +{ + (void) list; + (void) count; + +} + +struct Widget * +get_panel_widget (int idx) +{ + (void) idx; + + return NULL; +} + + +int +do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean reverse, + gboolean case_sensitive, gboolean exec_ff, const char *fltr) +{ + (void) path; + (void) list; + (void) sort; + (void) reverse; + (void) case_sensitive; + (void) exec_ff; + (void) fltr; + + return 0; +} + +int +do_reload_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, int count, + gboolean reverse, gboolean case_sensitive, gboolean exec_ff, const char *fltr) +{ + (void) vpath; + (void) list; + (void) sort; + (void) count; + (void) reverse; + (void) case_sensitive; + (void) exec_ff; + (void) fltr; + + return 0; + +} + +void +do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse, + gboolean case_sensitive, gboolean exec_ff) +{ + (void) list; + (void) sort; + (void) top; + (void) reverse; + (void) case_sensitive; + (void) exec_ff; +} + +int +regex_command (const char *filename, const char *action, int *move_dir) +{ + (void) filename; + (void) action; + (void) move_dir; + + return 0; +} + +gboolean +if_link_is_exe (const char *full_name, const file_entry * file) +{ + (void) full_name; + (void) file; + + return TRUE; +} + +void +change_panel (void) +{ +} + +gboolean +set_zero_dir (dir_list * list) +{ + (void) list; + + return TRUE; +} + +void +load_hint (gboolean force) +{ + (void) force; +} + +panel_view_mode_t +get_display_type (int idx) +{ + (void) idx; + return view_listing; +} + +panel_view_mode_t +get_current_type (void) +{ + return view_listing; +} + +panel_view_mode_t +get_other_type (void) +{ + return view_listing; +} + +int +get_current_index (void) +{ + return 0; +} + +int +get_other_index (void) +{ + return 1; +} + +int +unsorted (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_name (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_vers (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_ext (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_time (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_atime (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_ctime (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_size (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +int +sort_inode (file_entry * a, file_entry * b) +{ + (void) a; + (void) b; + + return 0; +} + +void +set_display_type (int num, panel_view_mode_t type) +{ + (void) num; + (void) type; +} + +void +copy_cmd_local (void) +{ +} + +void +delete_cmd_local (void) +{ +} + +void +view_raw_cmd (void) +{ +} + +void +edit_cmd_new (void) +{ +} + +void +rename_cmd_local (void) +{ +} + +void +select_invert_cmd (void) +{ +} + +void +unselect_cmd (void) +{ +} + +void +select_cmd (void) +{ +} + +struct WPanel * +get_other_panel (void) +{ + return NULL; +} + +const panel_field_t * +sort_box (panel_sort_info_t * info) +{ + (void) info; + + return NULL; +} + +void +midnight_set_buttonbar (WButtonBar * b) +{ + (void) b; +} -- 2.11.4.GIT