qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Hu Tao" <hutao@cn.fujitsu.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Luiz Capitulino" <lcapitulino@redhat.com>,
	"Anthony Liguori" <aliguori@amazon.com>,
	=?UTF-8?q?Andreas=20F=C3=A4rber?= <afaerber@suse.de>
Subject: [Qemu-devel] [PULL 37/37] tests: add human format test for string output visitor
Date: Sun, 29 Jun 2014 20:00:16 +0300	[thread overview]
Message-ID: <1404060115-27410-38-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1404060115-27410-1-git-send-email-mst@redhat.com>

From: Hu Tao <hutao@cn.fujitsu.com>

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/test-string-output-visitor.c | 109 ++++++++++++++++++++++++++++++-------
 1 file changed, 90 insertions(+), 19 deletions(-)

diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c
index 28e7359..e89e43c 100644
--- a/tests/test-string-output-visitor.c
+++ b/tests/test-string-output-visitor.c
@@ -21,12 +21,25 @@
 typedef struct TestOutputVisitorData {
     StringOutputVisitor *sov;
     Visitor *ov;
+    bool human;
 } TestOutputVisitorData;
 
 static void visitor_output_setup(TestOutputVisitorData *data,
                                  const void *unused)
 {
-    data->sov = string_output_visitor_new(false);
+    data->human = false;
+    data->sov = string_output_visitor_new(data->human);
+    g_assert(data->sov != NULL);
+
+    data->ov = string_output_get_visitor(data->sov);
+    g_assert(data->ov != NULL);
+}
+
+static void visitor_output_setup_human(TestOutputVisitorData *data,
+                                       const void *unused)
+{
+    data->human = true;
+    data->sov = string_output_visitor_new(data->human);
     g_assert(data->sov != NULL);
 
     data->ov = string_output_get_visitor(data->sov);
@@ -53,7 +66,11 @@ static void test_visitor_out_int(TestOutputVisitorData *data,
 
     str = string_output_get_string(data->sov);
     g_assert(str != NULL);
-    g_assert_cmpstr(str, ==, "42");
+    if (data->human) {
+        g_assert_cmpstr(str, ==, "42 (0x2a)");
+    } else {
+        g_assert_cmpstr(str, ==, "42");
+    }
     g_free(str);
 }
 
@@ -78,8 +95,15 @@ static void test_visitor_out_intList(TestOutputVisitorData *data,
 
     str = string_output_get_string(data->sov);
     g_assert(str != NULL);
-    g_assert_cmpstr(str, ==,
-        "0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807");
+    if (data->human) {
+        g_assert_cmpstr(str, ==,
+            "0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807 "
+            "(0x0-0x1,0x3-0x6,0x9-0x10,0x15-0x16,"
+            "0x7ffffffffffffffe-0x7fffffffffffffff)");
+    } else {
+        g_assert_cmpstr(str, ==,
+            "0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807");
+    }
     g_free(str);
     while (list) {
         intList *tmp2;
@@ -125,6 +149,7 @@ static void test_visitor_out_string(TestOutputVisitorData *data,
                                     const void *unused)
 {
     char *string = (char *) "Q E M U";
+    const char *string_human = "\"Q E M U\"";
     Error *err = NULL;
     char *str;
 
@@ -133,7 +158,11 @@ static void test_visitor_out_string(TestOutputVisitorData *data,
 
     str = string_output_get_string(data->sov);
     g_assert(str != NULL);
-    g_assert_cmpstr(str, ==, string);
+    if (data->human) {
+        g_assert_cmpstr(str, ==, string_human);
+    } else {
+        g_assert_cmpstr(str, ==, string);
+    }
     g_free(str);
 }
 
@@ -150,7 +179,11 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data,
 
     str = string_output_get_string(data->sov);
     g_assert(str != NULL);
-    g_assert_cmpstr(str, ==, "");
+    if (data->human) {
+        g_assert_cmpstr(str, ==, "<null>");
+    } else {
+        g_assert_cmpstr(str, ==, "");
+    }
     g_free(str);
 }
 
@@ -162,12 +195,26 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
     EnumOne i;
 
     for (i = 0; i < ENUM_ONE_MAX; i++) {
+        char *str_human;
+        int len;
+
         visit_type_EnumOne(data->ov, &i, "unused", &err);
         g_assert(!err);
 
+        len = strlen(EnumOne_lookup[i]) + 2;
+        str_human = g_malloc0(len);
+        str_human[0] = '"';
+        strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
+        str_human[len - 1] = '"';
+
         str = string_output_get_string(data->sov);
         g_assert(str != NULL);
-        g_assert_cmpstr(str, ==, EnumOne_lookup[i]);
+        if (data->human) {
+            g_assert_cmpstr(str, ==, str_human);
+        } else {
+            g_assert_cmpstr(str, ==, EnumOne_lookup[i]);
+        }
+        g_free(str_human);
 	g_free(str);
     }
 }
@@ -186,11 +233,15 @@ static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
     }
 }
 
-static void output_visitor_test_add(const char *testpath,
-                                    TestOutputVisitorData *data,
-                                    void (*test_func)(TestOutputVisitorData *data, const void *user_data))
+static void
+output_visitor_test_add(const char *testpath,
+                        TestOutputVisitorData *data,
+                        void (*test_func)(TestOutputVisitorData *data,
+                                          const void *user_data),
+                        bool human)
 {
-    g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup,
+    g_test_add(testpath, TestOutputVisitorData, data,
+               human ? visitor_output_setup_human : visitor_output_setup,
                test_func, visitor_output_teardown);
 }
 
