]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Organize code into two unit tests
authorAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 28 Apr 2017 11:42:31 +0000 (14:42 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 28 Apr 2017 13:46:23 +0000 (16:46 +0300)
auth-cache needs special setup

src/auth/Makefile.am
src/auth/test-auth-request-var-expand.c
src/auth/test-auth.h [new file with mode: 0644]
src/auth/test-db-dict.c
src/auth/test-main.c [new file with mode: 0644]
src/auth/test-mock.c [new file with mode: 0644]
src/auth/test-username-filter.c

index 2ad9ac089d4be1382dc12102d9307b7211841583..3dfd7a70440f5527dfb47edb99d27aa156d5e448 100644 (file)
@@ -224,15 +224,14 @@ libstats_auth_la_SOURCES = auth-stats.c
 
 test_programs = \
        test-auth-cache \
-       test-auth-request-var-expand \
-       test-username-filter \
-       test-db-dict
+       test-auth
 
 noinst_PROGRAMS = $(test_programs)
 
+noinst_HEADERS = test-auth.h
+
 test_libs = \
-       ../lib-test/libtest.la \
-       ../lib/liblib.la
+       ../lib-dovecot/libdovecot.la
 
 test_auth_cache_SOURCES = auth-cache.c test-auth-cache.c
 test_auth_cache_LDADD = $(test_libs)
@@ -240,17 +239,14 @@ test_auth_cache_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs)
 # this is needed to force auth-cache.c recompilation
 test_auth_cache_CPPFLAGS = $(AM_CPPFLAGS)
 
-test_auth_request_var_expand_SOURCES = test-auth-request-var-expand.c
-test_auth_request_var_expand_LDADD = $(test_libs) libauth.la
-test_auth_request_var_expand_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs)
-
-test_username_filter_SOURCES = test-username-filter.c
-test_username_filter_LDADD = $(test_libs) $(auth_libs) $(AUTH_LIBS) $(LIBDOVECOT)
-test_username_filter_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs) $(LIBDOVECOT_DEPS)
-
-test_db_dict_SOURCES = test-db-dict.c
-test_db_dict_LDADD = $(test_libs) libauth.la
-test_db_dict_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs)
+test_auth_SOURCES = \
+       test-auth-request-var-expand.c \
+       test-username-filter.c \
+       test-db-dict.c \
+       test-mock.c \
+       test-main.c
+test_auth_LDADD = $(test_libs) $(auth_libs) $(AUTH_LIBS)
+test_auth_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs)
 
 check: check-am check-test
 check-test: all-am
index 9b1ab2a4166b4617430ba92835d5cd3aa5e4e5f8..adf3bce68d684450a145a254ab06287cbb1e59eb 100644 (file)
@@ -1,12 +1,11 @@
 /* Copyright (c) 2015-2017 Dovecot authors, see the included COPYING file */
 
-#include "lib.h"
+#include "test-auth.h"
 #include "str.h"
 #include "auth.h"
 #include "passdb.h"
 #include "userdb.h"
 #include "auth-request.h"
-#include "test-common.h"
 
 static struct passdb_module test_passdb = {
        .id = 40
@@ -235,22 +234,18 @@ static void test_auth_request_var_expand_funcs(void)
        test_end();
 }
 
-int main(void)
+void test_auth_request_var_expand(void)
 {
-       static void (*const test_functions[])(void) = {
-               test_auth_request_var_expand_shortlong,
-               test_auth_request_var_expand_flags,
-               test_auth_request_var_expand_long,
-               test_auth_request_var_expand_usernames,
-               test_auth_request_var_expand_funcs,
-               NULL
-       };
-
        default_test_request.local_ip.u.ip4.s_addr = htonl(123456789);
        default_test_request.remote_ip.u.ip4.s_addr = htonl(1234567890);
        default_test_request.real_local_ip.u.ip4.s_addr = htonl(223456788);
        default_test_request.real_remote_ip.u.ip4.s_addr = htonl(223456789);
 
        test_request = default_test_request;
-       return test_run(test_functions);
+
+       test_auth_request_var_expand_shortlong();
+       test_auth_request_var_expand_flags();
+       test_auth_request_var_expand_long();
+       test_auth_request_var_expand_usernames();
+       test_auth_request_var_expand_funcs();
 }
