qapi: Add String visitor coverage to serialization unit tests

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Michael Roth 2012-02-22 10:16:31 -06:00 committed by Andreas Färber
parent 173bbb754f
commit 0d30b0a2d3

View File

@ -19,6 +19,8 @@
#include "qemu-objects.h"
#include "qapi/qmp-input-visitor.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
typedef struct PrimitiveType {
union {
@ -666,6 +668,37 @@ static void qmp_cleanup(void *datap)
qmp_input_visitor_cleanup(d->qiv);
}
typedef struct StringSerializeData {
StringOutputVisitor *sov;
StringInputVisitor *siv;
} StringSerializeData;
static void string_serialize(void *native_in, void **datap,
VisitorFunc visit, Error **errp)
{
StringSerializeData *d = g_malloc0(sizeof(*d));
d->sov = string_output_visitor_new();
visit(string_output_get_visitor(d->sov), &native_in, errp);
*datap = d;
}
static void string_deserialize(void **native_out, void *datap,
VisitorFunc visit, Error **errp)
{
StringSerializeData *d = datap;
d->siv = string_input_visitor_new(string_output_get_string(d->sov));
visit(string_input_get_visitor(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);
}
/* visitor registration, test harness */
/* note: to function interchangeably as a serialization mechanism your
@ -680,6 +713,13 @@ static const SerializeOps visitors[] = {
.cleanup = qmp_cleanup,
.caps = VCAP_PRIMITIVES | VCAP_STRUCTURES | VCAP_LISTS
},
{
.type = "String",
.serialize = string_serialize,
.deserialize = string_deserialize,
.cleanup = string_cleanup,
.caps = VCAP_PRIMITIVES
},
{ NULL }
};