On Tue, Mar 28, 2017 at 01:58:56PM +0200, Peter Krempa wrote:
Sometimes it may be desired to validate individual files against a
schema. Refactor the data structures to unify them and introduce a new
macro DO_TEST_FILE(schema, xmlfile) which will test the XML file against
the given schema file.
---
tests/virschematest.c | 34 +++---
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/tests/virschematest.c b/tests/virschematest.c
index faf66d642..beefabc96 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -35,6 +35,7 @@ VIR_LOG_INIT("tests.schematest");
struct testSchemaData {
virXMLValidatorPtr validator;
+const char *schema;
const char *xml_path;
};
@@ -140,15 +141,10 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr
validator, ...)
}
-struct testSchemaFileData {
-virXMLValidatorPtr validator;
-const char *schema;
-};
-
static int
testSchemaGrammar(const void *opaque)
{
-struct testSchemaFileData *data = (struct testSchemaFileData *) opaque;
+struct testSchemaData *data = (struct testSchemaData *) opaque;
char *schema_path;
int ret = -1;
@@ -171,7 +167,7 @@ static int
mymain(void)
{
int ret = 0;
-struct testSchemaFileData data;
+struct testSchemaData data;
memset(, 0, sizeof(data));
@@ -196,6 +192,30 @@ mymain(void)
} \
} while (0)
+#define DO_TEST_FILE(sch, xmlfile)
\
+do {
\
+data.schema = sch;
\
+data.xml_path = xmlfile;
\
+if (virTestRun("test schema grammar file: " sch,
\
+ testSchemaGrammar, ) == 0) {
\
+/* initialize the validator even if the schema test
\
+ * was skipped because of VIR_TEST_RANGE */
\
+if (!data.validator && testSchemaGrammar() < 0) {
\
+ret = -1;
\
+break;
\
+}
\
+if (virTestRun("Checking " xmlfile " against " sch,
\
+ testSchemaFile, ) < 0)
\
testSchemaFile does not prepend abs_srcdir to the path (like
testSchemaDirs does), so after you add the test case, the check fails in
vpath builds (I just checked it). I would suggest just a wrapper around
testSchemaFile that prepends that path or just use it when calling the
macro.
+ret = -1;
\
+
\
+virXMLValidatorFree(data.validator);
\
+data.validator = NULL;
\
+} else {
\
+ret = -1;
\
+}
\
+} while (0)
+
+
DO_TEST("capability.rng", "capabilityschemadata", "xencapsdata");
DO_TEST("domain.rng", "domainschemadata", "qemuargv2xmldata",
"qemuxml2argvdata", "sexpr2xmldata", "xmconfigdata",
--
2.12.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list