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_check.h 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _ttail_check_h__
  2. #define _ttail_check_h__
  3. #include <check.h>
  4. #include <errno.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <libgen.h>
  8. #include "ttail.h"
  9. #include "ttail_init.h"
  10. ttail_t *ttail;
  11. #define __Fname_sz 5
  12. #define FNAME_NO_EXIST 0
  13. #define FNAME_EXIST 1
  14. char *fname[__Fname_sz];
  15. /*date formats*/
  16. char *fmt[] = TTAIL_DEFAULT_FORMATS;
  17. void teardown_ttail(void)
  18. {
  19. ttail_free(ttail);
  20. }
  21. void setup_ttail_empty(void)
  22. {
  23. ttail = ttail_init(1, (char**)&"foo");
  24. }
  25. void setup_fname(void)
  26. {
  27. int i;
  28. FILE *fp;
  29. for(i=0;i<__Fname_sz;i++)
  30. {
  31. fname[i] = NULL;
  32. }
  33. for(i=0; i<__Fname_sz; i++)
  34. {
  35. fname[i] = tempnam(NULL, "ttail_check");
  36. if(i%2)
  37. {
  38. if((fp=fopen(fname[i], "w+")) == NULL)
  39. {
  40. perror("Unable to create file for testing");
  41. ck_abort_msg("Unable to create file for testing");
  42. }
  43. if(fclose(fp))
  44. {
  45. perror("Unable to close file for testing");
  46. ck_abort_msg("Unable to close file for testing");
  47. }
  48. }
  49. }
  50. }
  51. void teardown_fname(void)
  52. {
  53. int i;
  54. for(i=0; i<__Fname_sz; i++)
  55. {
  56. unlink(fname[i]);
  57. if(fname[i] != NULL)
  58. {
  59. free(fname[i]);
  60. }
  61. }
  62. }
  63. #define TTAIL_CHECK_MAIN(suite) int main(int argc, char **argv) {\
  64. int n_fail;\
  65. SRunner *sr;\
  66. chdir(dirname(argv[0])); /* move in ./tests dir */ \
  67. sr = srunner_create(suite());\
  68. srunner_set_fork_status(sr, CK_FORK);\
  69. srunner_run_all(sr, CK_VERBOSE);\
  70. n_fail = srunner_ntests_failed(sr);\
  71. srunner_free(sr);\
  72. return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
  73. }
  74. #endif