mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-01 20:05:46 +00:00
tests: json: Validate that attribute values are properly stolen
Make sure that the 'a' and 'A' modifiers for virJSONValueObjectAddVArgs behave correctly. Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
ea520f6b67
commit
d4dd836edc
@ -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
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
@ -588,6 +633,8 @@ mymain(void)
|
|||||||
NULL, true);
|
NULL, true);
|
||||||
DO_TEST_FULL("create object with nested json in attribute", EscapeObj,
|
DO_TEST_FULL("create object with nested json in attribute", EscapeObj,
|
||||||
NULL, NULL, true);
|
NULL, NULL, true);
|
||||||
|
DO_TEST_FULL("stealing of attributes while creating objects",
|
||||||
|
ObjectFormatSteal, NULL, NULL, true);
|
||||||
|
|
||||||
#define DO_TEST_DEFLATTEN(name, pass) \
|
#define DO_TEST_DEFLATTEN(name, pass) \
|
||||||
DO_TEST_FULL(name, Deflatten, name, NULL, pass)
|
DO_TEST_FULL(name, Deflatten, name, NULL, pass)
|
||||||
|
Loading…
Reference in New Issue
Block a user