#include #include #include #include #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