Add tests for _ttail_norm_dates
This commit is contained in:
parent
22183a4d4b
commit
3a4fe6be94
2 changed files with 199 additions and 2 deletions
|
|
@ -290,7 +290,7 @@ int _ttail_set_date_fmt(ttail_t*, char*, int);
|
|||
*/
|
||||
int _ttail_set_date_relative(ttail_t*, char*, int);
|
||||
|
||||
/**@brief Normalize dates
|
||||
/**@brief Normalize dates using ttail.fmt
|
||||
*
|
||||
*When dates are relatives from now all the struct tm fields are set. In
|
||||
*logfiles year or seconds can be missing from date format. In those case we
|
||||
|
|
@ -299,7 +299,6 @@ int _ttail_set_date_relative(ttail_t*, char*, int);
|
|||
*ttail_format_guess() calls
|
||||
*@param ttail_t* An initialized ttail_t
|
||||
*@return -1 if error 0 else
|
||||
*@todo checks
|
||||
*/
|
||||
int _ttail_norm_dates(ttail_t*);
|
||||
|
||||
|
|
|
|||
198
tests/ttail_init_norm_dates.c
Normal file
198
tests/ttail_init_norm_dates.c
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
#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
|
||||
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_init_norm_dates;
|
||||
|
||||
s = suite_create("ttail init checks");
|
||||
|
||||
tc_init_norm_dates = tcase_create("ttail_init_check() checks");
|
||||
tcase_add_checked_fixture(tc_init_norm_dates,
|
||||
setup_ttail_empty, teardown_ttail);
|
||||
tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_none);
|
||||
tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_min);
|
||||
tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_max);
|
||||
tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_both);
|
||||
tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_full);
|
||||
|
||||
suite_add_tcase(s, tc_init_norm_dates);
|
||||
return s;
|
||||
}
|
||||
|
||||
TTAIL_CHECK_MAIN(ttail_init_suite)
|
||||
Loading…
Add table
Add a link
Reference in a new issue