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 OBJECT (void *)0x91827364
27 #define DEADINT 0xdeadbeef
28 #define DEADPTR (void *)0xdeadbeef
31 check_init(hash_entry_t *entry, char *how)
33 if (entry->he_magic != HASH_ENTRY_MAGIC) /* Verify magic was set */
34 printf("FAIL/%s_magic:Initialization failed to set magic number\n", how);
36 printf("PASS/%s_magic:Initialization set magic number properly\n", how);
38 if (!le_verify(&entry->he_elem)) /* verify element was initialized */
39 printf("FAIL/%s_elem:Initialization failed to initialize linked list "
42 printf("PASS/%s_elem:Initialization initialized linked list element\n",
45 if (entry->he_table != 0) /* verify table was cleared */
46 printf("FAIL/%s_table:Initialization failed to clear table\n", how);
48 printf("PASS/%s_table:Initialization set table to 0\n", how);
50 if (entry->he_hash != 0) /* verify hash value was cleared */
51 printf("FAIL/%s_hash:Initialization failed to clear hash value\n", how);
53 printf("PASS/%s_hash:Initialization set hash value to 0\n", how);
55 if (dk_key(&entry->he_key) != 0) /* verify key value was cleared */
56 printf("FAIL/%s_key:Initialization failed to clear database key\n", how);
58 printf("PASS/%s_key:Initialization set database key to 0\n", how);
60 if (dk_len(&entry->he_key) != 0) /* verify key length was cleared */
61 printf("FAIL/%s_keylen:Initialization failed to clear database key "
64 printf("PASS/%s_keylen:Initialization set database key length to 0\n",
67 if (entry->he_value != OBJECT) /* verify value was set properly */
68 printf("FAIL/%s_value:Initialization failed to set value\n", how);
70 printf("PASS/%s_value:Initialization set value properly\n", how);
73 /* Check return value of operation and report PASS/FAIL */
75 check_result(unsigned long result, unsigned long expected, char *test,
78 if (result != expected) {
79 printf("FAIL/%s:%s incorrectly returned %lu (expected %lu)\n", test, info,
84 printf("PASS/%s:%s correctly returned %lu\n", test, info, result);
88 main(int argc, char **argv)
90 hash_entry_t entry = HASH_ENTRY_INIT(OBJECT);
92 /* Check that the static initializer produces a passable structure */
93 check_init(&entry, "he_static");
95 /* now, check what he_init does with bad arguments */
96 check_result(he_init(0, 0), DB_ERR_BADARGS, "he_init_noargs",
97 "he_init() with no valid arguments", 0);
99 /* Scramble the structure */
100 entry.he_magic = DEADINT;
101 entry.he_elem.le_magic = DEADINT;
102 entry.he_table = DEADPTR;
103 entry.he_hash = DEADINT;
104 entry.he_key.dk_key = DEADPTR;
105 entry.he_key.dk_len = DEADINT;
106 entry.he_value = DEADPTR;
108 /* Now try to initialize our structure and see what happens */
109 check_result(he_init(&entry, OBJECT), 0, "he_dynamic",
110 "he_init() to dynamically initialize hash entry", 0);
112 /* Finally, verify initialization */
113 check_init(&entry, "he_dynamic");