annotate src/lib-index/test-mail-index-transaction-update.c @ 22576:707ae9de3812

lib: istream-multiplex - Minor code cleanup Avoid propagating the error twice, and avoid any confusion about what "got" actually contains.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 05 Oct 2017 20:24:11 +0300
parents dc989aeb7299
children cb108f786fb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 19552
diff changeset
1 /* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "test-common.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "mail-index-private.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "mail-index-transaction-private.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
21571
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
9 #include <time.h>
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 static struct mail_index_header hdr;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 static struct mail_index_record rec;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 const struct mail_index_header *
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 mail_index_get_header(struct mail_index_view *view ATTR_UNUSED)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 return &hdr;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 const struct mail_index_record *
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 mail_index_lookup(struct mail_index_view *view ATTR_UNUSED,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 uint32_t seq ATTR_UNUSED)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 return &rec;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 void mail_index_lookup_keywords(struct mail_index_view *view ATTR_UNUSED,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 uint32_t seq ATTR_UNUSED,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 ARRAY_TYPE(keyword_indexes) *keyword_idx ATTR_UNUSED)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 array_clear(keyword_idx);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 bool mail_index_map_get_ext_idx(struct mail_index_map *map ATTR_UNUSED,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 uint32_t ext_id ATTR_UNUSED,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 uint32_t *idx_r ATTR_UNUSED)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 return FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 uint32_t mail_index_view_get_messages_count(struct mail_index_view *view ATTR_UNUSED)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 return hdr.messages_count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
14532
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
46 void mail_index_transaction_lookup_latest_keywords(struct mail_index_transaction *t ATTR_UNUSED,
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
47 uint32_t seq ATTR_UNUSED,
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
48 ARRAY_TYPE(keyword_indexes) *keywords ATTR_UNUSED)
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
49 {
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
50 }
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
51
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
52 struct mail_keywords *
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
53 mail_index_keywords_create_from_indexes(struct mail_index *index ATTR_UNUSED,
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
54 const ARRAY_TYPE(keyword_indexes)
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
55 *keyword_indexes ATTR_UNUSED)
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
56 {
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
57 return NULL;
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
58 }
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
59
15737
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
60 void mail_index_keywords_unref(struct mail_keywords **keywords ATTR_UNUSED)
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
61 {
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
62 }
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
63
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 static struct mail_index_transaction *
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 mail_index_transaction_new(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 struct mail_index_transaction *t;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 t = t_new(struct mail_index_transaction, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 t->first_new_seq = hdr.messages_count + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 return t;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
73 static void mail_index_transaction_cleanup(struct mail_index_transaction *t)
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
74 {
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
75 if (array_is_created(&t->appends))
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
76 array_free(&t->appends);
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
77 if (array_is_created(&t->updates))
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
78 array_free(&t->updates);
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
79 if (array_is_created(&t->modseq_updates))
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
80 array_free(&t->modseq_updates);
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
81 if (array_is_created(&t->expunges))
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
82 array_free(&t->expunges);
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
83 }
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 static void test_mail_index_append(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 struct mail_index_transaction *t;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 const struct mail_index_record *appends;
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
89 ARRAY_TYPE(seq_range) saved_uids_arr;
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
90 const struct seq_range *saved_uids;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 unsigned int count;
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
92 uint32_t seq;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 hdr.messages_count = 4;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 test_begin("mail index append");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 test_assert(t->log_updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 test_assert(seq == 5);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 test_assert(seq == 6);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 test_assert(!t->appends_nonsorted);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
105 t_array_init(&saved_uids_arr, 128);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
106 mail_index_append_finish_uids(t, 123, &saved_uids_arr);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
107 saved_uids = array_get(&saved_uids_arr, &count);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
108 test_assert(count == 1);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
109 test_assert(saved_uids[0].seq1 == 123 && saved_uids[0].seq2 == 124);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 appends = array_get(&t->appends, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 test_assert(appends[0].uid == 123);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 test_assert(appends[0].flags == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 test_assert(appends[1].uid == 124);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 test_assert(appends[1].flags == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
117 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 /* test with some uids */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 test_begin("mail index append with uids");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 test_assert(seq == 5);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 mail_index_append(t, 126, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 test_assert(seq == 6);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 test_assert(!t->appends_nonsorted);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 mail_index_append(t, 124, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 test_assert(seq == 7);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 test_assert(t->appends_nonsorted);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 test_assert(seq == 8);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 mail_index_append(t, 128, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 test_assert(seq == 9);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 test_assert(t->highest_append_uid == 128);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
137 mail_index_append_finish_uids(t, 125, &saved_uids_arr);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
138 saved_uids = array_get(&saved_uids_arr, &count);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
139 test_assert(count == 4);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
140 test_assert(saved_uids[0].seq1 == 129 && saved_uids[0].seq2 == 129);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
141 test_assert(saved_uids[1].seq1 == 126 && saved_uids[1].seq2 == 126);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
142 test_assert(saved_uids[2].seq1 == 130 && saved_uids[2].seq2 == 131);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
143 test_assert(saved_uids[3].seq1 == 128 && saved_uids[3].seq2 == 128);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 appends = array_get(&t->appends, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 test_assert(count == 5);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 test_assert(appends[0].uid == 129);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 test_assert(appends[1].uid == 126);
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
149 test_assert(appends[2].uid == 130);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
150 test_assert(appends[3].uid == 131);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 test_assert(appends[4].uid == 128);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
153
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
154 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 static void test_mail_index_flag_update_fastpath(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 struct mail_index_transaction *t;
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
160 const struct mail_index_flag_update *updates;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 unsigned int count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 hdr.messages_count = 20;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 test_begin("mail index flag update fast paths");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 mail_index_update_flags_range(t, 13, 14, MODIFY_REPLACE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 test_assert(t->last_update_idx == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 test_assert(array_count(&t->updates) == 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 mail_index_update_flags_range(t, 15, 15, MODIFY_REPLACE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 test_assert(t->last_update_idx == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 test_assert(array_count(&t->updates) == 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 mail_index_update_flags_range(t, 16, 16, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 test_assert(t->last_update_idx == 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 test_assert(array_count(&t->updates) == 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 updates = array_get(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 test_assert(updates[0].uid1 == 13);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 test_assert(updates[0].uid2 == 15);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 test_assert(updates[0].add_flags == MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 test_assert(updates[0].remove_flags ==
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_SEEN | MAIL_DRAFT));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 test_assert(updates[1].uid1 == 16);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 test_assert(updates[1].uid2 == 16);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 test_assert(updates[1].add_flags == MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 test_assert(updates[1].remove_flags == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 test_assert(!t->log_updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
195
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
196 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 static void test_mail_index_flag_update_simple_merges(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 struct mail_index_transaction *t;
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
202 const struct mail_index_flag_update *updates;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 unsigned int count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 hdr.messages_count = 20;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 test_begin("mail index flag update simple merges");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210 mail_index_update_flags_range(t, 6, 8, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 test_assert(t->last_update_idx == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 mail_index_update_flags_range(t, 5, 6, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 test_assert(t->last_update_idx == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 mail_index_update_flags_range(t, 4, 4, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 test_assert(t->last_update_idx == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 mail_index_update_flags_range(t, 7, 9, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221 test_assert(t->last_update_idx == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 mail_index_update_flags_range(t, 10, 10, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 updates = array_get(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225 test_assert(count == 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 test_assert(updates[0].uid1 == 4);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 test_assert(updates[0].uid2 == 10);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228 test_assert(updates[0].add_flags == MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 test_assert(updates[0].remove_flags == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 mail_index_update_flags_range(t, 12, 12, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 mail_index_update_flags_range(t, 11, 11, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 MAIL_FLAGGED);
11222
1b52e859933a lib-index: Minor unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 10582
diff changeset
235 updates = array_get(&t->updates, &count);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 test_assert(count == 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 test_assert(updates[0].uid1 == 4);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 test_assert(updates[0].uid2 == 12);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
240
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
241 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 static void test_mail_index_flag_update_complex_merges(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 struct mail_index_transaction *t;
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
247 const struct mail_index_flag_update *updates;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 unsigned int count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 hdr.messages_count = 20;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 test_begin("mail index flag update complex merges");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 mail_index_update_flags_range(t, 6, 8, MODIFY_REPLACE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 MAIL_SEEN);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 mail_index_update_flags_range(t, 3, 6, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 mail_index_update_flags_range(t, 5, 7, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 MAIL_DRAFT);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 mail_index_update_flags_range(t, 6, 6, MODIFY_REPLACE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 MAIL_SEEN | MAIL_ANSWERED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263 mail_index_update_flags_range(t, 5, 10, MODIFY_REMOVE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 MAIL_ANSWERED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 mail_index_update_flags_range(t, 7, 12, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 updates = array_get(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 test_assert(count == 7);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 test_assert(updates[0].uid1 == 3);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 test_assert(updates[0].uid2 == 4);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272 test_assert(updates[0].add_flags == MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 test_assert(updates[0].remove_flags == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 test_assert(updates[1].uid1 == 5);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 test_assert(updates[1].uid2 == 5);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 test_assert(updates[1].add_flags == (MAIL_DRAFT | MAIL_FLAGGED));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 test_assert(updates[1].remove_flags == MAIL_ANSWERED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 test_assert(updates[2].uid1 == 6);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 test_assert(updates[2].uid2 == 6);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280 test_assert(updates[2].add_flags == MAIL_SEEN);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 test_assert(updates[2].remove_flags == (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_DRAFT));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 test_assert(updates[3].uid1 == 7);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 test_assert(updates[3].uid2 == 7);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284 test_assert(updates[3].add_flags == (MAIL_SEEN | MAIL_DRAFT | MAIL_DELETED));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 test_assert(updates[3].remove_flags == (MAIL_ANSWERED | MAIL_FLAGGED));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 test_assert(updates[4].uid1 == 8);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 test_assert(updates[4].uid2 == 8);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 test_assert(updates[4].add_flags == (MAIL_SEEN | MAIL_DELETED));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 test_assert(updates[4].remove_flags == (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DRAFT));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 test_assert(updates[5].uid1 == 9);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 test_assert(updates[5].uid2 == 10);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 test_assert(updates[5].add_flags == MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 test_assert(updates[5].remove_flags == MAIL_ANSWERED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294 test_assert(updates[6].uid1 == 11);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 test_assert(updates[6].uid2 == 12);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 test_assert(updates[6].add_flags == MAIL_DELETED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297 test_assert(updates[6].remove_flags == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
300
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
301 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
304 static void
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 flags_array_check(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 const enum mail_flags *flags, unsigned int msg_count)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307 {
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
308 const struct mail_index_flag_update *updates;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 unsigned int i, count, seq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 if (array_is_created(&t->updates))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312 updates = array_get(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 updates = NULL;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 count = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 for (seq = 1, i = 0; i < count; i++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 if (i > 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 test_assert(updates[i-1].uid2 < updates[i].uid1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 test_assert(updates[i-1].uid2 + 1 != updates[i].uid1 ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 updates[i-1].add_flags != updates[i].add_flags ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 updates[i-1].remove_flags != updates[i].remove_flags);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 for (; seq != updates[i].uid1; seq++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 test_assert(flags[seq] == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 for (; seq <= updates[i].uid2; seq++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 test_assert(flags[seq] == updates[i].add_flags);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 for (; seq <= msg_count; seq++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 test_assert(flags[seq] == 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
331 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 static void test_mail_index_flag_update_random(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 struct mail_index_transaction *t;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 unsigned int r, seq1, seq2, seq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 enum mail_flags *flags, change;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 enum modify_type modify_type;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 hdr.messages_count = 20;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343 test_begin("mail index flag update random");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 flags = t_new(enum mail_flags, hdr.messages_count + 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 for (r = 0; r < 1000; r++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 change = rand() % (MAIL_FLAGS_NONRECENT+1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348 seq1 = (rand() % hdr.messages_count) + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 seq2 = seq1 == hdr.messages_count ? seq1 :
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 (rand() % (hdr.messages_count - seq1)) + seq1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 switch (rand() % 3) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 case 0:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 modify_type = MODIFY_ADD;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355 for (seq = seq1; seq <= seq2; seq++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
356 flags[seq] |= change;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
357 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358 case 1:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359 modify_type = MODIFY_REMOVE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 for (seq = seq1; seq <= seq2; seq++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361 flags[seq] &= ~change;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
363 case 2:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
364 modify_type = MODIFY_REPLACE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365 for (seq = seq1; seq <= seq2; seq++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 flags[seq] = change;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 default:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369 i_unreached();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 mail_index_update_flags_range(t, seq1, seq2, modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 change);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 flags_array_check(t, flags, hdr.messages_count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
376
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
377 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
380 static void test_mail_index_cancel_flag_updates(void)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
381 {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
382 struct mail_index_transaction *t;
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
383 const struct mail_index_flag_update *updates;
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
384 unsigned int count;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
385
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
386 hdr.messages_count = 20;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
387 t = mail_index_transaction_new();
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
388
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
389 test_begin("mail index cancel flag updates");
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
390
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
391 mail_index_update_flags_range(t, 5, 7, MODIFY_REPLACE, 0);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
392 updates = array_get(&t->updates, &count);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
393 test_assert(count == 1);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
394 test_assert(updates[0].uid1 == 5 && updates[0].uid2 == 7);
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
395 test_assert(mail_index_cancel_flag_updates(t, 5));
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
396 test_assert(updates[0].uid1 == 6 && updates[0].uid2 == 7);
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
397 test_assert(mail_index_cancel_flag_updates(t, 7));
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
398 test_assert(updates[0].uid1 == 6 && updates[0].uid2 == 6);
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
399 test_assert(mail_index_cancel_flag_updates(t, 6));
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
400 test_assert(!array_is_created(&t->updates));
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
401
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
402 mail_index_update_flags_range(t, 5, 7, MODIFY_REPLACE, 0);
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
403 test_assert(mail_index_cancel_flag_updates(t, 6));
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
404 updates = array_get(&t->updates, &count);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
405 test_assert(count == 2);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
406 test_assert(updates[0].uid1 == 5 && updates[0].uid2 == 5);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
407 test_assert(updates[1].uid1 == 7 && updates[1].uid2 == 7);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
408
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
409 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
410
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
411 mail_index_transaction_cleanup(t);
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
412 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
413
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 static void test_mail_index_flag_update_appends(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 struct mail_index_transaction *t;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 const struct mail_index_record *appends;
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
418 const struct mail_index_flag_update *updates;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419 unsigned int count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 uint32_t seq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
421
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422 hdr.messages_count = 4;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
425 test_begin("mail index flag update appends");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427 test_assert(seq == 5);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429 test_assert(seq == 6);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 mail_index_append(t, 0, &seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 test_assert(seq == 7);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 mail_index_update_flags_range(t, 5, 6, MODIFY_REPLACE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 MAIL_SEEN | MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 mail_index_update_flags_range(t, 6, 7, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 MAIL_DRAFT | MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 mail_index_update_flags_range(t, 5, 7, MODIFY_REMOVE,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 MAIL_FLAGGED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 appends = array_get(&t->appends, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441 test_assert(count == 3);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 test_assert(appends[0].flags == MAIL_SEEN);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443 test_assert(appends[1].flags == (MAIL_SEEN | MAIL_DRAFT));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 test_assert(appends[2].flags == MAIL_DRAFT);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 /* mixed existing/appends */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 mail_index_update_flags_range(t, 4, 5, MODIFY_ADD,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 MAIL_ANSWERED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 test_assert(appends[0].flags == (MAIL_SEEN | MAIL_ANSWERED));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 updates = array_get(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 test_assert(count == 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 test_assert(updates[0].uid1 == 4);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 test_assert(updates[0].uid2 == 4);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 test_assert(updates[0].add_flags == MAIL_ANSWERED);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
457
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
458 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461 static bool test_flag_update_pos(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 uint32_t seq, unsigned int idx)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 unsigned int i, j, count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 count = array_count(&t->updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 for (i = 0; i < idx; i++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 for (j = idx + 1; j <= count; j++) {
18746
2de3c7248922 lib-index: Unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
469 if (mail_index_transaction_get_flag_update_pos(t, i, j, seq) != idx) {
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 test_assert(FALSE);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 return FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 static void test_mail_index_transaction_get_flag_update_pos(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 struct mail_index_transaction *t;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 test_begin("mail index transaction get flag update pos");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 hdr.messages_count = 10;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 t = mail_index_transaction_new();
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 mail_index_update_flags_range(t, 1, 1, MODIFY_REPLACE, 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
487 mail_index_update_flags_range(t, 3, 4, MODIFY_REPLACE, 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
488 mail_index_update_flags_range(t, 6, 7, MODIFY_REPLACE, 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
489 mail_index_update_flags_range(t, 9, 10, MODIFY_REPLACE, 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
491 test_assert(test_flag_update_pos(t, 1, 0));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 test_assert(test_flag_update_pos(t, 2, 1));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493 test_assert(test_flag_update_pos(t, 3, 1));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494 test_assert(test_flag_update_pos(t, 4, 1));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
495 test_assert(test_flag_update_pos(t, 5, 2));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496 test_assert(test_flag_update_pos(t, 6, 2));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497 test_assert(test_flag_update_pos(t, 7, 2));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498 test_assert(test_flag_update_pos(t, 8, 3));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499 test_assert(test_flag_update_pos(t, 9, 3));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
500 test_assert(test_flag_update_pos(t, 10, 3));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501 test_assert(test_flag_update_pos(t, 11, 4));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 test_assert(test_flag_update_pos(t, 12, 4));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
504
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
505 mail_index_transaction_cleanup(t);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
507
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
508 static void test_mail_index_modseq_update(void)
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
509 {
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
510 struct mail_index_transaction *t;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
511 const struct mail_transaction_modseq_update *ups;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
512 unsigned int count;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
513
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
514 test_begin("mail index modseq update");
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
515
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
516 hdr.messages_count = 10;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
517 t = mail_index_transaction_new();
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
518
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
519 mail_index_update_modseq(t, 4, 0x8234fefa02747429ULL);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
520 mail_index_update_modseq(t, 6, 0x1234567890abcdefULL);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
521 mail_index_update_modseq(t, 2, 0xfeed);
10477
240739b27688 mail-index-transaction-update unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
522 mail_index_update_modseq(t, 4, 2);
240739b27688 mail-index-transaction-update unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
523 /* modseq=1 updates are ignored: */
240739b27688 mail-index-transaction-update unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
524 mail_index_update_modseq(t, 5, 1);
240739b27688 mail-index-transaction-update unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
525 mail_index_update_modseq(t, 6, 1);
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
526
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
527 ups = array_get(&t->modseq_updates, &count);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
528 test_assert(count == 4);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
529 test_assert(ups[0].uid == 4 &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
530 ups[0].modseq_high32 == 0x8234fefa &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
531 ups[0].modseq_low32 == 0x02747429);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
532 test_assert(ups[1].uid == 6 &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
533 ups[1].modseq_high32 == 0x12345678 &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
534 ups[1].modseq_low32 == 0x90abcdef);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
535 test_assert(ups[2].uid == 2 &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
536 ups[2].modseq_high32 == 0 &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
537 ups[2].modseq_low32 == 0xfeed);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
538 test_assert(ups[3].uid == 4 &&
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
539 ups[3].modseq_high32 == 0 &&
10477
240739b27688 mail-index-transaction-update unit test fix.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
540 ups[3].modseq_low32 == 2);
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
541 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
542
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
543 mail_index_transaction_cleanup(t);
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
544 }
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
545
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
546 static void test_mail_index_expunge(void)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
547 {
13287
957060ca5b69 Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
548 static guid_128_t empty_guid = { 0, };
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
549 struct mail_index_transaction *t;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
550 const struct mail_transaction_expunge_guid *expunges;
13287
957060ca5b69 Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
551 guid_128_t guid2, guid3, guid4;
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
552 unsigned int i, count;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
553
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
554 test_begin("mail index expunge");
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
555
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
556 hdr.messages_count = 10;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
557 t = mail_index_transaction_new();
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
558 for (i = 0; i < sizeof(guid2); i++) {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
559 guid2[i] = i + 1;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
560 guid3[i] = i ^ 0xff;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
561 guid4[i] = i + 0x80;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
562 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
563
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
564 mail_index_expunge_guid(t, 4, guid4);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
565 test_assert(!t->expunges_nonsorted);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
566 mail_index_expunge_guid(t, 2, guid2);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
567 test_assert(t->expunges_nonsorted);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
568 mail_index_expunge_guid(t, 3, guid3);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
569 mail_index_expunge(t, 1);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
570 mail_index_expunge(t, 5);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
571
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
572 expunges = array_get(&t->expunges, &count);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
573 test_assert(count == 5);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
574 test_assert(expunges[0].uid == 4);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
575 test_assert(memcmp(expunges[0].guid_128, guid4, sizeof(guid4)) == 0);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
576 test_assert(expunges[1].uid == 2);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
577 test_assert(memcmp(expunges[1].guid_128, guid2, sizeof(guid2)) == 0);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
578 test_assert(expunges[2].uid == 3);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
579 test_assert(memcmp(expunges[2].guid_128, guid3, sizeof(guid3)) == 0);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
580 test_assert(expunges[3].uid == 1);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
581 test_assert(memcmp(expunges[3].guid_128, empty_guid, sizeof(empty_guid)) == 0);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
582 test_assert(expunges[4].uid == 5);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
583 test_assert(memcmp(expunges[4].guid_128, empty_guid, sizeof(empty_guid)) == 0);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
584
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
585 test_end();
17781
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
586
f0701f84ca01 lib-index: test suite memory leak cleanup
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
587 mail_index_transaction_cleanup(t);
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
588 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
589
21571
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
590 static void test_mail_index_update_day_first_uid(void)
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
591 {
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
592 struct {
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
593 uint32_t now;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
594 uint32_t old_day_stamp;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
595 uint32_t new_day_stamp;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
596 uint32_t new_day_first_uid[8];
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
597 } tests[] = {
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
598 /* 1487116800 = 2017-02-15 00:00:00 UTC */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
599 { 1487116800, 1487116800, 1487116800, { 8, 7, 6, 5, 4, 3, 2, 1 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
600 /* still same day */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
601 { 1487116800+3600*24-1, 1487116800, 1487116800, { 8, 7, 6, 5, 4, 3, 2, 1 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
602 /* one day earlier */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
603 { 1487116800-1, 1487116800, 1487116800, { 8, 7, 6, 5, 4, 3, 2, 1 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
604 /* next day */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
605 { 1487116800+3600*24, 1487116800, 1487116800+3600*24, { 9, 8, 7, 6, 5, 4, 3, 2 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
606 { 1487116800+3600*24*2-1, 1487116800, 1487116800+3600*24, { 9, 8, 7, 6, 5, 4, 3, 2 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
607 /* 2 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
608 { 1487116800+3600*24*2, 1487116800, 1487116800+3600*24*2, { 9, 8, 8, 7, 6, 5, 4, 3 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
609 /* 3 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
610 { 1487116800+3600*24*3, 1487116800, 1487116800+3600*24*3, { 9, 8, 8, 8, 7, 6, 5, 4 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
611 /* 4 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
612 { 1487116800+3600*24*4, 1487116800, 1487116800+3600*24*4, { 9, 8, 8, 8, 8, 7, 6, 5 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
613 /* 5 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
614 { 1487116800+3600*24*5, 1487116800, 1487116800+3600*24*5, { 9, 8, 8, 8, 8, 8, 7, 6 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
615 /* 6 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
616 { 1487116800+3600*24*6, 1487116800, 1487116800+3600*24*6, { 9, 8, 8, 8, 8, 8, 8, 7 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
617 /* 7 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
618 { 1487116800+3600*24*7, 1487116800, 1487116800+3600*24*7, { 9, 8, 8, 8, 8, 8, 8, 8 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
619 /* 8 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
620 { 1487116800+3600*24*8, 1487116800, 1487116800+3600*24*8, { 9, 8, 8, 8, 8, 8, 8, 8 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
621 /* 366 days */
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
622 { 1487116800+3600*24*366, 1487116800, 1487116800+3600*24*366, { 9, 8, 8, 8, 8, 8, 8, 8 } },
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
623 };
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
624 struct mail_index_transaction *t;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
625 struct mail_index_record *rec;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
626 unsigned int i, j;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
627
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
628 test_begin("mail index update day first uid");
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
629
21751
dc989aeb7299 lib-index: Fix test-mail-index-transaction-update
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21571
diff changeset
630 /* daylight savings times were confusing these tests, so we'll now
dc989aeb7299 lib-index: Fix test-mail-index-transaction-update
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21571
diff changeset
631 just assume that TZ=UTC */
dc989aeb7299 lib-index: Fix test-mail-index-transaction-update
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21571
diff changeset
632 test_assert(timezone == 0);
dc989aeb7299 lib-index: Fix test-mail-index-transaction-update
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21571
diff changeset
633
21571
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
634 hdr.messages_count = 10;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
635 t = mail_index_transaction_new();
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
636 t->view = t_new(struct mail_index_view, 1);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
637 t->view->map = t_new(struct mail_index_map, 1);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
638
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
639 t_array_init(&t->appends, 1);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
640 rec = array_append_space(&t->appends);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
641 rec->uid = 9;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
642
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
643 for (i = 0; i < N_ELEMENTS(tests); i++) {
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
644 i_zero(&hdr);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
645 for (j = 0; j < N_ELEMENTS(hdr.day_first_uid); j++)
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
646 hdr.day_first_uid[j] = 8-j;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
647 hdr.day_stamp = tests[i].old_day_stamp + timezone;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
648 memcpy(t->post_hdr_change, &hdr, sizeof(hdr));
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
649 mail_index_update_day_headers(t, tests[i].now + timezone);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
650
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
651 struct mail_index_header new_hdr;
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
652 memcpy(&new_hdr, t->post_hdr_change, sizeof(new_hdr));
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
653 test_assert_idx(new_hdr.day_stamp == tests[i].new_day_stamp + timezone, i);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
654 test_assert_idx(memcmp(new_hdr.day_first_uid,
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
655 tests[i].new_day_first_uid,
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
656 sizeof(uint32_t) * 8) == 0, i);
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
657 }
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
658
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
659 test_end();
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
660 }
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
661
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
662 int main(void)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
663 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
664 static void (*test_functions[])(void) = {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
665 test_mail_index_append,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
666 test_mail_index_flag_update_fastpath,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
667 test_mail_index_flag_update_simple_merges,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
668 test_mail_index_flag_update_complex_merges,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
669 test_mail_index_flag_update_random,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
670 test_mail_index_flag_update_appends,
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
671 test_mail_index_cancel_flag_updates,
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
672 test_mail_index_transaction_get_flag_update_pos,
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
673 test_mail_index_modseq_update,
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
674 test_mail_index_expunge,
21571
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
675 test_mail_index_update_day_first_uid,
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
676 NULL
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
677 };
21751
dc989aeb7299 lib-index: Fix test-mail-index-transaction-update
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21571
diff changeset
678 /* daylight saving time confuses things */
dc989aeb7299 lib-index: Fix test-mail-index-transaction-update
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21571
diff changeset
679 putenv("TZ=UTC");
21571
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
680 tzset();
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
681 return test_run(test_functions);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
682 }