From 8ca319a172b84207be404ed3bb619c3548a802da Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 15 Aug 2023 09:23:15 +0200 Subject: [PATCH] tst_QHashFunctions: test with actual 64-bit seeds The old code only tested with seed = 0 and seed = 1045982819, the latter being a "random number", which, however, fits into 32-bits. Since Qt 6.0 increased the seed from uint to size_t, amend the test to actually test a seed value with some of the upper half of bits set, too, also in 64-bit mode. While we're at it, also test with each seed's bits flipped for extra coverage. Remove a static assertion that prevented testing seeds with the MSB set. Pick-to: 6.6 6.5 6.2 Change-Id: I5ed6ffb5cabaaead0eb9c01f994d15dcbc622509 Reviewed-by: Thiago Macieira Reviewed-by: Ivan Solovev --- .../qhashfunctions/tst_qhashfunctions.cpp | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 700102f834..63fcfb99d0 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -17,11 +17,11 @@ class tst_QHashFunctions : public QObject { Q_OBJECT public: - enum { - // random value - RandomSeed = 1045982819 - }; - uint seed; + // random values + static constexpr quint64 ZeroSeed = 0; + static constexpr quint64 RandomSeed32 = 1045982819; + static constexpr quint64 RandomSeed64 = QtPrivate::QHashCombine{}(RandomSeed32, RandomSeed32); + size_t seed; template void stdPair_template(const T1 &t1, const T2 &t2); @@ -124,17 +124,23 @@ void tst_QHashFunctions::consistent() void tst_QHashFunctions::initTestCase() { - static_assert(int(RandomSeed) > 0); + QTest::addColumn("seedValue"); - QTest::addColumn("seedValue"); - QTest::newRow("zero-seed") << 0U; - QTest::newRow("non-zero-seed") << uint(RandomSeed); + QTest::newRow("zero-seed") << ZeroSeed; + QTest::newRow("zero-seed-negated") << ~ZeroSeed; + QTest::newRow("non-zero-seed-32bit") << RandomSeed32; + QTest::newRow("non-zero-seed-32bit-negated") + << quint64{~quint32(RandomSeed32)}; // ensure this->seed gets same value on 32/64-bit + if constexpr (sizeof(size_t) == sizeof(quint64)) { + QTest::newRow("non-zero-seed-64bit") << RandomSeed64; + QTest::newRow("non-zero-seed-64bit-negated") << ~RandomSeed64; + } } void tst_QHashFunctions::init() { - QFETCH_GLOBAL(uint, seedValue); - seed = seedValue; + QFETCH_GLOBAL(quint64, seedValue); + seed = size_t(seedValue); } void tst_QHashFunctions::qhash()