Mercurial > dovecot > core-2.2
changeset 19667:36e7280c42a5
lib-index: Added unit test to mail_index_map_lookup_seq_range()
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 28 Jan 2016 19:48:09 +0200 |
parents | 2470745d19e7 |
children | f1aee594704f |
files | src/lib-index/Makefile.am src/lib-index/test-mail-index-map.c |
diffstat | 2 files changed, 62 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/Makefile.am Thu Jan 28 17:53:41 2016 +0200 +++ b/src/lib-index/Makefile.am Thu Jan 28 19:48:09 2016 +0200 @@ -61,6 +61,7 @@ mailbox-log.h test_programs = \ + test-mail-index-map \ test-mail-index-sync-ext \ test-mail-index-transaction-finish \ test-mail-index-transaction-update \ @@ -76,6 +77,10 @@ test_deps = $(noinst_LTLIBRARIES) $(test_libs) +test_mail_index_map_SOURCES = test-mail-index-map.c +test_mail_index_map_LDADD = $(noinst_LTLIBRARIES) $(test_libs) +test_mail_index_map_DEPENDENCIES = $(test_deps) + test_mail_index_sync_ext_SOURCES = test-mail-index-sync-ext.c test_mail_index_sync_ext_LDADD = mail-index-sync-ext.lo $(test_libs) test_mail_index_sync_ext_DEPENDENCIES = $(test_deps)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-index/test-mail-index-map.c Thu Jan 28 19:48:09 2016 +0200 @@ -0,0 +1,57 @@ +/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "test-common.h" +#include "mail-index-private.h" +#include "mail-index-modseq.h" +#include "mail-index-transaction-private.h" + +static void test_mail_index_map_lookup_seq_range_count(unsigned int messages_count) +{ + struct mail_index_record_map rec_map; + struct mail_index_map map; + uint32_t seq, first_uid, last_uid, first_seq, last_seq, max_uid; + + memset(&map, 0, sizeof(map)); + memset(&rec_map, 0, sizeof(rec_map)); + map.rec_map = &rec_map; + map.hdr.messages_count = messages_count; + map.hdr.record_size = sizeof(struct mail_index_record); + rec_map.records_count = map.hdr.messages_count; + rec_map.records = i_new(struct mail_index_record, map.hdr.messages_count); + + for (seq = 1; seq <= map.hdr.messages_count; seq++) + MAIL_INDEX_REC_AT_SEQ(&map, seq)->uid = seq*2; + max_uid = (seq-1)*2; + map.hdr.next_uid = max_uid + 1; + + for (first_uid = 2; first_uid <= max_uid; first_uid++) { + for (last_uid = first_uid; last_uid <= max_uid; last_uid++) { + if (first_uid == last_uid && first_uid%2 != 0) + continue; + mail_index_map_lookup_seq_range(&map, first_uid, last_uid, &first_seq, &last_seq); + test_assert((first_uid+1)/2 == first_seq && last_uid/2 == last_seq); + } + } + +} + +static void test_mail_index_map_lookup_seq_range(void) +{ + unsigned int i; + + test_begin("mail index map lookup seq range"); + for (i = 1; i < 20; i++) + test_mail_index_map_lookup_seq_range_count(i); + test_end(); +} + +int main(void) +{ + static void (*test_functions[])(void) = { + test_mail_index_map_lookup_seq_range, + NULL + }; + return test_run(test_functions); +}