On Thu, Apr 01, 2010 at 03:16:24PM -0400, Stefan Berger wrote:
This patch adds a couple of test cases for the XML parsing test suite
covering various filterable protocols. For each test case an input XML and an output XML
is provided checking the input XML after parsing and converting back into XML against the
exepcted output XML.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
[...]
tests/nwfilterxml2xmltest.c | 121
+++++++++++++++++++++++++
48 files changed, 908 insertions(+)
[...]
+static int testCompareXMLToXMLFiles(const char *inxml, const char
*outxml) {
+ char inXmlData[MAX_FILE];
+ char *inXmlPtr = &(inXmlData[0]);
+ char outXmlData[MAX_FILE];
+ char *outXmlPtr = &(outXmlData[0]);
+ char *actual = NULL;
+ int ret = -1;
+ virNWFilterDefPtr dev = NULL;
+
+ if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ goto fail;
+ if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ goto fail;
+
+ if (!(dev = virNWFilterDefParseString(NULL, inXmlData)))
+ goto fail;
+
+ if (!(actual = virNWFilterDefFormat(NULL, dev)))
+ goto fail;
+
+ if (STRNEQ(outXmlData, actual)) {
+ virtTestDifference(stderr, outXmlData, actual);
+ goto fail;
+ }
+
+ ret = 0;
+
+ fail:
+ free(actual);
+ virNWFilterDefFree(dev);
+ return ret;
+}
+
+static int testCompareXMLToXMLHelper(const void *data) {
+ char inxml[PATH_MAX];
+ char outxml[PATH_MAX];
+ snprintf(inxml, PATH_MAX, "%s/nwfilterxml2xmlin/%s.xml",
+ abs_srcdir, (const char*)data);
+ snprintf(outxml, PATH_MAX, "%s/nwfilterxml2xmlout/%s.xml",
+ abs_srcdir, (const char*)data);
+ return testCompareXMLToXMLFiles(inxml, outxml);
+}
+
+
+static int
+mymain(int argc, char **argv)
+{
+ int ret = 0;
+ char cwd[PATH_MAX];
+
+ progname = argv[0];
+
+ if (argc > 1) {
+ fprintf(stderr, "Usage: %s\n", progname);
+ return (EXIT_FAILURE);
+ }
+
+ abs_srcdir = getenv("abs_srcdir");
+ if (!abs_srcdir)
+ abs_srcdir = getcwd(cwd, sizeof(cwd));
+
+#define DO_TEST(name) \
+ if (virtTestRun("NWFilter XML-2-XML " name, \
+ 1, testCompareXMLToXMLHelper, (name)) < 0) \
+ ret = -1
+
ACK, good idea, but it would be nice if the XML could also be
validated against the Relax-NG syntax for the filters.
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit
http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine
http://rpmfind.net/
http://veillard.com/ | virtualization library
http://libvirt.org/