Create tests/mctest.h with useful inline macros
[midnight-commander.git] / tests / lib / name_quote.c
blob8fde629850953917f2b408c66308f2f5dde01cff
1 /*
2 lib/vfs - Quote file names
4 Copyright (C) 2011, 2013
5 The Free Software Foundation, Inc.
7 Written by:
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"
30 #include "lib/util.h"
32 /* --------------------------------------------------------------------------------------------- */
34 /* @Before */
35 static void
36 setup (void)
40 /* @After */
41 static void
42 teardown (void)
46 /* --------------------------------------------------------------------------------------------- */
48 /* @DataSource("data_source1") */
49 /* *INDENT-OFF* */
50 static const struct data_source1
52 gboolean input_quote_percent;
53 const char *input_string;
55 const char *expected_string;
56 } data_source1[] =
58 { TRUE, "%%", "%%%%"},
59 { FALSE, "%%", "%%"},
61 /* *INDENT-ON* */
63 /* @Test(dataSource = "data_source1") */
64 /* *INDENT-OFF* */
65 START_PARAMETRIZED_TEST (quote_percent_test, data_source1)
66 /* *INDENT-ON* */
68 /* given */
69 char *actual_string;
71 /* when */
72 actual_string = name_quote (data->input_string, data->input_quote_percent);
74 /* then */
75 mctest_assert_str_eq (actual_string, data->expected_string);
77 g_free (actual_string);
79 /* *INDENT-OFF* */
80 END_PARAMETRIZED_TEST
81 /* *INDENT-ON* */
83 /* --------------------------------------------------------------------------------------------- */
85 /* @DataSource("data_source2") */
86 /* *INDENT-OFF* */
87 static const struct data_source2
89 const char *input_string;
91 const char *expected_string;
92 } data_source2[] =
94 {"-", "./-"},
95 {"blabla-", "blabla-"},
96 {"\r\n\t", "\\\r\\\n\\\t"},
97 {"'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)"},
98 {"a b c ", "a\\ b\\ c\\ "},
99 {"#", "\\#"},
100 {"blabla#", "blabla#"},
101 {"~", "\\~"},
102 {"blabla~", "blabla~"},
104 /* *INDENT-ON* */
106 /* @Test(dataSource = "data_source2") */
107 /* *INDENT-OFF* */
108 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
109 /* *INDENT-ON* */
111 /* given */
112 char *actual_string;
114 /* when */
115 actual_string = name_quote (data->input_string, FALSE);
117 /* then */
118 mctest_assert_str_eq (actual_string, data->expected_string);
120 g_free (actual_string);
122 /* *INDENT-OFF* */
123 END_PARAMETRIZED_TEST
124 /* *INDENT-ON* */
126 /* --------------------------------------------------------------------------------------------- */
129 main (void)
131 int number_failed;
133 Suite *s = suite_create (TEST_SUITE_NAME);
134 TCase *tc_core = tcase_create ("Core");
135 SRunner *sr;
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 suite_add_tcase (s, tc_core);
145 sr = srunner_create (s);
146 srunner_set_log (sr, "serialize.log");
147 srunner_run_all (sr, CK_NORMAL);
148 number_failed = srunner_ntests_failed (sr);
149 srunner_free (sr);
150 return (number_failed == 0) ? 0 : 1;
153 /* --------------------------------------------------------------------------------------------- */