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; }
}
}
-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
$(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 \
$(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) \
$(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 \
$(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 \
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 = \
$(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
$(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"
#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
#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();
--- /dev/null
+#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);
+}