-DNDEBUG
endif
-check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests rss.tests torrent.tests tree.tests
+check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests rss.tests torrent.tests tree.tests
TESTS = $(check_PROGRAMS)
if ENABLE_MEMCHECK
meta_tests_CPPFLAGS = $(AM_CPPFLAGS) \
-DMETA_SRC_FILE="$(top_srcdir)/src/meta.c"
+opt_tests_SOURCES = \
+ $(common_SOURCES) \
+ $(torrent_SOURCES) \
+ opt.tests.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 \
+ $(top_srcdir)/src/opt/feed.c \
+ $(top_srcdir)/src/opt/filter.c \
+ $(top_srcdir)/src/opt/loglevel.c \
+ $(top_srcdir)/src/opt/out.c \
+ $(top_srcdir)/src/opt/piecel.c \
+ $(top_srcdir)/src/opt/set.c \
+ $(top_srcdir)/src/opt/watch.c \
+ $(top_srcdir)/src/opt/worker.c
+
+opt_tests_CPPFLAGS = $(AM_CPPFLAGS) \
+ -DTORRENT_INFO_SRC_FILE="$(top_srcdir)/src/torrent/info.c"
+
rss_tests_SOURCES = \
$(common_SOURCES) \
rss.tests.c \
--- /dev/null
+#include<test_utils.h>
+
+#include<opt.h>
+
+int session_torrent_add(struct torrent *p) { return 1; }
+
+#include INCLUDE(TORRENT_INFO_SRC_FILE)
+
+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();
+static void opt_add_watch_basic_test();
+static void opt_set_feed_url_basic_test();
+static void opt_set_file_filter_basic_test();
+static void opt_set_piece_length_basic_test();
+static void opt_set_worker_threads_basic_test();
+
+int main() {
+ setup_env();
+
+ // so logging works properly and default opt values set
+ assert(1==defaults());
+
+ opt_load_config_file_basic_test();
+ opt_load_from_env_basic_test();
+ opt_add_watch_basic_test();
+ opt_set_feed_url_basic_test();
+ opt_set_file_filter_basic_test();
+ opt_set_piece_length_basic_test();
+ opt_set_worker_threads_basic_test();
+
+ clean_env();
+
+ return EXIT_SUCCESS;
+}
+
+static void opt_load_config_file_basic_test() {
+ assert(opt_load_config_file(NULL)==-1);
+ assert(opt_load_config_file(TEST_DIRECTORY "/notarealfileslkdjfalksdjf")==-1);
+
+ assert(1==defaults());
+}
+
+static void opt_load_from_env_basic_test() {
+ assert(0==setenv("SEEDER_FEED_URL","test",1));
+ assert(0==setenv("SEEDER_FILE_FILTER","all",1));
+ assert(0==setenv("SEEDER_PIECE_LENGTH","32768",1));
+ assert(0==setenv("SEEDER_WORKER_THREADS","1",1));
+
+ assert(opt_load_from_env()==1);
+
+ assert(strcmp(global_options.feed_url,"test")==0);
+ assert(FILE_FILTER_ALL==global_options.file_filter);
+ assert(32768==global_options.piece_length);
+ assert(1==global_options.worker_threads);
+
+ assert(1==defaults());
+
+ reset_env();
+}
+
+static void opt_set_feed_url_basic_test() {
+ assert(-1==opt_set_feed_url(NULL));
+
+ assert(1==opt_set_feed_url("https://test.com"));
+ assert(1==opt_set_feed_url("https://test2.com"));
+
+ assert(strcmp(global_options.feed_url,"https://test2.com")==0);
+
+ assert(1==defaults());
+}
+
+static void opt_add_watch_basic_test() {
+ assert(-1==opt_add_watch(NULL));
+ assert(-1==opt_add_watch("notarealexistingdirectorylksdjflkajsdfklajsklf"));
+
+ assert(1==opt_add_watch(TEST_DIRECTORY));
+
+ assert(1==defaults());
+
+ reset_env();
+}
+
+static void opt_set_file_filter_basic_test() {
+ assert(-1==opt_set_file_filter(NULL));
+
+ assert(-1==opt_set_file_filter("invalidfiltervalue"));
+
+ assert(1==opt_set_file_filter("default"));
+ assert(1==opt_set_file_filter("-dotfiles"));
+ assert(1==opt_set_file_filter("all"));
+
+ assert(FILE_FILTER_ALL==global_options.file_filter);
+}
+
+static void opt_set_piece_length_basic_test() {
+ assert(-1==opt_set_piece_length(NULL));
+
+ assert(-1==opt_set_piece_length("-1"));
+ assert(-1==opt_set_piece_length("57"));
+ assert(-1==opt_set_piece_length("0"));
+
+ assert(-1==opt_set_piece_length("2"));
+ assert(-1==opt_set_piece_length("4"));
+ assert(-1==opt_set_piece_length("8"));
+ assert(-1==opt_set_piece_length("16"));
+ assert(-1==opt_set_piece_length("32"));
+ assert(-1==opt_set_piece_length("64"));
+ assert(-1==opt_set_piece_length("128"));
+ assert(-1==opt_set_piece_length("256"));
+ assert(-1==opt_set_piece_length("512"));
+ assert(-1==opt_set_piece_length("1024"));
+ assert(-1==opt_set_piece_length("2048"));
+ assert(-1==opt_set_piece_length("4096"));
+ assert(-1==opt_set_piece_length("8192"));
+ assert(1==opt_set_piece_length("16384"));
+ assert(1==opt_set_piece_length("32768"));
+ assert(1==opt_set_piece_length("65536"));
+ assert(1==opt_set_piece_length("131072"));
+ assert(1==opt_set_piece_length("262144"));
+ assert(1==opt_set_piece_length("524288"));
+ assert(1==opt_set_piece_length("1048576"));
+
+ assert(1048576==global_options.piece_length);
+
+ assert(1==defaults());
+}
+
+static void opt_set_worker_threads_basic_test() {
+ assert(-1==opt_set_worker_threads(NULL));
+ assert(-1==opt_set_worker_threads("notanumber"));
+
+ assert(1==opt_set_worker_threads("10"));
+
+ assert(10==global_options.worker_threads);
+
+ assert(1==defaults());
+}