New tests organisation
tests/Makfile.am is now generated using tests/regen.sh . bootstrap.sh has been updated. Argument parsing tests are splitted
This commit is contained in:
parent
e92e62046e
commit
fe2367eb13
10 changed files with 531 additions and 436 deletions
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
[ "$1" = "clean" ] && [ -f "Makefile" ] && make distclean # pour les .o
|
||||
|
||||
rm -fR configure aclocal.m4 autom4te.cache src/Makefile.in tests/Makefile.in Makefile.in compile depcomp install-sh missing
|
||||
rm -fR configure aclocal.m4 autom4te.cache src/Makefile.in tests/Makefile.in Makefile.in compile depcomp install-sh missing tests/Makefile.am
|
||||
|
||||
[ "$1" = "clean" ] && exit 0
|
||||
|
||||
./tests/regen.sh
|
||||
aclocal && automake -a -c && autoconf
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
TESTS = ttail_argparse_check ttail_init_check ttail_search_check
|
||||
check_PROGRAMS = ttail_argparse_check ttail_init_check ttail_search_check
|
||||
|
||||
ttail_argparse_check_SOURCES = ttail_argparse_check.c
|
||||
ttail_argparse_check_CFLAGS = @CHECK_CFLAGS@
|
||||
ttail_argparse_check_LDADD = $(top_builddir)/src/libttail.a @CHECK_LIBS@
|
||||
|
||||
ttail_init_check_SOURCES = ttail_init_check.c
|
||||
ttail_init_check_CFLAGS = @CHECK_CFLAGS@
|
||||
ttail_init_check_LDADD = $(top_builddir)/src/libttail.a @CHECK_LIBS@
|
||||
|
||||
ttail_search_check_SOURCES = ttail_search_check.c
|
||||
ttail_search_check_CFLAGS = @CHECK_CFLAGS@
|
||||
ttail_search_check_LDADD = $(top_builddir)/src/libttail.a @CHECK_LIBS@
|
||||
17
tests/regen.sh
Executable file
17
tests/regen.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd $(dirname "$0")
|
||||
echo "Generating $(pwd)/Makefile.am"
|
||||
|
||||
progs="$(echo *.c | sed -e 's/\.c / /g' -e 's/\.c$//')"
|
||||
echo "TESTS = $progs
|
||||
check_PROGRAMS = $progs" > Makefile.am
|
||||
|
||||
for p in $progs
|
||||
do
|
||||
echo "
|
||||
${p}_SOURCES = ${p}.c
|
||||
${p}_CFLAGS = @CHECK_CFLAGS@
|
||||
${p}_LDADD = \$(top_builddir)/src/libttail.a @CHECK_LIBS@
|
||||
"
|
||||
done >> Makefile.am
|
||||
97
tests/ttail_argparse_badarg.c
Normal file
97
tests/ttail_argparse_badarg.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ttail_check.h"
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
/*
|
||||
* Bad arguments
|
||||
*/
|
||||
|
||||
START_TEST (test_argparse_bad1)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--sdfsdf"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad2)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-x"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad3)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-p"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad4)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-f"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad5)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-d"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad6)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-m"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad7)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-l"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_argparse_badarg;
|
||||
|
||||
s = suite_create("ttail argument parsing checks");
|
||||
|
||||
tc_argparse_badarg = tcase_create("bad arguments parsing");
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad1);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad2);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad3);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad4);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad5);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad6);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad7);
|
||||
|
||||
suite_add_tcase(s, tc_argparse_badarg);
|
||||
return s;
|
||||
}
|
||||
|
||||
TTAIL_CHECK_MAIN(ttail_init_suite)
|
||||
|
|
@ -1,421 +0,0 @@
|
|||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
ttail_t *ttail;
|
||||
#define __Fname_sz 5
|
||||
#define FNAME_NO_EXIST 0
|
||||
#define FNAME_EXIST 1
|
||||
char *fname[__Fname_sz];
|
||||
|
||||
void teardown_ttail(void)
|
||||
{
|
||||
ttail_free(ttail);
|
||||
}
|
||||
/*
|
||||
* Empty argument parsing test case
|
||||
*/
|
||||
void setup_ttail_empty(void)
|
||||
{
|
||||
ttail = ttail_init(1, (char**)&"foo");
|
||||
}
|
||||
START_TEST (test_argparse_empty_logfilename)
|
||||
{
|
||||
ck_assert_msg(ttail->logfile_name == NULL,
|
||||
"ttail_t.logfile_name should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_logfile)
|
||||
{
|
||||
ck_assert_msg(ttail->logfile == NULL,
|
||||
"ttail_t.logfile should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_logfilesz)
|
||||
{
|
||||
ck_assert_msg(ttail->logfile_sz == 0,
|
||||
"ttail_t.logfile_sz should be 0");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_flag)
|
||||
{
|
||||
ck_assert_msg(ttail->flag == 0,
|
||||
"ttail_t.flag should be 0");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_fmt)
|
||||
{
|
||||
ck_assert_msg(ttail->fmt == NULL,
|
||||
"ttail_t.fmt should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_verbose)
|
||||
{
|
||||
ck_assert_msg(ttail->verbose == 0,
|
||||
"ttail_t.verbose should be 0");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_prefixsz)
|
||||
{
|
||||
ck_assert_msg(ttail->prefix_sz == -1,
|
||||
"ttail_t.prefix_sz should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_session)
|
||||
{
|
||||
ck_assert_msg(ttail->session == NULL,
|
||||
"ttail_t.session should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/*
|
||||
* Bad arguments
|
||||
*/
|
||||
|
||||
START_TEST (test_argparse_bad1)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--sdfsdf"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad2)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-x"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad3)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-p"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad4)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-f"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad5)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-d"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad6)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-m"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_bad7)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-l"};
|
||||
t = ttail_init(2, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
/*
|
||||
* file argument parsing
|
||||
*/
|
||||
|
||||
void setup_fname(void)
|
||||
{
|
||||
int i;
|
||||
FILE *fp;
|
||||
for(i=0;i<__Fname_sz;i++)
|
||||
{
|
||||
fname[i] = NULL;
|
||||
}
|
||||
|
||||
for(i=0; i<__Fname_sz; i++)
|
||||
{
|
||||
fname[i] = tempnam(NULL, "ttail_check");
|
||||
if(i%2)
|
||||
{
|
||||
if((fp=fopen(fname[i], "w+")) == NULL)
|
||||
{
|
||||
perror("Unable to create file for testing");
|
||||
ck_abort_msg("Unable to create file for testing");
|
||||
}
|
||||
if(fclose(fp))
|
||||
{
|
||||
perror("Unable to close file for testing");
|
||||
ck_abort_msg("Unable to close file for testing");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void teardown_fname(void)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<__Fname_sz; i++)
|
||||
{
|
||||
unlink(fname[i]);
|
||||
if(fname[i] != NULL)
|
||||
{
|
||||
free(fname[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
START_TEST (test_argparse_reprefix_short)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-r", "^[^ ]+ "};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_reprefix_long)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--re-prefix", "^[^ ]+ "};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_prefixlen_short)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-p", "10"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
ck_assert_int_eq(t->prefix_sz, 10);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_prefixlen_long)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--prefix-len", "42"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
ck_assert_int_eq(t->prefix_sz, 42);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_argparse_prefix_multiple)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--re-prefix", "^[^ ]+ ", "-p", "20"};
|
||||
t = ttail_init(5, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_fmt_short)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-f", "%m"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_fmt_long)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--date-format", "%m"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_fmt_multiple)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-f", "%m", "-f", "%d"};
|
||||
t = ttail_init(5, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_argparse_empty;
|
||||
TCase *tc_argparse_badarg;
|
||||
TCase *tc_argparse_files;
|
||||
TCase *tc_argparse_prefix;
|
||||
TCase *tc_argparse_fmt;
|
||||
|
||||
s = suite_create("ttail argument parsing checks");
|
||||
|
||||
tc_argparse_empty = tcase_create("empty arguments parsing");
|
||||
tcase_add_checked_fixture(tc_argparse_empty,
|
||||
setup_ttail_empty, teardown_ttail);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilename);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_logfile);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilesz);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_flag);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_fmt);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_verbose);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_prefixsz);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_session);
|
||||
|
||||
tc_argparse_badarg = tcase_create("bad arguments parsing");
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad1);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad2);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad3);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad4);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad5);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad6);
|
||||
tcase_add_test(tc_argparse_badarg, test_argparse_bad7);
|
||||
|
||||
tc_argparse_files = tcase_create("files options parse");
|
||||
tcase_add_checked_fixture(tc_argparse_files,
|
||||
setup_fname, teardown_fname);
|
||||
tcase_add_test(tc_argparse_files, test_argparse_file_non_exist);
|
||||
tcase_add_test(tc_argparse_files, test_argparse_file_exist);
|
||||
tcase_add_test(tc_argparse_files, test_argparse_file_multiple);
|
||||
|
||||
tc_argparse_prefix = tcase_create("re-prefix arguments parsing");
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_short);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_long);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_short);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_long);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_prefix_multiple);
|
||||
|
||||
tc_argparse_fmt = tcase_create("date format arguments parsing");
|
||||
tcase_add_test(tc_argparse_fmt, test_argparse_fmt_short);
|
||||
tcase_add_test(tc_argparse_fmt, test_argparse_fmt_long);
|
||||
tcase_add_test(tc_argparse_fmt, test_argparse_fmt_multiple);
|
||||
|
||||
suite_add_tcase(s, tc_argparse_empty);
|
||||
suite_add_tcase(s, tc_argparse_badarg);
|
||||
suite_add_tcase(s, tc_argparse_files);
|
||||
suite_add_tcase(s, tc_argparse_prefix);
|
||||
suite_add_tcase(s, tc_argparse_fmt);
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int number_failed = 0;
|
||||
SRunner *sr;
|
||||
|
||||
sr = srunner_create(ttail_init_suite());
|
||||
srunner_set_fork_status(sr, CK_FORK);
|
||||
|
||||
srunner_run_all(sr,CK_VERBOSE);
|
||||
number_failed = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
}
|
||||
53
tests/ttail_argparse_date_fmt.c
Normal file
53
tests/ttail_argparse_date_fmt.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ttail_check.h"
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
START_TEST (test_argparse_fmt_short)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-f", "%m"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_fmt_long)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--date-format", "%m"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_fmt_multiple)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-f", "%m", "-f", "%d"};
|
||||
t = ttail_init(5, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_argparse_fmt;
|
||||
|
||||
s = suite_create("ttail argument parsing checks");
|
||||
|
||||
tc_argparse_fmt = tcase_create("date format arguments parsing");
|
||||
tcase_add_test(tc_argparse_fmt, test_argparse_fmt_short);
|
||||
tcase_add_test(tc_argparse_fmt, test_argparse_fmt_long);
|
||||
tcase_add_test(tc_argparse_fmt, test_argparse_fmt_multiple);
|
||||
|
||||
suite_add_tcase(s, tc_argparse_fmt);
|
||||
return s;
|
||||
}
|
||||
|
||||
TTAIL_CHECK_MAIN(ttail_init_suite)
|
||||
95
tests/ttail_argparse_empty.c
Normal file
95
tests/ttail_argparse_empty.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ttail_check.h"
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
ttail_t *ttail;
|
||||
|
||||
void teardown_ttail(void)
|
||||
{
|
||||
ttail_free(ttail);
|
||||
}
|
||||
/*
|
||||
* Empty argument parsing test case
|
||||
*/
|
||||
void setup_ttail_empty(void)
|
||||
{
|
||||
ttail = ttail_init(1, (char**)&"foo");
|
||||
}
|
||||
START_TEST (test_argparse_empty_logfilename)
|
||||
{
|
||||
ck_assert_msg(ttail->logfile_name == NULL,
|
||||
"ttail_t.logfile_name should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_logfile)
|
||||
{
|
||||
ck_assert_msg(ttail->logfile == NULL,
|
||||
"ttail_t.logfile should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_logfilesz)
|
||||
{
|
||||
ck_assert_msg(ttail->logfile_sz == 0,
|
||||
"ttail_t.logfile_sz should be 0");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_flag)
|
||||
{
|
||||
ck_assert_msg(ttail->flag == 0,
|
||||
"ttail_t.flag should be 0");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_fmt)
|
||||
{
|
||||
ck_assert_msg(ttail->fmt == NULL,
|
||||
"ttail_t.fmt should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_verbose)
|
||||
{
|
||||
ck_assert_msg(ttail->verbose == 0,
|
||||
"ttail_t.verbose should be 0");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_prefixsz)
|
||||
{
|
||||
ck_assert_msg(ttail->prefix_sz == -1,
|
||||
"ttail_t.prefix_sz should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_argparse_empty_session)
|
||||
{
|
||||
ck_assert_msg(ttail->session == NULL,
|
||||
"ttail_t.session should be NULL");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_argparse_empty;
|
||||
|
||||
s = suite_create("ttail argument parsing checks");
|
||||
|
||||
tc_argparse_empty = tcase_create("empty arguments parsing");
|
||||
tcase_add_checked_fixture(tc_argparse_empty,
|
||||
setup_ttail_empty, teardown_ttail);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilename);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_logfile);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilesz);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_flag);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_fmt);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_verbose);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_prefixsz);
|
||||
tcase_add_test(tc_argparse_empty, test_argparse_empty_session);
|
||||
|
||||
suite_add_tcase(s, tc_argparse_empty);
|
||||
return s;
|
||||
}
|
||||
|
||||
TTAIL_CHECK_MAIN(ttail_init_suite)
|
||||
160
tests/ttail_argparse_files.c
Normal file
160
tests/ttail_argparse_files.c
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ttail_check.h"
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
ttail_t *ttail;
|
||||
#define __Fname_sz 5
|
||||
#define FNAME_NO_EXIST 0
|
||||
#define FNAME_EXIST 1
|
||||
char *fname[__Fname_sz];
|
||||
|
||||
/*
|
||||
* file argument parsing
|
||||
*/
|
||||
|
||||
void setup_fname(void)
|
||||
{
|
||||
int i;
|
||||
FILE *fp;
|
||||
for(i=0;i<__Fname_sz;i++)
|
||||
{
|
||||
fname[i] = NULL;
|
||||
}
|
||||
|
||||
for(i=0; i<__Fname_sz; i++)
|
||||
{
|
||||
fname[i] = tempnam(NULL, "ttail_check");
|
||||
if(i%2)
|
||||
{
|
||||
if((fp=fopen(fname[i], "w+")) == NULL)
|
||||
{
|
||||
perror("Unable to create file for testing");
|
||||
ck_abort_msg("Unable to create file for testing");
|
||||
}
|
||||
if(fclose(fp))
|
||||
{
|
||||
perror("Unable to close file for testing");
|
||||
ck_abort_msg("Unable to close file for testing");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void teardown_fname(void)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<__Fname_sz; i++)
|
||||
{
|
||||
unlink(fname[i]);
|
||||
if(fname[i] != NULL)
|
||||
{
|
||||
free(fname[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_argparse_files;
|
||||
|
||||
s = suite_create("ttail argument parsing checks");
|
||||
|
||||
tc_argparse_files = tcase_create("files options parse");
|
||||
tcase_add_checked_fixture(tc_argparse_files,
|
||||
setup_fname, teardown_fname);
|
||||
tcase_add_test(tc_argparse_files, test_argparse_file_non_exist);
|
||||
tcase_add_test(tc_argparse_files, test_argparse_file_exist);
|
||||
tcase_add_test(tc_argparse_files, test_argparse_file_multiple);
|
||||
|
||||
suite_add_tcase(s, tc_argparse_files);
|
||||
return s;
|
||||
}
|
||||
|
||||
TTAIL_CHECK_MAIN(ttail_init_suite)
|
||||
80
tests/ttail_argparse_re_prefix.c
Normal file
80
tests/ttail_argparse_re_prefix.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ttail_check.h"
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
START_TEST (test_argparse_reprefix_short)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-r", "^[^ ]+ "};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_reprefix_long)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--re-prefix", "^[^ ]+ "};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_prefixlen_short)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "-p", "10"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
ck_assert_int_eq(t->prefix_sz, 10);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_argparse_prefixlen_long)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--prefix-len", "42"};
|
||||
t = ttail_init(3, args);
|
||||
ck_assert(t != NULL);
|
||||
ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
|
||||
ck_assert_int_eq(t->prefix_sz, 42);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_argparse_prefix_multiple)
|
||||
{
|
||||
ttail_t *t;
|
||||
char *args[] = {"foo", "--re-prefix", "^[^ ]+ ", "-p", "20"};
|
||||
t = ttail_init(5, args);
|
||||
ck_assert(t == NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * ttail_init_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_argparse_prefix;
|
||||
|
||||
s = suite_create("ttail argument parsing checks");
|
||||
|
||||
tc_argparse_prefix = tcase_create("re-prefix arguments parsing");
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_short);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_long);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_short);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_long);
|
||||
tcase_add_test(tc_argparse_prefix, test_argparse_prefix_multiple);
|
||||
|
||||
suite_add_tcase(s, tc_argparse_prefix);
|
||||
return s;
|
||||
}
|
||||
|
||||
TTAIL_CHECK_MAIN(ttail_init_suite)
|
||||
27
tests/ttail_check.h
Normal file
27
tests/ttail_check.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef _ttail_check_h__
|
||||
#define _ttail_check_h__
|
||||
|
||||
#include <check.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "ttail.h"
|
||||
#include "ttail_init.h"
|
||||
|
||||
|
||||
#define TTAIL_CHECK_MAIN(suite) int main(int argc, char **argv) {\
|
||||
int n_fail;\
|
||||
SRunner *sr;\
|
||||
chdir(dirname(argv[0])); /* move in ./tests dir */ \
|
||||
sr = srunner_create(suite());\
|
||||
srunner_set_fork_status(sr, CK_FORK);\
|
||||
srunner_run_all(sr, CK_VERBOSE);\
|
||||
n_fail = srunner_ntests_failed(sr);\
|
||||
srunner_free(sr);\
|
||||
return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue