bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenbool mail_index_map_get_ext_idx(struct mail_index_map *map ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen uint32_t *idx_r ATTR_UNUSED) { return FALSE; }
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenvoid mail_index_ext_set_reset_id(struct mail_index_transaction *t ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenvoid mail_index_transaction_set_log_updates(struct mail_index_transaction *t ATTR_UNUSED) { }
d97f939b1c09e9f90b01b6f81bfb1c05da990148Timo Sirainenvoid mail_index_update_day_headers(struct mail_index_transaction *t ATTR_UNUSED, time_t day_stamp ATTR_UNUSED) {}
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenbool mail_index_cancel_flag_updates(struct mail_index_transaction *t ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenbool mail_index_cancel_keyword_updates(struct mail_index_transaction *t ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenvoid mail_index_transaction_sort_appends(struct mail_index_transaction *t ATTR_UNUSED) {}
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenint mail_index_map(struct mail_index *index ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen enum mail_index_sync_handler_type type ATTR_UNUSED) { return 1; }
4b89231f4ec9cc69f4aea715e1d34f405c7e317dTimo Sirainenvoid mail_index_update_modseq(struct mail_index_transaction *t ATTR_UNUSED, uint32_t seq ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenmail_index_lookup(struct mail_index_view *view ATTR_UNUSED, uint32_t seq)
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenmail_index_transaction_lookup(struct mail_index_transaction *t ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenuint64_t mail_index_modseq_lookup(struct mail_index_view *view ATTR_UNUSED,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainenuint64_t mail_index_modseq_get_highest(struct mail_index_view *view ATTR_UNUSED)
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen#define MAIL_INDEX_TRANSACTION_FINISH(t, n_so_far) \
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen for (unsigned int sofar = 0; sofar < n_so_far; sofar++) \
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainentest_mail_index_transaction_finish_flag_updates(unsigned int n_so_far)
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen u.add_flags = MAIL_SEEN; u.remove_flags = MAIL_DRAFT;
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen test_begin(t_strdup_printf("mail index transaction finish flag updates n_so_far=%u", n_so_far));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen /* test fast path: all changed */
bddd52cb7f3e5a894c080f60750aa76b5aeaf103Timo Sirainen test_assert(updates[0].uid1 == 1*2 && updates[0].uid2 == 1*2);
bddd52cb7f3e5a894c080f60750aa76b5aeaf103Timo Sirainen test_assert(updates[1].uid1 == 2*2 && updates[1].uid2 == 2*2);
bddd52cb7f3e5a894c080f60750aa76b5aeaf103Timo Sirainen test_assert(updates[2].uid1 == 4*2 && updates[2].uid2 == 4*2);
bddd52cb7f3e5a894c080f60750aa76b5aeaf103Timo Sirainen test_assert(updates[3].uid1 == 5*2 && updates[3].uid2 == 5*2);
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen /* nothing changed */
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen /* some changes */
bddd52cb7f3e5a894c080f60750aa76b5aeaf103Timo Sirainen test_assert(updates[0].uid1 == 3*2 && updates[0].uid2 == 3*2);
bddd52cb7f3e5a894c080f60750aa76b5aeaf103Timo Sirainen test_assert(updates[1].uid1 == 6*2 && updates[1].uid2 == 6*2);
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainentest_mail_index_transaction_finish_check_conflicts(unsigned int n_so_far)
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen ARRAY_TYPE(seq_range) conflict_seqs = ARRAY_INIT;
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen test_begin(t_strdup_printf("mail index transaction finish check conflicts n_so_far=%u", n_so_far));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen /* fast path: no conflicts */
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_assert(!array_is_created(&conflict_seqs));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen /* try some conflicts */
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen conflicts = array_get(&conflict_seqs, &count);
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_assert(conflicts[0].seq1 == 6 && conflicts[0].seq2 == 6);
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_assert(conflicts[1].seq1 == 8 && conflicts[1].seq2 == 8);
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainentest_mail_index_transaction_finish_modseq_updates(unsigned int n_so_far)
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen const struct mail_transaction_modseq_update *ups;
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen test_begin(t_strdup_printf("mail index transaction finish modseq updates n_so_far=%u", n_so_far));
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen u.uid = 1; array_append(&t->modseq_updates, &u, 1);
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen u.uid = 2; array_append(&t->modseq_updates, &u, 1);
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen u.uid = 5; array_append(&t->modseq_updates, &u, 1);
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen u.uid = 2; array_append(&t->modseq_updates, &u, 1);
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen test_assert(ups[0].modseq_low32 == 1234567890 &&
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen test_assert(ups[1].modseq_low32 == 1234567891 &&
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen test_assert(ups[2].modseq_low32 == 1234567892 &&
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainentest_mail_index_transaction_finish_expunges(unsigned int n_so_far)
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen const struct mail_transaction_expunge_guid *expunges;
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen for (i = 0; i < sizeof(guid2); i++) {
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen test_begin(t_strdup_printf("mail index transaction finish expunges n_so_far=%u", n_so_far));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen memcpy(expunge.guid_128, guid2, sizeof(expunge.guid_128));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen memcpy(expunge.guid_128, guid1, sizeof(expunge.guid_128));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen memcpy(expunge.guid_128, guid3, sizeof(expunge.guid_128));
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_assert(memcmp(expunges[0].guid_128, guid1, sizeof(guid1)) == 0);
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_assert(memcmp(expunges[1].guid_128, guid2, sizeof(guid2)) == 0);
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_assert(memcmp(expunges[2].guid_128, guid3, sizeof(guid3)) == 0);
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen for (unsigned int n = 1; n < N_ELEMENTS(recs); n++)
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainenstatic void test_mail_index_transaction_finish(void)
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen void (*const test_finish_functions[])(unsigned int) = {
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_mail_index_transaction_finish_flag_updates,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen test_mail_index_transaction_finish_check_conflicts,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen test_mail_index_transaction_finish_modseq_updates,
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen unsigned int i, j;
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen for (i = 0; i < N_ELEMENTS(test_finish_functions); i++) {
a42d489d99bcf7d18cfd0352fdf0c9348cb224fcTimo Sirainen for (j = 0; j < 3; j++) {
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {