#include<log.h>
-extern pthread_mutex_t shutdown_mutex;
+#define SHUTDOWN_MESSAGE_FAILED "graceful shutdown failed\n"
+#define SHUTDOWN_MESSAGE_SUCCESS "shutdown successful\n"
int shutdown_register();
void shutdown();
#include<shutdown.h>
+static void shutdown_logging();
+
int shutdown_register() {
if(0!=atexit(&shutdown)) {
perror("atexit");
}
void shutdown() {
- pthread_cancel(logging_thread);
+ shutdown_logging();
+}
+
+static void shutdown_logging() {
+ int ret_cancel, ret_join;
+ void *res;
+
+ ret_cancel = pthread_cancel(logging_thread);
+ ret_join = pthread_join(logging_thread,&res);
+
+ logging_thread = pthread_self();
+ if((ret_cancel!=0)||(ret_join!=0)||(res!=PTHREAD_CANCELED)) {
+ log_err(SHUTDOWN_MESSAGE_FAILED);
+ } else {
+ log_msg(SHUTDOWN_MESSAGE_SUCCESS);
+ }
}
p = path;
while((p = strchr(p, '/'))!=NULL) {
p++;
- log_info("p: %s\n",p);
if(p[0]=='.') { return -1; }
}
-Werror
EXTRA_DIST = \
- test_utils.h \
- util.filter.tests.h
+ test_utils.h
if ENABLE_DEBUG
else
-DNDEBUG
endif
-check_PROGRAMS = util.filter.tests
+check_PROGRAMS = hashmap.tests util.filter.tests
TESTS = $(check_PROGRAMS)
if ENABLE_MEMCHECK
common_SOURCES = test_utils.c
-common_SOURCES += $(top_srcdir)/src/default.c
-common_SOURCES += $(top_srcdir)/src/file.c
-common_SOURCES += $(top_srcdir)/src/hashmap.c
-common_SOURCES += $(top_srcdir)/src/log.c
-common_SOURCES += $(top_srcdir)/src/session.c
-common_SOURCES += $(top_srcdir)/src/setup.c
-common_SOURCES += $(top_srcdir)/src/torrent.c
-common_SOURCES += $(top_srcdir)/src/tree.c
-common_SOURCES += $(top_srcdir)/src/opt/loglevel.c
+hashmap_tests_SOURCES = \
+ $(common_SOURCES) \
+ hashmap.tests.c \
+ $(top_srcdir)/src/hashmap.c
util_filter_tests_SOURCES = \
$(common_SOURCES) \
util.filter.tests.c \
- $(top_srcdir)/src/opt/filter.c \
- $(top_srcdir)/src/opt/piecel.c \
- $(top_srcdir)/src/opt/watch.c \
- $(top_srcdir)/src/opt/worker.c \
- $(top_srcdir)/src/util/dir.c \
- $(top_srcdir)/src/util/file.c
+ $(top_srcdir)/src/util/filter.c
--- /dev/null
+#include<test_utils.h>
+
+#include<hashmap.h>
+
+int main();
+static void hashmap_init_basic_tests();
+
+int main() {
+ setup_env();
+
+ hashmap_init_basic_tests();
+
+ clean_env();
+
+ return EXIT_SUCCESS;
+}
+
+static void hashmap_init_basic_tests() {
+ assert(0);
+}
#include<test_utils.h>
+static void create_test_directory(const char*);
+static void create_test_file(const char*,const char*);
+
void clean_env() {
system("rm -rf " PREFIX);
}
void setup_env() {
clean_env();
- assert(setup_session()==1);
- assert(defaults()==1);
- assert(setup_logging()==1);
+ create_test_directory(TEST_DIRECTORY);
+ create_test_file(TEST_FILE_1,TEST_FILE_1_CONTENTS);
+ create_test_file(TEST_FILE_2,TEST_FILE_2_CONTENTS);
}
-void create_test_directory(const char *directory) {
+static void create_test_directory(const char *directory) {
assert(mkdir(directory,0700)==0);
}
-void create_test_file(const char *filename, const char *contents) {
+static void create_test_file(const char *filename, const char *contents) {
FILE *fp;
printf("creating %s\n",filename);
#include<default.h>
#include<setup.h>
+#include<shutdown.h>
+
+#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"
void clean_env();
-void create_test_directory(const char*);
-void create_test_file(const char*,const char*);
void reset_env();
void setup_env();
-#include<util.filter.tests.h>
+#include<test_utils.h>
+
+#include<util.h>
+
+int main();
+static void file_filter_all_basic_tests();
+static void file_filter_ignore_dotfiles_basic_tests();
int main() {
setup_env();
file_filter_all_basic_tests();
+ file_filter_ignore_dotfiles_basic_tests();
clean_env();
- return EXIT_FAILURE;
+ return EXIT_SUCCESS;
}
void file_filter_all_basic_tests() {
- log_info("%s\n",PREFIX);
- assert(1);
+ assert(1==file_filter_all(TEST_FILE_1));
+ assert(1==file_filter_all(TEST_FILE_2));
+}
+
+void file_filter_ignore_dotfiles_basic_tests() {
+ assert(1==file_filter_ignore_dotfiles(TEST_FILE_1));
+ assert(1==file_filter_ignore_dotfiles(TEST_FILE_2));
+ assert(-1==file_filter_ignore_dotfiles(TEST_FILE_3));
+ assert(-1==file_filter_ignore_dotfiles(TEST_FILE_4));
}
+++ /dev/null
-#ifndef __UTIL_FILTER_TESTS_H_
-#define __UTIL_FILTER_TESTS_H_
-
-#include<test_utils.h>
-
-int main();
-void file_filter_all_basic_tests();
-
-#endif