4 Copyright (C) 2011-2024
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
10 This file is part of the Midnight Commander.
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.
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.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define TEST_SUITE_NAME "/lib/util"
28 #include "tests/mctest.h"
32 /* --------------------------------------------------------------------------------------------- */
46 /* --------------------------------------------------------------------------------------------- */
48 /* @DataSource("data_source1") */
50 static const struct data_source1
52 gboolean input_quote_percent
;
53 const char *input_string
;
55 const char *expected_string
;
58 { TRUE
, "%%", "%%%%"},
63 /* @Test(dataSource = "data_source1") */
65 START_PARAMETRIZED_TEST (quote_percent_test
, data_source1
)
72 actual_string
= name_quote (data
->input_string
, data
->input_quote_percent
);
75 mctest_assert_str_eq (actual_string
, data
->expected_string
);
77 g_free (actual_string
);
83 /* --------------------------------------------------------------------------------------------- */
85 /* @DataSource("data_source2") */
87 static const struct data_source2
89 const char *input_string
;
91 const char *expected_string
;
97 {"blabla-", "blabla-"},
98 {"\r\n\t", "\\\r\\\n\\\t"},
99 {"'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)"},
100 {"a b c ", "a\\ b\\ c\\ "},
102 {"blabla#", "blabla#"},
104 {"blabla~", "blabla~"},
108 /* @Test(dataSource = "data_source2") */
110 START_PARAMETRIZED_TEST (name_quote_test
, data_source2
)
117 actual_string
= name_quote (data
->input_string
, FALSE
);
120 mctest_assert_str_eq (actual_string
, data
->expected_string
);
122 g_free (actual_string
);
125 END_PARAMETRIZED_TEST
128 /* --------------------------------------------------------------------------------------------- */
135 tc_core
= tcase_create ("Core");
137 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
139 /* Add new tests here: *************** */
140 mctest_add_parameterized_test (tc_core
, quote_percent_test
, data_source1
);
141 mctest_add_parameterized_test (tc_core
, name_quote_test
, data_source2
);
142 /* *********************************** */
144 return mctest_run_all (tc_core
);
147 /* --------------------------------------------------------------------------------------------- */