aboutsummaryrefslogtreecommitdiff
path: root/tests/check-qjson.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-02-17 21:38:20 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-02-22 19:52:06 +0100
commit363e13f86eb60bce1e112a35a4c107505a69c9fe (patch)
tree76361fe0824ba2f7488e03af988905b1f307f468 /tests/check-qjson.c
parentcd17ba51f5b25196c52afe5dfdd27c7dc8621cf4 (diff)
downloadqemu-363e13f86eb60bce1e112a35a4c107505a69c9fe.zip
qemu-363e13f86eb60bce1e112a35a4c107505a69c9fe.tar.gz
qemu-363e13f86eb60bce1e112a35a4c107505a69c9fe.tar.bz2
tests: Don't check qobject_type() before qobject_to_qstring()
qobject_to_qstring(obj) returns NULL when obj isn't a QString. Check that instead of qobject_type(obj) == QTYPE_QSTRING. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1487363905-9480-10-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests/check-qjson.c')
-rw-r--r--tests/check-qjson.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 49e02591..dd080a8 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -54,11 +54,8 @@ static void escaped_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded);
if (test_cases[i].skip == 0) {
@@ -89,11 +86,8 @@ static void simple_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
str = qobject_to_json(obj);
@@ -123,11 +117,8 @@ static void single_quote_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);
@@ -820,9 +811,8 @@ static void utf8_string(void)
obj = qobject_from_json(json_in);
if (utf8_out) {
- g_assert(obj);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
} else {
g_assert(!obj);
@@ -847,9 +837,8 @@ static void utf8_string(void)
*/
if (0 && json_out != json_in) {
obj = qobject_from_json(json_out);
- g_assert(obj);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
}
}
@@ -867,15 +856,11 @@ static void vararg_string(void)
};
for (i = 0; test_cases[i].decoded; i++) {
- QObject *obj;
QString *str;
- obj = qobject_from_jsonf("%s", test_cases[i].decoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
- str = qobject_to_qstring(obj);
+ str = qobject_to_qstring(qobject_from_jsonf("%s",
+ test_cases[i].decoded));
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);