...
authoralex <[email protected]>
Fri, 10 Sep 2021 00:22:29 +0000 (17:22 -0700)
committeralex <[email protected]>
Fri, 10 Sep 2021 00:22:29 +0000 (17:22 -0700)
Makefile.am
configure.ac
inc/setup.h
src/main.c
src/setup.c
test/unit/Makefile.am [new file with mode: 0644]
test/unit/test_utils.c [new file with mode: 0644]
test/unit/test_utils.h [new file with mode: 0644]
test/unit/util.filter.tests.c [new file with mode: 0644]
test/unit/util.filter.tests.h [new file with mode: 0644]

index 5150b9ea0342b00c632c3a05dc364eafd525a955..f165ee12b6cb064df9e4d0409313b981932bebe8 100644 (file)
@@ -49,3 +49,5 @@ seederd_SOURCES += \
        inc/tree.h \
        inc/usage.h \
        inc/util.h
+
+SUBDIRS = . test/unit
index a8c66d4733f5c466007460559376e5c6c9bf0f3c..ef805bc6525e53da7ecab0747322f64ed771ebc0 100644 (file)
@@ -73,5 +73,6 @@ AC_TYPE_SIZE_T
 AC_FUNC_MALLOC
 AC_CHECK_FUNCS([atexit])
 
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile
+                test/unit/Makefile])
 AC_OUTPUT
index a255aaf52b5ba8806249aee082f1f4bc85f8ec76..950da5915132af5f6d8d043010b5cee00750dacc 100644 (file)
@@ -4,7 +4,7 @@
 #include<log.h>
 #include<session.h>
 
-int setup();
+int setup_logging();
 int setup_session();
 
 #endif
index 743f173b5b6cd9826f1545a454cb6abd23a739cc..f7d7ff3bd6766ba1e883d35dc4434bf3ce6d7b3b 100644 (file)
@@ -57,7 +57,7 @@ int main(int argc, char **argv) {
                }
        }
 
-       if(setup()<0) { return EXIT_FAILURE; }
+       if(setup_logging()<0) { return EXIT_FAILURE; }
 
        if(add()<0) { return EXIT_FAILURE; }
 
index 53ce50b45ecee40f16b5cac2bc2658c97efc7895..983a26da159063f2869128fe687cedd919ea5c24 100644 (file)
@@ -1,18 +1,9 @@
 #include<setup.h>
 
-static int setup_logging();
-
-int setup() {
-       // logging must be setup first
-       if(setup_logging()<0) { return -1; }
-
-       return 1;
-}
-
 pthread_t logging_thread;
 pthread_mutex_t logging_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-static int setup_logging() {
+int setup_logging() {
        if(0!=atexit(&log_entries_clean)) {
                perror("atexit");
                return -1;
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am
new file mode 100644 (file)
index 0000000..69dc37d
--- /dev/null
@@ -0,0 +1,31 @@
+AM_CPPFLAGS = \
+       -DPREFIX=\"/tmp/seeder\" \
+       -Wall \
+       -Werror
+
+EXTRA_DIST = \
+       test_utils.h \
+       util.filter.tests.h
+
+if ENABLE_DEBUG
+else
+AM_CPPFLAGS += \
+       -DNDEBUG
+endif
+
+check_PROGRAMS = util.filter.tests
+TESTS = $(check_PROGRAMS)
+
+if ENABLE_MEMCHECK
+LOG_COMPILER = $(VALGRIND)
+AM_LOG_FLAGS = --leak-check=full -v --track-origins=yes --error-exitcode=1
+endif
+
+common_SOURCES = test_utils.c
+
+common_SOURCES += $(top_srcdir)/src/default.c
+common_SOURCES += $(top_srcdir)/src/log.c
+
+util_filter_tests_SOURCES = \
+       $(common_SOURCES) \
+       util.filter.tests.c
diff --git a/test/unit/test_utils.c b/test/unit/test_utils.c
new file mode 100644 (file)
index 0000000..1f21932
--- /dev/null
@@ -0,0 +1,16 @@
+#include<test_utils.h>
+
+void clean() {
+       system("rm -rf " PREFIX);
+}
+
+void reset_env() {
+       clean();
+       setup_env();
+}
+
+void setup_env() {
+       assert(setup_session()==1);
+       assert(defaults()==1);
+       assert(setup_logging()==1);
+}
diff --git a/test/unit/test_utils.h b/test/unit/test_utils.h
new file mode 100644 (file)
index 0000000..762acff
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __TEST_UTILS_H_
+#define __TEST_UTILS_H_
+
+#include<assert.h>
+
+#include<default.h>
+#include<setup.h>
+
+void clean();
+void reset_env();
+void setup_env();
+
+#endif
diff --git a/test/unit/util.filter.tests.c b/test/unit/util.filter.tests.c
new file mode 100644 (file)
index 0000000..e06fa6b
--- /dev/null
@@ -0,0 +1,9 @@
+#include<util.filter.tests.h>
+
+int main() {
+       setup_env();
+
+       clean();
+
+       return EXIT_FAILURE;
+}
diff --git a/test/unit/util.filter.tests.h b/test/unit/util.filter.tests.h
new file mode 100644 (file)
index 0000000..d6bf96d
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __UTIL_FILTER_TESTS_H_
+#define __UTIL_FILTER_TESTS_H_
+
+#include<test_utils.h>
+
+int main();
+
+#endif