timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
Ви не можете вибрати більше 25 тем Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_init_format_guess.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <check.h>
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include "ttail_check.h"
  6. #include "ttail.h"
  7. #include "ttail_init.h"
  8. /*
  9. * ttail_format_guess() tests
  10. */
  11. START_TEST (test_init_guess_date)
  12. {
  13. int ret;
  14. struct tm tm;
  15. char res[] = "%Y/%m/%d";
  16. ret = ttail_format_guess("1988/10/22", &tm);
  17. ck_assert_int_ne(ret, -1);
  18. ck_assert_str_eq(fmt[ret], res);
  19. ck_assert_int_eq(tm.tm_year, 88);
  20. ck_assert_int_eq(tm.tm_mon, 9);
  21. ck_assert_int_eq(tm.tm_mday, 22);
  22. ck_assert_int_eq(tm.tm_hour, 0);
  23. ck_assert_int_eq(tm.tm_min, 0);
  24. ck_assert_int_eq(tm.tm_sec, 0);
  25. }
  26. END_TEST
  27. START_TEST (test_init_guess_datetime)
  28. {
  29. int ret;
  30. struct tm tm;
  31. char res[] = "%Y/%m/%d:%H:%M";
  32. ret = ttail_format_guess("1988/10/22:22:10:00", &tm);
  33. ck_assert_int_ne(ret, -1);
  34. ck_assert_str_eq(fmt[ret], res);
  35. ck_assert_int_eq(tm.tm_year, 88);
  36. ck_assert_int_eq(tm.tm_mon, 9);
  37. ck_assert_int_eq(tm.tm_mday, 22);
  38. ck_assert_int_eq(tm.tm_hour, 22);
  39. ck_assert_int_eq(tm.tm_min, 10);
  40. ck_assert_int_eq(tm.tm_sec, 0);
  41. }
  42. END_TEST
  43. START_TEST (test_init_guess_datetime2)
  44. {
  45. int ret;
  46. struct tm tm;
  47. char res[] = "%B%n%d %H:%M:%S";
  48. ret = ttail_format_guess("Mar 6 00:01:39 pilgrim dhclient", &tm);
  49. ck_assert_int_ne(ret, -1);
  50. ck_assert_str_eq(fmt[ret], res);
  51. ck_assert_int_eq(tm.tm_year, 0);
  52. ck_assert_int_eq(tm.tm_mon, 2);
  53. ck_assert_int_eq(tm.tm_mday, 6);
  54. ck_assert_int_eq(tm.tm_hour, 0);
  55. ck_assert_int_eq(tm.tm_min, 1);
  56. ck_assert_int_eq(tm.tm_sec, 39);
  57. }
  58. END_TEST
  59. START_TEST (test_init_guess_noguess)
  60. {
  61. int ret;
  62. struct tm tm;
  63. ret = ttail_format_guess("notadate", &tm);
  64. ck_assert_int_eq(ret, -1);
  65. ck_assert_int_eq(tm.tm_year, 0);
  66. ck_assert_int_eq(tm.tm_mon, 0);
  67. ck_assert_int_eq(tm.tm_mday, 0);
  68. ck_assert_int_eq(tm.tm_hour, 0);
  69. ck_assert_int_eq(tm.tm_min, 0);
  70. ck_assert_int_eq(tm.tm_sec, 0);
  71. }
  72. END_TEST
  73. START_TEST (test_init_guess_date_notm)
  74. {
  75. int ret;
  76. char res[] = "%Y/%m/%d";
  77. ret = ttail_format_guess("1988/10/22", NULL);
  78. ck_assert_int_ne(ret, -1);
  79. ck_assert_str_eq(fmt[ret], res);
  80. }
  81. END_TEST
  82. START_TEST (test_init_guess_noguess_notm)
  83. {
  84. int ret;
  85. struct tm tm;
  86. ret = ttail_format_guess("notadate", &tm);
  87. ck_assert_int_eq(ret, -1);
  88. ck_assert(ttail->fmt == NULL);
  89. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
  90. }
  91. END_TEST
  92. TTAIL_CHECK_START("ttail init checks", "date format guess init checks")
  93. TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail);
  94. TTAIL_ADD_TEST(test_init_guess_date);
  95. TTAIL_ADD_TEST(test_init_guess_datetime);
  96. TTAIL_ADD_TEST(test_init_guess_datetime2);
  97. TTAIL_ADD_TEST(test_init_guess_noguess);
  98. TTAIL_ADD_TEST(test_init_guess_date_notm);
  99. TTAIL_ADD_TEST(test_init_guess_noguess_notm);
  100. TTAIL_CHECK_END