aboutsummaryrefslogtreecommitdiff
path: root/tests/check-qjson.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-08-06 08:53:27 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-08-16 08:42:06 +0200
commit6ce80fd80355d29b3ed8c2fa14251a9b8276a86a (patch)
tree6d048a675aaa10b377a5470a4ae94b06084ca679 /tests/check-qjson.c
parentbb340eb2387edfc59098bde4caea387c369005b1 (diff)
downloadqemu-6ce80fd80355d29b3ed8c2fa14251a9b8276a86a.zip
qemu-6ce80fd80355d29b3ed8c2fa14251a9b8276a86a.tar.gz
qemu-6ce80fd80355d29b3ed8c2fa14251a9b8276a86a.tar.bz2
qobject: Replace qobject_from_jsonf() by qobject_from_jsonf_nofail()
Commit ab45015a968 "qobject: Let qobject_from_jsonf() fail instead of abort" fails to accomplish its stated aim: the function can still abort due to its use of &error_abort. Its rationale for letting it fail is that all remaining users cope fine with failure. Well, they're just fine with aborting, too; it's what they do on failure. Simply reverting the broken commit would bring back the unfortunate asymmetry between qobject_from_jsonf() and qobject_from_jsonv(): one aborts, the other returns null. So also rename it to qobject_from_jsonf_nofail(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180806065344.7103-7-armbru@redhat.com>
Diffstat (limited to 'tests/check-qjson.c')
-rw-r--r--tests/check-qjson.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index da582df..eaf5d20 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -865,7 +865,8 @@ static void vararg_string(void)
QString *str;
str = qobject_to(QString,
- qobject_from_jsonf("%s", test_cases[i].decoded));
+ qobject_from_jsonf_nofail("%s",
+ test_cases[i].decoded));
g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
@@ -998,17 +999,17 @@ static void vararg_number(void)
double valuef = 2.323423423;
int64_t val;
- qnum = qobject_to(QNum, qobject_from_jsonf("%d", value));
+ qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%d", value));
g_assert(qnum_get_try_int(qnum, &val));
g_assert_cmpint(val, ==, value);
qobject_unref(qnum);
- qnum = qobject_to(QNum, qobject_from_jsonf("%lld", value_ll));
+ qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%lld", value_ll));
g_assert(qnum_get_try_int(qnum, &val));
g_assert_cmpint(val, ==, value_ll);
qobject_unref(qnum);
- qnum = qobject_to(QNum, qobject_from_jsonf("%f", valuef));
+ qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%f", valuef));
g_assert(qnum_get_double(qnum) == valuef);
qobject_unref(qnum);
}
@@ -1042,13 +1043,13 @@ static void keyword_literal(void)
qobject_unref(qbool);
- qbool = qobject_to(QBool, qobject_from_jsonf("%i", false));
+ qbool = qobject_to(QBool, qobject_from_jsonf_nofail("%i", false));
g_assert(qbool);
g_assert(qbool_get_bool(qbool) == false);
qobject_unref(qbool);
/* Test that non-zero values other than 1 get collapsed to true */
- qbool = qobject_to(QBool, qobject_from_jsonf("%i", 2));
+ qbool = qobject_to(QBool, qobject_from_jsonf_nofail("%i", 2));
g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
qobject_unref(qbool);
@@ -1298,7 +1299,7 @@ static void simple_varargs(void)
embedded_obj = qobject_from_json("[32, 42]", &error_abort);
g_assert(embedded_obj != NULL);
- obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
+ obj = qobject_from_jsonf_nofail("[%d, 2, %p]", 1, embedded_obj);
g_assert(qlit_equal_qobject(&decoded, obj));
qobject_unref(obj);