diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib-index/test-mail-index-map.c | |
parent | Initial commit. (diff) | |
download | dovecot-upstream.tar.xz dovecot-upstream.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib-index/test-mail-index-map.c')
-rw-r--r-- | src/lib-index/test-mail-index-map.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib-index/test-mail-index-map.c b/src/lib-index/test-mail-index-map.c new file mode 100644 index 0000000..0b0b3ad --- /dev/null +++ b/src/lib-index/test-mail-index-map.c @@ -0,0 +1,57 @@ +/* Copyright (c) 2016-2018 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; + + i_zero(&map); + i_zero(&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); + } + } + i_free(rec_map.records); +} + +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 (*const test_functions[])(void) = { + test_mail_index_map_lookup_seq_range, + NULL + }; + return test_run(test_functions); +} |