timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ttail_search_files.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * tests ttail_search_closest_files()
  10. */
  11. START_TEST (test_search_files1)
  12. {
  13. int ret;
  14. size_t i;
  15. struct tm tm;
  16. memset(&tm, 0, sizeof(tm));
  17. for(i=1;i<ttail->logfile_sz;i++)
  18. {
  19. fclose(ttail->logfile[i]);
  20. ttail->logfile[i] = NULL;
  21. }
  22. ttail->flag |= TTAIL_FLAG_PREFIX;
  23. ttail->prefix_sz = 0;
  24. ttail_set_fmt(ttail, "%B%n%d %H:%M");
  25. memcpy(&(ttail->date_min), &tm, sizeof(tm));
  26. ttail->flag |= TTAIL_FLAG_DATE_MIN;
  27. ret = ttail_search_files_init(ttail);
  28. ck_assert_int_eq(ret,0);
  29. ret = _ttail_search_closest_files(ttail);
  30. ck_assert_int_eq(ret, 0);
  31. ck_assert(ttail->session->file.off_min.id == 0);
  32. ck_assert(ttail->session->file.off_min.off == 0);
  33. }
  34. END_TEST
  35. START_TEST (test_search_files2)
  36. {
  37. int ret;
  38. size_t i;
  39. struct tm tm;
  40. memset(&tm, 0, sizeof(tm));
  41. for(i=1;i<ttail->logfile_sz;i++)
  42. {
  43. fclose(ttail->logfile[i]);
  44. ttail->logfile[i] = NULL;
  45. }
  46. ttail->flag |= TTAIL_FLAG_PREFIX;
  47. ttail->prefix_sz = 0;
  48. ttail_set_fmt(ttail, "%B%n%d %H:%M");
  49. tm.tm_year = -1;
  50. tm.tm_mon = 2;
  51. tm.tm_mday = 6;
  52. tm.tm_hour = 0;
  53. tm.tm_min = 29;
  54. tm.tm_sec = -1;
  55. memcpy(&(ttail->date_min), &tm, sizeof(tm));
  56. ttail->flag |= TTAIL_FLAG_DATE_MIN;
  57. ret = ttail_search_files_init(ttail);
  58. ck_assert_int_eq(ret,0);
  59. ret = _ttail_search_closest_files(ttail);
  60. ck_assert_int_eq(ret, 0);
  61. ck_assert(ttail->session->file.off_min.id == 0);
  62. ck_assert_int_eq(ttail->session->file.off_min.off, 221);
  63. }
  64. END_TEST
  65. START_TEST (test_search_files3)
  66. {
  67. int ret;
  68. size_t i;
  69. struct tm tm;
  70. memset(&tm, 0, sizeof(tm));
  71. for(i=1;i<ttail->logfile_sz-1;i++)
  72. {
  73. fclose(ttail->logfile[i]);
  74. ttail->logfile[i] = NULL;
  75. }
  76. ttail->flag |= TTAIL_FLAG_PREFIX;
  77. ttail->prefix_sz = 0;
  78. ttail_set_fmt(ttail, "%B%n%d %H:%M");
  79. tm.tm_year = -1;
  80. tm.tm_mon = 2;
  81. tm.tm_mday = 6;
  82. tm.tm_hour = 1;
  83. tm.tm_min = 0;
  84. tm.tm_sec = -1;
  85. memcpy(&(ttail->date_min), &tm, sizeof(tm));
  86. ttail->flag |= TTAIL_FLAG_DATE_MIN;
  87. ret = ttail_search_files_init(ttail);
  88. ck_assert_int_eq(ret,0);
  89. ret = _ttail_search_closest_files(ttail);
  90. ck_assert_int_eq(ret, 0);
  91. ck_assert_int_eq(ttail->session->file.off_min.id, 5);
  92. ck_assert_int_eq(ttail->session->file.off_min.off, 0);
  93. }
  94. END_TEST
  95. TTAIL_CHECK_START("ttail search_files checks", "ttail_logline2date() checks")
  96. TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
  97. TTAIL_ADD_TEST(test_search_files1);
  98. TTAIL_ADD_TEST(test_search_files2);
  99. TTAIL_ADD_TEST(test_search_files3);
  100. TTAIL_CHECK_END