dovecot-2.0: Added unit test for mailbox_get_expunges().

dovecot at dovecot.org dovecot at dovecot.org
Wed Jul 15 21:13:07 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/85064a01ddfd
changeset: 9632:85064a01ddfd
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jul 15 14:13:02 2009 -0400
description:
Added unit test for mailbox_get_expunges().

diffstat:

2 files changed, 174 insertions(+)
src/lib-storage/index/Makefile.am        |   20 +++
src/lib-storage/index/test-index-fetch.c |  154 ++++++++++++++++++++++++++++++

diffs (195 lines):

diff -r ee69a1de3b30 -r 85064a01ddfd src/lib-storage/index/Makefile.am
--- a/src/lib-storage/index/Makefile.am	Wed Jul 15 14:12:29 2009 -0400
+++ b/src/lib-storage/index/Makefile.am	Wed Jul 15 14:13:02 2009 -0400
@@ -4,6 +4,7 @@ noinst_LTLIBRARIES = libstorage_index.la
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-test \
 	-I$(top_srcdir)/src/lib-mail \
 	-I$(top_srcdir)/src/lib-imap \
 	-I$(top_srcdir)/src/lib-index \
@@ -43,6 +44,25 @@ headers = \
 	index-sync-private.h \
 	index-thread-private.h
 
+test_programs = \
+	test-index-fetch
+
+noinst_PROGRAMS = $(test_programs)
+
+test_libs = \
+	$(top_builddir)/src/lib-test/libtest.la \
+	$(top_builddir)/src/lib/liblib.la
+
+test_index_fetch_SOURCES = test-index-fetch.c
+test_index_fetch_LDADD = index-fetch.lo $(test_libs)
+test_index_fetch_DEPENDENCIES = index-fetch.lo $(test_libs)
+
+check: check-am check-test
+check-test: $(test_programs)
+	for bin in $(test_programs); do \
+	  if ! ./$$bin; then exit 1; fi; \
+	done
+
 if INSTALL_HEADERS
   pkginc_libdir=$(pkgincludedir)
   pkginc_lib_HEADERS = $(headers)
