This source file includes following definitions.
- START_PARAMETRIZED_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #define TEST_SUITE_NAME "lib/search/hex"
24
25 #include "tests/mctest.h"
26
27 #include "hex.c"
28
29
30
31
32 static const struct test_hex_translate_to_regex_ds
33 {
34 const char *input_value;
35 const char *expected_result;
36 mc_search_hex_parse_error_t expected_error;
37 } test_hex_translate_to_regex_ds[] = {
38 {
39
40 "12 34",
41 "\\x12\\x34",
42 MC_SEARCH_HEX_E_OK,
43 },
44 {
45
46 "0x12 0X34",
47 "\\x12\\x34",
48 MC_SEARCH_HEX_E_OK,
49 },
50 {
51
52 "012",
53 "\\x12",
54 MC_SEARCH_HEX_E_OK,
55 },
56 {
57
58 " 12 34 ",
59 "\\x12\\x34",
60 MC_SEARCH_HEX_E_OK,
61 },
62 {
63
64 "0 ff",
65 "\\x00\\xFF",
66 MC_SEARCH_HEX_E_OK,
67 },
68 {
69
70 "100",
71 NULL,
72 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE,
73 },
74 {
75
76 "-1",
77 NULL,
78 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE,
79 },
80 {
81
82 "1 z 2",
83 NULL,
84 MC_SEARCH_HEX_E_INVALID_CHARACTER,
85 },
86
87
88
89 {
90 " \"abc\" ",
91 "abc",
92 MC_SEARCH_HEX_E_OK,
93 },
94 {
95
96 "\"aBc\"",
97 "aBc",
98 MC_SEARCH_HEX_E_OK,
99 },
100 {
101 " 12\"abc\"34 ",
102 "\\x12abc\\x34",
103 MC_SEARCH_HEX_E_OK,
104 },
105 {
106 "\"a\"\"b\"",
107 "ab",
108 MC_SEARCH_HEX_E_OK,
109 },
110
111 {
112 "\"\"",
113 "",
114 MC_SEARCH_HEX_E_OK,
115 },
116 {
117 "12 \"\"",
118 "\\x12",
119 MC_SEARCH_HEX_E_OK,
120 },
121
122 {
123 "\"a",
124 NULL,
125 MC_SEARCH_HEX_E_UNMATCHED_QUOTES,
126 },
127 {
128 "\"",
129 NULL,
130 MC_SEARCH_HEX_E_UNMATCHED_QUOTES,
131 },
132
133 {
134 "\"a\\\"b\"",
135 "a\"b",
136 MC_SEARCH_HEX_E_OK,
137 },
138 {
139 "\"a\\\\b\"",
140 "a\\b",
141 MC_SEARCH_HEX_E_OK,
142 },
143 };
144
145
146 START_PARAMETRIZED_TEST (test_hex_translate_to_regex, test_hex_translate_to_regex_ds)
147 {
148 GString *tmp, *dest_str;
149 mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK;
150
151
152 tmp = g_string_new (data->input_value);
153
154
155 dest_str = mc_search__hex_translate_to_regex (tmp, &error, NULL);
156
157 g_string_free (tmp, TRUE);
158
159
160 if (dest_str != NULL)
161 {
162 mctest_assert_str_eq (dest_str->str, data->expected_result);
163 g_string_free (dest_str, TRUE);
164 }
165 else
166 ck_assert_int_eq (error, data->expected_error);
167 }
168 END_PARAMETRIZED_TEST
169
170
171
172 int
173 main (void)
174 {
175 TCase *tc_core;
176
177 tc_core = tcase_create ("Core");
178
179
180 mctest_add_parameterized_test (tc_core, test_hex_translate_to_regex,
181 test_hex_translate_to_regex_ds);
182
183
184 return mctest_run_all (tc_core);
185 }
186
187