root/tests/src/filemanager/exec_get_export_variables_ext.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_TEST
  4. main

   1 /*
   2    src/filemanager - filemanager functions
   3 
   4    Copyright (C) 2011-2019
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   9 
  10    This file is part of the Midnight Commander.
  11 
  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.
  16 
  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.
  21 
  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/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/src/filemanager"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "src/vfs/local/local.c"
  31 
  32 #include "src/filemanager/midnight.c"
  33 
  34 #include "src/filemanager/ext.c"
  35 
  36 /* --------------------------------------------------------------------------------------------- */
  37 /* mocked functions */
  38 
  39 
  40 /* --------------------------------------------------------------------------------------------- */
  41 
  42 static void
  43 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     str_init_strings (NULL);
  46 
  47     vfs_init ();
  48     vfs_init_localfs ();
  49     vfs_setup_work_dir ();
  50 
  51     mc_global.mc_run_mode = MC_RUN_FULL;
  52     current_panel = g_new0 (WPanel, 1);
  53     current_panel->cwd_vpath = vfs_path_from_str ("/home");
  54     current_panel->dir.size = DIR_LIST_MIN_SIZE;
  55     current_panel->dir.list = g_new0 (file_entry_t, current_panel->dir.size);
  56     current_panel->dir.len = 0;
  57 }
  58 
  59 static void
  60 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  61 {
  62     vfs_shut ();
  63     str_uninit_strings ();
  64 }
  65 
  66 /* --------------------------------------------------------------------------------------------- */
  67 
  68 /* *INDENT-OFF* */
  69 START_TEST (sanitize_variables)
     /* [previous][next][first][last][top][bottom][index][help]  */
  70 /* *INDENT-ON* */
  71 {
  72     /* given */
  73     vfs_path_t *filename_vpath;
  74     char *actual_string;
  75     const char *expected_string;
  76 
  77     current_panel->selected = 0;
  78     current_panel->dir.len = 3;
  79     current_panel->dir.list[0].fname = (char *) "selected file.txt";
  80     current_panel->dir.list[1].fname = (char *) "tagged file1.txt";
  81     current_panel->dir.list[1].f.marked = TRUE;
  82     current_panel->dir.list[2].fname = (char *) "tagged file2.txt";
  83     current_panel->dir.list[2].f.marked = TRUE;
  84 
  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);
  89 
  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";
 102 
 103     mctest_assert_str_eq (actual_string, expected_string);
 104 
 105     g_free (actual_string);
 106 }
 107 /* *INDENT-OFF* */
 108 END_TEST
 109 /* *INDENT-ON* */
 110 
 111 /* --------------------------------------------------------------------------------------------- */
 112 
 113 int
 114 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 115 {
 116     int number_failed;
 117 
 118     Suite *s = suite_create (TEST_SUITE_NAME);
 119     TCase *tc_core = tcase_create ("Core");
 120     SRunner *sr;
 121 
 122     tcase_add_checked_fixture (tc_core, setup, teardown);
 123 
 124     /* Add new tests here: *************** */
 125     tcase_add_test (tc_core, sanitize_variables);
 126     /* *********************************** */
 127 
 128     suite_add_tcase (s, tc_core);
 129     sr = srunner_create (s);
 130     srunner_set_log (sr, "exec_get_export_variables_ext.log");
 131     srunner_run_all (sr, CK_ENV);
 132     number_failed = srunner_ntests_failed (sr);
 133     srunner_free (sr);
 134     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 135 }
 136 
 137 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */