12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #include <check.h>
- #include <stdio.h>
- #include <libgen.h>
-
- #include "ttail_check.h"
- #include "ttail.h"
- #include "ttail_init.h"
- #include "ttail_search.h"
-
- /*
- * ttail_logline2date() checks
- */
- START_TEST (test_search_log2date1)
- {
- char re[] = "^[0-9]+ ";
- char fmt[] = "%Y-%m-%d:%H:%M";
- struct tm tm;
- int ret;
- ttail_set_flag_re_ex(ttail);
- ttail_set_prefix(ttail, re);
- ttail_set_fmt(ttail, fmt);
- ret = ttail_logline2date(ttail, "1337 1988-10-22:22:10 foobar", &tm);
- ck_assert_int_eq(ret, 0);
- ck_assert_int_eq(tm.tm_year, 88);
- ck_assert_int_eq(tm.tm_mon, 9);
- ck_assert_int_eq(tm.tm_mday, 22);
- ck_assert_int_eq(tm.tm_hour, 22);
- ck_assert_int_eq(tm.tm_min, 10);
- }
- END_TEST
-
- START_TEST (test_search_log2date_failpref)
- {
- char re[] = "^[0-9]+aa ";
- char fmt[] = "%Y-%m-%d:%H:%M";
- struct tm tm;
- int ret;
- ttail_set_flag_re_ex(ttail);
- ttail_set_prefix(ttail, re);
- ttail_set_fmt(ttail, fmt);
- ret = ttail_logline2date(ttail, "1337 1988-10-22:22:10 foobar", &tm);
- ck_assert_int_eq(ret, 1);
- ck_assert_int_eq(tm.tm_year, 0);
- ck_assert_int_eq(tm.tm_mon, 0);
- ck_assert_int_eq(tm.tm_mday, 0);
- ck_assert_int_eq(tm.tm_hour, 0);
- ck_assert_int_eq(tm.tm_min, 0);
- }
- END_TEST
-
- START_TEST (test_search_log2date_faildate)
- {
- char re[] = "^[0-9]+ ";
- char fmt[] = "%y-%m-%d:%H:%M";
- struct tm tm;
- int ret;
- ttail_set_flag_re_ex(ttail);
- ttail_set_prefix(ttail, re);
- ttail_set_fmt(ttail, fmt);
- ret = ttail_logline2date(ttail, "1337 1988-10-22:22:10 foobar", &tm);
- ck_assert_int_eq(ret, 2);
- ck_assert_int_eq(tm.tm_year, 0);
- ck_assert_int_eq(tm.tm_mon, 0);
- ck_assert_int_eq(tm.tm_mday, 0);
- ck_assert_int_eq(tm.tm_hour, 0);
- ck_assert_int_eq(tm.tm_min, 0);
- }
- END_TEST
-
- TTAIL_CHECK_START("ttail search_files checks","ttail_logline2date() checks")
- TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
- TTAIL_ADD_TEST(test_search_log2date1);
- TTAIL_ADD_TEST(test_search_log2date_failpref);
- TTAIL_ADD_TEST(test_search_log2date_faildate);
- TTAIL_CHECK_END
|