]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Thu, 21 Apr 2022 00:39:02 +0000 (17:39 -0700)
committeralex <[email protected]>
Thu, 21 Apr 2022 00:39:02 +0000 (17:39 -0700)
src/watch.c
test/unit/Makefile.am
test/unit/test_macros.h
test/unit/test_utils.h
test/unit/watch.tests.c [new file with mode: 0644]

index 7ee9e5d820e558895bfb8d4c5e5c5f5cd357c74b..142f7ec176d5c3e6f2ede940057772f1a1b127b6 100644 (file)
@@ -29,9 +29,7 @@ static void *watch_spawn(void *unused) {
        for(size_t i=0;i<session.torrents.infohashes->size;i++) {
                p = session.torrents.infohashes->map[i];
                if(p!=NULL) {
-                       if(watch_spawn_all(fd,p->root,p->tree)<0) {
-                               return NULL;
-                       }
+                       if(watch_spawn_all(fd,p->root,p->tree)<0) { return NULL; }
                }
 
        }
index e06c8cc0b249870b1bef5b03d1a55a52415461fd..050f8eaf204b4bbc5ea4b8588c8be56d213e5c76 100644 (file)
@@ -13,7 +13,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
+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
 TESTS = $(check_PROGRAMS)
 
 if ENABLE_MEMCHECK
@@ -28,6 +28,7 @@ torrent_SOURCES = \
        $(top_srcdir)/src/bencode/encode.c \
        $(top_srcdir)/src/block.c \
        $(top_srcdir)/src/file.c \
+       $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/hashmap.c \
        $(top_srcdir)/src/torrent/add.c \
        $(top_srcdir)/src/torrent/free.c \
@@ -44,7 +45,6 @@ add_tests_SOURCES = \
        $(torrent_SOURCES) \
        add.tests.c \
        $(top_srcdir)/src/fs/filter.c \
-       $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/session.c
 
 add_tests_CPPFLAGS = $(AM_CPPFLAGS) \
@@ -70,7 +70,6 @@ feed_tests_SOURCES = \
        $(top_srcdir)/src/feed/info.c \
        $(top_srcdir)/src/fs/concat.c \
        $(top_srcdir)/src/fs/dir.c \
-       $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/meta.c \
        $(top_srcdir)/src/rss/entry.c \
        $(top_srcdir)/src/rss/free.c \
@@ -147,7 +146,6 @@ opt_tests_SOURCES = \
        $(top_srcdir)/src/default.c \
        $(top_srcdir)/src/fs/dir.c \
        $(top_srcdir)/src/fs/concat.c \
-       $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/log.c \
        $(top_srcdir)/src/opt/config.c \
        $(top_srcdir)/src/opt/env.c \
@@ -189,7 +187,6 @@ session_tests_SOURCES = \
        session.tests.c \
        $(top_srcdir)/src/fs/concat.c \
        $(top_srcdir)/src/fs/dir.c \
-       $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/session.c
 
 torrent_tests_SOURCES = \
@@ -197,8 +194,7 @@ torrent_tests_SOURCES = \
        $(torrent_SOURCES) \
        torrent.tests.c \
        $(top_srcdir)/src/fs/concat.c \
-       $(top_srcdir)/src/fs/dir.c \
-       $(top_srcdir)/src/hash.c
+       $(top_srcdir)/src/fs/dir.c
 
 # src/torrent/file.c requires TORRENT_FILE_DIRECTORY to be overwritten for testing
 # src/torrent/path.c requires TORRENT_FILE_DIRECTORY to be overwritten for testing
@@ -214,3 +210,12 @@ tree_tests_SOURCES = \
        $(top_srcdir)/src/file.c \
        $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/tree.c
+
+watch_tests_SOURCES = \
+       $(common_SOURCES) \
+       $(torrent_SOURCES) \
+       watch.tests.c \
+       $(top_srcdir)/src/fs/concat.c
+
+watch_tests_CPPFLAGS = $(AM_CPPFLAGS) \
+       -DWATCH_SRC_FILE="$(top_srcdir)/src/watch.c"
index 2ad0ba6dd25de681d7749068e10925ebb3b981f4..5e7aa02566630b2c9b98b666d88f6cbbedb5540f 100644 (file)
@@ -1,6 +1,27 @@
 #ifndef __TEST_MACROS_H_
 #define __TEST_MACROS_H_
 
+#define __include(x) #x
+#define _include(x) __include(x)
+#define INCLUDE(x) _include(x)
+
+#define TEST_DIRECTORY PREFIX
+#define TEST_FILE_1 PREFIX "/test"
+#define TEST_FILE_1_CONTENTS "asldfkjaslkdfjalskdjf"
+#define TEST_FILE_2 PREFIX "/test2"
+#define TEST_FILE_2_CONTENTS "lsakjflkadkjfasjkldfhasdjf"
+#define TEST_FILE_3 PREFIX "/.test"
+#define TEST_FILE_3_CONTENTS "sdlifjasdiofjasoidfjaois"
+#define TEST_FILE_4 PREFIX "/.test.meta"
+#define TEST_FILE_4_CONTENTS ";alsikdjf;lkasdjflk\n;asjdflk\n;ajsdklfjl;aksdfjla;kj"
+#define TEST_FILE_5 PREFIX "/random.test"
+#define TEST_FILE_6 PREFIX "/file.torrent"
+#define TEST_FILE_7 PREFIX "/file.feed"
+#define TEST_FILE_8 PREFIX "/test.meta"
+#define TEST_FILE_8_CONTENTS "title=test title\nlink=https://whatisarealink.com\npubDate=Wed, 29 Dec 2021 12:21:12 +0000\ndescription=I wonder if \\n this'll properly be formatted/escaped \\><?\nguid=magnet=asldkfjsldkfjslkdjfldsdjlfkjsdf"
+#define TEST_FILE_9 PREFIX "/.meta"
+#define TEST_FILE_9_CONTENTS "title=TITLE\nlink=http://test.com\ndescription=what is a description\nlanguage=en-us\nlastBuildDate=Wed, 29 Dec 2021 12:21:12 +0000"
+
 /* Parameters:
  * const char *path
  * unsigned char *hash
index 2c62102fa25343475bee8477886fd0198d754f3f..e5b9209d2399ade150aabff8aaefe95073f10684 100644 (file)
 #include<setup.h>
 #include<shutdown.h>
 
-#define __include(x) #x
-#define _include(x) __include(x)
-#define INCLUDE(x) _include(x)
-
-#define TEST_DIRECTORY PREFIX
-#define TEST_FILE_1 PREFIX "/test"
-#define TEST_FILE_1_CONTENTS "asldfkjaslkdfjalskdjf"
-#define TEST_FILE_2 PREFIX "/test2"
-#define TEST_FILE_2_CONTENTS "lsakjflkadkjfasjkldfhasdjf"
-#define TEST_FILE_3 PREFIX "/.test"
-#define TEST_FILE_3_CONTENTS "sdlifjasdiofjasoidfjaois"
-#define TEST_FILE_4 PREFIX "/.test.meta"
-#define TEST_FILE_4_CONTENTS ";alsikdjf;lkasdjflk\n;asjdflk\n;ajsdklfjl;aksdfjla;kj"
-#define TEST_FILE_5 PREFIX "/random.test"
-#define TEST_FILE_6 PREFIX "/file.torrent"
-#define TEST_FILE_7 PREFIX "/file.feed"
-#define TEST_FILE_8 PREFIX "/test.meta"
-#define TEST_FILE_8_CONTENTS "title=test title\nlink=https://whatisarealink.com\npubDate=Wed, 29 Dec 2021 12:21:12 +0000\ndescription=I wonder if \\n this'll properly be formatted/escaped \\><?\nguid=magnet=asldkfjsldkfjslkdjfldsdjlfkjsdf"
-#define TEST_FILE_9 PREFIX "/.meta"
-#define TEST_FILE_9_CONTENTS "title=TITLE\nlink=http://test.com\ndescription=what is a description\nlanguage=en-us\nlastBuildDate=Wed, 29 Dec 2021 12:21:12 +0000"
-
 void clean_env();
 void reset_env();
 void setup_env();
diff --git a/test/unit/watch.tests.c b/test/unit/watch.tests.c
new file mode 100644 (file)
index 0000000..804a44a
--- /dev/null
@@ -0,0 +1,50 @@
+#include<test_utils.h>
+
+#include<watch.h>
+
+#include INCLUDE(WATCH_SRC_FILE)
+
+/* dummy functions */
+struct session session;
+void log_message(enum log_level lvl, FILE *fp, const char *format,...) { return; }
+/* end dummy functions */
+
+int main();
+static void watch_spawn_all_basic_test();
+static void watch_functionality_basic_test();
+
+int main() {
+       setup_env();
+
+       watch_spawn_all_basic_test();
+       watch_functionality_basic_test();
+
+       clean_env();
+
+       return EXIT_SUCCESS;
+}
+
+static void watch_functionality_basic_test() {
+       assert(0);
+}
+
+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));
+
+       fd = inotify_init();
+       assert(fd>=0);
+       
+       assert(1==watch_spawn_all(fd,p->root,p->tree));
+
+       close(fd);
+
+       torrent_free(p);
+}