From b057e32dc455d81f9378d6bd0c58888a7eddd155 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Fri, 19 Aug 2022 11:57:32 +0200 Subject: 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 --- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 23 ++++++++++++++++++---- .../tools/qhashfunctions/tst_qhashfunctions.cpp | 6 ++++++ tests/auto/corelib/tools/qset/tst_qset.cpp | 6 +++--- 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 5b51d6888d..5c0fbab406 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -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(); } }; diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index d060f50609..2d04579253 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -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" diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index e72bf34581..bd88c19bd0 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -1039,14 +1039,14 @@ void tst_QSet::qhash() // { // create some deterministic initial state: - qSetGlobalQHashSeed(0); + QHashSeed::setDeterministicGlobalSeed(); QSet s1; s1.reserve(4); s1 << 400 << 300 << 200 << 100; // also change the seed: - qSetGlobalQHashSeed(0x10101010); + QHashSeed::resetRandomGlobalSeed(); QSet 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 s3; s3 << 500; QVERIFY(!s1.intersects(s3)); -- cgit v1.2.3