From fc8f7f91c13c6d6697c729c3f2d6b72a8fec1369 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 12 Aug 2013 14:50:20 +0000 Subject: - test for external iterator - const added to result parameter of 'next' --- src/include/gnunet_container_lib.h | 2 +- src/util/container_multihashmap.c | 2 +- src/util/test_container_multihashmap.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index a6a0e519d..87249faca 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -728,7 +728,7 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_Mul */ int GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, - struct GNUNET_HashCode *key, void **value); + struct GNUNET_HashCode *key, const void **value); /** diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index bd22732be..1cd699dff 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c @@ -838,7 +838,7 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_Mul */ int GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, - struct GNUNET_HashCode *key, void **value) + struct GNUNET_HashCode *key, const void **value) { /* make sure nobody modified the map */ GNUNET_assert (iter->modification_counter == iter->map->modification_counter); diff --git a/src/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c index ff50df117..a0d29c606 100644 --- a/src/util/test_container_multihashmap.c +++ b/src/util/test_container_multihashmap.c @@ -37,6 +37,8 @@ testMap (int i) struct GNUNET_CONTAINER_MultiHashMap *m; struct GNUNET_HashCode k1; struct GNUNET_HashCode k2; + struct GNUNET_CONTAINER_MultiHashMapIterator *iter; + struct GNUNET_HashCode key_ret; const char *ret; int j; @@ -79,11 +81,23 @@ testMap (int i) CHECK (2 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL)); CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); + iter = GNUNET_CONTAINER_multihashmap_iterator_create (m); + CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, &key_ret, (const void **)&ret)); + CHECK (0 == memcmp (&key_ret, &k1, sizeof (key_ret))); + CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, &key_ret, (const void **)&ret)); + CHECK (0 == memcmp (&key_ret, &k1, sizeof (key_ret))); + CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, NULL)); + CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); for (j = 0; j < 1024; j++) CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + iter = GNUNET_CONTAINER_multihashmap_iterator_create (m); + for (j = 0; j < GNUNET_CONTAINER_multihashmap_size (m); j++) + CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, NULL)); + CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, NULL)); + GNUNET_CONTAINER_multihashmap_destroy (m); return 0; } -- cgit v1.2.3