Mercurial > dovecot > core-2.2
changeset 22201:1411caa97648
lib-storage: test-mail-search-args-simplify - test with initialized args
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 07 Jun 2017 19:54:10 +0300 |
parents | 171b3599cc0f |
children | 23f6dcef10c4 |
files | src/lib-storage/test-mail-search-args-simplify.c |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/test-mail-search-args-simplify.c Wed Jun 07 19:53:00 2017 +0300 +++ b/src/lib-storage/test-mail-search-args-simplify.c Wed Jun 07 19:54:10 2017 +0300 @@ -235,6 +235,36 @@ return sargs; } +static bool test_search_args_are_initialized(struct mail_search_arg *arg) +{ + for (; arg != NULL; arg = arg->next) { + switch (arg->type) { + case SEARCH_MODSEQ: + if (arg->value.str != NULL && + arg->initialized.keywords == NULL) + return FALSE; + break; + case SEARCH_KEYWORDS: + if (arg->initialized.keywords == NULL) + return FALSE; + break; + case SEARCH_MAILBOX_GLOB: + if (arg->initialized.mailbox_glob == NULL) + return FALSE; + break; + case SEARCH_INTHREAD: + case SEARCH_SUB: + case SEARCH_OR: + if (!test_search_args_are_initialized(arg->value.subargs)) + return FALSE; + break; + default: + break; + } + } + return TRUE; +} + static void test_mail_search_args_simplify(void) { struct mail_search_args *args; @@ -249,12 +279,18 @@ box.index = mail_index_alloc(NULL, "dovecot.index."); for (i = 0; i < N_ELEMENTS(tests); i++) { args = test_build_search_args(tests[i].input); + /* delay simplification until after init. that way we can test + that the simplification works correctly when working on + already-initialized args. */ + args->simplified = TRUE; mail_search_args_init(args, &box, FALSE, NULL); mail_search_args_simplify(args); str_truncate(str, 0); test_assert(mail_search_args_to_imap(str, args->args, &error)); test_assert_idx(strcmp(str_c(str), tests[i].output) == 0, i); + + test_assert_idx(test_search_args_are_initialized(args->args), i); mail_search_args_unref(&args); } mail_index_free(&box.index);