aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2020-12-11 18:11:37 +0100
committerMarkus Armbruster <armbru@redhat.com>2020-12-19 10:38:43 +0100
commiteab3a4678b07267c39e7290a6e9e7690b1d2a521 (patch)
tree223d43bbde1e59f4f6867a36e2dfdf0ca36603f3 /tests/qtest
parentf1cc129df8341ebb6176363d24b57035bb5dabe4 (diff)
downloadqemu-eab3a4678b07267c39e7290a6e9e7690b1d2a521.zip
qemu-eab3a4678b07267c39e7290a6e9e7690b1d2a521.tar.gz
qemu-eab3a4678b07267c39e7290a6e9e7690b1d2a521.tar.bz2
qobject: Change qobject_to_json()'s value to GString
qobject_to_json() and qobject_to_json_pretty() build a GString, then covert it to QString. Just one of the callers actually needs a QString: qemu_rbd_parse_filename(). A few others need a string they can modify: qmp_send_response(), qga's send_response(), to_json_str(), and qmp_fd_vsend_fds(). The remainder just need a string. Change qobject_to_json() and qobject_to_json_pretty() to return the GString. qemu_rbd_parse_filename() now has to convert to QString. All others save a QString temporary. to_json_str() actually becomes a bit simpler, because GString provides more convenient modification functions. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20201211171152.146877-6-armbru@redhat.com>
Diffstat (limited to 'tests/qtest')
-rw-r--r--tests/qtest/libqtest.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 213fa4f..8e93b0a 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -652,27 +652,25 @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
/* No need to send anything for an empty QObject. */
if (qobj) {
int log = getenv("QTEST_LOG") != NULL;
- QString *qstr = qobject_to_json(qobj);
- const char *str;
+ GString *str = qobject_to_json(qobj);
/*
* BUG: QMP doesn't react to input until it sees a newline, an
* object, or an array. Work-around: give it a newline.
*/
- qstring_append_chr(qstr, '\n');
- str = qstring_get_str(qstr);
+ g_string_append_c(str, '\n');
if (log) {
- fprintf(stderr, "%s", str);
+ fprintf(stderr, "%s", str->str);
}
/* Send QMP request */
if (fds && fds_num > 0) {
- socket_send_fds(fd, fds, fds_num, str, qstring_get_length(qstr));
+ socket_send_fds(fd, fds, fds_num, str->str, str->len);
} else {
- socket_send(fd, str, qstring_get_length(qstr));
+ socket_send(fd, str->str, str->len);
}
- qobject_unref(qstr);
+ g_string_free(str, true);
qobject_unref(qobj);
}
}
@@ -1197,9 +1195,9 @@ void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
g_assert(response);
if (!qdict_haskey(response, "return")) {
- QString *s = qobject_to_json_pretty(QOBJECT(response), true);
- g_test_message("%s", qstring_get_str(s));
- qobject_unref(s);
+ GString *s = qobject_to_json_pretty(QOBJECT(response), true);
+ g_test_message("%s", s->str);
+ g_string_free(s, true);
}
g_assert(qdict_haskey(response, "return"));
qobject_unref(response);