bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen#include "lib.h"
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen#include "message-id.h"
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen#include "test-common.h"
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainenstatic void test_message_id_get_next(void)
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen{
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen const char *input[] = {
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen "<foo@bar>",
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen "<foo@bar>,skipped,<foo2@bar2>",
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen "(c) < (c) foo (c) @ (c) bar (c) > (c)",
94fc6781711341cb3af587af236d85c74e5b1a1dTimo Sirainen "<\"foo 2\"@bar>"
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen };
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen const char *output[] = {
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen "foo@bar", NULL,
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen "foo@bar", "foo2@bar2", NULL,
94fc6781711341cb3af587af236d85c74e5b1a1dTimo Sirainen "foo@bar", NULL,
94fc6781711341cb3af587af236d85c74e5b1a1dTimo Sirainen "foo 2@bar", NULL
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen };
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen const char *msgid, *next_msgid;
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen unsigned int i, j;
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen test_begin("message id parser");
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen for (i = 0, j = 0; i < N_ELEMENTS(input); i++) {
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen msgid = input[i];
b879ed8dd4b5850987e6b89a92f794d87c6be7d7Timo Sirainen while ((next_msgid = message_id_get_next(&msgid)) != NULL) {
b879ed8dd4b5850987e6b89a92f794d87c6be7d7Timo Sirainen if (output[j] == NULL)
b879ed8dd4b5850987e6b89a92f794d87c6be7d7Timo Sirainen break;
648a6034e304c1ffa7fa8c291e03a0bca3c20288Timo Sirainen test_assert(strcmp(output[j], next_msgid) == 0);
648a6034e304c1ffa7fa8c291e03a0bca3c20288Timo Sirainen j++;
b879ed8dd4b5850987e6b89a92f794d87c6be7d7Timo Sirainen }
b879ed8dd4b5850987e6b89a92f794d87c6be7d7Timo Sirainen test_assert(output[j++] == NULL && next_msgid == NULL);
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen }
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen test_assert(j == N_ELEMENTS(output));
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen test_end();
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen}
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainenint main(void)
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen{
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen test_message_id_get_next,
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen NULL
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen };
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen return test_run(test_functions);
2d84942c22d30cf7b3e53943bce1e3ad024c7c88Timo Sirainen}