[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 2/3] Add test case for virHashEqual function



Add a test case to test the virHashEqual function.

---
 tests/hashtest.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

Index: libvirt-iterator/tests/hashtest.c
===================================================================
--- libvirt-iterator.orig/tests/hashtest.c
+++ libvirt-iterator/tests/hashtest.c
@@ -576,6 +576,83 @@ cleanup:
 
 
 static int
+testHashEqualCompValue(const void *value1, const void *value2)
+{
+    return strcmp (value1, value2);
+}
+
+
+static int
+testHashEqual(const void *data ATTRIBUTE_UNUSED)
+{
+    virHashTablePtr hash1, hash2;
+    int ret = -1;
+    char keya[] = "a";
+    char keyb[] = "b";
+    char keyc[] = "c";
+    char value1[] = "1";
+    char value2[] = "2";
+    char value3[] = "3";
+    char value4[] = "4";
+
+    if (!(hash1 = virHashCreate(0, NULL)) ||
+        !(hash2 = virHashCreate(0, NULL)) ||
+        virHashAddEntry(hash1, keya, value1) < 0 ||
+        virHashAddEntry(hash1, keyb, value2) < 0 ||
+        virHashAddEntry(hash1, keyc, value3) < 0 ||
+        virHashAddEntry(hash2, keya, value1) < 0 ||
+        virHashAddEntry(hash2, keyb, value2) < 0) {
+        if (virTestGetVerbose()) {
+            testError("\nfailed to create hashes");
+        }
+        goto cleanup;
+    }
+
+    if (virHashEqual(hash1, hash2, testHashEqualCompValue)) {
+        if (virTestGetVerbose()) {
+            testError("\nfailed equal test for different number of elements");
+        }
+        goto cleanup;
+    }
+
+    if (virHashAddEntry(hash2, keyc, value4) < 0) {
+        if (virTestGetVerbose()) {
+            testError("\nfailed to add element to hash2");
+        }
+        goto cleanup;
+    }
+
+    if (virHashEqual(hash1, hash2, testHashEqualCompValue)) {
+        if (virTestGetVerbose()) {
+            testError("\nfailed equal test for same number of elements");
+        }
+        goto cleanup;
+    }
+
+    if (virHashUpdateEntry(hash2, keyc, value3) < 0) {
+        if (virTestGetVerbose()) {
+            testError("\nfailed to update element in hash2");
+        }
+        goto cleanup;
+    }
+
+    if (!virHashEqual(hash1, hash2, testHashEqualCompValue)) {
+        if (virTestGetVerbose()) {
+            testError("\nfailed equal test for equal hash tables");
+        }
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    virHashFree(hash1);
+    virHashFree(hash2);
+    return ret;
+}
+
+
+static int
 mymain(void)
 {
     int ret = 0;
@@ -612,6 +689,7 @@ mymain(void)
     DO_TEST("RemoveSet", RemoveSet);
     DO_TEST("Search", Search);
     DO_TEST("GetItems", GetItems);
+    DO_TEST("Equal", Equal);
 
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]