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
24
25
26 #define TEST_SUITE_NAME "lib/search/regex"
27
28 #include "tests/mctest.h"
29
30 #include "regex.c"
31
32
33 #define test_helper_check_valid_data( a, b, c, d, e, f ) \
34 { \
35 ck_assert_msg (a == b, "ret_value != %s", (b) ? "TRUE": "FALSE"); \
36 ck_assert_msg (c == d, "skip_len(%d) != %d", c, d); \
37 if (f != 0) \
38 ck_assert_msg (e == f, "ret(%d) != %d", e, f); \
39 }
40
41 #define test_helper_handle_esc_seq( pos, r, skip, flag ) \
42 { \
43 skip_len = 0;\
44 test_helper_check_valid_data(\
45 mc_search_regex__replace_handle_esc_seq( replace_str, pos, &skip_len, &ret ), r,\
46 skip_len, skip,\
47 ret, flag\
48 ); \
49 }
50
51
52
53
54
55 static const struct test_regex_replace_esc_seq_prepare_ds
56 {
57 const char *input_string;
58 const size_t input_pos;
59
60 const gboolean expected_result;
61 const gsize expected_skipped_len;
62 const int expected_flags;
63 } test_regex_replace_esc_seq_prepare_ds[] =
64 {
65 {
66 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
67 7,
68 FALSE,
69 6,
70 REPLACE_PREPARE_T_ESCAPE_SEQ
71 },
72 {
73 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
74 20,
75 FALSE,
76 4,
77 REPLACE_PREPARE_T_ESCAPE_SEQ
78 },
79 {
80 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
81 36,
82 FALSE,
83 11,
84 REPLACE_PREPARE_T_ESCAPE_SEQ
85 },
86 {
87 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
88 54,
89 FALSE,
90 2,
91 REPLACE_PREPARE_T_NOTHING_SPECIAL
92 },
93 {
94 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
95 59,
96 FALSE,
97 2,
98 REPLACE_PREPARE_T_ESCAPE_SEQ
99 },
100 {
101 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
102 61,
103 FALSE,
104 2,
105 REPLACE_PREPARE_T_ESCAPE_SEQ
106 },
107 {
108 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
109 63,
110 FALSE,
111 2,
112 REPLACE_PREPARE_T_ESCAPE_SEQ
113 },
114 {
115 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
116 65,
117 FALSE,
118 2,
119 REPLACE_PREPARE_T_ESCAPE_SEQ
120 },
121 {
122 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
123 67,
124 FALSE,
125 2,
126 REPLACE_PREPARE_T_ESCAPE_SEQ
127 },
128 {
129 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
130 69,
131 FALSE,
132 2,
133 REPLACE_PREPARE_T_ESCAPE_SEQ
134 },
135 {
136 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
137 71,
138 FALSE,
139 2,
140 REPLACE_PREPARE_T_ESCAPE_SEQ
141 },
142 {
143 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
144 0,
145 TRUE,
146 5,
147 REPLACE_PREPARE_T_NOTHING_SPECIAL
148 },
149 {
150 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
151 6,
152 TRUE,
153 3,
154 REPLACE_PREPARE_T_NOTHING_SPECIAL
155 },
156 {
157 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
158 17,
159 TRUE,
160 0,
161 0
162 },
163 {
164 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
165 22,
166 TRUE,
167 7,
168 REPLACE_PREPARE_T_NOTHING_SPECIAL
169 },
170 {
171 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
172 41,
173 TRUE,
174 0,
175 0
176 },
177 };
178
179
180
181
182 START_PARAMETRIZED_TEST (test_regex_replace_esc_seq_prepare, test_regex_replace_esc_seq_prepare_ds)
183
184 {
185
186 GString *replace_str;
187 gsize actual_skipped_len = 0;
188 int actual_flags = 0;
189 gboolean actual_result;
190
191 replace_str = g_string_new (data->input_string);
192
193
194 actual_result =
195 mc_search_regex__replace_handle_esc_seq (replace_str, data->input_pos, &actual_skipped_len,
196 &actual_flags);
197
198
199 ck_assert_int_eq (actual_result, data->expected_result);
200 ck_assert_int_eq (actual_skipped_len, data->expected_skipped_len);
201 ck_assert_int_eq (actual_flags, data->expected_flags);
202
203 g_string_free (replace_str, TRUE);
204 }
205
206 END_PARAMETRIZED_TEST
207
208
209
210
211 int
212 main (void)
213 {
214 TCase *tc_core;
215
216 tc_core = tcase_create ("Core");
217
218
219 mctest_add_parameterized_test (tc_core, test_regex_replace_esc_seq_prepare,
220 test_regex_replace_esc_seq_prepare_ds);
221
222
223 return mctest_run_all (tc_core);
224 }
225
226