qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com
Subject: [PATCH 02/10] tests/check-qjson: Examine QNum more thoroughly
Date: Thu, 10 Dec 2020 17:14:44 +0100	[thread overview]
Message-ID: <20201210161452.2813491-3-armbru@redhat.com> (raw)
In-Reply-To: <20201210161452.2813491-1-armbru@redhat.com>

simple_number() checks only qnum_get_try_int().  Also check
qnum_get_try_uint() and qnum_get_double().

float_number() checks only qnum_get_double().  Also check
qnum_get_try_int() and qnum_get_try_uint().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/check-qjson.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 2a5852904a..6ab6b111b0 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -807,7 +807,8 @@ static void simple_number(void)
     };
     int i;
     QNum *qnum;
-    int64_t val;
+    int64_t ival;
+    uint64_t uval;
     QString *str;
 
     for (i = 0; test_cases[i].encoded; i++) {
@@ -815,8 +816,16 @@ static void simple_number(void)
                           qobject_from_json(test_cases[i].encoded,
                                             &error_abort));
         g_assert(qnum);
-        g_assert(qnum_get_try_int(qnum, &val));
-        g_assert_cmpint(val, ==, test_cases[i].decoded);
+        g_assert(qnum_get_try_int(qnum, &ival));
+        g_assert_cmpint(ival, ==, test_cases[i].decoded);
+        if (test_cases[i].decoded >= 0) {
+            g_assert(qnum_get_try_uint(qnum, &uval));
+            g_assert_cmpuint(uval, ==, (uint64_t)test_cases[i].decoded);
+        } else {
+            g_assert(!qnum_get_try_uint(qnum, &uval));
+        }
+        g_assert_cmpfloat(qnum_get_double(qnum), ==,
+                          (double)test_cases[i].decoded);
 
         str = qobject_to_json(QOBJECT(qnum));
         g_assert_cmpstr(qstring_get_str(str), ==,
@@ -885,6 +894,8 @@ static void float_number(void)
     };
     int i;
     QNum *qnum;
+    int64_t ival;
+    uint64_t uval;
     QString *str;
 
     for (i = 0; test_cases[i].encoded; i++) {
@@ -893,6 +904,8 @@ static void float_number(void)
                                             &error_abort));
         g_assert(qnum);
         g_assert_cmpfloat(qnum_get_double(qnum), ==, test_cases[i].decoded);
+        g_assert(!qnum_get_try_int(qnum, &ival));
+        g_assert(!qnum_get_try_uint(qnum, &uval));
 
         str = qobject_to_json(QOBJECT(qnum));
         g_assert_cmpstr(qstring_get_str(str), ==,
-- 
2.26.2



  parent reply	other threads:[~2020-12-10 16:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 16:14 [PATCH 00/10] Fix floating-point -> text conversion precision Markus Armbruster
2020-12-10 16:14 ` [PATCH 01/10] tests/check-qjson: Don't skip funny QNumber to JSON conversions Markus Armbruster
2020-12-10 16:14 ` Markus Armbruster [this message]
2020-12-10 16:14 ` [PATCH 03/10] tests/check-qjson: Cover number 2^63 Markus Armbruster
2020-12-10 16:14 ` [PATCH 04/10] tests/check-qjson: Replace redundant large_number() Markus Armbruster
2020-12-10 16:14 ` [PATCH 05/10] tests/check-qnum: Cover qnum_to_string() for "unround" argument Markus Armbruster
2020-12-10 16:14 ` [PATCH 06/10] qobject: Fix qnum_to_string() to use sufficient precision Markus Armbruster
2020-12-10 16:14 ` [PATCH 07/10] test-string-output-visitor: Cover "unround" number Markus Armbruster
2020-12-10 16:14 ` [PATCH 08/10] string-output-visitor: Fix to use sufficient precision Markus Armbruster
2020-12-10 16:14 ` [PATCH 09/10] test-visitor-serialization: Drop insufficient precision workaround Markus Armbruster
2020-12-10 16:14 ` [PATCH 10/10] test-visitor-serialization: Clean up test_primitives() Markus Armbruster
2020-12-10 20:36 ` [PATCH 00/10] Fix floating-point -> text conversion precision no-reply

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=20201210161452.2813491-3-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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).