diff options
author | Markus Armbruster | 2020-12-10 17:14:44 +0100 |
---|---|---|
committer | Markus Armbruster | 2020-12-19 10:37:16 +0100 |
commit | 1a68eb8c186d81a2836bd1e9abd03c0b39f252e9 (patch) | |
tree | fed847430010d104631523035cbb70735ed4822a /tests | |
parent | tests/check-qjson: Don't skip funny QNumber to JSON conversions (diff) | |
download | qemu-1a68eb8c186d81a2836bd1e9abd03c0b39f252e9.tar.gz qemu-1a68eb8c186d81a2836bd1e9abd03c0b39f252e9.tar.xz qemu-1a68eb8c186d81a2836bd1e9abd03c0b39f252e9.zip |
tests/check-qjson: Examine QNum more thoroughly
simple_number() checks only qnum_get_try_int(). Also check
qnum_get_try_uint() and qnum_get_double().
float_number() checks only qnum_get_double(). Also check
qnum_get_try_int() and qnum_get_try_uint().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201210161452.2813491-3-armbru@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check-qjson.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 2a5852904a..6ab6b111b0 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -807,7 +807,8 @@ static void simple_number(void) }; int i; QNum *qnum; - int64_t val; + int64_t ival; + uint64_t uval; QString *str; for (i = 0; test_cases[i].encoded; i++) { @@ -815,8 +816,16 @@ static void simple_number(void) qobject_from_json(test_cases[i].encoded, &error_abort)); g_assert(qnum); - g_assert(qnum_get_try_int(qnum, &val)); - g_assert_cmpint(val, ==, test_cases[i].decoded); + g_assert(qnum_get_try_int(qnum, &ival)); + g_assert_cmpint(ival, ==, test_cases[i].decoded); + if (test_cases[i].decoded >= 0) { + g_assert(qnum_get_try_uint(qnum, &uval)); + g_assert_cmpuint(uval, ==, (uint64_t)test_cases[i].decoded); + } else { + g_assert(!qnum_get_try_uint(qnum, &uval)); + } + g_assert_cmpfloat(qnum_get_double(qnum), ==, + (double)test_cases[i].decoded); str = qobject_to_json(QOBJECT(qnum)); g_assert_cmpstr(qstring_get_str(str), ==, @@ -885,6 +894,8 @@ static void float_number(void) }; int i; QNum *qnum; + int64_t ival; + uint64_t uval; QString *str; for (i = 0; test_cases[i].encoded; i++) { @@ -893,6 +904,8 @@ static void float_number(void) &error_abort)); g_assert(qnum); g_assert_cmpfloat(qnum_get_double(qnum), ==, test_cases[i].decoded); + g_assert(!qnum_get_try_int(qnum, &ival)); + g_assert(!qnum_get_try_uint(qnum, &uval)); str = qobject_to_json(QOBJECT(qnum)); g_assert_cmpstr(qstring_get_str(str), ==, |