summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-10-15 01:35:40 +0200
committerMichal Schmidt <mschmidt@redhat.com>2014-10-30 19:50:51 +0100
commite1323fbfbe8a574f28b704f2df8ce7f99e3a28f5 (patch)
tree7f288fdccb33a2858ea457748631b9a5c2ee4ef8
parent994701548d3ea6aafe3d9c47d51f701878118d65 (diff)
test: test a corner case in hashmap_remove_and_replace()
-rw-r--r--src/test/test-hashmap-plain.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c
index f7917521c5..d27d5ec819 100644
--- a/src/test/test-hashmap-plain.c
+++ b/src/test/test-hashmap-plain.c
@@ -380,6 +380,7 @@ static void test_hashmap_remove_and_replace(void) {
void *key2 = UINT_TO_PTR(2);
void *key3 = UINT_TO_PTR(3);
void *r;
+ int i, j;
m = hashmap_new(&trivial_hash_ops);
assert_se(m);
@@ -407,6 +408,25 @@ static void test_hashmap_remove_and_replace(void) {
r = hashmap_get(m, key2);
assert_se(r == key2);
assert_se(!hashmap_get(m, key3));
+
+ /* Repeat this test several times to increase the chance of hitting
+ * the less likely case in hashmap_remove_and_replace where it
+ * compensates for the backward shift. */
+ for (i = 0; i < 20; i++) {
+ hashmap_clear(m);
+
+ for (j = 1; j < 7; j++)
+ hashmap_put(m, UINT_TO_PTR(10*i + j), UINT_TO_PTR(10*i + j));
+ valid = hashmap_remove_and_replace(m, UINT_TO_PTR(10*i + 1),
+ UINT_TO_PTR(10*i + 2),
+ UINT_TO_PTR(10*i + 2));
+ assert_se(valid == 0);
+ assert_se(!hashmap_get(m, UINT_TO_PTR(10*i + 1)));
+ for (j = 2; j < 7; j++) {
+ r = hashmap_get(m, UINT_TO_PTR(10*i + j));
+ assert_se(r == UINT_TO_PTR(10*i + j));
+ }
+ }
}
static void test_hashmap_ensure_allocated(void) {