From c0c629257199aa084487b6b3d044f1769c683448 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 10 Sep 2021 17:00:30 -0700 Subject: [PATCH] ... --- configure.ac | 2 +- src/default.c | 4 ++-- test/unit/Makefile.am | 17 +++++++++++++++-- test/unit/test_utils.c | 23 +++++++++++++++++++++-- test/unit/test_utils.h | 2 +- test/unit/util.filter.tests.c | 7 +++++++ test/unit/util.filter.tests.h | 1 + 7 files changed, 48 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index ef805bc..096f106 100644 --- a/configure.ac +++ b/configure.ac @@ -33,7 +33,7 @@ AM_CONDITIONAL([HAVE_VALGRIND], [test -n "$VALGRIND"]) AC_MSG_CHECKING([if debugging]) if test x$enable_debug != xno; then AC_MSG_RESULT(yes) - CFLAGS="-ggdb -O0" + CFLAGS="-ggdb3 -O0" else AC_MSG_RESULT(no) fi diff --git a/src/default.c b/src/default.c index 0498a15..5402fca 100644 --- a/src/default.c +++ b/src/default.c @@ -38,8 +38,8 @@ static int default_add_all_directories() { struct dirent *ent; char *p; if((dir = opendir(PREFIX))==NULL) { - log_err(DEFAULT_MESSAGE_COULD_NOT_OPEN); - return -1; + log_info(DEFAULT_MESSAGE_COULD_NOT_OPEN); + return 0; } while((ent = readdir(dir))!=NULL) { diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 69dc37d..8c53df3 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -1,5 +1,5 @@ AM_CPPFLAGS = \ - -DPREFIX=\"/tmp/seeder\" \ + -DPREFIX=\".test\" \ -Wall \ -Werror @@ -24,8 +24,21 @@ endif common_SOURCES = test_utils.c common_SOURCES += $(top_srcdir)/src/default.c +common_SOURCES += $(top_srcdir)/src/file.c +common_SOURCES += $(top_srcdir)/src/hashmap.c common_SOURCES += $(top_srcdir)/src/log.c +common_SOURCES += $(top_srcdir)/src/session.c +common_SOURCES += $(top_srcdir)/src/setup.c +common_SOURCES += $(top_srcdir)/src/torrent.c +common_SOURCES += $(top_srcdir)/src/tree.c +common_SOURCES += $(top_srcdir)/src/opt/loglevel.c util_filter_tests_SOURCES = \ $(common_SOURCES) \ - util.filter.tests.c + util.filter.tests.c \ + $(top_srcdir)/src/opt/filter.c \ + $(top_srcdir)/src/opt/piecel.c \ + $(top_srcdir)/src/opt/watch.c \ + $(top_srcdir)/src/opt/worker.c \ + $(top_srcdir)/src/util/dir.c \ + $(top_srcdir)/src/util/file.c diff --git a/test/unit/test_utils.c b/test/unit/test_utils.c index 1f21932..e068038 100644 --- a/test/unit/test_utils.c +++ b/test/unit/test_utils.c @@ -1,16 +1,35 @@ #include -void clean() { +void clean_env() { system("rm -rf " PREFIX); } void reset_env() { - clean(); + clean_env(); setup_env(); } void setup_env() { + clean_env(); + + create_test_directory( + assert(setup_session()==1); assert(defaults()==1); assert(setup_logging()==1); } + +void create_test_directory(const char *directory) { + assert(mkdir(directory,0700)==0); +} + +void create_test_file(const char *filename, const char *contents) { + FILE *fp; + + printf("creating %s\n",filename); + fp = fopen(filename,"w+"); + assert(NULL!=fp); + + assert(strlen(contents)==fwrite(contents,sizeof(char),strlen(contents),fp)); + assert(fclose(fp)==0); +} diff --git a/test/unit/test_utils.h b/test/unit/test_utils.h index 762acff..3976831 100644 --- a/test/unit/test_utils.h +++ b/test/unit/test_utils.h @@ -6,7 +6,7 @@ #include #include -void clean(); +void clean_env(); void reset_env(); void setup_env(); diff --git a/test/unit/util.filter.tests.c b/test/unit/util.filter.tests.c index e06fa6b..73f5566 100644 --- a/test/unit/util.filter.tests.c +++ b/test/unit/util.filter.tests.c @@ -3,7 +3,14 @@ int main() { setup_env(); + file_filter_all_basic_tests(); + clean(); return EXIT_FAILURE; } + +void file_filter_all_basic_tests() { + log_info("%s\n",PREFIX); + assert(0); +} diff --git a/test/unit/util.filter.tests.h b/test/unit/util.filter.tests.h index d6bf96d..ce4993e 100644 --- a/test/unit/util.filter.tests.h +++ b/test/unit/util.filter.tests.h @@ -4,5 +4,6 @@ #include int main(); +void file_filter_all_basic_tests(); #endif -- 2.30.2