Patchwork [v2,4/6] qapi: add String visitor coverage to serialization unit tests

login
register
mail settings
Submitter Michael Roth
Date Feb. 23, 2012, 8:22 p.m.
Message ID <1330028546-13183-5-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/142700/
State New
Headers show

Comments

Michael Roth - Feb. 23, 2012, 8:22 p.m.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 test-visitor-serialization.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

Patch

diff --git a/test-visitor-serialization.c b/test-visitor-serialization.c
index 6ef57d0..b8ad16f 100644
--- a/test-visitor-serialization.c
+++ b/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 }
 };