aboutsummaryrefslogtreecommitdiff
path: root/tests/test-qmp-output-visitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-qmp-output-visitor.c')
-rw-r--r--tests/test-qmp-output-visitor.c92
1 files changed, 32 insertions, 60 deletions
diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index f8a7a271a9..513d71f0d1 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -18,28 +18,34 @@
#include "test-qapi-types.h"
#include "test-qapi-visit.h"
#include "qapi/qmp/types.h"
+#include "qapi/qmp/qjson.h"
typedef struct TestOutputVisitorData {
- QmpOutputVisitor *qov;
Visitor *ov;
+ QObject *obj;
} TestOutputVisitorData;
static void visitor_output_setup(TestOutputVisitorData *data,
const void *unused)
{
- data->qov = qmp_output_visitor_new();
- g_assert(data->qov != NULL);
-
- data->ov = qmp_output_get_visitor(data->qov);
- g_assert(data->ov != NULL);
+ data->ov = qmp_output_visitor_new(&data->obj);
+ g_assert(data->ov);
}
static void visitor_output_teardown(TestOutputVisitorData *data,
const void *unused)
{
- qmp_output_visitor_cleanup(data->qov);
- data->qov = NULL;
+ visit_free(data->ov);
data->ov = NULL;
+ qobject_decref(data->obj);
+ data->obj = NULL;
+}
+
+static QObject *visitor_get(TestOutputVisitorData *data)
+{
+ visit_complete(data->ov, &data->obj);
+ g_assert(data->obj);
+ return data->obj;
}
static void visitor_reset(TestOutputVisitorData *data)
@@ -56,12 +62,9 @@ static void test_visitor_out_int(TestOutputVisitorData *data,
visit_type_int(data->ov, NULL, &value, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QINT);
g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value);
-
- qobject_decref(obj);
}
static void test_visitor_out_bool(TestOutputVisitorData *data,
@@ -72,12 +75,9 @@ static void test_visitor_out_bool(TestOutputVisitorData *data,
visit_type_bool(data->ov, NULL, &value, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QBOOL);
g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value);
-
- qobject_decref(obj);
}
static void test_visitor_out_number(TestOutputVisitorData *data,
@@ -88,12 +88,9 @@ static void test_visitor_out_number(TestOutputVisitorData *data,
visit_type_number(data->ov, NULL, &value, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QFLOAT);
g_assert(qfloat_get_double(qobject_to_qfloat(obj)) == value);
-
- qobject_decref(obj);
}
static void test_visitor_out_string(TestOutputVisitorData *data,
@@ -104,12 +101,9 @@ static void test_visitor_out_string(TestOutputVisitorData *data,
visit_type_str(data->ov, NULL, &string, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QSTRING);
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string);
-
- qobject_decref(obj);
}
static void test_visitor_out_no_string(TestOutputVisitorData *data,
@@ -121,12 +115,9 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data,
/* A null string should return "" */
visit_type_str(data->ov, NULL, &string, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QSTRING);
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, "");
-
- qobject_decref(obj);
}
static void test_visitor_out_enum(TestOutputVisitorData *data,
@@ -138,12 +129,10 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
for (i = 0; i < ENUM_ONE__MAX; i++) {
visit_type_EnumOne(data->ov, "unused", &i, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QSTRING);
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==,
EnumOne_lookup[i]);
- qobject_decref(obj);
visitor_reset(data);
}
}
@@ -176,8 +165,7 @@ static void test_visitor_out_struct(TestOutputVisitorData *data,
visit_type_TestStruct(data->ov, NULL, &p, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QDICT);
qdict = qobject_to_qdict(obj);
@@ -185,8 +173,6 @@ static void test_visitor_out_struct(TestOutputVisitorData *data,
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false);
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo");
-
- QDECREF(qdict);
}
static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
@@ -221,8 +207,7 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QDICT);
qdict = qobject_to_qdict(obj);
@@ -249,7 +234,6 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value);
g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string);
- QDECREF(qdict);
qapi_free_UserDefTwo(ud2);
}
@@ -301,8 +285,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data,
visit_type_TestStructList(data->ov, NULL, &head, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QLIST);
qlist = qobject_to_qlist(obj);
@@ -323,7 +306,6 @@ static void test_visitor_out_list(TestOutputVisitorData *data,
}
g_assert_cmpint(i, ==, max_items);
- QDECREF(qlist);
qapi_free_TestStructList(head);
}
@@ -367,11 +349,9 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qobj = QOBJECT(qint_from_int(-42));
visit_type_any(data->ov, NULL, &qobj, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QINT);
g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42);
- qobject_decref(obj);
qobject_decref(qobj);
visitor_reset(data);
@@ -382,8 +362,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qobj = QOBJECT(qdict);
visit_type_any(data->ov, NULL, &qobj, &error_abort);
qobject_decref(qobj);
- obj = qmp_output_get_qobject(data->qov);
- g_assert(obj != NULL);
+ obj = visitor_get(data);
qdict = qobject_to_qdict(obj);
g_assert(qdict);
qobj = qdict_get(qdict, "integer");
@@ -401,7 +380,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qstring = qobject_to_qstring(qobj);
g_assert(qstring);
g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
- qobject_decref(obj);
}
static void test_visitor_out_union_flat(TestOutputVisitorData *data,
@@ -417,7 +395,7 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
tmp->u.value1.boolean = true;
visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort);
- arg = qmp_output_get_qobject(data->qov);
+ arg = visitor_get(data);
g_assert(qobject_type(arg) == QTYPE_QDICT);
qdict = qobject_to_qdict(arg);
@@ -428,7 +406,6 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
qapi_free_UserDefFlatUnion(tmp);
- QDECREF(qdict);
}
static void test_visitor_out_alternate(TestOutputVisitorData *data,
@@ -443,13 +420,12 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.i = 42;
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = qmp_output_get_qobject(data->qov);
+ arg = visitor_get(data);
g_assert(qobject_type(arg) == QTYPE_QINT);
g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42);
qapi_free_UserDefAlternate(tmp);
- qobject_decref(arg);
visitor_reset(data);
tmp = g_new0(UserDefAlternate, 1);
@@ -457,13 +433,12 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.s = g_strdup("hello");
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = qmp_output_get_qobject(data->qov);
+ arg = visitor_get(data);
g_assert(qobject_type(arg) == QTYPE_QSTRING);
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello");
qapi_free_UserDefAlternate(tmp);
- qobject_decref(arg);
visitor_reset(data);
tmp = g_new0(UserDefAlternate, 1);
@@ -474,7 +449,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.udfu.u.value1.boolean = true;
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = qmp_output_get_qobject(data->qov);
+ arg = visitor_get(data);
g_assert_cmpint(qobject_type(arg), ==, QTYPE_QDICT);
qdict = qobject_to_qdict(arg);
@@ -485,7 +460,6 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
qapi_free_UserDefAlternate(tmp);
- qobject_decref(arg);
}
static void test_visitor_out_null(TestOutputVisitorData *data,
@@ -498,15 +472,14 @@ static void test_visitor_out_null(TestOutputVisitorData *data,
visit_start_struct(data->ov, NULL, NULL, 0, &error_abort);
visit_type_null(data->ov, "a", &error_abort);
visit_check_struct(data->ov, &error_abort);
- visit_end_struct(data->ov);
- arg = qmp_output_get_qobject(data->qov);
+ visit_end_struct(data->ov, NULL);
+ arg = visitor_get(data);
g_assert(qobject_type(arg) == QTYPE_QDICT);
qdict = qobject_to_qdict(arg);
g_assert_cmpint(qdict_size(qdict), ==, 1);
nil = qdict_get(qdict, "a");
g_assert(nil);
g_assert(qobject_type(nil) == QTYPE_QNULL);
- qobject_decref(arg);
}
static void init_native_list(UserDefNativeListUnion *cvalue)
@@ -737,10 +710,9 @@ static void test_native_list(TestOutputVisitorData *data,
visit_type_UserDefNativeListUnion(data->ov, NULL, &cvalue, &error_abort);
- obj = qmp_output_get_qobject(data->qov);
+ obj = visitor_get(data);
check_native_list(obj, cvalue->type);
qapi_free_UserDefNativeListUnion(cvalue);
- qobject_decref(obj);
}
static void test_visitor_out_native_list_int(TestOutputVisitorData *data,