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

[libvirt] [PATCH 10/14] tests: virstorage: Allow testing return value of virStorageSourceNewFromBackingAbsolute



Modiy testBackingParse to allow testing other return values of the
backing store string parser.

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
 tests/virstoragetest.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 0495308318..be5cb98262 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -603,6 +603,7 @@ testPathRelative(const void *args)
 struct testBackingParseData {
     const char *backing;
     const char *expect;
+    int rv;
 };

 static int
@@ -612,14 +613,21 @@ testBackingParse(const void *args)
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     VIR_AUTOFREE(char *) xml = NULL;
     VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;
+    int rc;
+    int erc = data->rv;

-    if (virStorageSourceNewFromBackingAbsolute(data->backing, &src) < 0) {
-        if (!data->expect)
-            return 0;
-        else
-            return -1;
+    /* expect failure return code with NULL expected data */
+    if (!data->expect)
+        erc = -1;
+
+    if ((rc = virStorageSourceNewFromBackingAbsolute(data->backing, &src)) != erc) {
+        fprintf(stderr, "expected return value '%d' actual '%d'\n", erc, rc);
+        return -1;
     }

+    if (!src)
+        return 0;
+
     if (src && !data->expect) {
         fprintf(stderr, "parsing of backing store string '%s' should "
                         "have failed\n", data->backing);
@@ -1225,15 +1233,19 @@ mymain(void)

     virTestCounterReset("Backing store parse ");

-#define TEST_BACKING_PARSE(bck, xml) \
+#define TEST_BACKING_PARSE_FULL(bck, xml, rc) \
     do { \
         data5.backing = bck; \
         data5.expect = xml; \
+        data5.rv = rc; \
         if (virTestRun(virTestCounterNext(), \
                        testBackingParse, &data5) < 0) \
             ret = -1; \
     } while (0)

+#define TEST_BACKING_PARSE(bck, xml) \
+    TEST_BACKING_PARSE_FULL(bck, xml, 0)
+
     TEST_BACKING_PARSE("path", "<source file='path'/>\n");
     TEST_BACKING_PARSE("://", NULL);
     TEST_BACKING_PARSE("http://example.com";,
-- 
2.21.0


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