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

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