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>
This commit is contained in:
Marc Mutz 2023-08-15 09:23:15 +02:00
parent 003aa16e92
commit 8ca319a172

View File

@ -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<quint64>("seedValue");
QTest::addColumn<uint>("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()