5 #include "ndbneb.h" /* for ARRAY_SIZE() */
6 #include "test_utils.h"
13 { "kalle", "penslar" },
17 { "andreas", "regerar" },
21 static struct test_data
{
25 static struct test_data
*ddup(int x
, int i
, int j
)
29 d
= malloc(sizeof(*d
));
37 uint entries
, count
, max
, added
, removed
;
38 int ent_delta
, addrm_delta
;
41 static int del_matching(void *data
)
43 struct test_data
*d
= (struct test_data
*)data
;
45 if (!memcmp(d
, &del
, sizeof(del
))) {
47 return HASH_WALK_REMOVE
;
53 int main(int argc
, char **argv
)
55 hash_table
*ti
, *tj
, *tx
;
60 t_start("testing hash_walk_data()");
61 memset(&s
, 0, sizeof(s
));
62 /* first we set up the hash-tables */
67 for (x
= 0; x
< ARRAY_SIZE(keys
); x
++) {
68 hash_add(tx
, keys
[x
].k1
, ddup(x
, 0, 0));
69 hash_add(tx
, keys
[x
].k2
, ddup(x
, 0, 0));
70 hash_add2(tx
, keys
[x
].k1
, keys
[x
].k2
, ddup(x
, 0, 0));
72 ok_int(s
.x
, hash_entries(tx
), "x table adding");
74 for (i
= 0; i
< ARRAY_SIZE(keys
); i
++) {
75 hash_add(ti
, keys
[i
].k1
, ddup(x
, i
, 0));
76 hash_add(ti
, keys
[i
].k1
, ddup(x
, i
, 0));
77 hash_add2(ti
, keys
[i
].k1
, keys
[i
].k2
, ddup(x
, i
, 0));
79 ok_int(s
.i
, hash_entries(ti
), "i table adding");
81 for (j
= 0; j
< ARRAY_SIZE(keys
); j
++) {
82 hash_add(tj
, keys
[j
].k1
, ddup(x
, i
, j
));
83 hash_add(tj
, keys
[j
].k2
, ddup(x
, i
, j
));
84 hash_add2(tj
, keys
[j
].k1
, keys
[j
].k2
, ddup(x
, i
, j
));
86 ok_int(s
.j
, hash_entries(tj
), "j table adding");
91 ok_int(s
.x
, hash_entries(tx
), "x table done adding");
92 ok_int(s
.i
, hash_entries(ti
), "i table done adding");
93 ok_int(s
.j
, hash_entries(tj
), "j table done adding");
95 for (x
= 0; x
< ARRAY_SIZE(keys
); x
++) {
99 ok_int(s
.x
, hash_entries(tx
), "x table pre-delete");
101 hash_walk_data(tx
, del_matching
);
102 ok_int(s
.x
, hash_entries(tx
), "x table post-delete");
104 for (i
= 0; i
< ARRAY_SIZE(keys
); i
++) {
107 ok_int(s
.i
, hash_entries(ti
), "i table pre-delete");
108 hash_walk_data(ti
, del_matching
);
110 ok_int(s
.i
, hash_entries(ti
), "i table post-delete");
112 for (j
= 0; j
< ARRAY_SIZE(keys
); j
++) {
114 ok_int(s
.j
, hash_entries(tj
), "j table pre-delete");
115 hash_walk_data(tj
, del_matching
);
117 ok_int(s
.j
, hash_entries(tj
), "j table post-delete");
122 ok_int(0, hash_entries(tx
), "x table post all ops");
123 ok_int(0, hash_check_table(tx
), "x table consistency post all ops");
124 ok_int(0, hash_entries(ti
), "i table post all ops");
125 ok_int(0, hash_check_table(ti
), "i table consistency post all ops");
126 ok_int(0, hash_entries(tj
), "j table post all ops");
127 ok_int(0, hash_check_table(tj
), "j table consistency post all ops");
128 hash_debug_table(tx
, 0);
129 hash_debug_table(ti
, 0);
130 hash_debug_table(tj
, 0);