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