root/tests/lib/vfs/vfs_prefix_to_class.c

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

DEFINITIONS

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

   1 /*
   2    lib/vfs - test vfs_prefix_to_class() functionality
   3 
   4    Copyright (C) 2011-2025
   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 <https://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/xdirentry.h"
  32 #include "lib/vfs/vfs.c"  // for testing static methods
  33 
  34 #include "src/vfs/local/local.c"
  35 
  36 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 
  40 static int
  41 test_which (struct vfs_class *me, const char *path)
     /* [previous][next][first][last][top][bottom][index][help]  */
  42 {
  43     (void) me;
  44 
  45     if ((strcmp (path, "test_1:") == 0) || (strcmp (path, "test_2:") == 0)
  46         || (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
  47         return 1;
  48     return -1;
  49 }
  50 
  51 /* --------------------------------------------------------------------------------------------- */
  52 
  53 /* @Before */
  54 static void
  55 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  56 {
  57     str_init_strings (NULL);
  58 
  59     vfs_init ();
  60     vfs_init_localfs ();
  61     vfs_setup_work_dir ();
  62 
  63     vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
  64     vfs_test_ops1.which = test_which;
  65     vfs_register_class (&vfs_test_ops1);
  66 
  67     vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
  68     vfs_register_class (&vfs_test_ops2);
  69 
  70     vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
  71     vfs_register_class (&vfs_test_ops3);
  72 }
  73 
  74 /* --------------------------------------------------------------------------------------------- */
  75 
  76 /* @After */
  77 static void
  78 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  79 {
  80     vfs_shut ();
  81     str_uninit_strings ();
  82 }
  83 
  84 /* --------------------------------------------------------------------------------------------- */
  85 
  86 /* @DataSource("test_vfs_prefix_to_class_ds") */
  87 static const struct test_vfs_prefix_to_class_ds
  88 {
  89     const char *input_string;
  90     const struct vfs_class *expected_result;
  91 } test_vfs_prefix_to_class_ds[] = {
  92     {
  93         // 0
  94         "test_1:",
  95         &vfs_test_ops1,
  96     },
  97     {
  98         // 1
  99         "test_2:",
 100         &vfs_test_ops1,
 101     },
 102     {
 103         // 2
 104         "test_3:",
 105         &vfs_test_ops1,
 106     },
 107     {
 108         // 3
 109         "test_4:",
 110         &vfs_test_ops1,
 111     },
 112     {
 113         // 4
 114         "test2:",
 115         &vfs_test_ops2,
 116     },
 117     {
 118         // 5
 119         "test3:",
 120         &vfs_test_ops3,
 121     },
 122     {
 123         "test1:",
 124         NULL,
 125     },
 126     {
 127         // 6
 128         "test_5:",
 129         NULL,
 130     },
 131     {
 132         // 7
 133         "test4:",
 134         NULL,
 135     },
 136 };
 137 
 138 /* @Test(dataSource = "test_vfs_prefix_to_class_ds") */
 139 START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 140 {
 141     // given
 142     struct vfs_class *actual_result;
 143 
 144     // when
 145     actual_result = vfs_prefix_to_class ((char *) data->input_string);
 146 
 147     // then
 148     mctest_assert_ptr_eq (actual_result, data->expected_result);
 149 }
 150 END_PARAMETRIZED_TEST
 151 
 152 /* --------------------------------------------------------------------------------------------- */
 153 
 154 int
 155 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 156 {
 157     TCase *tc_core;
 158 
 159     tc_core = tcase_create ("Core");
 160 
 161     tcase_add_checked_fixture (tc_core, setup, teardown);
 162 
 163     // Add new tests here: ***************
 164     mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds);
 165     // ***********************************
 166 
 167     return mctest_run_all (tc_core);
 168 }
 169 
 170 /* --------------------------------------------------------------------------------------------- */

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