Manual pages: mcmcdiffmceditmcview

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-2025
   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 <https://www.gnu.org/licenses/>.
  23  */
  24 
  25 #define TEST_SUITE_NAME "/lib/vfs"
  26 
  27 #include "tests/mctest.h"
  28 
  29 #include "lib/charsets.h"
  30 
  31 #include "lib/strutil.h"
  32 #include "lib/vfs/xdirentry.h"
  33 #include "lib/vfs/path.h"
  34 
  35 #include "src/vfs/local/local.c"
  36 
  37 /* --------------------------------------------------------------------------------------------- */
  38 
  39 /* @Before */
  40 static void
  41 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  42 {
  43     str_init_strings ("UTF-8");
  44 
  45     vfs_init ();
  46     vfs_init_localfs ();
  47     vfs_setup_work_dir ();
  48 
  49     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  50     load_codepages_list ();
  51 }
  52 
  53 /* --------------------------------------------------------------------------------------------- */
  54 
  55 /* @After */
  56 static void
  57 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  58 {
  59     free_codepages_list ();
  60     vfs_shut ();
  61     str_uninit_strings ();
  62 }
  63 
  64 /* --------------------------------------------------------------------------------------------- */
  65 /* @DataSource("test_path_length_ds") */
  66 static const struct test_path_length_ds
  67 {
  68     const char *input_path;
  69     const size_t expected_length_element_encoding;
  70     const size_t expected_length_terminal_encoding;
  71 } test_path_length_ds[] = {
  72     {
  73         // 0.
  74         NULL,
  75         0,
  76         0,
  77     },
  78     {
  79         // 1.
  80         "/",
  81         1,
  82         1,
  83     },
  84     {
  85         // 2.
  86         "/тестовый/путь",
  87         26,
  88         26,
  89     },
  90     {
  91         // 3.
  92         "/#enc:KOI8-R/тестовый/путь",
  93         14,
  94         38,
  95     },
  96 };
  97 
  98 /* @Test(dataSource = "test_path_length_ds") */
  99 START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 100 {
 101     // given
 102     vfs_path_t *vpath;
 103     char *path;
 104     size_t actual_length_terminal_encoding, actual_length_element_encoding;
 105 
 106     vpath = vfs_path_from_str (data->input_path);
 107     path = vpath != NULL ? vfs_path_get_by_index (vpath, 0)->path : NULL;
 108 
 109     // when
 110     actual_length_terminal_encoding = vfs_path_len (vpath);
 111     actual_length_element_encoding = path != NULL ? strlen (path) : 0;
 112 
 113     // then
 114     ck_assert_int_eq (actual_length_terminal_encoding, data->expected_length_terminal_encoding);
 115     ck_assert_int_eq (actual_length_element_encoding, data->expected_length_element_encoding);
 116 
 117     vfs_path_free (vpath, TRUE);
 118 }
 119 END_PARAMETRIZED_TEST
 120 
 121 /* --------------------------------------------------------------------------------------------- */
 122 
 123 int
 124 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 125 {
 126     TCase *tc_core;
 127 
 128     tc_core = tcase_create ("Core");
 129 
 130     tcase_add_checked_fixture (tc_core, setup, teardown);
 131 
 132     // Add new tests here: ***************
 133     mctest_add_parameterized_test (tc_core, test_path_length, test_path_length_ds);
 134     // ***********************************
 135 
 136     return mctest_run_all (tc_core);
 137 }
 138 
 139 /* --------------------------------------------------------------------------------------------- */

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