Moved old tests away from tests/ to libraries' individual directories.
--HG--
branch : HEAD
src/dict/dict
src/imap-login/imap-login
src/imap/imap
+src/lib/test-lib
src/lib/unicodemap.c
src/lib/UnicodeData.txt
src/lib-dict/dict-drivers-register.c
+src/lib-index/test-index
+src/lib-imap/test-imap
+src/lib-mail/test-mail
src/lib-sql/sql-drivers-register.c
src/lib-storage/register/mail-storage-register.c
src/lib-storage/register/mailbox-list-register.c
src/plugins/fts-squat/squat-test
src/pop3-login/pop3-login
src/pop3/pop3
-src/tests/test-lib
-src/tests/test-mail
-src/tests/test-imap
src/util/doveadm
src/util/dovecotpw
src/util/gdbhelper
src/lib-otp/Makefile
src/lib-dovecot/Makefile
src/lib-settings/Makefile
+src/lib-test/Makefile
src/lib-storage/Makefile
src/lib-storage/list/Makefile
src/lib-storage/index/Makefile
src/master/Makefile
src/pop3/Makefile
src/pop3-login/Makefile
-src/tests/Makefile
src/util/Makefile
src/plugins/Makefile
src/plugins/acl/Makefile
lib-settings
SUBDIRS = \
+ lib-test \
$(LIBDOVECOT_SUBDIRS) \
lib-dovecot \
lib-index \
lmtp \
log \
config \
- tests \
util \
plugins
+
+test:
+ for dir in $(SUBDIRS); do \
+ cd $$dir && if ! $(MAKE) test; then exit 1; fi; cd ..; \
+ done
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-test \
-I$(top_srcdir)/src/lib-charset \
-I$(top_srcdir)/src/lib-mail
else
noinst_HEADERS = $(headers)
endif
+
+test_programs = test-imap
+noinst_PROGRAMS = $(test_programs)
+
+test_libs = \
+ libimap.la \
+ ../lib-test/libtest.la \
+ ../lib/liblib.la
+
+test_imap_SOURCES = \
+ test-imap.c
+
+test_imap_LDADD = $(test_libs)
+test_imap_DEPENDENCIES = $(test_libs)
+
+check: check-am check-test
+check-test: $(test_programs)
+ for bin in $(test_programs); do \
+ if ! ./$$bin; then exit 1; fi \
+ done
int main(void)
{
- test_init();
+ static void (*test_functions[])(void) = {
+ test_imap_match,
+ test_imap_utf7,
- test_imap_match();
- test_imap_utf7();
- return test_deinit();
+ NULL
+ };
+ return test_run(test_functions);
}
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-test \
-I$(top_srcdir)/src/lib-mail
libindex_la_SOURCES = \
mailbox-list-index.h \
mailbox-list-index-private.h
+test_programs = test-index
+noinst_PROGRAMS = $(test_programs)
+
+test_libs = \
+ libindex.la \
+ ../lib-test/libtest.la \
+ ../lib-mail/libmail.la \
+ ../lib/liblib.la
+
+test_index_SOURCES = \
+ test-index.c \
+ test-transaction-log-view.c
+
+test_headers = \
+ test-index.h
+
+test_index_LDADD = $(test_libs)
+test_index_DEPENDENCIES = $(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)
+ pkginc_lib_HEADERS = $(headers) $(test_headers)
else
- noinst_HEADERS = $(headers)
+ noinst_HEADERS = $(headers) $(test_headers)
endif
log_append_buffer(struct mail_index_export_context *ctx,
const buffer_t *buf, enum mail_transaction_type type)
{
- mail_transaction_log_append_add(ctx->append_ctx, type, buf);
+ mail_transaction_log_append_add(ctx->append_ctx, type,
+ buf->data, buf->used);
}
static const buffer_t *
static int mail_index_transaction_commit_real(struct mail_index_transaction *t)
{
struct mail_transaction_log *log = t->view->index->log;
+ bool external = (t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0;
struct mail_transaction_log_append_ctx *ctx;
uint32_t log_seq1, log_seq2;
uoff_t log_offset1, log_offset2;
int ret;
- if (mail_transaction_log_append_begin(t, &ctx) < 0)
+ if (mail_transaction_log_append_begin(log->index, external, &ctx) < 0)
return -1;
ret = mail_transaction_log_file_refresh(t, ctx);
if (ret > 0) {
void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,
enum mail_transaction_type type,
- const buffer_t *buf)
+ const void *data, size_t size)
{
struct mail_transaction_header hdr;
i_assert((type & MAIL_TRANSACTION_TYPE_MASK) != 0);
- i_assert((buf->used % 4) == 0);
+ i_assert((size % 4) == 0);
- if (buf->used == 0)
+ if (size == 0)
return;
memset(&hdr, 0, sizeof(hdr));
hdr.type |= MAIL_TRANSACTION_EXPUNGE_PROT;
if (ctx->external)
hdr.type |= MAIL_TRANSACTION_EXTERNAL;
- hdr.size = sizeof(hdr) + buf->used;
+ hdr.size = sizeof(hdr) + size;
hdr.size = mail_index_uint32_to_offset(hdr.size);
buffer_append(ctx->output, &hdr, sizeof(hdr));
- buffer_append(ctx->output, buf->data, buf->used);
+ buffer_append(ctx->output, data, size);
- if (mail_transaction_header_has_modseq(buf->data,
- CONST_PTR_OFFSET(buf->data, sizeof(hdr)),
- ctx->new_highest_modseq))
+ if (mail_transaction_header_has_modseq(data,
+ CONST_PTR_OFFSET(data, sizeof(hdr)),
+ ctx->new_highest_modseq))
ctx->new_highest_modseq++;
}
buffer_append(buf, &offset, sizeof(offset));
mail_transaction_log_append_add(ctx, MAIL_TRANSACTION_HEADER_UPDATE,
- buf);
+ buf->data, buf->used);
}
static int
return 0;
}
-int mail_transaction_log_append_begin(struct mail_index_transaction *t,
+int mail_transaction_log_append_begin(struct mail_index *index, bool external,
struct mail_transaction_log_append_ctx **ctx_r)
{
struct mail_transaction_log_append_ctx *ctx;
- struct mail_index *index;
- index = mail_index_view_get_index(t->view);
if (!index->log_locked) {
if (mail_transaction_log_lock_head(index->log) < 0)
return -1;
ctx = i_new(struct mail_transaction_log_append_ctx, 1);
ctx->log = index->log;
ctx->output = buffer_create_dynamic(default_pool, 1024);
- ctx->external = (t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0;
+ ctx->external = external;
*ctx_r = ctx;
return 0;
void mail_transaction_log_views_close(struct mail_transaction_log *log);
-int mail_transaction_log_append_begin(struct mail_index_transaction *t,
+int mail_transaction_log_append_begin(struct mail_index *index, bool external,
struct mail_transaction_log_append_ctx **ctx_r);
void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,
enum mail_transaction_type type,
- const buffer_t *buf);
+ const void *data, size_t size);
int mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
/* Lock transaction log for index synchronization. Log cannot be read or
--- /dev/null
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "test-index.h"
+
+int main(void)
+{
+ static void (*test_functions[])(void) = {
+ test_transaction_log_view,
+ NULL
+ };
+ return test_run(test_functions);
+}
--- /dev/null
+#ifndef TEST_INDEX_H
+#define TEST_INDEX_H
+
+#include "lib.h"
+#include "test-common.h"
+
+void test_transaction_log_view(void);
+
+#endif
--- /dev/null
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "test-index.h"
+#include "array.h"
+#include "mail-index-private.h"
+#include "mail-transaction-log-view-private.h"
+
+static struct mail_transaction_log *log;
+static struct mail_transaction_log_view *view;
+
+static void
+test_transaction_log_file_add(uint32_t file_seq)
+{
+ struct mail_transaction_log_file **p, *file;
+
+ file = i_new(struct mail_transaction_log_file, 1);
+ file->hdr.file_seq = file_seq;
+ file->hdr.hdr_size = file->sync_offset = sizeof(file->hdr);
+ file->hdr.prev_file_seq = file_seq - 1;
+ file->hdr.indexid = 1;
+ file->log = log;
+ file->fd = -1;
+
+ /* files must be sorted by file_seq */
+ for (p = &log->files; *p != NULL; p = &(*p)->next) {
+ if ((*p)->hdr.file_seq > file->hdr.file_seq)
+ break;
+ i_assert((*p)->hdr.file_seq < file->hdr.file_seq);
+ }
+ *p = file;
+ log->head = file;
+}
+
+static bool view_is_file_refed(uint32_t file_seq)
+{
+ struct mail_transaction_log_file *const *files;
+ unsigned int i, count;
+ bool ret = FALSE;
+
+ files = array_get(&view->file_refs, &count);
+ for (i = 0; i < count; i++) {
+ if (files[i]->hdr.file_seq == file_seq) {
+ i_assert(!ret); /* could be a test too.. */
+ ret = TRUE;
+ }
+ }
+ return ret;
+}
+
+void test_transaction_log_view(void)
+{
+ const struct mail_transaction_header *hdr;
+ struct mail_transaction_log_append_ctx *append_ctx;
+ struct mail_index_record append_rec;
+ const struct mail_index_record *rec;
+ const void *data;
+ uint32_t seq;
+ uoff_t offset, last_log_size;
+ bool reset;
+
+ test_begin("init");
+ log = i_new(struct mail_transaction_log, 1);
+ log->index = i_new(struct mail_index, 1);
+ log->index->log = log;
+ log->index->log_locked = TRUE;
+ test_transaction_log_file_add(1);
+ test_transaction_log_file_add(2);
+ test_transaction_log_file_add(3);
+
+ /* add an append record to the 3rd log file */
+ memset(&append_rec, 0, sizeof(append_rec));
+ append_rec.uid = 1;
+ test_assert(mail_transaction_log_append_begin(log->index, TRUE, &append_ctx) == 0);
+ mail_transaction_log_append_add(append_ctx, MAIL_TRANSACTION_APPEND,
+ &append_rec, sizeof(append_rec));
+ test_assert(mail_transaction_log_append_commit(&append_ctx) == 0);
+ last_log_size = sizeof(struct mail_transaction_log_header) +
+ sizeof(struct mail_transaction_header) + sizeof(append_rec);
+
+ view = mail_transaction_log_view_open(log);
+ test_assert(view != NULL && log->views == view &&
+ !view_is_file_refed(1) && !view_is_file_refed(2) &&
+ view_is_file_refed(3));
+ test_end();
+
+ /* we have files 1-3 opened */
+ test_begin("set all");
+ test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, (uoff_t)-1, &reset) == 1 &&
+ reset && view_is_file_refed(1) && view_is_file_refed(2) &&
+ view_is_file_refed(3) &&
+ !mail_transaction_log_view_is_corrupted(view));
+ mail_transaction_log_view_get_prev_pos(view, &seq, &offset);
+ test_assert(seq == 1 && offset == sizeof(struct mail_transaction_log_header));
+ test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 1);
+ test_assert(hdr->type == (MAIL_TRANSACTION_APPEND | MAIL_TRANSACTION_EXTERNAL));
+ rec = data;
+ test_assert(memcmp(rec, &append_rec, sizeof(*rec)) == 0);
+ test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 0);
+ test_assert(mail_transaction_log_view_is_last(view));
+ mail_transaction_log_view_get_prev_pos(view, &seq, &offset);
+ test_assert(seq == 3 && offset == last_log_size);
+ test_end();
+
+ test_begin("set first");
+ test_assert(mail_transaction_log_view_set(view, 0, 0, 0, 0, &reset) == 1);
+ mail_transaction_log_view_get_prev_pos(view, &seq, &offset);
+ test_assert(seq == 1 && offset == sizeof(struct mail_transaction_log_header));
+ test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 0);
+ mail_transaction_log_view_get_prev_pos(view, &seq, &offset);
+ test_assert(seq == 1 && offset == sizeof(struct mail_transaction_log_header));
+ test_end();
+
+ test_begin("set end");
+ test_assert(mail_transaction_log_view_set(view, 3, last_log_size, (uint32_t)-1, (uoff_t)-1, &reset) == 1);
+ mail_transaction_log_view_get_prev_pos(view, &seq, &offset);
+ test_assert(seq == 3 && offset == last_log_size);
+ test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 0);
+ mail_transaction_log_view_get_prev_pos(view, &seq, &offset);
+ test_assert(seq == 3 && offset == last_log_size);
+ test_end();
+
+ test_begin("log clear");
+ mail_transaction_log_view_clear(view, 2);
+ test_assert(!view_is_file_refed(1) && view_is_file_refed(2) &&
+ view_is_file_refed(3));
+ test_end();
+
+ /* --- first file has been removed --- */
+
+ test_begin("removed first");
+ mail_transaction_logs_clean(log);
+ test_assert(log->files->hdr.file_seq == 2);
+ test_end();
+
+ test_begin("set 2-3");
+ test_assert(mail_transaction_log_view_set(view, 2, 0, (uint32_t)-1, (uoff_t)-1, &reset) == 1);
+ test_end();
+
+ test_begin("missing log handing");
+ test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, (uoff_t)-1, &reset) == 0);
+ test_end();
+
+ test_begin("closed log handling");
+ view->log = NULL;
+ test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, (uoff_t)-1, &reset) == -1);
+ view->log = log;
+ test_end();
+}
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-test \
-I$(top_srcdir)/src/lib-charset
libmail_la_SOURCES = \
else
noinst_HEADERS = $(headers)
endif
+
+test_programs = test-mail
+noinst_PROGRAMS = $(test_programs)
+
+test_libs = \
+ libmail.la \
+ ../lib-test/libtest.la \
+ ../lib/liblib.la
+
+test_mail_SOURCES = \
+ test-mail.c
+
+test_mail_LDADD = $(test_libs)
+test_mail_DEPENDENCIES = $(test_libs)
+
+check: check-am check-test
+check-test: $(test_programs)
+ for bin in $(test_programs); do \
+ if ! ./$$bin; then exit 1; fi \
+ done
int main(void)
{
- test_init();
-
- test_message_address();
- test_message_date_parse();
- test_message_parser();
- test_rfc2231_parser();
- test_istream_filter();
- return test_deinit();
+ static void (*test_functions[])(void) = {
+ test_message_address,
+ test_message_date_parse,
+ test_message_parser,
+ test_rfc2231_parser,
+ test_istream_filter,
+
+ NULL
+ };
+ return test_run(test_functions);
}
--- /dev/null
+noinst_LTLIBRARIES = libtest.la
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-charset
+
+libtest_la_SOURCES = \
+ test-common.c
+
+headers = \
+ test-common.h
+
+if INSTALL_HEADERS
+ pkginc_libdir=$(pkgincludedir)
+ pkginc_lib_HEADERS = $(headers)
+else
+ noinst_HEADERS = $(headers)
+endif
#include <stdio.h>
-#define OUT_NAME_ALIGN 30
+#define OUT_NAME_ALIGN 70
+static char *test_prefix;
+static bool test_success;
static unsigned int failure_count;
static unsigned int total_count;
input->real_stream->read = allow ? test_read : test_noread;
}
+void test_begin(const char *name)
+{
+ i_assert(test_prefix == NULL);
+ test_prefix = i_strdup(name);
+ test_success = TRUE;
+}
+
+void test_assert_failed(const char *code, const char *file, unsigned int line)
+{
+ printf("%s:%u: Assert failed: %s\n", file, line, code);
+ test_success = FALSE;
+}
+
+void test_end(void)
+{
+ i_assert(test_prefix != NULL);
+
+ test_out("", test_success);
+ i_free_and_null(test_prefix);
+ test_success = FALSE;
+}
+
void test_out(const char *name, bool success)
{
test_out_reason(name, success, NULL);
void test_out_reason(const char *name, bool success, const char *reason)
{
- int i;
-
- fputs(name, stdout);
- putchar(' ');
- for (i = strlen(name) + 1; i < OUT_NAME_ALIGN; i++)
+ int i = 0;
+
+ if (test_prefix != NULL) {
+ fputs(test_prefix, stdout);
+ i += strlen(test_prefix);
+ if (*name != '\0') {
+ putchar(':');
+ i++;
+ }
+ putchar(' ');
+ i++;
+ }
+ if (*name != '\0') {
+ fputs(name, stdout);
+ putchar(' ');
+ i += strlen(name) + 1;
+ }
+ for (; i < OUT_NAME_ALIGN; i++)
putchar('.');
fputs(" : ", stdout);
if (success)
fputs("ok", stdout);
else {
fputs("FAILED", stdout);
+ test_success = FALSE;
failure_count++;
}
if (reason != NULL && *reason != '\0')
total_count++;
}
-void test_init(void)
+static void test_init(void)
{
+ test_prefix = NULL;
failure_count = 0;
total_count = 0;
lib_init();
}
-int test_deinit(void)
+static int test_deinit(void)
{
+ i_assert(test_prefix == NULL);
printf("%u / %u tests failed\n", failure_count, total_count);
return failure_count == 0 ? 0 : 1;
}
+
+int test_run(void (*test_functions[])(void))
+{
+ unsigned int i;
+
+ test_init();
+ for (i = 0; test_functions[i] != NULL; i++) {
+ T_BEGIN {
+ test_functions[i]();
+ } T_END;
+ }
+ return test_deinit();
+}
void test_istream_set_size(struct istream *input, uoff_t size);
void test_istream_set_allow_eof(struct istream *input, bool allow);
+void test_begin(const char *name);
+#define test_assert(code) STMT_START { \
+ if (!(code)) test_assert_failed(#code, __FILE__, __LINE__); \
+ } STMT_END
+void test_assert_failed(const char *code, const char *file, unsigned int line);
+void test_end(void);
+
void test_out(const char *name, bool success);
void test_out_reason(const char *name, bool success, const char *reason);
-void test_init(void);
-int test_deinit(void);
+int test_run(void (*test_functions[])(void));
#endif
--- /dev/null
+# test-common.lo - a libtool object file
+# Generated by ltmain.sh (GNU libtool) 2.2.6 Debian-2.2.6a-1ubuntu1
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object='.libs/test-common.o'
+
+# Name of the non-PIC object
+non_pic_object='test-common.o'
+
var-expand.h \
write-full.h
+test_programs = test-lib
+noinst_PROGRAMS = $(test_programs)
+
+test_lib_CPPFLAGS = \
+ -I$(top_srcdir)/src/lib-test
+
+test_libs = \
+ ../lib-test/libtest.la \
+ liblib.la
+
+test_lib_SOURCES = \
+ test-lib.c \
+ test-istream.c
+
+test_headers = \
+ test-lib.h
+
+test_lib_LDADD = $(test_libs)
+test_lib_DEPENDENCIES = $(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)
+ noinst_HEADERS = $(test_headers)
else
- noinst_HEADERS = $(headers)
+ noinst_HEADERS = $(headers) $(test_headers)
endif
test_istreams
};
- unsigned int i;
-
- test_init();
- for (i = 0; i < N_ELEMENTS(test_functions); i++) {
- T_BEGIN {
- test_functions[i]();
- } T_END;
- }
- return test_deinit();
+ return test_run(test_functions);
}
+++ /dev/null
-noinst_PROGRAMS = test-lib test-mail test-imap
-
-noinst_LIBRARIES = libtest.a
-
-AM_CPPFLAGS = \
- -I$(top_srcdir)/src/lib \
- -I$(top_srcdir)/src/lib-mail \
- -I$(top_srcdir)/src/lib-imap \
- -I$(top_srcdir)/src/lib-index \
- -I$(top_srcdir)/src/lib-storage
-
-libtest_a_SOURCES = \
- test-common.c
-
-libs = \
- libtest.a \
- $(LIBDOVECOT)
-
-test_lib_SOURCES = \
- test-istream.c \
- test-lib.c
-
-test_lib_LDADD = $(libs)
-test_lib_DEPENDENCIES = $(libs)
-
-test_mail_SOURCES = \
- test-mail.c
-
-test_mail_LDADD = $(libs)
-test_mail_DEPENDENCIES = $(libs)
-
-test_imap_SOURCES = \
- test-imap.c
-
-noinst_HEADERS = \
- test-common.h \
- test-lib.h
-
-test_imap_LDADD = $(libs)
-test_imap_DEPENDENCIES = $(libs)