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-2024
   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     str_init_strings ("UTF-8");
  46 
  47     vfs_init ();
  48     vfs_init_localfs ();
  49     vfs_setup_work_dir ();
  50 
  51 #ifdef HAVE_CHARSET
  52     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  53     load_codepages_list ();
  54 #endif
  55 }
  56 
  57 /* --------------------------------------------------------------------------------------------- */
  58 
  59 /* @After */
  60 static void
  61 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  62 {
  63 #ifdef HAVE_CHARSET
  64     free_codepages_list ();
  65 #endif
  66 
  67     vfs_shut ();
  68     str_uninit_strings ();
  69 }
  70 
  71 /* --------------------------------------------------------------------------------------------- */
  72 /* @DataSource("test_path_length_ds") */
  73 /* *INDENT-OFF* */
  74 static const struct test_path_length_ds
  75 {
  76     const char *input_path;
  77     const size_t expected_length_element_encoding;
  78     const size_t expected_length_terminal_encoding;
  79 } test_path_length_ds[] =
  80 {
  81     { /* 0. */
  82         NULL,
  83         0,
  84         0
  85     },
  86     { /* 1. */
  87         "/",
  88         1,
  89         1
  90     },
  91     { /* 2. */
  92         "/тестовый/путь",
  93         26,
  94         26
  95     },
  96 #ifdef HAVE_CHARSET
  97     { /* 3. */
  98         "/#enc:KOI8-R/тестовый/путь",
  99         14,
 100         38,
 101     },
 102 #endif /* HAVE_CHARSET */
 103 };
 104 /* *INDENT-ON* */
 105 
 106 /* @Test(dataSource = "test_path_length_ds") */
 107 /* *INDENT-OFF* */
 108 START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 109 /* *INDENT-ON* */
 110 {
 111     /* given */
 112     vfs_path_t *vpath;
 113     char *path;
 114     size_t actual_length_terminal_encoding, actual_length_element_encoding;
 115 
 116     vpath = vfs_path_from_str (data->input_path);
 117     path = vpath != NULL ? vfs_path_get_by_index (vpath, 0)->path : NULL;
 118 
 119     /* when */
 120     actual_length_terminal_encoding = vfs_path_len (vpath);
 121     actual_length_element_encoding = path != NULL ? strlen (path) : 0;
 122 
 123     /* then */
 124     ck_assert_int_eq (actual_length_terminal_encoding, data->expected_length_terminal_encoding);
 125     ck_assert_int_eq (actual_length_element_encoding, data->expected_length_element_encoding);
 126 
 127     vfs_path_free (vpath, TRUE);
 128 }
 129 /* *INDENT-OFF* */
 130 END_PARAMETRIZED_TEST
 131 /* *INDENT-ON* */
 132 
 133 /* --------------------------------------------------------------------------------------------- */
 134 
 135 int
 136 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 137 {
 138     TCase *tc_core;
 139 
 140     tc_core = tcase_create ("Core");
 141 
 142     tcase_add_checked_fixture (tc_core, setup, teardown);
 143 
 144     /* Add new tests here: *************** */
 145     mctest_add_parameterized_test (tc_core, test_path_length, test_path_length_ds);
 146     /* *********************************** */
 147 
 148     return mctest_run_all (tc_core);
 149 }
 150 
 151 /* --------------------------------------------------------------------------------------------- */

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