diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-01-14 18:08:11 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-01-19 20:57:41 -0800 |
commit | 69731bec5796beb53b5ab00388c7c21c6a01d822 (patch) | |
tree | d3822d1f6bef2183f1d8caa8a03ba7976d4fb8bb /tests/auto/corelib/serialization/json | |
parent | e3112bfa90872319f9ee2da2b50a524ebe159f8f (diff) |
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 <marc.mutz@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/corelib/serialization/json')
-rw-r--r-- | tests/auto/corelib/serialization/json/tst_qtjson.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
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<double>::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() |