diff -r ee69a1de3b30 -r 85064a01ddfd src/lib-storage/index/test-index-fetch.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/index/test-index-fetch.c	Wed Jul 15 14:13:02 2009 -0400
@@ -0,0 +1,154 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "test-common.h"
+#include "mail-index-modseq.h"
+#include "index-storage.h"
+
+static uint32_t expunge_uids[] = { 25, 15, 7, 3, 11, 1, 53, 33 };
+static uint8_t mail_guids[N_ELEMENTS(expunge_uids)][MAIL_GUID_128_SIZE];
+static unsigned int expunge_idx;
+static unsigned int nonexternal_idx;
+
+void mail_index_lookup_uid(struct mail_index_view *view ATTR_UNUSED,
+			   uint32_t seq, uint32_t *uid_r)
+{
+	*uid_r = seq;
+}
+
+bool mail_index_lookup_seq_range(struct mail_index_view *view ATTR_UNUSED,
+				 uint32_t first_uid, uint32_t last_uid,
+				 uint32_t *first_seq_r, uint32_t *last_seq_r)
+{
+	*first_seq_r = first_uid;
+	*last_seq_r = last_uid;
+	return TRUE;
+}
+
+bool mail_index_modseq_get_next_log_offset(struct mail_index_view *view ATTR_UNUSED,
+					   uint64_t modseq, uint32_t *log_seq_r,
+					   uoff_t *log_offset_r)
+{
+	*log_seq_r = modseq >> 32;
+	*log_offset_r = modseq & 0xfffffff;
+	return TRUE;
+}
+
+struct mail_transaction_log_view *
+mail_transaction_log_view_open(struct mail_transaction_log *log ATTR_UNUSED) { return NULL; }
+int mail_transaction_log_view_set(struct mail_transaction_log_view *view ATTR_UNUSED,
+				  uint32_t min_file_seq ATTR_UNUSED, uoff_t min_file_offset ATTR_UNUSED,
+				  uint32_t max_file_seq ATTR_UNUSED, uoff_t max_file_offset ATTR_UNUSED,
+				  bool *reset_r ATTR_UNUSED) {
+	if (min_file_seq < 99)
+		return 0;
+	return 1;
+}
+
+void mail_transaction_log_view_close(struct mail_transaction_log_view **view ATTR_UNUSED) { }
+
+void mail_transaction_log_get_tail(struct mail_transaction_log *log ATTR_UNUSED,
+				   uint32_t *file_seq_r)
+{
+	*file_seq_r = 100;
+}
+
+int mail_transaction_log_view_next(struct mail_transaction_log_view *view ATTR_UNUSED,
+				   const struct mail_transaction_header **hdr_r,
+				   const void **data_r)
+{
+	static struct mail_transaction_header hdr;
+	static struct mail_transaction_expunge_guid exp;
+	static struct mail_transaction_expunge old_exp;
+
+	if (expunge_idx == N_ELEMENTS(expunge_uids))
+		return 0;
+
+	if (mail_guids[expunge_idx][0] == 0) {
+		old_exp.uid1 = old_exp.uid2 = expunge_uids[expunge_idx];
+		hdr.type = MAIL_TRANSACTION_EXPUNGE;
+		hdr.size = sizeof(old_exp);
+		*data_r = &old_exp;
+	} else {
+		exp.uid = expunge_uids[expunge_idx];
+		memcpy(exp.guid_128, mail_guids[expunge_idx], sizeof(exp.guid_128));
+		hdr.type = MAIL_TRANSACTION_EXPUNGE_GUID;
+		hdr.size = sizeof(exp);
+		*data_r = &exp;
+	}
+	if (expunge_idx != nonexternal_idx)
+		hdr.type |= MAIL_TRANSACTION_EXTERNAL;
+
+	*hdr_r = &hdr;
+	expunge_idx++;
+	return 1;
+}
+
+static void test_index_storage_get_expunges(void)
+{
+	struct index_mailbox *ibox;
+	ARRAY_TYPE(seq_range) uids_filter;
+	ARRAY_TYPE(mailbox_expunge_rec) expunges;
+	const struct mailbox_expunge_rec *exp;
+	unsigned int i, count;
+	uint64_t modseq;
+
+	ibox = t_new(struct index_mailbox, 1);
+	ibox->index = t_new(struct mail_index, 1);
+	ibox->view = t_new(struct mail_index_view, 1);
+
+	ibox->view->log_file_head_seq = 101;
+	ibox->view->log_file_head_offset = 1024;
+
+	test_begin("index storage get expunges");
+
+	nonexternal_idx = 1;
+	memset(mail_guids + 2, 0, MAIL_GUID_128_SIZE);
+	memset(mail_guids + 4, 0, MAIL_GUID_128_SIZE);
+
+	t_array_init(&uids_filter, 32);
+	seq_range_array_add_range(&uids_filter, 1, 20);
+	seq_range_array_add_range(&uids_filter, 53, 53);
+
+	t_array_init(&expunges, 32);
+	modseq = 98ULL << 32;
+	for (i = 0; i < 2; i++) {
+		test_assert(index_storage_get_expunges(&ibox->box, modseq, &uids_filter,
+						       &expunges) == i);
+
+		exp = array_get(&expunges, &count);
+		test_assert(count == 5);
+		test_assert(exp[0].uid == 7);
+		test_assert(memcmp(exp[0].guid_128, mail_guids[2], MAIL_GUID_128_SIZE) == 0);
+		test_assert(exp[1].uid == 3);
+		test_assert(memcmp(exp[1].guid_128, mail_guids[3], MAIL_GUID_128_SIZE) == 0);
+		test_assert(exp[2].uid == 11);
+		test_assert(memcmp(exp[2].guid_128, mail_guids[4], MAIL_GUID_128_SIZE) == 0);
+		test_assert(exp[3].uid == 1);
+		test_assert(memcmp(exp[3].guid_128, mail_guids[5], MAIL_GUID_128_SIZE) == 0);
+		test_assert(exp[4].uid == 53);
+		test_assert(memcmp(exp[4].guid_128, mail_guids[6], MAIL_GUID_128_SIZE) == 0);
+
+		array_clear(&uids_filter);
+		expunge_idx = 0;
+		modseq = 100ULL << 32;
+	}
+
+	test_end();
+}
+
+int main(void)
+{
+	static void (*test_functions[])(void) = {
+		test_index_storage_get_expunges,
+		NULL
+	};
+	unsigned int i, j;
+
+	for (i = 0; i < N_ELEMENTS(mail_guids); i++) {
+		for (j = 0; j < MAIL_GUID_128_SIZE; j++)
+			mail_guids[i][j] = j + i + 1;
+	}
+	return test_run(test_functions);
+}


More information about the dovecot-cvs mailing list