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-2024
   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/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) ||
  46         (strcmp (path, "test_2:") == 0) ||
  47         (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
  48         return 1;
  49     return -1;
  50 }
  51 
  52 /* --------------------------------------------------------------------------------------------- */
  53 
  54 /* @Before */
  55 static void
  56 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  57 {
  58     str_init_strings (NULL);
  59 
  60     vfs_init ();
  61     vfs_init_localfs ();
  62     vfs_setup_work_dir ();
  63 
  64     vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
  65     vfs_test_ops1.which = test_which;
  66     vfs_register_class (&vfs_test_ops1);
  67 
  68     vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
  69     vfs_register_class (&vfs_test_ops2);
  70 
  71     vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
  72     vfs_register_class (&vfs_test_ops3);
  73 }
  74 
  75 /* --------------------------------------------------------------------------------------------- */
  76 
  77 /* @After */
  78 static void
  79 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  80 {
  81     vfs_shut ();
  82     str_uninit_strings ();
  83 }
  84 
  85 /* --------------------------------------------------------------------------------------------- */
  86 
  87 /* @DataSource("test_vfs_prefix_to_class_ds") */
  88 /* *INDENT-OFF* */
  89 static const struct test_vfs_prefix_to_class_ds
  90 {
  91     const char *input_string;
  92     const struct vfs_class *expected_result;
  93 } test_vfs_prefix_to_class_ds[] =
  94 {
  95     { /* 0 */
  96         "test_1:",
  97         &vfs_test_ops1
  98     },
  99     { /* 1 */
 100         "test_2:",
 101         &vfs_test_ops1
 102     },
 103     { /* 2 */
 104         "test_3:",
 105         &vfs_test_ops1
 106     },
 107     { /* 3 */
 108         "test_4:",
 109         &vfs_test_ops1
 110     },
 111     { /* 4 */
 112         "test2:",
 113         &vfs_test_ops2
 114     },
 115     { /* 5 */
 116         "test3:",
 117         &vfs_test_ops3
 118     },
 119     {
 120         "test1:",
 121         NULL
 122     },
 123     { /* 6 */
 124         "test_5:",
 125         NULL
 126     },
 127     { /* 7 */
 128         "test4:",
 129         NULL
 130     },
 131 };
 132 /* *INDENT-ON* */
 133 
 134 /* @Test(dataSource = "test_vfs_prefix_to_class_ds") */
 135 /* *INDENT-OFF* */
 136 START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 137 /* *INDENT-ON* */
 138 {
 139     /* given */
 140     struct vfs_class *actual_result;
 141 
 142     /* when */
 143     actual_result = vfs_prefix_to_class ((char *) data->input_string);
 144 
 145     /* then */
 146     mctest_assert_ptr_eq (actual_result, data->expected_result);
 147 }
 148 /* *INDENT-OFF* */
 149 END_PARAMETRIZED_TEST
 150 /* *INDENT-ON* */
 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]  */