summary refs log tree commit diff stats
path: root/tests/libqtest.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-08-30 17:58:07 +0200
committerThomas Huth <thuth@redhat.com>2018-08-31 09:53:10 +0200
commitebb4d82d88810c31cb5eee408e1ac6d319f7f9bb (patch)
tree3c58c804ec1f08f2da77bd3cae154caeb894947a /tests/libqtest.c
parentb8e1f74b0a258db394a35272a44d14ec0b6e0be9 (diff)
downloadfocaccia-qemu-ebb4d82d88810c31cb5eee408e1ac6d319f7f9bb.tar.gz
focaccia-qemu-ebb4d82d88810c31cb5eee408e1ac6d319f7f9bb.zip
tests: add qmp_assert_error_class()
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 <marcandre.lureau@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/libqtest.c')
-rw-r--r--tests/libqtest.c11
1 files changed, 11 insertions, 0 deletions
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);
+}