root/tests/lib/vfs/current_dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. test_chdir
  2. setup
  3. teardown
  4. START_PARAMETRIZED_TEST
  5. main

   1 /*
   2    lib/vfs - manipulate with current directory
   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 "/lib/vfs"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/global.h"
  31 #include "lib/strutil.h"
  32 #include "lib/vfs/xdirentry.h"
  33 
  34 #include "src/vfs/local/local.c"
  35 
  36 static struct vfs_class vfs_test_ops;
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 
  40 /* @Mock */
  41 static int
  42 test_chdir (const vfs_path_t * vpath)
     /* [previous][next][first][last][top][bottom][index][help]  */
  43 {
  44     (void) vpath;
  45 
  46     return 0;
  47 }
  48 
  49 /* --------------------------------------------------------------------------------------------- */
  50 
  51 /* @Before */
  52 static void
  53 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  54 {
  55     str_init_strings (NULL);
  56 
  57     vfs_init ();
  58     init_localfs ();
  59     vfs_setup_work_dir ();
  60 
  61     vfs_init_class (&vfs_test_ops, "testfs", VFS_UNKNOWN, "test");
  62     vfs_test_ops.chdir = test_chdir;
  63 }
  64 
  65 /* --------------------------------------------------------------------------------------------- */
  66 
  67 /* @After */
  68 static void
  69 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  70 {
  71     vfs_shut ();
  72     str_uninit_strings ();
  73 }
  74 
  75 /* --------------------------------------------------------------------------------------------- */
  76 
  77 /* @DataSource("test_cd_ds") */
  78 /* *INDENT-OFF* */
  79 static const struct test_cd_ds
  80 {
  81     const char *input_initial_path;
  82     const char *input_cd_path;
  83     const vfs_flags_t input_class_flags;
  84 
  85     const char *expected_cd_path;
  86 } test_cd_ds[] =
  87 {
  88     { /* 0. */
  89         "/",
  90         "/dev/some.file/test://",
  91         VFS_NOLINKS,
  92         "/dev/some.file/test://"
  93     },
  94     { /* 1. */
  95         "/",
  96         "/dev/some.file/test://bla-bla",
  97         VFS_NOLINKS,
  98         "/dev/some.file/test://bla-bla"
  99     },
 100     { /* 2. */
 101         "/dev/some.file/test://bla-bla",
 102         "..",
 103         VFS_NOLINKS,
 104         "/dev/some.file/test://"
 105     },
 106     { /* 3. */
 107         "/dev/some.file/test://",
 108         "..",
 109         VFS_NOLINKS,
 110         "/dev"
 111     },
 112     { /* 4. */
 113         "/dev",
 114         "..",
 115         VFS_NOLINKS,
 116         "/"
 117     },
 118     { /* 5. */
 119         "/",
 120         "..",
 121         VFS_NOLINKS,
 122         "/"
 123     },
 124     { /* 6. */
 125         "/",
 126         "/test://user:pass@host.net/path",
 127         VFS_NOLINKS | VFS_REMOTE,
 128         "/test://user:pass@host.net/path"
 129     },
 130     { /* 7. */
 131         "/test://user:pass@host.net/path",
 132         "..",
 133         VFS_NOLINKS | VFS_REMOTE,
 134         "/test://user:pass@host.net/"
 135     },
 136     { /* 8. */
 137         "/test://user:pass@host.net/",
 138         "..",
 139         VFS_NOLINKS | VFS_REMOTE,
 140         "/"
 141     },
 142 };
 143 /* *INDENT-ON* */
 144 
 145 /* @Test(dataSource = "test_cd_ds") */
 146 /* *INDENT-OFF* */
 147 START_PARAMETRIZED_TEST (test_cd, test_cd_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 148 /* *INDENT-ON* */
 149 {
 150     /* given */
 151     vfs_path_t *vpath;
 152 
 153     vfs_test_ops.flags = data->input_class_flags;
 154     vfs_register_class (&vfs_test_ops);
 155 
 156     vfs_set_raw_current_dir (vfs_path_from_str (data->input_initial_path));
 157 
 158     vpath = vfs_path_from_str (data->input_cd_path);
 159 
 160     /* when */
 161     mc_chdir (vpath);
 162 
 163     /* then */
 164     {
 165         char *actual_cd_path;
 166 
 167         actual_cd_path = _vfs_get_cwd ();
 168         mctest_assert_str_eq (actual_cd_path, data->expected_cd_path);
 169         g_free (actual_cd_path);
 170     }
 171     vfs_path_free (vpath);
 172 
 173     vfs_unregister_class (&vfs_test_ops);
 174 }
 175 /* *INDENT-OFF* */
 176 END_PARAMETRIZED_TEST
 177 /* *INDENT-ON* */
 178 
 179 /* --------------------------------------------------------------------------------------------- */
 180 
 181 int
 182 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 183 {
 184     int number_failed;
 185     char *cwd;
 186 
 187     Suite *s = suite_create (TEST_SUITE_NAME);
 188     TCase *tc_core = tcase_create ("Core");
 189     SRunner *sr;
 190 
 191     /* writable directory where check creates temporary files */
 192     cwd = g_get_current_dir ();
 193     g_setenv ("TEMP", cwd, TRUE);
 194     g_free (cwd);
 195 
 196     tcase_add_checked_fixture (tc_core, setup, teardown);
 197 
 198     /* Add new tests here: *************** */
 199     mctest_add_parameterized_test (tc_core, test_cd, test_cd_ds);
 200     /* *********************************** */
 201 
 202     suite_add_tcase (s, tc_core);
 203     sr = srunner_create (s);
 204     srunner_set_log (sr, "current_dir.log");
 205     srunner_run_all (sr, CK_ENV);
 206     number_failed = srunner_ntests_failed (sr);
 207     srunner_free (sr);
 208     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 209 }
 210 
 211 /* --------------------------------------------------------------------------------------------- */

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