timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_search_file_line.c 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <check.h>
  2. #include <stdio.h>
  3. #include <libgen.h>
  4. #include "ttail_check.h"
  5. #include "ttail.h"
  6. #include "ttail_init.h"
  7. #include "ttail_search.h"
  8. /*
  9. * _ttail_file_next_line() & _ttail_file_line_start() tests
  10. */
  11. START_TEST (test_file_line_next)
  12. {
  13. long res;
  14. res = _ttail_file_next_line(ttail, 0);
  15. ck_assert(res == 77);
  16. res = _ttail_file_next_line(ttail, 0);
  17. ck_assert(res == 136);
  18. res = _ttail_file_next_line(ttail, 0);
  19. ck_assert(res == 221);
  20. res = _ttail_file_next_line(ttail, 0);
  21. ck_assert(res == 298);
  22. res = _ttail_file_next_line(ttail, 0);
  23. ck_assert(res == 357);
  24. res = _ttail_file_next_line(ttail, 0);
  25. ck_assert(res == 0);
  26. res = _ttail_file_next_line(ttail, 0);
  27. ck_assert(res == -1);
  28. }
  29. END_TEST
  30. START_TEST (test_file_line_start)
  31. {
  32. long res;
  33. fseek(ttail->logfile[0], -1, SEEK_END);
  34. res = _ttail_file_start_line(ttail, 0);
  35. ck_assert(res == 357);
  36. res = _ttail_file_start_line(ttail, 0);
  37. ck_assert(res == 357);
  38. fseek(ttail->logfile[0], -1, SEEK_CUR);
  39. res = _ttail_file_start_line(ttail, 0);
  40. ck_assert(res == 298);
  41. fseek(ttail->logfile[0], -1, SEEK_CUR);
  42. res = _ttail_file_start_line(ttail, 0);
  43. ck_assert(res == 221);
  44. fseek(ttail->logfile[0], -1, SEEK_CUR);
  45. res = _ttail_file_start_line(ttail, 0);
  46. ck_assert(res == 136);
  47. fseek(ttail->logfile[0], -1, SEEK_CUR);
  48. res = _ttail_file_start_line(ttail, 0);
  49. ck_assert(res == 77);
  50. fseek(ttail->logfile[0], -1, SEEK_CUR);
  51. res = _ttail_file_start_line(ttail, 0);
  52. ck_assert(res == 0);
  53. }
  54. END_TEST
  55. START_TEST (test_file_line_end)
  56. {
  57. long res;
  58. struct tm tm;
  59. ttail_search_files_init(ttail);
  60. tm.tm_sec = 53;
  61. tm.tm_min = 30;
  62. tm.tm_hour = 0;
  63. tm.tm_mday = 6;
  64. tm.tm_mon = 2;
  65. res = _ttail_file_search_from_end(ttail, 0, &tm);
  66. ck_assert_int_eq(res, 357);
  67. tm.tm_min = 29;
  68. res = _ttail_file_search_from_end(ttail, 0, &tm);
  69. ck_assert_int_eq(res, 221);
  70. tm.tm_min = 0;
  71. res = _ttail_file_search_from_end(ttail, 0, &tm);
  72. ck_assert_int_eq(res, 0);
  73. }
  74. END_TEST
  75. TTAIL_CHECK_START("ttail search_files checks", "ttail_file_*line*() checks")
  76. TTAIL_SET_FIXTURE(setup_file_line, teardown_ttail);
  77. TTAIL_ADD_TEST(test_file_line_next);
  78. TTAIL_ADD_TEST(test_file_line_start);
  79. TTAIL_ADD_TEST(test_file_line_end);
  80. TTAIL_CHECK_END