mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
tests: hash: Test case for adding duplicate hash entry
Test that adding a duplicate entry is rejected properly. This also allows to see the error message of the duplicate key addition in verbose mode. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
ae60e05817
commit
7134f26b73
@ -510,6 +510,28 @@ testHashEqual(const void *data G_GNUC_UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testHashDuplicate(const void *data G_GNUC_UNUSED)
|
||||||
|
{
|
||||||
|
g_autoptr(virHashTable) hash = NULL;
|
||||||
|
|
||||||
|
if (!(hash = virHashCreate(0, NULL)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virHashAddEntry(hash, "a", NULL) < 0) {
|
||||||
|
VIR_TEST_VERBOSE("\nfailed to add key 'a' to hash");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virHashAddEntry(hash, "a", NULL) >= 0) {
|
||||||
|
VIR_TEST_VERBOSE("\nadding of key 'a' should have failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
@ -546,6 +568,7 @@ mymain(void)
|
|||||||
DO_TEST("Search", Search);
|
DO_TEST("Search", Search);
|
||||||
DO_TEST("GetItems", GetItems);
|
DO_TEST("GetItems", GetItems);
|
||||||
DO_TEST("Equal", Equal);
|
DO_TEST("Equal", Equal);
|
||||||
|
DO_TEST("Duplicate entry", Duplicate);
|
||||||
|
|
||||||
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user