2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Library General Public License for more details.
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the Free
16 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 #define TABLE0 (void *)0x76543210
28 #define DEADINT 0xdeadbeef
29 #define DEADPTR (void *)0xdeadbeef
32 check_init(smat_table_t *table, unsigned long flags, unsigned long mod,
33 smat_resize_t rsize, void *extra, char *how)
35 if (table->st_magic != SMAT_TABLE_MAGIC) /* Verify magic was set */
36 printf("FAIL/%s_magic:Initialization failed to set magic number\n", how);
38 printf("PASS/%s_magic:Initialization set magic number properly\n", how);
40 if (!ht_verify(&table->st_table)) /* Verify hash table initialized */
41 printf("FAIL/%s_htinit:Initialization failed to initialize hash table\n",
44 printf("PASS/%s_htinit:Initialization initialized hash table properly\n",
47 if (ht_flags(&table->st_table) != flags) /* verify flags were set */
48 printf("FAIL/%s_hflags:Initialization failed to set flags\n", how);
50 printf("PASS/%s_hflags:Initialization set flags properly\n", how);
52 if (ht_modulus(&table->st_table) != mod) /* verify modulus was set */
53 printf("FAIL/%s_hmodulus:Initialization failed to set modulus to %ld "
54 "(%ld instead)\n", how, mod, ht_modulus(&table->st_table));
56 printf("PASS/%s_hmodulus:Initialization set modulus to %ld\n", how, mod);
58 if (ht_func(&table->st_table) != _smat_hash) /* verify func was set */
59 printf("FAIL/%s_hfunc:Initialization failed to set hash func\n", how);
61 printf("PASS/%s_hfunc:Initialization set hash func properly\n", how);
63 if (ht_comp(&table->st_table) != _smat_comp) /* verify comp was set */
64 printf("FAIL/%s_hcomp:Initialization failed to set hash comp\n", how);
66 printf("PASS/%s_hcomp:Initialization set hash comp properly\n", how);
68 if (ht_rsize(&table->st_table) != _smat_resize) /* verify resize was set */
69 printf("FAIL/%s_hrsize:Initialization failed to set hash resize\n", how);
71 printf("PASS/%s_hrsize:Initialization set hash resize properly\n", how);
73 if (table->st_resize != rsize) /* verify resize was set */
74 printf("FAIL/%s_rsize:Initialization failed to set resize\n", how);
76 printf("PASS/%s_rsize:Initialization set resize properly\n", how);
78 if (ht_extra(&table->st_table) != extra) /* verify extra was set */
79 printf("FAIL/%s_hextra:Initialization failed to set extra\n", how);
81 printf("PASS/%s_hextra:Initialization set extra properly\n", how);
84 /* Check return value of operation and report PASS/FAIL */
86 check_result(unsigned long result, unsigned long expected, char *test,
89 if (result != expected) {
90 printf("FAIL/%s:%s incorrectly returned %lu (expected %lu)\n", test, info,
95 printf("PASS/%s:%s correctly returned %lu\n", test, info, result);
98 /* Scramble the table */
100 scramble(smat_table_t *table)
102 table->st_magic = DEADINT;
103 table->st_resize = (smat_resize_t)DEADPTR;
104 table->st_table.ht_magic = DEADINT;
105 ht_flags(&table->st_table) = DEADINT;
106 ht_modulus(&table->st_table) = DEADINT;
107 ht_func(&table->st_table) = (hash_func_t)DEADPTR;
108 ht_comp(&table->st_table) = (hash_comp_t)DEADPTR;
109 ht_extra(&table->st_table) = DEADPTR;
113 check_rsize(smat_table_t *tab, unsigned long new_mod)
119 main(int argc, char **argv)
121 smat_table_t table = SMAT_TABLE_INIT(0x80010000 | HASH_FLAG_AUTOGROW,
122 check_rsize, TABLE0);
124 /* Check that the static initializer produces a passable structure */
125 check_init(&table, HASH_FLAG_AUTOGROW, 0, check_rsize, TABLE0, "st_static");
127 /* now, check what ht_init does with bad arguments */
128 check_result(st_init(0, 0, 0, 0, 0), DB_ERR_BADARGS, "st_init_noargs",
129 "st_init() with no valid arguments", 0);
131 /* Scramble the structure */
134 /* Now try to initialize our structure with a 0 mod and see what happens */
135 check_result(st_init(&table, 0x80010000 | HASH_FLAG_AUTOGROW, check_rsize,
136 TABLE0, 0), 0, "st_dynamic_nomod",
137 "st_init() with zero modulus", 0);
138 check_init(&table, HASH_FLAG_AUTOGROW, 0, check_rsize, TABLE0,
141 /* Scramble the structure again */
144 /* Now try to initialize our structure with a non-0 mod and see what
147 check_result(st_init(&table, 0x80010000 | HASH_FLAG_AUTOGROW, check_rsize,
148 TABLE0, 6), 0, "st_dynamic_mod6",
149 "st_init() with non-zero modulus", 0);
150 check_init(&table, HASH_FLAG_AUTOGROW, 7, check_rsize, TABLE0,