summaryrefslogtreecommitdiffstats
path: root/src/lib-index/test-mail-index.h
blob: 75b343f92b0346ad951319445d760589ddcc6f0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef TEST_MAIL_INDEX_H
#define TEST_MAIL_INDEX_H

#include "ioloop.h"
#include "unlink-directory.h"
#include "mail-index-private.h"

#define TESTDIR_NAME ".dovecot.test"

static inline struct mail_index *test_mail_index_open(void)
{
	struct mail_index *index;

	index = mail_index_alloc(NULL, TESTDIR_NAME, "test.dovecot.index");
	test_assert(mail_index_open_or_create(index, MAIL_INDEX_OPEN_FLAG_CREATE) == 0);
	return index;
}

static inline struct mail_index *test_mail_index_init(void)
{
	const char *error;

	(void)unlink_directory(TESTDIR_NAME, UNLINK_DIRECTORY_FLAG_RMDIR, &error);
	if (mkdir(TESTDIR_NAME, 0700) < 0)
		i_error("mkdir(%s) failed: %m", TESTDIR_NAME);

	ioloop_time = 1;

	return test_mail_index_open();
}

static inline void test_mail_index_close(struct mail_index **index)
{
	mail_index_close(*index);
	mail_index_free(index);
}

static inline void test_mail_index_delete(void)
{
	const char *error;

	(void)unlink_directory(TESTDIR_NAME, UNLINK_DIRECTORY_FLAG_RMDIR, &error);
}

static inline void test_mail_index_deinit(struct mail_index **index)
{
	test_mail_index_close(index);
	test_mail_index_delete();
}

#endif