From edec095cf80b62057116ce75c581b5ca5866bdcc Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 21 Oct 2019 10:26:45 +0200 Subject: Fix 64-bit integer support in QtJSON Fixes parsing writing and pass-through of integers with higher precision than double can handle. Note this adds extra precision compared to JavaScript, but the JSON files read and written this way are still valid, and the extra precision in reading and writing this way is used by many JSON libraries. Fixes: QTBUG-28560 Change-Id: I30b2415c928d1c34c8cb4e4c6218602095e7e8aa Reviewed-by: Thiago Macieira --- .../serialization/qcborvalue_json/tst_qcborvalue_json.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp') diff --git a/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp b/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp index 56245a7173..76f2bb924a 100644 --- a/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp +++ b/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp @@ -97,9 +97,12 @@ void tst_QCborValue_Json::toVariant_data() add(1, 1, 1); add(-1, -1, -1); add(0., 0., 0.); + add(2., 2., 2.); add(1.25, 1.25, 1.25); add(-1.25, -1.25, -1.25); add("Hello", "Hello", "Hello"); + add(std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()); + add(std::numeric_limits::min(), std::numeric_limits::min(), std::numeric_limits::min()); // converts to string in JSON: add(QByteArray("Hello"), QByteArray("Hello"), "SGVsbG8"); @@ -123,14 +126,6 @@ void tst_QCborValue_Json::toVariant_data() << QVariant(qQNaN()) << QJsonValue(); - // large integral values lose precision in JSON - QTest::newRow("Integer:max") << QCborValue(std::numeric_limits::max()) - << QVariant(std::numeric_limits::max()) - << QJsonValue(std::numeric_limits::max()); - QTest::newRow("Integer:min") << QCborValue(std::numeric_limits::min()) - << QVariant(std::numeric_limits::min()) - << QJsonValue(std::numeric_limits::min()); - // empty arrays and maps add(QCborArray(), QVariantList(), QJsonArray()); add(QCborMap(), QVariantMap(), QJsonObject()); @@ -257,6 +252,10 @@ void tst_QCborValue_Json::fromJson_data() QTest::newRow("0") << QCborValue(0) << QJsonValue(0.); QTest::newRow("1") << QCborValue(1) << QJsonValue(1); QTest::newRow("1.5") << QCborValue(1.5) << QJsonValue(1.5); + QTest::newRow("Integer:max") << QCborValue(std::numeric_limits::max()) + << QJsonValue(std::numeric_limits::max()); + QTest::newRow("Integer:min") << QCborValue(std::numeric_limits::min()) + << QJsonValue(std::numeric_limits::min()); QTest::newRow("string") << QCborValue("Hello") << QJsonValue("Hello"); QTest::newRow("array") << QCborValue(QCborValue::Array) << QJsonValue(QJsonValue::Array); QTest::newRow("map") << QCborValue(QCborValue::Map) << QJsonValue(QJsonValue::Object); -- cgit v1.2.3