123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
-
- #include "ttail_check.h"
- #include "ttail.h"
- #include "ttail_init.h"
-
- /*
- * file argument parsing
- */
-
- START_TEST (test_argparse_file_non_exist)
- {
- ttail_t *t;
- char *args[4] = {"foo", "-d", "Mar 6 13:37", NULL};
-
- args[3] = fname[FNAME_NO_EXIST];
- t = ttail_init(4, args);
- ck_assert_msg(t != NULL, "init failed");
-
- ck_assert_msg(t->logfile_sz == 1,
- "ttail_t.logfile_sz should be 1");
- ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
- "ttail_t.logfile_name[0] does not contain the filename");
- ck_assert_msg(t->logfile[0] == NULL,
- "ttail_t.logfile[0] should be NULL");
-
- ttail_free(t);
-
- }
- END_TEST
-
- START_TEST (test_argparse_file_exist)
- {
- ttail_t *t;
- char *args[4] = {"foo", "-d", "Mar 10 13:37", NULL};
-
- args[3] = fname[FNAME_EXIST];
-
- t = ttail_init(4, args);
- ck_assert_msg(t != NULL, "init failed");
-
- ck_assert_msg(t->logfile_sz == 1,
- "ttail_t.logfile_sz should be 1");
- ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
- "ttail_t.logfile_name[0] does not contain the filename");
- ck_assert_msg(t->logfile[0] != NULL,
- "ttail_t.logfile[0] shouldn't be NULL");
-
- ttail_free(t);
-
- }
- END_TEST
-
- START_TEST (test_argparse_file_multiple)
- {
- ttail_t *t;
- int i;
- char *args[8] = {"foo", "-d", "mar 10 13:37", NULL, NULL, NULL, NULL,
- NULL};
-
- for(i=0; i<__Fname_sz; i++)
- {
- args[i+3] = fname[i];
- }
-
- t = ttail_init(8, args);
- ck_assert_msg(t != NULL, "init failed");
-
- ck_assert_msg(t->logfile_sz == __Fname_sz,
- "ttail_t.logfile_sz doesn't have the good value");
-
- for(i=0;i<__Fname_sz; i++)
- {
- ck_assert_msg(strcmp(t->logfile_name[i], args[i+3]) == 0,
- "some filename corrupted in ttail_t.logfile_name");
- if(i%2)
- {
- ck_assert_msg(t->logfile[i] != NULL,
- "logfile not opened");
- } else {
- ck_assert_msg(t->logfile[i] == NULL,
- "logfile should be NULL");
-
- }
- }
-
-
- }
- END_TEST
-
- TTAIL_CHECK_START("ttail argument parsing checks", "files options parse")
- TTAIL_SET_FIXTURE(setup_fname, teardown_fname);
- TTAIL_ADD_TEST(test_argparse_file_non_exist);
- TTAIL_ADD_TEST(test_argparse_file_exist);
- TTAIL_ADD_TEST(test_argparse_file_multiple);
- TTAIL_CHECK_END
|