#include #include #include #include #include "ttail_check.h" #include "ttail.h" #include "ttail_init.h" /* * ttail_set_dates() tests */ START_TEST (test_init_setdates_nothing) { int ret; char *arg[] = {NULL, NULL}; struct tm zero; memset(&zero, -1, sizeof(struct tm)); ret = ttail_set_dates(ttail, arg); ck_assert_int_eq(ret, 0); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0); ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0); ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0); } END_TEST START_TEST (test_init_setdates_nofmt_min) { int ret; char *arg[] = {"88/10/22", NULL}; struct tm zero; char *arg0; arg0 = malloc(sizeof(char)*(strlen(arg[0])+1)); if(!arg0) { perror("Malloc failed for argument"); ck_abort_msg("Unable to allocate memory"); } strcpy(arg0, arg[0]); arg[0]=arg0; memset(&zero, -1, sizeof(struct tm)); ret = ttail_set_dates(ttail, arg); ck_assert_int_eq(ret, 0); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0); ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0); ck_assert_int_eq(ttail->date_min.tm_year, 88); ck_assert_int_eq(ttail->date_min.tm_mon, 9); ck_assert_int_eq(ttail->date_min.tm_mday, 22); ck_assert_int_eq(ttail->date_min.tm_hour, 0); ck_assert_int_eq(ttail->date_min.tm_min, 0); ck_assert_int_eq(ttail->date_min.tm_sec, 0); } END_TEST START_TEST (test_init_setdates_nofmt_max) { int ret; char *arg[] = {NULL, "88/10/22"}; struct tm zero; char *arg1; arg1 = malloc(sizeof(char)*(strlen(arg[1])+1)); if(!arg1) { perror("Malloc failed for argument"); ck_abort_msg("Unable to allocate memory"); } strcpy(arg1, arg[1]); arg[1]=arg1; memset(&zero, -1, sizeof(struct tm)); ret = ttail_set_dates(ttail, arg); ck_assert_int_eq(ret, 0); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX); ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0); ck_assert_int_eq(ttail->date_max.tm_year, 88); ck_assert_int_eq(ttail->date_max.tm_mon, 9); ck_assert_int_eq(ttail->date_max.tm_mday, 22); ck_assert_int_eq(ttail->date_max.tm_hour, 0); ck_assert_int_eq(ttail->date_max.tm_min, 0); ck_assert_int_eq(ttail->date_max.tm_sec, 0); } END_TEST START_TEST (test_init_setdates_nofmt_both) { int ret; char *arg[] = {"1988/10/22", "2088/10/22"}; struct tm zero; char *arg0, *arg1; arg0 = malloc(sizeof(char)*(strlen(arg[0])+1)); if(!arg0) { perror("Malloc failed for argument"); ck_abort_msg("Unable to allocate memory"); } strcpy(arg0, arg[0]); arg[0]=arg0; arg1 = malloc(sizeof(char)*(strlen(arg[1])+1)); if(!arg1) { perror("Malloc failed for argument"); ck_abort_msg("Unable to allocate memory"); } strcpy(arg1, arg[1]); arg[1]=arg1; memset(&zero, 0, sizeof(struct tm)); ret = ttail_set_dates(ttail, arg); ck_assert_int_eq(ret, 0); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN); ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX); ck_assert_int_eq(ttail->date_min.tm_year, 88); ck_assert_int_eq(ttail->date_min.tm_mon, 9); ck_assert_int_eq(ttail->date_min.tm_mday, 22); ck_assert_int_eq(ttail->date_min.tm_hour, 0); ck_assert_int_eq(ttail->date_min.tm_min, 0); ck_assert_int_eq(ttail->date_min.tm_sec, 0); ck_assert_int_eq(ttail->date_max.tm_year, 188); ck_assert_int_eq(ttail->date_max.tm_mon, 9); ck_assert_int_eq(ttail->date_max.tm_mday, 22); ck_assert_int_eq(ttail->date_max.tm_hour, -1); ck_assert_int_eq(ttail->date_max.tm_min, -1); ck_assert_int_eq(ttail->date_max.tm_sec, -1); } END_TEST TTAIL_CHECK_START("ttail init checks", "dates min/max init checks") TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail); TTAIL_ADD_TEST(test_init_setdates_nothing); TTAIL_ADD_TEST(test_init_setdates_nofmt_min); TTAIL_ADD_TEST(test_init_setdates_nofmt_max); TTAIL_ADD_TEST(test_init_setdates_nofmt_both); TTAIL_CHECK_END