[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 09/34] tests/test-qmp-event: Use qobject_is_equal()
From: |
Marc-André Lureau |
Subject: |
Re: [PATCH v3 09/34] tests/test-qmp-event: Use qobject_is_equal() |
Date: |
Mon, 16 Mar 2020 16:13:13 +0100 |
On Sun, Mar 15, 2020 at 3:48 PM Markus Armbruster <address@hidden> wrote:
>
> 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>
Reviewed-by: Marc-André Lureau <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.1
>
>
--
Marc-André Lureau
- [PATCH v3 00/34] Configurable policy for handling deprecated interfaces, Markus Armbruster, 2020/03/15
- [PATCH v3 09/34] tests/test-qmp-event: Use qobject_is_equal(), Markus Armbruster, 2020/03/15
- Re: [PATCH v3 09/34] tests/test-qmp-event: Use qobject_is_equal(),
Marc-André Lureau <=
- [PATCH v3 03/34] docs/devel/qapi-code-gen: Clarify allow-oob introspection, Markus Armbruster, 2020/03/15
- [PATCH v3 06/34] tests/test-qmp-cmds: Check responses more thoroughly, Markus Armbruster, 2020/03/15
- [PATCH v3 10/34] tests/test-qmp-event: Check event is actually emitted, Markus Armbruster, 2020/03/15
- [PATCH v3 05/34] tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers, Markus Armbruster, 2020/03/15