bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen#include "lib.h"
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen#include "dict-private.h"
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen#include "test-common.h"
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainenstruct dict dict_driver_client;
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainenstruct dict dict_driver_file;
fefd62f9aaccecbc6011ecae359a3389668cbff5Timo Sirainenstruct dict dict_driver_memcached;
75bb83681e30d6a86109bbafdfe6b513c11124bcTimo Sirainenstruct dict dict_driver_memcached_ascii;
31257b47d47510ceb093a6b218810a1a5b830c55Timo Sirainenstruct dict dict_driver_redis;
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainenstatic void test_dict_escape(void)
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen{
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen static const char *input[] = {
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "", "",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "foo", "foo",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "foo\\", "foo\\\\",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "foo\\bar", "foo\\\\bar",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "\\bar", "\\\\bar",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "foo/", "foo\\|",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "foo/bar", "foo\\|bar",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "/bar", "\\|bar",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "////", "\\|\\|\\|\\|",
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen "/", "\\|"
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen };
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen unsigned int i;
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_begin("dict escape");
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen for (i = 0; i < N_ELEMENTS(input); i += 2) {
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_assert(strcmp(dict_escape_string(input[i]), input[i+1]) == 0);
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_assert(strcmp(dict_unescape_string(input[i+1]), input[i]) == 0);
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen }
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_assert(strcmp(dict_unescape_string("x\\"), "x") == 0);
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_assert(strcmp(dict_unescape_string("\\"), "") == 0);
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_end();
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen}
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainenint main(void)
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen{
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen test_dict_escape,
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen NULL
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen };
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen return test_run(test_functions);
8971ca621b7a7337947306494731b75d1d3919e5Timo Sirainen}