123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include <check.h>
- #include <stdio.h>
- #include <libgen.h>
-
- #include "ttail_check.h"
- #include "ttail.h"
- #include "ttail_init.h"
- #include "ttail_search.h"
-
- /*
- * tests ttail_search_closest_files()
- */
-
- START_TEST (test_search_files1)
- {
- int ret;
- size_t i;
- struct tm tm;
- memset(&tm, 0, sizeof(tm));
- for(i=1;i<ttail->logfile_sz;i++)
- {
- fclose(ttail->logfile[i]);
- ttail->logfile[i] = NULL;
- }
- ttail->flag |= TTAIL_FLAG_PREFIX;
- ttail->prefix_sz = 0;
- ttail_set_fmt(ttail, "%B%n%d %H:%M");
- memcpy(&(ttail->date_min), &tm, sizeof(tm));
- ttail->flag |= TTAIL_FLAG_DATE_MIN;
-
- ret = ttail_search_files_init(ttail);
- ck_assert_int_eq(ret,0);
-
- ret = _ttail_search_closest_files(ttail);
- ck_assert_int_eq(ret, 0);
- ck_assert(ttail->session->file.off_min.id == 0);
- ck_assert(ttail->session->file.off_min.off == 0);
- }
- END_TEST
-
- START_TEST (test_search_files2)
- {
- int ret;
- size_t i;
- struct tm tm;
- memset(&tm, 0, sizeof(tm));
- for(i=1;i<ttail->logfile_sz;i++)
- {
- fclose(ttail->logfile[i]);
- ttail->logfile[i] = NULL;
- }
- ttail->flag |= TTAIL_FLAG_PREFIX;
- ttail->prefix_sz = 0;
- ttail_set_fmt(ttail, "%B%n%d %H:%M");
-
- tm.tm_year = -1;
- tm.tm_mon = 2;
- tm.tm_mday = 6;
- tm.tm_hour = 0;
- tm.tm_min = 29;
- tm.tm_sec = -1;
- memcpy(&(ttail->date_min), &tm, sizeof(tm));
- ttail->flag |= TTAIL_FLAG_DATE_MIN;
-
- ret = ttail_search_files_init(ttail);
- ck_assert_int_eq(ret,0);
-
- ret = _ttail_search_closest_files(ttail);
- ck_assert_int_eq(ret, 0);
- ck_assert(ttail->session->file.off_min.id == 0);
- ck_assert_int_eq(ttail->session->file.off_min.off, 221);
- }
- END_TEST
-
- START_TEST (test_search_files3)
- {
- int ret;
- size_t i;
- struct tm tm;
- memset(&tm, 0, sizeof(tm));
- for(i=1;i<ttail->logfile_sz-1;i++)
- {
- fclose(ttail->logfile[i]);
- ttail->logfile[i] = NULL;
- }
- ttail->flag |= TTAIL_FLAG_PREFIX;
- ttail->prefix_sz = 0;
- ttail_set_fmt(ttail, "%B%n%d %H:%M");
-
- tm.tm_year = -1;
- tm.tm_mon = 2;
- tm.tm_mday = 6;
- tm.tm_hour = 1;
- tm.tm_min = 0;
- tm.tm_sec = -1;
- memcpy(&(ttail->date_min), &tm, sizeof(tm));
- ttail->flag |= TTAIL_FLAG_DATE_MIN;
-
- ret = ttail_search_files_init(ttail);
- ck_assert_int_eq(ret,0);
-
- ret = _ttail_search_closest_files(ttail);
- ck_assert_int_eq(ret, 0);
- ck_assert_int_eq(ttail->session->file.off_min.id, 1);
- ck_assert_int_eq(ttail->session->file.off_min.off, 0);
- }
- END_TEST
-
- TTAIL_CHECK_START("ttail search_files checks", "ttail_logline2date() checks")
- TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
- TTAIL_ADD_TEST(test_search_files1);
- TTAIL_ADD_TEST(test_search_files2);
- TTAIL_ADD_TEST(test_search_files3);
- TTAIL_CHECK_END
|