123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
-
- #include "ttail_check.h"
- #include "ttail.h"
- #include "ttail_init.h"
-
- START_TEST (test_norm_dates_flags_none)
- {
- struct tm tm;
- int ret;
-
- ttail->flag = 0;
- ttail_set_fmt(ttail, "%H %Y");
- tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
- tm.tm_year = 2;
- ttail->date_min = tm;
- ttail->date_max = tm;
-
- ret = ttail_norm_dates(ttail);
- ck_assert_int_eq(ret, 0);
-
- tm = ttail->date_min;
- ck_assert_int_eq(tm.tm_sec, 2);
- ck_assert_int_eq(tm.tm_min, 2);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, 2);
- ck_assert_int_eq(tm.tm_mon, 2);
- ck_assert_int_eq(tm.tm_year, 2);
-
- tm = ttail->date_max;
- ck_assert_int_eq(tm.tm_sec, 2);
- ck_assert_int_eq(tm.tm_min, 2);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, 2);
- ck_assert_int_eq(tm.tm_mon, 2);
- ck_assert_int_eq(tm.tm_year, 2);
- }
- END_TEST
-
- START_TEST (test_norm_dates_flags_min)
- {
- struct tm tm;
- int ret;
-
- ttail->flag |= TTAIL_FLAG_DATE_MIN;
- ttail_set_fmt(ttail, "%H %Y");
- tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
- tm.tm_year = 2;
- ttail->date_min = tm;
- ttail->date_max = tm;
-
- ret = ttail_norm_dates(ttail);
- ck_assert_int_eq(ret, 0);
-
- tm = ttail->date_min;
- ck_assert_int_eq(tm.tm_sec, -1);
- ck_assert_int_eq(tm.tm_min, -1);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, -1);
- ck_assert_int_eq(tm.tm_mon, -1);
- ck_assert_int_eq(tm.tm_year, 2);
-
- tm = ttail->date_max;
- ck_assert_int_eq(tm.tm_sec, 2);
- ck_assert_int_eq(tm.tm_min, 2);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, 2);
- ck_assert_int_eq(tm.tm_mon, 2);
- ck_assert_int_eq(tm.tm_year, 2);
- }
- END_TEST
-
- START_TEST (test_norm_dates_flags_max)
- {
- struct tm tm;
- int ret;
-
- ttail->flag |= TTAIL_FLAG_DATE_MAX;
- ttail_set_fmt(ttail, "%H %Y");
- tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
- tm.tm_year = 2;
- ttail->date_min = tm;
- ttail->date_max = tm;
-
- ret = ttail_norm_dates(ttail);
- ck_assert_int_eq(ret, 0);
-
- tm = ttail->date_min;
- ck_assert_int_eq(tm.tm_sec, 2);
- ck_assert_int_eq(tm.tm_min, 2);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, 2);
- ck_assert_int_eq(tm.tm_mon, 2);
- ck_assert_int_eq(tm.tm_year, 2);
-
- tm = ttail->date_max;
- ck_assert_int_eq(tm.tm_sec, -1);
- ck_assert_int_eq(tm.tm_min, -1);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, -1);
- ck_assert_int_eq(tm.tm_mon, -1);
- ck_assert_int_eq(tm.tm_year, 2);
- }
- END_TEST
-
- START_TEST (test_norm_dates_flags_both)
- {
- struct tm tm;
- int ret;
-
- ttail->flag |= TTAIL_FLAG_DATE_MAX;
- ttail->flag |= TTAIL_FLAG_DATE_MIN;
- ttail_set_fmt(ttail, "%H %Y");
- tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
- tm.tm_year = 2;
- ttail->date_min = tm;
- ttail->date_max = tm;
-
- ret = ttail_norm_dates(ttail);
- ck_assert_int_eq(ret, 0);
-
- tm = ttail->date_min;
- ck_assert_int_eq(tm.tm_sec, -1);
- ck_assert_int_eq(tm.tm_min, -1);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, -1);
- ck_assert_int_eq(tm.tm_mon, -1);
- ck_assert_int_eq(tm.tm_year, 2);
-
- tm = ttail->date_max;
- ck_assert_int_eq(tm.tm_sec, -1);
- ck_assert_int_eq(tm.tm_min, -1);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, -1);
- ck_assert_int_eq(tm.tm_mon, -1);
- ck_assert_int_eq(tm.tm_year, 2);
- }
- END_TEST
-
- START_TEST (test_norm_dates_flags_full)
- {
- struct tm tm;
- int ret;
-
- ttail->flag |= TTAIL_FLAG_DATE_MAX;
- ttail->flag |= TTAIL_FLAG_DATE_MIN;
- ttail_set_fmt(ttail, "%Y %m %d %H-%M-%S");
- tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
- tm.tm_year = 2;
- ttail->date_min = tm;
- ttail->date_max = tm;
-
- ret = ttail_norm_dates(ttail);
- ck_assert_int_eq(ret, 0);
-
- tm = ttail->date_min;
- ck_assert_int_eq(tm.tm_sec, 2);
- ck_assert_int_eq(tm.tm_min, 2);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, 2);
- ck_assert_int_eq(tm.tm_mon, 2);
- ck_assert_int_eq(tm.tm_year, 2);
-
- tm = ttail->date_max;
- ck_assert_int_eq(tm.tm_sec, 2);
- ck_assert_int_eq(tm.tm_min, 2);
- ck_assert_int_eq(tm.tm_hour, 2);
- ck_assert_int_eq(tm.tm_mday, 2);
- ck_assert_int_eq(tm.tm_mon, 2);
- ck_assert_int_eq(tm.tm_year, 2);
- }
- END_TEST
-
- TTAIL_CHECK_START("ttail init checks", "ttail_init_check() checks")
- TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail);
- TTAIL_ADD_TEST(test_norm_dates_flags_none);
- TTAIL_ADD_TEST(test_norm_dates_flags_min);
- TTAIL_ADD_TEST(test_norm_dates_flags_max);
- TTAIL_ADD_TEST(test_norm_dates_flags_both);
- TTAIL_ADD_TEST(test_norm_dates_flags_full);
- TTAIL_CHECK_END
|