aboutsummaryrefslogtreecommitdiff
path: root/tests/test-visitor-serialization.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-visitor-serialization.c')
-rw-r--r--tests/test-visitor-serialization.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index 777469f..dba4670 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -19,6 +19,7 @@
#include "test-qapi-visit.h"
#include "qapi/error.h"
#include "qapi/qmp/types.h"
+#include "qapi/qmp/qjson.h"
#include "qapi/qmp-input-visitor.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/string-input-visitor.h"
@@ -88,11 +89,11 @@ typedef void (*VisitorFunc)(Visitor *v, void **native, Error **errp);
static void dealloc_helper(void *native_in, VisitorFunc visit, Error **errp)
{
- QapiDeallocVisitor *qdv = qapi_dealloc_visitor_new();
+ Visitor *v = qapi_dealloc_visitor_new();
- visit(qapi_dealloc_get_visitor(qdv), &native_in, errp);
+ visit(v, &native_in, errp);
- qapi_dealloc_visitor_cleanup(qdv);
+ visit_free(v);
}
static void visit_primitive_type(Visitor *v, void **native, Error **errp)
@@ -1011,8 +1012,9 @@ static PrimitiveType pt_values[] = {
/* visitor-specific op implementations */
typedef struct QmpSerializeData {
- QmpOutputVisitor *qov;
- QmpInputVisitor *qiv;
+ Visitor *qov;
+ QObject *obj;
+ Visitor *qiv;
} QmpSerializeData;
static void qmp_serialize(void *native_in, void **datap,
@@ -1020,8 +1022,8 @@ static void qmp_serialize(void *native_in, void **datap,
{
QmpSerializeData *d = g_malloc0(sizeof(*d));
- d->qov = qmp_output_visitor_new();
- visit(qmp_output_get_visitor(d->qov), &native_in, errp);
+ d->qov = qmp_output_visitor_new(&d->obj);
+ visit(d->qov, &native_in, errp);
*datap = d;
}
@@ -1032,7 +1034,8 @@ static void qmp_deserialize(void **native_out, void *datap,
QString *output_json;
QObject *obj_orig, *obj;
- obj_orig = qmp_output_get_qobject(d->qov);
+ visit_complete(d->qov, &d->obj);
+ obj_orig = d->obj;
output_json = qobject_to_json(obj_orig);
obj = qobject_from_json(qstring_get_str(output_json));
@@ -1040,22 +1043,22 @@ static void qmp_deserialize(void **native_out, void *datap,
d->qiv = qmp_input_visitor_new(obj, true);
qobject_decref(obj_orig);
qobject_decref(obj);
- visit(qmp_input_get_visitor(d->qiv), native_out, errp);
+ visit(d->qiv, native_out, errp);
}
static void qmp_cleanup(void *datap)
{
QmpSerializeData *d = datap;
- qmp_output_visitor_cleanup(d->qov);
- qmp_input_visitor_cleanup(d->qiv);
+ visit_free(d->qov);
+ visit_free(d->qiv);
g_free(d);
}
typedef struct StringSerializeData {
char *string;
- StringOutputVisitor *sov;
- StringInputVisitor *siv;
+ Visitor *sov;
+ Visitor *siv;
} StringSerializeData;
static void string_serialize(void *native_in, void **datap,
@@ -1063,8 +1066,8 @@ static void string_serialize(void *native_in, void **datap,
{
StringSerializeData *d = g_malloc0(sizeof(*d));
- d->sov = string_output_visitor_new(false);
- visit(string_output_get_visitor(d->sov), &native_in, errp);
+ d->sov = string_output_visitor_new(false, &d->string);
+ visit(d->sov, &native_in, errp);
*datap = d;
}
@@ -1073,17 +1076,17 @@ static void string_deserialize(void **native_out, void *datap,
{
StringSerializeData *d = datap;
- d->string = string_output_get_string(d->sov);
+ visit_complete(d->sov, &d->string);
d->siv = string_input_visitor_new(d->string);
- visit(string_input_get_visitor(d->siv), native_out, errp);
+ visit(d->siv, native_out, errp);
}
static void string_cleanup(void *datap)
{
StringSerializeData *d = datap;
- string_output_visitor_cleanup(d->sov);
- string_input_visitor_cleanup(d->siv);
+ visit_free(d->sov);
+ visit_free(d->siv);
g_free(d->string);
g_free(d);
}