render / rpms / libvirt

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