Ticket #4217: remove OS/distro-specific stuff.
[midnight-commander.git] / tests / lib / vfs / path_len.c
bloba59724c7c7cf7c2da2b5e348b2f9a8c02732fb8f
1 /* lib/vfs - tests for vfspath_len() function.
3 Copyright (C) 2011-2021
4 Free Software Foundation, Inc.
6 Written by:
7 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
9 This file is part of the Midnight Commander.
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.
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.
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/>.
25 #define TEST_SUITE_NAME "/lib/vfs"
27 #include "tests/mctest.h"
29 #ifdef HAVE_CHARSET
30 #include "lib/charsets.h"
31 #endif
33 #include "lib/strutil.h"
34 #include "lib/vfs/xdirentry.h"
35 #include "lib/vfs/path.h"
37 #include "src/vfs/local/local.c"
39 /* --------------------------------------------------------------------------------------------- */
41 /* @Before */
42 static void
43 setup (void)
45 str_init_strings (NULL);
47 vfs_init ();
48 vfs_init_localfs ();
49 vfs_setup_work_dir ();
51 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
52 #ifdef HAVE_CHARSET
53 load_codepages_list ();
54 #endif
57 /* --------------------------------------------------------------------------------------------- */
59 /* @After */
60 static void
61 teardown (void)
63 #ifdef HAVE_CHARSET
64 free_codepages_list ();
65 #endif
67 vfs_shut ();
68 str_uninit_strings ();
71 /* --------------------------------------------------------------------------------------------- */
72 /* @DataSource("test_path_length_ds") */
73 /* *INDENT-OFF* */
74 static const struct test_path_length_ds
76 const char *input_path;
77 const size_t expected_length;
78 } test_path_length_ds[] =
80 { /* 0. */
81 NULL,
84 { /* 1. */
85 "/",
88 { /* 2. */
89 "/тестовый/путь",
92 #ifdef HAVE_CHARSET
93 { /* 3. */
94 "/#enc:KOI8-R/тестовый/путь",
97 #endif /* HAVE_CHARSET */
99 /* *INDENT-ON* */
101 /* @Test(dataSource = "test_path_length_ds") */
102 /* *INDENT-OFF* */
103 START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
104 /* *INDENT-ON* */
106 /* given */
107 vfs_path_t *vpath;
108 size_t actual_length;
110 vpath = vfs_path_from_str (data->input_path);
112 /* when */
113 actual_length = vfs_path_len (vpath);
115 /* then */
116 mctest_assert_int_eq (actual_length, data->expected_length);
118 vfs_path_free (vpath, TRUE);
120 /* *INDENT-OFF* */
121 END_PARAMETRIZED_TEST
122 /* *INDENT-ON* */
124 /* --------------------------------------------------------------------------------------------- */
127 main (void)
129 TCase *tc_core;
131 tc_core = tcase_create ("Core");
133 tcase_add_checked_fixture (tc_core, setup, teardown);
135 /* Add new tests here: *************** */
136 mctest_add_parameterized_test (tc_core, test_path_length, test_path_length_ds);
137 /* *********************************** */
139 return mctest_run_all (tc_core);
142 /* --------------------------------------------------------------------------------------------- */