mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 20:33:31 +01:00
r6979@Kushana: nickm | 2006-07-31 13:16:58 -0400
Add assert_ok functions for strmap and digestmap; use them in unit test code. svn:r6958
This commit is contained in:
parent
3843b1b3d0
commit
d934607069
@ -965,6 +965,17 @@ digestmap_free(digestmap_t *map, void (*free_val)(void*))
|
|||||||
tor_free(map);
|
tor_free(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
strmap_assert_ok(strmap_t *map)
|
||||||
|
{
|
||||||
|
tor_assert(!_strmap_impl_HT_REP_IS_BAD(&map->head));
|
||||||
|
}
|
||||||
|
void
|
||||||
|
digestmap_assert_ok(digestmap_t *map)
|
||||||
|
{
|
||||||
|
tor_assert(!_digestmap_impl_HT_REP_IS_BAD(&map->head));
|
||||||
|
}
|
||||||
|
|
||||||
/** Return true iff <b>map</b> has no entries. */
|
/** Return true iff <b>map</b> has no entries. */
|
||||||
int
|
int
|
||||||
strmap_isempty(strmap_t *map)
|
strmap_isempty(strmap_t *map)
|
||||||
|
@ -134,7 +134,8 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
|
|||||||
prefix##iter_t *prefix##iter_next(maptype *map, prefix##iter_t *iter); \
|
prefix##iter_t *prefix##iter_next(maptype *map, prefix##iter_t *iter); \
|
||||||
prefix##iter_t *prefix##iter_next_rmv(maptype *map, prefix##iter_t *iter); \
|
prefix##iter_t *prefix##iter_next_rmv(maptype *map, prefix##iter_t *iter); \
|
||||||
void prefix##iter_get(prefix##iter_t *iter, keytype *keyp, void **valp); \
|
void prefix##iter_get(prefix##iter_t *iter, keytype *keyp, void **valp); \
|
||||||
int prefix##iter_done(prefix##iter_t *iter);
|
int prefix##iter_done(prefix##iter_t *iter); \
|
||||||
|
void prefix##assert_ok(maptype *map);
|
||||||
|
|
||||||
/* Map from const char * to void *. Implemented with a hash table. */
|
/* Map from const char * to void *. Implemented with a hash table. */
|
||||||
DECLARE_MAP_FNS(strmap_t, const char *, strmap_);
|
DECLARE_MAP_FNS(strmap_t, const char *, strmap_);
|
||||||
|
@ -1105,8 +1105,10 @@ test_strmap(void)
|
|||||||
test_eq_ptr(strmap_get(map,"K1"), (void*)100);
|
test_eq_ptr(strmap_get(map,"K1"), (void*)100);
|
||||||
test_eq_ptr(strmap_get(map,"K2"), (void*)101);
|
test_eq_ptr(strmap_get(map,"K2"), (void*)101);
|
||||||
test_eq_ptr(strmap_get(map,"K-not-there"), NULL);
|
test_eq_ptr(strmap_get(map,"K-not-there"), NULL);
|
||||||
|
strmap_assert_ok(map);
|
||||||
|
|
||||||
v = strmap_remove(map,"K2");
|
v = strmap_remove(map,"K2");
|
||||||
|
strmap_assert_ok(map);
|
||||||
test_eq_ptr(v, (void*)101);
|
test_eq_ptr(v, (void*)101);
|
||||||
test_eq_ptr(strmap_get(map,"K2"), NULL);
|
test_eq_ptr(strmap_get(map,"K2"), NULL);
|
||||||
test_eq_ptr(strmap_remove(map,"K2"), NULL);
|
test_eq_ptr(strmap_remove(map,"K2"), NULL);
|
||||||
@ -1114,8 +1116,10 @@ test_strmap(void)
|
|||||||
strmap_set(map, "K2", (void*)101);
|
strmap_set(map, "K2", (void*)101);
|
||||||
strmap_set(map, "K3", (void*)102);
|
strmap_set(map, "K3", (void*)102);
|
||||||
strmap_set(map, "K4", (void*)103);
|
strmap_set(map, "K4", (void*)103);
|
||||||
|
strmap_assert_ok(map);
|
||||||
strmap_set(map, "K5", (void*)104);
|
strmap_set(map, "K5", (void*)104);
|
||||||
strmap_set(map, "K6", (void*)105);
|
strmap_set(map, "K6", (void*)105);
|
||||||
|
strmap_assert_ok(map);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
iter = strmap_iter_init(map);
|
iter = strmap_iter_init(map);
|
||||||
@ -1142,6 +1146,7 @@ test_strmap(void)
|
|||||||
test_eq_ptr(strmap_get(map, "K5"), (void*)10816);
|
test_eq_ptr(strmap_get(map, "K5"), (void*)10816);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
strmap_assert_ok(map);
|
||||||
/* Clean up after ourselves. */
|
/* Clean up after ourselves. */
|
||||||
strmap_free(map, NULL);
|
strmap_free(map, NULL);
|
||||||
|
|
||||||
@ -1149,9 +1154,11 @@ test_strmap(void)
|
|||||||
map = strmap_new();
|
map = strmap_new();
|
||||||
strmap_set_lc(map,"Ab.C", (void*)1);
|
strmap_set_lc(map,"Ab.C", (void*)1);
|
||||||
test_eq_ptr(strmap_get(map,"ab.c"), (void*)1);
|
test_eq_ptr(strmap_get(map,"ab.c"), (void*)1);
|
||||||
|
strmap_assert_ok(map);
|
||||||
test_eq_ptr(strmap_get_lc(map,"AB.C"), (void*)1);
|
test_eq_ptr(strmap_get_lc(map,"AB.C"), (void*)1);
|
||||||
test_eq_ptr(strmap_get(map,"AB.C"), NULL);
|
test_eq_ptr(strmap_get(map,"AB.C"), NULL);
|
||||||
test_eq_ptr(strmap_remove_lc(map,"aB.C"), (void*)1);
|
test_eq_ptr(strmap_remove_lc(map,"aB.C"), (void*)1);
|
||||||
|
strmap_assert_ok(map);
|
||||||
test_eq_ptr(strmap_get_lc(map,"AB.C"), NULL);
|
test_eq_ptr(strmap_get_lc(map,"AB.C"), NULL);
|
||||||
strmap_free(map,NULL);
|
strmap_free(map,NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user