tests/test-qmp-cmds: Check responses more thoroughly

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200317115459.31821-7-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2020-03-17 12:54:31 +01:00
parent 3306459a78
commit ef9f5f0d59
1 changed files with 17 additions and 6 deletions

View File

@ -151,9 +151,10 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow_oob)
QObject *ret;
resp = qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob);
g_assert(resp && !qdict_haskey(resp, "error"));
g_assert(resp);
ret = qdict_get(resp, "return");
g_assert(ret);
g_assert(qdict_size(resp) == 1);
qobject_ref(ret);
qobject_unref(resp);
@ -163,9 +164,17 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow_oob)
static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass cls)
{
QDict *resp;
QDict *error;
resp = qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob);
g_assert(resp && qdict_haskey(resp, "error"));
g_assert(resp);
error = qdict_get_qdict(resp, "error");
g_assert(error);
g_assert_cmpstr(qdict_get_try_str(error, "class"),
==, QapiErrorClass_str(cls));
g_assert(qdict_get_try_str(error, "desc"));
g_assert(qdict_size(error) == 2);
g_assert(qdict_size(resp) == 1);
qobject_unref(resp);
}
@ -174,11 +183,12 @@ static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass cls)
static void test_dispatch_cmd(void)
{
QDict *req = qdict_new();
QObject *ret;
QDict *ret;
qdict_put_str(req, "execute", "user_def_cmd");
ret = do_qmp_dispatch(req, false);
ret = qobject_to(QDict, do_qmp_dispatch(req, false));
assert(ret && qdict_size(ret) == 0);
qobject_unref(ret);
qobject_unref(req);
@ -187,11 +197,12 @@ static void test_dispatch_cmd(void)
static void test_dispatch_cmd_oob(void)
{
QDict *req = qdict_new();
QObject *ret;
QDict *ret;
qdict_put_str(req, "exec-oob", "test-flags-command");
ret = do_qmp_dispatch(req, true);
ret = qobject_to(QDict, do_qmp_dispatch(req, true));
assert(ret && qdict_size(ret) == 0);
qobject_unref(ret);
qobject_unref(req);