MCPcopy Index your code
hub / github.com/git/git / t_add

Function t_add

t/unit-tests/u-hashmap.c:139–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139static void t_add(struct hashmap *map, unsigned int ignore_case)
140{
141 struct test_entry *entry;
142 const char *key_val[][2] = {
143 { "key1", "value1" },
144 { ignore_case ? "Key1" : "key1", "value2" },
145 { "fooBarFrotz", "value3" },
146 { ignore_case ? "FOObarFrotz" : "fooBarFrotz", "value4" }
147 };
148 const char *query_keys[] = { "key1", ignore_case ? "FOObarFrotz" :
149 "fooBarFrotz" };
150 char seen[ARRAY_SIZE(key_val)] = { 0 };
151
152 for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
153 entry = alloc_test_entry(key_val[i][0], key_val[i][1], ignore_case);
154 hashmap_add(map, &entry->ent);
155 }
156
157 for (size_t i = 0; i < ARRAY_SIZE(query_keys); i++) {
158 int count = 0;
159 entry = hashmap_get_entry_from_hash(map,
160 ignore_case ? strihash(query_keys[i]) :
161 strhash(query_keys[i]),
162 query_keys[i], struct test_entry, ent);
163
164 hashmap_for_each_entry_from(map, entry, ent)
165 {
166 int ret = key_val_contains(key_val, seen,
167 ARRAY_SIZE(key_val), entry);
168 cl_assert_equal_i(ret, 0);
169 count++;
170 }
171 cl_assert_equal_i(count, 2);
172 }
173
174 for (size_t i = 0; i < ARRAY_SIZE(seen); i++)
175 cl_assert_equal_i(seen[i], 1);
176
177 cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
178 cl_assert_equal_p(get_test_entry(map, "notInMap", ignore_case), NULL);
179}
180
181static void t_remove(struct hashmap *map, unsigned int ignore_case)
182{

Callers

nothing calls this directly

Calls 7

hashmap_addFunction · 0.85
strihashFunction · 0.85
strhashFunction · 0.85
hashmap_get_sizeFunction · 0.85
get_test_entryFunction · 0.85
alloc_test_entryFunction · 0.70
key_val_containsFunction · 0.70

Tested by

no test coverage detected