summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-08-15 09:23:15 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-09-08 09:32:44 +0000
commit8ca319a172b84207be404ed3bb619c3548a802da (patch)
treeed100cff52f57868347989fa52f123a9a12967fd /tests/auto/corelib/tools
parent003aa16e92c74560315a9b897b0c3feca6c08a58 (diff)
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 <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp30
1 files changed, 18 insertions, 12 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 <typename T1, typename T2> 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<uint>("seedValue");
- QTest::newRow("zero-seed") << 0U;
- QTest::newRow("non-zero-seed") << uint(RandomSeed);
+ QTest::addColumn<quint64>("seedValue");
+
+ 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()