[or-cvs] r6958: Add assert_ok functions for strmap and digestmap; use them i (in tor/trunk: . src/common src/or)

nickm at seul.org nickm at seul.org
Mon Jul 31 18:01:28 UTC 2006


Author: nickm
Date: 2006-07-31 14:01:27 -0400 (Mon, 31 Jul 2006)
New Revision: 6958

Modified:
   tor/trunk/
   tor/trunk/src/common/container.c
   tor/trunk/src/common/container.h
   tor/trunk/src/or/test.c
Log:
 r6979 at Kushana:  nickm | 2006-07-31 13:16:58 -0400
 Add assert_ok functions for strmap and digestmap; use them in unit test code.



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:6978
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
   + c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:6979
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950

Modified: tor/trunk/src/common/container.c
===================================================================
--- tor/trunk/src/common/container.c	2006-07-31 18:01:22 UTC (rev 6957)
+++ tor/trunk/src/common/container.c	2006-07-31 18:01:27 UTC (rev 6958)
@@ -965,6 +965,17 @@
   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. */
 int
 strmap_isempty(strmap_t *map)

Modified: tor/trunk/src/common/container.h
===================================================================
--- tor/trunk/src/common/container.h	2006-07-31 18:01:22 UTC (rev 6957)
+++ tor/trunk/src/common/container.h	2006-07-31 18:01:27 UTC (rev 6958)
@@ -134,7 +134,8 @@
   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_);

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2006-07-31 18:01:22 UTC (rev 6957)
+++ tor/trunk/src/or/test.c	2006-07-31 18:01:27 UTC (rev 6958)
@@ -1105,8 +1105,10 @@
   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 @@
   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_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 @@
   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);
 }



More information about the tor-commits mailing list