提交 d4dd836e 编写于 作者: P Peter Krempa

tests: json: Validate that attribute values are properly stolen

Make sure that the 'a' and 'A' modifiers for virJSONValueObjectAddVArgs
behave correctly.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 ea520f6b
......@@ -429,6 +429,51 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED)
}
static int
testJSONObjectFormatSteal(const void *opaque ATTRIBUTE_UNUSED)
{
virJSONValuePtr a1 = NULL;
virJSONValuePtr a2 = NULL;
virJSONValuePtr t1 = NULL;
virJSONValuePtr t2 = NULL;
int ret = -1;
if (!(a1 = virJSONValueNewString("test")) ||
!(a2 = virJSONValueNewString("test"))) {
VIR_TEST_VERBOSE("Failed to create json object");
}
if (virJSONValueObjectCreate(&t1, "a:t", &a1, "s:f", NULL, NULL) != -1) {
VIR_TEST_VERBOSE("virJSONValueObjectCreate(t1) should have failed\n");
goto cleanup;
}
if (a1) {
VIR_TEST_VERBOSE("appended object a1 was not consumed\n");
goto cleanup;
}
if (virJSONValueObjectCreate(&t2, "s:f", NULL, "a:t", &a1, NULL) != -1) {
VIR_TEST_VERBOSE("virJSONValueObjectCreate(t2) should have failed\n");
goto cleanup;
}
if (!a2) {
VIR_TEST_VERBOSE("appended object a2 was consumed\n");
goto cleanup;
}
ret = 0;
cleanup:
virJSONValueFree(a1);
virJSONValueFree(a2);
virJSONValueFree(t1);
virJSONValueFree(t2);
return ret;
}
static int
mymain(void)
{
......@@ -588,6 +633,8 @@ mymain(void)
NULL, true);
DO_TEST_FULL("create object with nested json in attribute", EscapeObj,
NULL, NULL, true);
DO_TEST_FULL("stealing of attributes while creating objects",
ObjectFormatSteal, NULL, NULL, true);
#define DO_TEST_DEFLATTEN(name, pass) \
DO_TEST_FULL(name, Deflatten, name, NULL, pass)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册