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
33 static const struct test_hex_translate_to_regex_ds
34 {
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[] =
39 {
40 {
41
42 "12 34",
43 "\\x12\\x34",
44 MC_SEARCH_HEX_E_OK
45 },
46 {
47
48 "0x12 0X34",
49 "\\x12\\x34",
50 MC_SEARCH_HEX_E_OK
51 },
52 {
53
54 "012",
55 "\\x12",
56 MC_SEARCH_HEX_E_OK
57 },
58 {
59
60 " 12 34 ",
61 "\\x12\\x34",
62 MC_SEARCH_HEX_E_OK
63 },
64 {
65
66 "0 ff",
67 "\\x00\\xFF",
68 MC_SEARCH_HEX_E_OK
69 },
70 {
71
72 "100",
73 NULL,
74 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE
75 },
76 {
77
78 "-1",
79 NULL,
80 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE
81 },
82 {
83
84 "1 z 2",
85 NULL,
86 MC_SEARCH_HEX_E_INVALID_CHARACTER
87 },
88
89
90
91 {
92 " \"abc\" ",
93 "abc",
94 MC_SEARCH_HEX_E_OK
95 },
96 {
97
98 "\"aBc\"",
99 "aBc",
100 MC_SEARCH_HEX_E_OK
101 },
102 {
103 " 12\"abc\"34 ",
104 "\\x12abc\\x34",
105 MC_SEARCH_HEX_E_OK
106 },
107 {
108 "\"a\"\"b\"",
109 "ab",
110 MC_SEARCH_HEX_E_OK
111 },
112
113 {
114 "\"\"",
115 "",
116 MC_SEARCH_HEX_E_OK
117 },
118 {
119 "12 \"\"",
120 "\\x12",
121 MC_SEARCH_HEX_E_OK
122 },
123
124 {
125 "\"a",
126 NULL,
127 MC_SEARCH_HEX_E_UNMATCHED_QUOTES
128 },
129 {
130 "\"",
131 NULL,
132 MC_SEARCH_HEX_E_UNMATCHED_QUOTES
133 },
134
135 {
136 "\"a\\\"b\"",
137 "a\"b",
138 MC_SEARCH_HEX_E_OK
139 },
140 {
141 "\"a\\\\b\"",
142 "a\\b",
143 MC_SEARCH_HEX_E_OK
144 },
145 };
146
147
148
149
150 START_PARAMETRIZED_TEST (test_hex_translate_to_regex, test_hex_translate_to_regex_ds)
151
152 {
153 GString *tmp, *dest_str;
154 mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK;
155
156
157 tmp = g_string_new (data->input_value);
158
159
160 dest_str = mc_search__hex_translate_to_regex (tmp, &error, NULL);
161
162 g_string_free (tmp, TRUE);
163
164
165 if (dest_str != NULL)
166 {
167 mctest_assert_str_eq (dest_str->str, data->expected_result);
168 g_string_free (dest_str, TRUE);
169 }
170 else
171 ck_assert_int_eq (error, data->expected_error);
172 }
173
174 END_PARAMETRIZED_TEST
175
176
177
178
179 int
180 main (void)
181 {
182 TCase *tc_core;
183
184 tc_core = tcase_create ("Core");
185
186
187 mctest_add_parameterized_test (tc_core, test_hex_translate_to_regex,
188 test_hex_translate_to_regex_ds);
189
190
191 return mctest_run_all (tc_core);
192 }
193
194