aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-02-17 21:38:21 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-02-22 19:52:09 +0100
commit0abfc4b885566eb41c3a4e1de5e2e105bdc062d9 (patch)
tree78148f230b948ffb4530620290e30d8e06aaf712 /tests
parent363e13f86eb60bce1e112a35a4c107505a69c9fe (diff)
tests: Don't check qobject_type() before qobject_to_qint()
qobject_to_qint(obj) returns NULL when obj isn't a QInt. Check that instead of qobject_type(obj) == QTYPE_QINT. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1487363905-9480-11-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/check-qjson.c24
-rw-r--r--tests/test-qobject-output-visitor.c28
2 files changed, 17 insertions, 35 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index dd080a8024..aab4e0a86d 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -884,19 +884,15 @@ static void simple_number(void)
};
for (i = 0; test_cases[i].encoded; i++) {
- QObject *obj;
QInt *qint;
- obj = qobject_from_json(test_cases[i].encoded);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QINT);
-
- qint = qobject_to_qint(obj);
+ qint = qobject_to_qint(qobject_from_json(test_cases[i].encoded));
+ g_assert(qint);
g_assert(qint_get_int(qint) == test_cases[i].decoded);
if (test_cases[i].skip == 0) {
QString *str;
- str = qobject_to_json(obj);
+ str = qobject_to_json(QOBJECT(qint));
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
QDECREF(str);
}
@@ -952,22 +948,12 @@ static void vararg_number(void)
long long value_ll = 0x2342342343LL;
double valuef = 2.323423423;
- obj = qobject_from_jsonf("%d", value);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QINT);
-
- qint = qobject_to_qint(obj);
+ qint = qobject_to_qint(qobject_from_jsonf("%d", value));
g_assert(qint_get_int(qint) == value);
-
QDECREF(qint);
- obj = qobject_from_jsonf("%lld", value_ll);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QINT);
-
- qint = qobject_to_qint(obj);
+ qint = qobject_to_qint(qobject_from_jsonf("%lld", value_ll));
g_assert(qint_get_int(qint) == value_ll);
-
QDECREF(qint);
obj = qobject_from_jsonf("%f", valuef);
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index 3e34aa5783..50b807e1ab 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -58,13 +58,13 @@ static void test_visitor_out_int(TestOutputVisitorData *data,
const void *unused)
{
int64_t value = -42;
- QObject *obj;
+ QInt *qint;
visit_type_int(data->ov, NULL, &value, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QINT);
- g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value);
+ qint = qobject_to_qint(visitor_get(data));
+ g_assert(qint);
+ g_assert_cmpint(qint_get_int(qint), ==, value);
}
static void test_visitor_out_bool(TestOutputVisitorData *data,
@@ -335,13 +335,12 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
QBool *qbool;
QString *qstring;
QDict *qdict;
- QObject *obj;
qobj = QOBJECT(qint_from_int(-42));
visit_type_any(data->ov, NULL, &qobj, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QINT);
- g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42);
+ qint = qobject_to_qint(visitor_get(data));
+ g_assert(qint);
+ g_assert_cmpint(qint_get_int(qint), ==, -42);
qobject_decref(qobj);
visitor_reset(data);
@@ -354,9 +353,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qobject_decref(qobj);
qdict = qobject_to_qdict(visitor_get(data));
g_assert(qdict);
- qobj = qdict_get(qdict, "integer");
- g_assert(qobj);
- qint = qobject_to_qint(qobj);
+ qint = qobject_to_qint(qdict_get(qdict, "integer"));
g_assert(qint);
g_assert_cmpint(qint_get_int(qint), ==, -42);
qobj = qdict_get(qdict, "boolean");
@@ -394,8 +391,8 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
static void test_visitor_out_alternate(TestOutputVisitorData *data,
const void *unused)
{
- QObject *arg;
UserDefAlternate *tmp;
+ QInt *qint;
QString *qstr;
QDict *qdict;
@@ -404,10 +401,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.i = 42;
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = visitor_get(data);
-
- g_assert(qobject_type(arg) == QTYPE_QINT);
- g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42);
+ qint = qobject_to_qint(visitor_get(data));
+ g_assert(qint);
+ g_assert_cmpint(qint_get_int(qint), ==, 42);
qapi_free_UserDefAlternate(tmp);