test-mail-index-transaction-update.c revision 95fe5a25ac87f2a56933117a80373cf38379c456
/* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "test-common.h"
#include "mail-index-private.h"
#include "mail-index-transaction-private.h"
#include <time.h>
static struct mail_index_header hdr;
static struct mail_index_record rec;
const struct mail_index_header *
{
return &hdr;
}
const struct mail_index_record *
{
return &rec;
}
{
}
{
return FALSE;
}
{
return hdr.messages_count;
}
{
}
struct mail_keywords *
const ARRAY_TYPE(keyword_indexes)
{
return NULL;
}
{
}
static struct mail_index_transaction *
{
struct mail_index_transaction *t;
return t;
}
static void mail_index_transaction_cleanup(struct mail_index_transaction *t)
{
if (array_is_created(&t->appends))
array_free(&t->appends);
if (array_is_created(&t->updates))
array_free(&t->updates);
if (array_is_created(&t->modseq_updates))
array_free(&t->modseq_updates);
if (array_is_created(&t->expunges))
array_free(&t->expunges);
}
static void test_mail_index_append(void)
{
struct mail_index_transaction *t;
const struct mail_index_record *appends;
const struct seq_range *saved_uids;
unsigned int count;
t = mail_index_transaction_new();
test_begin("mail index append");
mail_index_append(t, 0, &seq);
test_assert(t->log_updates);
mail_index_append(t, 0, &seq);
test_assert(!t->appends_nonsorted);
test_end();
/* test with some uids */
t = mail_index_transaction_new();
test_begin("mail index append with uids");
mail_index_append(t, 0, &seq);
test_assert(!t->appends_nonsorted);
mail_index_append(t, 0, &seq);
test_end();
}
static void test_mail_index_flag_update_fastpath(void)
{
struct mail_index_transaction *t;
const struct mail_index_flag_update *updates;
unsigned int count;
t = mail_index_transaction_new();
test_begin("mail index flag update fast paths");
test_assert(t->last_update_idx == 0);
test_assert(t->last_update_idx == 0);
test_assert(!t->log_updates);
test_end();
}
static void test_mail_index_flag_update_simple_merges(void)
{
struct mail_index_transaction *t;
const struct mail_index_flag_update *updates;
unsigned int count;
t = mail_index_transaction_new();
test_begin("mail index flag update simple merges");
test_assert(t->last_update_idx == 0);
test_assert(t->last_update_idx == 0);
test_assert(t->last_update_idx == 0);
test_assert(t->last_update_idx == 0);
test_end();
}
static void test_mail_index_flag_update_complex_merges(void)
{
struct mail_index_transaction *t;
const struct mail_index_flag_update *updates;
unsigned int count;
t = mail_index_transaction_new();
test_begin("mail index flag update complex merges");
test_end();
}
static void
flags_array_check(struct mail_index_transaction *t,
{
const struct mail_index_flag_update *updates;
if (array_is_created(&t->updates))
else {
count = 0;
}
if (i > 0) {
}
}
}
static void test_mail_index_flag_update_random(void)
{
struct mail_index_transaction *t;
enum modify_type modify_type;
t = mail_index_transaction_new();
test_begin("mail index flag update random");
for (r = 0; r < 1000; r++) {
switch (rand() % 3) {
case 0:
break;
case 1:
break;
case 2:
break;
default:
i_unreached();
}
change);
}
test_end();
}
static void test_mail_index_cancel_flag_updates(void)
{
struct mail_index_transaction *t;
const struct mail_index_flag_update *updates;
unsigned int count;
t = mail_index_transaction_new();
test_begin("mail index cancel flag updates");
test_end();
}
static void test_mail_index_flag_update_appends(void)
{
struct mail_index_transaction *t;
const struct mail_index_record *appends;
const struct mail_index_flag_update *updates;
unsigned int count;
t = mail_index_transaction_new();
test_begin("mail index flag update appends");
mail_index_append(t, 0, &seq);
mail_index_append(t, 0, &seq);
mail_index_append(t, 0, &seq);
test_end();
}
static bool test_flag_update_pos(struct mail_index_transaction *t,
{
unsigned int i, j, count;
for (i = 0; i < idx; i++) {
return FALSE;
}
}
}
return TRUE;
}
static void test_mail_index_transaction_get_flag_update_pos(void)
{
struct mail_index_transaction *t;
test_begin("mail index transaction get flag update pos");
t = mail_index_transaction_new();
test_end();
}
static void test_mail_index_modseq_update(void)
{
struct mail_index_transaction *t;
const struct mail_transaction_modseq_update *ups;
unsigned int count;
test_begin("mail index modseq update");
t = mail_index_transaction_new();
/* modseq=1 updates are ignored: */
test_end();
}
static void test_mail_index_expunge(void)
{
static guid_128_t empty_guid = { 0, };
struct mail_index_transaction *t;
const struct mail_transaction_expunge_guid *expunges;
unsigned int i, count;
test_begin("mail index expunge");
t = mail_index_transaction_new();
for (i = 0; i < sizeof(guid2); i++) {
guid2[i] = i + 1;
guid3[i] = i ^ 0xff;
guid4[i] = i + 0x80;
}
mail_index_expunge(t, 1);
mail_index_expunge(t, 5);
test_end();
}
static void test_mail_index_update_day_first_uid(void)
{
struct {
} tests[] = {
/* 1487116800 = 2017-02-15 00:00:00 UTC */
{ 1487116800, 1487116800, 1487116800, { 8, 7, 6, 5, 4, 3, 2, 1 } },
/* still same day */
{ 1487116800+3600*24-1, 1487116800, 1487116800, { 8, 7, 6, 5, 4, 3, 2, 1 } },
/* one day earlier */
{ 1487116800-1, 1487116800, 1487116800, { 8, 7, 6, 5, 4, 3, 2, 1 } },
/* next day */
{ 1487116800+3600*24, 1487116800, 1487116800+3600*24, { 9, 8, 7, 6, 5, 4, 3, 2 } },
{ 1487116800+3600*24*2-1, 1487116800, 1487116800+3600*24, { 9, 8, 7, 6, 5, 4, 3, 2 } },
/* 2 days */
{ 1487116800+3600*24*2, 1487116800, 1487116800+3600*24*2, { 9, 8, 8, 7, 6, 5, 4, 3 } },
/* 3 days */
{ 1487116800+3600*24*3, 1487116800, 1487116800+3600*24*3, { 9, 8, 8, 8, 7, 6, 5, 4 } },
/* 4 days */
{ 1487116800+3600*24*4, 1487116800, 1487116800+3600*24*4, { 9, 8, 8, 8, 8, 7, 6, 5 } },
/* 5 days */
{ 1487116800+3600*24*5, 1487116800, 1487116800+3600*24*5, { 9, 8, 8, 8, 8, 8, 7, 6 } },
/* 6 days */
{ 1487116800+3600*24*6, 1487116800, 1487116800+3600*24*6, { 9, 8, 8, 8, 8, 8, 8, 7 } },
/* 7 days */
{ 1487116800+3600*24*7, 1487116800, 1487116800+3600*24*7, { 9, 8, 8, 8, 8, 8, 8, 8 } },
/* 8 days */
{ 1487116800+3600*24*8, 1487116800, 1487116800+3600*24*8, { 9, 8, 8, 8, 8, 8, 8, 8 } },
/* 366 days */
{ 1487116800+3600*24*366, 1487116800, 1487116800+3600*24*366, { 9, 8, 8, 8, 8, 8, 8, 8 } },
};
struct mail_index_transaction *t;
struct mail_index_record *rec;
unsigned int i, j;
test_begin("mail index update day first uid");
/* daylight savings times were confusing these tests, so we'll now
just assume that TZ=UTC */
test_assert(timezone == 0);
t = mail_index_transaction_new();
for (i = 0; i < N_ELEMENTS(tests); i++) {
struct mail_index_header new_hdr;
sizeof(uint32_t) * 8) == 0, i);
}
test_end();
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
/* daylight saving time confuses things */
putenv("TZ=UTC");
tzset();
return test_run(test_functions);
}