summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-01-23 17:32:00 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-01-23 23:38:27 +0100
commitf272c40697f399b6a105d0dddb8468e2d7789912 (patch)
treecfa896fab11a64c4a7030851c5421d22e3f65b72 /tests
parent6a1d9134b8c84bc4ab6e0cdbc1bb5624cb62f2c8 (diff)
tst_QSet: make qhash() test deterministic
Change-Id: I857e66f21030da2210122c8c95c95f05a73da50a Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index b8e23d3fae..30f7e3741d 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -973,18 +973,35 @@ QT_BEGIN_NAMESPACE
extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed; // from qhash.cpp
QT_END_NAMESPACE
+class QtQHashSeedSaver {
+ int oldSeed, newSeed;
+public:
+ explicit QtQHashSeedSaver(int seed)
+ : oldSeed(qt_qhash_seed.fetchAndStoreRelaxed(seed)),
+ newSeed(seed)
+ {}
+ ~QtQHashSeedSaver()
+ {
+ // only restore when no-one else changed the seed in the meantime:
+ qt_qhash_seed.testAndSetRelaxed(newSeed, oldSeed);
+ }
+};
+
void tst_QSet::qhash()
{
//
// check that sets containing the same elements hash to the same value
//
{
+ // create some deterministic initial state:
+ const QtQHashSeedSaver seed1(0);
+
QSet<int> s1;
s1.reserve(4);
s1 << 400 << 300 << 200 << 100;
// also change the seed:
- qt_qhash_seed = qt_qhash_seed + 0x9e3779b9;
+ const QtQHashSeedSaver seed2(0x10101010);
QSet<int> s2;
s2.reserve(100); // provoke different bucket counts