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_subst.c 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <check.h>
  2. #include <stdio.h>
  3. #include <libgen.h>
  4. #include "ttail_check.h"
  5. #include "ttail.h"
  6. #include "ttail_init.h"
  7. #include "ttail_search.h"
  8. /*
  9. * ttail_logline_subst() tests
  10. */
  11. START_TEST (test_search_subst_const1)
  12. {
  13. char expl[] = "Hello world !";
  14. const char *res;
  15. ttail->flag |= TTAIL_FLAG_PREFIX;
  16. ttail->prefix_sz = 4;
  17. res = ttail_logline_subst(ttail, expl);
  18. ck_assert(res != NULL);
  19. ck_assert(res == expl+4);
  20. }
  21. END_TEST
  22. START_TEST (test_search_subst_const2)
  23. {
  24. char expl[] = "Hello world !";
  25. const char *res;
  26. ttail->flag |= TTAIL_FLAG_PREFIX;
  27. ttail->prefix_sz = 0;
  28. res = ttail_logline_subst(ttail, expl);
  29. ck_assert(res != NULL);
  30. ck_assert(res == expl);
  31. }
  32. END_TEST
  33. START_TEST (test_search_subst_re1)
  34. {
  35. char expl[] = "1337 Foo Bar - Hello world !";
  36. char re[] = "^1337 Fo* Bar - ";
  37. const char *res;
  38. int ret;
  39. ret = ttail_set_prefix(ttail, re);
  40. ck_assert_int_eq(ret,0);
  41. res = ttail_logline_subst(ttail, expl);
  42. ck_assert(res != NULL);
  43. ck_assert_str_eq(res, "Hello world !");
  44. }
  45. END_TEST
  46. START_TEST (test_search_subst_re2)
  47. {
  48. char expl[] = "1337 Foo Bar - Hello world !";
  49. char re[] = "^[0-9]+ Fo{2} Bar - ";
  50. const char *res;
  51. int ret;
  52. ttail->flag |= TTAIL_FLAG_EXTENDED_RE;
  53. ret = ttail_set_prefix(ttail, re);
  54. ck_assert_int_eq(ret,0);
  55. res = ttail_logline_subst(ttail, expl);
  56. ck_assert(res != NULL);
  57. ck_assert_str_eq(res, "Hello world !");
  58. }
  59. END_TEST
  60. START_TEST (test_search_subst_re_nomatch)
  61. {
  62. char expl[] = "1337 Foo Bar - Hello world !";
  63. char re[] = "Never match m*";
  64. const char *res;
  65. int ret;
  66. ret = ttail_set_prefix(ttail, re);
  67. ck_assert_int_eq(ret,0);
  68. res = ttail_logline_subst(ttail, expl);
  69. ck_assert(res == NULL);
  70. }
  71. END_TEST
  72. TTAIL_CHECK_START("ttail search_files checks", "ttail_logline_subst() checks")
  73. TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
  74. TTAIL_ADD_TEST(test_search_subst_const1);
  75. TTAIL_ADD_TEST(test_search_subst_const2);
  76. TTAIL_ADD_TEST(test_search_subst_re1);
  77. TTAIL_ADD_TEST(test_search_subst_re2);
  78. TTAIL_ADD_TEST(test_search_subst_re_nomatch);
  79. TTAIL_CHECK_END