...
authoralex <[email protected]>
Tue, 3 May 2022 22:58:54 +0000 (15:58 -0700)
committeralex <[email protected]>
Tue, 3 May 2022 22:58:54 +0000 (15:58 -0700)
inc/opt.h
src/default.c
test/unit/Makefile.am
test/unit/default.tests.c [new file with mode: 0644]
test/unit/opt.tests.c
test/unit/rss.tests.c
test/unit/session.tests.c
test/unit/test_utils.h
test/unit/watch.tests.c

index b7d968f0c7df338e97ece980965310b93b03c564..07c21681590ea6ceda0f9cfc10883e47f69ee012 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -4,6 +4,7 @@
 #include<libgen.h>
 #include<string.h>
 
+#include<default.h>
 #include<fs.h>
 #include<log.h>
 #include<session.h>
index fd8bbae243e5be201d11bd87b32037c069ebc357..3d839e08f000f8f01cce93e9c08f287f34fcecb5 100644 (file)
@@ -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;
index e31546e2b74498b3f35010a59929f72130ce07eb..c58b1bc154207faa1d99abfe24d546f3d8122d18 100644 (file)
@@ -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 (file)
index 0000000..0702a2a
--- /dev/null
@@ -0,0 +1,65 @@
+#include<test_utils.h>
+
+#include<default.h>
+
+#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
+}
index f639c5e18e62a5aac6521404e9efb01e76e17485..ff474ba2d359e63659b65b52dfcd3bd4a032504d 100644 (file)
@@ -2,9 +2,6 @@
 
 #include<opt.h>
 
-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();
index 059fe453f0c73fabb80873d50f604d756191ccf8..4aeb340a5e70b32cb69fd2bffd2f1e11648b1f82 100644 (file)
@@ -2,6 +2,10 @@
 
 #include<rss.h>
 
+/* this is required because hashing is used 
+ * to verify results in correctness tests. */
+#include<hash.h>
+
 int main();
 static FILE *setup_file_pointer();
 static void rss_channel_info_init_basic_test();
index 50954ab40ec095602518135a339d8dad659b73b6..38192cf61c8d57d2efb3e91e773641fd79d00ac1 100644 (file)
@@ -2,6 +2,8 @@
 
 #include<session.h>
 
+#include INCLUDE(SESSION_SRC_FILE)
+
 int main();
 static void session_init_basic_test();
 static void session_torrent_add_basic_test();
index e5b9209d2399ade150aabff8aaefe95073f10684..9090a0464277210705972e1569f859cac255c7c5 100644 (file)
@@ -4,15 +4,13 @@
 #include<test_macros.h>
 
 #include<assert.h>
+#include<stdio.h>
 #include<stdlib.h>
 #include<string.h>
+#include<sys/stat.h>
+#include<sys/types.h>
 #include<time.h>
 
-#include<default.h>
-#include<hash.h>
-#include<setup.h>
-#include<shutdown.h>
-
 void clean_env();
 void reset_env();
 void setup_env();
index 1935e4d038144ef06e768cc20ea8ceb4e027234d..e877d21ce07e3e3a686467f27201e7c4d907beed 100644 (file)
@@ -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);