1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include <check.h>
- #include <stdio.h>
- #include <libgen.h>
-
- #include "ttail_check.h"
- #include "ttail.h"
- #include "ttail_init.h"
- #include "ttail_search.h"
-
- /*
- * _ttail_file_next_line() & _ttail_file_line_start() tests
- */
- START_TEST (test_file_line_next)
- {
- long res;
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == 77);
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == 136);
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == 221);
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == 298);
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == 357);
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == 0);
- res = _ttail_file_next_line(ttail, 0);
- ck_assert(res == -1);
- }
- END_TEST
-
- START_TEST (test_file_line_start)
- {
- long res;
- fseek(ttail->logfile[0], -1, SEEK_END);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 357);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 357);
- fseek(ttail->logfile[0], -1, SEEK_CUR);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 298);
- fseek(ttail->logfile[0], -1, SEEK_CUR);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 221);
- fseek(ttail->logfile[0], -1, SEEK_CUR);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 136);
- fseek(ttail->logfile[0], -1, SEEK_CUR);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 77);
- fseek(ttail->logfile[0], -1, SEEK_CUR);
- res = _ttail_file_start_line(ttail, 0);
- ck_assert(res == 0);
- }
- END_TEST
-
- START_TEST (test_file_line_end)
- {
- long res;
- struct tm tm;
- ttail_search_files_init(ttail);
- tm.tm_sec = 53;
- tm.tm_min = 30;
- tm.tm_hour = 0;
- tm.tm_mday = 6;
- tm.tm_mon = 2;
- res = _ttail_file_search_from_end(ttail, 0, &tm);
- ck_assert_int_eq(res, 357);
- tm.tm_min = 29;
- res = _ttail_file_search_from_end(ttail, 0, &tm);
- ck_assert_int_eq(res, 221);
- tm.tm_min = 0;
- res = _ttail_file_search_from_end(ttail, 0, &tm);
- ck_assert_int_eq(res, 0);
- }
- END_TEST
-
- TTAIL_CHECK_START("ttail search_files checks", "ttail_file_*line*() checks")
- TTAIL_SET_FIXTURE(setup_file_line, teardown_ttail);
- TTAIL_ADD_TEST(test_file_line_next);
- TTAIL_ADD_TEST(test_file_line_start);
- TTAIL_ADD_TEST(test_file_line_end);
- TTAIL_CHECK_END
|