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_logline2date.c 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. Suite * ttail_search_files_suite(void)
  66. {
  67. Suite *s;
  68. TCase *tc_search_logline2date;
  69. s = suite_create("ttail search_files checks");
  70. tc_search_logline2date = tcase_create("ttail_logline2date() checks");
  71. tcase_add_checked_fixture(tc_search_logline2date,
  72. setup_closest_fileinit, teardown_closest_fileinit);
  73. tcase_add_test(tc_search_logline2date, test_search_log2date1);
  74. tcase_add_test(tc_search_logline2date, test_search_log2date_failpref);
  75. tcase_add_test(tc_search_logline2date, test_search_log2date_faildate);
  76. suite_add_tcase(s, tc_search_logline2date);
  77. return s;
  78. }
  79. TTAIL_CHECK_MAIN(ttail_search_files_suite)