tests: Don't check qobject_type() before qobject_to_qbool()
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 <armbru@redhat.com> Message-Id: <1487363905-9480-13-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
8978b34af3
commit
dfad9ec4e9
@ -966,10 +966,8 @@ static void keyword_literal(void)
|
|||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
obj = qobject_from_json("true");
|
obj = qobject_from_json("true");
|
||||||
g_assert(obj != NULL);
|
|
||||||
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
qbool = qobject_to_qbool(obj);
|
||||||
|
g_assert(qbool);
|
||||||
g_assert(qbool_get_bool(qbool) == true);
|
g_assert(qbool_get_bool(qbool) == true);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
@ -979,10 +977,8 @@ static void keyword_literal(void)
|
|||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
obj = qobject_from_json("false");
|
obj = qobject_from_json("false");
|
||||||
g_assert(obj != NULL);
|
|
||||||
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
qbool = qobject_to_qbool(obj);
|
||||||
|
g_assert(qbool);
|
||||||
g_assert(qbool_get_bool(qbool) == false);
|
g_assert(qbool_get_bool(qbool) == false);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
@ -991,23 +987,15 @@ static void keyword_literal(void)
|
|||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
obj = qobject_from_jsonf("%i", false);
|
qbool = qobject_to_qbool(qobject_from_jsonf("%i", false));
|
||||||
g_assert(obj != NULL);
|
g_assert(qbool);
|
||||||
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
|
||||||
g_assert(qbool_get_bool(qbool) == false);
|
g_assert(qbool_get_bool(qbool) == false);
|
||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
/* Test that non-zero values other than 1 get collapsed to true */
|
/* Test that non-zero values other than 1 get collapsed to true */
|
||||||
obj = qobject_from_jsonf("%i", 2);
|
qbool = qobject_to_qbool(qobject_from_jsonf("%i", 2));
|
||||||
g_assert(obj != NULL);
|
g_assert(qbool);
|
||||||
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
|
||||||
g_assert(qbool_get_bool(qbool) == true);
|
g_assert(qbool_get_bool(qbool) == true);
|
||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
obj = qobject_from_json("null");
|
obj = qobject_from_json("null");
|
||||||
|
@ -71,13 +71,13 @@ static void test_visitor_out_bool(TestOutputVisitorData *data,
|
|||||||
const void *unused)
|
const void *unused)
|
||||||
{
|
{
|
||||||
bool value = true;
|
bool value = true;
|
||||||
QObject *obj;
|
QBool *qbool;
|
||||||
|
|
||||||
visit_type_bool(data->ov, NULL, &value, &error_abort);
|
visit_type_bool(data->ov, NULL, &value, &error_abort);
|
||||||
|
|
||||||
obj = visitor_get(data);
|
qbool = qobject_to_qbool(visitor_get(data));
|
||||||
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
g_assert(qbool);
|
||||||
g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value);
|
g_assert(qbool_get_bool(qbool) == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_visitor_out_number(TestOutputVisitorData *data,
|
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"));
|
qint = qobject_to_qint(qdict_get(qdict, "integer"));
|
||||||
g_assert(qint);
|
g_assert(qint);
|
||||||
g_assert_cmpint(qint_get_int(qint), ==, -42);
|
g_assert_cmpint(qint_get_int(qint), ==, -42);
|
||||||
qobj = qdict_get(qdict, "boolean");
|
qbool = qobject_to_qbool(qdict_get(qdict, "boolean"));
|
||||||
g_assert(qobj);
|
|
||||||
qbool = qobject_to_qbool(qobj);
|
|
||||||
g_assert(qbool);
|
g_assert(qbool);
|
||||||
g_assert(qbool_get_bool(qbool) == true);
|
g_assert(qbool_get_bool(qbool) == true);
|
||||||
qstring = qobject_to_qstring(qdict_get(qdict, "string"));
|
qstring = qobject_to_qstring(qdict_get(qdict, "string"));
|
||||||
|
Loading…
Reference in New Issue
Block a user