[libvirt] [PATCH 10/10] tests: virerror: Make sure that error messages stay in correct order

Peter Krempa pkrempa at redhat.com
Wed Dec 5 16:47:51 UTC 2018


Since we don't look up the error message according to the error code but
they have to be in the correct order in virErrorMsgStrings, we need
to make sure that they stay in the correct order.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tests/virerrortest.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tests/virerrortest.c b/tests/virerrortest.c
index 0d0377bfa8..6d333f02d0 100644
--- a/tests/virerrortest.c
+++ b/tests/virerrortest.c
@@ -87,6 +87,24 @@ virErrorTestMsgs(const void *opaque ATTRIBUTE_UNUSED)
 }


+static int
+virErrorTestMsgOrder(const void *opaque ATTRIBUTE_UNUSED)
+{
+    size_t i;
+    int ret = 0;
+
+    for (i = 0; i < VIR_ERR_NUMBER_LAST; i++) {
+        if (i != virErrorMsgStrings[i].error) {
+            VIR_TEST_VERBOSE("\nvirErrorMsgStrings[%zu] error code is '%d'\n",
+                             i, virErrorMsgStrings[i].error);
+            ret = -1;
+        }
+    }
+
+    return ret;
+}
+
+
 static int
 mymain(void)
 {
@@ -94,6 +112,8 @@ mymain(void)

     if (virTestRun("error message strings ", virErrorTestMsgs, NULL) < 0)
         ret = -1;
+    if (virTestRun("error messages are in correct order ", virErrorTestMsgOrder, NULL) < 0)
+        ret = -1;

     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
2.19.2




More information about the libvir-list mailing list