Re: [Qemu-devel] [PATCH 06/14] test-qmp-event: Simplify and tighten event_test_emit()

2017-02-21 Thread Eric Blake
On 02/17/2017 02:38 PM, Markus Armbruster wrote:
> Use qdict_get_qdict() and qdict_get_try_int() to simplify.
> 
> While there, add a sanity check for seconds.
> 
> Signed-off-by: Markus Armbruster 
> ---
>  tests/test-qmp-event.c | 14 --
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 06/14] test-qmp-event: Simplify and tighten event_test_emit()

2017-02-17 Thread Markus Armbruster
Use qdict_get_qdict() and qdict_get_try_int() to simplify.

While there, add a sanity check for seconds.

Signed-off-by: Markus Armbruster 
---
 tests/test-qmp-event.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index 633dc87..7bb621b 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 <= 99);
 }
 g_assert(qdict_size(t) == 2);
-- 
2.7.4