bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen#include "test-lib.h"
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen#include "str-table.h"
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainenvoid test_str_table(void)
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen{
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen struct str_table *table;
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen const char *key1, *key2, *key1_copy, *key2_copy;
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_begin("str_table");
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen table = str_table_init();
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen key1 = str_table_ref(table, "str1");
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen key2 = str_table_ref(table, "str2");
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_assert(key1 != key2);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen key1_copy = str_table_ref(table, "str1");
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_assert(key1_copy == key1);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen key2_copy = str_table_ref(table, "str2");
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_assert(key2_copy == key2);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen str_table_unref(table, &key1);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_assert(key1 == NULL);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen str_table_unref(table, &key1_copy);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen str_table_unref(table, &key2);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen str_table_unref(table, &key2_copy);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_assert(str_table_is_empty(table));
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen str_table_deinit(&table);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_assert(table == NULL);
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen test_end();
639587335dfe5d66dc7034817b3e685458ecbee1Timo Sirainen}