mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-11 16:00:50 -07:00
qapi: merge QInt and QFloat in QNum
We would like to use a same QObject type to represent numbers, whether they are int, uint, or floats. Getters will allow some compatibility between the various types if the number fits other representations. Add a few more tests while at it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170607163635.17635-7-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [parse_stats_intervals() simplified a bit, comment in test_visitor_in_int_overflow() tidied up, suppress bogus warnings] Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
58634047b7
commit
01b2ffcedd
65 changed files with 630 additions and 664 deletions
|
|
@ -165,9 +165,10 @@ static void test_visitor_in_int_overflow(TestInputVisitorData *data,
|
|||
Error *err = NULL;
|
||||
Visitor *v;
|
||||
|
||||
/* this will overflow a Qint/int64, so should be deserialized into
|
||||
* a QFloat/double field instead, leading to an error if we pass it
|
||||
* to visit_type_int. confirm this.
|
||||
/*
|
||||
* This will overflow a QNUM_I64, so should be deserialized into a
|
||||
* QNUM_DOUBLE field instead, leading to an error if we pass it to
|
||||
* visit_type_int(). Confirm this.
|
||||
*/
|
||||
v = visitor_input_test_init(data, "%f", DBL_MAX);
|
||||
|
||||
|
|
@ -469,17 +470,19 @@ static void test_visitor_in_any(TestInputVisitorData *data,
|
|||
{
|
||||
QObject *res = NULL;
|
||||
Visitor *v;
|
||||
QInt *qint;
|
||||
QNum *qnum;
|
||||
QBool *qbool;
|
||||
QString *qstring;
|
||||
QDict *qdict;
|
||||
QObject *qobj;
|
||||
int64_t val;
|
||||
|
||||
v = visitor_input_test_init(data, "-42");
|
||||
visit_type_any(v, NULL, &res, &error_abort);
|
||||
qint = qobject_to_qint(res);
|
||||
g_assert(qint);
|
||||
g_assert_cmpint(qint_get_int(qint), ==, -42);
|
||||
qnum = qobject_to_qnum(res);
|
||||
g_assert(qnum);
|
||||
g_assert(qnum_get_try_int(qnum, &val));
|
||||
g_assert_cmpint(val, ==, -42);
|
||||
qobject_decref(res);
|
||||
|
||||
v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }");
|
||||
|
|
@ -488,9 +491,10 @@ static void test_visitor_in_any(TestInputVisitorData *data,
|
|||
g_assert(qdict && qdict_size(qdict) == 3);
|
||||
qobj = qdict_get(qdict, "integer");
|
||||
g_assert(qobj);
|
||||
qint = qobject_to_qint(qobj);
|
||||
g_assert(qint);
|
||||
g_assert_cmpint(qint_get_int(qint), ==, -42);
|
||||
qnum = qobject_to_qnum(qobj);
|
||||
g_assert(qnum);
|
||||
g_assert(qnum_get_try_int(qnum, &val));
|
||||
g_assert_cmpint(val, ==, -42);
|
||||
qobj = qdict_get(qdict, "boolean");
|
||||
g_assert(qobj);
|
||||
qbool = qobject_to_qbool(qobj);
|
||||
|
|
@ -568,7 +572,7 @@ static void test_visitor_in_alternate(TestInputVisitorData *data,
|
|||
|
||||
v = visitor_input_test_init(data, "42");
|
||||
visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
|
||||
g_assert_cmpint(tmp->type, ==, QTYPE_QINT);
|
||||
g_assert_cmpint(tmp->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpint(tmp->u.i, ==, 42);
|
||||
qapi_free_UserDefAlternate(tmp);
|
||||
|
||||
|
|
@ -596,7 +600,7 @@ static void test_visitor_in_alternate(TestInputVisitorData *data,
|
|||
|
||||
v = visitor_input_test_init(data, "{ 'alt': 42 }");
|
||||
visit_type_WrapAlternate(v, NULL, &wrap, &error_abort);
|
||||
g_assert_cmpint(wrap->alt->type, ==, QTYPE_QINT);
|
||||
g_assert_cmpint(wrap->alt->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpint(wrap->alt->u.i, ==, 42);
|
||||
qapi_free_WrapAlternate(wrap);
|
||||
|
||||
|
|
@ -637,19 +641,19 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
|
|||
|
||||
v = visitor_input_test_init(data, "42");
|
||||
visit_type_AltEnumNum(v, NULL, &aen, &error_abort);
|
||||
g_assert_cmpint(aen->type, ==, QTYPE_QFLOAT);
|
||||
g_assert_cmpint(aen->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpfloat(aen->u.n, ==, 42);
|
||||
qapi_free_AltEnumNum(aen);
|
||||
|
||||
v = visitor_input_test_init(data, "42");
|
||||
visit_type_AltNumEnum(v, NULL, &ans, &error_abort);
|
||||
g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT);
|
||||
g_assert_cmpint(ans->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpfloat(ans->u.n, ==, 42);
|
||||
qapi_free_AltNumEnum(ans);
|
||||
|
||||
v = visitor_input_test_init(data, "42");
|
||||
visit_type_AltEnumInt(v, NULL, &asi, &error_abort);
|
||||
g_assert_cmpint(asi->type, ==, QTYPE_QINT);
|
||||
g_assert_cmpint(asi->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpint(asi->u.i, ==, 42);
|
||||
qapi_free_AltEnumInt(asi);
|
||||
|
||||
|
|
@ -662,13 +666,13 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
|
|||
|
||||
v = visitor_input_test_init(data, "42.5");
|
||||
visit_type_AltEnumNum(v, NULL, &aen, &error_abort);
|
||||
g_assert_cmpint(aen->type, ==, QTYPE_QFLOAT);
|
||||
g_assert_cmpint(aen->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpfloat(aen->u.n, ==, 42.5);
|
||||
qapi_free_AltEnumNum(aen);
|
||||
|
||||
v = visitor_input_test_init(data, "42.5");
|
||||
visit_type_AltNumEnum(v, NULL, &ans, &error_abort);
|
||||
g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT);
|
||||
g_assert_cmpint(ans->type, ==, QTYPE_QNUM);
|
||||
g_assert_cmpfloat(ans->u.n, ==, 42.5);
|
||||
qapi_free_AltNumEnum(ans);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue