Port tests away from using q{Set}GlobalQHashSeed
These functions are marked as deprecated in future Qt releases. Task-number: QTBUG-104858 Change-Id: I25d2932455d8c9e3e2d722b1c48fc2cfa2d1e679 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
804172f23c
commit
b057e32dc4
@ -904,16 +904,31 @@ class QGlobalQHashSeedResetter
|
||||
int oldSeed;
|
||||
public:
|
||||
// not entirely correct (may lost changes made by another thread between the query
|
||||
// of the old and the setting of the new seed), but qSetGlobalQHashSeed doesn't
|
||||
// of the old and the setting of the new seed), but setHashSeed() can't
|
||||
// return the old value, so this is the best we can do:
|
||||
explicit QGlobalQHashSeedResetter(int newSeed)
|
||||
: oldSeed(qGlobalQHashSeed())
|
||||
: oldSeed(getHashSeed())
|
||||
{
|
||||
qSetGlobalQHashSeed(newSeed);
|
||||
setHashSeed(newSeed);
|
||||
}
|
||||
~QGlobalQHashSeedResetter()
|
||||
{
|
||||
qSetGlobalQHashSeed(oldSeed);
|
||||
setHashSeed(oldSeed);
|
||||
}
|
||||
|
||||
private:
|
||||
// The functions are implemented to replace the deprecated
|
||||
// qGlobalQHashSeed() and qSetGlobalQHashSeed()
|
||||
static int getHashSeed()
|
||||
{
|
||||
return int(QHashSeed::globalSeed() & INT_MAX);
|
||||
}
|
||||
static void setHashSeed(int seed)
|
||||
{
|
||||
if (seed == 0)
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
else
|
||||
QHashSeed::resetRandomGlobalSeed();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -53,7 +53,9 @@ private Q_SLOTS:
|
||||
void stdPair_string_pairIntInt() { stdPair_template(QString("Hello"), std::make_pair(42, -47)); } // QTBUG-92910
|
||||
void stdPair_int_pairIntPairIntInt() { stdPair_template(1, std::make_pair(2, std::make_pair(3, 4))); }
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
void setGlobalQHashSeed();
|
||||
#endif
|
||||
};
|
||||
|
||||
void tst_QHashFunctions::consistent()
|
||||
@ -370,8 +372,10 @@ void tst_QHashFunctions::stdPair_template(const T1 &t1, const T2 &t2)
|
||||
QCOMPARE(qHash(vpair, seed), qHash(vpair, seed));
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
void tst_QHashFunctions::setGlobalQHashSeed()
|
||||
{
|
||||
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
|
||||
// Setter works as advertised
|
||||
qSetGlobalQHashSeed(0);
|
||||
QCOMPARE(qGlobalQHashSeed(), 0);
|
||||
@ -384,7 +388,9 @@ void tst_QHashFunctions::setGlobalQHashSeed()
|
||||
// Reset works as advertised
|
||||
qSetGlobalQHashSeed(-1);
|
||||
QVERIFY(qGlobalQHashSeed() > 0);
|
||||
QT_WARNING_POP
|
||||
}
|
||||
#endif // QT_DEPRECATED_SINCE(6, 6)
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QHashFunctions)
|
||||
#include "tst_qhashfunctions.moc"
|
||||
|
@ -1039,14 +1039,14 @@ void tst_QSet::qhash()
|
||||
//
|
||||
{
|
||||
// create some deterministic initial state:
|
||||
qSetGlobalQHashSeed(0);
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
|
||||
QSet<int> s1;
|
||||
s1.reserve(4);
|
||||
s1 << 400 << 300 << 200 << 100;
|
||||
|
||||
// also change the seed:
|
||||
qSetGlobalQHashSeed(0x10101010);
|
||||
QHashSeed::resetRandomGlobalSeed();
|
||||
|
||||
QSet<int> s2;
|
||||
s2.reserve(100); // provoke different bucket counts
|
||||
@ -1087,7 +1087,7 @@ void tst_QSet::intersects()
|
||||
s1 << 200;
|
||||
QVERIFY(s1.intersects(s2));
|
||||
|
||||
qSetGlobalQHashSeed(0x10101010);
|
||||
QHashSeed::resetRandomGlobalSeed();
|
||||
QSet<int> s3;
|
||||
s3 << 500;
|
||||
QVERIFY(!s1.intersects(s3));
|
||||
|
@ -34,8 +34,8 @@ private slots:
|
||||
|
||||
void tst_QDBusXmlParser::initTestCase()
|
||||
{
|
||||
// Always initialize the hash seed to 0 to get reliable test results
|
||||
qSetGlobalQHashSeed(0);
|
||||
// Always initialize the hash seed with a known value to get reliable test results
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
}
|
||||
|
||||
void tst_QDBusXmlParser::parsing_data()
|
||||
|
@ -469,7 +469,8 @@ QTEST_MAIN(tst_Lancelot)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
|
||||
// Avoid rendering variations caused by QHash randomization
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
|
||||
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
||||
return _realmain(argc, argv);
|
||||
|
@ -198,7 +198,8 @@ QTEST_MAIN(tst_Stylesheet)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
|
||||
// Avoid rendering variations caused by QHash randomization
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
|
||||
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
||||
return _realmain(argc, argv);
|
||||
|
@ -88,7 +88,8 @@ QTEST_MAIN(tst_Text)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
|
||||
// Avoid rendering variations caused by QHash randomization
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
|
||||
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
||||
return _realmain(argc, argv);
|
||||
|
@ -1095,7 +1095,8 @@ QTEST_MAIN(tst_Widgets)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
|
||||
// Avoid rendering variations caused by QHash randomization
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
|
||||
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
||||
return _realmain(argc, argv);
|
||||
|
Loading…
Reference in New Issue
Block a user