aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-02-24 15:00:51 +0000
committerPeter Maydell <peter.maydell@linaro.org>2017-02-24 15:00:51 +0000
commitfe8ee082db5038a05dbd8872e946049e9a9c550e (patch)
tree08196bf3cf3c278b6f8fcf51a91affb87b45162f
parent63f495beb4007de5444614125fd6fd178ca6e2b1 (diff)
parent7c81e4e9db5f63635fbf11d66bf08e73d325ae97 (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-02-22' into staging
QAPI patches for 2017-02-22 # gpg: Signature made Wed 22 Feb 2017 19:12:27 GMT # gpg: using RSA key 0x3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2017-02-22: block: Don't bother asserting type of output visitor's output monitor: Clean up handle_hmp_command() a bit tests: Don't check qobject_type() before qobject_to_qbool() tests: Don't check qobject_type() before qobject_to_qfloat() tests: Don't check qobject_type() before qobject_to_qint() tests: Don't check qobject_type() before qobject_to_qstring() tests: Don't check qobject_type() before qobject_to_qlist() Don't check qobject_type() before qobject_to_qdict() test-qmp-event: Simplify and tighten event_test_emit() libqtest: Clean up qmp_response() a bit check-qjson: Simplify around compare_litqobj_to_qobj() check-qdict: Tighten qdict_crumple_test_recursive() some check-qdict: Simplify qdict_crumple_test_recursive() qdict: Make qdict_get_qlist() safe like qdict_get_qdict() net: Flatten simple union NetLegacyOptions numa: Flatten simple union NumaOptions Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--block.c4
-rw-r--r--block/nbd.c2
-rw-r--r--block/nfs.c2
-rw-r--r--block/qapi.c1
-rw-r--r--hw/pci/pcie_aer.c2
-rw-r--r--monitor.c13
-rw-r--r--net/net.c44
-rw-r--r--numa.c4
-rw-r--r--qapi-schema.json21
-rw-r--r--qapi/qmp-dispatch.c5
-rw-r--r--qobject/qdict.c30
-rw-r--r--tests/check-qdict.c37
-rw-r--r--tests/check-qjson.c113
-rw-r--r--tests/libqtest.c4
-rw-r--r--tests/test-qmp-event.c14
-rw-r--r--tests/test-qobject-output-visitor.c133
16 files changed, 155 insertions, 274 deletions
diff --git a/block.c b/block.c
index 743c349100..3c36af5e76 100644
--- a/block.c
+++ b/block.c
@@ -1169,13 +1169,13 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
return NULL;
}
- if (qobject_type(options_obj) != QTYPE_QDICT) {
+ options = qobject_to_qdict(options_obj);
+ if (!options) {
qobject_decref(options_obj);
error_setg(errp, "Invalid JSON object given");
return NULL;
}
- options = qobject_to_qdict(options_obj);
qdict_flatten(options);
return options;
diff --git a/block/nbd.c b/block/nbd.c
index 35f24be069..a7f9108fe5 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -537,8 +537,6 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort);
visit_complete(ov, &saddr_qdict);
visit_free(ov);
- assert(qobject_type(saddr_qdict) == QTYPE_QDICT);
-
qdict_put_obj(opts, "server", saddr_qdict);
if (s->export) {
diff --git a/block/nfs.c b/block/nfs.c
index 08b43dd189..0cf115e7d6 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -805,8 +805,6 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options)
ov = qobject_output_visitor_new(&server_qdict);
visit_type_NFSServer(ov, NULL, &client->server, &error_abort);
visit_complete(ov, &server_qdict);
- assert(qobject_type(server_qdict) == QTYPE_QDICT);
-
qdict_put_obj(opts, "server", server_qdict);
qdict_put(opts, "path", qstring_from_str(client->path));
diff --git a/block/qapi.c b/block/qapi.c
index ac480aa93c..a40922ea26 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -682,7 +682,6 @@ void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort);
visit_complete(v, &obj);
- assert(qobject_type(obj) == QTYPE_QDICT);
data = qdict_get(qobject_to_qdict(obj), "data");
dump_qobject(func_fprintf, f, 1, data);
qobject_decref(obj);
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index daf1f65427..a8c18203d6 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -1025,8 +1025,8 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict)
return;
}
- assert(qobject_type(data) == QTYPE_QDICT);
qdict = qobject_to_qdict(data);
+ assert(qdict);
devfn = (int)qdict_get_int(qdict, "devfn");
monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n",
diff --git a/monitor.c b/monitor.c
index ead4c633fb..5aff7aebb0 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3712,12 +3712,12 @@ static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp)
int has_exec_key = 0;
QDict *input_dict;
- if (qobject_type(input_obj) != QTYPE_QDICT) {
+ input_dict = qobject_to_qdict(input_obj);
+ if (!input_dict) {
error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "object");
return NULL;
}
- input_dict = qobject_to_qdict(input_obj);
for (ent = qdict_first(input_dict); ent; ent = qdict_next(input_dict, ent)){
const char *arg_name = qdict_entry_key(ent);
@@ -3761,10 +3761,11 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
Error *err = NULL;
req = json_parser_parse_err(tokens, NULL, &err);
- if (err || !req || qobject_type(req) != QTYPE_QDICT) {
- if (!err) {
- error_setg(&err, QERR_JSON_PARSING);
- }
+ if (!req && !err) {
+ /* json_parser_parse_err() sucks: can fail without setting @err */
+ error_setg(&err, QERR_JSON_PARSING);
+ }
+ if (err) {
goto err_out;
}
diff --git a/net/net.c b/net/net.c
index fb7af3a432..0ac3b9e80c 100644
--- a/net/net.c
+++ b/net/net.c
@@ -993,47 +993,47 @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp)
/* Map the old options to the new flat type */
switch (opts->type) {
- case NET_LEGACY_OPTIONS_KIND_NONE:
+ case NET_LEGACY_OPTIONS_TYPE_NONE:
return 0; /* nothing to do */
- case NET_LEGACY_OPTIONS_KIND_NIC:
+ case NET_LEGACY_OPTIONS_TYPE_NIC:
legacy.type = NET_CLIENT_DRIVER_NIC;
- legacy.u.nic = *opts->u.nic.data;
+ legacy.u.nic = opts->u.nic;
break;
- case NET_LEGACY_OPTIONS_KIND_USER:
+ case NET_LEGACY_OPTIONS_TYPE_USER:
legacy.type = NET_CLIENT_DRIVER_USER;
- legacy.u.user = *opts->u.user.data;
+ legacy.u.user = opts->u.user;
break;
- case NET_LEGACY_OPTIONS_KIND_TAP:
+ case NET_LEGACY_OPTIONS_TYPE_TAP:
legacy.type = NET_CLIENT_DRIVER_TAP;
- legacy.u.tap = *opts->u.tap.data;
+ legacy.u.tap = opts->u.tap;
break;
- case NET_LEGACY_OPTIONS_KIND_L2TPV3:
+ case NET_LEGACY_OPTIONS_TYPE_L2TPV3:
legacy.type = NET_CLIENT_DRIVER_L2TPV3;
- legacy.u.l2tpv3 = *opts->u.l2tpv3.data;
+ legacy.u.l2tpv3 = opts->u.l2tpv3;
break;
- case NET_LEGACY_OPTIONS_KIND_SOCKET:
+ case NET_LEGACY_OPTIONS_TYPE_SOCKET:
legacy.type = NET_CLIENT_DRIVER_SOCKET;
- legacy.u.socket = *opts->u.socket.data;
+ legacy.u.socket = opts->u.socket;
break;
- case NET_LEGACY_OPTIONS_KIND_VDE:
+ case NET_LEGACY_OPTIONS_TYPE_VDE:
legacy.type = NET_CLIENT_DRIVER_VDE;
- legacy.u.vde = *opts->u.vde.data;
+ legacy.u.vde = opts->u.vde;
break;
- case NET_LEGACY_OPTIONS_KIND_DUMP:
+ case NET_LEGACY_OPTIONS_TYPE_DUMP:
legacy.type = NET_CLIENT_DRIVER_DUMP;
- legacy.u.dump = *opts->u.dump.data;
+ legacy.u.dump = opts->u.dump;
break;
- case NET_LEGACY_OPTIONS_KIND_BRIDGE:
+ case NET_LEGACY_OPTIONS_TYPE_BRIDGE:
legacy.type = NET_CLIENT_DRIVER_BRIDGE;
- legacy.u.bridge = *opts->u.bridge.data;
+ legacy.u.bridge = opts->u.bridge;
break;
- case NET_LEGACY_OPTIONS_KIND_NETMAP:
+ case NET_LEGACY_OPTIONS_TYPE_NETMAP:
legacy.type = NET_CLIENT_DRIVER_NETMAP;
- legacy.u.netmap = *opts->u.netmap.data;
+ legacy.u.netmap = opts->u.netmap;
break;
- case NET_LEGACY_OPTIONS_KIND_VHOST_USER:
+ case NET_LEGACY_OPTIONS_TYPE_VHOST_USER:
legacy.type = NET_CLIENT_DRIVER_VHOST_USER;
- legacy.u.vhost_user = *opts->u.vhost_user.data;
+ legacy.u.vhost_user = opts->u.vhost_user;
break;
default:
abort();
@@ -1048,7 +1048,7 @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp)
/* Do not add to a vlan if it's a nic with a netdev= parameter. */
if (netdev->type != NET_CLIENT_DRIVER_NIC ||
- !opts->u.nic.data->has_netdev) {
+ !opts->u.nic.has_netdev) {
peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
}
diff --git a/numa.c b/numa.c
index 9f56be960f..e01cb547a2 100644
--- a/numa.c
+++ b/numa.c
@@ -228,8 +228,8 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
}
switch (object->type) {
- case NUMA_OPTIONS_KIND_NODE:
- numa_node_parse(object->u.node.data, opts, &err);
+ case NUMA_OPTIONS_TYPE_NODE:
+ numa_node_parse(&object->u.node, opts, &err);
if (err) {
goto end;
}
diff --git a/qapi-schema.json b/qapi-schema.json
index f6ca18c3be..150ee98e9e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3972,6 +3972,15 @@
'opts': 'NetLegacyOptions' } }
##
+# @NetLegacyOptionsType:
+#
+# Since: 1.2
+##
+{ 'enum': 'NetLegacyOptionsType',
+ 'data': ['none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde',
+ 'dump', 'bridge', 'netmap', 'vhost-user'] }
+
+##
# @NetLegacyOptions:
#
# Like Netdev, but for use only by the legacy command line options
@@ -3979,6 +3988,8 @@
# Since: 1.2
##
{ 'union': 'NetLegacyOptions',
+ 'base': { 'type': 'NetLegacyOptionsType' },
+ 'discriminator': 'type',
'data': {
'none': 'NetdevNoneOptions',
'nic': 'NetLegacyNicOptions',
@@ -5584,6 +5595,14 @@
'events' : [ 'InputEvent' ] } }
##
+# @NumaOptionsType:
+#
+# Since: 2.1
+##
+{ 'enum': 'NumaOptionsType',
+ 'data': [ 'node' ] }
+
+##
# @NumaOptions:
#
# A discriminated record of NUMA options. (for OptsVisitor)
@@ -5591,6 +5610,8 @@
# Since: 2.1
##
{ 'union': 'NumaOptions',
+ 'base': { 'type': 'NumaOptionsType' },
+ 'discriminator': 'type',
'data': {
'node': 'NumaNodeOptions' }}
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 505eb418ac..48bec2072b 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -28,14 +28,13 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
bool has_exec_key = false;
QDict *dict = NULL;
- if (qobject_type(request) != QTYPE_QDICT) {
+ dict = qobject_to_qdict(request);
+ if (!dict) {
error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT,
"request is not a dictionary");
return NULL;
}
- dict = qobject_to_qdict(request);
-
for (ent = qdict_first(dict); ent;
ent = qdict_next(dict, ent)) {
arg_name = qdict_entry_key(ent);
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 197b0fbd47..b0c5364506 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -178,20 +178,6 @@ size_t qdict_size(const QDict *qdict)
}
/**
- * qdict_get_obj(): Get a QObject of a specific type
- */
-static QObject *qdict_get_obj(const QDict *qdict, const char *key, QType type)
-{
- QObject *obj;
-
- obj = qdict_get(qdict, key);
- assert(obj != NULL);
- assert(qobject_type(obj) == type);
-
- return obj;
-}
-
-/**
* qdict_get_double(): Get an number mapped by 'key'
*
* This function assumes that 'key' exists and it stores a
@@ -241,25 +227,15 @@ bool qdict_get_bool(const QDict *qdict, const char *key)
}
/**
- * qdict_get_qlist(): Get the QList mapped by 'key'
- *
- * This function assumes that 'key' exists and it stores a
- * QList object.
- *
- * Return QList mapped by 'key'.
+ * qdict_get_qlist(): If @qdict maps @key to a QList, return it, else NULL.
*/
QList *qdict_get_qlist(const QDict *qdict, const char *key)
{
- return qobject_to_qlist(qdict_get_obj(qdict, key, QTYPE_QLIST));
+ return qobject_to_qlist(qdict_get(qdict, key));
}
/**
- * qdict_get_qdict(): Get the QDict mapped by 'key'
- *
- * This function assumes that 'key' exists and it stores a
- * QDict object.
- *
- * Return QDict mapped by 'key'.
+ * qdict_get_qdict(): If @qdict maps @key to a QDict, return it, else NULL.
*/
QDict *qdict_get_qdict(const QDict *qdict, const char *key)
{
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index 07b1c798d8..81162ee572 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -591,7 +591,6 @@ static void qdict_join_test(void)
static void qdict_crumple_test_recursive(void)
{
QDict *src, *dst, *rule, *vnc, *acl, *listen;
- QObject *child, *res;
QList *rules;
src = qdict_new();
@@ -605,40 +604,37 @@ static void qdict_crumple_test_recursive(void)
qdict_put(src, "vnc.acl..name", qstring_from_str("acl0"));
qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0"));
- res = qdict_crumple(src, &error_abort);
-
- g_assert_cmpint(qobject_type(res), ==, QTYPE_QDICT);
-
- dst = qobject_to_qdict(res);
-
+ dst = qobject_to_qdict(qdict_crumple(src, &error_abort));
+ g_assert(dst);
g_assert_cmpint(qdict_size(dst), ==, 1);
- child = qdict_get(dst, "vnc");
- g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT);
- vnc = qobject_to_qdict(child);
+ vnc = qdict_get_qdict(dst, "vnc");
+ g_assert(vnc);
+ g_assert_cmpint(qdict_size(vnc), ==, 3);
- child = qdict_get(vnc, "listen");
- g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT);
- listen = qobject_to_qdict(child);
+ listen = qdict_get_qdict(vnc, "listen");
+ g_assert(listen);
+ g_assert_cmpint(qdict_size(listen), ==, 2);
g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr"));
g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port"));
- child = qdict_get(vnc, "acl");
- g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT);
- acl = qobject_to_qdict(child);
+ acl = qdict_get_qdict(vnc, "acl");
+ g_assert(acl);
+ g_assert_cmpint(qdict_size(acl), ==, 3);
- child = qdict_get(acl, "rules");
- g_assert_cmpint(qobject_type(child), ==, QTYPE_QLIST);
- rules = qobject_to_qlist(child);
+ rules = qdict_get_qlist(acl, "rules");
+ g_assert(rules);
g_assert_cmpint(qlist_size(rules), ==, 2);
rule = qobject_to_qdict(qlist_pop(rules));
+ g_assert(rule);
g_assert_cmpint(qdict_size(rule), ==, 2);
g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match"));
g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy"));
QDECREF(rule);
rule = qobject_to_qdict(qlist_pop(rules));
+ g_assert(rule);
g_assert_cmpint(qdict_size(rule), ==, 2);
g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match"));
g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy"));
@@ -646,9 +642,6 @@ static void qdict_crumple_test_recursive(void)
/* With recursive crumpling, we should see all names unescaped */
g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name"));
- child = qdict_get(vnc, "acl");
- g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT);
- acl = qdict_get_qdict(vnc, "acl");
g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name"));
QDECREF(src);
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 0b21a22e10..e6d6935653 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -54,11 +54,8 @@ static void escaped_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded);
if (test_cases[i].skip == 0) {
@@ -89,11 +86,8 @@ static void simple_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
str = qobject_to_json(obj);
@@ -123,11 +117,8 @@ static void single_quote_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);
@@ -820,9 +811,8 @@ static void utf8_string(void)
obj = qobject_from_json(json_in);
if (utf8_out) {
- g_assert(obj);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
} else {
g_assert(!obj);
@@ -847,9 +837,8 @@ static void utf8_string(void)
*/
if (0 && json_out != json_in) {
obj = qobject_from_json(json_out);
- g_assert(obj);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
}
}
@@ -867,15 +856,11 @@ static void vararg_string(void)
};
for (i = 0; test_cases[i].decoded; i++) {
- QObject *obj;
QString *str;
- obj = qobject_from_jsonf("%s", test_cases[i].decoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
- str = qobject_to_qstring(obj);
+ str = qobject_to_qstring(qobject_from_jsonf("%s",
+ test_cases[i].decoded));
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);
@@ -899,19 +884,15 @@ static void simple_number(void)
};
for (i = 0; test_cases[i].encoded; i++) {
- QObject *obj;
QInt *qint;
- obj = qobject_from_json(test_cases[i].encoded);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QINT);
-
- qint = qobject_to_qint(obj);
+ qint = qobject_to_qint(qobject_from_json(test_cases[i].encoded));
+ g_assert(qint);
g_assert(qint_get_int(qint) == test_cases[i].decoded);
if (test_cases[i].skip == 0) {
QString *str;
- str = qobject_to_json(obj);
+ str = qobject_to_json(QOBJECT(qint));
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
QDECREF(str);
}
@@ -940,10 +921,8 @@ static void float_number(void)
QFloat *qfloat;
obj = qobject_from_json(test_cases[i].encoded);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QFLOAT);
-
qfloat = qobject_to_qfloat(obj);
+ g_assert(qfloat);
g_assert(qfloat_get_double(qfloat) == test_cases[i].decoded);
if (test_cases[i].skip == 0) {
@@ -960,38 +939,22 @@ static void float_number(void)
static void vararg_number(void)
{
- QObject *obj;
QInt *qint;
QFloat *qfloat;
int value = 0x2342;
long long value_ll = 0x2342342343LL;
double valuef = 2.323423423;
- obj = qobject_from_jsonf("%d", value);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QINT);
-
- qint = qobject_to_qint(obj);
+ qint = qobject_to_qint(qobject_from_jsonf("%d", value));
g_assert(qint_get_int(qint) == value);
-
QDECREF(qint);
- obj = qobject_from_jsonf("%lld", value_ll);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QINT);
-
- qint = qobject_to_qint(obj);
+ qint = qobject_to_qint(qobject_from_jsonf("%lld", value_ll));
g_assert(qint_get_int(qint) == value_ll);
-
QDECREF(qint);
- obj = qobject_from_jsonf("%f", valuef);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QFLOAT);
-
- qfloat = qobject_to_qfloat(obj);
+ qfloat = qobject_to_qfloat(qobject_from_jsonf("%f", valuef));
g_assert(qfloat_get_double(qfloat) == valuef);
-
QDECREF(qfloat);
}
@@ -1003,10 +966,8 @@ static void keyword_literal(void)
QString *str;
obj = qobject_from_json("true");
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
qbool = qobject_to_qbool(obj);
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
str = qobject_to_json(obj);
@@ -1016,10 +977,8 @@ static void keyword_literal(void)
QDECREF(qbool);
obj = qobject_from_json("false");
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
qbool = qobject_to_qbool(obj);
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == false);
str = qobject_to_json(obj);
@@ -1028,23 +987,15 @@ static void keyword_literal(void)
QDECREF(qbool);
- obj = qobject_from_jsonf("%i", false);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
- qbool = qobject_to_qbool(obj);
+ qbool = qobject_to_qbool(qobject_from_jsonf("%i", false));
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == false);
-
QDECREF(qbool);
/* Test that non-zero values other than 1 get collapsed to true */
- obj = qobject_from_jsonf("%i", 2);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
- qbool = qobject_to_qbool(obj);
+ qbool = qobject_to_qbool(qobject_from_jsonf("%i", 2));
+ g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
-
QDECREF(qbool);
obj = qobject_from_json("null");
@@ -1110,7 +1061,7 @@ static void compare_helper(QObject *obj, void *opaque)
static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
{
- if (lhs->type != qobject_type(rhs)) {
+ if (!rhs || lhs->type != qobject_type(rhs)) {
return 0;
}
@@ -1184,18 +1135,12 @@ static void simple_dict(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QDICT);
-
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
str = qobject_to_json(obj);
qobject_decref(obj);
obj = qobject_from_json(qstring_get_str(str));
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QDICT);
-
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
qobject_decref(obj);
QDECREF(str);
@@ -1299,18 +1244,12 @@ static void simple_list(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QLIST);
-
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
str = qobject_to_json(obj);
qobject_decref(obj);
obj = qobject_from_json(qstring_get_str(str));
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QLIST);
-
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
qobject_decref(obj);
QDECREF(str);
@@ -1367,18 +1306,12 @@ static void simple_whitespace(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QLIST);
-
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
str = qobject_to_json(obj);
qobject_decref(obj);
obj = qobject_from_json(qstring_get_str(str));
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QLIST);
-
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
qobject_decref(obj);
@@ -1403,8 +1336,6 @@ static void simple_varargs(void)
g_assert(embedded_obj != NULL);
obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
- g_assert(obj != NULL);
-
g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1);
qobject_decref(obj);
diff --git a/tests/libqtest.c b/tests/libqtest.c
index d8fba6647a..e54354de8a 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -379,9 +379,9 @@ static void qmp_response(JSONMessageParser *parser, GQueue *tokens)
exit(1);
}
- g_assert(qobject_type(obj) == QTYPE_QDICT);
g_assert(!qmp->response);
- qmp->response = (QDict *)obj;
+ qmp->response = qobject_to_qdict(obj);
+ g_assert(qmp->response);
}
QDict *qmp_fd_receive(int fd)
diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index 633dc87402..7bb621b027 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -95,24 +95,18 @@ static bool qdict_cmp_simple(QDict *a, QDict *b)
correctness. */
static void event_test_emit(test_QAPIEvent event, QDict *d, Error **errp)
{
- QObject *obj;
QDict *t;
int64_t s, ms;
/* Verify that we have timestamp, then remove it to compare other fields */
- obj = qdict_get(d, "timestamp");
- g_assert(obj);
- t = qobject_to_qdict(obj);
+ t = qdict_get_qdict(d, "timestamp");
g_assert(t);
- obj = qdict_get(t, "seconds");
- g_assert(obj && qobject_type(obj) == QTYPE_QINT);
- s = qint_get_int(qobject_to_qint(obj));
- obj = qdict_get(t, "microseconds");
- g_assert(obj && qobject_type(obj) == QTYPE_QINT);
- ms = qint_get_int(qobject_to_qint(obj));
+ s = qdict_get_try_int(t, "seconds", -2);
+ ms = qdict_get_try_int(t, "microseconds", -2);
if (s == -1) {
g_assert(ms == -1);
} else {
+ g_assert(s >= 0);
g_assert(ms >= 0 && ms <= 999999);
}
g_assert(qdict_size(t) == 2);
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index 4e2d79c5d1..500b452d98 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -58,81 +58,80 @@ static void test_visitor_out_int(TestOutputVisitorData *data,
const void *unused)
{
int64_t value = -42;
- QObject *obj;
+ QInt *qint;
visit_type_int(data->ov, NULL, &value, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QINT);
- g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value);
+ qint = qobject_to_qint(visitor_get(data));
+ g_assert(qint);
+ g_assert_cmpint(qint_get_int(qint), ==, value);
}
static void test_visitor_out_bool(TestOutputVisitorData *data,
const void *unused)
{
bool value = true;
- QObject *obj;
+ QBool *qbool;
visit_type_bool(data->ov, NULL, &value, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QBOOL);
- g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value);
+ qbool = qobject_to_qbool(visitor_get(data));
+ g_assert(qbool);
+ g_assert(qbool_get_bool(qbool) == value);
}
static void test_visitor_out_number(TestOutputVisitorData *data,
const void *unused)
{
double value = 3.14;
- QObject *obj;
+ QFloat *qfloat;
visit_type_number(data->ov, NULL, &value, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QFLOAT);
- g_assert(qfloat_get_double(qobject_to_qfloat(obj)) == value);
+ qfloat = qobject_to_qfloat(visitor_get(data));
+ g_assert(qfloat);
+ g_assert(qfloat_get_double(qfloat) == value);
}
static void test_visitor_out_string(TestOutputVisitorData *data,
const void *unused)
{
char *string = (char *) "Q E M U";
- QObject *obj;
+ QString *qstr;
visit_type_str(data->ov, NULL, &string, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string);
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, string);
}
static void test_visitor_out_no_string(TestOutputVisitorData *data,
const void *unused)
{
char *string = NULL;
- QObject *obj;
+ QString *qstr;
/* A null string should return "" */
visit_type_str(data->ov, NULL, &string, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, "");
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, "");
}
static void test_visitor_out_enum(TestOutputVisitorData *data,
const void *unused)
{
- QObject *obj;
EnumOne i;
+ QString *qstr;
for (i = 0; i < ENUM_ONE__MAX; i++) {
visit_type_EnumOne(data->ov, "unused", &i, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==,
- EnumOne_lookup[i]);
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_lookup[i]);
visitor_reset(data);
}
}
@@ -160,15 +159,12 @@ static void test_visitor_out_struct(TestOutputVisitorData *data,
.boolean = false,
.string = (char *) "foo"};
TestStruct *p = &test_struct;
- QObject *obj;
QDict *qdict;
visit_type_TestStruct(data->ov, NULL, &p, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QDICT);
-
- qdict = qobject_to_qdict(obj);
+ qdict = qobject_to_qdict(visitor_get(data));
+ g_assert(qdict);
g_assert_cmpint(qdict_size(qdict), ==, 3);
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false);
@@ -180,7 +176,6 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
{
int64_t value = 42;
UserDefTwo *ud2;
- QObject *obj;
QDict *qdict, *dict1, *dict2, *dict3, *userdef;
const char *string = "user def string";
const char *strings[] = { "forty two", "forty three", "forty four",
@@ -207,10 +202,8 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QDICT);
-
- qdict = qobject_to_qdict(obj);
+ qdict = qobject_to_qdict(visitor_get(data));
+ g_assert(qdict);
g_assert_cmpint(qdict_size(qdict), ==, 2);
g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]);
@@ -267,7 +260,6 @@ static void test_visitor_out_list(TestOutputVisitorData *data,
bool value_bool = true;
int value_int = 10;
QListEntry *entry;
- QObject *obj;
QList *qlist;
int i;
@@ -285,10 +277,8 @@ static void test_visitor_out_list(TestOutputVisitorData *data,
visit_type_TestStructList(data->ov, NULL, &head, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QLIST);
-
- qlist = qobject_to_qlist(obj);
+ qlist = qobject_to_qlist(visitor_get(data));
+ g_assert(qlist);
g_assert(!qlist_empty(qlist));
/* ...and ensure that the visitor sees it in order */
@@ -296,8 +286,8 @@ static void test_visitor_out_list(TestOutputVisitorData *data,
QLIST_FOREACH_ENTRY(qlist, entry) {
QDict *qdict;
- g_assert(qobject_type(entry->value) == QTYPE_QDICT);
qdict = qobject_to_qdict(entry->value);
+ g_assert(qdict);
g_assert_cmpint(qdict_size(qdict), ==, 3);
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i);
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool);
@@ -345,13 +335,12 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
QBool *qbool;
QString *qstring;
QDict *qdict;
- QObject *obj;
qobj = QOBJECT(qint_from_int(-42));
visit_type_any(data->ov, NULL, &qobj, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QINT);
- g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42);
+ qint = qobject_to_qint(visitor_get(data));
+ g_assert(qint);
+ g_assert_cmpint(qint_get_int(qint), ==, -42);
qobject_decref(qobj);
visitor_reset(data);
@@ -362,22 +351,15 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qobj = QOBJECT(qdict);
visit_type_any(data->ov, NULL, &qobj, &error_abort);
qobject_decref(qobj);
- obj = visitor_get(data);
- qdict = qobject_to_qdict(obj);
+ qdict = qobject_to_qdict(visitor_get(data));
g_assert(qdict);
- qobj = qdict_get(qdict, "integer");
- g_assert(qobj);
- qint = qobject_to_qint(qobj);
+ qint = qobject_to_qint(qdict_get(qdict, "integer"));
g_assert(qint);
g_assert_cmpint(qint_get_int(qint), ==, -42);
- qobj = qdict_get(qdict, "boolean");
- g_assert(qobj);
- qbool = qobject_to_qbool(qobj);
+ qbool = qobject_to_qbool(qdict_get(qdict, "boolean"));
g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
- qobj = qdict_get(qdict, "string");
- g_assert(qobj);
- qstring = qobject_to_qstring(qobj);
+ qstring = qobject_to_qstring(qdict_get(qdict, "string"));
g_assert(qstring);
g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
}
@@ -385,7 +367,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
static void test_visitor_out_union_flat(TestOutputVisitorData *data,
const void *unused)
{
- QObject *arg;
QDict *qdict;
UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
@@ -395,11 +376,8 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
tmp->u.value1.boolean = true;
visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort);
- arg = visitor_get(data);
-
- g_assert(qobject_type(arg) == QTYPE_QDICT);
- qdict = qobject_to_qdict(arg);
-
+ qdict = qobject_to_qdict(visitor_get(data));
+ g_assert(qdict);
g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1");
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41);
@@ -411,8 +389,9 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
static void test_visitor_out_alternate(TestOutputVisitorData *data,
const void *unused)
{
- QObject *arg;
UserDefAlternate *tmp;
+ QInt *qint;
+ QString *qstr;
QDict *qdict;
tmp = g_new0(UserDefAlternate, 1);
@@ -420,10 +399,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.i = 42;
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = visitor_get(data);
-
- g_assert(qobject_type(arg) == QTYPE_QINT);
- g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42);
+ qint = qobject_to_qint(visitor_get(data));
+ g_assert(qint);
+ g_assert_cmpint(qint_get_int(qint), ==, 42);
qapi_free_UserDefAlternate(tmp);
@@ -433,10 +411,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.s = g_strdup("hello");
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = visitor_get(data);
-
- g_assert(qobject_type(arg) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello");
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, "hello");
qapi_free_UserDefAlternate(tmp);
@@ -449,10 +426,8 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.udfu.u.value1.boolean = true;
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = visitor_get(data);
-
- g_assert_cmpint(qobject_type(arg), ==, QTYPE_QDICT);
- qdict = qobject_to_qdict(arg);
+ qdict = qobject_to_qdict(visitor_get(data));
+ g_assert(qdict);
g_assert_cmpint(qdict_size(qdict), ==, 4);
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 1);
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
@@ -465,7 +440,6 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
static void test_visitor_out_null(TestOutputVisitorData *data,
const void *unused)
{
- QObject *arg;
QDict *qdict;
QObject *nil;
@@ -473,9 +447,8 @@ static void test_visitor_out_null(TestOutputVisitorData *data,
visit_type_null(data->ov, "a", &error_abort);
visit_check_struct(data->ov, &error_abort);
visit_end_struct(data->ov, NULL);
- arg = visitor_get(data);
- g_assert(qobject_type(arg) == QTYPE_QDICT);
- qdict = qobject_to_qdict(arg);
+ qdict = qobject_to_qdict(visitor_get(data));
+ g_assert(qdict);
g_assert_cmpint(qdict_size(qdict), ==, 1);
nil = qdict_get(qdict, "a");
g_assert(nil);
@@ -618,8 +591,6 @@ static void check_native_list(QObject *qobj,
QList *qlist;
int i;
- g_assert(qobj);
- g_assert(qobject_type(qobj) == QTYPE_QDICT);
qdict = qobject_to_qdict(qobj);
g_assert(qdict);
g_assert(qdict_haskey(qdict, "data"));