diff --git a/src/auth/test-auth.h b/src/auth/test-auth.h
new file mode 100644 (file)
index 0000000..ae059da
--- /dev/null
@@ -0,0 +1,14 @@
+/* Copyright (c) 2017 Dovecot authors, see the included COPYING file */
+
+#ifndef TEST_AUTH_H
+#define TEST_AUTH_H 1
+
+#include "lib.h"
+#include "test-common.h"
+
+void test_auth_request_var_expand(void);
+void test_db_dict_parse_cache_key(void);
+void test_username_filter(void);
+
+#endif
+
index ad102357935c9b5ad9e374dea74f6c7adf8ed7c2..e1523434fcce4b5c588d9157179b48e25c951a38 100644 (file)
@@ -1,11 +1,10 @@
 /* Copyright (c) 2013-2017 Dovecot authors, see the included COPYING file */
 
-#include "lib.h"
+#include "test-auth.h"
 #include "array.h"
 #include "db-dict.h"
-#include "test-common.h"
 
-static void test_db_dict_parse_cache_key(void)
+void test_db_dict_parse_cache_key(void)
 {
        struct db_dict_key keys[] = {
                { "key0", "%d and %n", NULL, NULL, 0 },
@@ -40,12 +39,3 @@ static void test_db_dict_parse_cache_key(void)
                           "\t%d and %n\t%l\t%{foo}%r%{bar}\t%{test1}/path\t%{extra}\tpath2/%{test2}\t%{plop}") == 0);
        test_end();
 }
-
-int main(void)
-{
-       static void (*const test_functions[])(void) = {
-               test_db_dict_parse_cache_key,
-               NULL
-       };
-       return test_run(test_functions);
-}
diff --git a/src/auth/test-main.c b/src/auth/test-main.c
new file mode 100644 (file)
index 0000000..0d7de23
--- /dev/null
@@ -0,0 +1,19 @@
+#include "lib.h"
+#include "test-common.h"
+#include "test-auth.h"
+
+int main(int argc, const char *argv[])
+{
+       const char *match = "";
+       static const struct named_test test_functions[] = {
+               TEST_NAMED(test_auth_request_var_expand)
+               TEST_NAMED(test_db_dict_parse_cache_key)
+               TEST_NAMED(test_username_filter)
+               { NULL, NULL }
+       };
+
+       if (argc > 2 && strcasecmp(argv[1], "--match") == 0)
+               match = argv[2];
+
+       return test_run_named(test_functions, match);
+}
diff --git a/src/auth/test-mock.c b/src/auth/test-mock.c
new file mode 100644 (file)
index 0000000..b523391
--- /dev/null
@@ -0,0 +1,11 @@
+#include "lib.h"
+#include "auth-common.h"
+
+struct auth_penalty *auth_penalty;
+time_t process_start_time;
+bool worker, worker_restart_request;
+void auth_module_load(const char *names ATTR_UNUSED)
+{
+}
+void auth_refresh_proctitle(void) {
+}
index ed9e65edb15da591e62652ef9472a5e9a7d40cdd..c0f64d5e61cd17791a699e7b1f34917e5d18f437 100644 (file)
@@ -1,19 +1,9 @@
 /* Copyright (c) 2017 Dovecot authors, see the included COPYING file */
 
-#include "lib.h"
-#include "test-common.h"
-#include "auth-common.h"
+#include "test-auth.h"
 #include "auth-request.h"
-struct auth_penalty *auth_penalty;
-time_t process_start_time;
-bool worker, worker_restart_request;
-void auth_module_load(const char *names ATTR_UNUSED)
-{
-}
-void auth_refresh_proctitle(void) {
-}
 
-static void test_username_filter(void)
+void test_username_filter(void)
 {
        const struct {
                const char *filter;
@@ -56,13 +46,3 @@ static void test_username_filter(void)
 
        test_end();
 }
-
-int main(void)
-{
-       static void (*const test_functions[])(void) = {
-               test_username_filter,
-               NULL
-       };
-
-       return test_run(test_functions);
-}