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