timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ttail_search_tm_cmp.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <check.h>
  2. #include <stdio.h>
  3. #include "ttail_check.h"
  4. #include "ttail.h"
  5. #include "ttail_init.h"
  6. #include "ttail_search.h"
  7. #define TTAIL_TM_CMP_INIT \
  8. struct tm a, b;\
  9. int ret;\
  10. ttail_tm_init(&a);\
  11. ttail_tm_init(&b);\
  12. START_TEST (test_tm_cmp_init)
  13. {
  14. TTAIL_TM_CMP_INIT
  15. ret = ttail_tm_cmp(&a, &b);
  16. ck_assert_int_eq(ret, 0);
  17. }
  18. END_TEST
  19. START_TEST (test_tm_cmp_field_priority)
  20. {
  21. TTAIL_TM_CMP_INIT
  22. a.tm_sec = 42;
  23. b.tm_sec = 41;
  24. ret = ttail_tm_cmp(&a, &b);
  25. ck_assert_int_gt(ret, 0);
  26. a.tm_min = 41;
  27. b.tm_min = 42;
  28. ret = ttail_tm_cmp(&a, &b);
  29. ck_assert_int_lt(ret, 0);
  30. a.tm_hour = 42;
  31. b.tm_hour = 41;
  32. ret = ttail_tm_cmp(&a, &b);
  33. ck_assert_int_gt(ret, 0);
  34. a.tm_mday = 21;
  35. b.tm_mday = 22;
  36. ret = ttail_tm_cmp(&a, &b);
  37. ck_assert_int_lt(ret, 0);
  38. a.tm_mon = 10;
  39. b.tm_mon = 9;
  40. ret = ttail_tm_cmp(&a, &b);
  41. ck_assert_int_gt(ret, 0);
  42. a.tm_year = 14;
  43. b.tm_year = 15;
  44. ret = ttail_tm_cmp(&a, &b);
  45. ck_assert_int_lt(ret, 0);
  46. }
  47. END_TEST
  48. START_TEST (test_tm_cmp_empty_fields1)
  49. {
  50. TTAIL_TM_CMP_INIT
  51. a.tm_sec = 42;
  52. b.tm_min = 41;
  53. a.tm_hour = 1;
  54. b.tm_hour = 1;
  55. ret = ttail_tm_cmp(&a, &b);
  56. ck_assert_int_eq(ret, 0);
  57. }
  58. END_TEST
  59. START_TEST (test_tm_cmp_empty_fields2)
  60. {
  61. TTAIL_TM_CMP_INIT
  62. a.tm_sec = 42;
  63. b.tm_min = 41;
  64. b.tm_hour = 1;
  65. b.tm_mday = 6;
  66. b.tm_mon = 7;
  67. b.tm_year = 15;
  68. ret = ttail_tm_cmp(&a, &b);
  69. ck_assert_int_eq(ret, 0);
  70. }
  71. END_TEST
  72. START_TEST (test_tm_cmp_empty_fields3)
  73. {
  74. TTAIL_TM_CMP_INIT
  75. a.tm_sec = 42;
  76. b.tm_sec = 55;
  77. b.tm_min = 41;
  78. b.tm_hour = 1;
  79. b.tm_mday = 6;
  80. b.tm_mon = 7;
  81. b.tm_year = 15;
  82. ret = ttail_tm_cmp(&a, &b);
  83. ck_assert_int_lt(ret, 0);
  84. }
  85. END_TEST
  86. START_TEST (test_tm_cmp_empty_fields4)
  87. {
  88. TTAIL_TM_CMP_INIT
  89. b.tm_sec = 42;
  90. a.tm_min = 41;
  91. a.tm_hour = 1;
  92. a.tm_mday = 6;
  93. a.tm_mon = 7;
  94. a.tm_year = 15;
  95. ret = ttail_tm_cmp(&a, &b);
  96. ck_assert_int_eq(ret, 0);
  97. }
  98. END_TEST
  99. TTAIL_CHECK_START("ttail search functions checks", "ttail_tm_cmp() checks")
  100. TTAIL_ADD_TEST(test_tm_cmp_init);
  101. TTAIL_ADD_TEST(test_tm_cmp_field_priority);
  102. TTAIL_ADD_TEST(test_tm_cmp_empty_fields1);
  103. TTAIL_ADD_TEST(test_tm_cmp_empty_fields2);
  104. TTAIL_ADD_TEST(test_tm_cmp_empty_fields3);
  105. TTAIL_ADD_TEST(test_tm_cmp_empty_fields4);
  106. TTAIL_CHECK_END