dovecot-2.0: Added libstorage-test.a for unit testing lib-storag...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 5 03:20:55 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/4dca587d5b75
changeset: 9457:4dca587d5b75
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 04 20:20:49 2009 -0400
description:
Added libstorage-test.a for unit testing lib-storage users.

diffstat:

4 files changed, 647 insertions(+)
src/lib-storage/Makefile.am         |    6 
src/lib-storage/test-mail-storage.c |   73 +++++++
src/lib-storage/test-mail.c         |  227 +++++++++++++++++++++++
src/lib-storage/test-mailbox.c      |  341 +++++++++++++++++++++++++++++++++++

diffs (truncated from 676 to 300 lines):

diff -r 63f4a2825bbe -r 4dca587d5b75 src/lib-storage/Makefile.am
--- a/src/lib-storage/Makefile.am	Thu Jun 04 20:14:52 2009 -0400
+++ b/src/lib-storage/Makefile.am	Thu Jun 04 20:20:49 2009 -0400
@@ -1,6 +1,7 @@ SUBDIRS = list index register
 SUBDIRS = list index register
 
 noinst_LTLIBRARIES = libstorage.la libstorage_service.la
+noinst_LIBRARIES = libstorage_test.a
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
@@ -65,6 +66,11 @@ libdovecot_storage_la_DEPENDENCIES = $(s
 libdovecot_storage_la_DEPENDENCIES = $(shlibs)
 libdovecot_storage_la_LDFLAGS = -export-dynamic
 
+libstorage_test_a_SOURCES = \
+	test-mail-storage.c \
+	test-mailbox.c \
+	test-mail.c
+
 if INSTALL_HEADERS
   pkginc_libdir=$(pkgincludedir)
   pkginc_lib_HEADERS = $(headers)
diff -r 63f4a2825bbe -r 4dca587d5b75 src/lib-storage/test-mail-storage.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/test-mail-storage.c	Thu Jun 04 20:20:49 2009 -0400
@@ -0,0 +1,73 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "mail-storage-private.h"
+#include "test-mail-storage.h"
+
+extern struct mail_storage test_storage;
+struct mail_index_module_register mail_index_module_register = { 0 };
+
+static struct mail_storage *test_storage_alloc(void)
+{
+	struct mail_storage *storage;
+	pool_t pool;
+
+	pool = pool_alloconly_create("test mail storage", 1024);
+	storage = p_new(pool, struct mail_storage, 1);
+	*storage = test_storage;
+	storage->pool = pool;
+	return storage;
+}
+
+static void
+test_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
+			      struct mailbox_list_settings *set)
+{
+	if (set->layout == NULL)
+		set->layout = "test";
+	if (set->subscription_fname == NULL)
+		set->subscription_fname = "subscriptions";
+}
+
+static int
+test_mailbox_create(struct mail_storage *storage,
+		    struct mailbox_list *list ATTR_UNUSED,
+		    const char *name ATTR_UNUSED,
+		    bool directory ATTR_UNUSED)
+{
+	mail_storage_set_error(storage, MAIL_ERROR_NOTPOSSIBLE,
+			       "Test mailbox creation isn't supported");
+	return -1;
+}
+
+struct mail_storage test_storage = {
+	MEMBER(name) "test",
+	MEMBER(class_flags) 0,
+
+	{
+		NULL,
+		NULL,
+		NULL,
+		test_storage_alloc,
+		NULL,
+		NULL,
+		NULL,
+		test_storage_get_list_settings,
+		NULL,
+		test_mailbox_open,
+		test_mailbox_create,
+		NULL
+	}
+};
+
+struct mail_storage *test_mail_storage_create(void)
+{
+	struct mail_storage *storage;
+
+	storage = test_storage_alloc();
+	storage->refcount = 1;
+	storage->storage_class = &test_storage;
+	p_array_init(&storage->module_contexts, storage->pool, 5);
+	return storage;
+}
diff -r 63f4a2825bbe -r 4dca587d5b75 src/lib-storage/test-mail.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/test-mail.c	Thu Jun 04 20:20:49 2009 -0400
@@ -0,0 +1,227 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "mail-storage-private.h"
+#include "test-mail-storage.h"
+
+extern struct mail_vfuncs test_mail_vfuncs;
+
+struct mail *
+test_mailbox_mail_alloc(struct mailbox_transaction_context *t,
+			enum mail_fetch_field wanted_fields ATTR_UNUSED,
+			struct mailbox_header_lookup_ctx *wanted_headers ATTR_UNUSED)
+{
+	struct mail_private *mail;
+	pool_t pool;
+
+	pool = pool_alloconly_create("test mail", 1024);
+	mail = p_new(pool, struct mail_private, 1);
+	mail->mail.box = t->box;
+	mail->mail.transaction = t;
+	mail->v = test_mail_vfuncs;
+	mail->pool = pool;
+	p_array_init(&mail->module_contexts, pool, 5);
+	return &mail->mail;
+}
+
+static void test_mail_free(struct mail *mail)
+{
+	struct mail_private *pmail = (struct mail_private *)mail;
+
+	pool_unref(&pmail->pool);
+}
+
+static void test_mail_set_seq(struct mail *mail, uint32_t seq)
+{
+	mail->seq = seq;
+	mail->uid = seq;
+
+	mail->expunged = TRUE;
+	mail->has_nuls = FALSE;
+	mail->has_no_nuls = FALSE;
+}
+
+static bool test_mail_set_uid(struct mail *mail, uint32_t uid)
+{
+	test_mail_set_seq(mail, uid);
+	return TRUE;
+}
+
+static void test_mail_set_uid_cache_updates(struct mail *mail ATTR_UNUSED,
+					    bool set ATTR_UNUSED)
+{
+}
+
+static enum mail_flags test_mail_get_flags(struct mail *mail ATTR_UNUSED)
+{
+	return 0;
+}
+
+static const char *const *
+test_mail_get_keywords(struct mail *mail ATTR_UNUSED)
+{
+	return t_new(const char *, 1);
+}
+
+static const ARRAY_TYPE(keyword_indexes) *
+test_mail_get_keyword_indexes(struct mail *mail ATTR_UNUSED)
+{
+	ARRAY_TYPE(keyword_indexes) *kw_indexes;
+
+	kw_indexes = t_new(ARRAY_TYPE(keyword_indexes), 1);
+	t_array_init(kw_indexes, 1);
+	(void)array_append_space(kw_indexes);
+	return kw_indexes;
+}
+
+static uint64_t test_mail_get_modseq(struct mail *mail ATTR_UNUSED)
+{
+	return 0;
+}
+
+static int
+test_mail_get_parts(struct mail *mail ATTR_UNUSED,
+		    const struct message_part **parts_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_date(struct mail *mail ATTR_UNUSED,
+		   time_t *date_r ATTR_UNUSED, int *timezone_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_received_date(struct mail *mail ATTR_UNUSED,
+			    time_t *date_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_save_date(struct mail *mail ATTR_UNUSED,
+			time_t *date_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_test_mail_size(struct mail *mail ATTR_UNUSED,
+			     uoff_t *size_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_physical_size(struct mail *mail ATTR_UNUSED,
+			    uoff_t *size_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_first_header(struct mail *mail ATTR_UNUSED,
+			   const char *field ATTR_UNUSED,
+			   bool decode_to_utf8 ATTR_UNUSED,
+			   const char **value_r)
+{
+	*value_r = NULL;
+	return 0;
+}
+
+static int
+test_mail_get_headers(struct mail *mail ATTR_UNUSED,
+		      const char *field ATTR_UNUSED,
+		      bool decode_to_utf8 ATTR_UNUSED,
+		      const char *const **value_r)
+{
+	*value_r = NULL;
+	return 0;
+}
+
+static int
+test_mail_get_header_stream(struct mail *mail ATTR_UNUSED,
+			    struct mailbox_header_lookup_ctx *headers ATTR_UNUSED,
+			    struct istream **stream_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_stream(struct mail *mail ATTR_UNUSED,
+		     struct message_size *hdr_size ATTR_UNUSED,
+		     struct message_size *body_size ATTR_UNUSED,
+		     struct istream **stream_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static int
+test_mail_get_special(struct mail *mail ATTR_UNUSED,
+		      enum mail_fetch_field field ATTR_UNUSED,
+		      const char **value_r ATTR_UNUSED)
+{
+	return -1;
+}
+
+static void
+test_mail_update_flags(struct mail *mail ATTR_UNUSED,
+		       enum modify_type modify_type ATTR_UNUSED,
+		       enum mail_flags flags ATTR_UNUSED)
+{
+}
+
+static void
+test_mail_update_keywords(struct mail *mail ATTR_UNUSED,
+			  enum modify_type modify_type ATTR_UNUSED,
+			  struct mail_keywords *keywords ATTR_UNUSED)
+{
+}
+
+static void test_mail_expunge(struct mail *mail ATTR_UNUSED)
+{
+}
+
+static void
+test_mail_set_cache_corrupted(struct mail *mail ATTR_UNUSED,
+			      enum mail_fetch_field field ATTR_UNUSED)
+{
+}
+
+static struct index_mail *
+test_mail_get_index_mail(struct mail *mail ATTR_UNUSED)
+{


More information about the dovecot-cvs mailing list