tst_QtJson: fix test for numbers above the limit of qint64

Commit 289f909621 ("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>
bb10
Thiago Macieira 2022-01-14 18:08:11 -08:00
parent e3112bfa90
commit 69731bec57
1 changed files with 7 additions and 10 deletions

View File

@ -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()