/* if dirRegex is non-NULL the provided regular expression is used to match
* the file names in a directory (without path prefixed) and only matching
* files are validated */
+ const char **exceptions; /* optional NULL terminated list of filenames inside
+ directory where the expected validation result is
+ inverted */
const char *dirRegex;
const char *file;
};
struct testSchemaData {
virXMLValidator *validator;
+ bool exception;
const char *xml_path;
};
bool shouldFail = !!strstr(data->xml_path, "-invalid.");
g_autoptr(xmlDoc) xml = NULL;
+ if (data->exception)
+ shouldFail = !shouldFail;
+
if (!(xml = virXMLParseFileCtxt(data->xml_path, NULL)))
return -1;
static int
testSchemaFile(const char *schema,
virXMLValidator *validator,
- const char *path)
+ const char *path,
+ bool exception)
{
g_autofree char *test_name = NULL;
struct testSchemaData data = {
.validator = validator,
.xml_path = path,
+ .exception = exception,
};
test_name = g_strdup_printf("Checking %s against %s", path, schema);
testSchemaDir(const char *schema,
virXMLValidator *validator,
const char *dir_path,
- const char *filterstr)
+ const struct testSchemaEntry *entry)
{
g_autoptr(DIR) dir = NULL;
struct dirent *ent;
return -1;
}
- if (filterstr) {
+ if (entry->dirRegex) {
g_autoptr(GError) err = NULL;
- if (!(filter = g_regex_new(filterstr, 0, 0, &err))) {
- VIR_TEST_VERBOSE("\nfailed to compile regex '%s': %s", filterstr, err->message);
+ if (!(filter = g_regex_new(entry->dirRegex, 0, 0, &err))) {
+ VIR_TEST_VERBOSE("\nfailed to compile regex '%s': %s", entry->dirRegex, err->message);
return -1;
}
}
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
g_autofree char *xml_path = NULL;
+ bool exception = false;
if (!virStringHasSuffix(ent->d_name, ".xml"))
continue;
!g_regex_match(filter, ent->d_name, 0, NULL))
continue;
+ if (entry->exceptions)
+ exception = g_strv_contains(entry->exceptions, ent->d_name);
+
xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
- if (testSchemaFile(schema, validator, xml_path) < 0)
+ if (testSchemaFile(schema, validator, xml_path, exception) < 0)
ret = -1;
}
if (entry->dir) {
g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir, entry->dir);
- if (testSchemaDir(schema, validator, path, entry->dirRegex) < 0)
+ if (testSchemaDir(schema, validator, path, entry) < 0)
ret = -1;
}
if (entry->file) {
g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir, entry->file);
- if (testSchemaFile(schema, validator, path) < 0)
+ if (testSchemaFile(schema, validator, path, false) < 0)
ret = -1;
}
}
{ .dir = "tests/qemucaps2xmloutdata" },
};
+
+/* give exceptions for output files of invalid input XMLs */
+static const char *exceptions_qemuxml2xmloutdata[] = {
+ "disk-cdrom-empty-network-invalid.x86_64-latest.xml",
+ NULL
+};
+
static const struct testSchemaEntry schemaDomain[] = {
{ .dir = "tests/domainschemadata" },
{ .dir = "tests/qemuxml2argvdata" },
{ .dir = "tests/xmconfigdata" },
- { .dir = "tests/qemuxml2xmloutdata" },
+ { .dir = "tests/qemuxml2xmloutdata",
+ .exceptions = exceptions_qemuxml2xmloutdata,
+ },
{ .dir = "tests/lxcxml2xmldata" },
{ .dir = "tests/lxcxml2xmloutdata" },
{ .dir = "tests/bhyvexml2argvdata" },