static int testTextMetadata(const void *data) { const struct metadataTest *test = data; char *actual = NULL; int ret = -1; if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0) < 0) { if (test->fail) return 0; return -1; } actual = virDomainGetMetadata(test->dom, test->type, NULL, 0); if (STRNEQ_NULLABLE(test->data, actual)) { virReportError(VIR_ERR_INTERNAL_ERROR, "expected metadata doesn't match actual: " "expected:'%s'\ngot: '%s'", NULLSTR(test->data), NULLSTR(actual)); goto cleanup; } ret = 0; cleanup: VIR_FREE(actual); return ret; }
static bool verifyMetadata(virDomainPtr dom, const char *expectXML, const char *expectAPI, const char *uri) { bool ret = false; char *metadataXML = NULL; char *metadataAPI = NULL; if (!expectAPI) { if ((metadataAPI = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, uri, 0))) { virReportError(VIR_ERR_INTERNAL_ERROR, "expected no metadata in API, but got:\n[%s]", metadataAPI); goto cleanup; } } else { if (!(metadataAPI = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, uri, 0))) goto cleanup; metadataXMLConvertApostrophe(metadataAPI); if (STRNEQ(metadataAPI, expectAPI)) { virReportError(VIR_ERR_INTERNAL_ERROR, "XML metadata in API doesn't match expected metadata: " "expected:\n[%s]\ngot:\n[%s]", expectAPI, metadataAPI); goto cleanup; } } if (!expectXML) { if ((metadataXML = getMetadataFromXML(dom))) { virReportError(VIR_ERR_INTERNAL_ERROR, "expected no metadata in XML, but got:\n[%s]", metadataXML); goto cleanup; } } else { if (!(metadataXML = getMetadataFromXML(dom))) goto cleanup; metadataXMLConvertApostrophe(metadataXML); if (STRNEQ(metadataXML, expectXML)) { virReportError(VIR_ERR_INTERNAL_ERROR, "XML in dump doesn't match expected metadata: " "expected:\n[%s]\ngot:\n[%s]", expectXML, metadataXML); goto cleanup; } } ret = true; cleanup: VIR_FREE(metadataXML); VIR_FREE(metadataAPI); return ret; }