1 /* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
2
3 #include "lib.h"
4 #include "array.h"
5 #include "test-common.h"
6 #include "mail-index-private.h"
7 #include "mail-index-modseq.h"
8 #include "mail-index-transaction-private.h"
9
test_mail_index_map_lookup_seq_range_count(unsigned int messages_count)10 static void test_mail_index_map_lookup_seq_range_count(unsigned int messages_count)
11 {
12 struct mail_index_record_map rec_map;
13 struct mail_index_map map;
14 uint32_t seq, first_uid, last_uid, first_seq, last_seq, max_uid;
15
16 i_zero(&map);
17 i_zero(&rec_map);
18 map.rec_map = &rec_map;
19 map.hdr.messages_count = messages_count;
20 map.hdr.record_size = sizeof(struct mail_index_record);
21 rec_map.records_count = map.hdr.messages_count;
22 rec_map.records = i_new(struct mail_index_record, map.hdr.messages_count);
23
24 for (seq = 1; seq <= map.hdr.messages_count; seq++)
25 MAIL_INDEX_REC_AT_SEQ(&map, seq)->uid = seq*2;
26 max_uid = (seq-1)*2;
27 map.hdr.next_uid = max_uid + 1;
28
29 for (first_uid = 2; first_uid <= max_uid; first_uid++) {
30 for (last_uid = first_uid; last_uid <= max_uid; last_uid++) {
31 if (first_uid == last_uid && first_uid%2 != 0)
32 continue;
33 mail_index_map_lookup_seq_range(&map, first_uid, last_uid, &first_seq, &last_seq);
34 test_assert((first_uid+1)/2 == first_seq && last_uid/2 == last_seq);
35 }
36 }
37 i_free(rec_map.records);
38 }
39
test_mail_index_map_lookup_seq_range(void)40 static void test_mail_index_map_lookup_seq_range(void)
41 {
42 unsigned int i;
43
44 test_begin("mail index map lookup seq range");
45 for (i = 1; i < 20; i++)
46 test_mail_index_map_lookup_seq_range_count(i);
47 test_end();
48 }
49
main(void)50 int main(void)
51 {
52 static void (*const test_functions[])(void) = {
53 test_mail_index_map_lookup_seq_range,
54 NULL
55 };
56 return test_run(test_functions);
57 }
58