#include #include #include #include #include "ttail_check.h" #include "ttail.h" #include "ttail_init.h" /* * ttail_format_guess() tests */ START_TEST (test_init_guess_date) { int ret; struct tm tm; char res[] = "%Y/%m/%d"; ret = ttail_format_guess(ttail, "1988/10/22", &tm); ck_assert_int_ne(ret, -1); ck_assert_str_eq(fmt[ret], res); ck_assert(ttail->fmt != NULL); ck_assert_str_eq(ttail->fmt, res); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT); 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, 0); ck_assert_int_eq(tm.tm_min, 0); ck_assert_int_eq(tm.tm_sec, 0); } END_TEST START_TEST (test_init_guess_datetime) { int ret; struct tm tm; char res[] = "%Y/%m/%d:%H:%M"; ret = ttail_format_guess(ttail, "1988/10/22:22:10:00", &tm); ck_assert_int_ne(ret, -1); ck_assert_str_eq(fmt[ret], res); ck_assert(ttail->fmt != NULL); ck_assert_str_eq(ttail->fmt, res); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT); 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); ck_assert_int_eq(tm.tm_sec, 0); } END_TEST START_TEST (test_init_guess_datetime2) { int ret; struct tm tm; char res[] = "%B%n%d %H:%M:%S"; ret = ttail_format_guess(ttail, "Mar 6 00:01:39 pilgrim dhclient", &tm); ck_assert_int_ne(ret, -1); ck_assert_str_eq(fmt[ret], res); ck_assert(ttail->fmt != NULL); ck_assert_str_eq(ttail->fmt, res); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT); ck_assert_int_eq(tm.tm_year, 0); ck_assert_int_eq(tm.tm_mon, 2); ck_assert_int_eq(tm.tm_mday, 6); ck_assert_int_eq(tm.tm_hour, 0); ck_assert_int_eq(tm.tm_min, 1); ck_assert_int_eq(tm.tm_sec, 39); } END_TEST START_TEST (test_init_guess_noguess) { int ret; struct tm tm; ret = ttail_format_guess(ttail, "notadate", &tm); ck_assert_int_eq(ret, -1); ck_assert(ttail->fmt == NULL); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0); 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); ck_assert_int_eq(tm.tm_sec, 0); } END_TEST START_TEST (test_init_guess_date_notm) { int ret; char res[] = "%Y/%m/%d"; ret = ttail_format_guess(ttail, "1988/10/22", NULL); ck_assert_int_ne(ret, -1); ck_assert_str_eq(fmt[ret], res); ck_assert(ttail->fmt != NULL); ck_assert_str_eq(ttail->fmt, res); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT); } END_TEST START_TEST (test_init_guess_noguess_notm) { int ret; struct tm tm; ret = ttail_format_guess(ttail, "notadate", &tm); ck_assert_int_eq(ret, -1); ck_assert(ttail->fmt == NULL); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0); } END_TEST START_TEST (test_init_guess_fmt_set) { int ret; char res[] = "%Y/%m/%d"; ret = ttail_format_guess(ttail, "1988/10/22", NULL); ck_assert_str_eq(fmt[ret], res); ret = ttail_format_guess(ttail, "1988/10/22", NULL); ck_assert_int_eq(ret, -2); ck_assert_str_eq(ttail->fmt, res); ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT); } END_TEST TTAIL_CHECK_START("ttail init checks", "date format guess init checks") TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail); TTAIL_ADD_TEST(test_init_guess_date); TTAIL_ADD_TEST(test_init_guess_datetime); TTAIL_ADD_TEST(test_init_guess_datetime2); TTAIL_ADD_TEST(test_init_guess_noguess); TTAIL_ADD_TEST(test_init_guess_date_notm); TTAIL_ADD_TEST(test_init_guess_noguess_notm); TTAIL_ADD_TEST(test_init_guess_fmt_set); TTAIL_CHECK_END