diff options
author | Liang Qi <liang.qi@qt.io> | 2017-04-20 11:19:14 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-04-20 12:31:27 +0200 |
commit | 7950b6b283549c98f1e0f981c84b68071a13b616 (patch) | |
tree | cf7281872045ebd57c68e10064ff0f400084aa13 /tests/auto/corelib/tools | |
parent | 58d2927861d3e57cac4f6db599e209d2bfb17a2c (diff) | |
parent | 0794d61c822585530243f638687b8a75f0a15d0c (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/corelib/tools/qbytearray.h
src/corelib/tools/qdatetime.h
src/corelib/tools/qstring.h
src/corelib/tools/qversionnumber.h
src/plugins/platforms/android/qandroidplatformintegration.cpp
tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
Change-Id: Iefd92a435e687a76cd593099e40d9a9620a1454d
Diffstat (limited to 'tests/auto/corelib/tools')
3 files changed, 124 insertions, 48 deletions
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index a8ea9ccf27..dbfcf57955 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -37,12 +37,23 @@ class tst_QHashFunctions : public QObject { Q_OBJECT +public: + enum { + // random value + RandomSeed = 1045982819 + }; + uint seed; + +public slots: + void initTestCase(); + void init(); + private Q_SLOTS: void consistent(); void qhash(); void qhash_of_empty_and_null_qstring(); void qhash_of_empty_and_null_qbytearray(); - void fp_qhash_of_zero_is_zero(); + void fp_qhash_of_zero_is_seed(); void qthash_data(); void qthash(); void range(); @@ -62,12 +73,27 @@ void tst_QHashFunctions::consistent() } } +void tst_QHashFunctions::initTestCase() +{ + Q_STATIC_ASSERT(int(RandomSeed) > 0); + + QTest::addColumn<uint>("seedValue"); + QTest::newRow("zero-seed") << 0U; + QTest::newRow("non-zero-seed") << uint(RandomSeed); +} + +void tst_QHashFunctions::init() +{ + QFETCH_GLOBAL(uint, seedValue); + seed = seedValue; +} + void tst_QHashFunctions::qhash() { { QBitArray a1; QBitArray a2; - QVERIFY(qHash(a1) == 0); + QCOMPARE(qHash(a1, seed), seed); a1.resize(1); a1.setBit(0, true); @@ -75,53 +101,53 @@ void tst_QHashFunctions::qhash() a2.resize(1); a2.setBit(0, false); - uint h1 = qHash(a1); - uint h2 = qHash(a2); + uint h1 = qHash(a1, seed); + uint h2 = qHash(a2, seed); - QVERIFY(h1 != h2); + QVERIFY(h1 != h2); // not guaranteed a2.setBit(0, true); - QVERIFY(h1 == qHash(a2)); + QVERIFY(h1 == qHash(a2, seed)); a1.fill(true, 8); a1.resize(7); - h1 = qHash(a1); + h1 = qHash(a1, seed); a2.fill(true, 7); - h2 = qHash(a2); + h2 = qHash(a2, seed); QVERIFY(h1 == h2); a2.setBit(0, false); - uint h3 = qHash(a2); - QVERIFY(h2 != h3); + uint h3 = qHash(a2, seed); + QVERIFY(h2 != h3); // not guaranteed a2.setBit(0, true); - QVERIFY(h2 == qHash(a2)); + QVERIFY(h2 == qHash(a2, seed)); a2.setBit(6, false); - uint h4 = qHash(a2); - QVERIFY(h2 != h4); + uint h4 = qHash(a2, seed); + QVERIFY(h2 != h4); // not guaranteed a2.setBit(6, true); - QVERIFY(h2 == qHash(a2)); + QVERIFY(h2 == qHash(a2, seed)); - QVERIFY(h3 != h4); + QVERIFY(h3 != h4); // not guaranteed } { QPair<int, int> p12(1, 2); QPair<int, int> p21(2, 1); - QVERIFY(qHash(p12) == qHash(p12)); - QVERIFY(qHash(p21) == qHash(p21)); - QVERIFY(qHash(p12) != qHash(p21)); + QVERIFY(qHash(p12, seed) == qHash(p12, seed)); + QVERIFY(qHash(p21, seed) == qHash(p21, seed)); + QVERIFY(qHash(p12, seed) != qHash(p21, seed)); // not guaranteed QPair<int, int> pA(0x12345678, 0x12345678); QPair<int, int> pB(0x12345675, 0x12345675); - QVERIFY(qHash(pA) != qHash(pB)); + QVERIFY(qHash(pA, seed) != qHash(pB, seed)); // not guaranteed } { @@ -130,14 +156,14 @@ void tst_QHashFunctions::qhash() using QT_PREPEND_NAMESPACE(qHash); - QVERIFY(qHash(p12) == qHash(p12)); - QVERIFY(qHash(p21) == qHash(p21)); - QVERIFY(qHash(p12) != qHash(p21)); + QVERIFY(qHash(p12, seed) == qHash(p12, seed)); + QVERIFY(qHash(p21, seed) == qHash(p21, seed)); + QVERIFY(qHash(p12, seed) != qHash(p21, seed)); // not guaranteed std::pair<int, int> pA(0x12345678, 0x12345678); std::pair<int, int> pB(0x12345675, 0x12345675); - QVERIFY(qHash(pA) != qHash(pB)); + QVERIFY(qHash(pA, seed) != qHash(pB, seed)); // not guaranteed } } @@ -145,35 +171,35 @@ void tst_QHashFunctions::qhash_of_empty_and_null_qstring() { QString null, empty(""); QCOMPARE(null, empty); - QCOMPARE(qHash(null), qHash(empty)); + QCOMPARE(qHash(null, seed), qHash(empty, seed)); QStringRef nullRef, emptyRef(&empty); QCOMPARE(nullRef, emptyRef); - QCOMPARE(qHash(nullRef), qHash(emptyRef)); + QCOMPARE(qHash(nullRef, seed), qHash(emptyRef, seed)); QStringView nullView, emptyView(empty); QCOMPARE(nullView, emptyView); - QCOMPARE(qHash(nullView), qHash(emptyView)); + QCOMPARE(qHash(nullView, seed), qHash(emptyView, seed)); } void tst_QHashFunctions::qhash_of_empty_and_null_qbytearray() { QByteArray null, empty(""); QCOMPARE(null, empty); - QCOMPARE(qHash(null), qHash(empty)); + QCOMPARE(qHash(null, seed), qHash(empty, seed)); } -void tst_QHashFunctions::fp_qhash_of_zero_is_zero() +void tst_QHashFunctions::fp_qhash_of_zero_is_seed() { - QCOMPARE(qHash(-0.0f), 0U); - QCOMPARE(qHash( 0.0f), 0U); + QCOMPARE(qHash(-0.0f, seed), seed); + QCOMPARE(qHash( 0.0f, seed), seed); - QCOMPARE(qHash(-0.0 ), 0U); - QCOMPARE(qHash( 0.0 ), 0U); + QCOMPARE(qHash(-0.0 , seed), seed); + QCOMPARE(qHash( 0.0 , seed), seed); #ifndef Q_OS_DARWIN - QCOMPARE(qHash(-0.0L), 0U); - QCOMPARE(qHash( 0.0L), 0U); + QCOMPARE(qHash(-0.0L, seed), seed); + QCOMPARE(qHash( 0.0L, seed), seed); #endif } @@ -208,10 +234,10 @@ void tst_QHashFunctions::range() static const size_t numInts = sizeof ints / sizeof *ints; // empty range just gives the seed: - QCOMPARE(qHashRange(ints, ints, 0xdeadbeefU), 0xdeadbeefU); - // verify that order matters: - QVERIFY(qHashRange(ints, ints + numInts) != - qHashRange(std::reverse_iterator<const int*>(ints + numInts), std::reverse_iterator<const int*>(ints))); + QCOMPARE(qHashRange(ints, ints, seed), seed); + // verify that order matters (test not guaranteed): + QVERIFY(qHashRange(ints, ints + numInts, seed) != + qHashRange(std::reverse_iterator<const int*>(ints + numInts), std::reverse_iterator<const int*>(ints), seed)); { // verify that the input iterator category suffices: @@ -220,13 +246,13 @@ void tst_QHashFunctions::range() std::copy(ints, ints + numInts, std::ostream_iterator<int>(sstream, " ")); sstream.seekg(0); std::istream_iterator<int> it(sstream), end; - QCOMPARE(qHashRange(ints, ints + numInts), qHashRange(it, end)); + QCOMPARE(qHashRange(ints, ints + numInts, seed), qHashRange(it, end, seed)); } SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}}; static const size_t numHashables = sizeof hashables / sizeof *hashables; // compile check: is qHash() found using ADL? - (void)qHashRange(hashables, hashables + numHashables); + (void)qHashRange(hashables, hashables + numHashables, seed); } void tst_QHashFunctions::rangeCommutative() @@ -235,10 +261,10 @@ void tst_QHashFunctions::rangeCommutative() static const size_t numInts = sizeof ints / sizeof *ints; // empty range just gives the seed: - QCOMPARE(qHashRangeCommutative(ints, ints, 0xdeadbeefU), 0xdeadbeefU); - // verify that order doesn't matter: - QCOMPARE(qHashRangeCommutative(ints, ints + numInts), - qHashRangeCommutative(std::reverse_iterator<int*>(ints + numInts), std::reverse_iterator<int*>(ints))); + QCOMPARE(qHashRangeCommutative(ints, ints, seed), seed); + // verify that order doesn't matter (test not guaranteed): + QCOMPARE(qHashRangeCommutative(ints, ints + numInts, seed), + qHashRangeCommutative(std::reverse_iterator<int*>(ints + numInts), std::reverse_iterator<int*>(ints), seed)); { // verify that the input iterator category suffices: @@ -246,13 +272,13 @@ void tst_QHashFunctions::rangeCommutative() std::copy(ints, ints + numInts, std::ostream_iterator<int>(sstream, " ")); sstream.seekg(0); std::istream_iterator<int> it(sstream), end; - QCOMPARE(qHashRangeCommutative(ints, ints + numInts), qHashRangeCommutative(it, end)); + QCOMPARE(qHashRangeCommutative(ints, ints + numInts, seed), qHashRangeCommutative(it, end, seed)); } SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}}; static const size_t numHashables = sizeof hashables / sizeof *hashables; // compile check: is qHash() found using ADL? - (void)qHashRangeCommutative(hashables, hashables + numHashables); + (void)qHashRangeCommutative(hashables, hashables + numHashables, seed); } void tst_QHashFunctions::setGlobalQHashSeed() diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index d0a0feb125..7850478602 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -97,6 +97,8 @@ private slots: void qvariantCast(); void sharedFromThis(); + void constructorThrow(); + void threadStressTest_data(); void threadStressTest(); void validConstructs(); @@ -2594,6 +2596,54 @@ void tst_QSharedPointer::sharedFromThis() QCOMPARE(Data::destructorCounter, destructions + 6); } +#ifndef QT_NO_EXCEPTIONS +class ThrowData: public Data +{ +public: + static int childDestructorCounter; + static int childGenerationCounter; + + ThrowData() + { + childGenerationCounter++; + throw QStringLiteral("Dummy exception"); + } + + ~ThrowData() + { + childDestructorCounter++; + } +}; +int ThrowData::childDestructorCounter = 0; +int ThrowData::childGenerationCounter = 0; +#endif // !QT_NO_EXCEPTIONS + +void tst_QSharedPointer::constructorThrow() +{ +#ifndef QT_NO_EXCEPTIONS + int generation = Data::generationCounter; + int destructorCounter = Data::destructorCounter; + + int childGeneration = ThrowData::childGenerationCounter; + int childDestructorCounter = ThrowData::childDestructorCounter; + + QSharedPointer<ThrowData> ptr; + QVERIFY_EXCEPTION_THROWN(ptr = QSharedPointer<ThrowData>::create(), QString); + QVERIFY(ptr.isNull()); + QCOMPARE(ThrowData::childGenerationCounter, childGeneration + 1); + // destructor should never be called, if a constructor throws + // an exception + QCOMPARE(ThrowData::childDestructorCounter, childDestructorCounter); + + QCOMPARE(Data::generationCounter, generation + 1); + // but base class constructor doesn't throw, so base class destructor + // should be called + QCOMPARE(Data::destructorCounter, destructorCounter + 1); +#else + QSKIP("Needs exceptions"); +#endif // !QT_NO_EXCEPTIONS +} + namespace ReentrancyWhileDestructing { struct IB { diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 4a82d952ab..70ccc72630 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -5850,7 +5850,7 @@ void tst_QString::fromUtf16_char16() void tst_QString::unicodeStrings() { -#ifdef Q_COMPILER_UNICODE_STRINGS +#ifdef Q_STDLIB_UNICODE_STRINGS QString s1, s2; static const std::u16string u16str1(u"Hello Unicode World"); static const std::u32string u32str1(U"Hello Unicode World"); @@ -5865,7 +5865,7 @@ void tst_QString::unicodeStrings() s1 = QString::fromStdU32String(std::u32string(U"\u221212\U000020AC\U00010000")); QCOMPARE(s1, QString::fromUtf8("\342\210\222" "12" "\342\202\254" "\360\220\200\200")); #else - QSKIP("Compiler does not support C++11 unicode strings"); + QSKIP("Standard Library does not support C++11 unicode strings"); #endif } |