diff options
author | Michael Roth <mdroth@linux.vnet.ibm.com> | 2012-02-22 10:16:31 -0600 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2012-06-08 16:11:14 +0200 |
commit | 0d30b0a2d338cd5f463a0fd3942d19f70eb6db56 (patch) | |
tree | 6b1f14fa8578895e463a7150c7603da333aff227 /tests/test-visitor-serialization.c | |
parent | 173bbb754f53e8bfc8e4d488f2ed66fe1072ed69 (diff) |
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>
Diffstat (limited to 'tests/test-visitor-serialization.c')
-rw-r--r-- | tests/test-visitor-serialization.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index 6ef57d046f..b8ad16fc9e 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -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 } }; |