From ebb4d82d88810c31cb5eee408e1ac6d319f7f9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 30 Aug 2018 17:58:07 +0200 Subject: tests: add qmp_assert_error_class() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helper will simplify a bunch of code checking for QMP errors and can be shared by various tests. Note that test-qga does check for error description as well, so don't replace the code there for now. Signed-off-by: Marc-André Lureau Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- tests/libqtest.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index d635c5bea0..2cd5736642 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -1194,3 +1194,14 @@ bool qmp_rsp_is_err(QDict *rsp) qobject_unref(rsp); return !!error; } + +void qmp_assert_error_class(QDict *rsp, const char *class) +{ + QDict *error = qdict_get_qdict(rsp, "error"); + + g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class); + g_assert_nonnull(qdict_get_try_str(error, "desc")); + g_assert(!qdict_haskey(rsp, "return")); + + qobject_unref(rsp); +} -- cgit v1.2.3