On 17.03.2014 16:19, Francesco Romani wrote:
the test is loosely inspired from qemucapabilitiestest
and qemuxml2xmltest.

Added a new test instead of extending an existing one because
the feature being tested don't really fits nicely in any
existing place.
---
  tests/Makefile.am                                  |  10 +-
  tests/qemucaps2xmldata/all_1.6.0-1.caps            | 142 ++++++++++++++
  tests/qemucaps2xmldata/all_1.6.0-1.xml             |  31 ++++
  tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.caps | 141 ++++++++++++++
  tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.xml  |  31 ++++
  tests/qemucaps2xmltest.c                           | 206 +++++++++++++++++++++
  6 files changed, 560 insertions(+), 1 deletion(-)
  create mode 100644 tests/qemucaps2xmldata/all_1.6.0-1.caps
  create mode 100644 tests/qemucaps2xmldata/all_1.6.0-1.xml
  create mode 100644 tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.caps
  create mode 100644 tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.xml
  create mode 100644 tests/qemucaps2xmltest.c


diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c
new file mode 100644
index 0000000..c447af7
--- /dev/null
+++ b/tests/qemucaps2xmltest.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */

I'm adding Authors line here among with your name.

+
+#include <config.h>
+
+#include "testutils.h"
+#include "qemu/qemu_capabilities.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+
+static int
+testCompareXMLToXML(const char *inxmldata, const char *outxmldata)
+{
+    int ret = 0;
+
+    if (STRNEQ(outxmldata, inxmldata)) {
+        virtTestDifference(stderr, outxmldata, inxmldata);
+        ret = -1;
+    }
+
+    return ret;
+}

While this works, I'm changing it to match the pattern used in the rest of the code.

+
+
+typedef struct _testQemuData testQemuData;
+typedef testQemuData *testQemuDataPtr;
+struct _testQemuData {
+    const char *base;
+    virArch guestarch;
+};
+
+static virQEMUCapsPtr
+testQemuGetCaps(char *caps)
+{
+    virQEMUCapsPtr qemuCaps = NULL;
+    xmlDocPtr xml;
+    xmlXPathContextPtr ctxt = NULL;
+    ssize_t i, n;
+    xmlNodePtr *nodes = NULL;
+
+    if (!(xml = virXMLParseStringCtxt(caps, "(test caps)", &ctxt)))
+        goto error;
+
+    if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) {
+        fprintf(stderr, "failed to parse qemu capabilities flags");
+        goto error;
+    }
+
+    if (n > 0) {

There's no need for this. I mean, if there's no /qemuCaps/flag the virXPathNodeSet() returns 0 which may be handy if we want to test empty capabilities.

+        if (!(qemuCaps = virQEMUCapsNew()))
+            goto error;
+
+        for (i = 0; i < n; i++) {
+            char *str = virXMLPropString(nodes[i], "name");
+            if (str) {
+                int flag = virQEMUCapsTypeFromString(str);
+                if (flag < 0) {
+                    fprintf(stderr, "Unknown qemu capabilities flag %s", str);
+                    VIR_FREE(str);
+                    goto error;
+                }
+                VIR_FREE(str);
+                virQEMUCapsSet(qemuCaps, flag);
+            }
+        }
+    }
+
+    VIR_FREE(nodes);
+    xmlFreeDoc(xml);
+    xmlXPathFreeContext(ctxt);
+    return qemuCaps;
+
+error:
+    VIR_FREE(nodes);
+    virObjectUnref(qemuCaps);
+    xmlFreeDoc(xml);
+    xmlXPathFreeContext(ctxt);
+    return NULL;
+}

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to