root/tests/lib/vfs/vfs_s_get_path.c

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

DEFINITIONS

This source file includes following definitions.
  1. test1_mock_open_archive
  2. test1_mock_archive_same
  3. setup
  4. teardown
  5. vfs_die
  6. START_TEST
  7. main

   1 /*
   2    lib/vfs - test vfs_s_get_path() function
   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/strutil.h"
  31 #include "lib/vfs/direntry.c"   /* for testing static methods  */
  32 
  33 #include "src/vfs/local/local.c"
  34 
  35 #define ARCH_NAME "/path/to/some/file.ext"
  36 #define ETALON_PATH "path/to/test1_file.ext"
  37 #define ETALON_VFS_NAME "#test2:user:pass@host.net"
  38 #define ETALON_VFS_URL_NAME "test2://user:pass@host.net"
  39 
  40 struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
  41 static struct vfs_class *vfs_test_ops1 = VFS_CLASS (&test_subclass1);
  42 static struct vfs_class *vfs_test_ops2 = VFS_CLASS (&test_subclass2);
  43 static struct vfs_class *vfs_test_ops3 = VFS_CLASS (&test_subclass3);
  44 
  45 /* --------------------------------------------------------------------------------------------- */
  46 
  47 static int
  48 test1_mock_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath,
     /* [previous][next][first][last][top][bottom][index][help]  */
  49                          const vfs_path_element_t * vpath_element)
  50 {
  51     struct vfs_s_inode *root;
  52 
  53     mctest_assert_str_eq (vfs_path_as_str (vpath), "/" ETALON_VFS_URL_NAME ARCH_NAME);
  54 
  55     super->name = g_strdup (vfs_path_as_str (vpath));
  56     root = vfs_s_new_inode (vpath_element->class, super, NULL);
  57     super->root = root;
  58     return 0;
  59 }
  60 
  61 /* --------------------------------------------------------------------------------------------- */
  62 
  63 static int
  64 test1_mock_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *super,
     /* [previous][next][first][last][top][bottom][index][help]  */
  65                          const vfs_path_t * vpath, void *cookie)
  66 {
  67     const vfs_path_element_t *path_element;
  68 
  69     (void) vpath_element;
  70     (void) super;
  71     (void) cookie;
  72 
  73     path_element = vfs_path_get_by_index (vpath, -1);
  74     if (strcmp (ARCH_NAME, path_element->path) != 0)
  75         return 0;
  76     return 1;
  77 }
  78 
  79 /* --------------------------------------------------------------------------------------------- */
  80 
  81 /* @Before */
  82 static void
  83 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  84 {
  85     str_init_strings (NULL);
  86 
  87     vfs_init ();
  88     vfs_init_localfs ();
  89     vfs_setup_work_dir ();
  90 
  91     vfs_init_subclass (&test_subclass1, "testfs1", VFS_NOLINKS | VFS_REMOTE, "test1");
  92     test_subclass1.open_archive = test1_mock_open_archive;
  93     test_subclass1.archive_same = test1_mock_archive_same;
  94     test_subclass1.archive_check = NULL;
  95     vfs_register_class (vfs_test_ops1);
  96 
  97     vfs_init_subclass (&test_subclass2, "testfs2", VFS_UNKNOWN, "test2");
  98     vfs_register_class (vfs_test_ops2);
  99 
 100     vfs_init_subclass (&test_subclass3, "testfs3", VFS_UNKNOWN, "test3");
 101     vfs_register_class (vfs_test_ops3);
 102 }
 103 
 104 /* --------------------------------------------------------------------------------------------- */
 105 
 106 /* @After */
 107 static void
 108 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 109 {
 110     vfs_shut ();
 111     str_uninit_strings ();
 112 }
 113 
 114 
 115 void
 116 vfs_die (const char *m)
     /* [previous][next][first][last][top][bottom][index][help]  */
 117 {
 118     printf ("VFS_DIE: '%s'\n", m);
 119 }
 120 
 121 /* --------------------------------------------------------------------------------------------- */
 122 
 123 /* @Test */
 124 /* *INDENT-OFF* */
 125 START_TEST (test_vfs_s_get_path)
     /* [previous][next][first][last][top][bottom][index][help]  */
 126 /* *INDENT-ON* */
 127 {
 128     /* given */
 129     struct vfs_s_super *archive;
 130     const char *result;
 131 
 132     /* when */
 133     vfs_path_t *vpath =
 134         vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH,
 135                                  VPF_USE_DEPRECATED_PARSER);
 136 
 137     result = vfs_s_get_path (vpath, &archive, 0);
 138 
 139     /* then */
 140     mctest_assert_str_eq (result, ETALON_PATH);
 141     mctest_assert_str_eq (archive->name, "/" ETALON_VFS_URL_NAME ARCH_NAME);
 142 
 143     g_free (vpath);
 144 
 145 }
 146 /* *INDENT-OFF* */
 147 END_TEST
 148 /* *INDENT-ON* */
 149 
 150 /* --------------------------------------------------------------------------------------------- */
 151 
 152 int
 153 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 154 {
 155     int number_failed;
 156 
 157     Suite *s = suite_create (TEST_SUITE_NAME);
 158     TCase *tc_core = tcase_create ("Core");
 159     SRunner *sr;
 160 
 161     tcase_add_checked_fixture (tc_core, setup, teardown);
 162 
 163     /* Add new tests here: *************** */
 164     tcase_add_test (tc_core, test_vfs_s_get_path);
 165     /* *********************************** */
 166 
 167     suite_add_tcase (s, tc_core);
 168     sr = srunner_create (s);
 169     srunner_set_log (sr, "vfs_s_get_path.log");
 170     srunner_run_all (sr, CK_ENV);
 171     number_failed = srunner_ntests_failed (sr);
 172     srunner_free (sr);
 173     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 174 }
 175 
 176 /* --------------------------------------------------------------------------------------------- */

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