From d934607069c77d6cf4caf9061e43d6d20c5aa111 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 31 Jul 2006 18:01:27 +0000 Subject: 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 --- src/common/container.c | 11 +++++++++++ src/common/container.h | 3 ++- src/or/test.c | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/common/container.c b/src/common/container.c index d8ce9d654b..1e1fd985b1 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -965,6 +965,17 @@ digestmap_free(digestmap_t *map, void (*free_val)(void*)) 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 map has no entries. */ int strmap_isempty(strmap_t *map) diff --git a/src/common/container.h b/src/common/container.h index 0b5d0618af..85072e644a 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -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_rmv(maptype *map, prefix##iter_t *iter); \ 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. */ DECLARE_MAP_FNS(strmap_t, const char *, strmap_); diff --git a/src/or/test.c b/src/or/test.c index 4a258afb71..fa342d629a 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -1105,8 +1105,10 @@ test_strmap(void) test_eq_ptr(strmap_get(map,"K1"), (void*)100); test_eq_ptr(strmap_get(map,"K2"), (void*)101); test_eq_ptr(strmap_get(map,"K-not-there"), NULL); + strmap_assert_ok(map); v = strmap_remove(map,"K2"); + strmap_assert_ok(map); test_eq_ptr(v, (void*)101); test_eq_ptr(strmap_get(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, "K3", (void*)102); strmap_set(map, "K4", (void*)103); + strmap_assert_ok(map); strmap_set(map, "K5", (void*)104); strmap_set(map, "K6", (void*)105); + strmap_assert_ok(map); #if 0 iter = strmap_iter_init(map); @@ -1142,6 +1146,7 @@ test_strmap(void) test_eq_ptr(strmap_get(map, "K5"), (void*)10816); #endif + strmap_assert_ok(map); /* Clean up after ourselves. */ strmap_free(map, NULL); @@ -1149,9 +1154,11 @@ test_strmap(void) map = strmap_new(); strmap_set_lc(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(map,"AB.C"), NULL); 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); strmap_free(map,NULL); } -- cgit v1.2.3-54-g00ecf