diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-12-10 17:14:45 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-12-19 10:37:16 +0100 |
commit | 4aea88335d5c824b7b63b73c12830b5db558d463 (patch) | |
tree | 5632e9bf6749d66557a5a29e8ec82f22a00e7c2e /tests | |
parent | 1a68eb8c186d81a2836bd1e9abd03c0b39f252e9 (diff) |
tests/check-qjson: Cover number 2^63
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201210161452.2813491-4-armbru@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check-qjson.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 6ab6b111b0..8cb8a40524 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -791,7 +791,7 @@ static void utf8_string(void) } } -static void simple_number(void) +static void int_number(void) { struct { const char *encoded; @@ -836,6 +836,42 @@ static void simple_number(void) } } +static void uint_number(void) +{ + struct { + const char *encoded; + uint64_t decoded; + const char *reencoded; + } test_cases[] = { + { "9223372036854775808", (uint64_t)1 << 63 }, + {}, + }; + int i; + QNum *qnum; + int64_t ival; + uint64_t uval; + QString *str; + + for (i = 0; test_cases[i].encoded; i++) { + qnum = qobject_to(QNum, + qobject_from_json(test_cases[i].encoded, + &error_abort)); + g_assert(qnum); + g_assert(qnum_get_try_uint(qnum, &uval)); + g_assert_cmpuint(uval, ==, test_cases[i].decoded); + g_assert(!qnum_get_try_int(qnum, &ival)); + 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), ==, + test_cases[i].reencoded ?: test_cases[i].encoded); + qobject_unref(str); + + qobject_unref(qnum); + } +} + static void large_number(void) { const char *maxu64 = "18446744073709551615"; /* 2^64-1 */ @@ -1487,7 +1523,8 @@ int main(int argc, char **argv) g_test_add_func("/literals/string/quotes", string_with_quotes); g_test_add_func("/literals/string/utf8", utf8_string); - g_test_add_func("/literals/number/simple", simple_number); + g_test_add_func("/literals/number/int", int_number); + g_test_add_func("/literals/number/uint", uint_number); g_test_add_func("/literals/number/large", large_number); g_test_add_func("/literals/number/float", float_number); |