qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v2 4/6] qapi: add String visitor coverage to serialization unit tests
Date: Thu, 23 Feb 2012 14:22:24 -0600	[thread overview]
Message-ID: <1330028546-13183-5-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1330028546-13183-1-git-send-email-mdroth@linux.vnet.ibm.com>


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

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 }
 };
 
-- 
1.7.4.1

  parent reply	other threads:[~2012-02-23 20:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23 20:22 [Qemu-devel] [PATCH v2 0/6] add fixed-width visitors and serialization tests Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 1/6] qapi: add Visitor interfaces for uint*_t and int*_t Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 2/6] qapi: unit tests for visitor-based serialization Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 3/6] qapi: QMP input visitor, handle floats parsed as ints Michael Roth
2012-02-23 20:22 ` Michael Roth [this message]
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 5/6] qapi: String visitor, use %f represenation for floats Michael Roth
2012-02-23 20:22 ` [Qemu-devel] [PATCH v2 6/6] qdev: switch property accessors to fixed-width visitor interfaces Michael Roth
2012-02-24 17:22   ` Anthony Liguori
2012-02-25 15:41     ` Michael Roth
2012-02-25 16:08       ` Andreas Färber
2012-02-25 20:33         ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1330028546-13183-5-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).