qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 13/16] tests: Don't check qobject_type() before qobject_to_qfloat()
Date: Wed, 22 Feb 2017 20:14:55 +0100	[thread overview]
Message-ID: <1487790898-24921-14-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1487790898-24921-1-git-send-email-armbru@redhat.com>

qobject_to_qfloat(obj) returns NULL when obj isn't a QFloat.  Check
that instead of qobject_type(obj) == QTYPE_QFLOAT.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1487363905-9480-12-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 tests/check-qjson.c                 | 12 ++----------
 tests/test-qobject-output-visitor.c |  8 ++++----
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index aab4e0a..591b70a 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -921,10 +921,8 @@ static void float_number(void)
         QFloat *qfloat;
 
         obj = qobject_from_json(test_cases[i].encoded);
-        g_assert(obj != NULL);
-        g_assert(qobject_type(obj) == QTYPE_QFLOAT);
-
         qfloat = qobject_to_qfloat(obj);
+        g_assert(qfloat);
         g_assert(qfloat_get_double(qfloat) == test_cases[i].decoded);
 
         if (test_cases[i].skip == 0) {
@@ -941,7 +939,6 @@ static void float_number(void)
 
 static void vararg_number(void)
 {
-    QObject *obj;
     QInt *qint;
     QFloat *qfloat;
     int value = 0x2342;
@@ -956,13 +953,8 @@ static void vararg_number(void)
     g_assert(qint_get_int(qint) == value_ll);
     QDECREF(qint);
 
-    obj = qobject_from_jsonf("%f", valuef);
-    g_assert(obj != NULL);
-    g_assert(qobject_type(obj) == QTYPE_QFLOAT);
-
-    qfloat = qobject_to_qfloat(obj);
+    qfloat = qobject_to_qfloat(qobject_from_jsonf("%f", valuef));
     g_assert(qfloat_get_double(qfloat) == valuef);
-
     QDECREF(qfloat);
 }
 
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index 50b807e..5617fd3 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -84,13 +84,13 @@ static void test_visitor_out_number(TestOutputVisitorData *data,
                                     const void *unused)
 {
     double value = 3.14;
-    QObject *obj;
+    QFloat *qfloat;
 
     visit_type_number(data->ov, NULL, &value, &error_abort);
 
-    obj = visitor_get(data);
-    g_assert(qobject_type(obj) == QTYPE_QFLOAT);
-    g_assert(qfloat_get_double(qobject_to_qfloat(obj)) == value);
+    qfloat = qobject_to_qfloat(visitor_get(data));
+    g_assert(qfloat);
+    g_assert(qfloat_get_double(qfloat) == value);
 }
 
 static void test_visitor_out_string(TestOutputVisitorData *data,
-- 
2.7.4

  parent reply	other threads:[~2017-02-22 19:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-22 19:14 [Qemu-devel] [PULL 00/16] QAPI patches for 2017-02-22 Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 01/16] numa: Flatten simple union NumaOptions Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 02/16] net: Flatten simple union NetLegacyOptions Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 03/16] qdict: Make qdict_get_qlist() safe like qdict_get_qdict() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 04/16] check-qdict: Simplify qdict_crumple_test_recursive() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 05/16] check-qdict: Tighten qdict_crumple_test_recursive() some Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 06/16] check-qjson: Simplify around compare_litqobj_to_qobj() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 07/16] libqtest: Clean up qmp_response() a bit Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 08/16] test-qmp-event: Simplify and tighten event_test_emit() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 09/16] Don't check qobject_type() before qobject_to_qdict() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 10/16] tests: Don't check qobject_type() before qobject_to_qlist() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 11/16] tests: Don't check qobject_type() before qobject_to_qstring() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 12/16] tests: Don't check qobject_type() before qobject_to_qint() Markus Armbruster
2017-02-22 19:14 ` Markus Armbruster [this message]
2017-02-22 19:14 ` [Qemu-devel] [PULL 14/16] tests: Don't check qobject_type() before qobject_to_qbool() Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 15/16] monitor: Clean up handle_hmp_command() a bit Markus Armbruster
2017-02-22 19:14 ` [Qemu-devel] [PULL 16/16] block: Don't bother asserting type of output visitor's output Markus Armbruster
2017-02-24 17:27 ` [Qemu-devel] [PULL 00/16] QAPI patches for 2017-02-22 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=1487790898-24921-14-git-send-email-armbru@redhat.com \
    --to=armbru@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).