timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ttail_search_logline2date.c 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_logline2date() checks
  10. */
  11. START_TEST (test_search_log2date1)
  12. {
  13. char re[] = "^[0-9]+ ";
  14. char fmt[] = "%Y-%m-%d:%H:%M";
  15. struct tm tm;
  16. int ret;
  17. ttail_set_flag_re_ex(ttail);
  18. ttail_set_prefix(ttail, re);
  19. ttail_set_fmt(ttail, fmt);
  20. ret = ttail_logline2date(ttail, "1337 1988-10-22:22:10 foobar", &tm);
  21. ck_assert_int_eq(ret, 0);
  22. ck_assert_int_eq(tm.tm_year, 88);
  23. ck_assert_int_eq(tm.tm_mon, 9);
  24. ck_assert_int_eq(tm.tm_mday, 22);
  25. ck_assert_int_eq(tm.tm_hour, 22);
  26. ck_assert_int_eq(tm.tm_min, 10);
  27. }
  28. END_TEST
  29. START_TEST (test_search_log2date_failpref)
  30. {
  31. char re[] = "^[0-9]+aa ";
  32. char fmt[] = "%Y-%m-%d:%H:%M";
  33. struct tm tm;
  34. int ret;
  35. ttail_set_flag_re_ex(ttail);
  36. ttail_set_prefix(ttail, re);
  37. ttail_set_fmt(ttail, fmt);
  38. ret = ttail_logline2date(ttail, "1337 1988-10-22:22:10 foobar", &tm);
  39. ck_assert_int_eq(ret, 1);
  40. ck_assert_int_eq(tm.tm_year, 0);
  41. ck_assert_int_eq(tm.tm_mon, 0);
  42. ck_assert_int_eq(tm.tm_mday, 0);
  43. ck_assert_int_eq(tm.tm_hour, 0);
  44. ck_assert_int_eq(tm.tm_min, 0);
  45. }
  46. END_TEST
  47. START_TEST (test_search_log2date_faildate)
  48. {
  49. char re[] = "^[0-9]+ ";
  50. char fmt[] = "%y-%m-%d:%H:%M";
  51. struct tm tm;
  52. int ret;
  53. ttail_set_flag_re_ex(ttail);
  54. ttail_set_prefix(ttail, re);
  55. ttail_set_fmt(ttail, fmt);
  56. ret = ttail_logline2date(ttail, "1337 1988-10-22:22:10 foobar", &tm);
  57. ck_assert_int_eq(ret, 2);
  58. ck_assert_int_eq(tm.tm_year, 0);
  59. ck_assert_int_eq(tm.tm_mon, 0);
  60. ck_assert_int_eq(tm.tm_mday, 0);
  61. ck_assert_int_eq(tm.tm_hour, 0);
  62. ck_assert_int_eq(tm.tm_min, 0);
  63. }
  64. END_TEST
  65. TTAIL_CHECK_START("ttail search_files checks","ttail_logline2date() checks")
  66. TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
  67. TTAIL_ADD_TEST(test_search_log2date1);
  68. TTAIL_ADD_TEST(test_search_log2date_failpref);
  69. TTAIL_ADD_TEST(test_search_log2date_faildate);
  70. TTAIL_CHECK_END