root/tests/lib/vfs/path_len.c

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

DEFINITIONS

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

   1 /* lib/vfs - tests for vfspath_len() function.
   2 
   3    Copyright (C) 2011-2020
   4    Free Software Foundation, Inc.
   5 
   6    Written by:
   7    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   8 
   9    This file is part of the Midnight Commander.
  10 
  11    The Midnight Commander is free software: you can redistribute it
  12    and/or modify it under the terms of the GNU General Public License as
  13    published by the Free Software Foundation, either version 3 of the License,
  14    or (at your option) any later version.
  15 
  16    The Midnight Commander is distributed in the hope that it will be useful,
  17    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19    GNU General Public License for more details.
  20 
  21    You should have received a copy of the GNU General Public License
  22    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23  */
  24 
  25 #define TEST_SUITE_NAME "/lib/vfs"
  26 
  27 #include "tests/mctest.h"
  28 
  29 #ifdef HAVE_CHARSET
  30 #include "lib/charsets.h"
  31 #endif
  32 
  33 #include "lib/strutil.h"
  34 #include "lib/vfs/xdirentry.h"
  35 #include "lib/vfs/path.h"
  36 
  37 #include "src/vfs/local/local.c"
  38 
  39 /* --------------------------------------------------------------------------------------------- */
  40 
  41 /* @Before */
  42 static void
  43 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     mc_global.timer = mc_timer_new ();
  46     str_init_strings (NULL);
  47 
  48     vfs_init ();
  49     vfs_init_localfs ();
  50     vfs_setup_work_dir ();
  51 
  52     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  53 #ifdef HAVE_CHARSET
  54     load_codepages_list ();
  55 #endif
  56 }
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 
  60 /* @After */
  61 static void
  62 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  63 {
  64 #ifdef HAVE_CHARSET
  65     free_codepages_list ();
  66 #endif
  67 
  68     vfs_shut ();
  69     str_uninit_strings ();
  70     mc_timer_destroy (mc_global.timer);
  71 }
  72 
  73 /* --------------------------------------------------------------------------------------------- */
  74 /* @DataSource("test_path_length_ds") */
  75 /* *INDENT-OFF* */
  76 static const struct test_path_length_ds
  77 {
  78     const char *input_path;
  79     const size_t expected_length;
  80 } test_path_length_ds[] =
  81 {
  82     { /* 0. */
  83         NULL,
  84         0
  85     },
  86     { /* 1. */
  87         "/",
  88         1
  89     },
  90     { /* 2. */
  91         "/тестовый/путь",
  92         26
  93     },
  94 #ifdef HAVE_CHARSET
  95     { /* 3. */
  96         "/#enc:KOI8-R/тестовый/путь",
  97         38
  98     },
  99 #endif /* HAVE_CHARSET */
 100 };
 101 /* *INDENT-ON* */
 102 
 103 /* @Test(dataSource = "test_path_length_ds") */
 104 /* *INDENT-OFF* */
 105 START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 106 /* *INDENT-ON* */
 107 {
 108     /* given */
 109     vfs_path_t *vpath;
 110     size_t actual_length;
 111 
 112     vpath = vfs_path_from_str (data->input_path);
 113 
 114     /* when */
 115     actual_length = vfs_path_len (vpath);
 116 
 117     /* then */
 118     mctest_assert_int_eq (actual_length, data->expected_length);
 119 
 120     vfs_path_free (vpath);
 121 }
 122 /* *INDENT-OFF* */
 123 END_PARAMETRIZED_TEST
 124 /* *INDENT-ON* */
 125 
 126 /* --------------------------------------------------------------------------------------------- */
 127 
 128 int
 129 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 130 {
 131     int number_failed;
 132 
 133     Suite *s = suite_create (TEST_SUITE_NAME);
 134     TCase *tc_core = tcase_create ("Core");
 135     SRunner *sr;
 136 
 137     tcase_add_checked_fixture (tc_core, setup, teardown);
 138 
 139     /* Add new tests here: *************** */
 140     mctest_add_parameterized_test (tc_core, test_path_length, test_path_length_ds);
 141     /* *********************************** */
 142 
 143     suite_add_tcase (s, tc_core);
 144     sr = srunner_create (s);
 145     srunner_set_log (sr, "path_len.log");
 146     srunner_run_all (sr, CK_ENV);
 147     number_failed = srunner_ntests_failed (sr);
 148     srunner_free (sr);
 149     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 150 }
 151 
 152 /* --------------------------------------------------------------------------------------------- */

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