2
* Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
4
* Permission to use, copy, modify, and/or distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
8
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
* PERFORMANCE OF THIS SOFTWARE.
27
#include <isc/symtab.h>
28
#include <isc/print.h>
33
undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) {
36
ATF_REQUIRE_EQ(type, 1);
37
isc_mem_free(mctx, key);
38
isc_mem_free(mctx, value.as_pointer);
42
* Individual unit tests
46
ATF_TC_HEAD(symtab_grow, tc) {
47
atf_tc_set_md_var(tc, "descr", "symbol table growth");
49
ATF_TC_BODY(symtab_grow, tc) {
51
isc_symtab_t *st = NULL;
53
isc_symexists_t policy = isc_symexists_reject;
58
result = isc_test_begin(NULL);
59
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
61
result = isc_symtab_create(mctx, 3, undefine, NULL, ISC_FALSE, &st);
62
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
63
ATF_REQUIRE(st != NULL);
65
/* Nothing should be in the table yet */
68
* Put 1024 entries in the table (this should necessate
69
* regrowing the hash table several times
71
for (i = 0; i < 1024; i++) {
74
snprintf(str, sizeof(str), "%04x", i);
75
key = isc_mem_strdup(mctx, str);
76
ATF_REQUIRE(key != NULL);
77
value.as_pointer = isc_mem_strdup(mctx, str);
78
ATF_REQUIRE(value.as_pointer != NULL);
79
result = isc_symtab_define(st, key, 1, value, policy);
80
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
81
if (result != ISC_R_SUCCESS)
82
undefine(key, 1, value, NULL);
86
* Try to put them in again; this should fail
88
for (i = 0; i < 1024; i++) {
91
snprintf(str, sizeof(str), "%04x", i);
92
key = isc_mem_strdup(mctx, str);
93
ATF_REQUIRE(key != NULL);
94
value.as_pointer = isc_mem_strdup(mctx, str);
95
ATF_REQUIRE(value.as_pointer != NULL);
96
result = isc_symtab_define(st, key, 1, value, policy);
97
ATF_CHECK_EQ(result, ISC_R_EXISTS);
98
undefine(key, 1, value, NULL);
102
* Retrieve them; this should succeed
104
for (i = 0; i < 1024; i++) {
107
snprintf(str, sizeof(str), "%04x", i);
108
result = isc_symtab_lookup(st, str, 0, &value);
109
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
110
ATF_CHECK_STREQ(str, value.as_pointer);
116
for (i = 0; i < 1024; i++) {
119
snprintf(str, sizeof(str), "%04x", i);
120
result = isc_symtab_undefine(st, str, 1);
121
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
125
* Retrieve them again; this should fail
127
for (i = 0; i < 1024; i++) {
130
snprintf(str, sizeof(str), "%04x", i);
131
result = isc_symtab_lookup(st, str, 0, &value);
132
ATF_CHECK_EQ(result, ISC_R_NOTFOUND);
135
isc_symtab_destroy(&st);
143
ATF_TP_ADD_TC(tp, symtab_grow);
145
return (atf_no_error());