#include<libgen.h>
#include<string.h>
+#include<default.h>
#include<fs.h>
#include<log.h>
#include<session.h>
}
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;
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;
-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
$(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) \
$(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) \
--- /dev/null
+#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
+}
#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();
#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();
#include<session.h>
+#include INCLUDE(SESSION_SRC_FILE)
+
int main();
static void session_init_basic_test();
static void session_torrent_add_basic_test();
#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();
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);