2 libmc - checks for hex pattern parsing
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software: you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the License,
12 or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define TEST_SUITE_NAME "lib/search/hex"
25 #include "tests/mctest.h"
27 #include "hex.c" /* for testing static functions */
29 /* --------------------------------------------------------------------------------------------- */
31 /* @DataSource("test_hex_translate_to_regex_ds") */
33 static const struct test_hex_translate_to_regex_ds
35 const char *input_value
;
36 const char *expected_result
;
37 mc_search_hex_parse_error_t expected_error
;
38 } test_hex_translate_to_regex_ds
[] =
47 /* Prefixes (0x, 0X) */
53 /* Prefix "0" doesn't signify octal! Numbers are always interpreted in hex. */
59 /* Extra whitespace */
71 /* Error: Number out of range */
74 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE
77 /* Error: Number out of range (negative) */
80 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE
83 /* Error: Invalid characters */
86 MC_SEARCH_HEX_E_INVALID_CHARACTER
97 /* Preserve upper/lower case */
123 /* Error: Unmatched quotes */
127 MC_SEARCH_HEX_E_UNMATCHED_QUOTES
132 MC_SEARCH_HEX_E_UNMATCHED_QUOTES
148 /* @Test(dataSource = "test_hex_translate_to_regex_ds") */
150 START_PARAMETRIZED_TEST (test_hex_translate_to_regex
, test_hex_translate_to_regex_ds
)
153 GString
*tmp
, *dest_str
;
154 mc_search_hex_parse_error_t error
;
157 tmp
= g_string_new (data
->input_value
);
160 dest_str
= mc_search__hex_translate_to_regex (tmp
, &error
, NULL
);
162 g_string_free (tmp
, TRUE
);
165 if (dest_str
!= NULL
)
167 mctest_assert_str_eq (dest_str
->str
, data
->expected_result
);
168 g_string_free (dest_str
, TRUE
);
172 mctest_assert_int_eq (error
, data
->expected_error
);
176 END_PARAMETRIZED_TEST
179 /* --------------------------------------------------------------------------------------------- */
186 Suite
*s
= suite_create (TEST_SUITE_NAME
);
187 TCase
*tc_core
= tcase_create ("Core");
190 /* Add new tests here: *************** */
191 mctest_add_parameterized_test (tc_core
, test_hex_translate_to_regex
,
192 test_hex_translate_to_regex_ds
);
193 /* *********************************** */
195 suite_add_tcase (s
, tc_core
);
196 sr
= srunner_create (s
);
197 srunner_set_log (sr
, "hex_translate_to_regex.log");
198 srunner_run_all (sr
, CK_ENV
);
199 number_failed
= srunner_ntests_failed (sr
);
201 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
204 /* --------------------------------------------------------------------------------------------- */