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_set_dates.c 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_set_dates() tests
  10. */
  11. START_TEST (test_init_setdates_nothing)
  12. {
  13. int ret;
  14. char *arg[] = {NULL, NULL};
  15. struct tm zero;
  16. memset(&zero, -1, sizeof(struct tm));
  17. ret = ttail_set_dates(ttail, arg);
  18. ck_assert_int_eq(ret, 0);
  19. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
  20. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
  21. ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
  22. ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
  23. }
  24. END_TEST
  25. START_TEST (test_init_setdates_nofmt_min)
  26. {
  27. int ret;
  28. char *arg[] = {"88/10/22", NULL};
  29. struct tm zero;
  30. char *arg0;
  31. arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
  32. if(!arg0)
  33. {
  34. perror("Malloc failed for argument");
  35. ck_abort_msg("Unable to allocate memory");
  36. }
  37. strcpy(arg0, arg[0]);
  38. arg[0]=arg0;
  39. memset(&zero, -1, sizeof(struct tm));
  40. ret = ttail_set_dates(ttail, arg);
  41. ck_assert_int_eq(ret, 0);
  42. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
  43. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
  44. ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
  45. ck_assert_int_eq(ttail->date_min.tm_year, 88);
  46. ck_assert_int_eq(ttail->date_min.tm_mon, 9);
  47. ck_assert_int_eq(ttail->date_min.tm_mday, 22);
  48. ck_assert_int_eq(ttail->date_min.tm_hour, 0);
  49. ck_assert_int_eq(ttail->date_min.tm_min, 0);
  50. ck_assert_int_eq(ttail->date_min.tm_sec, 0);
  51. }
  52. END_TEST
  53. START_TEST (test_init_setdates_nofmt_max)
  54. {
  55. int ret;
  56. char *arg[] = {NULL, "88/10/22"};
  57. struct tm zero;
  58. char *arg1;
  59. arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
  60. if(!arg1)
  61. {
  62. perror("Malloc failed for argument");
  63. ck_abort_msg("Unable to allocate memory");
  64. }
  65. strcpy(arg1, arg[1]);
  66. arg[1]=arg1;
  67. memset(&zero, -1, sizeof(struct tm));
  68. ret = ttail_set_dates(ttail, arg);
  69. ck_assert_int_eq(ret, 0);
  70. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
  71. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
  72. ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
  73. ck_assert_int_eq(ttail->date_max.tm_year, 88);
  74. ck_assert_int_eq(ttail->date_max.tm_mon, 9);
  75. ck_assert_int_eq(ttail->date_max.tm_mday, 22);
  76. ck_assert_int_eq(ttail->date_max.tm_hour, 0);
  77. ck_assert_int_eq(ttail->date_max.tm_min, 0);
  78. ck_assert_int_eq(ttail->date_max.tm_sec, 0);
  79. }
  80. END_TEST
  81. START_TEST (test_init_setdates_nofmt_both)
  82. {
  83. int ret;
  84. char *arg[] = {"1988/10/22", "2088/10/22"};
  85. struct tm zero;
  86. char *arg0, *arg1;
  87. arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
  88. if(!arg0)
  89. {
  90. perror("Malloc failed for argument");
  91. ck_abort_msg("Unable to allocate memory");
  92. }
  93. strcpy(arg0, arg[0]);
  94. arg[0]=arg0;
  95. arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
  96. if(!arg1)
  97. {
  98. perror("Malloc failed for argument");
  99. ck_abort_msg("Unable to allocate memory");
  100. }
  101. strcpy(arg1, arg[1]);
  102. arg[1]=arg1;
  103. memset(&zero, 0, sizeof(struct tm));
  104. ret = ttail_set_dates(ttail, arg);
  105. ck_assert_int_eq(ret, 0);
  106. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
  107. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
  108. ck_assert_int_eq(ttail->date_min.tm_year, 88);
  109. ck_assert_int_eq(ttail->date_min.tm_mon, 9);
  110. ck_assert_int_eq(ttail->date_min.tm_mday, 22);
  111. ck_assert_int_eq(ttail->date_min.tm_hour, 0);
  112. ck_assert_int_eq(ttail->date_min.tm_min, 0);
  113. ck_assert_int_eq(ttail->date_min.tm_sec, 0);
  114. ck_assert_int_eq(ttail->date_max.tm_year, 188);
  115. ck_assert_int_eq(ttail->date_max.tm_mon, 9);
  116. ck_assert_int_eq(ttail->date_max.tm_mday, 22);
  117. ck_assert_int_eq(ttail->date_max.tm_hour, -1);
  118. ck_assert_int_eq(ttail->date_max.tm_min, -1);
  119. ck_assert_int_eq(ttail->date_max.tm_sec, -1);
  120. }
  121. END_TEST
  122. TTAIL_CHECK_START("ttail init checks", "dates min/max init checks")
  123. TTAIL_SET_FIXTURE(setup_ttail_empty, teardown_ttail);
  124. TTAIL_ADD_TEST(test_init_setdates_nothing);
  125. TTAIL_ADD_TEST(test_init_setdates_nofmt_min);
  126. TTAIL_ADD_TEST(test_init_setdates_nofmt_max);
  127. TTAIL_ADD_TEST(test_init_setdates_nofmt_both);
  128. TTAIL_CHECK_END