|
@@ -168,13 +168,80 @@ START_TEST (test_file_minmax1)
|
168
|
168
|
}
|
169
|
169
|
END_TEST
|
170
|
170
|
|
171
|
|
-Suite * ttail_search_suite(void)
|
|
171
|
+START_TEST (test_search_subst_const1)
|
|
172
|
+{
|
|
173
|
+ char expl[] = "Hello world !";
|
|
174
|
+ const char *res;
|
|
175
|
+ ttail->flag |= TTAIL_FLAG_PREFIX;
|
|
176
|
+ ttail->prefix_sz = 4;
|
|
177
|
+ res = ttail_logline_subst(ttail, expl);
|
|
178
|
+ ck_assert(res != NULL);
|
|
179
|
+ ck_assert(res == expl+4);
|
|
180
|
+}
|
|
181
|
+END_TEST
|
|
182
|
+
|
|
183
|
+START_TEST (test_search_subst_const2)
|
|
184
|
+{
|
|
185
|
+ char expl[] = "Hello world !";
|
|
186
|
+ const char *res;
|
|
187
|
+ ttail->flag |= TTAIL_FLAG_PREFIX;
|
|
188
|
+ ttail->prefix_sz = 0;
|
|
189
|
+ res = ttail_logline_subst(ttail, expl);
|
|
190
|
+ ck_assert(res != NULL);
|
|
191
|
+ ck_assert(res == expl);
|
|
192
|
+}
|
|
193
|
+END_TEST
|
|
194
|
+
|
|
195
|
+START_TEST (test_search_subst_re1)
|
|
196
|
+{
|
|
197
|
+ char expl[] = "1337 Foo Bar - Hello world !";
|
|
198
|
+ char re[] = "^1337 Fo* Bar - ";
|
|
199
|
+ const char *res;
|
|
200
|
+ int ret;
|
|
201
|
+ ret = ttail_set_prefix(ttail, re);
|
|
202
|
+ ck_assert_int_eq(ret,0);
|
|
203
|
+ res = ttail_logline_subst(ttail, expl);
|
|
204
|
+ ck_assert(res != NULL);
|
|
205
|
+ ck_assert_str_eq(res, "Hello world !");
|
|
206
|
+}
|
|
207
|
+END_TEST
|
|
208
|
+
|
|
209
|
+START_TEST (test_search_subst_re2)
|
|
210
|
+{
|
|
211
|
+ char expl[] = "1337 Foo Bar - Hello world !";
|
|
212
|
+ char re[] = "^[0-9]+ Fo{2} Bar - ";
|
|
213
|
+ const char *res;
|
|
214
|
+ int ret;
|
|
215
|
+ ttail->flag |= TTAIL_FLAG_EXTENDED_RE;
|
|
216
|
+ ret = ttail_set_prefix(ttail, re);
|
|
217
|
+ ck_assert_int_eq(ret,0);
|
|
218
|
+ res = ttail_logline_subst(ttail, expl);
|
|
219
|
+ ck_assert(res != NULL);
|
|
220
|
+ ck_assert_str_eq(res, "Hello world !");
|
|
221
|
+}
|
|
222
|
+END_TEST
|
|
223
|
+
|
|
224
|
+START_TEST (test_search_subst_re_nomatch)
|
|
225
|
+{
|
|
226
|
+ char expl[] = "1337 Foo Bar - Hello world !";
|
|
227
|
+ char re[] = "Never match m*";
|
|
228
|
+ const char *res;
|
|
229
|
+ int ret;
|
|
230
|
+ ret = ttail_set_prefix(ttail, re);
|
|
231
|
+ ck_assert_int_eq(ret,0);
|
|
232
|
+ res = ttail_logline_subst(ttail, expl);
|
|
233
|
+ ck_assert(res == NULL);
|
|
234
|
+}
|
|
235
|
+END_TEST
|
|
236
|
+
|
|
237
|
+Suite * ttail_search_files_suite(void)
|
172
|
238
|
{
|
173
|
239
|
Suite *s;
|
|
240
|
+ TCase *tc_search_subst;
|
174
|
241
|
TCase *tc_search_closest_fileinit, *tc_file_line,
|
175
|
242
|
*tc_file_minmax;
|
176
|
243
|
|
177
|
|
- s = suite_create("ttail search checks");
|
|
244
|
+ s = suite_create("ttail search_files checks");
|
178
|
245
|
tc_search_closest_fileinit = tcase_create("\
|
179
|
246
|
ttail_logline_closest_files_init() checks");
|
180
|
247
|
tcase_add_checked_fixture(tc_search_closest_fileinit,
|
|
@@ -196,6 +263,16 @@ ttail_logline_closest_files_init() checks");
|
196
|
263
|
setup_closest_fileinit, teardown_closest_fileinit);
|
197
|
264
|
tcase_add_test(tc_file_minmax, test_file_minmax1);
|
198
|
265
|
|
|
266
|
+ tc_search_subst = tcase_create("ttail_logline_subst() checks");
|
|
267
|
+ tcase_add_checked_fixture(tc_search_subst,
|
|
268
|
+ setup_closest_fileinit, teardown_closest_fileinit);
|
|
269
|
+ tcase_add_test(tc_search_subst, test_search_subst_const1);
|
|
270
|
+ tcase_add_test(tc_search_subst, test_search_subst_const2);
|
|
271
|
+ tcase_add_test(tc_search_subst, test_search_subst_re1);
|
|
272
|
+ tcase_add_test(tc_search_subst, test_search_subst_re2);
|
|
273
|
+ tcase_add_test(tc_search_subst, test_search_subst_re_nomatch);
|
|
274
|
+
|
|
275
|
+ suite_add_tcase(s, tc_search_subst);
|
199
|
276
|
suite_add_tcase(s, tc_search_closest_fileinit);
|
200
|
277
|
suite_add_tcase(s, tc_file_line);
|
201
|
278
|
suite_add_tcase(s, tc_file_minmax);
|
|
@@ -209,9 +286,8 @@ int main(int argc, char **argv)
|
209
|
286
|
|
210
|
287
|
chdir(dirname(argv[0])); /* move in ./tests dir */
|
211
|
288
|
|
212
|
|
- sr = srunner_create(ttail_search_suite());
|
|
289
|
+ sr = srunner_create(ttail_search_files_suite());
|
213
|
290
|
srunner_set_fork_status(sr, CK_FORK);
|
214
|
|
-
|
215
|
291
|
srunner_run_all(sr,CK_VERBOSE);
|
216
|
292
|
number_failed = srunner_ntests_failed(sr);
|
217
|
293
|
srunner_free(sr);
|