123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
-
- #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
|