From d00341af384665d259af475b14c96bb8414df415 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 1 Dec 2015 22:20:51 -0700 Subject: qapi: Fix alternates that accept 'number' but not 'int' The QMP input visitor allows integral values to be assigned by promotion to a QTYPE_QFLOAT. However, when parsing an alternate, we did not take this into account, such that an alternate that accepts 'number' and some other type, but not 'int', would reject integral values. With this patch, we now have the following desirable table: alternate has case selected for 'int' 'number' QTYPE_QINT QTYPE_QFLOAT no no error error no yes 'number' 'number' yes no 'int' error yes yes 'int' 'number' While it is unlikely that we will ever use 'number' in an alternate other than in the testsuite, it never hurts to be more precise in what we allow. Signed-off-by: Eric Blake Message-Id: <1449033659-25497-8-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/test-qmp-input-visitor.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c index 43b9e18912..b4a5bee6a5 100644 --- a/tests/test-qmp-input-visitor.c +++ b/tests/test-qmp-input-visitor.c @@ -347,20 +347,16 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data, error_free_or_abort(&err); qapi_free_AltStrBool(asb); - /* FIXME: integer should parse as number */ v = visitor_input_test_init(data, "42"); - visit_type_AltStrNum(v, &asn, NULL, &err); - /* FIXME g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); */ - /* FIXME g_assert_cmpfloat(asn->u.n, ==, 42); */ - error_free_or_abort(&err); + visit_type_AltStrNum(v, &asn, NULL, &error_abort); + g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); + g_assert_cmpfloat(asn->u.n, ==, 42); qapi_free_AltStrNum(asn); - /* FIXME: integer should parse as number */ v = visitor_input_test_init(data, "42"); - visit_type_AltNumStr(v, &ans, NULL, &err); - /* FIXME g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); */ - /* FIXME g_assert_cmpfloat(ans->u.n, ==, 42); */ - error_free_or_abort(&err); + visit_type_AltNumStr(v, &ans, NULL, &error_abort); + g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); + g_assert_cmpfloat(ans->u.n, ==, 42); qapi_free_AltNumStr(ans); v = visitor_input_test_init(data, "42"); -- cgit v1.2.3-55-g7522