diff options
Diffstat (limited to 'tests/auto')
25 files changed, 719 insertions, 515 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 9f022b3b14..91733bea90 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2279,16 +2279,6 @@ void tst_QVariant::variantMap() QCOMPARE(qvariant_cast<QVariantMap>(v3).value("test").toInt(), 42); QCOMPARE(v, QVariant(v.toHash())); - - // multi-keys - map.insertMulti("test", 47); - v = map; - map2 = qvariant_cast<QVariantMap>(v); - QCOMPARE(map2, map); - map2 = v.toMap(); - QCOMPARE(map2, map); - - QCOMPARE(v, QVariant(v.toHash())); } void tst_QVariant::variantHash() @@ -2312,16 +2302,6 @@ void tst_QVariant::variantHash() QCOMPARE(qvariant_cast<QVariantHash>(v3).value("test").toInt(), 42); QCOMPARE(v, QVariant(v.toMap())); - - // multi-keys - hash.insertMulti("test", 47); - v = hash; - hash2 = qvariant_cast<QVariantHash>(v); - QCOMPARE(hash2, hash); - hash2 = v.toHash(); - QCOMPARE(hash2, hash); - - QCOMPARE(v, QVariant(v.toMap())); } class CustomQObject : public QObject { @@ -3063,7 +3043,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); - map.insertMulti("3", 5); + map.insert("4", 5); QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); } @@ -3073,7 +3053,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); - map.insertMulti("3", 5); + map.insert("4", 5); QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); } @@ -3083,7 +3063,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); - hash.insertMulti("3", 5); + hash.insert("4", 5); QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); } @@ -3093,7 +3073,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); - hash.insertMulti("3", 5); + hash.insert("4", 5); QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); } diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 29cff8b469..d1a77173c3 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -121,9 +121,15 @@ private slots: void stream_Map_data(); void stream_Map(); + void stream_MultiMap_data(); + void stream_MultiMap(); + void stream_Hash_data(); void stream_Hash(); + void stream_MultiHash_data(); + void stream_MultiHash(); + void stream_qint64_data(); void stream_qint64(); @@ -230,7 +236,9 @@ private: void writeQRegularExpression(QDataStream *dev); #endif void writeMap(QDataStream* dev); + void writeMultiMap(QDataStream* dev); void writeHash(QDataStream* dev); + void writeMultiHash(QDataStream* dev); void writeqint64(QDataStream *s); void writeQIcon(QDataStream *s); void writeQEasingCurve(QDataStream *s); @@ -262,7 +270,9 @@ private: void readQRegularExpression(QDataStream *s); #endif void readMap(QDataStream *s); + void readMultiMap(QDataStream *s); void readHash(QDataStream *s); + void readMultiHash(QDataStream *s); void readqint64(QDataStream *s); void readQIcon(QDataStream *s); void readQEasingCurve(QDataStream *s); @@ -650,16 +660,10 @@ static Map MapData(int index) map.insert(2, "bbb"); map.insert(3, "cccccc"); break; - case 2: - map.insert(1, "a"); - map.insert(2, "one"); - map.insertMulti(2, "two"); - map.insertMulti(2, "three"); - map.insert(3, "cccccc"); } return map; } -#define MAX_MAP_DATA 3 +#define MAX_MAP_DATA 2 void tst_QDataStream::stream_Map_data() { @@ -689,6 +693,60 @@ void tst_QDataStream::readMap(QDataStream *s) QCOMPARE(S, test); } +typedef QMultiMap<int, QString> MultiMap; + +static MultiMap MultiMapData(int index) +{ + MultiMap map; + + switch (index) { + case 0: + default: + break; + case 1: + map.insert(1, "a"); + map.insert(2, "bbb"); + map.insert(3, "cccccc"); + break; + case 2: + map.insert(1, "a"); + map.insert(2, "one"); + map.insert(2, "two"); + map.insert(2, "three"); + map.insert(3, "cccccc"); + } + return map; +} +#define MAX_MULTIMAP_DATA 3 + +void tst_QDataStream::stream_MultiMap_data() +{ + stream_data(MAX_MULTIMAP_DATA); +} + +void tst_QDataStream::stream_MultiMap() +{ + STREAM_IMPL(MultiMap); +} + +void tst_QDataStream::writeMultiMap(QDataStream* s) +{ + MultiMap test(MultiMapData(dataIndex(QTest::currentDataTag()))); + *s << test; + *s << test; +} + +void tst_QDataStream::readMultiMap(QDataStream *s) +{ + MultiMap S; + MultiMap test(MultiMapData(dataIndex(QTest::currentDataTag()))); + + *s >> S; + QCOMPARE(S, test); + *s >> S; + QCOMPARE(S, test); +} + // ************************************ typedef QHash<int, QString> Hash; @@ -706,16 +764,10 @@ static Hash HashData(int index) map.insert(2, "bbb"); map.insert(3, "cccccc"); break; - case 2: - map.insert(1, "a"); - map.insert(2, "one"); - map.insertMulti(2, "two"); - map.insertMulti(2, "three"); - map.insert(3, "cccccc"); } return map; } -#define MAX_HASH_DATA 3 +#define MAX_HASH_DATA 2 void tst_QDataStream::stream_Hash_data() { @@ -745,6 +797,60 @@ void tst_QDataStream::readHash(QDataStream *s) QCOMPARE(S, test); } +typedef QMultiHash<int, QString> MultiHash; + +static MultiHash MultiHashData(int index) +{ + MultiHash map; + + switch (index) { + case 0: + default: + break; + case 1: + map.insert(1, "a"); + map.insert(2, "bbb"); + map.insert(3, "cccccc"); + break; + case 2: + map.insert(1, "a"); + map.insert(2, "one"); + map.insert(2, "two"); + map.insert(2, "three"); + map.insert(3, "cccccc"); + } + return map; +} +#define MAX_MULTIHASH_DATA 3 + +void tst_QDataStream::stream_MultiHash_data() +{ + stream_data(MAX_HASH_DATA); +} + +void tst_QDataStream::stream_MultiHash() +{ + STREAM_IMPL(MultiHash); +} + +void tst_QDataStream::writeMultiHash(QDataStream* s) +{ + MultiHash test(MultiHashData(dataIndex(QTest::currentDataTag()))); + *s << test; + *s << test; +} + +void tst_QDataStream::readMultiHash(QDataStream *s) +{ + MultiHash S; + MultiHash test(MultiHashData(dataIndex(QTest::currentDataTag()))); + + *s >> S; + QCOMPARE(S, test); + *s >> S; + QCOMPARE(S, test); +} + // ************************************ static QEasingCurve QEasingCurveData(int index) diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 6381ce5ed0..6565924f58 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -2449,8 +2449,8 @@ void tst_QTextStream::generateRealNumbersDataWrite() QTest::newRow("0") << 0.0 << QByteArray("0") << QByteArray("0"); QTest::newRow("3.14") << 3.14 << QByteArray("3.14") << QByteArray("3.14"); QTest::newRow("-3.14") << -3.14 << QByteArray("-3.14") << QByteArray("-3.14"); - QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10") << QByteArray("1.2e+10"); - QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10") << QByteArray("-1.2e+10"); + QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10") << QByteArray("1.2E+10"); + QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10") << QByteArray("-1.2E+10"); QTest::newRow("12345") << 12345. << QByteArray("12345") << QByteArray("12,345"); } diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 7b2d92f9cb..f19b66be37 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -59,6 +59,7 @@ #endif Q_DECLARE_METATYPE(QLocale::FormatType) +Q_DECLARE_METATYPE(QStringView) class tst_QLocale : public QObject { @@ -95,6 +96,7 @@ private slots: void long_long_conversion_extra(); void testInfAndNan(); void fpExceptions(); + void negativeZero_data(); void negativeZero(); void dayOfWeek(); void dayOfWeek_data(); @@ -1060,8 +1062,8 @@ void tst_QLocale::doubleToString_data() QTest::newRow("de_DE 3,4 f 1") << QString("de_DE") << QString("3,4") << 3.4 << 'f' << 1; QTest::newRow("de_DE 3,4 f -") << QString("de_DE") << QString("3,4") << 3.4 << 'f' << shortest; - QTest::newRow("de_DE 3,4 e 1") << QString("de_DE") << QString("3,4e+00") << 3.4 << 'e' << 1; - QTest::newRow("de_DE 3,4 e -") << QString("de_DE") << QString("3,4e+00") << 3.4 << 'e' << shortest; + QTest::newRow("de_DE 3,4 e 1") << QString("de_DE") << QString("3,4E+00") << 3.4 << 'e' << 1; + QTest::newRow("de_DE 3,4 e -") << QString("de_DE") << QString("3,4E+00") << 3.4 << 'e' << shortest; QTest::newRow("de_DE 3,4 g 2") << QString("de_DE") << QString("3,4") << 3.4 << 'g' << 2; QTest::newRow("de_DE 3,4 g -") << QString("de_DE") << QString("3,4") << 3.4 << 'g' << shortest; @@ -1081,8 +1083,8 @@ void tst_QLocale::doubleToString_data() QTest::newRow("de_DE 0,035003945 f 9") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'f' << 9; QTest::newRow("de_DE 0,035003945 f -") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'f' << shortest; - QTest::newRow("de_DE 0,035003945 e 7") << QString("de_DE") << QString("3,5003945e-02") << 0.035003945 << 'e' << 7; - QTest::newRow("de_DE 0,035003945 e -") << QString("de_DE") << QString("3,5003945e-02") << 0.035003945 << 'e' << shortest; + QTest::newRow("de_DE 0,035003945 e 7") << QString("de_DE") << QString("3,5003945E-02") << 0.035003945 << 'e' << 7; + QTest::newRow("de_DE 0,035003945 e -") << QString("de_DE") << QString("3,5003945E-02") << 0.035003945 << 'e' << shortest; QTest::newRow("de_DE 0,035003945 g 8") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'g' << 8; QTest::newRow("de_DE 0,035003945 g -") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'g' << shortest; @@ -1102,10 +1104,10 @@ void tst_QLocale::doubleToString_data() QTest::newRow("de_DE 0,000003945 f 9") << QString("de_DE") << QString("0,000003945") << 0.000003945 << 'f' << 9; QTest::newRow("de_DE 0,000003945 f -") << QString("de_DE") << QString("0,000003945") << 0.000003945 << 'f' << shortest; - QTest::newRow("de_DE 0,000003945 e 3") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'e' << 3; - QTest::newRow("de_DE 0,000003945 e -") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'e' << shortest; - QTest::newRow("de_DE 0,000003945 g 4") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'g' << 4; - QTest::newRow("de_DE 0,000003945 g -") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'g' << shortest; + QTest::newRow("de_DE 0,000003945 e 3") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'e' << 3; + QTest::newRow("de_DE 0,000003945 e -") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'e' << shortest; + QTest::newRow("de_DE 0,000003945 g 4") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'g' << 4; + QTest::newRow("de_DE 0,000003945 g -") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'g' << shortest; QTest::newRow("C 12456789012 f 3") << QString("C") << QString("12456789012.000") << 12456789012.0 << 'f' << 3; QTest::newRow("C 12456789012 e 13") << QString("C") << QString("1.2456789012000e+10") << 12456789012.0 << 'e' << 13; @@ -1122,8 +1124,8 @@ void tst_QLocale::doubleToString_data() QTest::newRow("de_DE 12456789012 f 0") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'f' << 0; QTest::newRow("de_DE 12456789012 f -") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'f' << shortest; - QTest::newRow("de_DE 12456789012 e 10") << QString("de_DE") << QString("1,2456789012e+10") << 12456789012.0 << 'e' << 10; - QTest::newRow("de_DE 12456789012 e -") << QString("de_DE") << QString("1,2456789012e+10") << 12456789012.0 << 'e' << shortest; + QTest::newRow("de_DE 12456789012 e 10") << QString("de_DE") << QString("1,2456789012E+10") << 12456789012.0 << 'e' << 10; + QTest::newRow("de_DE 12456789012 e -") << QString("de_DE") << QString("1,2456789012E+10") << 12456789012.0 << 'e' << shortest; QTest::newRow("de_DE 12456789012 g 11") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'g' << 11; QTest::newRow("de_DE 12456789012 g -") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'g' << shortest; } @@ -1422,13 +1424,29 @@ void tst_QLocale::fpExceptions() #endif } +void tst_QLocale::negativeZero_data() +{ + QTest::addColumn<QLocale::Language>("language"); + QTest::addColumn<QLocale::Script>("script"); + QTest::addColumn<QLocale::Country>("territory"); + QTest::addColumn<QStringView>("expect"); + + QTest::newRow("C") + << QLocale::C << QLocale::AnyScript << QLocale::AnyCountry + << QStringView(u"0"); + QTest::newRow("Arabic") + << QLocale::Arabic << QLocale::ArabicScript << QLocale::AnyCountry + << QStringView(u"\u0660"); +} + void tst_QLocale::negativeZero() { - double negativeZero( 0.0 ); // Initialise to zero. - uchar *ptr = (uchar *)&negativeZero; - ptr[QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 7] = 0x80; - QString s = QString::number(negativeZero); - QCOMPARE(s, QString("0")); + QFETCH(QLocale::Language, language); + QFETCH(QLocale::Script, script); + QFETCH(QLocale::Country, territory); + QFETCH(QStringView, expect); + QLocale locale(language, script, territory); + QCOMPARE(locale.toString(std::copysign(0.0, -1.0)), expect); } void tst_QLocale::dayOfWeek_data() diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index e5b5e526de..ca58b664a0 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -4927,13 +4927,14 @@ void tst_QString::arg() void tst_QString::number() { - QCOMPARE( QString::number(int(0)), QLatin1String("0") ); - QCOMPARE( QString::number((unsigned int)(11)), QLatin1String("11") ); - QCOMPARE( QString::number(-22L), QLatin1String("-22") ); - QCOMPARE( QString::number(333UL), QLatin1String("333") ); - QCOMPARE( QString::number(4.4), QLatin1String("4.4") ); - QCOMPARE( QString::number(Q_INT64_C(-555)), QLatin1String("-555") ); - QCOMPARE( QString::number(Q_UINT64_C(6666)), QLatin1String("6666") ); + QCOMPARE(QString::number(int(0)), QLatin1String("0")); + QCOMPARE(QString::number(std::copysign(0.0, -1.0)), QLatin1String("0")); + QCOMPARE(QString::number((unsigned int)(11)), QLatin1String("11")); + QCOMPARE(QString::number(-22L), QLatin1String("-22")); + QCOMPARE(QString::number(333UL), QLatin1String("333")); + QCOMPARE(QString::number(4.4), QLatin1String("4.4")); + QCOMPARE(QString::number(Q_INT64_C(-555)), QLatin1String("-555")); + QCOMPARE(QString::number(Q_UINT64_C(6666)), QLatin1String("6666")); #ifndef QT_NO_DOUBLECONVERSION // snprintf_l is too stupid for this QCOMPARE( QString::number(12.05, 'f', 1), QString("12.1") ); diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 023b22b4ba..f319244bd3 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -1551,12 +1551,12 @@ void tst_Collections::hash() } { - QHash<int, QString> hash1, hash2; - hash1.insertMulti(1, "Alpha"); - hash1.insertMulti(1, "Gamma"); - hash2.insertMulti(1, "Beta"); - hash2.insertMulti(1, "Gamma"); - hash2.insertMulti(1, "Gamma"); + QMultiHash<int, QString> hash1, hash2; + hash1.insert(1, "Alpha"); + hash1.insert(1, "Gamma"); + hash2.insert(1, "Beta"); + hash2.insert(1, "Gamma"); + hash2.insert(1, "Gamma"); hash1.unite(hash2); QCOMPARE(hash1.size(), 5); @@ -1986,15 +1986,6 @@ void tst_Collections::qstring() QVERIFY(null.isNull()); QVERIFY(!nonNull.isNull()); -#if QT_DEPRECATED_SINCE(5, 9) - QVERIFY(null == QString::null); - QVERIFY(QString::null == null); - QVERIFY(nonNull != QString::null); - QVERIFY(QString::null != nonNull); - QVERIFY(null == nonNull); - QVERIFY(QString::null == QString::null); -#endif - QString fill = "123"; fill.fill('a'); QCOMPARE(fill, QLatin1String("aaa")); @@ -2710,8 +2701,10 @@ void testMapLikeStlIterators() QString t; fake.insert(k, t); - typename Container::iterator i1 = fake.begin(), i2 = i1 + 1; - typename Container::const_iterator c1 = i1, c2 = c1 + 1; + typename Container::iterator i1 = fake.begin(), i2 = i1; + ++i2; + typename Container::const_iterator c1 = i1, c2 = c1; + ++c2; QVERIFY(i1 == i1); QVERIFY(i1 == c1); @@ -2721,8 +2714,6 @@ void testMapLikeStlIterators() QVERIFY(i2 == c2); QVERIFY(c2 == i2); QVERIFY(c2 == c2); - QVERIFY(1 + i1 == i1 + 1); - QVERIFY(1 + c1 == c1 + 1); QVERIFY(i1 != i2); QVERIFY(i1 != c2); @@ -2933,10 +2924,6 @@ void instantiateMutableIterationContainer() it = container.begin(); it = container.end(); Q_UNUSED(it) - - // QSet lacks count(T). - const ValueType value = ValueType(); - container.count(value); } template <typename ContainerType, typename ValueType> @@ -2944,10 +2931,9 @@ void instantiateSequence() { instantiateMutableIterationContainer<ContainerType, ValueType>(); -// QVector lacks removeAll(T) -// ValueType value = ValueType(); -// ContainerType container; -// container.removeAll(value); + ValueType value = ValueType(); + ContainerType container; + container.removeAll(value); } template <typename ContainerType, typename ValueType> @@ -3020,11 +3006,10 @@ void instantiatePairAssociative() constContainer.keys(); container.remove(key); container.take(key); - container.unite(constContainer); + container.insert(constContainer); container.value(key); container.value(key, value); container.values(); - container.values(key); container[key]; const int foo = constContainer[key]; Q_UNUSED(foo); diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 91cd3eb0bd..4052eff0ae 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -451,20 +451,6 @@ void tst_QHash::insert1() QCOMPARE(hash.find(searchKey).value(), id01.id); // last-inserted value QCOMPARE(hash.find(searchKey).key().id, id00.id); // but first-inserted key } - { - QMultiHash<IdentityTracker, int> hash; - QCOMPARE(hash.size(), 0); - const int dummy = -1; - IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; - QCOMPARE(hash.insert(id00, id00.id).key().id, id00.id); - QCOMPARE(hash.size(), 1); - QCOMPARE(hash.insert(id01, id01.id).key().id, id01.id); - QCOMPARE(hash.size(), 2); - QMultiHash<IdentityTracker, int>::const_iterator pos = hash.constFind(searchKey); - QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with - ++pos; - QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with - } } void tst_QHash::erase() @@ -491,13 +477,15 @@ void tst_QHash::erase() ++n; } QVERIFY(n == 3); - QHash<int, int> h2; - h2.insertMulti(20, 41); - h2.insertMulti(20, 42); + + QMultiHash<int, int> h2; + h2.insert(20, 41); + h2.insert(20, 42); QVERIFY(h2.size() == 2); - it1 = h2.erase(h2.begin()); - it1 = h2.erase(h2.begin()); - QVERIFY(it1 == h2.end()); + auto bit = h2.begin(); + auto mit = h2.erase(bit); + mit = h2.erase(h2.begin()); + QVERIFY(mit == h2.end()); } void tst_QHash::key() @@ -631,14 +619,15 @@ void tst_QHash::find() QCOMPARE(map1.find(1).value(), QLatin1String("Mayer")); QCOMPARE(map1.find(2).value(), QLatin1String("Hej")); - for(i = 3; i < 10; ++i) { + QMultiHash<int, QString> multiMap(map1); + for (i = 3; i < 10; ++i) { compareString = testString.arg(i); - map1.insertMulti(4, compareString); + multiMap.insert(4, compareString); } - QHash<int, QString>::const_iterator it=map1.constFind(4); + auto it = multiMap.constFind(4); - for(i = 9; i > 2 && it != map1.constEnd() && it.key() == 4; --i) { + for (i = 9; i > 2 && it != multiMap.constEnd() && it.key() == 4; --i) { compareString = testString.arg(i); QVERIFY(it.value() == compareString); ++it; @@ -664,14 +653,15 @@ void tst_QHash::constFind() QCOMPARE(map1.constFind(1).value(), QLatin1String("Mayer")); QCOMPARE(map1.constFind(2).value(), QLatin1String("Hej")); - for(i = 3; i < 10; ++i) { + QMultiHash<int, QString> multiMap(map1); + for (i = 3; i < 10; ++i) { compareString = testString.arg(i); - map1.insertMulti(4, compareString); + multiMap.insert(4, compareString); } - QHash<int, QString>::const_iterator it=map1.constFind(4); + auto it = multiMap.constFind(4); - for(i = 9; i > 2 && it != map1.constEnd() && it.key() == 4; --i) { + for (i = 9; i > 2 && it != multiMap.constEnd() && it.key() == 4; --i) { compareString = testString.arg(i); QVERIFY(it.value() == compareString); ++it; @@ -689,9 +679,9 @@ void tst_QHash::contains() map1.insert(1, "one"); QVERIFY(map1.contains(1)); - for(i=2; i < 100; ++i) + for (i=2; i < 100; ++i) map1.insert(i, "teststring"); - for(i=99; i > 1; --i) + for (i=99; i > 1; --i) QVERIFY(map1.contains(i)); map1.remove(43); @@ -855,33 +845,33 @@ void tst_QHash::operator_eq() // regardless of insertion or iteration order { - QHash<int, int> a; - QHash<int, int> b; + QMultiHash<int, int> a; + QMultiHash<int, int> b; - a.insertMulti(0, 0); - a.insertMulti(0, 1); + a.insert(0, 0); + a.insert(0, 1); - b.insertMulti(0, 1); - b.insertMulti(0, 0); + b.insert(0, 1); + b.insert(0, 0); QVERIFY(a == b); QVERIFY(!(a != b)); } { - QHash<int, int> a; - QHash<int, int> b; + QMultiHash<int, int> a; + QMultiHash<int, int> b; enum { Count = 100 }; for (int key = 0; key < Count; ++key) { for (int value = 0; value < Count; ++value) - a.insertMulti(key, value); + a.insert(key, value); } for (int key = Count - 1; key >= 0; --key) { for (int value = 0; value < Count; ++value) - b.insertMulti(key, value); + b.insert(key, value); } QVERIFY(a == b); @@ -889,8 +879,8 @@ void tst_QHash::operator_eq() } { - QHash<int, int> a; - QHash<int, int> b; + QMultiHash<int, int> a; + QMultiHash<int, int> b; enum { Count = 100, @@ -900,7 +890,7 @@ void tst_QHash::operator_eq() for (int key = 0; key < Count; ++key) { for (int value = 0; value < Count; ++value) - a.insertMulti(key, value); + a.insert(key, value); } // Generates two permutations of [0, Count) for the keys and values, @@ -909,7 +899,7 @@ void tst_QHash::operator_eq() for (int k = 0; k < Count; ++k) { const int key = (k * KeyStep) % Count; for (int v = 0; v < Count; ++v) - b.insertMulti(key, (v * ValueStep) % Count); + b.insert(key, (v * ValueStep) % Count); } QVERIFY(a == b); @@ -923,10 +913,10 @@ void tst_QHash::compare() QString testString = "Teststring %1"; int i; - for(i = 0; i < 1000; ++i) + for (i = 0; i < 1000; ++i) hash1.insert(i,testString.arg(i)); - for(--i; i >= 0; --i) + for (--i; i >= 0; --i) hash2.insert(i,testString.arg(i)); hash1.squeeze(); @@ -947,39 +937,39 @@ void tst_QHash::compare() void tst_QHash::compare2() { - QHash<int, int> a; - QHash<int, int> b; + QMultiHash<int, int> a; + QMultiHash<int, int> b; - a.insertMulti(17, 1); - a.insertMulti(17 * 2, 1); - b.insertMulti(17 * 2, 1); - b.insertMulti(17, 1); + a.insert(17, 1); + a.insert(17 * 2, 1); + b.insert(17 * 2, 1); + b.insert(17, 1); QVERIFY(a == b); QVERIFY(b == a); - a.insertMulti(17, 2); - a.insertMulti(17 * 2, 3); - b.insertMulti(17 * 2, 3); - b.insertMulti(17, 2); + a.insert(17, 2); + a.insert(17 * 2, 3); + b.insert(17 * 2, 3); + b.insert(17, 2); QVERIFY(a == b); QVERIFY(b == a); - a.insertMulti(17, 4); - a.insertMulti(17 * 2, 5); - b.insertMulti(17 * 2, 4); - b.insertMulti(17, 5); + a.insert(17, 4); + a.insert(17 * 2, 5); + b.insert(17 * 2, 4); + b.insert(17, 5); QVERIFY(!(a == b)); QVERIFY(!(b == a)); a.clear(); b.clear(); - a.insertMulti(1, 1); - a.insertMulti(1, 2); - a.insertMulti(1, 3); - b.insertMulti(1, 1); - b.insertMulti(1, 2); - b.insertMulti(1, 3); - b.insertMulti(1, 4); + a.insert(1, 1); + a.insert(1, 2); + a.insert(1, 3); + b.insert(1, 1); + b.insert(1, 2); + b.insert(1, 3); + b.insert(1, 4); QVERIFY(!(a == b)); QVERIFY(!(b == a)); } @@ -993,7 +983,7 @@ void tst_QHash::iterators() QString testString1; int i; - for(i = 1; i < 100; ++i) + for (i = 1; i < 100; ++i) hash.insert(i, testString.arg(i)); //to get some chaos in the hash @@ -1010,18 +1000,13 @@ void tst_QHash::iterators() QVERIFY(stlIt.value() == testMap.value(1)); - stlIt+=5; + for (int i = 0; i < 5; ++i) + ++stlIt; QVERIFY(stlIt.value() == testMap.value(6)); stlIt++; QVERIFY(stlIt.value() == testMap.value(7)); - stlIt-=3; - QVERIFY(stlIt.value() == testMap.value(4)); - - stlIt--; - QVERIFY(stlIt.value() == testMap.value(3)); - testMap.clear(); //STL-Style const-iterators @@ -1035,18 +1020,13 @@ void tst_QHash::iterators() QVERIFY(cstlIt.value() == testMap.value(1)); - cstlIt+=5; + for (int i = 0; i < 5; ++i) + ++cstlIt; QVERIFY(cstlIt.value() == testMap.value(6)); cstlIt++; QVERIFY(cstlIt.value() == testMap.value(7)); - cstlIt-=3; - QVERIFY(cstlIt.value() == testMap.value(4)); - - cstlIt--; - QVERIFY(cstlIt.value() == testMap.value(3)); - testMap.clear(); //Java-Style iterators @@ -1068,14 +1048,7 @@ void tst_QHash::iterators() QVERIFY(javaIt.value() == testMap.value(i)); } - ++i; - while(javaIt.hasPrevious()) { - --i; - javaIt.previous(); - QVERIFY(javaIt.value() == testMap.value(i)); - } - - //peekNext() peekPrevious() + //peekNext() javaIt.toFront(); javaIt.next(); while(javaIt.hasNext()) { @@ -1083,14 +1056,6 @@ void tst_QHash::iterators() testString1 = javaIt.peekNext().value(); javaIt.next(); QVERIFY(javaIt.value() == testString1); - QCOMPARE(javaIt.peekPrevious().value(), testString1); - } - while(javaIt.hasPrevious()) { - testString = javaIt.value(); - testString1 = javaIt.peekPrevious().value(); - javaIt.previous(); - QVERIFY(javaIt.value() == testString1); - QCOMPARE(javaIt.peekNext().value(), testString1); } } @@ -1115,9 +1080,15 @@ void tst_QHash::keyIterator() QVERIFY(key_it != hash.keyEnd()); QCOMPARE(*key_it, it.key()); QCOMPARE(*(key_it++), (it++).key()); - QCOMPARE(*(key_it--), (it--).key()); - QCOMPARE(*(++key_it), (++it).key()); - QCOMPARE(*(--key_it), (--it).key()); + if (key_it != hash.keyEnd()) { + QVERIFY(it != hash.end()); + ++key_it; + ++it; + if (key_it != hash.keyEnd()) + QCOMPARE(*key_it, it.key()); + else + QVERIFY(it == hash.end()); + } QCOMPARE(std::count(hash.keyBegin(), hash.keyEnd(), 99), 1); @@ -1162,19 +1133,11 @@ void tst_QHash::keyValueIterator() ++it; ++key_value_it; - QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); - - --it; - --key_value_it; - QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); - - ++it; - ++key_value_it; - QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); + if (it != hash.end()) + QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); + else + QVERIFY(key_value_it == hash.constKeyValueEnd()); - --it; - --key_value_it; - QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); key = 99; value = 99 * 100; QCOMPARE(std::count(hash.constKeyValueBegin(), hash.constKeyValueEnd(), entry_type(key, value)), 1); @@ -1184,9 +1147,9 @@ void tst_QHash::rehash_isnt_quadratic() { // this test should be incredibly slow if rehash() is quadratic for (int j = 0; j < 5; ++j) { - QHash<int, int> testHash; + QMultiHash<int, int> testHash; for (int i = 0; i < 500000; ++i) - testHash.insertMulti(1, 1); + testHash.insert(1, 1); } } @@ -1330,27 +1293,27 @@ QList<T> sorted(const QList<T> &list) void tst_QHash::keys_values_uniqueKeys() { - QHash<QString, int> hash; + QMultiHash<QString, int> hash; QVERIFY(hash.uniqueKeys().isEmpty()); QVERIFY(hash.keys().isEmpty()); QVERIFY(hash.values().isEmpty()); - hash.insertMulti("alpha", 1); + hash.insert("alpha", 1); QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha")); QVERIFY(hash.keys() == hash.uniqueKeys()); QVERIFY(hash.values() == (QList<int>() << 1)); - hash.insertMulti("beta", -2); + hash.insert("beta", -2); QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "beta")); QVERIFY(hash.keys() == hash.uniqueKeys()); QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 1 << -2)); - hash.insertMulti("alpha", 2); + hash.insert("alpha", 2); QVERIFY(sorted(hash.uniqueKeys()) == (QList<QString>() << "alpha" << "beta")); QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "alpha" << "beta")); QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 2 << 1 << -2)); - hash.insertMulti("beta", 4); + hash.insert("beta", 4); QVERIFY(sorted(hash.uniqueKeys()) == (QList<QString>() << "alpha" << "beta")); QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "alpha" << "beta" << "beta")); QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 2 << 1 << 4 << -2)); @@ -1504,14 +1467,14 @@ void tst_QHash::initializerList() void tst_QHash::eraseValidIteratorOnSharedHash() { - QHash<int, int> a, b; + QMultiHash<int, int> a, b; a.insert(10, 10); - a.insertMulti(10, 25); - a.insertMulti(10, 30); + a.insert(10, 25); + a.insert(10, 30); a.insert(20, 20); a.insert(40, 40); - QHash<int, int>::iterator i = a.begin(); + auto i = a.begin(); while (i.value() != 25) ++i; @@ -1533,7 +1496,7 @@ void tst_QHash::eraseValidIteratorOnSharedHash() void tst_QHash::equal_range() { - QHash<int, QString> hash; + QMultiHash<int, QString> hash; auto result = hash.equal_range(0); QCOMPARE(result.first, hash.end()); @@ -1546,7 +1509,7 @@ void tst_QHash::equal_range() QCOMPARE(result.first, hash.find(1)); QVERIFY(std::distance(result.first, result.second) == 1); - QHash<int, int> h1; + QMultiHash<int, int> h1; { auto p = h1.equal_range(0); QVERIFY(p.first == p.second); @@ -1597,7 +1560,7 @@ void tst_QHash::equal_range() QVERIFY(p2.first == m1.begin() || p2.second == m1.end()); } - const QHash<int, int> ch1 = h1; + const QMultiHash<int, int> ch1 = h1; { auto p1 = ch1.equal_range(9); QVERIFY(p1.first == p1.second); @@ -1623,10 +1586,10 @@ void tst_QHash::equal_range() QVERIFY(p2.first == cm1.cbegin() || p2.second == cm1.cend()); } - QHash<int, int> h2; + QMultiHash<int, int> h2; for (int i = 0; i < 8; ++i) for (int j = 0; j < 8; ++j) - h2.insertMulti(i, i*j); + h2.insert(i, i*j); for (int i = 0; i < 8; ++i) { auto pair = h2.equal_range(i); @@ -1692,21 +1655,6 @@ void tst_QHash::insert_hash() QCOMPARE(hash[2], 5); QCOMPARE(hash[7], 55); } - { - // This will use a QMultiHash and then insert that into QHash, - // the ordering is undefined so we won't test that but make - // sure this isn't adding multiple entries with the same key - // to the QHash. - QHash<int, int> hash; - QMultiHash<int, int> hash2; - hash2.insert(0, 5); - hash2.insert(0, 6); - hash2.insert(0, 7); - - hash.insert(hash2); - - QCOMPARE(hash.count(), 1); - } } QTEST_APPLESS_MAIN(tst_QHash) diff --git a/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro b/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro index c8e6a8e05a..6c00f4f081 100644 --- a/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro +++ b/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro @@ -1,6 +1,5 @@ CONFIG += testcase TARGET = tst_qoffsetstringarray QT = core testlib core-private -CONFIG += c++11 CONFIG += strict_c++ SOURCES = $$PWD/tst_qoffsetstringarray.cpp diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 6638ad8b60..0ca8be7fa3 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -59,7 +59,6 @@ private slots: void begin(); void end(); void insert(); - void reverseIterators(); void setOperations(); void stlIterator(); void stlMutableIterator(); @@ -577,21 +576,6 @@ void tst_QSet::insert() } } -void tst_QSet::reverseIterators() -{ - QSet<int> s; - s << 1 << 17 << 61 << 127 << 911; - std::vector<int> v(s.begin(), s.end()); - std::reverse(v.begin(), v.end()); - const QSet<int> &cs = s; - QVERIFY(std::equal(v.begin(), v.end(), s.rbegin())); - QVERIFY(std::equal(v.begin(), v.end(), s.crbegin())); - QVERIFY(std::equal(v.begin(), v.end(), cs.rbegin())); - QVERIFY(std::equal(s.rbegin(), s.rend(), v.begin())); - QVERIFY(std::equal(s.crbegin(), s.crend(), v.begin())); - QVERIFY(std::equal(cs.rbegin(), cs.rend(), v.begin())); -} - void tst_QSet::setOperations() { QSet<QString> set1, set2; @@ -705,16 +689,6 @@ void tst_QSet::stlIterator() } QVERIFY(sum == 24999 * 25000 / 2); } - - { - int sum = 0; - QSet<QString>::const_iterator i = set1.end(); - while (i != set1.begin()) { - --i; - sum += toNumber(*i); - } - QVERIFY(sum == 24999 * 25000 / 2); - } } void tst_QSet::stlMutableIterator() @@ -734,21 +708,10 @@ void tst_QSet::stlMutableIterator() } { - int sum = 0; - QSet<QString>::iterator i = set1.end(); - while (i != set1.begin()) { - --i; - sum += toNumber(*i); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - - { QSet<QString> set2 = set1; QSet<QString> set3 = set2; QSet<QString>::iterator i = set2.begin(); - QSet<QString>::iterator j = set3.begin(); while (i != set2.end()) { i = set2.erase(i); @@ -756,24 +719,7 @@ void tst_QSet::stlMutableIterator() QVERIFY(set2.isEmpty()); QVERIFY(!set3.isEmpty()); - j = set3.end(); - while (j != set3.begin()) { - j--; - if (j + 1 != set3.end()) - set3.erase(j + 1); - } - if (set3.begin() != set3.end()) - set3.erase(set3.begin()); - - QVERIFY(set2.isEmpty()); - QVERIFY(set3.isEmpty()); - -// #if QT_VERSION >= 0x050000 -// i = set2.insert("foo"); -// #else - QSet<QString>::const_iterator k = set2.insert("foo"); - i = reinterpret_cast<QSet<QString>::iterator &>(k); -// #endif + i = set2.insert("foo"); QCOMPARE(*i, QLatin1String("foo")); } } @@ -802,47 +748,6 @@ void tst_QSet::javaIterator() QVERIFY(sum == 24999 * 25000 / 2); } - { - int sum = 0; - QSetIterator<QString> i(set1); - while (i.hasNext()) { - i.next(); - sum += toNumber(i.peekPrevious()); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - - { - int sum = 0; - QSetIterator<QString> i(set1); - i.toBack(); - while (i.hasPrevious()) - sum += toNumber(i.previous()); - QVERIFY(sum == 24999 * 25000 / 2); - } - - { - int sum = 0; - QSetIterator<QString> i(set1); - i.toBack(); - while (i.hasPrevious()) { - sum += toNumber(i.peekPrevious()); - i.previous(); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - - { - int sum = 0; - QSetIterator<QString> i(set1); - i.toBack(); - while (i.hasPrevious()) { - i.previous(); - sum += toNumber(i.peekNext()); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - int sum1 = 0; int sum2 = 0; QSetIterator<QString> i(set1); @@ -897,52 +802,10 @@ void tst_QSet::javaMutableIterator() } { - int sum = 0; - QMutableSetIterator<QString> i(set1); - while (i.hasNext()) { - i.next(); - sum += toNumber(i.peekPrevious()); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - - { - int sum = 0; - QMutableSetIterator<QString> i(set1); - i.toBack(); - while (i.hasPrevious()) - sum += toNumber(i.previous()); - QVERIFY(sum == 24999 * 25000 / 2); - } - - { - int sum = 0; - QMutableSetIterator<QString> i(set1); - i.toBack(); - while (i.hasPrevious()) { - sum += toNumber(i.peekPrevious()); - i.previous(); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - - { - int sum = 0; - QMutableSetIterator<QString> i(set1); - i.toBack(); - while (i.hasPrevious()) { - i.previous(); - sum += toNumber(i.peekNext()); - } - QVERIFY(sum == 24999 * 25000 / 2); - } - - { QSet<QString> set2 = set1; QSet<QString> set3 = set2; QMutableSetIterator<QString> i(set2); - QMutableSetIterator<QString> j(set3); while (i.hasNext()) { i.next(); @@ -950,14 +813,6 @@ void tst_QSet::javaMutableIterator() } QVERIFY(set2.isEmpty()); QVERIFY(!set3.isEmpty()); - - j.toBack(); - while (j.hasPrevious()) { - j.previous(); - j.remove(); - } - QVERIFY(set2.isEmpty()); - QVERIFY(set3.isEmpty()); } } diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index a9fd282ac9..8a621cd5d9 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -2155,7 +2155,7 @@ void tst_QSharedPointer::threadStressTest() } } -template<typename Container, bool Ordered> +template<typename Container, bool Ordered, bool Multi> void hashAndMapTest() { typedef typename Container::key_type Key; @@ -2200,26 +2200,30 @@ void hashAndMapTest() QVERIFY(it == c.end()); } - c.insertMulti(k1, Value(47)); - it = c.find(k1); - QVERIFY(it != c.end()); - QCOMPARE(it.key(), k1); - ++it; - QVERIFY(it != c.end()); - QCOMPARE(it.key(), k1); - ++it; - if (Ordered) - QVERIFY(it == c.end()); + if (Multi) { + c.insert(k1, Value(47)); + it = c.find(k1); + QVERIFY(it != c.end()); + QCOMPARE(it.key(), k1); + ++it; + QVERIFY(it != c.end()); + QCOMPARE(it.key(), k1); + ++it; + if (Ordered) + QVERIFY(it == c.end()); + } } void tst_QSharedPointer::map() { - hashAndMapTest<QMap<QSharedPointer<int>, int>, true>(); + hashAndMapTest<QMap<QSharedPointer<int>, int>, true, false>(); + hashAndMapTest<QMultiMap<QSharedPointer<int>, int>, true, true>(); } void tst_QSharedPointer::hash() { - hashAndMapTest<QHash<QSharedPointer<int>, int>, false>(); + hashAndMapTest<QHash<QSharedPointer<int>, int>, false, false>(); + hashAndMapTest<QMultiHash<QSharedPointer<int>, int>, false, true>(); } void tst_QSharedPointer::validConstructs() diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 7a69e844d4..6ae312fb8d 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -324,6 +324,18 @@ private slots: void swapItemsAt() const; + void emplaceInt(); + void emplaceCustom(); + void emplaceMovable(); + void emplaceConsistentWithStdVectorInt(); + void emplaceConsistentWithStdVectorCustom(); + void emplaceConsistentWithStdVectorMovable(); + void emplaceReturnsIterator(); + void emplaceBack(); + void emplaceBackReturnsRef(); + void emplaceWithElementFromTheSameContainer(); + void emplaceWithElementFromTheSameContainer_data(); + private: template<typename T> void copyConstructor() const; template<typename T> void add() const; @@ -349,6 +361,8 @@ private: template<typename T> void initializeList(); template<typename T> void detach() const; template<typename T> void detachThreadSafety() const; + template<typename T> void emplaceImpl() const; + template<typename T> void emplaceConsistentWithStdVectorImpl() const; }; @@ -2645,5 +2659,172 @@ void tst_QVector::swapItemsAt() const QCOMPARE(copy.at(2), 2); } +void tst_QVector::emplaceInt() +{ + emplaceImpl<int>(); +} + +void tst_QVector::emplaceCustom() +{ + emplaceImpl<Custom>(); +} + +void tst_QVector::emplaceMovable() +{ + emplaceImpl<Movable>(); +} + +void tst_QVector::emplaceConsistentWithStdVectorInt() +{ + emplaceConsistentWithStdVectorImpl<int>(); +} + +void tst_QVector::emplaceConsistentWithStdVectorCustom() +{ + emplaceConsistentWithStdVectorImpl<Custom>(); +} + +void tst_QVector::emplaceConsistentWithStdVectorMovable() +{ + emplaceConsistentWithStdVectorImpl<Movable>(); +} + +void tst_QVector::emplaceReturnsIterator() +{ + QVector<Movable> vec; + + vec.emplace(0, 'k')->i = 'p'; + + QCOMPARE(vec[0].i, 'p'); +} + +void tst_QVector::emplaceBack() +{ + QScopedValueRollback<QAtomicInt> rollback(Movable::counter, 0); + + QVector<Movable> vec; + + vec.emplaceBack('k'); + + QCOMPARE(Movable::counter, 1); +} + +void tst_QVector::emplaceBackReturnsRef() +{ + QVector<Movable> vec; + + vec.emplaceBack('k').i = 'p'; + + QCOMPARE(vec.at(0).i, 'p'); +} + +void tst_QVector::emplaceWithElementFromTheSameContainer() +{ + QFETCH(int, elementPos); + QFETCH(int, insertPos); + QFETCH(bool, doCopy); + + QVector<QString> vec {"a", "b", "c", "d", "e"}; + const QString e = vec[elementPos]; + + if (doCopy) + vec.emplace(insertPos, vec[elementPos]); + else + vec.emplace(insertPos, std::move(vec[elementPos])); + + QCOMPARE(vec[insertPos], e); +} + +void tst_QVector::emplaceWithElementFromTheSameContainer_data() +{ + QTest::addColumn<int>("elementPos"); + QTest::addColumn<int>("insertPos"); + QTest::addColumn<bool>("doCopy"); + + for (int i = 0; i < 2; ++i) { + const bool doCopy = i == 0; + const char *opName = doCopy ? "copy" : "move"; + + QTest::addRow("%s: begin -> end" , opName) << 0 << 5 << doCopy; + QTest::addRow("%s: begin -> middle", opName) << 0 << 2 << doCopy; + QTest::addRow("%s: middle -> begin" , opName) << 2 << 0 << doCopy; + QTest::addRow("%s: middle -> end" , opName) << 2 << 5 << doCopy; + QTest::addRow("%s: end -> middle", opName) << 4 << 2 << doCopy; + QTest::addRow("%s: end -> begin" , opName) << 4 << 0 << doCopy; + } +} + +template<typename T> +void tst_QVector::emplaceImpl() const +{ + QVector<T> vec {'a', 'b', 'c', 'd'}; + + vec.emplace(2, 'k'); + + QCOMPARE(vec[2], T('k')); +} + +template <class T> +static void vecEq(const QVector<T> &qVec, const std::vector<T> &stdVec) +{ + QCOMPARE(std::size_t(qVec.size()), stdVec.size()); + QVERIFY(std::equal(qVec.begin(), qVec.end(), stdVec.begin(), stdVec.end())); +} + +template <class T> +static void squeezeVec(QVector<T> &qVec, std::vector<T> &stdVec) +{ + qVec.squeeze(); + stdVec.shrink_to_fit(); +} + +template<typename T> +void tst_QVector::emplaceConsistentWithStdVectorImpl() const +{ + QVector<T> qVec {'a', 'b', 'c', 'd', 'e'}; + std::vector<T> stdVec {'a', 'b', 'c', 'd', 'e'}; + vecEq(qVec, stdVec); + + qVec.emplaceBack('f'); + stdVec.emplace_back('f'); + vecEq(qVec, stdVec); + + qVec.emplace(3, 'g'); + stdVec.emplace(stdVec.begin() + 3, 'g'); + vecEq(qVec, stdVec); + + qVec.emplaceBack(std::move(qVec[0])); + stdVec.emplace_back(std::move(stdVec[0])); + vecEq(qVec, stdVec); + + squeezeVec(qVec, stdVec); + + qVec.emplaceBack(std::move(qVec[1])); + stdVec.emplace_back(std::move(stdVec[1])); + vecEq(qVec, stdVec); + + squeezeVec(qVec, stdVec); + + qVec.emplace(3, std::move(qVec[5])); + stdVec.emplace(stdVec.begin() + 3, std::move(stdVec[5])); + vecEq(qVec, stdVec); + + qVec.emplaceBack(qVec[3]); + stdVec.emplace_back(stdVec[3]); + vecEq(qVec, stdVec); + + squeezeVec(qVec, stdVec); + + qVec.emplaceBack(qVec[4]); + stdVec.emplace_back(stdVec[4]); + vecEq(qVec, stdVec); + + squeezeVec(qVec, stdVec); + + qVec.emplace(5, qVec[7]); + stdVec.emplace(stdVec.begin() + 5, stdVec[7]); + vecEq(qVec, stdVec); +} + QTEST_MAIN(tst_QVector) #include "tst_qvector.moc" diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp index 7c4d1071ce..928bd365fd 100644 --- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp +++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp @@ -81,6 +81,10 @@ private slots: void serialize(); void moveSemantics(); void qtVersion(); + void qTypeRevision_data(); + void qTypeRevision(); + void qTypeRevisionTypes(); + void qTypeRevisionComparison(); }; void tst_QVersionNumber::singleInstanceData() @@ -645,6 +649,153 @@ void tst_QVersionNumber::qtVersion() QCOMPARE(v.toString(), QString(qVersion())); } +template<typename Integer> +void compileTestRevisionMajorMinor() +{ + const Integer major = 8; + const Integer minor = 4; + + const QTypeRevision r2 = QTypeRevision::fromVersion(major, minor); + QCOMPARE(r2.majorVersion(), 8); + QCOMPARE(r2.minorVersion(), 4); + + const QTypeRevision r3 = QTypeRevision::fromMajorVersion(major); + QCOMPARE(r3.majorVersion(), 8); + QVERIFY(!r3.hasMinorVersion()); + + const QTypeRevision r4 = QTypeRevision::fromMinorVersion(minor); + QVERIFY(!r4.hasMajorVersion()); + QCOMPARE(r4.minorVersion(), 4); +} + + +template<typename Integer> +void compileTestRevision() +{ + if (std::is_signed<Integer>::value) + compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Signed>(); + else + compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Unsigned>(); + + const Integer value = 0x0510; + const QTypeRevision r = QTypeRevision::fromEncodedVersion(value); + + QCOMPARE(r.majorVersion(), 5); + QCOMPARE(r.minorVersion(), 16); + QCOMPARE(r.toEncodedVersion<Integer>(), value); + + compileTestRevisionMajorMinor<Integer>(); +} + +template<> +void compileTestRevision<qint16>() +{ + compileTestRevisionMajorMinor<quint8>(); +} + +template<> +void compileTestRevision<quint8>() +{ + compileTestRevisionMajorMinor<quint8>(); +} + +template<> +void compileTestRevision<qint8>() +{ + compileTestRevisionMajorMinor<qint8>(); +} + +void tst_QVersionNumber::qTypeRevision_data() +{ + QTest::addColumn<QTypeRevision>("revision"); + QTest::addColumn<bool>("valid"); + QTest::addColumn<int>("major"); + QTest::addColumn<int>("minor"); + + QTest::addRow("Qt revision") << QTypeRevision::fromVersion(QT_VERSION_MAJOR, QT_VERSION_MINOR) + << true << QT_VERSION_MAJOR << QT_VERSION_MINOR; + QTest::addRow("invalid") << QTypeRevision() << false << 0xff << 0xff; + QTest::addRow("major") << QTypeRevision::fromMajorVersion(6) << true << 6 << 0xff; + QTest::addRow("minor") << QTypeRevision::fromMinorVersion(15) << true << 0xff << 15; + QTest::addRow("zero") << QTypeRevision::fromVersion(0, 0) << true << 0 << 0; + + // We're intentionally not testing negative numbers. + // There are asserts against negative numbers in QTypeRevision. + // You must not pass them as major or minor versions, or values. +} + +void tst_QVersionNumber::qTypeRevision() +{ + const QTypeRevision other = QTypeRevision::fromVersion(127, 128); + + QFETCH(QTypeRevision, revision); + + QFETCH(bool, valid); + QFETCH(int, major); + QFETCH(int, minor); + + QCOMPARE(revision.isValid(), valid); + QCOMPARE(revision.majorVersion(), major); + QCOMPARE(revision.minorVersion(), minor); + + QCOMPARE(revision.hasMajorVersion(), QTypeRevision::isValidSegment(major)); + QCOMPARE(revision.hasMinorVersion(), QTypeRevision::isValidSegment(minor)); + + const QTypeRevision copy = QTypeRevision::fromEncodedVersion(revision.toEncodedVersion<int>()); + QCOMPARE(copy, revision); + + QVERIFY(revision != other); + QVERIFY(copy != other); +} + +void tst_QVersionNumber::qTypeRevisionTypes() +{ + compileTestRevision<quint64>(); + compileTestRevision<qint64>(); + + QVERIFY(!QTypeRevision::isValidSegment(0xff)); + QVERIFY(!QTypeRevision::isValidSegment(-1)); + + const QTypeRevision maxRevision = QTypeRevision::fromVersion(254, 254); + QVERIFY(maxRevision.hasMajorVersion()); + QVERIFY(maxRevision.hasMinorVersion()); +} + +void tst_QVersionNumber::qTypeRevisionComparison() +{ + const QTypeRevision revisions[] = { + QTypeRevision::zero(), + QTypeRevision::fromMajorVersion(0), + QTypeRevision::fromVersion(0, 1), + QTypeRevision::fromVersion(0, 20), + QTypeRevision::fromMinorVersion(0), + QTypeRevision(), + QTypeRevision::fromMinorVersion(1), + QTypeRevision::fromMinorVersion(20), + QTypeRevision::fromVersion(1, 0), + QTypeRevision::fromMajorVersion(1), + QTypeRevision::fromVersion(1, 1), + QTypeRevision::fromVersion(1, 20), + QTypeRevision::fromVersion(20, 0), + QTypeRevision::fromMajorVersion(20), + QTypeRevision::fromVersion(20, 1), + QTypeRevision::fromVersion(20, 20), + }; + + const int length = sizeof(revisions) / sizeof(QTypeRevision); + + for (int i = 0; i < length; ++i) { + for (int j = 0; j < length; ++j) { + QCOMPARE(revisions[i] == revisions[j], i == j); + QCOMPARE(revisions[i] != revisions[j], i != j); + QCOMPARE(revisions[i] < revisions[j], i < j); + QCOMPARE(revisions[i] > revisions[j], i > j); + QCOMPARE(revisions[i] <= revisions[j], i <= j); + QCOMPARE(revisions[i] >= revisions[j], i >= j); + } + } +} + QTEST_APPLESS_MAIN(tst_QVersionNumber) #include "tst_qversionnumber.moc" diff --git a/tests/auto/gui/kernel/qguiapplication/BLACKLIST b/tests/auto/gui/kernel/qguiapplication/BLACKLIST index e6ffe78ae3..58ca7bf782 100644 --- a/tests/auto/gui/kernel/qguiapplication/BLACKLIST +++ b/tests/auto/gui/kernel/qguiapplication/BLACKLIST @@ -1,3 +1,6 @@ [focusObject] ubuntu-16.04 opensuse-42.3 + +[quitOnLastWindowClosedMulti] +macos ci diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp index 78638a7518..97c6ad60b8 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -46,8 +46,6 @@ private slots: void qhash(); void translate(); void scale(); - void matrix(); - void testOffset(); void types(); void types2_data(); void types2(); @@ -372,67 +370,6 @@ void tst_QTransform::scale() QVERIFY( QTransform::fromScale( 1, 1 ) == QTransform()); } -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -void tst_QTransform::matrix() -{ - QMatrix mat1; - mat1.scale(0.3, 0.7); - mat1.translate(53.3, 94.4); - mat1.rotate(45); - - QMatrix mat2; - mat2.rotate(33); - mat2.scale(0.6, 0.6); - mat2.translate(13.333, 7.777); - - QTransform tran1(mat1); - QTransform tran2(mat2); - QTransform dummy; - dummy.setMatrix(mat1.m11(), mat1.m12(), 0, - mat1.m21(), mat1.m22(), 0, - mat1.dx(), mat1.dy(), 1); - - QCOMPARE(tran1, dummy); - QCOMPARE(tran1.inverted(), dummy.inverted()); - QCOMPARE(tran1.inverted(), QTransform(mat1.inverted())); - QCOMPARE(tran2.inverted(), QTransform(mat2.inverted())); - - QMatrix mat3 = mat1 * mat2; - QTransform tran3 = tran1 * tran2; - QCOMPARE(QTransform(mat3), tran3); - - /* QMatrix::operator==() doesn't use qFuzzyCompare(), which - * on win32-g++ results in a failure. So we work around it by - * calling QTranform::operator==(), which performs a fuzzy compare. */ - QCOMPARE(QTransform(mat3), QTransform(tran3.toAffine())); - - QTransform tranInv = tran1.inverted(); - QMatrix matInv = mat1.inverted(); - - QRect rect(43, 70, 200, 200); - QPoint pt(43, 66); - QCOMPARE(tranInv.mapRect(rect), matInv.mapRect(rect)); - QCOMPARE(tranInv.map(pt), matInv.map(pt)); - - QPainterPath path; - path.moveTo(55, 60); - path.lineTo(110, 110); - path.quadTo(220, 50, 10, 20); - path.closeSubpath(); - QCOMPARE(tranInv.map(path), matInv.map(path)); -} - -void tst_QTransform::testOffset() -{ - QTransform trans; - const QMatrix &aff = trans.toAffine(); - QCOMPARE((void*)(&aff), (void*)(&trans)); -} -QT_WARNING_POP -#endif - void tst_QTransform::types() { QTransform m1; diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 3a7ad6dad5..cf839e1931 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -28,6 +28,7 @@ #include <QtOpenGL/QOpenGLPaintDevice> #include <QtOpenGL/QOpenGLTexture> +#include <QtOpenGL/qopengltextureblitter.h> #include <QtGui/private/qopenglcontext_p.h> #include <QtGui/QOpenGLFramebufferObject> #include <QtGui/QOpenGLFunctions> @@ -40,7 +41,6 @@ #include <QtGui/QOffscreenSurface> #include <QtGui/QGenericMatrix> #include <QtGui/QMatrix4x4> -#include <QtGui/qopengltextureblitter.h> #include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qopenglextensions_p.h> #include <qpa/qplatformintegration.h> diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp index 5be00630ca..1ef9382f0a 100644 --- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp +++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp @@ -530,11 +530,17 @@ void tst_PlatformSocketEngine::tooManySockets() void tst_PlatformSocketEngine::bind() { #if !defined Q_OS_WIN - PLATFORMSOCKETENGINE binder; - QVERIFY(binder.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol)); - QVERIFY(!binder.bind(QHostAddress::AnyIPv4, 82)); - QCOMPARE(binder.error(), QAbstractSocket::SocketAccessError); -#endif +#if defined Q_OS_MACOS + // On macOS >= 10.14 the bind on this port is successful. + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave) +#endif // Q_OS_MACOS + { + PLATFORMSOCKETENGINE binder; + QVERIFY(binder.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol)); + QVERIFY(!binder.bind(QHostAddress::AnyIPv4, 82)); + QCOMPARE(binder.error(), QAbstractSocket::SocketAccessError); + } +#endif // Q_OS_WIN PLATFORMSOCKETENGINE binder2; QVERIFY(binder2.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol)); diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 9ab5e88900..bf08d70eb3 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -558,8 +558,18 @@ void tst_QTcpSocket::bind_data() // try to bind to a privileged ports // we should fail if we're not root (unless the ports are in use!) QTest::newRow("127.0.0.1:1") << "127.0.0.1" << 1 << !geteuid() << (geteuid() ? QString() : "127.0.0.1"); - if (testIpv6) + if (testIpv6) { +#ifdef Q_OS_DARWIN + // This case is faling in different ways, first, it manages to bind to + // port 1 on macOS >= 10.14, but if we change the logic to not fail, + // it's becoming flaky and sometimes fails to bind, with error 'port in use' + // (apparently inflicted by the previous test row with 127.0.0.1). Amen. + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave) + QTest::qWarn("Skipping [::]:1, see QTBUG-81905", __FILE__, __LINE__); + else +#endif // Q_OS_DARWIN QTest::newRow("[::]:1") << "::" << 1 << !geteuid() << (geteuid() ? QString() : "::"); + } #endif } diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index a4ee6795c4..be86fc8e21 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -32,6 +32,7 @@ #include <qobject.h> #include <qmetaobject.h> #include <qjsondocument.h> +#include <qversionnumber.h> #include "using-namespaces.h" #include "assign-namespace.h" @@ -1895,12 +1896,14 @@ class VersionTest : public QObject Q_OBJECT Q_PROPERTY(int prop1 READ foo) Q_PROPERTY(int prop2 READ foo REVISION 2) + Q_PROPERTY(int prop514 READ foo REVISION(5, 14)) public: int foo() const { return 0; } Q_INVOKABLE void method1() {} Q_INVOKABLE Q_REVISION(4) void method2() {} + Q_INVOKABLE Q_REVISION(6, 0) void method60() {} enum TestEnum { One, Two }; Q_ENUM(TestEnum); @@ -1909,18 +1912,26 @@ public: public slots: void slot1() {} Q_REVISION(3) void slot2() {} + Q_REVISION(6, 1) void slot61() {} signals: void signal1(); Q_REVISION(5) void signal2(); + Q_REVISION(6, 2) void signal62(); public slots Q_REVISION(6): void slot3() {} void slot4() {} +public slots Q_REVISION(5, 12): + void slot512() {} + signals Q_REVISION(7): void signal3(); void signal4(); + +signals Q_REVISION(5, 15): + void signal515(); }; // If changed, update VersionTest above @@ -1929,12 +1940,14 @@ class VersionTestNotify : public QObject Q_OBJECT Q_PROPERTY(int prop1 READ foo NOTIFY fooChanged) Q_PROPERTY(int prop2 READ foo REVISION 2) + Q_PROPERTY(int prop514 READ foo REVISION(5, 14)) public: int foo() const { return 0; } Q_INVOKABLE void method1() {} Q_INVOKABLE Q_REVISION(4) void method2() {} + Q_INVOKABLE Q_REVISION(6, 0) void method60() {} enum TestEnum { One, Two }; Q_ENUM(TestEnum); @@ -1942,19 +1955,27 @@ public: public slots: void slot1() {} Q_REVISION(3) void slot2() {} + Q_REVISION(6, 1) void slot61() {} signals: void fooChanged(); void signal1(); Q_REVISION(5) void signal2(); + Q_REVISION(6, 2) void signal62(); public slots Q_REVISION(6): void slot3() {} void slot4() {} +public slots Q_REVISION(5, 12): + void slot512() {} + signals Q_REVISION(7): void signal3(); void signal4(); + +signals Q_REVISION(5, 15): + void signal515(); }; template <class T> @@ -1963,32 +1984,58 @@ void tst_Moc::revisions_T() int idx = T::staticMetaObject.indexOfProperty("prop1"); QCOMPARE(T::staticMetaObject.property(idx).revision(), 0); idx = T::staticMetaObject.indexOfProperty("prop2"); - QCOMPARE(T::staticMetaObject.property(idx).revision(), 2); + QCOMPARE(T::staticMetaObject.property(idx).revision(), + QTypeRevision::fromMinorVersion(2).toEncodedVersion<int>()); + idx = T::staticMetaObject.indexOfProperty("prop514"); + QCOMPARE(T::staticMetaObject.property(idx).revision(), + QTypeRevision::fromVersion(5, 14).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfMethod("method1()"); QCOMPARE(T::staticMetaObject.method(idx).revision(), 0); idx = T::staticMetaObject.indexOfMethod("method2()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 4); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(4).toEncodedVersion<int>()); + idx = T::staticMetaObject.indexOfMethod("method60()"); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromVersion(6, 0).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfSlot("slot1()"); QCOMPARE(T::staticMetaObject.method(idx).revision(), 0); idx = T::staticMetaObject.indexOfSlot("slot2()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 3); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(3).toEncodedVersion<int>()); + idx = T::staticMetaObject.indexOfSlot("slot61()"); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromVersion(6, 1).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfSlot("slot3()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 6); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(6).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfSlot("slot4()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 6); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(6).toEncodedVersion<int>()); + idx = T::staticMetaObject.indexOfSlot("slot512()"); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromVersion(5, 12).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfSignal("signal1()"); QCOMPARE(T::staticMetaObject.method(idx).revision(), 0); idx = T::staticMetaObject.indexOfSignal("signal2()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 5); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(5).toEncodedVersion<int>()); + idx = T::staticMetaObject.indexOfSignal("signal62()"); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromVersion(6, 2).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfSignal("signal3()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 7); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(7).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfSignal("signal4()"); - QCOMPARE(T::staticMetaObject.method(idx).revision(), 7); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromMinorVersion(7).toEncodedVersion<int>()); + idx = T::staticMetaObject.indexOfSignal("signal515()"); + QCOMPARE(T::staticMetaObject.method(idx).revision(), + QTypeRevision::fromVersion(5, 15).toEncodedVersion<int>()); idx = T::staticMetaObject.indexOfEnumerator("TestEnum"); QCOMPARE(T::staticMetaObject.enumerator(idx).keyCount(), 2); diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index 7398cc103e..4e31c3e57c 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -1063,7 +1063,7 @@ void tst_QFileSystemModel::roleNames() QVERIFY(roles.contains(role)); QFETCH(QByteArray, roleName); - QCOMPARE(roles.values(role).count(), 1); + QCOMPARE(roles.contains(role), true); QCOMPARE(roles.value(role), roleName); } diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp index 546b2ab3a8..925c578300 100644 --- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp +++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp @@ -713,7 +713,7 @@ void tst_QDirModel::roleNames() QVERIFY(roles.contains(role)); QFETCH(QByteArray, roleName); - QCOMPARE(roles.values(role).count(), 1); + QCOMPARE(roles.contains(role), true); QCOMPARE(roles.value(role), roleName); } diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 89c4a74739..fe3e3c7f72 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1807,7 +1807,7 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); - QSignalSpy activatedSpy(&cbox, QOverload<int>::of(&QComboBox::activated)); + QSignalSpy activatedSpy(&cbox, &QComboBox::activated); // Tab key will complete but not activate cbox.lineEdit()->clear(); @@ -1851,7 +1851,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice() QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); - QSignalSpy activatedSpy(&cbox, QOverload<int>::of(&QComboBox::activated)); + QSignalSpy activatedSpy(&cbox, &QComboBox::activated); // Navigate + enter activates only once (first item) cbox.lineEdit()->clear(); diff --git a/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp index 47dfc86a69..5d52acd1a2 100644 --- a/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp +++ b/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp @@ -280,67 +280,43 @@ void tst_QButtonGroup::testSignals() qRegisterMetaType<QAbstractButton *>("QAbstractButton *"); QSignalSpy clickedSpy(&buttons, SIGNAL(buttonClicked(QAbstractButton*))); - QSignalSpy clickedIdSpy(&buttons, SIGNAL(buttonClicked(int))); QSignalSpy pressedSpy(&buttons, SIGNAL(buttonPressed(QAbstractButton*))); - QSignalSpy pressedIdSpy(&buttons, SIGNAL(buttonPressed(int))); QSignalSpy releasedSpy(&buttons, SIGNAL(buttonReleased(QAbstractButton*))); - QSignalSpy releasedIdSpy(&buttons, SIGNAL(buttonReleased(int))); pb1.animateClick(); QTestEventLoop::instance().enterLoop(1); QCOMPARE(clickedSpy.count(), 1); - QCOMPARE(clickedIdSpy.count(), 1); - int expectedId = -2; - - QCOMPARE(clickedIdSpy.takeFirst().at(0).toInt(), expectedId); QCOMPARE(pressedSpy.count(), 1); - QCOMPARE(pressedIdSpy.count(), 1); - QCOMPARE(pressedIdSpy.takeFirst().at(0).toInt(), expectedId); QCOMPARE(releasedSpy.count(), 1); - QCOMPARE(releasedIdSpy.count(), 1); - QCOMPARE(releasedIdSpy.takeFirst().at(0).toInt(), expectedId); clickedSpy.clear(); - clickedIdSpy.clear(); pressedSpy.clear(); - pressedIdSpy.clear(); releasedSpy.clear(); - releasedIdSpy.clear(); pb2.animateClick(); QTestEventLoop::instance().enterLoop(1); QCOMPARE(clickedSpy.count(), 1); - QCOMPARE(clickedIdSpy.count(), 1); - QCOMPARE(clickedIdSpy.takeFirst().at(0).toInt(), 23); QCOMPARE(pressedSpy.count(), 1); - QCOMPARE(pressedIdSpy.count(), 1); - QCOMPARE(pressedIdSpy.takeFirst().at(0).toInt(), 23); QCOMPARE(releasedSpy.count(), 1); - QCOMPARE(releasedIdSpy.count(), 1); - QCOMPARE(releasedIdSpy.takeFirst().at(0).toInt(), 23); QSignalSpy toggledSpy(&buttons, SIGNAL(buttonToggled(QAbstractButton*, bool))); - QSignalSpy toggledIdSpy(&buttons, SIGNAL(buttonToggled(int, bool))); pb1.setCheckable(true); pb2.setCheckable(true); pb1.toggle(); QCOMPARE(toggledSpy.count(), 1); - QCOMPARE(toggledIdSpy.count(), 1); pb2.toggle(); QCOMPARE(toggledSpy.count(), 3); // equals 3 since pb1 and pb2 are both toggled - QCOMPARE(toggledIdSpy.count(), 3); pb1.setCheckable(false); pb2.setCheckable(false); pb1.toggle(); QCOMPARE(toggledSpy.count(), 3); - QCOMPARE(toggledIdSpy.count(), 3); } void tst_QButtonGroup::task106609() @@ -372,7 +348,6 @@ void tst_QButtonGroup::task106609() qRegisterMetaType<QAbstractButton*>("QAbstractButton*"); QSignalSpy spy1(buttons, SIGNAL(buttonClicked(QAbstractButton*))); - QSignalSpy spy2(buttons, SIGNAL(buttonClicked(int))); QApplication::setActiveWindow(&dlg); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&dlg)); @@ -381,8 +356,6 @@ void tst_QButtonGroup::task106609() radio1->setChecked(true); QTestEventLoop::instance().enterLoop(1); - //qDebug() << "int:" << spy2.count() << "QAbstractButton*:" << spy1.count(); - QCOMPARE(spy2.count(), 2); QCOMPARE(spy1.count(), 2); } @@ -427,11 +400,12 @@ public: : group(group) , deleteButton(deleteButton) { - connect(group, SIGNAL(buttonClicked(int)), SLOT(buttonClicked(int))); + connect(group, &QButtonGroup::buttonClicked, + this, &task209485_ButtonDeleter::buttonClicked); } private slots: - void buttonClicked(int) + void buttonClicked() { if (deleteButton) group->removeButton(group->buttons().first()); @@ -447,7 +421,7 @@ void tst_QButtonGroup::task209485_removeFromGroupInEventHandler_data() QTest::addColumn<bool>("deleteButton"); QTest::addColumn<int>("signalCount"); QTest::newRow("buttonPress 1") << true << 1; - QTest::newRow("buttonPress 2") << false << 2; + QTest::newRow("buttonPress 2") << false << 1; } void tst_QButtonGroup::task209485_removeFromGroupInEventHandler() @@ -463,12 +437,11 @@ void tst_QButtonGroup::task209485_removeFromGroupInEventHandler() task209485_ButtonDeleter buttonDeleter(&group, deleteButton); QSignalSpy spy1(&group, SIGNAL(buttonClicked(QAbstractButton*))); - QSignalSpy spy2(&group, SIGNAL(buttonClicked(int))); // NOTE: Reintroducing the bug of this task will cause the following line to crash: QTest::mouseClick(button, Qt::LeftButton); - QCOMPARE(spy1.count() + spy2.count(), signalCount); + QCOMPARE(spy1.count(), signalCount); } void tst_QButtonGroup::autoIncrementId() diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 3878e7ccb2..1f301fd60f 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -2484,7 +2484,7 @@ void tst_QComboBox::task247863_keyBoardSelection() QApplication::setActiveWindow(&combo); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&combo)); - QSignalSpy spy(&combo, SIGNAL(activated(QString))); + QSignalSpy spy(&combo, &QComboBox::activated); qApp->setEffectEnabled(Qt::UI_AnimateCombo, false); QTest::keyClick(&combo, Qt::Key_Space); qApp->setEffectEnabled(Qt::UI_AnimateCombo, true); diff --git a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp index c6de750482..cec2da1d57 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp @@ -419,7 +419,7 @@ void tst_QDoubleSpinBox::setTracking() spin.setDecimals(decimals); spin.show(); - connect(&spin, SIGNAL(valueChanged(QString)), this, SLOT(valueChangedHelper(QString))); + connect(&spin, SIGNAL(textChanged(QString)), this, SLOT(valueChangedHelper(QString))); keys.simulate(&spin); QCOMPARE(actualTexts, texts); @@ -1774,7 +1774,7 @@ void tst_QDoubleSpinBox::stepModifierPressAndHold() stepModifierStyle->stepModifier = static_cast<Qt::KeyboardModifier>(stepModifier); spin.setStyle(stepModifierStyle.data()); - QSignalSpy spy(&spin, QOverload<double>::of(&DoubleSpinBox::valueChanged)); + QSignalSpy spy(&spin, &DoubleSpinBox::valueChanged); spin.show(); QVERIFY(QTest::qWaitForWindowExposed(&spin)); diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 5b49e3484c..a8b47ffc46 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -1830,9 +1830,9 @@ void tst_QSpinBox::stepModifierPressAndHold() stepModifierStyle->stepModifier = static_cast<Qt::KeyboardModifier>(stepModifier); spin.setStyle(stepModifierStyle.data()); - QSignalSpy spy(&spin, QOverload<int>::of(&SpinBox::valueChanged)); + QSignalSpy spy(&spin, &SpinBox::valueChanged); // TODO: remove debug output when QTBUG-69492 is fixed - connect(&spin, QOverload<int>::of(&SpinBox::valueChanged), [=]() { + connect(&spin, &SpinBox::valueChanged, [=]() { qDebug() << QTime::currentTime() << "valueChanged emitted"; }); |