From 01b2ffcedd94ad7b42bc870e4c6936c87ad03429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Jun 2017 20:35:58 +0400 Subject: qapi: merge QInt and QFloat in QNum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Message-Id: <20170607163635.17635-7-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [parse_stats_intervals() simplified a bit, comment in test_visitor_in_int_overflow() tidied up, suppress bogus warnings] Signed-off-by: Markus Armbruster --- tests/test-qobject-input-visitor.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'tests/test-qobject-input-visitor.c') diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c index 4dc9c03..6890ce5 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -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); -- cgit v1.1