MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/htable/test/run-type.c:110–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110int main(void)
111{
112 unsigned int i;
113 struct htable_obj ht, ht2;
114 struct obj val[NUM_VALS], *result;
115 unsigned int dne;
116 void *p;
117 struct htable_obj_iter iter;
118
119 plan_tests(35);
120 for (i = 0; i < NUM_VALS; i++)
121 val[i].key = i;
122 dne = i;
123
124 htable_obj_init(&ht);
125 ok1(htable_obj_count(&ht) == 0);
126 ok1(ht_max(&ht.raw) == 0);
127 ok1(ht.raw.bits == 0);
128
129 /* We cannot find an entry which doesn't exist. */
130 ok1(!htable_obj_get(&ht, &dne));
131 ok1(!htable_obj_pick(&ht, 0, NULL));
132
133 /* Fill it, it should increase in size. */
134 add_vals(&ht, val, NUM_VALS);
135 ok1(ht.raw.bits == NUM_BITS + 1);
136 ok1(ht_max(&ht.raw) < (1 << ht.raw.bits));
137
138 /* Mask should be set. */
139 ok1(ht.raw.common_mask != 0);
140 ok1(ht.raw.common_mask != -1);
141 ok1(check_mask(&ht.raw, val, NUM_VALS));
142
143 /* Find all. */
144 find_vals(&ht, val, NUM_VALS);
145 ok1(!htable_obj_get(&ht, &dne));
146 ok1(htable_obj_pick(&ht, 0, NULL));
147 ok1(htable_obj_pick(&ht, 0, &iter));
148
149 /* Walk once, should get them all. */
150 i = 0;
151 for (p = htable_obj_first(&ht,&iter); p; p = htable_obj_next(&ht, &iter))
152 i++;
153 ok1(i == NUM_VALS);
154 i = 0;
155 for (p = htable_obj_prev(&ht,&iter); p; p = htable_obj_prev(&ht, &iter))
156 i++;
157 ok1(i == NUM_VALS);
158
159 /* Delete all. */
160 del_vals(&ht, val, NUM_VALS);
161 ok1(!htable_obj_get(&ht, &val[0].key));
162
163 /* Worst case, a "pointer" which doesn't have any matching bits. */
164 htable_add(&ht.raw, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]);
165 htable_obj_add(&ht, &val[NUM_VALS-1]);
166 ok1(ht.raw.common_mask == 0);
167 ok1(ht.raw.common_bits == 0);

Callers

nothing calls this directly

Calls 6

ht_maxFunction · 0.85
add_valsFunction · 0.70
check_maskFunction · 0.70
find_valsFunction · 0.70
del_valsFunction · 0.70
del_vals_bykeyFunction · 0.70

Tested by

no test coverage detected