timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
Ви не можете вибрати більше 25 тем Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_argparse_files.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * file argument parsing
  10. */
  11. START_TEST (test_argparse_file_non_exist)
  12. {
  13. ttail_t *t;
  14. char *args[4] = {"foo", "-d", "Mar 6 13:37", NULL};
  15. args[3] = fname[FNAME_NO_EXIST];
  16. t = ttail_init(4, args);
  17. ck_assert_msg(t != NULL, "init failed");
  18. ck_assert_msg(t->logfile_sz == 1,
  19. "ttail_t.logfile_sz should be 1");
  20. ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
  21. "ttail_t.logfile_name[0] does not contain the filename");
  22. ck_assert_msg(t->logfile[0] == NULL,
  23. "ttail_t.logfile[0] should be NULL");
  24. ttail_free(t);
  25. }
  26. END_TEST
  27. START_TEST (test_argparse_file_exist)
  28. {
  29. ttail_t *t;
  30. char *args[4] = {"foo", "-d", "Mar 10 13:37", NULL};
  31. args[3] = fname[FNAME_EXIST];
  32. t = ttail_init(4, args);
  33. ck_assert_msg(t != NULL, "init failed");
  34. ck_assert_msg(t->logfile_sz == 1,
  35. "ttail_t.logfile_sz should be 1");
  36. ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
  37. "ttail_t.logfile_name[0] does not contain the filename");
  38. ck_assert_msg(t->logfile[0] != NULL,
  39. "ttail_t.logfile[0] shouldn't be NULL");
  40. ttail_free(t);
  41. }
  42. END_TEST
  43. START_TEST (test_argparse_file_multiple)
  44. {
  45. ttail_t *t;
  46. int i;
  47. char *args[8] = {"foo", "-d", "mar 10 13:37", NULL, NULL, NULL, NULL,
  48. NULL};
  49. for(i=0; i<__Fname_sz; i++)
  50. {
  51. args[i+3] = fname[i];
  52. }
  53. t = ttail_init(8, args);
  54. ck_assert_msg(t != NULL, "init failed");
  55. ck_assert_msg(t->logfile_sz == __Fname_sz,
  56. "ttail_t.logfile_sz doesn't have the good value");
  57. for(i=0;i<__Fname_sz; i++)
  58. {
  59. ck_assert_msg(strcmp(t->logfile_name[i], args[i+3]) == 0,
  60. "some filename corrupted in ttail_t.logfile_name");
  61. if(i%2)
  62. {
  63. ck_assert_msg(t->logfile[i] != NULL,
  64. "logfile not opened");
  65. } else {
  66. ck_assert_msg(t->logfile[i] == NULL,
  67. "logfile should be NULL");
  68. }
  69. }
  70. }
  71. END_TEST
  72. TTAIL_CHECK_START("ttail argument parsing checks", "files options parse")
  73. TTAIL_SET_FIXTURE(setup_fname, teardown_fname);
  74. TTAIL_ADD_TEST(test_argparse_file_non_exist);
  75. TTAIL_ADD_TEST(test_argparse_file_exist);
  76. TTAIL_ADD_TEST(test_argparse_file_multiple);
  77. TTAIL_CHECK_END