cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qapi-fix-visitor-serialization-tests-for-numbers-dou.patch

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