1 /*
2 lib/vfs - test vfs_get_encoding() functionality
3
4 Copyright (C) 2013-2025
5 Free Software Foundation, Inc.
6
7 Written by:
8 Andrew Borodin <aborodin@vmail.ru>, 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 <https://www.gnu.org/licenses/>.
24 */
25
26 #define TEST_SUITE_NAME "/lib/vfs"
27
28 #include "tests/mctest.h"
29
30 #include "lib/vfs/path.h"
31
32 /* --------------------------------------------------------------------------------------------- */
33
34 /* @DataSource("test_vfs_get_encoding_ds") */
35 static const struct test_vfs_get_encoding_ds
36 {
37 const char *path;
38 const char *expected_encoding;
39 } test_vfs_get_encoding_ds[] = {
40 {
41 // 0
42 "",
43 NULL,
44 },
45 {
46 // 1
47 "aaaa",
48 NULL,
49 },
50 {
51 // 2
52 "/aaaa",
53 NULL,
54 },
55 {
56 // 3
57 "aaaa/bbbb",
58 NULL,
59 },
60 {
61 // 4
62 "/aaaa/bbbb",
63 NULL,
64 },
65 {
66 // 5
67 "#enc:UTF-8/aaaa",
68 "UTF-8",
69 },
70 {
71 // 6
72 "/#enc:UTF-8/aaaa",
73 "UTF-8",
74 },
75 {
76 // 7
77 "/aaaa/#enc:UTF-8/bbbb",
78 "UTF-8",
79 },
80 {
81 // 8
82 "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R",
83 "KOI8-R",
84 },
85 {
86 // 9
87 "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R/cccc",
88 "KOI8-R",
89 },
90 {
91 // 10
92 "/aaaa/#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
93 "UTF-8",
94 },
95 {
96 // 11
97 "/#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
98 "UTF-8",
99 },
100 {
101 // 12
102 "#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
103 "UTF-8",
104 },
105 {
106 // 13
107 "aaaa#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
108 NULL,
109 },
110 {
111 // 14
112 "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R#enc:CP866/cccc",
113 "KOI8-R#enc:CP866",
114 },
115 };
116
117 /* @Test(dataSource = "test_vfs_get_encoding_ds") */
118 START_PARAMETRIZED_TEST (test_vfs_get_encoding, test_vfs_get_encoding_ds)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
119 {
120 // given
121 char *actual_encoding;
122
123 // when
124 actual_encoding = vfs_get_encoding (data->path, -1);
125
126 // then
127 mctest_assert_str_eq (actual_encoding, data->expected_encoding);
128
129 g_free (actual_encoding);
130 }
131 END_PARAMETRIZED_TEST
132
133 /* --------------------------------------------------------------------------------------------- */
134
135 int
136 main (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
137 {
138 TCase *tc_core;
139
140 tc_core = tcase_create ("Core");
141
142 // Add new tests here: ***************
143 mctest_add_parameterized_test (tc_core, test_vfs_get_encoding, test_vfs_get_encoding_ds);
144 // ***********************************
145
146 return mctest_run_all (tc_core);
147 }
148
149 /* --------------------------------------------------------------------------------------------- */