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_init_format_guess.c 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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(ttail, "1988/10/22", &tm);
  17. ck_assert_int_ne(ret, -1);
  18. ck_assert_str_eq(fmt[ret], res);
  19. ck_assert(ttail->fmt != NULL);
  20. ck_assert_str_eq(ttail->fmt, res);
  21. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  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, 0);
  26. ck_assert_int_eq(tm.tm_min, 0);
  27. ck_assert_int_eq(tm.tm_sec, 0);
  28. }
  29. END_TEST
  30. START_TEST (test_init_guess_datetime)
  31. {
  32. int ret;
  33. struct tm tm;
  34. char res[] = "%Y/%m/%d:%H:%M";
  35. ret = ttail_format_guess(ttail, "1988/10/22:22:10:00", &tm);
  36. ck_assert_int_ne(ret, -1);
  37. ck_assert_str_eq(fmt[ret], res);
  38. ck_assert(ttail->fmt != NULL);
  39. ck_assert_str_eq(ttail->fmt, res);
  40. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  41. ck_assert_int_eq(tm.tm_year, 88);
  42. ck_assert_int_eq(tm.tm_mon, 9);
  43. ck_assert_int_eq(tm.tm_mday, 22);
  44. ck_assert_int_eq(tm.tm_hour, 22);
  45. ck_assert_int_eq(tm.tm_min, 10);
  46. ck_assert_int_eq(tm.tm_sec, 0);
  47. }
  48. END_TEST
  49. START_TEST (test_init_guess_datetime2)
  50. {
  51. int ret;
  52. struct tm tm;
  53. char res[] = "%B%n%d %H:%M:%S";
  54. ret = ttail_format_guess(ttail, "Mar 6 00:01:39 pilgrim dhclient", &tm);
  55. ck_assert_int_ne(ret, -1);
  56. ck_assert_str_eq(fmt[ret], res);
  57. ck_assert(ttail->fmt != NULL);
  58. ck_assert_str_eq(ttail->fmt, res);
  59. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  60. ck_assert_int_eq(tm.tm_year, 0);
  61. ck_assert_int_eq(tm.tm_mon, 2);
  62. ck_assert_int_eq(tm.tm_mday, 6);
  63. ck_assert_int_eq(tm.tm_hour, 0);
  64. ck_assert_int_eq(tm.tm_min, 1);
  65. ck_assert_int_eq(tm.tm_sec, 39);
  66. }
  67. END_TEST
  68. START_TEST (test_init_guess_noguess)
  69. {
  70. int ret;
  71. struct tm tm;
  72. ret = ttail_format_guess(ttail, "notadate", &tm);
  73. ck_assert_int_eq(ret, -1);
  74. ck_assert(ttail->fmt == NULL);
  75. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
  76. ck_assert_int_eq(tm.tm_year, 0);
  77. ck_assert_int_eq(tm.tm_mon, 0);
  78. ck_assert_int_eq(tm.tm_mday, 0);
  79. ck_assert_int_eq(tm.tm_hour, 0);
  80. ck_assert_int_eq(tm.tm_min, 0);
  81. ck_assert_int_eq(tm.tm_sec, 0);
  82. }
  83. END_TEST
  84. START_TEST (test_init_guess_date_notm)
  85. {
  86. int ret;
  87. char res[] = "%Y/%m/%d";
  88. ret = ttail_format_guess(ttail, "1988/10/22", NULL);
  89. ck_assert_int_ne(ret, -1);
  90. ck_assert_str_eq(fmt[ret], res);
  91. ck_assert(ttail->fmt != NULL);
  92. ck_assert_str_eq(ttail->fmt, res);
  93. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  94. }
  95. END_TEST
  96. START_TEST (test_init_guess_noguess_notm)
  97. {
  98. int ret;
  99. struct tm tm;
  100. ret = ttail_format_guess(ttail, "notadate", &tm);
  101. ck_assert_int_eq(ret, -1);
  102. ck_assert(ttail->fmt == NULL);
  103. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
  104. }
  105. END_TEST
  106. START_TEST (test_init_guess_fmt_set)
  107. {
  108. int ret;
  109. char res[] = "%Y/%m/%d";
  110. ret = ttail_format_guess(ttail, "1988/10/22", NULL);
  111. ck_assert_str_eq(fmt[ret], res);
  112. ret = ttail_format_guess(ttail, "1988/10/22", NULL);
  113. ck_assert_int_eq(ret, -2);
  114. ck_assert_str_eq(ttail->fmt, res);
  115. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  116. }
  117. END_TEST
  118. TTAIL_CHECK_START("ttail init checks", "date format guess init checks")
  119. TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail);
  120. TTAIL_ADD_TEST(test_init_guess_date);
  121. TTAIL_ADD_TEST(test_init_guess_datetime);
  122. TTAIL_ADD_TEST(test_init_guess_datetime2);
  123. TTAIL_ADD_TEST(test_init_guess_noguess);
  124. TTAIL_ADD_TEST(test_init_guess_date_notm);
  125. TTAIL_ADD_TEST(test_init_guess_noguess_notm);
  126. TTAIL_ADD_TEST(test_init_guess_fmt_set);
  127. TTAIL_CHECK_END