From 69731bec5796beb53b5ab00388c7c21c6a01d822 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 14 Jan 2022 18:08:11 -0800 Subject: tst_QtJson: fix test for numbers above the limit of qint64 Commit 289f909621a8d83320d33e3ff7d651c164034098 ("Test conversion of ulonglong variant to JSON") was trying to ensure the result becomes a double. So there's no reason to make a test in the _data() function. Drive-by fix the UB condition on Windows (ulong is 32-bit, so 1ul << 63 is UB). Change-Id: I0e5f6bec596a4a78bd3bfffd16ca4f8f5219f785 Reviewed-by: Marc Mutz Reviewed-by: Sona Kurazyan --- tests/auto/corelib/serialization/json/tst_qtjson.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 3a57d3b8a5..d23f866690 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -3541,16 +3541,13 @@ void tst_QtJson::fromToVariantConversions_data() QTest::newRow("NaN") << QVariant(qQNaN()) << QJsonValue(QJsonValue::Null) << QVariant::fromValue(nullptr); - const qulonglong ulongValue = (1ul << 63) + 1; - const double uLongToDouble = ulongValue; - qint64 n; - if (convertDoubleTo(uLongToDouble, &n)) { - QTest::newRow("ulonglong") << QVariant(ulongValue) << QJsonValue(uLongToDouble) - << QVariant(n); - } else { - QTest::newRow("ulonglong") << QVariant(ulongValue) << QJsonValue(uLongToDouble) - << QVariant(uLongToDouble); - } + static_assert(std::numeric_limits::digits <= 63, + "double is too big on this platform, this test would fail"); + constexpr quint64 Threshold = Q_UINT64_C(1) << 63; + const qulonglong ulongValue = qulonglong(Threshold) + 1; + const double uLongToDouble = Threshold; + QTest::newRow("ulonglong") << QVariant(ulongValue) << QJsonValue(uLongToDouble) + << QVariant(uLongToDouble); } void tst_QtJson::fromToVariantConversions() -- cgit v1.2.3