From: alex Date: Thu, 21 Apr 2022 00:39:02 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=40337c8fda371be7accf860b240980a652906c9f;p=seeder ... --- diff --git a/src/watch.c b/src/watch.c index 7ee9e5d..142f7ec 100644 --- a/src/watch.c +++ b/src/watch.c @@ -29,9 +29,7 @@ static void *watch_spawn(void *unused) { for(size_t i=0;isize;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; } } } diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index e06c8cc..050f8ea 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -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" diff --git a/test/unit/test_macros.h b/test/unit/test_macros.h index 2ad0ba6..5e7aa02 100644 --- a/test/unit/test_macros.h +++ b/test/unit/test_macros.h @@ -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 \\> #include -#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 \\> + +#include + +#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); +}