summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2015-06-16 15:46:40 +0200
committerMichal Schmidt <mschmidt@redhat.com>2015-06-17 17:28:44 +0200
commit8f8a5213a9ad89f1ebab6efb19377ed9df512ee6 (patch)
tree75c5589554d74f3b446489f559f2f33e530ad1a0 /src
parent49e440cdc9782ea615e4b6a4dd21e12716a5b675 (diff)
hashmap: allow NULL key in ordered_hashmap_next()
There is no reason to require key to be non-NULL. Change test_ordered_hashmap_next() to use trivial_hash_ops in order to test NULL key too.
Diffstat (limited to 'src')
-rw-r--r--src/basic/hashmap.c2
-rw-r--r--src/test/test-hashmap.c43
2 files changed, 11 insertions, 34 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 0ee2f3bd31..e5f05f36f8 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -1798,8 +1798,6 @@ void *ordered_hashmap_next(OrderedHashmap *h, const void *key) {
struct ordered_hashmap_entry *e;
unsigned hash, idx;
- assert(key);
-
if (!h)
return NULL;
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
index 767cbd90e9..d0e65001f5 100644
--- a/src/test/test-hashmap.c
+++ b/src/test/test-hashmap.c
@@ -24,38 +24,17 @@ void test_hashmap_funcs(void);
void test_ordered_hashmap_funcs(void);
static void test_ordered_hashmap_next(void) {
- OrderedHashmap *m;
- char *val1, *val2, *val3, *val4, *r;
-
- m = ordered_hashmap_new(&string_hash_ops);
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
-
- ordered_hashmap_put(m, "key 1", val1);
- ordered_hashmap_put(m, "key 2", val2);
- ordered_hashmap_put(m, "key 3", val3);
- ordered_hashmap_put(m, "key 4", val4);
-
- r = ordered_hashmap_next(m, "key 1");
- assert_se(streq(r, val2));
- r = ordered_hashmap_next(m, "key 2");
- assert_se(streq(r, val3));
- r = ordered_hashmap_next(m, "key 3");
- assert_se(streq(r, val4));
- r = ordered_hashmap_next(m, "key 4");
- assert_se(!r);
- r = ordered_hashmap_next(NULL, "key 1");
- assert_se(!r);
- r = ordered_hashmap_next(m, "key 5");
- assert_se(!r);
-
- ordered_hashmap_free_free(m);
+ _cleanup_ordered_hashmap_free_ OrderedHashmap *m = NULL;
+ int i;
+
+ assert_se(m = ordered_hashmap_new(NULL));
+ for (i = -2; i <= 2; i++)
+ assert_se(ordered_hashmap_put(m, INT_TO_PTR(i), INT_TO_PTR(i+10)) == 1);
+ for (i = -2; i <= 1; i++)
+ assert_se(ordered_hashmap_next(m, INT_TO_PTR(i)) == INT_TO_PTR(i+11));
+ assert_se(!ordered_hashmap_next(m, INT_TO_PTR(2)));
+ assert_se(!ordered_hashmap_next(NULL, INT_TO_PTR(1)));
+ assert_se(!ordered_hashmap_next(m, INT_TO_PTR(3)));
}
static void test_uint64_compare_func(void) {