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_init_norm_dates.c 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. START_TEST (test_norm_dates_flags_none)
  9. {
  10. struct tm tm;
  11. int ret;
  12. ttail->flag = 0;
  13. ttail_set_fmt(ttail, "%H %Y");
  14. tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
  15. tm.tm_year = 2;
  16. ttail->date_min = tm;
  17. ttail->date_max = tm;
  18. ret = ttail_norm_dates(ttail);
  19. ck_assert_int_eq(ret, 0);
  20. tm = ttail->date_min;
  21. ck_assert_int_eq(tm.tm_sec, 2);
  22. ck_assert_int_eq(tm.tm_min, 2);
  23. ck_assert_int_eq(tm.tm_hour, 2);
  24. ck_assert_int_eq(tm.tm_mday, 2);
  25. ck_assert_int_eq(tm.tm_mon, 2);
  26. ck_assert_int_eq(tm.tm_year, 2);
  27. tm = ttail->date_max;
  28. ck_assert_int_eq(tm.tm_sec, 2);
  29. ck_assert_int_eq(tm.tm_min, 2);
  30. ck_assert_int_eq(tm.tm_hour, 2);
  31. ck_assert_int_eq(tm.tm_mday, 2);
  32. ck_assert_int_eq(tm.tm_mon, 2);
  33. ck_assert_int_eq(tm.tm_year, 2);
  34. }
  35. END_TEST
  36. START_TEST (test_norm_dates_flags_min)
  37. {
  38. struct tm tm;
  39. int ret;
  40. ttail->flag |= TTAIL_FLAG_DATE_MIN;
  41. ttail_set_fmt(ttail, "%H %Y");
  42. tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
  43. tm.tm_year = 2;
  44. ttail->date_min = tm;
  45. ttail->date_max = tm;
  46. ret = ttail_norm_dates(ttail);
  47. ck_assert_int_eq(ret, 0);
  48. tm = ttail->date_min;
  49. ck_assert_int_eq(tm.tm_sec, -1);
  50. ck_assert_int_eq(tm.tm_min, -1);
  51. ck_assert_int_eq(tm.tm_hour, 2);
  52. ck_assert_int_eq(tm.tm_mday, -1);
  53. ck_assert_int_eq(tm.tm_mon, -1);
  54. ck_assert_int_eq(tm.tm_year, 2);
  55. tm = ttail->date_max;
  56. ck_assert_int_eq(tm.tm_sec, 2);
  57. ck_assert_int_eq(tm.tm_min, 2);
  58. ck_assert_int_eq(tm.tm_hour, 2);
  59. ck_assert_int_eq(tm.tm_mday, 2);
  60. ck_assert_int_eq(tm.tm_mon, 2);
  61. ck_assert_int_eq(tm.tm_year, 2);
  62. }
  63. END_TEST
  64. START_TEST (test_norm_dates_flags_max)
  65. {
  66. struct tm tm;
  67. int ret;
  68. ttail->flag |= TTAIL_FLAG_DATE_MAX;
  69. ttail_set_fmt(ttail, "%H %Y");
  70. tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
  71. tm.tm_year = 2;
  72. ttail->date_min = tm;
  73. ttail->date_max = tm;
  74. ret = ttail_norm_dates(ttail);
  75. ck_assert_int_eq(ret, 0);
  76. tm = ttail->date_min;
  77. ck_assert_int_eq(tm.tm_sec, 2);
  78. ck_assert_int_eq(tm.tm_min, 2);
  79. ck_assert_int_eq(tm.tm_hour, 2);
  80. ck_assert_int_eq(tm.tm_mday, 2);
  81. ck_assert_int_eq(tm.tm_mon, 2);
  82. ck_assert_int_eq(tm.tm_year, 2);
  83. tm = ttail->date_max;
  84. ck_assert_int_eq(tm.tm_sec, -1);
  85. ck_assert_int_eq(tm.tm_min, -1);
  86. ck_assert_int_eq(tm.tm_hour, 2);
  87. ck_assert_int_eq(tm.tm_mday, -1);
  88. ck_assert_int_eq(tm.tm_mon, -1);
  89. ck_assert_int_eq(tm.tm_year, 2);
  90. }
  91. END_TEST
  92. START_TEST (test_norm_dates_flags_both)
  93. {
  94. struct tm tm;
  95. int ret;
  96. ttail->flag |= TTAIL_FLAG_DATE_MAX;
  97. ttail->flag |= TTAIL_FLAG_DATE_MIN;
  98. ttail_set_fmt(ttail, "%H %Y");
  99. tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
  100. tm.tm_year = 2;
  101. ttail->date_min = tm;
  102. ttail->date_max = tm;
  103. ret = ttail_norm_dates(ttail);
  104. ck_assert_int_eq(ret, 0);
  105. tm = ttail->date_min;
  106. ck_assert_int_eq(tm.tm_sec, -1);
  107. ck_assert_int_eq(tm.tm_min, -1);
  108. ck_assert_int_eq(tm.tm_hour, 2);
  109. ck_assert_int_eq(tm.tm_mday, -1);
  110. ck_assert_int_eq(tm.tm_mon, -1);
  111. ck_assert_int_eq(tm.tm_year, 2);
  112. tm = ttail->date_max;
  113. ck_assert_int_eq(tm.tm_sec, -1);
  114. ck_assert_int_eq(tm.tm_min, -1);
  115. ck_assert_int_eq(tm.tm_hour, 2);
  116. ck_assert_int_eq(tm.tm_mday, -1);
  117. ck_assert_int_eq(tm.tm_mon, -1);
  118. ck_assert_int_eq(tm.tm_year, 2);
  119. }
  120. END_TEST
  121. START_TEST (test_norm_dates_flags_full)
  122. {
  123. struct tm tm;
  124. int ret;
  125. ttail->flag |= TTAIL_FLAG_DATE_MAX;
  126. ttail->flag |= TTAIL_FLAG_DATE_MIN;
  127. ttail_set_fmt(ttail, "%Y %m %d %H-%M-%S");
  128. tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
  129. tm.tm_year = 2;
  130. ttail->date_min = tm;
  131. ttail->date_max = tm;
  132. ret = ttail_norm_dates(ttail);
  133. ck_assert_int_eq(ret, 0);
  134. tm = ttail->date_min;
  135. ck_assert_int_eq(tm.tm_sec, 2);
  136. ck_assert_int_eq(tm.tm_min, 2);
  137. ck_assert_int_eq(tm.tm_hour, 2);
  138. ck_assert_int_eq(tm.tm_mday, 2);
  139. ck_assert_int_eq(tm.tm_mon, 2);
  140. ck_assert_int_eq(tm.tm_year, 2);
  141. tm = ttail->date_max;
  142. ck_assert_int_eq(tm.tm_sec, 2);
  143. ck_assert_int_eq(tm.tm_min, 2);
  144. ck_assert_int_eq(tm.tm_hour, 2);
  145. ck_assert_int_eq(tm.tm_mday, 2);
  146. ck_assert_int_eq(tm.tm_mon, 2);
  147. ck_assert_int_eq(tm.tm_year, 2);
  148. }
  149. END_TEST
  150. TTAIL_CHECK_START("ttail init checks", "ttail_init_check() checks")
  151. TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail);
  152. TTAIL_ADD_TEST(test_norm_dates_flags_none);
  153. TTAIL_ADD_TEST(test_norm_dates_flags_min);
  154. TTAIL_ADD_TEST(test_norm_dates_flags_max);
  155. TTAIL_ADD_TEST(test_norm_dates_flags_both);
  156. TTAIL_ADD_TEST(test_norm_dates_flags_full);
  157. TTAIL_CHECK_END