[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 05/19] tests/test-qmp-event: Use qobject_is_equal()
From: |
Markus Armbruster |
Subject: |
[RFC PATCH 05/19] tests/test-qmp-event: Use qobject_is_equal() |
Date: |
Thu, 24 Oct 2019 14:34:44 +0200 |
Locally defined helper qdict_cmp_simple() implements just enough of a
comparison to serve here. Replace it by qobject_is_equal(), which
implements all of it.
Signed-off-by: Markus Armbruster <address@hidden>
---
tests/test-qmp-event.c | 66 +-----------------------------------------
1 file changed, 1 insertion(+), 65 deletions(-)
diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index 430001e622..d64066139c 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -28,73 +28,9 @@ typedef struct TestEventData {
QDict *expect;
} TestEventData;
-typedef struct QDictCmpData {
- QDict *expect;
- bool result;
-} QDictCmpData;
-
TestEventData *test_event_data;
static GMutex test_event_lock;
-/* Only compares bool, int, string */
-static
-void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque)
-
-{
- QObject *obj2;
- QDictCmpData d_new, *d = opaque;
- int64_t val1, val2;
-
- if (!d->result) {
- return;
- }
-
- obj2 = qdict_get(d->expect, key);
- if (!obj2) {
- d->result = false;
- return;
- }
-
- if (qobject_type(obj1) != qobject_type(obj2)) {
- d->result = false;
- return;
- }
-
- switch (qobject_type(obj1)) {
- case QTYPE_QBOOL:
- d->result = (qbool_get_bool(qobject_to(QBool, obj1)) ==
- qbool_get_bool(qobject_to(QBool, obj2)));
- return;
- case QTYPE_QNUM:
- g_assert(qnum_get_try_int(qobject_to(QNum, obj1), &val1));
- g_assert(qnum_get_try_int(qobject_to(QNum, obj2), &val2));
- d->result = val1 == val2;
- return;
- case QTYPE_QSTRING:
- d->result = g_strcmp0(qstring_get_str(qobject_to(QString, obj1)),
- qstring_get_str(qobject_to(QString, obj2))) == 0;
- return;
- case QTYPE_QDICT:
- d_new.expect = qobject_to(QDict, obj2);
- d_new.result = true;
- qdict_iter(qobject_to(QDict, obj1), qdict_cmp_do_simple, &d_new);
- d->result = d_new.result;
- return;
- default:
- abort();
- }
-}
-
-static bool qdict_cmp_simple(QDict *a, QDict *b)
-{
- QDictCmpData d;
-
- d.expect = b;
- d.result = true;
- qdict_iter(a, qdict_cmp_do_simple, &d);
- return d.result;
-}
-
void test_qapi_event_emit(test_QAPIEvent event, QDict *d)
{
QDict *t;
@@ -115,7 +51,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d)
qdict_del(d, "timestamp");
- g_assert(qdict_cmp_simple(d, test_event_data->expect));
+ g_assert(qobject_is_equal(QOBJECT(d), QOBJECT(test_event_data->expect)));
}
--
2.21.0
- [RFC PATCH 02/19] tests/test-qmp-cmds: Check responses more thoroughly, (continued)
- [RFC PATCH 02/19] tests/test-qmp-cmds: Check responses more thoroughly, Markus Armbruster, 2019/10/24
- [RFC PATCH 03/19] tests/test-qmp-cmds: Simplify test data setup, Markus Armbruster, 2019/10/24
- [RFC PATCH 04/19] tests/test-qmp-event: Simplify test data setup, Markus Armbruster, 2019/10/24
- [RFC PATCH 01/19] tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers, Markus Armbruster, 2019/10/24
- [RFC PATCH 12/19] qapi: Replace qmp_dispatch()'s TODO comment by an explanation, Markus Armbruster, 2019/10/24
- [RFC PATCH 15/19] qapi: Mark deprecated QMP commands with feature 'deprecated', Markus Armbruster, 2019/10/24
- [RFC PATCH 18/19] qapi: Include a warning in the response to a deprecated command, Markus Armbruster, 2019/10/24
- [RFC PATCH 19/19] qapi: Implement -compat deprecated-output=hide for events, Markus Armbruster, 2019/10/24
- [RFC PATCH 17/19] qapi: Implement -compat deprecated-input=crash for commands, Markus Armbruster, 2019/10/24
- [RFC PATCH 13/19] qapi: New special feature flag "deprecated", Markus Armbruster, 2019/10/24
- [RFC PATCH 05/19] tests/test-qmp-event: Use qobject_is_equal(),
Markus Armbruster <=
- [RFC PATCH 14/19] qemu-options: New -compat to set policy for "funny" interfaces, Markus Armbruster, 2019/10/24
- [RFC PATCH 09/19] qapi: Inline do_qmp_dispatch() into qmp_dispatch(), Markus Armbruster, 2019/10/24
- [RFC PATCH 11/19] qapi: Simplify how qmp_dispatch() gets the request ID, Markus Armbruster, 2019/10/24
- [RFC PATCH 16/19] qapi: Implement -compat deprecated-input=reject for commands, Markus Armbruster, 2019/10/24
- [RFC PATCH 06/19] tests/test-qmp-event: Check event is actually emitted, Markus Armbruster, 2019/10/24
- [RFC PATCH 10/19] qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP, Markus Armbruster, 2019/10/24
- [RFC PATCH 08/19] qapi: Consistently put @features parameter right after @ifcond, Markus Armbruster, 2019/10/24
- [RFC PATCH 07/19] qapi: Add feature flags to remaining definitions, Markus Armbruster, 2019/10/24