[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/33] tests/check-qjson: Cover number 2^63
From: |
Markus Armbruster |
Subject: |
[PULL 06/33] tests/check-qjson: Cover number 2^63 |
Date: |
Sat, 19 Dec 2020 11:55:05 +0100 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201210161452.2813491-4-armbru@redhat.com>
---
tests/check-qjson.c | 41 +++++++++++++++++++++++++++++++++++++++--
1 file 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);
--
2.26.2
- [PULL 00/33] QAPI patches patches for 2020-12-19, Markus Armbruster, 2020/12/19
- [PULL 04/33] tests/check-qjson: Don't skip funny QNumber to JSON conversions, Markus Armbruster, 2020/12/19
- [PULL 01/33] rocker: Revamp fp_port_get_info, Markus Armbruster, 2020/12/19
- [PULL 11/33] string-output-visitor: Fix to use sufficient precision, Markus Armbruster, 2020/12/19
- [PULL 05/33] tests/check-qjson: Examine QNum more thoroughly, Markus Armbruster, 2020/12/19
- [PULL 09/33] qobject: Fix qnum_to_string() to use sufficient precision, Markus Armbruster, 2020/12/19
- [PULL 06/33] tests/check-qjson: Cover number 2^63,
Markus Armbruster <=
- [PULL 10/33] test-string-output-visitor: Cover "unround" number, Markus Armbruster, 2020/12/19
- [PULL 08/33] tests/check-qnum: Cover qnum_to_string() for "unround" argument, Markus Armbruster, 2020/12/19
- [PULL 12/33] test-visitor-serialization: Drop insufficient precision workaround, Markus Armbruster, 2020/12/19
- [PULL 07/33] tests/check-qjson: Replace redundant large_number(), Markus Armbruster, 2020/12/19
- [PULL 02/33] migration: Refactor migrate_cap_add, Markus Armbruster, 2020/12/19
- [PULL 26/33] qobject: Drop qstring_get_try_str(), Markus Armbruster, 2020/12/19
- [PULL 13/33] test-visitor-serialization: Clean up test_primitives(), Markus Armbruster, 2020/12/19
- [PULL 19/33] Revert "qstring: add qstring_free()", Markus Armbruster, 2020/12/19
- [PULL 16/33] qobject: Make qobject_to_json_pretty() take a pretty argument, Markus Armbruster, 2020/12/19
- [PULL 15/33] monitor: Use GString instead of QString for output buffer, Markus Armbruster, 2020/12/19