fbe740
From cbdb97e438e9e45b4c0219e95a1d638d03faa8ae Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <cbdb97e438e9e45b4c0219e95a1d638d03faa8ae@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 4 Feb 2020 15:07:44 +0100
fbe740
Subject: [PATCH] tests: hash: Test case for adding duplicate hash entry
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Test that adding a duplicate entry is rejected properly. This also
fbe740
allows to see the error message of the duplicate key addition in verbose
fbe740
mode.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
(cherry picked from commit 7134f26b73162536b8bea2af860b32bad6a7f965)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
fbe740
Message-Id: <9bec2f7b4dc1be3ec963efa667c93ff225e9a0b6.1580824112.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 tests/virhashtest.c | 23 +++++++++++++++++++++++
fbe740
 1 file changed, 23 insertions(+)
fbe740
fbe740
diff --git a/tests/virhashtest.c b/tests/virhashtest.c
fbe740
index 66fa3a428e..4d05cbb0f8 100644
fbe740
--- a/tests/virhashtest.c
fbe740
+++ b/tests/virhashtest.c
fbe740
@@ -510,6 +510,28 @@ testHashEqual(const void *data G_GNUC_UNUSED)
fbe740
 }
fbe740
 
fbe740
 
fbe740
+static int
fbe740
+testHashDuplicate(const void *data G_GNUC_UNUSED)
fbe740
+{
fbe740
+    g_autoptr(virHashTable) hash = NULL;
fbe740
+
fbe740
+    if (!(hash = virHashCreate(0, NULL)))
fbe740
+        return -1;
fbe740
+
fbe740
+    if (virHashAddEntry(hash, "a", NULL) < 0) {
fbe740
+        VIR_TEST_VERBOSE("\nfailed to add key 'a' to hash");
fbe740
+        return -1;
fbe740
+    }
fbe740
+
fbe740
+    if (virHashAddEntry(hash, "a", NULL) >= 0) {
fbe740
+        VIR_TEST_VERBOSE("\nadding of key 'a' should have failed");
fbe740
+        return -1;
fbe740
+    }
fbe740
+
fbe740
+    return 0;
fbe740
+}
fbe740
+
fbe740
+
fbe740
 static int
fbe740
 mymain(void)
fbe740
 {
fbe740
@@ -546,6 +568,7 @@ mymain(void)
fbe740
     DO_TEST("Search", Search);
fbe740
     DO_TEST("GetItems", GetItems);
fbe740
     DO_TEST("Equal", Equal);
fbe740
+    DO_TEST("Duplicate entry", Duplicate);
fbe740
 
fbe740
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
fbe740
 }
fbe740
-- 
fbe740
2.25.0
fbe740