cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From e9f800ec6e87d1fee21c59dc83236456ee7f91f8 Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <e9f800ec6e87d1fee21c59dc83236456ee7f91f8.1387369730.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <091eecc4fa42754760dfff393dabcc2b444e9693.1387369730.git.minovotn@redhat.com>
9ae3a8
References: <091eecc4fa42754760dfff393dabcc2b444e9693.1387369730.git.minovotn@redhat.com>
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
Date: Tue, 10 Dec 2013 15:29:06 +0100
9ae3a8
Subject: [PATCH 06/21] qapi: fix visitor serialization tests for
9ae3a8
 numbers/doubles
9ae3a8
9ae3a8
RH-Author: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: <1386689361-30281-4-git-send-email-armbru@redhat.com>
9ae3a8
Patchwork-id: 56121
9ae3a8
O-Subject: [PATCH 7.0 qemu-kvm 03/18] qapi: fix visitor serialization tests for numbers/doubles
9ae3a8
Bugzilla: 997915
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
9ae3a8
From: Michael Roth <mdroth@linux.vnet.ibm.com>
9ae3a8
9ae3a8
We never actually stored the stringified double values into the strings
9ae3a8
before we did the comparisons. This left number/double values completely
9ae3a8
uncovered in test-visitor-serialization tests.
9ae3a8
9ae3a8
Fixing this exposed a bug in our handling of large whole number values
9ae3a8
in QEMU's JSON parser which is now fixed.
9ae3a8
9ae3a8
Simplify the code while we're at it by dropping the
9ae3a8
calc_float_string_storage() craziness in favor of GStrings.
9ae3a8
9ae3a8
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9ae3a8
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Reviewed-by: Amos Kong <akong@redhat.com>
9ae3a8
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
(cherry picked from commit 089f26bb735fb414b79f5fa3753910d5339d2a1d)
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
---
9ae3a8
 tests/test-visitor-serialization.c | 25 ++++++++-----------------
9ae3a8
 1 file changed, 8 insertions(+), 17 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 tests/test-visitor-serialization.c | 25 ++++++++-----------------
9ae3a8
 1 file changed, 8 insertions(+), 17 deletions(-)
9ae3a8
9ae3a8
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
9ae3a8
index 8c8adac..fed6810 100644
9ae3a8
--- a/tests/test-visitor-serialization.c
9ae3a8
+++ b/tests/test-visitor-serialization.c
9ae3a8
@@ -229,17 +229,6 @@ typedef struct TestArgs {
9ae3a8
     void *test_data;
9ae3a8
 } TestArgs;
9ae3a8
 
9ae3a8
-#define FLOAT_STRING_PRECISION 6 /* corresponding to n in %.nf formatting */
9ae3a8
-static gsize calc_float_string_storage(double value)
9ae3a8
-{
9ae3a8
-    int whole_value = value;
9ae3a8
-    gsize i = 0;
9ae3a8
-    do {
9ae3a8
-        i++;
9ae3a8
-    } while (whole_value /= 10);
9ae3a8
-    return i + 2 + FLOAT_STRING_PRECISION;
9ae3a8
-}
9ae3a8
-
9ae3a8
 static void test_primitives(gconstpointer opaque)
9ae3a8
 {
9ae3a8
     TestArgs *args = (TestArgs *) opaque;
9ae3a8
@@ -248,7 +237,6 @@ static void test_primitives(gconstpointer opaque)
9ae3a8
     PrimitiveType *pt_copy = g_malloc0(sizeof(*pt_copy));
9ae3a8
     Error *err = NULL;
9ae3a8
     void *serialize_data;
9ae3a8
-    char *double1, *double2;
9ae3a8
 
9ae3a8
     pt_copy->type = pt->type;
9ae3a8
     ops->serialize(pt, &serialize_data, visit_primitive_type, &err;;
9ae3a8
@@ -260,14 +248,17 @@ static void test_primitives(gconstpointer opaque)
9ae3a8
         g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string);
9ae3a8
         g_free((char *)pt_copy->value.string);
9ae3a8
     } else if (pt->type == PTYPE_NUMBER) {
9ae3a8
+        GString *double_expected = g_string_new("");
9ae3a8
+        GString *double_actual = g_string_new("");
9ae3a8
         /* we serialize with %f for our reference visitors, so rather than fuzzy
9ae3a8
          * floating math to test "equality", just compare the formatted values
9ae3a8
          */
9ae3a8
-        double1 = g_malloc0(calc_float_string_storage(pt->value.number));
9ae3a8
-        double2 = g_malloc0(calc_float_string_storage(pt_copy->value.number));
9ae3a8
-        g_assert_cmpstr(double1, ==, double2);
9ae3a8
-        g_free(double1);
9ae3a8
-        g_free(double2);
9ae3a8
+        g_string_printf(double_expected, "%.6f", pt->value.number);
9ae3a8
+        g_string_printf(double_actual, "%.6f", pt_copy->value.number);
9ae3a8
+        g_assert_cmpstr(double_actual->str, ==, double_expected->str);
9ae3a8
+
9ae3a8
+        g_string_free(double_expected, true);
9ae3a8
+        g_string_free(double_actual, true);
9ae3a8
     } else if (pt->type == PTYPE_BOOLEAN) {
9ae3a8
         g_assert_cmpint(!!pt->value.max, ==, !!pt->value.max);
9ae3a8
     } else {
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8