test-mail-storage.c revision bcb4e51a409d94ae670de96afb8483a4f7855294
/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "test-common.h"
#include "mail-storage-private.h"
{
}
{
}
}
static void test_mail_storage_errors(void)
{
struct mail_storage storage;
enum mail_error mail_error;
const char *errstr;
test_begin("mail storage errors");
/* try a regular error */
/* set the error to itself */
/* clear the error - asking for it afterwards is a bug */
test_assert(strcmp(mail_storage_get_last_error(&storage, &mail_error), "BUG: Unknown internal error") == 0);
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "BUG: Unknown internal error") == 0);
/* set internal error in preparation for the next test */
test_expect_error_string("critical0");
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
/* internal error without specifying what it is. this needs to clear
the previous internal error. */
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
test_assert(strstr(mail_storage_get_last_internal_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
/* proper internal error */
test_expect_error_string("critical1");
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
/* use it in the following internal error */
test_expect_error_string("critical2: critical1");
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "critical2: critical1") == 0);
/* use the previous non-internal error as part of the internal error */
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
/* clear the error again and check that all is as expected */
test_assert(strcmp(mail_storage_get_last_error(&storage, &mail_error), "BUG: Unknown internal error") == 0);
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "BUG: Unknown internal error") == 0);
/* use internal error as a regular error (although that really
shouldn't be done) */
test_expect_error_string("critical4");
test_end();
}
static void test_mail_storage_last_error_push_pop(void)
{
struct mail_storage storage;
enum mail_error mail_error;
/* regular error 1 */
/* critical error 1 */
test_expect_error_string("critical error 1");
/* regular error 2 */
/* critical error 2 */
test_expect_error_string("critical error 2");
/* -- clear all errors -- */
/* critical error 2 pop */
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "critical error 2") == 0);
/* regular error 2 pop */
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "regular error 2") == 0);
/* critical error 1 pop */
test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "critical error 1") == 0);
/* regular error 1 pop */
test_assert(strcmp(mail_storage_get_last_internal_error(&storage, &mail_error), "regular error 1") == 0);
test_end();
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}