diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-06-22 11:34:38 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-06-22 11:34:39 +0100 |
commit | 84e3d0725b06bdf8c6985788caa7776d6b7353ce (patch) | |
tree | e4b273590132a034fe693debb52e7037bb7730f2 /tests/test-qobject-output-visitor.c | |
parent | db7a99cdc1d0f4d8cbf7c41ce9e570dce04f0a11 (diff) | |
parent | 269c20b2bbd2aa8531e0cdc741fb166f290d7a2b (diff) | |
download | qemu-84e3d0725b06bdf8c6985788caa7776d6b7353ce.zip qemu-84e3d0725b06bdf8c6985788caa7776d6b7353ce.tar.gz qemu-84e3d0725b06bdf8c6985788caa7776d6b7353ce.tar.bz2 |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-06-09-v2' into staging
QAPI patches for 2017-06-09
# gpg: Signature made Tue 20 Jun 2017 13:31:39 BST
# 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-06-09-v2: (41 commits)
tests/qdict: check more get_try_int() cases
console: use get_uint() for "head" property
i386/cpu: use get_uint() for "min-level"/"min-xlevel" properties
numa: use get_uint() for "size" property
pnv-core: use get_uint() for "core-pir" property
pvpanic: use get_uint() for "ioport" property
auxbus: use get_uint() for "addr" property
arm: use get_uint() for "mp-affinity" property
xen: use get_uint() for "max-ram-below-4g" property
pc: use get_uint() for "hpet-intcap" property
pc: use get_uint() for "apic-id" property
pc: use get_uint() for "iobase" property
acpi: use get_uint() for "pci-hole*" properties
acpi: use get_uint() for various acpi properties
acpi: use get_uint() for "acpi-pcihp-io*" properties
platform-bus: use get_uint() for "addr" property
bcm2835_fb: use {get, set}_uint() for "vcram-size" and "vcram-base"
aspeed: use {set, get}_uint() for "ram-size" property
pcihp: use get_uint() for "bsel" property
pc-dimm: make "size" property uint64
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/test-qobject-output-visitor.c')
-rw-r--r-- | tests/test-qobject-output-visitor.c | 93 |
1 files changed, 59 insertions, 34 deletions
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c index 4e8fdf1..749c540 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -58,13 +58,15 @@ static void test_visitor_out_int(TestOutputVisitorData *data, const void *unused) { int64_t value = -42; - QInt *qint; + int64_t val; + QNum *qnum; visit_type_int(data->ov, NULL, &value, &error_abort); - qint = qobject_to_qint(visitor_get(data)); - g_assert(qint); - g_assert_cmpint(qint_get_int(qint), ==, value); + qnum = qobject_to_qnum(visitor_get(data)); + g_assert(qnum); + g_assert(qnum_get_try_int(qnum, &val)); + g_assert_cmpint(val, ==, value); } static void test_visitor_out_bool(TestOutputVisitorData *data, @@ -84,13 +86,13 @@ static void test_visitor_out_number(TestOutputVisitorData *data, const void *unused) { double value = 3.14; - QFloat *qfloat; + QNum *qnum; visit_type_number(data->ov, NULL, &value, &error_abort); - qfloat = qobject_to_qfloat(visitor_get(data)); - g_assert(qfloat); - g_assert(qfloat_get_double(qfloat) == value); + qnum = qobject_to_qnum(visitor_get(data)); + g_assert(qnum); + g_assert(qnum_get_double(qnum) == value); } static void test_visitor_out_string(TestOutputVisitorData *data, @@ -329,16 +331,18 @@ static void test_visitor_out_any(TestOutputVisitorData *data, const void *unused) { QObject *qobj; - QInt *qint; + QNum *qnum; QBool *qbool; QString *qstring; QDict *qdict; + int64_t val; - qobj = QOBJECT(qint_from_int(-42)); + qobj = QOBJECT(qnum_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); - qint = qobject_to_qint(visitor_get(data)); - g_assert(qint); - g_assert_cmpint(qint_get_int(qint), ==, -42); + qnum = qobject_to_qnum(visitor_get(data)); + g_assert(qnum); + g_assert(qnum_get_try_int(qnum, &val)); + g_assert_cmpint(val, ==, -42); qobject_decref(qobj); visitor_reset(data); @@ -351,9 +355,10 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobject_decref(qobj); qdict = qobject_to_qdict(visitor_get(data)); g_assert(qdict); - qint = qobject_to_qint(qdict_get(qdict, "integer")); - g_assert(qint); - g_assert_cmpint(qint_get_int(qint), ==, -42); + qnum = qobject_to_qnum(qdict_get(qdict, "integer")); + g_assert(qnum); + g_assert(qnum_get_try_int(qnum, &val)); + g_assert_cmpint(val, ==, -42); qbool = qobject_to_qbool(qdict_get(qdict, "boolean")); g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); @@ -388,18 +393,20 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { UserDefAlternate *tmp; - QInt *qint; + QNum *qnum; QString *qstr; QDict *qdict; + int64_t val; tmp = g_new0(UserDefAlternate, 1); - tmp->type = QTYPE_QINT; + tmp->type = QTYPE_QNUM; tmp->u.i = 42; visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qint = qobject_to_qint(visitor_get(data)); - g_assert(qint); - g_assert_cmpint(qint_get_int(qint), ==, 42); + qnum = qobject_to_qnum(visitor_get(data)); + g_assert(qnum); + g_assert(qnum_get_try_int(qnum, &val)); + g_assert_cmpint(val, ==, 42); qapi_free_UserDefAlternate(tmp); @@ -595,26 +602,44 @@ static void check_native_list(QObject *qobj, qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data"))); switch (kind) { - case USER_DEF_NATIVE_LIST_UNION_KIND_S8: - case USER_DEF_NATIVE_LIST_UNION_KIND_S16: - case USER_DEF_NATIVE_LIST_UNION_KIND_S32: - case USER_DEF_NATIVE_LIST_UNION_KIND_S64: case USER_DEF_NATIVE_LIST_UNION_KIND_U8: case USER_DEF_NATIVE_LIST_UNION_KIND_U16: case USER_DEF_NATIVE_LIST_UNION_KIND_U32: case USER_DEF_NATIVE_LIST_UNION_KIND_U64: - /* all integer elements in JSON arrays get stored into QInts when - * we convert to QObjects, so we can check them all in the same - * fashion, so simply fall through here + for (i = 0; i < 32; i++) { + QObject *tmp; + QNum *qvalue; + uint64_t val; + + tmp = qlist_peek(qlist); + g_assert(tmp); + qvalue = qobject_to_qnum(tmp); + g_assert(qnum_get_try_uint(qvalue, &val)); + g_assert_cmpint(val, ==, i); + qobject_decref(qlist_pop(qlist)); + } + break; + + case USER_DEF_NATIVE_LIST_UNION_KIND_S8: + case USER_DEF_NATIVE_LIST_UNION_KIND_S16: + case USER_DEF_NATIVE_LIST_UNION_KIND_S32: + case USER_DEF_NATIVE_LIST_UNION_KIND_S64: + /* + * All integer elements in JSON arrays get stored into QNums + * when we convert to QObjects, so we can check them all in + * the same fashion, so simply fall through here. */ case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: for (i = 0; i < 32; i++) { QObject *tmp; - QInt *qvalue; + QNum *qvalue; + int64_t val; + tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qint(tmp); - g_assert_cmpint(qint_get_int(qvalue), ==, i); + qvalue = qobject_to_qnum(tmp); + g_assert(qnum_get_try_int(qvalue, &val)); + g_assert_cmpint(val, ==, i); qobject_decref(qlist_pop(qlist)); } break; @@ -645,15 +670,15 @@ static void check_native_list(QObject *qobj, case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER: for (i = 0; i < 32; i++) { QObject *tmp; - QFloat *qvalue; + QNum *qvalue; GString *double_expected = g_string_new(""); GString *double_actual = g_string_new(""); tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qfloat(tmp); + qvalue = qobject_to_qnum(tmp); g_string_printf(double_expected, "%.6f", (double)i / 3); - g_string_printf(double_actual, "%.6f", qfloat_get_double(qvalue)); + g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue)); g_assert_cmpstr(double_actual->str, ==, double_expected->str); qobject_decref(qlist_pop(qlist)); |