@@ -201,21 +252,41 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
 
     output_visitor_test_add("/string-visitor/output/int",
-                            &out_visitor_data, test_visitor_out_int);
+                            &out_visitor_data, test_visitor_out_int, false);
+    output_visitor_test_add("/string-visitor/output/int",
+                            &out_visitor_data, test_visitor_out_int, true);
+    output_visitor_test_add("/string-visitor/output/bool",
+                            &out_visitor_data, test_visitor_out_bool, false);
     output_visitor_test_add("/string-visitor/output/bool",
-                            &out_visitor_data, test_visitor_out_bool);
+                            &out_visitor_data, test_visitor_out_bool, true);
+    output_visitor_test_add("/string-visitor/output/number",
+                            &out_visitor_data, test_visitor_out_number, false);
     output_visitor_test_add("/string-visitor/output/number",
-                            &out_visitor_data, test_visitor_out_number);
+                            &out_visitor_data, test_visitor_out_number, true);
     output_visitor_test_add("/string-visitor/output/string",
-                            &out_visitor_data, test_visitor_out_string);
+                            &out_visitor_data, test_visitor_out_string, false);
+    output_visitor_test_add("/string-visitor/output/string",
+                            &out_visitor_data, test_visitor_out_string, true);
+    output_visitor_test_add("/string-visitor/output/no-string",
+                            &out_visitor_data, test_visitor_out_no_string,
+                            false);
     output_visitor_test_add("/string-visitor/output/no-string",
-                            &out_visitor_data, test_visitor_out_no_string);
+                            &out_visitor_data, test_visitor_out_no_string,
+                            true);
+    output_visitor_test_add("/string-visitor/output/enum",
+                            &out_visitor_data, test_visitor_out_enum, false);
     output_visitor_test_add("/string-visitor/output/enum",
-                            &out_visitor_data, test_visitor_out_enum);
+                            &out_visitor_data, test_visitor_out_enum, true);
     output_visitor_test_add("/string-visitor/output/enum-errors",
-                            &out_visitor_data, test_visitor_out_enum_errors);
+                            &out_visitor_data, test_visitor_out_enum_errors,
+                            false);
+    output_visitor_test_add("/string-visitor/output/enum-errors",
+                            &out_visitor_data, test_visitor_out_enum_errors,
+                            true);
+    output_visitor_test_add("/string-visitor/output/intList",
+                            &out_visitor_data, test_visitor_out_intList, false);
     output_visitor_test_add("/string-visitor/output/intList",
-                            &out_visitor_data, test_visitor_out_intList);
+                            &out_visitor_data, test_visitor_out_intList, true);
 
     g_test_run();
 
-- 
MST

  parent reply	other threads:[~2014-06-29 17:00 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-29 16:58 [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 01/37] numa: fix comment Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 02/37] openrisc: " Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 03/37] numa: " Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 04/37] pc: Move q35 compat props to PC_COMPAT_* Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 05/37] pc: Fix "prog_if" typo on PC_COMPAT_2_0 Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 06/37] mc146818rtc: add rtc-reset-reinjection QMP command Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 07/37] vhost-user: fix wrong ids in documentation Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 08/37] pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 09/37] Allow mismatched virtio config-len Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 10/37] numa: Keep track of NUMA nodes present on the command-line Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 11/37] numa: Reject duplicate node IDs Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 12/37] numa: Reject configuration if not all node IDs are present Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 13/37] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 14/37] vhost-user: typo fixups Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 16/37] virtio-serial: don't migrate the config space Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 17/37] virtio: introduce device specific migration calls Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 18/37] virtio-net: implement per-device " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 19/37] virtio-blk: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 20/37] virtio-serial: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 21/37] virtio-balloon: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 22/37] virtio-rng: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 23/37] virtio: add subsections to the migration stream Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 24/37] exec: introduce target_words_bigendian() helper Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 25/37] cpu: introduce CPUClass::virtio_is_big_endian() Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 26/37] virtio: add endian-ambivalent support to VirtIODevice Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 27/37] virtio: memory accessors for endian-ambivalent targets Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 28/37] virtio: allow byte swapping for vring Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 29/37] virtio-net: use virtio wrappers to access headers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 30/37] virtio-balloon: use virtio wrappers to access page frame numbers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 31/37] virtio-blk: use virtio wrappers to access headers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 32/37] virtio-scsi: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 33/37] virtio-serial-bus: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 34/37] virtio-9p: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 35/37] target-ppc: enable virtio endian ambivalent support Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 36/37] vhost-net: disable when cross-endian Michael S. Tsirkin
2014-06-29 17:00 ` Michael S. Tsirkin [this message]
2014-07-09 19:14   ` [Qemu-devel] [PULL 37/37] tests: add human format test for string output visitor Andreas Färber
2014-07-09 19:34     ` Peter Maydell
2014-06-29 17:36 ` [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements Peter Maydell
2014-06-29 20:34   ` Michael S. Tsirkin
2014-06-29 20:41     ` Peter Maydell

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=1404060115-27410-38-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=hutao@cn.fujitsu.com \
    --cc=lcapitulino@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).