chiark / gitweb /
test: hashmap_put behaviour for equal keys
authorMartin Pitt <martin.pitt@ubuntu.com>
Sat, 13 Dec 2014 03:22:28 +0000 (04:22 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Wed, 14 Jan 2015 07:05:16 +0000 (08:05 +0100)
Check string ops hashmap_put() for keys with a different pointer but the same
value.

src/test/test-hashmap-plain.c

index 6f0910aae7bee01f4cdd0fa647929940937c3398..84b508f874e754efd7d8f72b1cd41a8828e8d141 100644 (file)
@@ -245,6 +245,8 @@ static void test_hashmap_put(void) {
         Hashmap *m = NULL;
         int valid_hashmap_put;
         void *val1 = (void*) "val 1";
         Hashmap *m = NULL;
         int valid_hashmap_put;
         void *val1 = (void*) "val 1";
+        void *val2 = (void*) "val 2";
+        _cleanup_free_ char* key1 = NULL;
 
         assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0);
         assert_se(m);
 
         assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0);
         assert_se(m);
@@ -252,7 +254,10 @@ static void test_hashmap_put(void) {
         valid_hashmap_put = hashmap_put(m, "key 1", val1);
         assert_se(valid_hashmap_put == 1);
         assert_se(hashmap_put(m, "key 1", val1) == 0);
         valid_hashmap_put = hashmap_put(m, "key 1", val1);
         assert_se(valid_hashmap_put == 1);
         assert_se(hashmap_put(m, "key 1", val1) == 0);
-        assert_se(hashmap_put(m, "key 1", (void *)"val 2") == -EEXIST);
+        assert_se(hashmap_put(m, "key 1", val2) == -EEXIST);
+        key1 = strdup("key 1");
+        assert_se(hashmap_put(m, key1, val1) == 0);
+        assert_se(hashmap_put(m, key1, val2) == -EEXIST);
 
         hashmap_free(m);
 }
 
         hashmap_free(m);
 }