[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/16] tests: Don't check qobject_type() before qobje
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 14/16] tests: Don't check qobject_type() before qobject_to_qbool() |
Date: |
Wed, 22 Feb 2017 20:14:56 +0100 |
qobject_to_qbool(obj) returns NULL when obj isn't a QBool. Check
that instead of qobject_type(obj) == QTYPE_QBOOL.
Signed-off-by: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
tests/check-qjson.c | 24 ++++++------------------
tests/test-qobject-output-visitor.c | 12 +++++-------
2 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 591b70a..e6d6935 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -966,10 +966,8 @@ static void keyword_literal(void)
QString *str;
obj = qobject_from_json("true");
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
qbool = qobject_to_qbool(obj);
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
str = qobject_to_json(obj);
@@ -979,10 +977,8 @@ static void keyword_literal(void)
QDECREF(qbool);
obj = qobject_from_json("false");
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
qbool = qobject_to_qbool(obj);
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == false);
str = qobject_to_json(obj);
@@ -991,23 +987,15 @@ static void keyword_literal(void)
QDECREF(qbool);
- obj = qobject_from_jsonf("%i", false);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
- qbool = qobject_to_qbool(obj);
+ qbool = qobject_to_qbool(qobject_from_jsonf("%i", false));
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == false);
-
QDECREF(qbool);
/* Test that non-zero values other than 1 get collapsed to true */
- obj = qobject_from_jsonf("%i", 2);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
- qbool = qobject_to_qbool(obj);
+ qbool = qobject_to_qbool(qobject_from_jsonf("%i", 2));
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
-
QDECREF(qbool);
obj = qobject_from_json("null");
diff --git a/tests/test-qobject-output-visitor.c
b/tests/test-qobject-output-visitor.c
index 5617fd3..500b452 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -71,13 +71,13 @@ static void test_visitor_out_bool(TestOutputVisitorData
*data,
const void *unused)
{
bool value = true;
- QObject *obj;
+ QBool *qbool;
visit_type_bool(data->ov, NULL, &value, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
- g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value);
+ qbool = qobject_to_qbool(visitor_get(data));
+ g_assert(qbool);
+ g_assert(qbool_get_bool(qbool) == value);
}
static void test_visitor_out_number(TestOutputVisitorData *data,
@@ -356,9 +356,7 @@ static void test_visitor_out_any(TestOutputVisitorData
*data,
qint = qobject_to_qint(qdict_get(qdict, "integer"));
g_assert(qint);
g_assert_cmpint(qint_get_int(qint), ==, -42);
- qobj = qdict_get(qdict, "boolean");
- g_assert(qobj);
- qbool = qobject_to_qbool(qobj);
+ qbool = qobject_to_qbool(qdict_get(qdict, "boolean"));
g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
qstring = qobject_to_qstring(qdict_get(qdict, "string"));
--
2.7.4
- [Qemu-devel] [PULL 10/16] tests: Don't check qobject_type() before qobject_to_qlist(), (continued)
- [Qemu-devel] [PULL 10/16] tests: Don't check qobject_type() before qobject_to_qlist(), Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 16/16] block: Don't bother asserting type of output visitor's output, Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 06/16] check-qjson: Simplify around compare_litqobj_to_qobj(), Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 11/16] tests: Don't check qobject_type() before qobject_to_qstring(), Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 03/16] qdict: Make qdict_get_qlist() safe like qdict_get_qdict(), Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 02/16] net: Flatten simple union NetLegacyOptions, Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 04/16] check-qdict: Simplify qdict_crumple_test_recursive(), Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 05/16] check-qdict: Tighten qdict_crumple_test_recursive() some, Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 15/16] monitor: Clean up handle_hmp_command() a bit, Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 12/16] tests: Don't check qobject_type() before qobject_to_qint(), Markus Armbruster, 2017/02/22
- [Qemu-devel] [PULL 14/16] tests: Don't check qobject_type() before qobject_to_qbool(),
Markus Armbruster <=
- [Qemu-devel] [PULL 09/16] Don't check qobject_type() before qobject_to_qdict(), Markus Armbruster, 2017/02/22
- Re: [Qemu-devel] [PULL 00/16] QAPI patches for 2017-02-22, Peter Maydell, 2017/02/24