2 lib/vfs - Quote file names
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011
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"
32 #include "lib/global.h"
46 /* --------------------------------------------------------------------------------------------- */
48 static const struct data_source1_struct
50 gboolean input_quote_percent
;
51 const char *input_string
;
53 const char *expected_string
;
56 { TRUE
, "%%", "%%%%"},
60 START_TEST (quote_percent_test
)
64 const struct data_source1_struct test_data
= data_source1
[_i
];
67 actual_string
= name_quote (test_data
.input_string
, test_data
.input_quote_percent
);
70 g_assert_cmpstr (actual_string
, ==, test_data
.expected_string
);
72 g_free (actual_string
);
76 /* --------------------------------------------------------------------------------------------- */
78 static const struct data_source2_struct
80 const char *input_string
;
82 const char *expected_string
;
86 {"blabla-", "blabla-"},
87 {"\r\n\t", "\\\r\\\n\\\t"},
88 {"'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)"},
89 {"a b c ", "a\\ b\\ c\\ "},
91 {"blabla#", "blabla#"},
93 {"blabla~", "blabla~"},
96 START_TEST (name_quote_test
)
100 const struct data_source2_struct test_data
= data_source2
[_i
];
103 actual_string
= name_quote (test_data
.input_string
, FALSE
);
106 g_assert_cmpstr (actual_string
, ==, test_data
.expected_string
);
108 g_free (actual_string
);
112 /* --------------------------------------------------------------------------------------------- */
119 Suite
*s
= suite_create (TEST_SUITE_NAME
);
120 TCase
*tc_core
= tcase_create ("Core");
123 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
125 /* Add new tests here: *************** */
126 tcase_add_loop_test (tc_core
, quote_percent_test
, 0, sizeof(data_source1
)/sizeof(data_source1
[0]));
128 tcase_add_loop_test (tc_core
, name_quote_test
, 0, sizeof(data_source2
)/sizeof(data_source2
[0]));
129 /* *********************************** */
131 suite_add_tcase (s
, tc_core
);
132 sr
= srunner_create (s
);
133 srunner_set_log (sr
, "serialize.log");
134 srunner_run_all (sr
, CK_NORMAL
);
135 number_failed
= srunner_ntests_failed (sr
);
137 return (number_failed
== 0) ? 0 : 1;
140 /* --------------------------------------------------------------------------------------------- */