bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen#include "test-lib.h"
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen#include "wildcard-match.h"
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen
b7324e421e2132cbbf753e6fdbe675bbaecdf929Timo Sirainenstatic const struct {
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen const char *data;
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen const char *mask;
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen bool result;
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen} tests[] = {
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "*", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "*foo*", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "foo", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f*o*o", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f??", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f?o", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "*??", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "???", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f??*", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "???*", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "fo", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "fooo", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "????", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f*o*o*o", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "foo", "f???*", FALSE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen
52b61e1dfc393a7d4999dbfaa6ff8e59c3662e79Timo Sirainen { "*foo", "foo", FALSE },
52b61e1dfc393a7d4999dbfaa6ff8e59c3662e79Timo Sirainen { "foo*", "foo", FALSE },
52b61e1dfc393a7d4999dbfaa6ff8e59c3662e79Timo Sirainen { "*foo*", "foo", FALSE },
52b61e1dfc393a7d4999dbfaa6ff8e59c3662e79Timo Sirainen
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "", "*", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "", "", TRUE },
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen { "", "?", FALSE }
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen};
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainenvoid test_wildcard_match(void)
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen{
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen unsigned int i;
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen test_begin("wildcard_match()");
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen for (i = 0; i < N_ELEMENTS(tests); i++) {
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen test_assert_idx(wildcard_match(tests[i].data, tests[i].mask) == tests[i].result, i);
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen }
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen test_end();
5a9c7366ed354a7ad309cc17c7cf9951facfedf5Timo Sirainen}