From: alex Date: Tue, 3 May 2022 22:58:54 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=a848e11b245c458f8dbad1c37a381fb881e42cd6;p=seeder ... --- diff --git a/inc/opt.h b/inc/opt.h index b7d968f..07c2168 100644 --- a/inc/opt.h +++ b/inc/opt.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/default.c b/src/default.c index fd8bbae..3d839e0 100644 --- a/src/default.c +++ b/src/default.c @@ -40,10 +40,10 @@ int defaults() { } static int default_add_all_directories() { - // add all directories in PREFIX DIR *dir; struct dirent *ent; char *p; + if((dir = opendir(PREFIX))==NULL) { log_info(DEFAULT_MESSAGE_COULD_NOT_OPEN); return 0; @@ -54,7 +54,7 @@ static int default_add_all_directories() { if(strcmp(ent->d_name,"..")==0) { continue; } if(ent->d_type==DT_DIR) { - p = malloc(sizeof(char)*(strlen(PREFIX)+strlen(ent->d_name)+1)); + p = malloc(sizeof(char)*(strlen(PREFIX)+strlen(ent->d_name)+2)); if(NULL==p) { perror("malloc"); return -1; diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index e31546e..c58b1bc 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS += \ -DNDEBUG endif -check_PROGRAMS = add.tests bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests net.tests opt.tests peer.tests pqueue.tests rss.tests session.tests torrent.tests tree.tests watch.tests +check_PROGRAMS = add.tests bencode.tests block.tests default.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests net.tests opt.tests peer.tests pqueue.tests rss.tests session.tests torrent.tests tree.tests watch.tests TESTS = $(check_PROGRAMS) if ENABLE_MEMCHECK @@ -64,6 +64,20 @@ block_tests_SOURCES = \ $(top_srcdir)/src/block.c \ $(top_srcdir)/src/hash.c +default_tests_SOURCES = \ + $(common_SOURCES) \ + default.tests.c \ + $(top_srcdir)/src/log.c \ + $(top_srcdir)/src/opt/feed.c \ + $(top_srcdir)/src/opt/filter.c \ + $(top_srcdir)/src/opt/loglevel.c \ + $(top_srcdir)/src/opt/piecel.c \ + $(top_srcdir)/src/opt/port.c \ + $(top_srcdir)/src/opt/worker.c + +default_tests_CPPFLAGS = $(AM_CPPFLAGS) \ + -DDEFAULT_SRC_FILE="$(top_srcdir)/src/default.c" + feed_tests_SOURCES = \ $(common_SOURCES) \ $(torrent_SOURCES) \ @@ -188,8 +202,10 @@ session_tests_SOURCES = \ $(torrent_SOURCES) \ session.tests.c \ $(top_srcdir)/src/fs/concat.c \ - $(top_srcdir)/src/fs/dir.c \ - $(top_srcdir)/src/session.c + $(top_srcdir)/src/fs/dir.c + +session_tests_CPPFLAGS = $(AM_CPPFLAGS) \ + -DSESSION_SRC_FILE="$(top_srcdir)/src/session.c" torrent_tests_SOURCES = \ $(common_SOURCES) \ diff --git a/test/unit/default.tests.c b/test/unit/default.tests.c new file mode 100644 index 0000000..0702a2a --- /dev/null +++ b/test/unit/default.tests.c @@ -0,0 +1,65 @@ +#include + +#include + +#include INCLUDE(DEFAULT_SRC_FILE) + +/* dummy functions */ +int opt_add_watch(const char*p) { return 1; } +/* end dummy */ + +int main(); +static void defaults_add_all_directories_basic_test(); +static void defaults_basic_test(); + +int main() { + setup_env(); + + defaults_basic_test(); + + defaults_add_all_directories_basic_test(); + + clean_env(); + + return EXIT_SUCCESS; +} + +static void defaults_add_all_directories_basic_test() { + clean_env(); + + assert(0==default_add_all_directories()); + + assert(mkdir(TEST_DIRECTORY,0700)==0); + + assert(1==default_add_all_directories()); + + assert(mkdir(TEST_DIRECTORY "/test1",0700)==0); + assert(1==default_add_all_directories()); + + assert(mkdir(TEST_DIRECTORY "/test2",0700)==0); + assert(1==default_add_all_directories()); + + assert(mkdir(TEST_DIRECTORY "/test3",0700)==0); + assert(1==default_add_all_directories()); + + assert(mkdir(TEST_DIRECTORY "/test4",0700)==0); + assert(1==default_add_all_directories()); + + reset_env(); +} + +static void defaults_basic_test() { + assert(1==defaults()); + + assert(strcmp(global_options.feed_url,"")==0); + assert(global_options.file_filter==FILE_FILTER_DEFAULT); + assert(global_options.piece_length==16384); + assert(strcmp(global_options.port,"5150")==0); + assert(global_options.worker_threads==sysconf(_SC_NPROCESSORS_ONLN)); + +#ifndef NDEBUG + assert(global_options.verbose_flag==LOG_LEVEL_VERBOSE); +#else + assert(global_options.verbose_flag==LOG_LEVEL_DEFAULT); +#endif +} diff --git a/test/unit/opt.tests.c b/test/unit/opt.tests.c index f639c5e..ff474ba 100644 --- a/test/unit/opt.tests.c +++ b/test/unit/opt.tests.c @@ -2,9 +2,6 @@ #include -pthread_t logging_thread; -pthread_mutex_t logging_mutex = PTHREAD_MUTEX_INITIALIZER; - int main(); static void opt_load_config_file_basic_test(); static void opt_load_from_env_basic_test(); diff --git a/test/unit/rss.tests.c b/test/unit/rss.tests.c index 059fe45..4aeb340 100644 --- a/test/unit/rss.tests.c +++ b/test/unit/rss.tests.c @@ -2,6 +2,10 @@ #include +/* this is required because hashing is used + * to verify results in correctness tests. */ +#include + int main(); static FILE *setup_file_pointer(); static void rss_channel_info_init_basic_test(); diff --git a/test/unit/session.tests.c b/test/unit/session.tests.c index 50954ab..38192cf 100644 --- a/test/unit/session.tests.c +++ b/test/unit/session.tests.c @@ -2,6 +2,8 @@ #include +#include INCLUDE(SESSION_SRC_FILE) + int main(); static void session_init_basic_test(); static void session_torrent_add_basic_test(); diff --git a/test/unit/test_utils.h b/test/unit/test_utils.h index e5b9209..9090a04 100644 --- a/test/unit/test_utils.h +++ b/test/unit/test_utils.h @@ -4,15 +4,13 @@ #include #include +#include #include #include +#include +#include #include -#include -#include -#include -#include - void clean_env(); void reset_env(); void setup_env(); diff --git a/test/unit/watch.tests.c b/test/unit/watch.tests.c index 1935e4d..e877d21 100644 --- a/test/unit/watch.tests.c +++ b/test/unit/watch.tests.c @@ -170,21 +170,19 @@ static void watch_functionality_multi_level_test() { static void watch_spawn_all_basic_test() { struct torrent *p; - int fd; TORRENT_SETUP_EXAMPLE(&p); - assert(-1==watch_spawn_all(-1,NULL,NULL)); - assert(-1==watch_spawn_all(0,NULL,NULL)); - assert(-1==watch_spawn_all(0,p->root,NULL)); - assert(-1==watch_spawn_all(0,p->root,p->tree)); + assert(-1==watch_spawn_all(NULL,NULL)); + assert(-1==watch_spawn_all(p->root,NULL)); + assert(-1==watch_spawn_all(p->root,p->tree)); - fd = inotify_init(); - assert(fd>=0); + watch_fd = inotify_init(); + assert(watch_fd>=0); - assert(1==watch_spawn_all(fd,p->root,p->tree)); + assert(1==watch_spawn_all(p->root,p->tree)); - close(fd); + close(watch_fd); torrent_free(p);