From f2f040ae1c4fe48bff68bb45b2e20308fa895c50 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 2 Oct 2018 12:36:04 +0200 Subject: Improve support for QImages in QDataStream read transactions QImage's operator>>(QDataStream&) did not set an error mode on the stream on read failures. That would break QDataStream transactions. Since the current QImage serialization cannot differentiate between truncated and corrupted data, we set the ReadPastEnd error as expected by the transaction system. Also specify the expected file format on decoding QImage from stream, to avoid all the format handlers' canRead() being invoked. This is necessary since some of them may call ungetChar(), which fails when the stream is in a transaction. Also add testing of this feature to the QDataStram transaction autotest. That required a slight rewrite of the fake sequential QIODevice subclass. The previous implementation had incorrect behavior of peek(), which is required by QImage decoders. Task-number: QTBUG-70875 Change-Id: If3f1ca7186ad1e6ca0e6e8ea81d2b2fbece6ea01 Reviewed-by: Alex Trotsenko Reviewed-by: Thiago Macieira --- .../serialization/qdatastream/tst_qdatastream.cpp | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index c6faf8c7d5..011a0e1a85 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -2211,25 +2211,22 @@ void tst_QDataStream::setVersion() } } -class SequentialBuffer : public QBuffer +class SequentialBuffer : public QIODevice { public: - SequentialBuffer(QByteArray *data) : QBuffer(data) { offset = 0; } + SequentialBuffer(QByteArray *data) : QIODevice() { buf.setBuffer(data); } - bool isSequential() const { return true; } - bool seek(qint64 pos) { offset = pos; return QBuffer::seek(pos); } - qint64 pos() const { return qint64(offset); } + bool isSequential() const override { return true; } + bool open(OpenMode mode) override { return buf.open(mode) && QIODevice::open(mode | QIODevice::Unbuffered); } + void close() override { buf.close(); QIODevice::close(); } + qint64 bytesAvailable() const override { return QIODevice::bytesAvailable() + buf.bytesAvailable(); } protected: - qint64 readData(char *data, qint64 maxSize) - { - qint64 ret = QBuffer::readData(data, maxSize); - offset += ret; - return ret; - } + qint64 readData(char *data, qint64 maxSize) override { return buf.read(data, maxSize); } + qint64 writeData(const char *data, qint64 maxSize) override { return buf.write(data, maxSize); } private: - int offset; + QBuffer buf; }; void tst_QDataStream::skipRawData_data() @@ -3329,15 +3326,21 @@ void tst_QDataStream::transaction_data() QTest::addColumn("bData"); QTest::addColumn("fData"); QTest::addColumn("dData"); + QTest::addColumn("imgData"); QTest::addColumn("strData"); QTest::addColumn("rawData"); + QImage img1(open_xpm); + QImage img2; + QImage img3(50, 50, QImage::Format_ARGB32); + img3.fill(qRgba(12, 34, 56, 78)); + QTest::newRow("1") << qint8(1) << qint16(2) << qint32(3) << qint64(4) << true << 5.0f - << double(6.0) << QByteArray("Hello world!") << QByteArray("Qt rocks!"); + << double(6.0) << img1 << QByteArray("Hello world!") << QByteArray("Qt rocks!"); QTest::newRow("2") << qint8(1 << 6) << qint16(1 << 14) << qint32(1 << 30) << qint64Data(3) << false << 123.0f - << double(234.0) << stringData(5).toUtf8() << stringData(6).toUtf8(); + << double(234.0) << img2 << stringData(5).toUtf8() << stringData(6).toUtf8(); QTest::newRow("3") << qint8(-1) << qint16(-2) << qint32(-3) << qint64(-4) << true << -123.0f - << double(-234.0) << stringData(3).toUtf8() << stringData(4).toUtf8(); + << double(-234.0) << img3 << stringData(3).toUtf8() << stringData(4).toUtf8(); } void tst_QDataStream::transaction() @@ -3351,6 +3354,7 @@ void tst_QDataStream::transaction() QFETCH(bool, bData); QFETCH(float, fData); QFETCH(double, dData); + QFETCH(QImage, imgData); QFETCH(QByteArray, strData); QFETCH(QByteArray, rawData); @@ -3358,12 +3362,13 @@ void tst_QDataStream::transaction() QDataStream stream(&testBuffer, QIODevice::WriteOnly); stream << i8Data << i16Data << i32Data << i64Data - << bData << fData << dData << strData.constData(); + << bData << fData << dData << imgData << strData.constData(); stream.writeRawData(rawData.constData(), rawData.size()); } for (int splitPos = 0; splitPos <= testBuffer.size(); ++splitPos) { QByteArray readBuffer(testBuffer.left(splitPos)); + SequentialBuffer dev(&readBuffer); dev.open(QIODevice::ReadOnly); QDataStream stream(&dev); @@ -3375,12 +3380,13 @@ void tst_QDataStream::transaction() bool b; float f; double d; + QImage img; char *str; QByteArray raw(rawData.size(), 0); forever { stream.startTransaction(); - stream >> i8 >> i16 >> i32 >> i64 >> b >> f >> d >> str; + stream >> i8 >> i16 >> i32 >> i64 >> b >> f >> d >> img >> str; stream.readRawData(raw.data(), raw.size()); if (stream.commitTransaction()) @@ -3402,6 +3408,7 @@ void tst_QDataStream::transaction() QCOMPARE(b, bData); QCOMPARE(f, fData); QCOMPARE(d, dData); + QCOMPARE(img, imgData); QVERIFY(strData == str); delete [] str; QCOMPARE(raw, rawData); -- cgit v1.2.3 From aa633ff276e593af227d7c4a84db230382185490 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 15 Oct 2018 20:08:47 +0300 Subject: QMetaEnum: fix UB Check ptr before usage. Change-Id: Iac757a2e260b237d837318932cc0b5896c6e04c2 Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp b/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp index bb111a9137..6ed0a6caa9 100644 --- a/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp +++ b/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp @@ -46,6 +46,7 @@ private slots: void fromType(); void valuesToKeys_data(); void valuesToKeys(); + void defaultConstructed(); }; void tst_QMetaEnum::fromType() @@ -99,6 +100,15 @@ void tst_QMetaEnum::valuesToKeys() QCOMPARE(me.valueToKeys(windowFlags), expected); } +void tst_QMetaEnum::defaultConstructed() +{ + QMetaEnum e; + QVERIFY(!e.isValid()); + QVERIFY(!e.isScoped()); + QVERIFY(!e.isFlag()); + QCOMPARE(e.name(), QByteArray()); +} + Q_STATIC_ASSERT(QtPrivate::IsQEnumHelper::Value); Q_STATIC_ASSERT(QtPrivate::IsQEnumHelper::Value); Q_STATIC_ASSERT(QtPrivate::IsQEnumHelper::Value); -- cgit v1.2.3 From 16ebc78ef3280bf284da9a49bdd3fc1fabad347f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 16 Oct 2018 12:48:22 +0200 Subject: Fix odd test in tst_qflags This test triggered a compiler warning for good reason, it made no sense, trying to change it to what it was probably meant to be. Change-Id: I01a848272b42dae2aaa58a4f5bed998644d864da Reviewed-by: Friedemann Kleint --- tests/auto/corelib/global/qflags/tst_qflags.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 6129184738..72b086350e 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -121,7 +121,7 @@ void tst_QFlags::constExpr() QVERIFY(verifyConstExpr(Qt::RightButton)); QVERIFY(verifyConstExpr(0xff)); - QVERIFY(!verifyConstExpr(!Qt::MouseButtons(Qt::LeftButton))); + QVERIFY(!verifyConstExpr(~Qt::MouseButtons(Qt::LeftButton))); #if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304 QVERIFY(verifyConstExpr(Qt::MiddleButton)); -- cgit v1.2.3 From cea2b5510c28d1057018007d65589fecee62b0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Fri, 19 Oct 2018 12:39:12 +0200 Subject: Fix building tests with -no-gui Change-Id: I37307080e5adc334fcfcdd2fee650d675228a746 Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/itemmodels/itemmodels.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/itemmodels.pro b/tests/auto/corelib/itemmodels/itemmodels.pro index bcb6e604f8..cca350ad43 100644 --- a/tests/auto/corelib/itemmodels/itemmodels.pro +++ b/tests/auto/corelib/itemmodels/itemmodels.pro @@ -1,9 +1,9 @@ TEMPLATE=subdirs -SUBDIRS = qabstractitemmodel \ - qstringlistmodel \ +SUBDIRS = qstringlistmodel qtHaveModule(gui): SUBDIRS += \ + qabstractitemmodel \ qabstractproxymodel \ qidentityproxymodel \ qitemselectionmodel \ -- cgit v1.2.3 From 95ba049f8787258ccb28eeda72d1fac71f90e6f6 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 23 Oct 2018 11:18:22 +0200 Subject: Remove QSKIP and bring the test back to business MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on macOS, where it was skipped but where it now seems to be stable/work. Task-number: QTBUG-39983 Change-Id: I100a57f23b43074ebacc012be247d92acc6ae336 Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index fed05698fd..da5327594c 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -209,9 +209,6 @@ void tst_QIODevice::read_QByteArray() //-------------------------------------------------------------------- void tst_QIODevice::unget() { -#if defined(Q_OS_MAC) - QSKIP("The unget network test is unstable on Mac. See QTBUG-39983."); -#endif QBuffer buffer; buffer.open(QBuffer::ReadWrite); buffer.write("ZXCV"); -- cgit v1.2.3 From b10ee45546e152e08b2494bd45eb22426e9d2dc9 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 23 Oct 2018 15:42:24 +0200 Subject: tst_qeventdispatcher: remove macOS from the BLACKLIST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the test is stable in Qt 5.12. Task-number: QTBUG-60993 Change-Id: I0c366567121688d9518e90b5e8f9ec1b4006b7b9 Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST index fb7e025b7c..b1590a5ccf 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST +++ b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST @@ -1,7 +1,5 @@ [sendPostedEvents] windows -osx [registerTimer] windows -osx winrt -- cgit v1.2.3 From 95476bfcf64aa9cb43775ebfe3410ce9565de4d5 Mon Sep 17 00:00:00 2001 From: Ivan Komissarov Date: Mon, 22 Oct 2018 19:08:57 +0200 Subject: qendian: Fix float conversions Since Qt 5.10, qTo/FromBig/LittleEndian stopped working. It may be confusing, but big endian floats do exist, so not to break old code, we should support them. Change-Id: I21cdbc7f48ec030ce3d82f1cd1aad212f0fe5dd0 Reviewed-by: Thiago Macieira --- .../auto/corelib/global/qtendian/tst_qtendian.cpp | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp index 7043969c2f..2345bb39c1 100644 --- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp +++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp @@ -64,6 +64,9 @@ struct TestData quint16 data16; quint8 data8; + float dataFloat; + double dataDouble; + quint8 reserved; }; @@ -72,6 +75,7 @@ template <> quint8 getData(const TestData &d) { return d.data8; } template <> quint16 getData(const TestData &d) { return d.data16; } template <> quint32 getData(const TestData &d) { return d.data32; } template <> quint64 getData(const TestData &d) { return d.data64; } +template <> float getData(const TestData &d) { return d.dataFloat; } union RawTestData { @@ -79,9 +83,39 @@ union RawTestData TestData data; }; -static const TestData inNativeEndian = { Q_UINT64_C(0x0123456789abcdef), 0x00c0ffee, 0xcafe, 0xcf, '\0' }; -static const RawTestData inBigEndian = { "\x01\x23\x45\x67\x89\xab\xcd\xef" "\x00\xc0\xff\xee" "\xca\xfe" "\xcf" }; -static const RawTestData inLittleEndian = { "\xef\xcd\xab\x89\x67\x45\x23\x01" "\xee\xff\xc0\x00" "\xfe\xca" "\xcf" }; +template +Float int2Float(typename QIntegerForSizeof::Unsigned i) +{ + Float result = 0; + memcpy(reinterpret_cast(&result), reinterpret_cast(&i), sizeof (Float)); + return result; +} + +static const TestData inNativeEndian = { + Q_UINT64_C(0x0123456789abcdef), + 0x00c0ffee, + 0xcafe, + 0xcf, + int2Float(0x00c0ffeeU), + int2Float(Q_UINT64_C(0x0123456789abcdef)), + '\0' +}; +static const RawTestData inBigEndian = { + "\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x00\xc0\xff\xee" + "\xca\xfe" + "\xcf" + "\x00\xc0\xff\xee" + "\x01\x23\x45\x67\x89\xab\xcd\xef" +}; +static const RawTestData inLittleEndian = { + "\xef\xcd\xab\x89\x67\x45\x23\x01" + "\xee\xff\xc0\x00" + "\xfe\xca" + "\xcf" + "\xee\xff\xc0\x00" + "\xef\xcd\xab\x89\x67\x45\x23\x01" +}; #define EXPAND_ENDIAN_TEST(endian) \ do { \ -- cgit v1.2.3 From 0330b967f20bc265b9799418ce8e0b6faf929a62 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 29 Oct 2018 12:21:38 +0100 Subject: Simplify the Q_FOREACH macro when using C++17 This way there is only one for loop, which is more optimizer friendly Change-Id: Iaa02026627d5259c3eea1ff5664e8f22664eef73 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qglobal/qglobal.pro | 1 + tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 40 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qglobal/qglobal.pro b/tests/auto/corelib/global/qglobal/qglobal.pro index a40cb9a288..b105769430 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.pro +++ b/tests/auto/corelib/global/qglobal/qglobal.pro @@ -2,3 +2,4 @@ CONFIG += testcase TARGET = tst_qglobal QT = core testlib SOURCES = tst_qglobal.cpp qglobal.c +contains(QT_CONFIG, c++1z): CONFIG += c++1z diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 78b954f373..56da047147 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -126,6 +126,46 @@ void tst_QGlobal::for_each() QCOMPARE(i, counter++); } QCOMPARE(counter, list.count()); + + // Should also work with an existing variable + int local; + counter = 0; + foreach (local, list) { + QCOMPARE(local, counter++); + } + QCOMPARE(counter, list.count()); + QCOMPARE(local, counter - 1); + + // Test the macro does not mess if/else conditions + counter = 0; + if (true) + foreach (int i, list) + QCOMPARE(i, counter++); + else + QFAIL("If/Else mismatch"); + QCOMPARE(counter, list.count()); + + counter = 0; + if (false) + foreach (int i, list) + if (i) QFAIL("If/Else mismatch"); + else QFAIL("If/Else mismatch"); + else + foreach (int i, list) + if (false) { } + else QCOMPARE(i, counter++); + QCOMPARE(counter, list.count()); + + // break and continue + counter = 0; + foreach (int i, list) { + if (i == 0) + continue; + QCOMPARE(i, (counter++) + 1); + if (i == 3) + break; + } + QCOMPARE(counter, 3); } void tst_QGlobal::qassert() -- cgit v1.2.3 From 7e7514482fb2086fda100439a34b5b4ef627d329 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 25 Oct 2018 15:28:40 +0200 Subject: winrt: Skip a test row of tst_QRegularExpression::threadSafety PCRE2 does not support JIT on winrt. This test row takes a long time (30 seconds here) without JIT and thus might cause test timeouts in COIN when run on winrt. Change-Id: I79d9f6be16dbe16594ae2bf51f353acd06b3d2fe Reviewed-by: Simon Hausmann --- .../auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index f520e9742a..18098f16bf 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -2108,12 +2108,16 @@ void tst_QRegularExpression::threadSafety_data() QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; } + // pcre2 does not support JIT for winrt. As this test row takes a long time without JIT we skip + // it for winrt as it might time out in COIN. +#ifndef Q_OS_WINRT { QString subject = "ab"; subject.append(QString(512*1024, QLatin1Char('x'))); subject.append("c"); QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; } +#endif // Q_OS_WINRT { QString subject = "ab"; -- cgit v1.2.3 From 497f43c90f7160c1b198d829eab21c8c010fc7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Wed, 24 Oct 2018 12:46:04 +0200 Subject: tst_QCborValue: Disable support for spaceship operator Spaceship operator was disabled for QCborValue, but not the test. Change-Id: Icb91da689f62ef6de9f4fa926346505c5e50e9eb Reviewed-by: Thiago Macieira --- tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 38b26e7de4..4b753eab6b 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -330,7 +330,7 @@ void tst_QCborValue::copyCompare() QCOMPARE(v, other); QVERIFY(!(v != other)); QVERIFY(!(v < other)); -#if QT_HAS_INCLUDE() +#if 0 && QT_HAS_INCLUDE() QVERIFY(v <= other); QVERIFY(v >= other); QVERIFY(!(v > other)); -- cgit v1.2.3 From a952fd7d5b03ce1968ec58871fbb8b3600895900 Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Wed, 26 Sep 2018 10:29:14 +0300 Subject: QObject: Fix isSignalConnected() when signals have been disconnected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bitmap cache for the first 64 signals being connected was only set when the connection is added. It was never unset when the connection was removed. Internal use of the connectedSignals bitmap is not hurt by it occasionally saying a signal is connected even though it is not, since the purpose of those checks is avoiding expensive operations that are not necessary if nothing is connected to the signal. However, the public API using this cache meant that it also never spotted signals being disconnected. This was not documented. Fix the behavior by only using the cache if it is up to date. If it is not, use a slower path that gives the correct answer. To avoid making disconnections and QObject destructions slower, the cache is only updated to unset disconnected signals when new signal connections are added. No extra work is done in the common case where signals are only removed in the end of the QObject's lifetime. Fixes: QTBUG-32340 Change-Id: Ieb6e498060157153cec60d9c8f1c33056993fda1 Reviewed-by: Ville Voutilainen Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 68c6ece583..effc82261b 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -103,6 +103,7 @@ private slots: void deleteQObjectWhenDeletingEvent(); void overloads(); void isSignalConnected(); + void isSignalConnectedAfterDisconnection(); void qMetaObjectConnect(); void qMetaObjectDisconnectOne(); void sameName(); @@ -3835,6 +3836,58 @@ void tst_QObject::isSignalConnected() QVERIFY(!o.isSignalConnected(QMetaMethod())); } +void tst_QObject::isSignalConnectedAfterDisconnection() +{ + ManySignals o; + const QMetaObject *meta = o.metaObject(); + + const QMetaMethod sig00 = meta->method(meta->indexOfSignal("sig00()")); + QVERIFY(!o.isSignalConnected(sig00)); + QObject::connect(&o, &ManySignals::sig00, qt_noop); + QVERIFY(o.isSignalConnected(sig00)); + QVERIFY(QObject::disconnect(&o, &ManySignals::sig00, 0, 0)); + QVERIFY(!o.isSignalConnected(sig00)); + + const QMetaMethod sig69 = meta->method(meta->indexOfSignal("sig69()")); + QVERIFY(!o.isSignalConnected(sig69)); + QObject::connect(&o, &ManySignals::sig69, qt_noop); + QVERIFY(o.isSignalConnected(sig69)); + QVERIFY(QObject::disconnect(&o, &ManySignals::sig69, 0, 0)); + QVERIFY(!o.isSignalConnected(sig69)); + + { + ManySignals o2; + QObject::connect(&o, &ManySignals::sig00, &o2, &ManySignals::sig00); + QVERIFY(o.isSignalConnected(sig00)); + // o2 is destructed + } + QVERIFY(!o.isSignalConnected(sig00)); + + const QMetaMethod sig01 = meta->method(meta->indexOfSignal("sig01()")); + QObject::connect(&o, &ManySignals::sig00, qt_noop); + QObject::connect(&o, &ManySignals::sig01, qt_noop); + QObject::connect(&o, &ManySignals::sig69, qt_noop); + QVERIFY(o.isSignalConnected(sig00)); + QVERIFY(o.isSignalConnected(sig01)); + QVERIFY(o.isSignalConnected(sig69)); + QVERIFY(QObject::disconnect(&o, &ManySignals::sig69, 0, 0)); + QVERIFY(o.isSignalConnected(sig00)); + QVERIFY(o.isSignalConnected(sig01)); + QVERIFY(!o.isSignalConnected(sig69)); + QVERIFY(QObject::disconnect(&o, &ManySignals::sig00, 0, 0)); + QVERIFY(!o.isSignalConnected(sig00)); + QVERIFY(o.isSignalConnected(sig01)); + QVERIFY(!o.isSignalConnected(sig69)); + QObject::connect(&o, &ManySignals::sig69, qt_noop); + QVERIFY(!o.isSignalConnected(sig00)); + QVERIFY(o.isSignalConnected(sig01)); + QVERIFY(o.isSignalConnected(sig69)); + QVERIFY(QObject::disconnect(&o, &ManySignals::sig01, 0, 0)); + QVERIFY(!o.isSignalConnected(sig00)); + QVERIFY(!o.isSignalConnected(sig01)); + QVERIFY(o.isSignalConnected(sig69)); +} + void tst_QObject::qMetaObjectConnect() { SenderObject *s = new SenderObject; -- cgit v1.2.3 From 779a73762de6addb2a2e3fee5b98d00d64101b92 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 14 Sep 2018 14:59:21 +0200 Subject: Fully support operator[] on QCborValue and QCborValueRef Added operator[] to QCborValueRef and mutating operator[] both there and in QCborValue. If the value (referenced) is not a container, it is replaced with a map and a reference into the result is returned. If the value is an array and the key is a string, negative, or more than 0xffff, the array is first converted to a map. Change-Id: Ibbc9e480fb25eb3d05547c8a1b99e762b2a68b68 Reviewed-by: Thiago Macieira --- .../serialization/qcborvalue/tst_qcborvalue.cpp | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index c609aa6621..f69ce4120d 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -384,11 +384,17 @@ void tst_QCborValue::arrayDefaultInitialization() QVERIFY(v.isArray()); QVERIFY(!v.isMap()); QVERIFY(!v.isTag()); - QVERIFY(v[0].isUndefined()); QCborArray a2 = v.toArray(); QVERIFY(a2.isEmpty()); QCOMPARE(a2, a); + auto front = v[0]; + QVERIFY(front.isUndefined()); + front = 1; + QCOMPARE(v[0], 1); + QVERIFY(a2.isEmpty()); + a2 = v.toArray(); + QCOMPARE(a2.size(), 1); } void tst_QCborValue::mapDefaultInitialization() @@ -425,7 +431,7 @@ void tst_QCborValue::mapDefaultInitialization() QVERIFY(m == QCborMap{}); QVERIFY(QCborMap{} == m); - QCborValue v(m); + const QCborValue v(m); QVERIFY(v.isMap()); QVERIFY(!v.isArray()); QVERIFY(!v.isTag()); @@ -727,6 +733,31 @@ void tst_QCborValue::arrayMutation() QCOMPARE(a.at(1), QCborValue(-1)); QCOMPARE(a2.at(1), QCborValue(nullptr)); QCOMPARE(++it, end); + + // Array accessed via value: + QCborValue val(a); + val[2] = QCborArray{2, 3, 5, 7}; + QCOMPARE(a.size(), 2); // Unchanged + QVERIFY(val.isArray()); + QCOMPARE(val.toArray().size(), 3); + val[2][4] = 17; + QVERIFY(val.isArray()); + QVERIFY(val[2].isArray()); + QCOMPARE(val[2].toArray().size(), 5); + QCOMPARE(val[2][4], 17); + QCOMPARE(val.toArray().size(), 3); + val[3] = 42; + QVERIFY(val.isArray()); + QCOMPARE(val.toArray().size(), 4); + QCOMPARE(val[3], 42); + + // Coerce to map on string key: + const QLatin1String any("any"); + val[any] = any; + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 5); + QVERIFY(val[2].isArray()); + QCOMPARE(val[2].toArray().size(), 5); } void tst_QCborValue::mapMutation() @@ -782,6 +813,30 @@ void tst_QCborValue::mapMutation() QCOMPARE((m.end() - 1)->toInteger(), -1); QVERIFY((m2.end() - 1)->isNull()); QCOMPARE(++it, end); + + // Map accessed via value: + QCborValue val(m); + val[7] = QCborMap({{0, 2}, {1, 3}, {2, 5}}); + QCOMPARE(m.size(), 2); // Unchanged + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 3); + val[7][3] = 11; + QVERIFY(val.isMap()); + QVERIFY(val[7].isMap()); + QCOMPARE(val[7].toMap().size(), 4); + val[14] = 42; + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 4); + + const QLatin1String any("any"); + const QString hello(QStringLiteral("Hello World")); + val[any][3][hello] = any; + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 5); + QVERIFY(val[any].isMap()); + QCOMPARE(val[any].toMap().size(), 1); + QVERIFY(val[any][3].isMap()); + QCOMPARE(val[any][3].toMap().size(), 1); } void tst_QCborValue::arrayPrepend() -- cgit v1.2.3 From 00674a1643422de2e56ac23c89174c0ead83eb18 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 25 Sep 2018 15:02:58 +0200 Subject: Treat shorts as int in QVariant::canConvert() Follow the pattern of char and float, and treat shorts as a more generic type in QVariant::canConvert() Task-number: QTBUG-60914 Change-Id: Ib1cc7941ee47cb0fc0098f22f98a03cd6f6b63fe Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 0780fb9172..4da34c407e 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -525,6 +525,12 @@ void tst_QVariant::canConvert_data() var = QVariant::fromValue(-1); QTest::newRow("SChar") << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant((short)-3); + QTest::newRow("Short") + << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant((ushort)7); + QTest::newRow("UShort") + << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; var = QVariant::fromValue(QJsonValue(QStringLiteral("hello"))); QTest::newRow("JsonValue") << var << N << N << Y << N << N << N << N << N << N << Y << N << N << Y << N << N << Y << Y << Y << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; @@ -563,6 +569,8 @@ void tst_QVariant::toInt_data() QTest::newRow( "char" ) << QVariant::fromValue('a') << int('a') << true; signed char signedChar = -13; QTest::newRow( "signed char" ) << QVariant::fromValue(signedChar) << -13 << true; + QTest::newRow( "short" ) << QVariant::fromValue(short(-7)) << int(-7) << true; + QTest::newRow( "ushort" ) << QVariant::fromValue(ushort(30000)) << 30000 << true; QTest::newRow( "double" ) << QVariant( 3.1415927 ) << 3 << true; QTest::newRow( "float" ) << QVariant( 3.1415927f ) << 3 << true; QTest::newRow( "uint" ) << QVariant( 123u ) << 123 << true; -- cgit v1.2.3 From e3c84b6da1cbef7ed779ba5eec6ae3ed8e4e5d59 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Tue, 23 Oct 2018 14:17:29 +0800 Subject: QMimeType: Use default key as fallback for comment() property When QMimeProvider parses the shared mime database xml files, it will read the element for mime comment and treat the `xml:lang` attribute as locale language string. When no `xml:lang` attr is provided, QMimeProvider will read the value and treat it as a en_US locale string as the default key. When we call QMimeType::comment(), it will try to get the locale comment string with the default language (QLocale().name()), once it can't find a matched result, it should return the default key (which QMimeProvider set it as en_US locale before) as fallback. Task-number: QTBUG-71314 Change-Id: I444f8159d6f19dfef6338cd79312f608d8f13394 Reviewed-by: David Faure --- .../corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 597d51e7e0..9df52887f7 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -992,6 +992,20 @@ void tst_QMimeDatabase::installNewGlobalMimeType() const QString fooTestFile2 = QLatin1String(RESOURCE_PREFIX "magic-and-hierarchy2.foo"); QCOMPARE(db.mimeTypeForFile(fooTestFile2).name(), QString::fromLatin1("application/vnd.qnx.bar-descriptor")); + // Test if we can use the default comment + { + struct RestoreLocale + { + ~RestoreLocale() { QLocale::setDefault(QLocale::c()); } + } restoreLocale; + + QLocale::setDefault(QLocale("zh_CN")); + QMimeType suseymp = db.mimeTypeForName("text/x-suse-ymp"); + QVERIFY(suseymp.isValid()); + QCOMPARE(suseymp.comment(), + QString::fromLatin1("YaST Meta Package")); + } + // Now test removing the mimetype definitions again for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) QFile::remove(destDir + m_additionalMimeFileNames.at(i)); -- cgit v1.2.3 From e9bebc12812b5c50346952cd9128bdd08ddd0b9d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 18 Oct 2018 22:45:09 +0200 Subject: Fix use of deprecated ItemDataRoles Background/TextColorRole Replace BackgroundColorRole/TextColorRole with BackgroundRole/ForegroundRole and explicit deprecate them for 5.13 Change-Id: I6b0d99844a32d2f5fdfd1878317a7b7422b800d3 Reviewed-by: Samuel Gaist Reviewed-by: Luca Beldi Reviewed-by: Richard Moe Gustavsen --- tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp | 4 ++-- tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp index 6ea7a38137..dbc7173028 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp @@ -251,7 +251,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) QString val = xval + QString::number(y) + QString::number(i); QModelIndex index = model->index(x, y, parent); model->setData(index, val); - model->setData(index, blue, Qt::TextColorRole); + model->setData(index, blue, Qt::ForegroundRole); } } */ @@ -276,7 +276,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) QString val = xval + QString::number(y) + QString::number(i); QModelIndex index = realModel->index(x, y, parent); realModel->setData(index, val); - realModel->setData(index, blue, Qt::TextColorRole); + realModel->setData(index, blue, Qt::ForegroundRole); } } */ diff --git a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp index 7cd220e684..da13b9f33f 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp @@ -576,12 +576,12 @@ void tst_QItemModel::data() alignment == Qt::AlignJustify); } - QVariant colorVariant = currentModel->data(currentModel->index(0,0), Qt::BackgroundColorRole); + QVariant colorVariant = currentModel->data(currentModel->index(0,0), Qt::BackgroundRole); if (colorVariant.isValid()) { QVERIFY(colorVariant.canConvert()); } - colorVariant = currentModel->data(currentModel->index(0,0), Qt::TextColorRole); + colorVariant = currentModel->data(currentModel->index(0,0), Qt::ForegroundRole); if (colorVariant.isValid()) { QVERIFY(colorVariant.canConvert()); } -- cgit v1.2.3 From 6963efb396f7f206afb2f3f9655f26b0c21b6a05 Mon Sep 17 00:00:00 2001 From: Luca Beldi Date: Mon, 5 Nov 2018 12:17:31 +0000 Subject: New proxy model: QTransposeProxyModel Implemented a new proxy model to transpose the source model. Rows will become columns and vice-versa. Both flat and tree models supported. [ChangeLog][QtCore] New class QTransposeProxyModel to swap rows and columns of the source model. Change-Id: I902963c6b81aa0f63b5ad2bddca538f28b565084 Reviewed-by: David Faure --- tests/auto/corelib/itemmodels/itemmodels.pro | 1 + .../qtransposeproxymodel/qtransposeproxymodel.pro | 6 + .../tst_qtransposeproxymodel.cpp | 915 +++++++++++++++++++++ 3 files changed, 922 insertions(+) create mode 100644 tests/auto/corelib/itemmodels/qtransposeproxymodel/qtransposeproxymodel.pro create mode 100644 tests/auto/corelib/itemmodels/qtransposeproxymodel/tst_qtransposeproxymodel.cpp (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/itemmodels.pro b/tests/auto/corelib/itemmodels/itemmodels.pro index b27938e0c0..ffbda6ec40 100644 --- a/tests/auto/corelib/itemmodels/itemmodels.pro +++ b/tests/auto/corelib/itemmodels/itemmodels.pro @@ -9,6 +9,7 @@ qtHaveModule(gui): SUBDIRS += \ qidentityproxymodel \ qitemselectionmodel \ qsortfilterproxymodel_recursive \ + qtransposeproxymodel \ qtHaveModule(widgets) { SUBDIRS += \ diff --git a/tests/auto/corelib/itemmodels/qtransposeproxymodel/qtransposeproxymodel.pro b/tests/auto/corelib/itemmodels/qtransposeproxymodel/qtransposeproxymodel.pro new file mode 100644 index 0000000000..3834add115 --- /dev/null +++ b/tests/auto/corelib/itemmodels/qtransposeproxymodel/qtransposeproxymodel.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_qtransposeproxymodel +QT = core gui testlib + +SOURCES = tst_qtransposeproxymodel.cpp + diff --git a/tests/auto/corelib/itemmodels/qtransposeproxymodel/tst_qtransposeproxymodel.cpp b/tests/auto/corelib/itemmodels/qtransposeproxymodel/tst_qtransposeproxymodel.cpp new file mode 100644 index 0000000000..a30ac46571 --- /dev/null +++ b/tests/auto/corelib/itemmodels/qtransposeproxymodel/tst_qtransposeproxymodel.cpp @@ -0,0 +1,915 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Luca Beldi +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include + +class tst_QTransposeProxyModel : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void initTestCase(); + void index(); + void data(); + void setData_data(); + void setData(); + void parent(); + void mapToSource(); + void mapFromSource(); + void basicTest_data(); + void basicTest(); + void sort(); + void insertRowBase_data(); + void insertRowBase(); + void insertColumnBase_data(); + void insertColumnBase(); + void insertColumnProxy_data(); + void insertColumnProxy(); + void insertRowProxy_data(); + void insertRowProxy(); + void removeRowBase_data(); + void removeRowBase(); + void removeColumnBase_data(); + void removeColumnBase(); + void removeColumnProxy_data(); + void removeColumnProxy(); + void removeRowProxy_data(); + void removeRowProxy(); + void headerData(); + void setHeaderData(); + void span(); + void itemData(); + void setItemData(); + void moveRowsBase(); + void moveColumnsProxy(); +private: + void testTransposed( + const QAbstractItemModel *const baseModel, + const QAbstractItemModel *const transposed, + const QModelIndex &baseParent = QModelIndex(), + const QModelIndex &transposedParent = QModelIndex() + ); + QAbstractItemModel *createListModel(QObject *parent); + QAbstractItemModel *createTableModel(QObject *parent); + QAbstractItemModel *createTreeModel(QObject *parent); +}; + +QAbstractItemModel *tst_QTransposeProxyModel::createListModel(QObject *parent) +{ + QStringList sequence; + sequence.reserve(10); + for (int i = 0; i < 10; ++i) + sequence.append(QString::number(i)); + return new QStringListModel(sequence, parent); +} + +QAbstractItemModel *tst_QTransposeProxyModel::createTableModel(QObject *parent) +{ + QAbstractItemModel *model = new QStandardItemModel(parent); + model->insertRows(0, 5); + model->insertColumns(0, 4); + for (int i = 0; i < model->rowCount(); ++i) { + for (int j = 0; j < model->columnCount(); ++j) { + model->setData(model->index(i, j), QStringLiteral("%1,%2").arg(i).arg(j), Qt::EditRole); + model->setData(model->index(i, j), i, Qt::UserRole); + model->setData(model->index(i, j), j, Qt::UserRole + 1); + } + } + return model; +} + +QAbstractItemModel *tst_QTransposeProxyModel::createTreeModel(QObject *parent) +{ + QAbstractItemModel *model = new QStandardItemModel(parent); + model->insertRows(0, 5); + model->insertColumns(0, 4); + for (int i = 0; i < model->rowCount(); ++i) { + for (int j = 0; j < model->columnCount(); ++j) { + const QModelIndex parIdx = model->index(i, j); + model->setData(parIdx, QStringLiteral("%1,%2").arg(i).arg(j), Qt::EditRole); + model->setData(parIdx, i, Qt::UserRole); + model->setData(parIdx, j, Qt::UserRole + 1); + model->insertRows(0, 3, parIdx); + model->insertColumns(0, 2, parIdx); + for (int h = 0; h < model->rowCount(parIdx); ++h) { + for (int k = 0; k < model->columnCount(parIdx); ++k) { + const QModelIndex childIdx = model->index(h, k, parIdx); + model->setData(childIdx, QStringLiteral("%1,%2,%3,%4").arg(i).arg(j).arg(h).arg(k), Qt::EditRole); + model->setData(childIdx, i, Qt::UserRole); + model->setData(childIdx, j, Qt::UserRole + 1); + model->setData(childIdx, h, Qt::UserRole + 2); + model->setData(childIdx, k, Qt::UserRole + 3); + } + } + } + } + return model; +} + +void tst_QTransposeProxyModel::testTransposed( + const QAbstractItemModel *const baseModel, + const QAbstractItemModel *const transposed, + const QModelIndex &baseParent, + const QModelIndex &transposedParent +) +{ + QCOMPARE(transposed->hasChildren(transposedParent), baseModel->hasChildren(baseParent)); + QCOMPARE(transposed->columnCount(transposedParent), baseModel->rowCount(baseParent)); + QCOMPARE(transposed->rowCount(transposedParent), baseModel->columnCount(baseParent)); + for (int i = 0, maxRow = baseModel->rowCount(baseParent); i < maxRow; ++i) { + for (int j = 0, maxCol = baseModel->columnCount(baseParent); j < maxCol; ++j) { + const QModelIndex baseIdx = baseModel->index(i, j, baseParent); + const QModelIndex transIdx = transposed->index(j, i, transposedParent); + QCOMPARE(transIdx.data(), baseIdx.data()); + QCOMPARE(transIdx.data(Qt::UserRole), baseIdx.data(Qt::UserRole)); + QCOMPARE(transIdx.data(Qt::UserRole + 1), baseIdx.data(Qt::UserRole + 1)); + QCOMPARE(transIdx.data(Qt::UserRole + 2), baseIdx.data(Qt::UserRole + 2)); + QCOMPARE(transIdx.data(Qt::UserRole + 3), baseIdx.data(Qt::UserRole + 3)); + if (baseModel->hasChildren(baseIdx)) { + testTransposed(baseModel, transposed, baseIdx, transIdx); + } + } + } +} + +void tst_QTransposeProxyModel::initTestCase() +{ + qRegisterMetaType >(); + qRegisterMetaType(); +} + +void tst_QTransposeProxyModel::index() +{ + QAbstractItemModel *model = createTreeModel(this); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + QVERIFY(!proxy.index(0, -1).isValid()); + QVERIFY(!proxy.index(0, -1).isValid()); + QVERIFY(!proxy.index(-1, -1).isValid()); + QVERIFY(!proxy.index(0, proxy.columnCount()).isValid()); + QVERIFY(!proxy.index(proxy.rowCount(), 0).isValid()); + QVERIFY(!proxy.index(proxy.rowCount(), proxy.columnCount()).isValid()); + QModelIndex tempIdx = proxy.index(0, 1); + QVERIFY(tempIdx.isValid()); + QCOMPARE(tempIdx.row(), 0); + QCOMPARE(tempIdx.column(), 1); + tempIdx = proxy.index(0, 1, tempIdx); + QVERIFY(tempIdx.isValid()); + QCOMPARE(tempIdx.row(), 0); + QCOMPARE(tempIdx.column(), 1); + delete model; +} + +void tst_QTransposeProxyModel::data() +{ + QStringListModel model{QStringList{"A", "B"}}; + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(&model); + QCOMPARE(proxy.index(0, 1).data().toString(), QStringLiteral("B")); +} + +void tst_QTransposeProxyModel::parent() +{ + QAbstractItemModel *model = createTreeModel(this); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + const QModelIndex parentIdx = proxy.index(0, 0); + const QModelIndex childIdx = proxy.index(0, 0, parentIdx); + QVERIFY(parentIdx.isValid()); + QVERIFY(childIdx.isValid()); + QCOMPARE(childIdx.parent(), parentIdx); + delete model; +} + +void tst_QTransposeProxyModel::mapToSource() +{ + QAbstractItemModel *model = createTreeModel(this); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + QVERIFY(!proxy.mapToSource(QModelIndex()).isValid()); + QCOMPARE(proxy.mapToSource(proxy.index(0, 0)), model->index(0, 0)); + QCOMPARE(proxy.mapToSource(proxy.index(1, 0)), model->index(0, 1)); + QCOMPARE(proxy.mapToSource(proxy.index(0, 1)), model->index(1, 0)); + const QModelIndex proxyParent = proxy.index(1, 0); + const QModelIndex sourceParent = model->index(0, 1); + QCOMPARE(proxy.mapToSource(proxy.index(0, 0, proxyParent)), model->index(0, 0, sourceParent)); + QCOMPARE(proxy.mapToSource(proxy.index(1, 0, proxyParent)), model->index(0, 1, sourceParent)); + QCOMPARE(proxy.mapToSource(proxy.index(0, 1, proxyParent)), model->index(1, 0, sourceParent)); + delete model; +} + +void tst_QTransposeProxyModel::mapFromSource() +{ + QAbstractItemModel *model = createTreeModel(this); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + QVERIFY(!proxy.mapFromSource(QModelIndex()).isValid()); + QCOMPARE(proxy.mapFromSource(model->index(0, 0)), proxy.index(0, 0)); + QCOMPARE(proxy.mapFromSource(model->index(0, 1)), proxy.index(1, 0)); + QCOMPARE(proxy.mapFromSource(model->index(1, 0)), proxy.index(0, 1)); + const QModelIndex proxyParent = proxy.index(1, 0); + const QModelIndex sourceParent = model->index(0, 1); + QCOMPARE(proxy.mapToSource(proxy.index(0, 0, proxyParent)), model->index(0, 0, sourceParent)); + QCOMPARE(proxy.mapFromSource(model->index(1, 0, sourceParent)), proxy.index(0, 1, proxyParent)); + QCOMPARE(proxy.mapFromSource(model->index(0, 1, sourceParent)), proxy.index(1, 0, proxyParent)); + delete model; +} + +void tst_QTransposeProxyModel::basicTest_data() +{ + QTest::addColumn("model"); + QTest::newRow("List") << createListModel(this); + QTest::newRow("Table") << createTableModel(this); + QTest::newRow("Tree") << createTreeModel(this); +} + +void tst_QTransposeProxyModel::basicTest() +{ + QFETCH(QAbstractItemModel *, model); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + testTransposed(model, &proxy); + delete model; +} + +void tst_QTransposeProxyModel::sort() +{ + QStringList sequence; + sequence.reserve(100); + for (int i = 0; i < 100; ++i) + sequence.append(QStringLiteral("%1").arg(i, 3, 10, QLatin1Char('0'))); + std::shuffle(sequence.begin(), sequence.end(), std::mt19937(88)); + const QString firstItemBeforeSort = sequence.first(); + QStringListModel baseModel(sequence); + QTransposeProxyModel proxyModel; + new QAbstractItemModelTester(&proxyModel, &proxyModel); + proxyModel.setSourceModel(&baseModel); + QSignalSpy layoutChangedSpy(&proxyModel, &QAbstractItemModel::layoutChanged); + QVERIFY(layoutChangedSpy.isValid()); + QSignalSpy layoutAboutToBeChangedSpy(&proxyModel, &QAbstractItemModel::layoutAboutToBeChanged); + QVERIFY(layoutAboutToBeChangedSpy.isValid()); + QPersistentModelIndex firstIndexBeforeSort = proxyModel.index(0, 0); + baseModel.sort(0, Qt::AscendingOrder); + QCOMPARE(layoutChangedSpy.count(), 1); + QCOMPARE(layoutAboutToBeChangedSpy.count(), 1); + QCOMPARE(layoutChangedSpy.takeFirst().at(1).toInt(), int(QAbstractItemModel::HorizontalSortHint)); + QCOMPARE(firstIndexBeforeSort.data().toString(), firstItemBeforeSort); + for (int i = 0; i < 100; ++i) + QCOMPARE(proxyModel.index(0, i).data().toInt(), i); +} + +void tst_QTransposeProxyModel::removeColumnBase_data() +{ + QTest::addColumn("model"); + QTest::addColumn("parent"); + QTest::newRow("Table") << createTableModel(this) << QModelIndex(); + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << QModelIndex(); + QAbstractItemModel *model = createTreeModel(this); + QTest::newRow("Tree_Child_Item") << model << model->index(0, 0); +} + +void tst_QTransposeProxyModel::removeColumnBase() +{ + QFETCH(QAbstractItemModel * const, model); + QFETCH(const QModelIndex, parent); + QTransposeProxyModel proxy; + QSignalSpy rowRemoveSpy(&proxy, &QAbstractItemModel::rowsRemoved); + QVERIFY(rowRemoveSpy.isValid()); + QSignalSpy rowAboutToBeRemoveSpy(&proxy, &QAbstractItemModel::rowsAboutToBeRemoved); + QVERIFY(rowAboutToBeRemoveSpy.isValid()); + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + const int oldRowCount = proxy.rowCount(proxy.mapFromSource(parent)); + const QVariant expectedNewVal = model->index(0, 2, parent).data(); + QVERIFY(model->removeColumn(1, parent)); + QCOMPARE(proxy.rowCount(proxy.mapFromSource(parent)), oldRowCount - 1); + QCOMPARE(proxy.index(1, 0, proxy.mapFromSource(parent)).data(), expectedNewVal); + QCOMPARE(rowRemoveSpy.count(), 1); + QCOMPARE(rowAboutToBeRemoveSpy.count(), 1); + for (const auto &spyArgs : {rowRemoveSpy.takeFirst(), + rowAboutToBeRemoveSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxy.mapFromSource(parent)); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::insertColumnBase_data() +{ + QTest::addColumn("model"); + QTest::addColumn("parent"); + QTest::newRow("Table") << createTableModel(this) << QModelIndex(); + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << QModelIndex(); + QAbstractItemModel *model = createTreeModel(this); + QTest::newRow("Tree_Child_Item") << model << model->index(0, 0); +} + +void tst_QTransposeProxyModel::insertColumnBase() +{ + QFETCH(QAbstractItemModel * const, model); + QFETCH(const QModelIndex, parent); + QTransposeProxyModel proxy; + QSignalSpy rowInsertSpy(&proxy, &QAbstractItemModel::rowsInserted); + QVERIFY(rowInsertSpy.isValid()); + QSignalSpy rowAboutToBeInsertSpy(&proxy, &QAbstractItemModel::rowsAboutToBeInserted); + QVERIFY(rowAboutToBeInsertSpy.isValid()); + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + const int oldRowCount = proxy.rowCount(proxy.mapFromSource(parent)); + QVERIFY(model->insertColumn(1, parent)); + QCOMPARE(proxy.rowCount(proxy.mapFromSource(parent)), oldRowCount + 1); + QVERIFY(!proxy.index(1, 0, proxy.mapFromSource(parent)).data().isValid()); + QCOMPARE(rowInsertSpy.count(), 1); + QCOMPARE(rowAboutToBeInsertSpy.count(), 1); + for (const auto &spyArgs : {rowInsertSpy.takeFirst(), + rowAboutToBeInsertSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxy.mapFromSource(parent)); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::removeRowBase_data() +{ + QTest::addColumn("model"); + QTest::addColumn("parent"); + QTest::newRow("List") << createListModel(this) << QModelIndex(); + QTest::newRow("Table") << createTableModel(this) << QModelIndex(); + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << QModelIndex(); + QAbstractItemModel *model = createTreeModel(this); + QTest::newRow("Tree_Child_Item") << model << model->index(0, 0); +} + +void tst_QTransposeProxyModel::removeRowBase() +{ + QFETCH(QAbstractItemModel * const, model); + QFETCH(const QModelIndex, parent); + QTransposeProxyModel proxy; + QSignalSpy columnsRemoveSpy(&proxy, &QAbstractItemModel::columnsRemoved); + QVERIFY(columnsRemoveSpy.isValid()); + QSignalSpy columnsAboutToBeRemoveSpy(&proxy, &QAbstractItemModel::columnsAboutToBeRemoved); + QVERIFY(columnsAboutToBeRemoveSpy.isValid()); + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + const int oldColCount = proxy.columnCount(proxy.mapFromSource(parent)); + const QVariant expectedNewVal = model->index(2, 0, parent).data(); + QVERIFY(model->removeRow(1, parent)); + QCOMPARE(proxy.columnCount(proxy.mapFromSource(parent)), oldColCount - 1); + QCOMPARE(proxy.index(0, 1, proxy.mapFromSource(parent)).data(), expectedNewVal); + QCOMPARE(columnsRemoveSpy.count(), 1); + QCOMPARE(columnsAboutToBeRemoveSpy.count(), 1); + for (const auto &spyArgs : {columnsRemoveSpy.takeFirst(), + columnsAboutToBeRemoveSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxy.mapFromSource(parent)); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::insertRowBase_data() +{ + QTest::addColumn("model"); + QTest::addColumn("parent"); + QTest::newRow("List") << createListModel(this) << QModelIndex(); + QTest::newRow("Table") << createTableModel(this) << QModelIndex(); + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << QModelIndex(); + QAbstractItemModel *model = createTreeModel(this); + QTest::newRow("Tree_Child_Item") << model << model->index(0, 0); +} + +void tst_QTransposeProxyModel::insertRowBase() +{ + QFETCH(QAbstractItemModel * const, model); + QFETCH(const QModelIndex, parent); + QTransposeProxyModel proxy; + QSignalSpy columnsInsertSpy(&proxy, &QAbstractItemModel::columnsInserted); + QVERIFY(columnsInsertSpy.isValid()); + QSignalSpy columnsAboutToBeInsertSpy(&proxy, &QAbstractItemModel::columnsAboutToBeInserted); + QVERIFY(columnsAboutToBeInsertSpy.isValid()); + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + const int oldColCount = proxy.columnCount(proxy.mapFromSource(parent)); + QVERIFY(model->insertRow(1, parent)); + QCOMPARE(proxy.columnCount(proxy.mapFromSource(parent)), oldColCount + 1); + QVERIFY(proxy.index(0, 1, proxy.mapFromSource(parent)).data().isNull()); + QCOMPARE(columnsInsertSpy.count(), 1); + QCOMPARE(columnsAboutToBeInsertSpy.count(), 1); + for (const auto &spyArgs : {columnsInsertSpy.takeFirst(), + columnsAboutToBeInsertSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxy.mapFromSource(parent)); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::removeColumnProxy_data() +{ + QTest::addColumn("model"); + QTest::addColumn("rootItem"); + QTest::newRow("List") << createListModel(this) << true; + QTest::newRow("Table") << createTableModel(this) << true; + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << true; + QTest::newRow("Tree_Child_Item") << createTreeModel(this) << false; +} + +void tst_QTransposeProxyModel::removeColumnProxy() +{ + QFETCH(QAbstractItemModel *, model); + QFETCH(bool, rootItem); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + QSignalSpy columnsRemoveSpy(&proxy, &QAbstractItemModel::columnsRemoved); + QVERIFY(columnsRemoveSpy.isValid()); + QSignalSpy columnsAboutToBeRemoveSpy(&proxy, &QAbstractItemModel::columnsAboutToBeRemoved); + QVERIFY(columnsAboutToBeRemoveSpy.isValid()); + QSignalSpy rowsRemoveSpy(model, &QAbstractItemModel::rowsRemoved); + QVERIFY(rowsRemoveSpy.isValid()); + QSignalSpy rowsAboutToBeRemoveSpy(model, &QAbstractItemModel::rowsAboutToBeRemoved); + QVERIFY(rowsAboutToBeRemoveSpy.isValid()); + proxy.setSourceModel(model); + const QModelIndex proxyParent = rootItem ? QModelIndex() : proxy.index(0, 1); + const QModelIndex sourceParent = proxy.mapToSource(proxyParent); + const int oldColCount = proxy.columnCount(proxyParent); + const int oldRowCount = model->rowCount(sourceParent); + const QVariant expectedNewVal = proxy.index(0, 2, proxyParent).data(); + QVERIFY(proxy.removeColumn(1, proxyParent)); + QCOMPARE(proxy.columnCount(proxyParent), oldColCount - 1); + QCOMPARE(model->rowCount(sourceParent), oldRowCount - 1); + QCOMPARE(proxy.index(0, 1, proxyParent).data(), expectedNewVal); + QCOMPARE(model->index(1, 0, sourceParent).data(), expectedNewVal); + QCOMPARE(columnsRemoveSpy.count(), 1); + QCOMPARE(columnsAboutToBeRemoveSpy.count(), 1); + QCOMPARE(rowsRemoveSpy.count(), 1); + QCOMPARE(rowsAboutToBeRemoveSpy.count(), 1); + for (const auto &spyArgs : {columnsRemoveSpy.takeFirst(), + columnsAboutToBeRemoveSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxyParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + for (const auto &spyArgs : {rowsRemoveSpy.takeFirst(), + rowsAboutToBeRemoveSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), sourceParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::insertColumnProxy_data() +{ + QTest::addColumn("model"); + QTest::addColumn("rootItem"); + QTest::newRow("List") << createListModel(this) << true; + QTest::newRow("Table") << createTableModel(this) << true; + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << true; + QTest::newRow("Tree_Child_Item") << createTreeModel(this) << false; +} + +void tst_QTransposeProxyModel::insertColumnProxy() +{ + QFETCH(QAbstractItemModel *, model); + QFETCH(bool, rootItem); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + QSignalSpy columnsInsertSpy(&proxy, &QAbstractItemModel::columnsInserted); + QVERIFY(columnsInsertSpy.isValid()); + QSignalSpy columnsAboutToBeInsertSpy(&proxy, &QAbstractItemModel::columnsAboutToBeInserted); + QVERIFY(columnsAboutToBeInsertSpy.isValid()); + QSignalSpy rowsInsertSpy(model, &QAbstractItemModel::rowsInserted); + QVERIFY(rowsInsertSpy.isValid()); + QSignalSpy rowsAboutToBeInsertSpy(model, &QAbstractItemModel::rowsAboutToBeInserted); + QVERIFY(rowsAboutToBeInsertSpy.isValid()); + proxy.setSourceModel(model); + const QModelIndex proxyParent = rootItem ? QModelIndex() : proxy.index(0, 1); + const QModelIndex sourceParent = proxy.mapToSource(proxyParent); + const int oldColCount = proxy.columnCount(proxyParent); + const int oldRowCount = model->rowCount(sourceParent); + QVERIFY(proxy.insertColumn(1, proxyParent)); + QCOMPARE(proxy.columnCount(proxyParent), oldColCount + 1); + QCOMPARE(model->rowCount(sourceParent), oldRowCount + 1); + QVERIFY(proxy.index(0, 1, proxyParent).data().isNull()); + QVERIFY(model->index(1, 0, sourceParent).data().isNull()); + QCOMPARE(columnsInsertSpy.count(), 1); + QCOMPARE(columnsAboutToBeInsertSpy.count(), 1); + QCOMPARE(rowsInsertSpy.count(), 1); + QCOMPARE(rowsAboutToBeInsertSpy.count(), 1); + for (const auto &spyArgs : {columnsInsertSpy.takeFirst(), + columnsAboutToBeInsertSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxyParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + for (const auto &spyArgs : {rowsInsertSpy.takeFirst(), + rowsAboutToBeInsertSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), sourceParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::removeRowProxy_data() +{ + QTest::addColumn("model"); + QTest::addColumn("rootItem"); + QTest::newRow("Table") << createTableModel(this) << true; + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << true; + QTest::newRow("Tree_Child_Item") << createTreeModel(this) << false; +} + +void tst_QTransposeProxyModel::removeRowProxy() +{ + QFETCH(QAbstractItemModel *, model); + QFETCH(bool, rootItem); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + QSignalSpy rowsRemoveSpy(&proxy, &QAbstractItemModel::rowsRemoved); + QVERIFY(rowsRemoveSpy.isValid()); + QSignalSpy rowsAboutToBeRemoveSpy(&proxy, &QAbstractItemModel::rowsAboutToBeRemoved); + QVERIFY(rowsAboutToBeRemoveSpy.isValid()); + QSignalSpy columnsRemoveSpy(model, &QAbstractItemModel::columnsRemoved); + QVERIFY(columnsRemoveSpy.isValid()); + QSignalSpy columnsAboutToBeRemoveSpy(model, &QAbstractItemModel::columnsAboutToBeRemoved); + QVERIFY(columnsAboutToBeRemoveSpy.isValid()); + proxy.setSourceModel(model); + const QModelIndex proxyParent = rootItem ? QModelIndex() : proxy.index(0, 1); + const QModelIndex sourceParent = proxy.mapToSource(proxyParent); + const int oldRowCount = proxy.rowCount(proxyParent); + const int oldColCount = model->columnCount(sourceParent); + const QVariant expectedNewVal = proxy.index(2, 0, proxyParent).data(); + QVERIFY(proxy.removeRow(1, proxyParent)); + QCOMPARE(proxy.rowCount(proxyParent), oldRowCount - 1); + QCOMPARE(model->columnCount(sourceParent), oldColCount - 1); + QCOMPARE(proxy.index(1, 0, proxyParent).data(), expectedNewVal); + QCOMPARE(model->index(0, 1, sourceParent).data(), expectedNewVal); + QCOMPARE(columnsRemoveSpy.count(), 1); + QCOMPARE(columnsAboutToBeRemoveSpy.count(), 1); + QCOMPARE(rowsRemoveSpy.count(), 1); + QCOMPARE(rowsAboutToBeRemoveSpy.count(), 1); + for (const auto &spyArgs : {columnsRemoveSpy.takeFirst(), + columnsAboutToBeRemoveSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), sourceParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + for (const auto &spyArgs : {rowsRemoveSpy.takeFirst(), + rowsAboutToBeRemoveSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxyParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::insertRowProxy_data() +{ + QTest::addColumn("model"); + QTest::addColumn("rootItem"); + QTest::newRow("Table") << createTableModel(this) << true; + QTest::newRow("Tree_Root_Item") << createTreeModel(this) << true; + QTest::newRow("Tree_Child_Item") << createTreeModel(this) << false; +} + +void tst_QTransposeProxyModel::insertRowProxy() +{ + QFETCH(QAbstractItemModel *, model); + QFETCH(bool, rootItem); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + QSignalSpy rowsInsertSpy(&proxy, &QAbstractItemModel::rowsInserted); + QVERIFY(rowsInsertSpy.isValid()); + QSignalSpy rowsAboutToBeInsertSpy(&proxy, &QAbstractItemModel::rowsAboutToBeInserted); + QVERIFY(rowsAboutToBeInsertSpy.isValid()); + QSignalSpy columnsInsertSpy(model, &QAbstractItemModel::columnsInserted); + QVERIFY(columnsInsertSpy.isValid()); + QSignalSpy columnsAboutToBeInsertSpy(model, &QAbstractItemModel::columnsAboutToBeInserted); + QVERIFY(columnsAboutToBeInsertSpy.isValid()); + proxy.setSourceModel(model); + const QModelIndex proxyParent = rootItem ? QModelIndex() : proxy.index(0, 1); + const QModelIndex sourceParent = proxy.mapToSource(proxyParent); + const int oldRowCount = proxy.rowCount(proxyParent); + const int oldColCount = model->columnCount(sourceParent); + QVERIFY(proxy.insertRow(1, proxyParent)); + QCOMPARE(proxy.rowCount(proxyParent), oldRowCount + 1); + QCOMPARE(model->columnCount(sourceParent), oldColCount + 1); + QVERIFY(proxy.index(1, 0, proxyParent).data().isNull()); + QVERIFY(model->index(0, 1, sourceParent).data().isNull()); + QCOMPARE(columnsInsertSpy.count(), 1); + QCOMPARE(columnsAboutToBeInsertSpy.count(), 1); + QCOMPARE(rowsInsertSpy.count(), 1); + QCOMPARE(rowsAboutToBeInsertSpy.count(), 1); + for (const auto &spyArgs : {columnsInsertSpy.takeFirst(), + columnsAboutToBeInsertSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), sourceParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + for (const auto &spyArgs : {rowsInsertSpy.takeFirst(), + rowsAboutToBeInsertSpy.takeFirst()}) { + QCOMPARE(spyArgs.at(0).value(), proxyParent); + QCOMPARE(spyArgs.at(1).toInt(), 1); + QCOMPARE(spyArgs.at(2).toInt(), 1); + } + delete model; +} + +void tst_QTransposeProxyModel::headerData() +{ + QStandardItemModel model; + model.insertRows(0, 3); + model.insertColumns(0, 5); + for (int i = 0; i < model.rowCount(); ++i) + model.setHeaderData(i, Qt::Horizontal, QChar('A' + i)); + for (int i = 1; i <= model.columnCount(); ++i) + model.setHeaderData(i, Qt::Vertical, i); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(&model); + for (int i = 0; i < model.rowCount(); ++i) + QCOMPARE(model.headerData(i, Qt::Horizontal), proxy.headerData(i, Qt::Vertical)); + for (int i = 0; i < model.columnCount(); ++i) + QCOMPARE(model.headerData(i, Qt::Vertical), proxy.headerData(i, Qt::Horizontal)); +} + +void tst_QTransposeProxyModel::setHeaderData() +{ + QStandardItemModel model; + model.insertRows(0, 3); + model.insertColumns(0, 5); + for (int i = 0; i < model.rowCount(); ++i) + model.setHeaderData(i, Qt::Horizontal, QChar('A' + i)); + for (int i = 1; i <= model.columnCount(); ++i) + model.setHeaderData(i, Qt::Vertical, i); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(&model); + QVERIFY(proxy.setHeaderData(1, Qt::Horizontal, 99)); + QCOMPARE(model.headerData(1, Qt::Vertical).toInt(), 99); + QVERIFY(proxy.setHeaderData(1, Qt::Vertical, QChar('Z'))); + QCOMPARE(model.headerData(1, Qt::Horizontal).toChar(), QChar('Z')); +} + +void tst_QTransposeProxyModel::span() +{ + class SpanModel : public QStandardItemModel + { + Q_DISABLE_COPY(SpanModel) + public: + SpanModel(int rows, int columns, QObject *parent = nullptr) + : QStandardItemModel(rows, columns, parent) + {} + QSize span(const QModelIndex &index) const override + { + Q_UNUSED(index) + return QSize(2, 1); + } + }; + SpanModel model(3, 5); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(&model); + QCOMPARE(proxy.span(proxy.index(0, 0)), QSize(1, 2)); +} + +void tst_QTransposeProxyModel::itemData() +{ + QAbstractItemModel *model = createTreeModel(this); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + QMap itmData = proxy.itemData(proxy.index(0, 1)); + QCOMPARE(itmData.value(Qt::DisplayRole).toString(), QStringLiteral("1,0")); + QCOMPARE(itmData.value(Qt::UserRole).toInt(), 1); + QCOMPARE(itmData.value(Qt::UserRole + 1).toInt(), 0); + itmData = proxy.itemData(proxy.index(1, 2, proxy.index(0, 1))); + QCOMPARE(itmData.value(Qt::DisplayRole).toString(), QStringLiteral("1,0,2,1")); + QCOMPARE(itmData.value(Qt::UserRole).toInt(), 1); + QCOMPARE(itmData.value(Qt::UserRole + 1).toInt(), 0); + QCOMPARE(itmData.value(Qt::UserRole + 2).toInt(), 2); + QCOMPARE(itmData.value(Qt::UserRole + 3).toInt(), 1); + QVERIFY(proxy.itemData(QModelIndex()).isEmpty()); + delete model; +} + +void tst_QTransposeProxyModel::setItemData() +{ + QAbstractItemModel *model = createTreeModel(this); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + QSignalSpy sourceDataChangeSpy(model, &QAbstractItemModel::dataChanged); + QVERIFY(sourceDataChangeSpy.isValid()); + QSignalSpy proxyDataChangeSpy(&proxy, &QAbstractItemModel::dataChanged); + QVERIFY(proxyDataChangeSpy.isValid()); + const QMap itmData = { + std::make_pair(Qt::DisplayRole, QStringLiteral("Test")), + std::make_pair(Qt::UserRole, 88), + std::make_pair(Qt::UserRole + 1, 99), + }; + QModelIndex idx = proxy.index(0, 1); + QVERIFY(proxy.setItemData(idx, itmData)); + QCOMPARE(idx.data(Qt::DisplayRole).toString(), QStringLiteral("Test")); + QCOMPARE(idx.data(Qt::UserRole).toInt(), 88); + QCOMPARE(idx.data(Qt::UserRole + 1).toInt(), 99); + QCOMPARE(sourceDataChangeSpy.size(), 1); + QCOMPARE(proxyDataChangeSpy.size(), 1); + auto signalData = proxyDataChangeSpy.takeFirst(); + QCOMPARE(signalData.at(0).value(), idx); + QCOMPARE(signalData.at(1).value(), idx); + const QVector expectedRoles{Qt::DisplayRole, Qt::UserRole, Qt::EditRole, Qt::UserRole + 1}; + QVector receivedRoles = signalData.at(2).value >(); + QCOMPARE(receivedRoles.size(), expectedRoles.size()); + for (int role : expectedRoles) + QVERIFY(receivedRoles.contains(role)); + signalData = sourceDataChangeSpy.takeFirst(); + QCOMPARE(signalData.at(0).value(), proxy.mapToSource(idx)); + QCOMPARE(signalData.at(1).value(), proxy.mapToSource(idx)); + receivedRoles = signalData.at(2).value >(); + QCOMPARE(receivedRoles.size(), expectedRoles.size()); + for (int role : expectedRoles) + QVERIFY(receivedRoles.contains(role)); + idx = proxy.index(1, 2, proxy.index(0, 1)); + QVERIFY(proxy.setItemData(idx, itmData)); + QCOMPARE(idx.data(Qt::DisplayRole).toString(), QStringLiteral("Test")); + QCOMPARE(idx.data(Qt::UserRole).toInt(), 88); + QCOMPARE(idx.data(Qt::UserRole + 1).toInt(), 99); + QCOMPARE(idx.data(Qt::UserRole + 2).toInt(), 2); + QCOMPARE(idx.data(Qt::UserRole + 3).toInt(), 1); + QCOMPARE(sourceDataChangeSpy.size(), 1); + QCOMPARE(proxyDataChangeSpy.size(), 1); + signalData = proxyDataChangeSpy.takeFirst(); + QCOMPARE(signalData.at(0).value(), idx); + QCOMPARE(signalData.at(1).value(), idx); + receivedRoles = signalData.at(2).value >(); + QCOMPARE(receivedRoles.size(), expectedRoles.size()); + for (int role : expectedRoles) + QVERIFY(receivedRoles.contains(role)); + signalData = sourceDataChangeSpy.takeFirst(); + QCOMPARE(signalData.at(0).value(), proxy.mapToSource(idx)); + QCOMPARE(signalData.at(1).value(), proxy.mapToSource(idx)); + receivedRoles = signalData.at(2).value >(); + QCOMPARE(receivedRoles.size(), expectedRoles.size()); + for (int role : expectedRoles) + QVERIFY(receivedRoles.contains(role)); + QVERIFY(!proxy.setItemData(QModelIndex(), itmData)); + delete model; +} + +void tst_QTransposeProxyModel::moveRowsBase() +{ + QStringListModel model{QStringList{"A", "B", "C", "D"}}; + QTransposeProxyModel proxy; + QSignalSpy columnsMoveSpy(&proxy, &QAbstractItemModel::columnsMoved); + QVERIFY(columnsMoveSpy.isValid()); + QSignalSpy columnsAboutToBeMoveSpy(&proxy, &QAbstractItemModel::columnsAboutToBeMoved); + QVERIFY(columnsAboutToBeMoveSpy.isValid()); + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(&model); + const QStringList expectedNewVal = {"B", "A", "C", "D"}; + QVERIFY(model.moveRows(QModelIndex(), 0, 1, QModelIndex(), 2)); + for (int i = 0; i < expectedNewVal.size(); ++i) + QCOMPARE(proxy.index(0, i).data(), expectedNewVal.at(i)); + QCOMPARE(columnsMoveSpy.count(), 1); + QCOMPARE(columnsAboutToBeMoveSpy.count(), 1); + for (const auto &spyArgs : {columnsMoveSpy.takeFirst(), + columnsAboutToBeMoveSpy.takeFirst()}) { + QVERIFY(!spyArgs.at(0).value().isValid()); + QCOMPARE(spyArgs.at(1).toInt(), 0); + QCOMPARE(spyArgs.at(2).toInt(), 0); + QVERIFY(!spyArgs.at(3).value().isValid()); + QCOMPARE(spyArgs.at(4).toInt(), 2); + } +} + +void tst_QTransposeProxyModel::moveColumnsProxy() +{ + QStringListModel model{QStringList{"A", "B", "C", "D"}}; + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + QSignalSpy columnsMoveSpy(&proxy, &QAbstractItemModel::columnsMoved); + QVERIFY(columnsMoveSpy.isValid()); + QSignalSpy columnsAboutToBeMoveSpy(&proxy, &QAbstractItemModel::columnsAboutToBeMoved); + QVERIFY(columnsAboutToBeMoveSpy.isValid()); + QSignalSpy rowsMoveSpy(&model, &QAbstractItemModel::rowsMoved); + QVERIFY(rowsMoveSpy.isValid()); + QSignalSpy rowsAboutToBeMoveSpy(&model, &QAbstractItemModel::rowsAboutToBeMoved); + QVERIFY(rowsAboutToBeMoveSpy.isValid()); + proxy.setSourceModel(&model); + const QStringList expectedNewVal = {"B", "A", "C", "D"}; + QVERIFY(proxy.moveColumns(QModelIndex(), 0, 1, QModelIndex(), 2)); + for (int i = 0; i < expectedNewVal.size(); ++i) + QCOMPARE(proxy.index(0, i).data(), expectedNewVal.at(i)); + for (int i = 0; i < expectedNewVal.size(); ++i) + QCOMPARE(model.index(i, 0).data(), expectedNewVal.at(i)); + QCOMPARE(columnsMoveSpy.count(), 1); + QCOMPARE(columnsAboutToBeMoveSpy.count(), 1); + QCOMPARE(rowsMoveSpy.count(), 1); + QCOMPARE(rowsAboutToBeMoveSpy.count(), 1); + for (const auto &spyArgs : {columnsMoveSpy.takeFirst(), + columnsAboutToBeMoveSpy.takeFirst(), + rowsMoveSpy.takeFirst(),rowsAboutToBeMoveSpy.takeFirst()}) { + QVERIFY(!spyArgs.at(0).value().isValid()); + QCOMPARE(spyArgs.at(1).toInt(), 0); + QCOMPARE(spyArgs.at(2).toInt(), 0); + QVERIFY(!spyArgs.at(3).value().isValid()); + } +} + +void tst_QTransposeProxyModel::setData_data() +{ + QTest::addColumn("model"); + QTest::addColumn("rootItem"); + QTest::addColumn("viaProxy"); + QTest::newRow("List_via_Base") << createListModel(this) << true << false; + QTest::newRow("Table_via_Base") << createTableModel(this) << true << false; + QTest::newRow("Tree_via_Base_Root_Item") << createTreeModel(this) << true << false; + QTest::newRow("Tree_via_Base_Child_Item") << createTreeModel(this) << false << false; + QTest::newRow("List_via_Proxy") << createListModel(this) << true << true; + QTest::newRow("Table_via_Proxy") << createTableModel(this) << true << true; + QTest::newRow("Tree_via_Proxy_Root_Item") << createTreeModel(this) << true << true; + QTest::newRow("Tree_via_Proxy_Child_Item") << createTreeModel(this) << false << true; +} + +void tst_QTransposeProxyModel::setData() +{ + QFETCH(QAbstractItemModel *, model); + QFETCH(bool, rootItem); + QFETCH(bool, viaProxy); + QTransposeProxyModel proxy; + new QAbstractItemModelTester(&proxy, &proxy); + proxy.setSourceModel(model); + QSignalSpy sourceDataChangeSpy(model, &QAbstractItemModel::dataChanged); + QVERIFY(sourceDataChangeSpy.isValid()); + QSignalSpy proxyDataChangeSpy(&proxy, &QAbstractItemModel::dataChanged); + QVERIFY(proxyDataChangeSpy.isValid()); + const QString testData = QStringLiteral("TestingSetData"); + if (viaProxy) { + const QModelIndex parIdx = rootItem ? QModelIndex() : proxy.index(0, 1); + QVERIFY(proxy.setData(proxy.index(0, 1, parIdx), testData)); + QCOMPARE(model->index(1, 0, proxy.mapToSource(parIdx)).data().toString(), testData); + } else { + const QModelIndex parIdx = rootItem ? QModelIndex() : model->index(1, 0); + QVERIFY(model->setData(model->index(1, 0, parIdx), testData)); + QCOMPARE(proxy.index(0, 1, proxy.mapFromSource(parIdx)).data().toString(), testData); + } + QCOMPARE(sourceDataChangeSpy.size(), 1); + QCOMPARE(proxyDataChangeSpy.size(), 1); + delete model; +} + +QTEST_GUILESS_MAIN(tst_QTransposeProxyModel) + +#include "tst_qtransposeproxymodel.moc" -- cgit v1.2.3 From fc88dd52a42da682cbd360916be7c9f94a69b72c Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 25 Oct 2018 11:07:58 +0200 Subject: QByteArrayList: add indexOf(const char*) overload This avoids memory allocation and data copying in e.g. QObject::property(). Detected by heaptrack's "Temporary allocations" counter in an application using the breeze widget style (many animations). Change-Id: Iabdb58a3e504cb121cce906ef707b0722de89df6 Reviewed-by: Thiago Macieira --- .../tools/qbytearraylist/tst_qbytearraylist.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp index 85b4c4bfb7..2d2c536453 100644 --- a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp +++ b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp @@ -49,6 +49,9 @@ private slots: void operator_plus() const; void operator_plus_data() const; + void indexOf_data() const; + void indexOf() const; + void initializerList() const; }; @@ -259,6 +262,29 @@ void tst_QByteArrayList::operator_plus_data() const << ( QByteArrayList() << "a" << "" << "c" ); } +void tst_QByteArrayList::indexOf_data() const +{ + QTest::addColumn("list"); + QTest::addColumn("item"); + QTest::addColumn("expectedResult"); + + QTest::newRow("empty") << QByteArrayList() << QByteArray("a") << -1; + QTest::newRow("found_1") << ( QByteArrayList() << "a" ) << QByteArray("a") << 0; + QTest::newRow("not_found_1") << ( QByteArrayList() << "a" ) << QByteArray("b") << -1; + QTest::newRow("found_2") << ( QByteArrayList() << "hello" << "world" ) << QByteArray("world") << 1; + QTest::newRow("returns_first") << ( QByteArrayList() << "hello" << "world" << "hello" << "again" ) << QByteArray("hello") << 0; +} + +void tst_QByteArrayList::indexOf() const +{ + QFETCH(QByteArrayList, list); + QFETCH(QByteArray, item); + QFETCH(int, expectedResult); + + QCOMPARE(list.indexOf(item), expectedResult); + QCOMPARE(list.indexOf(item.constData()), expectedResult); +} + void tst_QByteArrayList::initializerList() const { #ifdef Q_COMPILER_INITIALIZER_LISTS -- cgit v1.2.3 From e7998dc187cf8f1218711ac963c441afbea1577c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 27 Oct 2018 19:43:09 -0700 Subject: QCborStreamReader: make sure setDevice() clears the last error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unit tests weren't running into this problem because the every setDevice() was preceded by the object being initialized with the exact same data, so there was never a previous error state. I've only changed a couple of tests, left the other setDevice() unchanged so we test both behaviors. Fixes: QTBUG-71426 Change-Id: I1bd327aeaf73421a8ec5fffd1561a590e3933376 Reviewed-by: Nils Jeisecke Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- .../corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp index 24d9c7409e..3dd4b5114c 100644 --- a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp +++ b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp @@ -269,7 +269,7 @@ void tst_QCborStreamReader::integers() quint64 absolute = (isNegative ? expectedRaw + 1 : expectedRaw); QBuffer buffer(&data); - QCborStreamReader reader(data); + QCborStreamReader reader(useDevice ? QByteArray() : data); if (useDevice) { buffer.open(QIODevice::ReadOnly); reader.setDevice(&buffer); @@ -605,7 +605,7 @@ void tst_QCborStreamReader::fixed() removeIndicators(expected); QBuffer buffer(&data); - QCborStreamReader reader(data); + QCborStreamReader reader(useDevice ? QByteArray() : data); if (useDevice) { buffer.open(QIODevice::ReadOnly); reader.setDevice(&buffer); -- cgit v1.2.3 From 27fb51fa529fb6501acfd4495adf597db326bb32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 6 Nov 2018 14:16:05 +0100 Subject: macOS: Remove blacklist entries for no longer supported OS versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iae6552f1fdcf1dea07a03d3788d378af9140d1a7 Reviewed-by: Morten Johan Sørvig --- tests/auto/corelib/io/qsettings/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 tests/auto/corelib/io/qsettings/BLACKLIST (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qsettings/BLACKLIST b/tests/auto/corelib/io/qsettings/BLACKLIST deleted file mode 100644 index 36d68bd918..0000000000 --- a/tests/auto/corelib/io/qsettings/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[isWritable:native] -osx-10.11 -- cgit v1.2.3 From 2569a5136e72214f45f4e34f8fa2fdf5ab0dbf83 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 5 Oct 2018 18:03:51 +0200 Subject: QMimeDatabase: update freedesktop.org.xml to shared-mime-info 1.10 Including https://gitlab.freedesktop.org/xdg/shared-mime-info/commit/4f7ad5ec448d38137ddc4de5624215ba0f8ebfa9 to make appimage not ambiguous Change-Id: I8db13fc785b267c09667ef38430bf98135c7f0d6 Reviewed-by: David Faure --- .../corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 9df52887f7..fd3cc18af5 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -73,12 +73,12 @@ static inline QString testSuiteWarning() str << "\nCannot find the shared-mime-info test suite\nstarting from: " << QDir::toNativeSeparators(QDir::currentPath()) << "\n" "cd " << QDir::toNativeSeparators(QStringLiteral("tests/auto/corelib/mimetypes/qmimedatabase")) << "\n" - "wget http://cgit.freedesktop.org/xdg/shared-mime-info/snapshot/Release-1-8.zip\n" - "unzip Release-1-8.zip\n"; + "wget http://cgit.freedesktop.org/xdg/shared-mime-info/snapshot/Release-1-10.zip\n" + "unzip Release-1-10.zip\n"; #ifdef Q_OS_WIN - str << "mkdir testfiles\nxcopy /s Release-1-8 s-m-i\n"; + str << "mkdir testfiles\nxcopy /s Release-1-10 s-m-i\n"; #else - str << "ln -s Release-1-8 s-m-i\n"; + str << "ln -s Release-1-10 s-m-i\n"; #endif return result; } @@ -611,7 +611,7 @@ void tst_QMimeDatabase::allMimeTypes() QVERIFY(!lst.isEmpty()); // Hardcoding this is the only way to check both providers find the same number of mimetypes. - QCOMPARE(lst.count(), 749); + QCOMPARE(lst.count(), 779); foreach (const QMimeType &mime, lst) { const QString name = mime.name(); @@ -640,7 +640,7 @@ void tst_QMimeDatabase::suffixes_data() QTest::newRow("mimetype with multiple patterns") << "text/plain" << "*.asc;*.txt;*,v" << "txt"; QTest::newRow("mimetype with uncommon pattern") << "text/x-readme" << "README*" << QString(); QTest::newRow("mimetype with no patterns") << "application/x-ole-storage" << QString() << QString(); - QTest::newRow("default_mimetype") << "application/octet-stream" << "*.bin" << QString(); + QTest::newRow("default_mimetype") << "application/octet-stream" << QString() << QString(); } void tst_QMimeDatabase::suffixes() -- cgit v1.2.3 From 16830c827b075c274f2f208fcc57c9f6174e9fcc Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 14 Nov 2018 12:09:51 +0100 Subject: Make sure QEventDispatcher::registerTimer() cleans up after itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test needs to also unregister its timers when it fails. Therefore, wrap the registering and unregistering in an RAII class. Task-number: QTBUG-71773 Change-Id: I6ef44e580880deecb32763b5b0cd71e1c26929be Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- .../qeventdispatcher/tst_qeventdispatcher.cpp | 178 +++++++++++++++------ 1 file changed, 126 insertions(+), 52 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index 5784f0728c..ca183752a5 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -92,77 +92,151 @@ void tst_QEventDispatcher::initTestCase() } } +class TimerManager { + Q_DISABLE_COPY(TimerManager) + +public: + TimerManager(QAbstractEventDispatcher *eventDispatcher, QObject *parent) + : m_eventDispatcher(eventDispatcher), m_parent(parent) + { + } + + ~TimerManager() + { + if (!registeredTimers().isEmpty()) + m_eventDispatcher->unregisterTimers(m_parent); + } + + TimerManager(TimerManager &&) = delete; + TimerManager &operator=(TimerManager &&) = delete; + + int preciseTimerId() const { return m_preciseTimerId; } + int coarseTimerId() const { return m_coarseTimerId; } + int veryCoarseTimerId() const { return m_veryCoarseTimerId; } + + bool foundPrecise() const { return m_preciseTimerId > 0; } + bool foundCoarse() const { return m_coarseTimerId > 0; } + bool foundVeryCoarse() const { return m_veryCoarseTimerId > 0; } + + QList registeredTimers() const + { + return m_eventDispatcher->registeredTimers(m_parent); + } + + void registerAll() + { + // start 3 timers, each with the different timer types and different intervals + m_preciseTimerId = m_eventDispatcher->registerTimer( + PreciseTimerInterval, Qt::PreciseTimer, m_parent); + m_coarseTimerId = m_eventDispatcher->registerTimer( + CoarseTimerInterval, Qt::CoarseTimer, m_parent); + m_veryCoarseTimerId = m_eventDispatcher->registerTimer( + VeryCoarseTimerInterval, Qt::VeryCoarseTimer, m_parent); + QVERIFY(m_preciseTimerId > 0); + QVERIFY(m_coarseTimerId > 0); + QVERIFY(m_veryCoarseTimerId > 0); + findTimers(); + } + + void unregister(int timerId) + { + m_eventDispatcher->unregisterTimer(timerId); + findTimers(); + } + + void unregisterAll() + { + m_eventDispatcher->unregisterTimers(m_parent); + findTimers(); + } + +private: + void findTimers() + { + bool foundPrecise = false; + bool foundCoarse = false; + bool foundVeryCoarse = false; + const QList timers = registeredTimers(); + for (int i = 0; i < timers.count(); ++i) { + const QAbstractEventDispatcher::TimerInfo &timerInfo = timers.at(i); + if (timerInfo.timerId == m_preciseTimerId) { + QCOMPARE(timerInfo.interval, int(PreciseTimerInterval)); + QCOMPARE(timerInfo.timerType, Qt::PreciseTimer); + foundPrecise = true; + } else if (timerInfo.timerId == m_coarseTimerId) { + QCOMPARE(timerInfo.interval, int(CoarseTimerInterval)); + QCOMPARE(timerInfo.timerType, Qt::CoarseTimer); + foundCoarse = true; + } else if (timerInfo.timerId == m_veryCoarseTimerId) { + QCOMPARE(timerInfo.interval, int(VeryCoarseTimerInterval)); + QCOMPARE(timerInfo.timerType, Qt::VeryCoarseTimer); + foundVeryCoarse = true; + } + } + if (!foundPrecise) + m_preciseTimerId = -1; + if (!foundCoarse) + m_coarseTimerId = -1; + if (!foundVeryCoarse) + m_veryCoarseTimerId = -1; + } + + QAbstractEventDispatcher *m_eventDispatcher = nullptr; + + int m_preciseTimerId = -1; + int m_coarseTimerId = -1; + int m_veryCoarseTimerId = -1; + + QObject *m_parent = nullptr; +}; + // test that the eventDispatcher's timer implementation is complete and working void tst_QEventDispatcher::registerTimer() { -#define FIND_TIMERS() \ - do { \ - foundPrecise = false; \ - foundCoarse = false; \ - foundVeryCoarse = false; \ - for (int i = 0; i < registeredTimers.count(); ++i) { \ - const QAbstractEventDispatcher::TimerInfo &timerInfo = registeredTimers.at(i); \ - if (timerInfo.timerId == preciseTimerId) { \ - QCOMPARE(timerInfo.interval, int(PreciseTimerInterval)); \ - QCOMPARE(timerInfo.timerType, Qt::PreciseTimer); \ - foundPrecise = true; \ - } else if (timerInfo.timerId == coarseTimerId) { \ - QCOMPARE(timerInfo.interval, int(CoarseTimerInterval)); \ - QCOMPARE(timerInfo.timerType, Qt::CoarseTimer); \ - foundCoarse = true; \ - } else if (timerInfo.timerId == veryCoarseTimerId) { \ - QCOMPARE(timerInfo.interval, int(VeryCoarseTimerInterval)); \ - QCOMPARE(timerInfo.timerType, Qt::VeryCoarseTimer); \ - foundVeryCoarse = true; \ - } \ - } \ - } while (0) - - // start 3 timers, each with the different timer types and different intervals - int preciseTimerId = eventDispatcher->registerTimer(PreciseTimerInterval, Qt::PreciseTimer, this); - int coarseTimerId = eventDispatcher->registerTimer(CoarseTimerInterval, Qt::CoarseTimer, this); - int veryCoarseTimerId = eventDispatcher->registerTimer(VeryCoarseTimerInterval, Qt::VeryCoarseTimer, this); - QVERIFY(preciseTimerId > 0); - QVERIFY(coarseTimerId > 0); - QVERIFY(veryCoarseTimerId > 0); + TimerManager timers(eventDispatcher, this); + timers.registerAll(); + if (QTest::currentTestFailed()) + return; // check that all 3 are present in the eventDispatcher's registeredTimer() list - QList registeredTimers = eventDispatcher->registeredTimers(this); - QCOMPARE(registeredTimers.count(), 3); - bool foundPrecise, foundCoarse, foundVeryCoarse; - FIND_TIMERS(); - QVERIFY(foundPrecise && foundCoarse && foundVeryCoarse); + QCOMPARE(timers.registeredTimers().count(), 3); + QVERIFY(timers.foundPrecise()); + QVERIFY(timers.foundCoarse()); + QVERIFY(timers.foundVeryCoarse()); // process events, waiting for the next event... this should only fire the precise timer receivedEventType = -1; timerIdFromEvent = -1; QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), PreciseTimerInterval * 2); - QCOMPARE(timerIdFromEvent, preciseTimerId); + QCOMPARE(timerIdFromEvent, timers.preciseTimerId()); // now unregister it and make sure it's gone - eventDispatcher->unregisterTimer(preciseTimerId); - registeredTimers = eventDispatcher->registeredTimers(this); - QCOMPARE(registeredTimers.count(), 2); - FIND_TIMERS(); - QVERIFY(!foundPrecise && foundCoarse && foundVeryCoarse); + timers.unregister(timers.preciseTimerId()); + if (QTest::currentTestFailed()) + return; + QCOMPARE(timers.registeredTimers().count(), 2); + QVERIFY(!timers.foundPrecise()); + QVERIFY(timers.foundCoarse()); + QVERIFY(timers.foundVeryCoarse()); // do the same again for the coarse timer receivedEventType = -1; timerIdFromEvent = -1; QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), CoarseTimerInterval * 2); - QCOMPARE(timerIdFromEvent, coarseTimerId); + QCOMPARE(timerIdFromEvent, timers.coarseTimerId()); // now unregister it and make sure it's gone - eventDispatcher->unregisterTimer(coarseTimerId); - registeredTimers = eventDispatcher->registeredTimers(this); - QCOMPARE(registeredTimers.count(), 1); - FIND_TIMERS(); - QVERIFY(!foundPrecise && !foundCoarse && foundVeryCoarse); + timers.unregister(timers.coarseTimerId()); + if (QTest::currentTestFailed()) + return; + QCOMPARE(timers.registeredTimers().count(), 1); + QVERIFY(!timers.foundPrecise()); + QVERIFY(!timers.foundCoarse()); + QVERIFY(timers.foundVeryCoarse()); // not going to wait for the VeryCoarseTimer, would take too long, just unregister it - eventDispatcher->unregisterTimers(this); - registeredTimers = eventDispatcher->registeredTimers(this); - QVERIFY(registeredTimers.isEmpty()); - -#undef FIND_TIMERS + timers.unregisterAll(); + if (QTest::currentTestFailed()) + return; + QVERIFY(timers.registeredTimers().isEmpty()); } void tst_QEventDispatcher::sendPostedEvents_data() -- cgit v1.2.3 From 900b57ea90ebe60414a5188337bc85ee4faac220 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 13 Nov 2018 18:35:50 +0100 Subject: Re-blacklist tst_QEventDispatcher::registerTimer() on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test has been failing over and over since it was removed from the blacklist. Obviously it is not stable. This is a partial revert of commit b10ee45546e152e08b2494bd45eb22426e9d2dc9. Task-number: QTBUG-71773 Change-Id: Ie2588538ee704652c2f09ce6ad947da3011e7dad Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST index b1590a5ccf..06588188d4 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST +++ b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST @@ -3,3 +3,4 @@ windows [registerTimer] windows winrt +osx -- cgit v1.2.3 From 527406cbd99f44470ef87468b73c18df949e8ac7 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Mon, 12 Nov 2018 09:40:47 +0100 Subject: Modernize the "settings" feature Change-Id: I9b8a61ecb1413b513ae5c9e77d3ee1b3e8b6562c Reviewed-by: Edward Welbourne Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/io/io.pro | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro index 3c93fd5e1f..eee2c0e30d 100644 --- a/tests/auto/corelib/io/io.pro +++ b/tests/auto/corelib/io/io.pro @@ -65,6 +65,9 @@ win32:!qtConfig(private_tests): SUBDIRS -= \ qprocess \ qprocess-noapplication +!qtConfig(settings): SUBDIRS -= \ + qsettings + winrt: SUBDIRS -= \ qstorageinfo -- cgit v1.2.3 From 7a4f41bad98da9953abcea05a71c2986406c7695 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Wed, 14 Nov 2018 09:47:21 +0100 Subject: tests: Distinguish tst_qeventdispatcher and tst_qguieventdispatcher Both use same source, but link without and with Qt Gui library. Task-number: QTBUG-71751 Change-Id: I5643a07a8067f5fc10fc66f717f19bc3e16a33ab Reviewed-by: Timur Pocheptsov Reviewed-by: Edward Welbourne --- tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index ca183752a5..49c10c6a24 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -28,6 +28,7 @@ #ifdef QT_GUI_LIB # include +# define tst_QEventDispatcher tst_QGuiEventDispatcher #else # include #endif -- cgit v1.2.3 From 6125fce79936d3ce96e3faac9ad3a9bad3101796 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 1 Nov 2018 15:57:35 -0700 Subject: tst_QResourceEngine: store the actual byte contents that we expect Instead of using a QString with only the prefix, let's do a full comparison to make sure there's no junk at the end of the file. Take the opportunity to remove the nonsense of a space at the end of most of these files (I didn't remove from all). Change-Id: I343f2beed55440a7ac0bfffd15632228c1bfe78f Reviewed-by: Lars Knoll --- .../auto/corelib/io/qresourceengine/.gitattributes | 1 + .../qresourceengine/testqrc/aliasdir/aliasdir.txt | 2 +- .../io/qresourceengine/testqrc/blahblah.txt | 2 +- .../io/qresourceengine/testqrc/currentdir.txt | 2 +- .../io/qresourceengine/testqrc/currentdir2.txt | 2 +- .../qresourceengine/testqrc/otherdir/otherdir.txt | 2 +- .../io/qresourceengine/testqrc/subdir/subdir.txt | 2 +- .../io/qresourceengine/testqrc/test/test/test1.txt | 2 +- .../io/qresourceengine/testqrc/test/test/test2.txt | 2 +- .../io/qresourceengine/testqrc/test/testdir.txt | 2 +- .../io/qresourceengine/testqrc/test/testdir2.txt | 2 +- .../io/qresourceengine/tst_qresourceengine.cpp | 59 +++++++++++----------- 12 files changed, 41 insertions(+), 39 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qresourceengine/.gitattributes b/tests/auto/corelib/io/qresourceengine/.gitattributes index add3716d81..88edd3681a 100644 --- a/tests/auto/corelib/io/qresourceengine/.gitattributes +++ b/tests/auto/corelib/io/qresourceengine/.gitattributes @@ -1 +1,2 @@ testqrc/test.qrc -crlf +*.txt -crlf diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/aliasdir/aliasdir.txt b/tests/auto/corelib/io/qresourceengine/testqrc/aliasdir/aliasdir.txt index 21a3dfa0b8..dcf7937f0a 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/aliasdir/aliasdir.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/aliasdir/aliasdir.txt @@ -1 +1 @@ -"This is a korean text file" +"This is a korean text file" diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/blahblah.txt b/tests/auto/corelib/io/qresourceengine/testqrc/blahblah.txt index 436c4d11c3..19f0805d8d 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/blahblah.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/blahblah.txt @@ -1 +1 @@ -qwerty +qwerty diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/currentdir.txt b/tests/auto/corelib/io/qresourceengine/testqrc/currentdir.txt index 38e389979a..65f1f43def 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/currentdir.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/currentdir.txt @@ -1 +1 @@ -"This is the current dir" +"This is the current dir" diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/currentdir2.txt b/tests/auto/corelib/io/qresourceengine/testqrc/currentdir2.txt index 6ac16a3306..7d89108011 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/currentdir2.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/currentdir2.txt @@ -1 +1 @@ -"This is also the current dir" +"This is also the current dir" diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/otherdir/otherdir.txt b/tests/auto/corelib/io/qresourceengine/testqrc/otherdir/otherdir.txt index b0e4a124ee..e1b430f33b 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/otherdir/otherdir.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/otherdir/otherdir.txt @@ -1 +1 @@ -"This is the other dir" +"This is the other dir" diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/subdir/subdir.txt b/tests/auto/corelib/io/qresourceengine/testqrc/subdir/subdir.txt index b6115207a2..4506acf413 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/subdir/subdir.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/subdir/subdir.txt @@ -1 +1 @@ -"This is in the sub directory" +"This is in the sub directory" diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test1.txt b/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test1.txt index adc01d1354..8baef1b4ab 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test1.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test1.txt @@ -1 +1 @@ -abc +abc diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test2.txt b/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test2.txt index 3f48e3cdc3..24c5735c3e 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test2.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/test/test/test2.txt @@ -1 +1 @@ -def +def diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir.txt b/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir.txt index 40ee68dccb..b8cb3a8c01 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir.txt @@ -1 +1 @@ -"This is in the test directory" +"This is in the test directory" diff --git a/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir2.txt b/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir2.txt index 051430298a..dccfdc9bcf 100644 --- a/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir2.txt +++ b/tests/auto/corelib/io/qresourceengine/testqrc/test/testdir2.txt @@ -1 +1 @@ -"This is another file in this directory" +"This is another file in this directory" diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index ab49dea6d8..2678bb0db3 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -104,7 +105,7 @@ void tst_QResourceEngine::cleanupTestCase() void tst_QResourceEngine::checkStructure_data() { QTest::addColumn("pathName"); - QTest::addColumn("contents"); + QTest::addColumn("contents"); QTest::addColumn("containedFiles"); QTest::addColumn("containedDirs"); QTest::addColumn("locale"); @@ -134,7 +135,7 @@ void tst_QResourceEngine::checkStructure_data() QTest::newRow("root dir") << QString(":/") - << QString() + << QByteArray() << (QStringList() #if defined(BUILTIN_TESTDATA) << "parentdir.txt" @@ -146,7 +147,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(0); QTest::newRow("secondary root") << QString(":/secondary_root/") - << QString() + << QByteArray() << QStringList() << (QStringList() << QLatin1String("runtime_resource")) << QLocale::c() @@ -158,56 +159,56 @@ void tst_QResourceEngine::checkStructure_data() const QString root = roots.at(i); QTest::newRow(QString(root + "prefix dir").toLatin1().constData()) << QString(root + "test/abc/123/+++") - << QString() + << QByteArray() << (QStringList() << QLatin1String("currentdir.txt") << QLatin1String("currentdir2.txt") << QLatin1String("parentdir.txt")) << (QStringList() << QLatin1String("subdir")) << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "parent to prefix").toLatin1().constData()) << QString(root + "test/abc/123") - << QString() + << QByteArray() << QStringList() << (QStringList() << QLatin1String("+++")) << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "two parents prefix").toLatin1().constData()) << QString(root + "test/abc") - << QString() + << QByteArray() << QStringList() << QStringList(QLatin1String("123")) << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "test dir ").toLatin1().constData()) << QString(root + "test") - << QString() + << QByteArray() << (QStringList() << QLatin1String("testdir.txt")) << (QStringList() << QLatin1String("abc") << QLatin1String("test")) << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "prefix no slashes").toLatin1().constData()) << QString(root + "withoutslashes") - << QString() + << QByteArray() << QStringList("blahblah.txt") << QStringList() << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "other dir").toLatin1().constData()) << QString(root + "otherdir") - << QString() + << QByteArray() << QStringList(QLatin1String("otherdir.txt")) << QStringList() << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "alias dir").toLatin1().constData()) << QString(root + "aliasdir") - << QString() + << QByteArray() << QStringList(QLatin1String("aliasdir.txt")) << QStringList() << QLocale::c() << qlonglong(0); QTest::newRow(QString(root + "second test dir").toLatin1().constData()) << QString(root + "test/test") - << QString() + << QByteArray() << (QStringList() << QLatin1String("test1.txt") << QLatin1String("test2.txt")) << QStringList() << QLocale::c() @@ -215,7 +216,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/test/test1.txt")); QTest::newRow(QString(root + "test1 text").toLatin1().constData()) << QString(root + "test/test/test1.txt") - << QString("abc") + << QByteArray("abc\n") << QStringList() << QStringList() << QLocale::c() @@ -223,7 +224,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/blahblah.txt")); QTest::newRow(QString(root + "text no slashes").toLatin1().constData()) << QString(root + "withoutslashes/blahblah.txt") - << QString("qwerty") + << QByteArray("qwerty\n") << QStringList() << QStringList() << QLocale::c() @@ -232,7 +233,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/test/test2.txt")); QTest::newRow(QString(root + "test1 text").toLatin1().constData()) << QString(root + "test/test/test2.txt") - << QString("def") + << QByteArray("def\n") << QStringList() << QStringList() << QLocale::c() @@ -240,7 +241,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/currentdir.txt")); QTest::newRow(QString(root + "currentdir text").toLatin1().constData()) << QString(root + "test/abc/123/+++/currentdir.txt") - << QString("\"This is the current dir\" ") + << QByteArray("\"This is the current dir\"\n") << QStringList() << QStringList() << QLocale::c() @@ -248,7 +249,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/currentdir2.txt")); QTest::newRow(QString(root + "currentdir text2").toLatin1().constData()) << QString(root + "test/abc/123/+++/currentdir2.txt") - << QString("\"This is also the current dir\" ") + << QByteArray("\"This is also the current dir\"\n") << QStringList() << QStringList() << QLocale::c() @@ -256,7 +257,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("parentdir.txt")); QTest::newRow(QString(root + "parentdir text").toLatin1().constData()) << QString(root + "test/abc/123/+++/parentdir.txt") - << QString("abcdefgihklmnopqrstuvwxyz ") + << QByteArray("abcdefgihklmnopqrstuvwxyz \n") << QStringList() << QStringList() << QLocale::c() @@ -264,7 +265,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/subdir/subdir.txt")); QTest::newRow(QString(root + "subdir text").toLatin1().constData()) << QString(root + "test/abc/123/+++/subdir/subdir.txt") - << QString("\"This is in the sub directory\" ") + << QByteArray("\"This is in the sub directory\"\n") << QStringList() << QStringList() << QLocale::c() @@ -272,7 +273,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/testdir.txt")); QTest::newRow(QString(root + "testdir text").toLatin1().constData()) << QString(root + "test/testdir.txt") - << QString("\"This is in the test directory\" ") + << QByteArray("\"This is in the test directory\"\n") << QStringList() << QStringList() << QLocale::c() @@ -280,7 +281,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/otherdir/otherdir.txt")); QTest::newRow(QString(root + "otherdir text").toLatin1().constData()) << QString(root + "otherdir/otherdir.txt") - << QString("\"This is the other dir\" ") + << QByteArray("\"This is the other dir\"\n") << QStringList() << QStringList() << QLocale::c() @@ -288,7 +289,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/testdir2.txt")); QTest::newRow(QString(root + "alias text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") - << QString("\"This is another file in this directory\" ") + << QByteArray("\"This is another file in this directory\"\n") << QStringList() << QStringList() << QLocale::c() @@ -296,7 +297,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/aliasdir.txt")); QTest::newRow(QString(root + "korean text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") - << QString("\"This is a korean text file\" ") + << QByteArray("\"This is a korean text file\"\n") << QStringList() << QStringList() << QLocale("ko") @@ -304,7 +305,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/aliasdir.txt")); QTest::newRow(QString(root + "korean text 2").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") - << QString("\"This is a korean text file\" ") + << QByteArray("\"This is a korean text file\"\n") << QStringList() << QStringList() << QLocale("ko_KR") @@ -312,7 +313,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/german.txt")); QTest::newRow(QString(root + "german text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") - << QString("Deutsch") + << QByteArray("Deutsch\n") << QStringList() << QStringList() << QLocale("de") @@ -320,7 +321,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/german.txt")); QTest::newRow(QString(root + "german text 2").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") - << QString("Deutsch") + << QByteArray("Deutsch\n") << QStringList() << QStringList() << QLocale("de_DE") @@ -330,7 +331,7 @@ void tst_QResourceEngine::checkStructure_data() file.open(QFile::ReadOnly); info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/compressme.txt")); QTest::newRow(QString(root + "compressed text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") - << QString(file.readAll()) + << file.readAll() << QStringList() << QStringList() << QLocale("de_CH") @@ -341,7 +342,7 @@ void tst_QResourceEngine::checkStructure_data() void tst_QResourceEngine::checkStructure() { QFETCH(QString, pathName); - QFETCH(QString, contents); + QFETCH(QByteArray, contents); QFETCH(QStringList, containedFiles); QFETCH(QStringList, containedDirs); QFETCH(QLocale, locale); @@ -401,8 +402,8 @@ void tst_QResourceEngine::checkStructure() QFile file(pathName); QVERIFY(file.open(QFile::ReadOnly)); - QByteArray ba = file.readAll(); - QVERIFY(QString(ba).startsWith(contents)); + // check contents + QCOMPARE(file.readAll(), contents); } QLocale::setDefault(QLocale::system()); } -- cgit v1.2.3 From 460866ee47c2a2ee98d7874a88bc3cc4b17b6f6a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 1 Nov 2018 16:09:05 -0700 Subject: tst_QResourceEngine: use QTest::addRow instead of QString concatenation Change-Id: I343f2beed55440a7ac0bfffd156322c95aebb847 Reviewed-by: Oswald Buddenhagen Reviewed-by: hjk Reviewed-by: Kai Koehne --- .../io/qresourceengine/tst_qresourceengine.cpp | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 2678bb0db3..cf1d249f54 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -158,56 +158,56 @@ void tst_QResourceEngine::checkStructure_data() for(int i = 0; i < roots.size(); ++i) { const QString root = roots.at(i); - QTest::newRow(QString(root + "prefix dir").toLatin1().constData()) << QString(root + "test/abc/123/+++") + QTest::addRow("%s prefix dir", qPrintable(root)) << QString(root + "test/abc/123/+++") << QByteArray() << (QStringList() << QLatin1String("currentdir.txt") << QLatin1String("currentdir2.txt") << QLatin1String("parentdir.txt")) << (QStringList() << QLatin1String("subdir")) << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "parent to prefix").toLatin1().constData()) << QString(root + "test/abc/123") + QTest::addRow("%s parent to prefix", qPrintable(root)) << QString(root + "test/abc/123") << QByteArray() << QStringList() << (QStringList() << QLatin1String("+++")) << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "two parents prefix").toLatin1().constData()) << QString(root + "test/abc") + QTest::addRow("%s two parents prefix", qPrintable(root)) << QString(root + "test/abc") << QByteArray() << QStringList() << QStringList(QLatin1String("123")) << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "test dir ").toLatin1().constData()) << QString(root + "test") + QTest::addRow("%s test dir ", qPrintable(root)) << QString(root + "test") << QByteArray() << (QStringList() << QLatin1String("testdir.txt")) << (QStringList() << QLatin1String("abc") << QLatin1String("test")) << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "prefix no slashes").toLatin1().constData()) << QString(root + "withoutslashes") + QTest::addRow("%s prefix no slashes", qPrintable(root)) << QString(root + "withoutslashes") << QByteArray() << QStringList("blahblah.txt") << QStringList() << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "other dir").toLatin1().constData()) << QString(root + "otherdir") + QTest::addRow("%s other dir", qPrintable(root)) << QString(root + "otherdir") << QByteArray() << QStringList(QLatin1String("otherdir.txt")) << QStringList() << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "alias dir").toLatin1().constData()) << QString(root + "aliasdir") + QTest::addRow("%s alias dir", qPrintable(root)) << QString(root + "aliasdir") << QByteArray() << QStringList(QLatin1String("aliasdir.txt")) << QStringList() << QLocale::c() << qlonglong(0); - QTest::newRow(QString(root + "second test dir").toLatin1().constData()) << QString(root + "test/test") + QTest::addRow("%s second test dir", qPrintable(root)) << QString(root + "test/test") << QByteArray() << (QStringList() << QLatin1String("test1.txt") << QLatin1String("test2.txt")) << QStringList() @@ -215,7 +215,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(0); info = QFileInfo(QFINDTESTDATA("testqrc/test/test/test1.txt")); - QTest::newRow(QString(root + "test1 text").toLatin1().constData()) << QString(root + "test/test/test1.txt") + QTest::addRow("%s test1 text", qPrintable(root)) << QString(root + "test/test/test1.txt") << QByteArray("abc\n") << QStringList() << QStringList() @@ -223,7 +223,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/blahblah.txt")); - QTest::newRow(QString(root + "text no slashes").toLatin1().constData()) << QString(root + "withoutslashes/blahblah.txt") + QTest::addRow("%s text no slashes", qPrintable(root)) << QString(root + "withoutslashes/blahblah.txt") << QByteArray("qwerty\n") << QStringList() << QStringList() @@ -232,7 +232,7 @@ void tst_QResourceEngine::checkStructure_data() info = QFileInfo(QFINDTESTDATA("testqrc/test/test/test2.txt")); - QTest::newRow(QString(root + "test1 text").toLatin1().constData()) << QString(root + "test/test/test2.txt") + QTest::addRow("%s test1 text", qPrintable(root)) << QString(root + "test/test/test2.txt") << QByteArray("def\n") << QStringList() << QStringList() @@ -240,7 +240,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/currentdir.txt")); - QTest::newRow(QString(root + "currentdir text").toLatin1().constData()) << QString(root + "test/abc/123/+++/currentdir.txt") + QTest::addRow("%s currentdir text", qPrintable(root)) << QString(root + "test/abc/123/+++/currentdir.txt") << QByteArray("\"This is the current dir\"\n") << QStringList() << QStringList() @@ -248,7 +248,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/currentdir2.txt")); - QTest::newRow(QString(root + "currentdir text2").toLatin1().constData()) << QString(root + "test/abc/123/+++/currentdir2.txt") + QTest::addRow("%s currentdir text2", qPrintable(root)) << QString(root + "test/abc/123/+++/currentdir2.txt") << QByteArray("\"This is also the current dir\"\n") << QStringList() << QStringList() @@ -256,7 +256,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("parentdir.txt")); - QTest::newRow(QString(root + "parentdir text").toLatin1().constData()) << QString(root + "test/abc/123/+++/parentdir.txt") + QTest::addRow("%s parentdir text", qPrintable(root)) << QString(root + "test/abc/123/+++/parentdir.txt") << QByteArray("abcdefgihklmnopqrstuvwxyz \n") << QStringList() << QStringList() @@ -264,7 +264,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/subdir/subdir.txt")); - QTest::newRow(QString(root + "subdir text").toLatin1().constData()) << QString(root + "test/abc/123/+++/subdir/subdir.txt") + QTest::addRow("%s subdir text", qPrintable(root)) << QString(root + "test/abc/123/+++/subdir/subdir.txt") << QByteArray("\"This is in the sub directory\"\n") << QStringList() << QStringList() @@ -272,7 +272,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/test/testdir.txt")); - QTest::newRow(QString(root + "testdir text").toLatin1().constData()) << QString(root + "test/testdir.txt") + QTest::addRow("%s testdir text", qPrintable(root)) << QString(root + "test/testdir.txt") << QByteArray("\"This is in the test directory\"\n") << QStringList() << QStringList() @@ -280,7 +280,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/otherdir/otherdir.txt")); - QTest::newRow(QString(root + "otherdir text").toLatin1().constData()) << QString(root + "otherdir/otherdir.txt") + QTest::addRow("%s otherdir text", qPrintable(root)) << QString(root + "otherdir/otherdir.txt") << QByteArray("\"This is the other dir\"\n") << QStringList() << QStringList() @@ -288,7 +288,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/test/testdir2.txt")); - QTest::newRow(QString(root + "alias text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") + QTest::addRow("%s alias text", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt") << QByteArray("\"This is another file in this directory\"\n") << QStringList() << QStringList() @@ -296,7 +296,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/aliasdir.txt")); - QTest::newRow(QString(root + "korean text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") + QTest::addRow("%s korean text", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt") << QByteArray("\"This is a korean text file\"\n") << QStringList() << QStringList() @@ -304,7 +304,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/aliasdir.txt")); - QTest::newRow(QString(root + "korean text 2").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") + QTest::addRow("%s korean text 2", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt") << QByteArray("\"This is a korean text file\"\n") << QStringList() << QStringList() @@ -312,7 +312,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/test/german.txt")); - QTest::newRow(QString(root + "german text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") + QTest::addRow("%s german text", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt") << QByteArray("Deutsch\n") << QStringList() << QStringList() @@ -320,7 +320,7 @@ void tst_QResourceEngine::checkStructure_data() << qlonglong(info.size()); info = QFileInfo(QFINDTESTDATA("testqrc/test/german.txt")); - QTest::newRow(QString(root + "german text 2").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") + QTest::addRow("%s german text 2", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt") << QByteArray("Deutsch\n") << QStringList() << QStringList() @@ -330,7 +330,7 @@ void tst_QResourceEngine::checkStructure_data() QFile file(QFINDTESTDATA("testqrc/aliasdir/compressme.txt")); file.open(QFile::ReadOnly); info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/compressme.txt")); - QTest::newRow(QString(root + "compressed text").toLatin1().constData()) << QString(root + "aliasdir/aliasdir.txt") + QTest::addRow("%s compressed text", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt") << file.readAll() << QStringList() << QStringList() -- cgit v1.2.3 From 6a792d6f0b5a15ce09b7883bbbb06b2724596e40 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 2 Nov 2018 13:54:26 -0700 Subject: QResourceFileEngine: fix map() for compressed files We were returning a pointer to the compressed data and comparing to the compressed data size. Change-Id: I343f2beed55440a7ac0bfffd1563232d557c9427 Reviewed-by: Oswald Buddenhagen Reviewed-by: hjk --- tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index cf1d249f54..6461e6274f 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -404,6 +404,12 @@ void tst_QResourceEngine::checkStructure() // check contents QCOMPARE(file.readAll(), contents); + + // check memory map too + uchar *ptr = file.map(0, file.size(), QFile::MapPrivateOption); + QVERIFY2(ptr, qPrintable(file.errorString())); + QByteArray ba = QByteArray::fromRawData(reinterpret_cast(ptr), file.size()); + QCOMPARE(ba, contents); } QLocale::setDefault(QLocale::system()); } -- cgit v1.2.3 From 6b088b7a1da37511a8abb1503e4f2f95632dbdac Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 1 Nov 2018 16:35:29 -0700 Subject: QResourceFileEngine: fix use of mapped files after close() QFile::map() is documented to continue working after the QFile is closed, so this should work for the resource file engine too. Change-Id: I343f2beed55440a7ac0bfffd1563243a3966441f Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 6461e6274f..0b50c391b8 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -410,6 +410,10 @@ void tst_QResourceEngine::checkStructure() QVERIFY2(ptr, qPrintable(file.errorString())); QByteArray ba = QByteArray::fromRawData(reinterpret_cast(ptr), file.size()); QCOMPARE(ba, contents); + + // check that it is still valid after closing the file + file.close(); + QCOMPARE(ba, contents); } QLocale::setDefault(QLocale::system()); } -- cgit v1.2.3 From e00c73911ae0127f986e056984eff02b099325f4 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 25 Oct 2018 15:08:13 +0200 Subject: Reduce run time of tst_QRegularExpression::threadSafety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test was taking so much time that it regularly timed out on WinRT and when running in qemu. Reduce it from around 40 to 7 seconds on a powerful desktop. Now it either runs for two full seconds for each test function or until it has done 50 iterations. Fixes: QTBUG-71405 Change-Id: If752c1e65d3b19009b883f64edc96d020df479d1 Reviewed-by: Oliver Wolff Reviewed-by: Jędrzej Nowacki Reviewed-by: Timur Pocheptsov --- .../auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 18098f16bf..c23ee3b0ba 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -2135,11 +2135,12 @@ void tst_QRegularExpression::threadSafety() QFETCH(QString, pattern); QFETCH(QString, subject); + QElapsedTimer time; + time.start(); static const int THREAD_SAFETY_ITERATIONS = 50; - const int threadCount = qMax(QThread::idealThreadCount(), 4); - for (int threadSafetyIteration = 0; threadSafetyIteration < THREAD_SAFETY_ITERATIONS; ++threadSafetyIteration) { + for (int threadSafetyIteration = 0; threadSafetyIteration < THREAD_SAFETY_ITERATIONS && time.elapsed() < 2000; ++threadSafetyIteration) { QRegularExpression re(pattern); QVector threads; -- cgit v1.2.3 From c02d579c567a9e0413801aad87d3ecc9710ed2b2 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 21 Nov 2018 14:26:58 +0100 Subject: Remove usage of win32-msvc2012 qmake scope We don't support MSVC 2012 anymore. Change-Id: I454ba0f8e893f5910a17e473ab7cf70a1c581e81 Reviewed-by: Oliver Wolff --- tests/auto/corelib/kernel/qmetatype/qmetatype.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro index d70befecfd..56b8c071c3 100644 --- a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro +++ b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro @@ -10,7 +10,7 @@ msvc|winrt { # Prevents "fatal error C1128: number of sections exceeded object file format limit". QMAKE_CXXFLAGS += /bigobj # Reduce compile time - win32-msvc2012|winrt { + winrt { QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CFLAGS_RELEASE -= -O2 } -- cgit v1.2.3 From eef9b4f0d5c3582364e327eca302f9499dffeea3 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 21 Nov 2018 14:18:28 +0100 Subject: Use msvc qmake scope where appropriate Use 'msvc' instead of 'win32-msvc' or even 'win32-mscv*'. Change-Id: I21dc7748a4019119066aea0a88a29a61827f9429 Reviewed-by: Oliver Wolff Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne --- tests/auto/corelib/plugin/qlibrary/lib/lib.pro | 2 +- tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro | 2 +- tests/auto/corelib/plugin/qpluginloader/lib/lib.pro | 2 +- tests/auto/corelib/tools/qdatetime/qdatetime.pro | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro index 3e15861021..c44cd46597 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro +++ b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro @@ -6,7 +6,7 @@ TARGET = mylib DESTDIR = ../ QT = core -win32-msvc: DEFINES += WIN32_MSVC +msvc: DEFINES += WIN32_MSVC # This project is testdata for tst_qlibrary target.path = $$[QT_INSTALL_TESTS]/tst_qlibrary diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro index bd73227b3d..bfda0e0194 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro +++ b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro @@ -7,7 +7,7 @@ DESTDIR = ../ VERSION = 2 QT = core -win32-msvc: DEFINES += WIN32_MSVC +msvc: DEFINES += WIN32_MSVC # Force a copy of the library to have an extension that is non-standard. # We want to test if we can load a shared library with *any* filename... diff --git a/tests/auto/corelib/plugin/qpluginloader/lib/lib.pro b/tests/auto/corelib/plugin/qpluginloader/lib/lib.pro index 44b71e6e99..9fc76a4201 100644 --- a/tests/auto/corelib/plugin/qpluginloader/lib/lib.pro +++ b/tests/auto/corelib/plugin/qpluginloader/lib/lib.pro @@ -7,7 +7,7 @@ DESTDIR = ../bin winrt:include(../winrt.pri) QT = core -win32-msvc: DEFINES += WIN32_MSVC +msvc: DEFINES += WIN32_MSVC # This is testdata for the tst_qpluginloader test. target.path = $$[QT_INSTALL_TESTS]/tst_qpluginloader/bin diff --git a/tests/auto/corelib/tools/qdatetime/qdatetime.pro b/tests/auto/corelib/tools/qdatetime/qdatetime.pro index ba36621cf1..742eb47075 100644 --- a/tests/auto/corelib/tools/qdatetime/qdatetime.pro +++ b/tests/auto/corelib/tools/qdatetime/qdatetime.pro @@ -5,7 +5,7 @@ SOURCES = tst_qdatetime.cpp # For some reason using optimization here triggers a compiler issue, which causes an exception # However, the code is correct -win32-msvc|win32-msvc9x { +msvc { !build_pass:message ( "Compiler issue, removing -O1 flag" ) QMAKE_CFLAGS_RELEASE -= -O1 QMAKE_CXXFLAGS_RELEASE -= -O1 -- cgit v1.2.3 From 108c9015b960fccd79efc6de4459dbf05f6ced54 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 16 Nov 2018 14:29:42 +0100 Subject: Implement transient locale as instantiating a class A couple of QLocale tests were using setlocale twice to provide a transient locale tweak in tests; however, if the test in between fails, that can leave the program running in the "transient" locale after. So implement a proper class whose destructor ensures the transient is tidied away. Also change the locale in use by one of these transient changes: it purported to be checking things didn't depend on locale, but was using the same local as most of the test-cases for its test. Change-Id: I0d954edcc96019a8c2eb12b7a7c568e8b87a41d5 Reviewed-by: Thiago Macieira Reviewed-by: Ulf Hermann --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index b7cb8a1bdc..4803451399 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -153,6 +153,16 @@ private: QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; QString m_sysapp; bool europeanTimeZone; + + class TransientLocale + { + const int m_category; + const char *const m_prior; + public: + TransientLocale(int category, const char *locale) + : m_category(category), m_prior(setlocale(category, locale)) {} + ~TransientLocale() { setlocale(m_category, m_prior); } + }; }; tst_QLocale::tst_QLocale() @@ -806,10 +816,12 @@ void tst_QLocale::stringToDouble() double d = locale.toDouble(num_str, &ok); QCOMPARE(ok, good); - char *currentLocale = setlocale(LC_ALL, "de_DE"); - QCOMPARE(locale.toDouble(num_str, &ok), d); // make sure result is independent of locale - QCOMPARE(ok, good); - setlocale(LC_ALL, currentLocale); + { + // Make sure result is independent of locale: + TransientLocale ignoreme(LC_ALL, "ar_SA"); + QCOMPARE(locale.toDouble(num_str, &ok), d); + QCOMPARE(ok, good); + } if (ok) { double diff = d - num; @@ -939,9 +951,8 @@ void tst_QLocale::doubleToString() const QLocale locale(locale_name); QCOMPARE(locale.toString(num, mode, precision), num_str); - char *currentLocale = setlocale(LC_ALL, "de_DE"); + TransientLocale ignoreme(LC_ALL, "de_DE"); QCOMPARE(locale.toString(num, mode, precision), num_str); - setlocale(LC_ALL, currentLocale); } void tst_QLocale::strtod_data() -- cgit v1.2.3 From 704137f8de49a55a1b21bb6d612d2594562f51ce Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 16 Nov 2018 15:44:44 +0100 Subject: tst_QLocale: Add tests for toFloat() Mirror those for toDouble(). Change-Id: Ide0ef3cd99528d575f6a578ef19547f3b1119c5d Reviewed-by: Ulf Hermann --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 55 +++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 4803451399..fa1a64a045 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -83,6 +83,8 @@ private slots: void matchingLocales(); void stringToDouble_data(); void stringToDouble(); + void stringToFloat_data() { stringToDouble_data(); } + void stringToFloat(); void doubleToString_data(); void doubleToString(); void strtod_data(); @@ -801,7 +803,7 @@ void tst_QLocale::stringToDouble_data() void tst_QLocale::stringToDouble() { -#define MY_DOUBLE_EPSILON (2.22045e-16) +#define MY_DOUBLE_EPSILON (2.22045e-16) // 1/2^{52}; double has a 53-bit mantissa QFETCH(QString, locale_name); QFETCH(QString, num_str); @@ -824,6 +826,8 @@ void tst_QLocale::stringToDouble() } if (ok) { + // First use fuzzy-compare, then a more precise check: + QCOMPARE(d, num); double diff = d - num; if (diff < 0) diff = -diff; @@ -834,11 +838,60 @@ void tst_QLocale::stringToDouble() QCOMPARE(ok, good); if (ok) { + QCOMPARE(d, num); double diff = d - num; if (diff < 0) diff = -diff; QVERIFY(diff <= MY_DOUBLE_EPSILON); } +#undef MY_DOUBLE_EPSILON +} + +void tst_QLocale::stringToFloat() +{ +#define MY_FLOAT_EPSILON (2.384e-7) // 1/2^{22}; float has a 23-bit mantissa + + QFETCH(QString, locale_name); + QFETCH(QString, num_str); + QFETCH(bool, good); + QFETCH(double, num); + QStringRef num_strRef = num_str.leftRef(-1); + float fnum = num; + + QLocale locale(locale_name); + QCOMPARE(locale.name(), locale_name); + + bool ok; + float f = locale.toFloat(num_str, &ok); + QCOMPARE(ok, good); + + { + // Make sure result is independent of locale: + TransientLocale ignoreme(LC_ALL, "ar_SA"); + QCOMPARE(locale.toFloat(num_str, &ok), f); + QCOMPARE(ok, good); + } + + if (ok) { + // First use fuzzy-compare, then a more precise check: + QCOMPARE(f, fnum); + float diff = f - fnum; + if (diff < 0) + diff = -diff; + QVERIFY(diff <= MY_FLOAT_EPSILON); + } + + f = locale.toFloat(num_strRef, &ok); + QCOMPARE(ok, good); + + if (ok) { + QCOMPARE(f, fnum); + float diff = f - fnum; + if (diff < 0) + diff = -diff; + QVERIFY(diff <= MY_FLOAT_EPSILON); + } +#undef MY_FLOAT_EPSILON } void tst_QLocale::doubleToString_data() -- cgit v1.2.3 From a9923674030980706940b3ee11145c38674bb35d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 19 Nov 2018 16:27:03 +0100 Subject: Change documentation of some toDouble()s to reflect reality They actually return infinity if conversion overflows, while still setting ok to false; they were documented to return 0 on failure, with no mention of this special handling of overflow. Documented reality rather than changing the behavior. Gave underflow as an example of failure other than overflow (toDouble()s do indeed fail on it). Added some tests of out-of-range values, infinities and NaNs. [ChangeLog][QtCore][toDouble] QString, QByteArray and QLocale return an infinity on overflow (since 5.7), while setting ok to false; this was at odds with their documented behavior of returning 0 on failure. The documentation now reflects the actual behavior. Fixes: QTBUG-71256 Change-Id: I8d7e80ba1f06091cf0f1480c341553381103703b Reviewed-by: Ulf Hermann --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 56 +++++++++++++++++++----- 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index fa1a64a045..7bf6d1327e 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -83,7 +83,7 @@ private slots: void matchingLocales(); void stringToDouble_data(); void stringToDouble(); - void stringToFloat_data() { stringToDouble_data(); } + void stringToFloat_data(); void stringToFloat(); void doubleToString_data(); void doubleToString(); @@ -155,6 +155,7 @@ private: QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; QString m_sysapp; bool europeanTimeZone; + void toReal_data(); class TransientLocale { @@ -679,7 +680,7 @@ void tst_QLocale::unixLocaleName() #undef TEST_NAME } -void tst_QLocale::stringToDouble_data() +void tst_QLocale::toReal_data() { QTest::addColumn("locale_name"); QTest::addColumn("num_str"); @@ -801,6 +802,32 @@ void tst_QLocale::stringToDouble_data() QTest::newRow("de_DE 9.876543,0e--2") << QString("de_DE") << QString("9.876543,0e")+QChar(8722)+QString("2") << false << 0.0; } +void tst_QLocale::stringToDouble_data() +{ + toReal_data(); + if (std::numeric_limits::has_infinity) { + double huge = std::numeric_limits::infinity(); + QTest::newRow("C inf") << QString("C") << QString("inf") << true << huge; + QTest::newRow("C +inf") << QString("C") << QString("+inf") << true << +huge; + QTest::newRow("C -inf") << QString("C") << QString("-inf") << true << -huge; + // Overflow: + QTest::newRow("C huge") << QString("C") << QString("2e308") << false << huge; + QTest::newRow("C -huge") << QString("C") << QString("-2e308") << false << -huge; + } + if (std::numeric_limits::has_quiet_NaN) + QTest::newRow("C qnan") << QString("C") << QString("NaN") << true << std::numeric_limits::quiet_NaN(); + + // In range (but outside float's range): + QTest::newRow("C big") << QString("C") << QString("3.5e38") << true << 3.5e38; + QTest::newRow("C -big") << QString("C") << QString("-3.5e38") << true << -3.5e38; + QTest::newRow("C small") << QString("C") << QString("1e-45") << true << 1e-45; + QTest::newRow("C -small") << QString("C") << QString("-1e-45") << true << -1e-45; + + // Underflow: + QTest::newRow("C tiny") << QString("C") << QString("2e-324") << false << 0.; + QTest::newRow("C -tiny") << QString("C") << QString("-2e-324") << false << 0.; +} + void tst_QLocale::stringToDouble() { #define MY_DOUBLE_EPSILON (2.22045e-16) // 1/2^{52}; double has a 53-bit mantissa @@ -825,28 +852,33 @@ void tst_QLocale::stringToDouble() QCOMPARE(ok, good); } - if (ok) { + if (ok || std::isinf(num)) { // First use fuzzy-compare, then a more precise check: QCOMPARE(d, num); - double diff = d - num; - if (diff < 0) - diff = -diff; - QVERIFY(diff <= MY_DOUBLE_EPSILON); + if (std::isfinite(num)) { + double diff = d > num ? d - num : num - d; + QVERIFY(diff <= MY_DOUBLE_EPSILON); + } } d = locale.toDouble(num_strRef, &ok); QCOMPARE(ok, good); - if (ok) { + if (ok || std::isinf(num)) { QCOMPARE(d, num); - double diff = d - num; - if (diff < 0) - diff = -diff; - QVERIFY(diff <= MY_DOUBLE_EPSILON); + if (std::isfinite(num)) { + double diff = d > num ? d - num : num - d; + QVERIFY(diff <= MY_DOUBLE_EPSILON); + } } #undef MY_DOUBLE_EPSILON } +void tst_QLocale::stringToFloat_data() +{ + toReal_data(); +} + void tst_QLocale::stringToFloat() { #define MY_FLOAT_EPSILON (2.384e-7) // 1/2^{22}; float has a 23-bit mantissa -- cgit v1.2.3 From ce159d1a3e48308d54300560f024e8501c1395c9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 19 Nov 2018 19:53:38 +0100 Subject: Fix toFloat()s between float and double ranges and document Revised some toFloat()s to be consistent with the matching toDouble()s; previously, they would return infinity if toDouble() did but return 0 if toDouble() got a finite value outside float's range. That also applied to values that underflowed float's range, succeeding and returning 0 as long as they were within double's range but failing if toDouble() underflowed. Now float-underflow also fails. Amended their documentation to reflect this more consistent reality. Added some tests of out-of-range values, infinities and NaNs. [ChangeLog][QtCore][toFloat] QString, QByteArray and QLocale returned an infinity on double-overflow (since 5.7) but returned 0 on a finite double outside float's range, while setting ok to false; this was at odds with their documented behavior of returning 0 on any failure. They also succeeded, returning zero, on underflow of float's range, unless double underflowed, where they failed. Changed the handling of values outside float's range to match that of values outside double's range: fail, returning an infinity on overflow or zero on underflow. The documentation now reflects the revised behavior, which matches toDouble(). Change-Id: Ia168bcacf7def0df924840d45d8edc5f850449d6 Reviewed-by: Ulf Hermann --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 42 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 7bf6d1327e..b8f1cc568a 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -877,6 +877,28 @@ void tst_QLocale::stringToDouble() void tst_QLocale::stringToFloat_data() { toReal_data(); + if (std::numeric_limits::has_infinity) { + double huge = std::numeric_limits::infinity(); + QTest::newRow("C inf") << QString("C") << QString("inf") << true << huge; + QTest::newRow("C +inf") << QString("C") << QString("+inf") << true << +huge; + QTest::newRow("C -inf") << QString("C") << QString("-inf") << true << -huge; + // Overflow float, but not double: + QTest::newRow("C big") << QString("C") << QString("3.5e38") << false << huge; + QTest::newRow("C -big") << QString("C") << QString("-3.5e38") << false << -huge; + // Overflow double, too: + QTest::newRow("C huge") << QString("C") << QString("2e308") << false << huge; + QTest::newRow("C -huge") << QString("C") << QString("-2e308") << false << -huge; + } + if (std::numeric_limits::has_quiet_NaN) + QTest::newRow("C qnan") << QString("C") << QString("NaN") << true << double(std::numeric_limits::quiet_NaN()); + + // Underflow float, but not double: + QTest::newRow("C small") << QString("C") << QString("1e-45") << false << 0.; + QTest::newRow("C -small") << QString("C") << QString("-1e-45") << false << 0.; + + // Underflow double, too: + QTest::newRow("C tiny") << QString("C") << QString("2e-324") << false << 0.; + QTest::newRow("C -tiny") << QString("C") << QString("-2e-324") << false << 0.; } void tst_QLocale::stringToFloat() @@ -904,24 +926,24 @@ void tst_QLocale::stringToFloat() QCOMPARE(ok, good); } - if (ok) { + if (ok || std::isinf(fnum)) { // First use fuzzy-compare, then a more precise check: QCOMPARE(f, fnum); - float diff = f - fnum; - if (diff < 0) - diff = -diff; - QVERIFY(diff <= MY_FLOAT_EPSILON); + if (std::isfinite(fnum)) { + float diff = f > fnum ? f - fnum : fnum - f; + QVERIFY(diff <= MY_FLOAT_EPSILON); + } } f = locale.toFloat(num_strRef, &ok); QCOMPARE(ok, good); - if (ok) { + if (ok || std::isinf(fnum)) { QCOMPARE(f, fnum); - float diff = f - fnum; - if (diff < 0) - diff = -diff; - QVERIFY(diff <= MY_FLOAT_EPSILON); + if (std::isfinite(fnum)) { + float diff = f > fnum ? f - fnum : fnum - f; + QVERIFY(diff <= MY_FLOAT_EPSILON); + } } #undef MY_FLOAT_EPSILON } -- cgit v1.2.3 From d8b401959f6f58bc80f767684b250dd4589735d6 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 19 Nov 2018 16:26:02 +0100 Subject: Recognize E along with e as exponent character in asciiToDouble Fixed a misguided condition in the check for bogus texts in the sscanf branch of the decoder; it checked for 'e' but neglected 'E', which is just as valid. Change-Id: I9236c76faea000c92df641930e401bce445e06c8 Reviewed-by: Ulf Hermann --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index b8f1cc568a..fd37a03b8e 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -693,6 +693,8 @@ void tst_QLocale::toReal_data() QTest::newRow("C 1.234e-10") << QString("C") << QString("1.234e-10") << true << 1.234e-10; QTest::newRow("C 1.234E10") << QString("C") << QString("1.234E10") << true << 1.234e10; QTest::newRow("C 1e10") << QString("C") << QString("1e10") << true << 1.0e10; + QTest::newRow("C 1e310") << QString("C") << QString("1e310") << false << std::numeric_limits::infinity(); + QTest::newRow("C 1E310") << QString("C") << QString("1E310") << false << std::numeric_limits::infinity(); QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0; QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0; QTest::newRow("C 1 ") << QString("C") << QString("1 ") << true << 1.0; -- cgit v1.2.3 From 71bd06d516a2410ae0ea698e79dcb94aba9bc5b4 Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Wed, 13 Jun 2018 16:35:40 +0300 Subject: Make developer build tests pass for boot2qt Some tests were fixed and others were skipped/blacklisted. Task-number: QTBUG-63152 Change-Id: Ica7df555f8d152ee589865911130525101d4b941 Reviewed-by: Liang Qi --- tests/auto/corelib/global/qlogging/BLACKLIST | 4 ++++ tests/auto/corelib/io/qstandardpaths/BLACKLIST | 3 --- tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro | 3 +++ tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 6 ++++++ tests/auto/corelib/serialization/qtextstream/test/test.pro | 2 ++ tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp | 5 ++++- 6 files changed, 19 insertions(+), 4 deletions(-) delete mode 100644 tests/auto/corelib/io/qstandardpaths/BLACKLIST (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qlogging/BLACKLIST b/tests/auto/corelib/global/qlogging/BLACKLIST index 1dcee92361..e474064f54 100644 --- a/tests/auto/corelib/global/qlogging/BLACKLIST +++ b/tests/auto/corelib/global/qlogging/BLACKLIST @@ -1,3 +1,7 @@ +[qMessagePattern:backtrace] +# QTBUG-63915 +b2qt 64bit + [qMessagePattern:backtrace depth,separator] # QTBUG-63915 b2qt 64bit diff --git a/tests/auto/corelib/io/qstandardpaths/BLACKLIST b/tests/auto/corelib/io/qstandardpaths/BLACKLIST deleted file mode 100644 index d5ee9650cd..0000000000 --- a/tests/auto/corelib/io/qstandardpaths/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -[testFindExecutable] -# QTBUG-64404 -b2qt 64bit diff --git a/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro b/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro index 9fd7047405..44b1ce8dd8 100644 --- a/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro +++ b/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro @@ -5,3 +5,6 @@ INCLUDEPATH += ../../../../shared/ HEADERS += ../../../../shared/emulationdetector.h SOURCES = tst_qstandardpaths.cpp TESTDATA += tst_qstandardpaths.cpp qstandardpaths.pro + +# QTBUG-64404 +boot2qt: DEFINES+=SKIP_FINDEXECUTABLE diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 3de777653e..e316ce9acb 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -369,6 +369,12 @@ static inline QFileInfo findSh() void tst_qstandardpaths::testFindExecutable_data() { +#ifdef SKIP_FINDEXECUTABLE + // Test needs to be skipped or Q_ASSERT below will cancel the test + // and report FAIL regardless of BLACKLIST contents + QSKIP("QTBUG-64404"); +#endif + QTest::addColumn("directory"); QTest::addColumn("needle"); QTest::addColumn("expected"); diff --git a/tests/auto/corelib/serialization/qtextstream/test/test.pro b/tests/auto/corelib/serialization/qtextstream/test/test.pro index 3dcfa0b414..0f289a5ce1 100644 --- a/tests/auto/corelib/serialization/qtextstream/test/test.pro +++ b/tests/auto/corelib/serialization/qtextstream/test/test.pro @@ -3,6 +3,8 @@ TARGET = ../tst_qtextstream QT = core network testlib SOURCES = ../tst_qtextstream.cpp RESOURCES += ../qtextstream.qrc +INCLUDEPATH += ../../../../../shared/ +HEADERS += ../../../../../shared/emulationdetector.h win32 { CONFIG(debug, debug|release) { diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index df8746e518..77675b8e44 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -44,7 +44,7 @@ # include #endif #include "../../../network-settings.h" - +#include "emulationdetector.h" QT_BEGIN_NAMESPACE template<> struct QMetaTypeId @@ -1459,6 +1459,9 @@ void tst_QTextStream::pos2() // ------------------------------------------------------------------------------ void tst_QTextStream::pos3LargeFile() { + if (EmulationDetector::isRunningArmOnX86()) + QSKIP("Running QTextStream::pos() in tight loop is too slow on emulator"); + { QFile file(testFileName); file.open(QIODevice::WriteOnly | QIODevice::Text); -- cgit v1.2.3 From 042707a6339cff6795d8d2ea08f927924f218a7b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 22 Nov 2018 17:17:21 +0100 Subject: Avoid invalid qmake code in macOS-specific pluginloader test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You cannot manipulate variables in custom target dependencies, so the following code was invalid: i386_d.depends = EXPORT_VALID_ARCHS=i386 In order to still build the fat binary, we split the project in four, one for each architecture, plus one to create the final package. Change-Id: If08cf54e2e4098a7e10df41b7ea8d2bf699f58be Reviewed-by: Oswald Buddenhagen Reviewed-by: Tor Arne Vestbø --- .../plugin/qpluginloader/machtest/machtest.pri | 13 ++++ .../plugin/qpluginloader/machtest/machtest.pro | 73 ++++------------------ .../plugin/qpluginloader/machtest/machtest_fat.pro | 41 ++++++++++++ .../qpluginloader/machtest/machtest_i386.pro | 3 + .../qpluginloader/machtest/machtest_ppc64.pro | 9 +++ .../qpluginloader/machtest/machtest_x86_64.pro | 2 + 6 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pri create mode 100644 tests/auto/corelib/plugin/qpluginloader/machtest/machtest_fat.pro create mode 100644 tests/auto/corelib/plugin/qpluginloader/machtest/machtest_i386.pro create mode 100644 tests/auto/corelib/plugin/qpluginloader/machtest/machtest_ppc64.pro create mode 100644 tests/auto/corelib/plugin/qpluginloader/machtest/machtest_x86_64.pro (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pri b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pri new file mode 100644 index 0000000000..ca4a0a07e9 --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pri @@ -0,0 +1,13 @@ +TEMPLATE = aux + +# Needs explicit load()ing due to aux template. Relies on QT being non-empty. +load(qt) + +goodlib.target = good.$${QMAKE_APPLE_DEVICE_ARCHS}.dylib +goodlib.commands = $(CXX) $(CXXFLAGS) -shared -o $@ -I$(INCPATH) $< +goodlib.depends += $$PWD/../fakeplugin.cpp + +all.depends += goodlib + +QMAKE_EXTRA_TARGETS += goodlib all +QMAKE_CLEAN += $$goodlib.target diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pro b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pro index 7f7caa7f76..795dd89895 100644 --- a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pro +++ b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest.pro @@ -1,64 +1,15 @@ -TEMPLATE = aux -OTHER_FILES += \ - ppcconverter.pl \ - generate-bad.pl +TEMPLATE = subdirs -# Needs explicit load()ing due to aux template. Relies on QT being non-empty. -load(qt) - -i386_d.target = good.i386.dylib -i386_d.depends = EXPORT_VALID_ARCHS=i386 -i386.target = good.i386.dylib -i386.commands = $(CXX) $(CXXFLAGS) -shared -o $@ -I$(INCPATH) $< -i386.depends += $$PWD/../fakeplugin.cpp - -x86_64_d.target = good.x86_64.dylib -x86_64_d.depends = EXPORT_VALID_ARCHS=x86_64 -x86_64.target = good.x86_64.dylib -x86_64.commands = $(CXX) $(CXXFLAGS) -shared -o $@ -I$(INCPATH) $< -x86_64.depends += $$PWD/../fakeplugin.cpp - -# Current Mac OS X toolchains have no compiler for PPC anymore -# So we fake it by converting an x86-64 binary to (little-endian!) PPC64 -ppc64.target = good.ppc64.dylib -ppc64.commands = $$PWD/ppcconverter.pl $< $@ -ppc64.depends = x86_64 $$PWD/ppcconverter.pl - -# Generate a fat binary with three architectures -fat_all.target = good.fat.all.dylib -fat_all.commands = lipo -create -output $@ \ - -arch ppc64 $$ppc64.target \ - -arch i386 $$i386.target \ - -arch x86_64 $$x86_64.target -fat_all.depends += i386 x86_64 ppc64 - -fat_no_i386.target = good.fat.no-i386.dylib -fat_no_i386.commands = lipo -create -output $@ -arch x86_64 $$x86_64.target -arch ppc64 $$ppc64.target -fat_no_i386.depends += x86_64 ppc64 - -fat_no_x86_64.target = good.fat.no-x86_64.dylib -fat_no_x86_64.commands = lipo -create -output $@ -arch i386 $$i386.target -arch ppc64 $$ppc64.target -fat_no_x86_64.depends += i386 ppc64 - -fat_stub_i386.target = good.fat.stub-i386.dylib -fat_stub_i386.commands = lipo -create -output $@ -arch ppc64 $$ppc64.target -arch_blank i386 -fat_stub_i386.depends += x86_64 ppc64 - -fat_stub_x86_64.target = good.fat.stub-x86_64.dylib -fat_stub_x86_64.commands = lipo -create -output $@ -arch ppc64 $$ppc64.target -arch_blank x86_64 -fat_stub_x86_64.depends += i386 ppc64 - -bad.commands = $$PWD/generate-bad.pl -bad.depends += $$PWD/generate-bad.pl - -MYTARGETS = $$fat_all.depends fat_all fat_no_x86_64 fat_no_i386 \ - fat_stub_i386 fat_stub_x86_64 bad -all.depends += $$MYTARGETS -QMAKE_EXTRA_TARGETS += i386_d x86_64_d $$MYTARGETS all - -QMAKE_CLEAN += $$i386.target $$x86_64.target $$ppc64.target $$fat_all.target \ - $$fat_no_i386.target $$fat_no_x86_64.target \ - $$fat_stub_i386.target $$fat_stub_x86_64.target \ - "bad*.dylib" +SUBDIRS = \ + machtest_i386.pro \ + machtest_x86_64.pro \ + machtest_ppc64.pro \ + machtest_fat.pro +machtest_fat-pro.depends = \ + machtest_i386.pro \ + machtest_x86_64.pro \ + machtest_ppc64.pro +machtest_ppc64-pro.depends = \ + machtest_x86_64.pro diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_fat.pro b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_fat.pro new file mode 100644 index 0000000000..8daa343e2b --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_fat.pro @@ -0,0 +1,41 @@ +TEMPLATE = aux +OTHER_FILES += generate-bad.pl + +# Needs explicit load()ing due to aux template. Relies on QT being non-empty. +load(qt) + +# Generate a fat binary with three architectures +fat_all.target = good.fat.all.dylib +fat_all.commands = lipo -create -output $@ \ + -arch ppc64 good.ppc64.dylib \ + -arch i386 good.i386.dylib \ + -arch x86_64 good.x86_64.dylib +fat_all.depends += good.i386.dylib good.x86_64.dylib good.ppc64.dylib + +fat_no_i386.target = good.fat.no-i386.dylib +fat_no_i386.commands = lipo -create -output $@ -arch x86_64 good.x86_64.dylib -arch ppc64 good.ppc64.dylib +fat_no_i386.depends += good.x86_64.dylib good.ppc64.dylib + +fat_no_x86_64.target = good.fat.no-x86_64.dylib +fat_no_x86_64.commands = lipo -create -output $@ -arch i386 good.i386.dylib -arch ppc64 good.ppc64.dylib +fat_no_x86_64.depends += good.i386.dylib good.ppc64.dylib + +fat_stub_i386.target = good.fat.stub-i386.dylib +fat_stub_i386.commands = lipo -create -output $@ -arch ppc64 good.ppc64.dylib -arch_blank i386 +fat_stub_i386.depends += good.x86_64.dylib good.ppc64.dylib + +fat_stub_x86_64.target = good.fat.stub-x86_64.dylib +fat_stub_x86_64.commands = lipo -create -output $@ -arch ppc64 good.ppc64.dylib -arch_blank x86_64 +fat_stub_x86_64.depends += good.i386.dylib good.ppc64.dylib + +bad.commands = $$PWD/generate-bad.pl +bad.depends += $$PWD/generate-bad.pl + +MYTARGETS = $$fat_all.depends fat_all fat_no_x86_64 fat_no_i386 \ + fat_stub_i386 fat_stub_x86_64 bad +all.depends += $$MYTARGETS +QMAKE_EXTRA_TARGETS += $$MYTARGETS all + +QMAKE_CLEAN += $$fat_all.target $$fat_no_i386.target $$fat_no_x86_64.target \ + $$fat_stub_i386.target $$fat_stub_x86_64.target \ + "bad*.dylib" diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_i386.pro b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_i386.pro new file mode 100644 index 0000000000..bfb2e0930c --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_i386.pro @@ -0,0 +1,3 @@ +QMAKE_APPLE_DEVICE_ARCHS = i386 +include(machtest.pri) + diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_ppc64.pro b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_ppc64.pro new file mode 100644 index 0000000000..a73f97ccc6 --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_ppc64.pro @@ -0,0 +1,9 @@ +QMAKE_APPLE_DEVICE_ARCHS = ppc64 +include(machtest.pri) + +OTHER_FILES += ppcconverter.pl + +# Current macOS toolchains have no compiler for PPC anymore +# So we fake it by converting an x86-64 binary to (little-endian!) PPC64 +goodlib.commands = $$PWD/ppcconverter.pl $< $@ +goodlib.depends = good.x86_64.dylib $$PWD/ppcconverter.pl diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_x86_64.pro b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_x86_64.pro new file mode 100644 index 0000000000..9dbae5c4ee --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/machtest/machtest_x86_64.pro @@ -0,0 +1,2 @@ +QMAKE_APPLE_DEVICE_ARCHS = x86_64 +include(machtest.pri) -- cgit v1.2.3 From c0dd44556454ce0fa451f83decdad3931a6deaec Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Fri, 30 Nov 2018 12:49:01 +0200 Subject: Fix a nullptr compile error with gcc 4.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit template argument deduction/substitution failed: qtbase/tests/auto/corelib/kernel/qobject/tst_qobject.cpp:6756:71: note: mismatched types ‘const typename QtPrivate::FunctionPointer::Object*’ and ‘std::nullptr_t’ Change-Id: I8e7872457d1fc30c4b29e96c16091915264f9bce Reviewed-by: Simon Hausmann --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index effc82261b..06254091cd 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6750,16 +6750,16 @@ void tst_QObject::connectWarnings() r1.reset(); QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter"); - connect(nullptr, &SubSender::signal1, &r1, &ReceiverObject::slot1); + connect(static_cast(nullptr), &SubSender::signal1, &r1, &ReceiverObject::slot1); QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SubSender, Unknown): invalid null parameter"); - connect(&sub, &SubSender::signal1, nullptr, &ReceiverObject::slot1); + connect(&sub, &SubSender::signal1, static_cast(nullptr), &ReceiverObject::slot1); QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter"); - connect(nullptr, &SenderObject::signal1, &r1, &ReceiverObject::slot1); + connect(static_cast(nullptr), &SenderObject::signal1, &r1, &ReceiverObject::slot1); QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, Unknown): invalid null parameter"); - connect(&obj, &SenderObject::signal1, nullptr, &ReceiverObject::slot1); + connect(&obj, &SenderObject::signal1, static_cast(nullptr), &ReceiverObject::slot1); } struct QmlReceiver : public QtPrivate::QSlotObjectBase -- cgit v1.2.3 From 4ee59cf96d80c752ebfa127792d65d7b84abbd74 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 6 Dec 2018 13:11:25 +0100 Subject: Remove one out-of-date comment, refine another that was imprecise The former is a follow-up to c17563eca8. Change-Id: I3cd41e6e38f740de67605f785a804ffd879b9e67 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qcollator/tst_qcollator.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp index 00b22dab6c..2d65d3433f 100644 --- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp @@ -95,11 +95,6 @@ void tst_QCollator::compare_data() QTest::addColumn("ignorePunctuation"); QTest::addColumn("punctuationResult"); - /* - A few tests below are commented out on the mac. It's unclear why they fail, - as it looks like the collator for the locale is created correctly. - */ - /* It's hard to test English, because it's treated differently on different platforms. For example, on Linux, it uses the @@ -164,7 +159,7 @@ void tst_QCollator::compare_data() QTest::newRow("german13") << QString("de_DE") << QString("test.19") << QString("test,19") << 1 << 1 << true << true << 0; /* - French sorting of e and e with accent + French sorting of e and e with acute accent */ QTest::newRow("french1") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("e") << 1 << 1 << false << false << 1; QTest::newRow("french2") << QString("fr_FR") << QString::fromLatin1("\xe9t") << QString::fromLatin1("et") << 1 << 1 << false << false << 1; -- cgit v1.2.3 From 962bded90f0ffb7390b4a2a1a5a895156aa5f541 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 1 Dec 2018 18:02:52 -0600 Subject: Fix QSettings parsing of spaces after comment lines [ChangeLog][QtCore][QSettings] Fixed QSettings parsing of blank spaces after comment lines in INI-style configuration files. Fixes: QTBUG-72007 Change-Id: Idd0c85a4e7b64f9c9c7dfffd156c5b219f3b5c0a Reviewed-by: Oliver Wolff --- tests/auto/corelib/io/qsettings/qsettings.qrc | 1 + tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 29 +++++++++++++++++++++++ tests/auto/corelib/io/qsettings/withcomments.ini | 19 +++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/auto/corelib/io/qsettings/withcomments.ini (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qsettings/qsettings.qrc b/tests/auto/corelib/io/qsettings/qsettings.qrc index c664a6f68c..db1d8c663f 100644 --- a/tests/auto/corelib/io/qsettings/qsettings.qrc +++ b/tests/auto/corelib/io/qsettings/qsettings.qrc @@ -7,5 +7,6 @@ resourcefile5.ini resourcefile6.plist bom.ini + withcomments.ini diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 5357194406..8b69518ef7 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -187,6 +187,7 @@ private slots: void bom(); void embeddedZeroByte_data(); void embeddedZeroByte(); + void spaceAfterComment(); void testXdg(); private: @@ -764,6 +765,34 @@ void tst_QSettings::embeddedZeroByte() } } +void tst_QSettings::spaceAfterComment() +{ + QSettings settings(QFINDTESTDATA("withcomments.ini"), QSettings::IniFormat); + QCOMPARE(settings.status(), QSettings::NoError); + + QStringList groups = settings.childGroups(); + QVERIFY(groups.contains("Regular")); + QVERIFY(groups.contains("WithSpaces")); + QVERIFY(groups.contains("WithTab")); + QVERIFY(groups.contains("SpacedGroup")); + + settings.beginGroup("Regular"); + QCOMPARE(settings.value("bar"), QVariant(2)); + settings.endGroup(); + + settings.beginGroup("WithSpaces"); + QCOMPARE(settings.value("bar"), QVariant(4)); + settings.endGroup(); + + settings.beginGroup("WithTab"); + QCOMPARE(settings.value("bar"), QVariant(6)); + settings.endGroup(); + + settings.beginGroup("SpacedGroup"); + QCOMPARE(settings.value("bar"), QVariant(7)); + settings.endGroup(); +} + void tst_QSettings::testErrorHandling_data() { QTest::addColumn("filePerms"); // -1 means file should not exist diff --git a/tests/auto/corelib/io/qsettings/withcomments.ini b/tests/auto/corelib/io/qsettings/withcomments.ini new file mode 100644 index 0000000000..d2de3a356b --- /dev/null +++ b/tests/auto/corelib/io/qsettings/withcomments.ini @@ -0,0 +1,19 @@ +; -*- conf -*- +; If you edit this file, make sure, that "WithSpaces" has spaces and that +; "WithTab" has one tab + +[Regular] +;bar = 1 +bar = 2 + +[WithSpaces] +;bar = 3 + bar = 4 + +[WithTab] +;bar = 5 + bar = 6 + +; [SpacedGroup] + [SpacedGroup] + bar = 7 -- cgit v1.2.3 From b2297e595c43a5986a082c40443576436f8497d0 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 19 Nov 2018 21:37:37 +0100 Subject: QUrlQuery: Implement initializer list constructor [ChangeLog][QtCore][QUrlQuery] QUrlQuery now provides an initializer list constructor. It can be created using a list of key/value pairs. Fixes: QTBUG-68645 Change-Id: Ief5939aa477718f6dd3580f2c60f95ff3aa892ae Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp index d839141091..25d392b37e 100644 --- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp +++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp @@ -233,6 +233,14 @@ void tst_QUrlQuery::constructing() query += qMakePair(QString("prosent"), QString("%")); copy.setQueryItems(query); QVERIFY(!copy.isEmpty()); + + QUrlQuery fromList = { + {QString("type"), QString("login")}, + {QString("name"), QString::fromUtf8("åge nissemannsen")}, + {QString("ole&du"), QString::fromUtf8("anne+jørgen=sant")}, + {QString("prosent"), QString("%")} + }; + QCOMPARE(fromList, copy); } void tst_QUrlQuery::addRemove() -- cgit v1.2.3 From fc85a6b6b952aa619b87262d4187dc05865ab51a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 6 Oct 2018 22:33:57 +0200 Subject: QTypeInfo: use C++11 type traits to deduce if a type is static or complex All types that can be trivially copied and destructed are by definition relocatable, and we should apply those semantics when moving them in memory. Types that are trivial, are by definition not complex and should be treated as such. [ChangeLog][QtCore] Qt Containers and meta type system now use C++11 type traits (std::is_trivial, std::is_trivially_copyable and std::is_trivially_destructible) to detect the class of a type not explicitly set by Q_DECLARE_TYPEINFO. (Q_DECLARE_TYPEINFO is still needed for QList.) Done-with: Olivier Goffart (Woboq GmbH) Change-Id: Iebb87ece425ea919e86169d06cd509c54a074282 Reviewed-by: Thiago Macieira --- .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 24 ++++++++++++++++------ tests/auto/corelib/tools/qpair/tst_qpair.cpp | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 0c328dff58..fb11e4c522 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -342,6 +342,7 @@ struct Bar ++failureCount; } } + ~Bar() {} public: static int failureCount; @@ -458,7 +459,7 @@ void tst_QMetaType::threadSafety() namespace TestSpace { - struct Foo { double d; }; + struct Foo { double d; public: ~Foo() {} }; struct QungTfu {}; } Q_DECLARE_METATYPE(TestSpace::Foo) @@ -515,11 +516,17 @@ void tst_QMetaType::properties() } template -struct Whity { T t; }; +struct Whity { T t; Whity() {} }; Q_DECLARE_METATYPE( Whity < int > ) Q_DECLARE_METATYPE(Whity) +#if !defined(Q_CC_CLANG) && defined(Q_CC_GNU) && Q_CC_GNU < 501 +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(Whity, Q_MOVABLE_TYPE); +QT_END_NAMESPACE +#endif + void tst_QMetaType::normalizedTypes() { int WhityIntId = ::qMetaTypeId >(); @@ -818,10 +825,13 @@ void tst_QMetaType::sizeOfStaticLess() QCOMPARE(size_t(QMetaType(type).sizeOf()), size); } -struct CustomMovable {}; +struct CustomMovable { CustomMovable() {} }; +#if !defined(Q_CC_CLANG) && defined(Q_CC_GNU) && Q_CC_GNU < 501 QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(CustomMovable, Q_MOVABLE_TYPE); QT_END_NAMESPACE +#endif + Q_DECLARE_METATYPE(CustomMovable); class CustomObject : public QObject @@ -850,13 +860,15 @@ public: }; Q_DECLARE_METATYPE(CustomMultiInheritanceObject*); -class C { char _[4]; }; -class M { char _[4]; }; +class C { char _[4]; public: C() = default; C(const C&) {} }; +class M { char _[4]; public: M() {} }; class P { char _[4]; }; QT_BEGIN_NAMESPACE +#if defined(Q_CC_GNU) && Q_CC_GNU < 501 Q_DECLARE_TYPEINFO(M, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(P, Q_PRIMITIVE_TYPE); +#endif QT_END_NAMESPACE // avoid the comma: @@ -902,7 +914,7 @@ QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) #undef ADD_METATYPE_TEST_ROW QTest::newRow("TestSpace::Foo") << ::qMetaTypeId() << false << true << false << false; - QTest::newRow("Whity") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("Whity") << ::qMetaTypeId >() << true << true << false << false; QTest::newRow("CustomMovable") << ::qMetaTypeId() << true << true << false << false; QTest::newRow("CustomObject*") << ::qMetaTypeId() << true << false << true << false; QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId() << true << false << true << false; diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp index 1d5f7536c8..dedc353e67 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -41,8 +41,8 @@ private Q_SLOTS: void taskQTBUG_48780_pairContainingCArray(); }; -class C { char _[4]; }; -class M { char _[4]; }; +class C { C() {} char _[4]; }; +class M { M() {} char _[4]; }; class P { char _[4]; }; QT_BEGIN_NAMESPACE -- cgit v1.2.3 From b3008f8e253f5fca2c7d3328badcfeb189181652 Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Thu, 4 Oct 2018 16:49:34 +0200 Subject: Use QScopedPointer instead of new/delete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0651ad0244c1b4d3126a1dd3304f247f92240ffa Reviewed-by: Mårten Nordheim Reviewed-by: Jędrzej Nowacki Reviewed-by: Edward Welbourne --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 68a92ebcc3..31268c5cf3 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #if QT_CONFIG(process) # include #endif @@ -500,14 +501,13 @@ void tst_QObject::connectSlotsByName() void tst_QObject::qobject_castTemplate() { - QObject *o = 0; - QVERIFY( !::qobject_cast(o) ); + QScopedPointer o; + QVERIFY(!::qobject_cast(o.data())); - o = new SenderObject; - QVERIFY( ::qobject_cast(o) ); - QVERIFY( ::qobject_cast(o) ); - QVERIFY( !::qobject_cast(o) ); - delete o; + o.reset(new SenderObject); + QVERIFY(::qobject_cast(o.data())); + QVERIFY(::qobject_cast(o.data())); + QVERIFY(!::qobject_cast(o.data())); } void tst_QObject::findChildren() -- cgit v1.2.3 From ab448f731ecd8437c7c5c8b96a0e7f419ec3a7ca Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 2 Oct 2018 19:02:29 +0200 Subject: Handle QCollator with locale C by delegating to QString Previously, the C locale was treated as English because each back-end takes the locale's bcp47Name(), which maps C to en. However, the C locale has its own rules; which QString helpfully implements; so we can delegate to it in this case. Extended this to sort keys, where possible. Clean up existing implementations in the process. Extended tst_QCollator::compare() with some cases to check this. That required wrapping the test's calls to collator.compare() in a sign canonicalizer, since it can return any -ve for < or +ve for >, not just -1 and +1 for these cases (and it'd be rash to hard-code specific negative and positive values, as they may vary between backends). [ChangeLog][QtCore][QCollator] Added support for collation in the C locale, albeit this is only well-defined for ASCII. Collation sort keys remain unsupported on Darwin. Fixes: QTBUG-58621 Change-Id: I327010d90f09bd1b1816f5590cb124e3d423e61d Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qcollator/tst_qcollator.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp index 2d65d3433f..72f88a235d 100644 --- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp @@ -93,7 +93,7 @@ void tst_QCollator::compare_data() QTest::addColumn("caseInsensitiveResult"); QTest::addColumn("numericMode"); QTest::addColumn("ignorePunctuation"); - QTest::addColumn("punctuationResult"); + QTest::addColumn("punctuationResult"); // Test ignores punctuation *and case* /* It's hard to test English, because it's treated differently @@ -169,8 +169,12 @@ void tst_QCollator::compare_data() QTest::newRow("french6") << QString("fr_FR") << QString("Test 9") << QString("Test_19") << -1 << -1 << true << true << -1; QTest::newRow("french7") << QString("fr_FR") << QString("test_19") << QString("test 19") << 1 << 1 << true << false << 1; QTest::newRow("french8") << QString("fr_FR") << QString("test.19") << QString("test,19") << 1 << 1 << true << true << 0; -} + // C locale: case sensitive [A-Z] < [a-z] but case insensitive [Aa] < [Bb] <...< [Zz] + const QString C = QStringLiteral("C"); + QTest::newRow("C:ABBA:AaaA") << C << QStringLiteral("ABBA") << QStringLiteral("AaaA") << -1 << 1 << false << false << 1; + QTest::newRow("C:AZa:aAZ") << C << QStringLiteral("AZa") << QStringLiteral("aAZ") << -1 << 1 << false << false << 1; +} void tst_QCollator::compare() { @@ -184,6 +188,10 @@ void tst_QCollator::compare() QFETCH(int, punctuationResult); QCollator collator(locale); + // Need to canonicalize sign to -1, 0 or 1, as .compare() can produce any -ve for <, any +ve for >. + auto asSign = [](int compared) { + return compared < 0 ? -1 : compared > 0 ? 1 : 0; + }; #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) if (collator.locale() != QLocale()) @@ -193,12 +201,12 @@ void tst_QCollator::compare() if (numericMode) collator.setNumericMode(true); - QCOMPARE(collator.compare(s1, s2), result); + QCOMPARE(asSign(collator.compare(s1, s2)), result); collator.setCaseSensitivity(Qt::CaseInsensitive); - QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult); + QCOMPARE(asSign(collator.compare(s1, s2)), caseInsensitiveResult); #if !QT_CONFIG(iconv) collator.setIgnorePunctuation(ignorePunctuation); - QCOMPARE(collator.compare(s1, s2), punctuationResult); + QCOMPARE(asSign(collator.compare(s1, s2)), punctuationResult); #endif } -- cgit v1.2.3 From eaf4438b3511c8380b9b691b656a87a60e342e29 Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Tue, 11 Dec 2018 11:42:34 +0200 Subject: Make url normalization closer to common browser behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Firefox, Chrome and various http libraries normalize /./ and /../ from urls, but retain multiple adjacent slashes as is. Qt removes duplicated slashes which makes it impossible to access some web resources that rely on those. Fixes: QTBUG-71973 Change-Id: Ie18ae6ad3264acb252fcd87a754726a8c546e5ec Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 9 ++------- tests/auto/corelib/io/qurl/tst_qurl.cpp | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 30f0e447ad..af9c6be432 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -62,12 +62,7 @@ #endif #ifdef QT_BUILD_INTERNAL - -QT_BEGIN_NAMESPACE -extern Q_AUTOTEST_EXPORT QString - qt_normalizePathSegments(const QString &path, bool allowUncPaths, bool *ok = nullptr); -QT_END_NAMESPACE - +#include "private/qdir_p.h" #endif static QByteArray msgDoesNotExist(const QString &name) @@ -1376,7 +1371,7 @@ void tst_QDir::normalizePathSegments() QFETCH(QString, path); QFETCH(UncHandling, uncHandling); QFETCH(QString, expected); - QString cleaned = qt_normalizePathSegments(path, uncHandling == HandleUnc); + QString cleaned = qt_normalizePathSegments(path, uncHandling == HandleUnc ? QDirPrivate::AllowUncPaths : QDirPrivate::DefaultNormalization); QCOMPARE(cleaned, expected); if (path == expected) QVERIFY2(path.isSharedWith(cleaned), "Strings are same but data is not shared"); diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 84af1c255a..4f173d2dfd 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -182,6 +182,8 @@ private slots: void matches(); void ipv6_zoneId_data(); void ipv6_zoneId(); + void normalizeRemotePaths_data(); + void normalizeRemotePaths(); private: void testThreadingHelper(); @@ -323,7 +325,7 @@ void tst_QUrl::comparison() QUrl url3bis = QUrl::fromEncoded("example://a/b/c/%7Bfoo%7D/"); QUrl url3bisNoSlash = QUrl::fromEncoded("example://a/b/c/%7Bfoo%7D"); - QUrl url4bis = QUrl::fromEncoded("example://a/.//b/../b/c//%7Bfoo%7D/"); + QUrl url4bis = QUrl::fromEncoded("example://a/./b/../b/c/%7Bfoo%7D/"); QCOMPARE(url4bis.adjusted(QUrl::NormalizePathSegments), url3bis); QCOMPARE(url4bis.adjusted(QUrl::NormalizePathSegments | QUrl::StripTrailingSlash), url3bisNoSlash); QVERIFY(url3bis.matches(url4bis, QUrl::NormalizePathSegments)); @@ -335,7 +337,7 @@ void tst_QUrl::comparison() QCOMPARE(url4EncodedDots.path(QUrl::FullyDecoded), QString("/.//b/..//b/c/")); QCOMPARE(QString::fromLatin1(url4EncodedDots.toEncoded()), QString::fromLatin1("example://a/.//b/..%2F/b/c/")); QCOMPARE(url4EncodedDots.toString(), QString("example://a/.//b/..%2F/b/c/")); - QCOMPARE(url4EncodedDots.adjusted(QUrl::NormalizePathSegments).toString(), QString("example://a/b/..%2F/b/c/")); + QCOMPARE(url4EncodedDots.adjusted(QUrl::NormalizePathSegments).toString(), QString("example://a//b/..%2F/b/c/")); // 6.2.2.1 Make sure hexdecimal characters in percent encoding are // treated case-insensitively @@ -4201,6 +4203,36 @@ void tst_QUrl::ipv6_zoneId() QCOMPARE(url.toString(QUrl::FullyEncoded), "x://[" + encodedHost + "]"); } +void tst_QUrl::normalizeRemotePaths_data() +{ + QTest::addColumn("url"); + QTest::addColumn("expected"); + + QTest::newRow("dotdot-slashslash") << QUrl("http://qt-project.org/some/long/..//path") << "http://qt-project.org/some//path"; + QTest::newRow("slashslash-dotdot") << QUrl("http://qt-project.org/some//../path") << "http://qt-project.org/some/path"; + QTest::newRow("slashslash-dotdot2") << QUrl("http://qt-project.org/some//path/../") << "http://qt-project.org/some//"; + QTest::newRow("dot-slash") << QUrl("http://qt-project.org/some/./path") << "http://qt-project.org/some/path"; + QTest::newRow("slashslash-dot-slashslash") << QUrl("http://qt-project.org/some//.//path") << "http://qt-project.org/some///path"; + QTest::newRow("dot-slashslash") << QUrl("http://qt-project.org/some/.//path") << "http://qt-project.org/some//path"; + QTest::newRow("multiple-slashes") << QUrl("http://qt-project.org/some//path") << "http://qt-project.org/some//path"; + QTest::newRow("multiple-slashes4") << QUrl("http://qt-project.org/some////path") << "http://qt-project.org/some////path"; + QTest::newRow("slashes-at-end") << QUrl("http://qt-project.org/some//") << "http://qt-project.org/some//"; + QTest::newRow("dot-dotdot") << QUrl("http://qt-project.org/path/./../") << "http://qt-project.org/"; + QTest::newRow("slash-dot-slash-dot-slash") << QUrl("http://qt-project.org/path//.//.//") << "http://qt-project.org/path////"; + QTest::newRow("dotdot") << QUrl("http://qt-project.org/../") << "http://qt-project.org/"; + QTest::newRow("dotdot-dotdot") << QUrl("http://qt-project.org/path/../../") << "http://qt-project.org/"; + QTest::newRow("dot-dotdot-tail") << QUrl("http://qt-project.org/stem/path/./../tail") << "http://qt-project.org/stem/tail"; + QTest::newRow("slash-dotdot-slash-tail") << QUrl("http://qt-project.org/stem/path//..//tail") << "http://qt-project.org/stem/path//tail"; +} + +void tst_QUrl::normalizeRemotePaths() +{ + QFETCH(QUrl, url); + QFETCH(QString, expected); + + QCOMPARE(url.adjusted(QUrl::NormalizePathSegments).toString(), expected); +} + QTEST_MAIN(tst_QUrl) #include "tst_qurl.moc" -- cgit v1.2.3 From 649ee12aba2ee92781f0ab888d21a1bdb440b7da Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Fri, 14 Dec 2018 20:59:55 +0100 Subject: QRegularExpression: anchor wildcard pattern The current implementation of wildcardToRegularExpression doesn't anchor the pattern which makes it not narrow enough for globbing patterns. This patch fixes that by applying anchoredPattern before returning the wildcard pattern. [ChangeLog][QtCore][QRegularExpression] The wildcardToRegularExpression method now returns a properly anchored pattern. Change-Id: I7bee73389d408cf42499652e4fb854517a8125b5 Fixes: QTBUG-72539 Reviewed-by: Thiago Macieira --- .../qregularexpression/tst_qregularexpression.cpp | 76 +++++++++++----------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index c23ee3b0ba..c02756d76a 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -2169,47 +2169,47 @@ void tst_QRegularExpression::wildcard_data() addRow("*.html", "test.html", 0); addRow("*.html", "test.htm", -1); - addRow("bar*", "foobarbaz", 3); + addRow("*bar*", "foobarbaz", 0); addRow("*", "Qt Rocks!", 0); - addRow(".html", "test.html", 4); - addRow(".h", "test.cpp", -1); - addRow(".???l", "test.html", 4); - addRow("?", "test.html", 0); - addRow("?m", "test.html", 6); - addRow("[*]", "test.html", -1); - addRow("[?]","test.html", -1); - addRow("[?]","test.h?ml", 6); - addRow("[[]","test.h[ml", 6); - addRow("[]]","test.h]ml", 6); - addRow(".h[a-z]ml", "test.html", 4); - addRow(".h[A-Z]ml", "test.html", -1); - addRow(".h[A-Z]ml", "test.hTml", 4); - addRow(".h[!A-Z]ml", "test.hTml", -1); - addRow(".h[!A-Z]ml", "test.html", 4); - addRow(".h[!T]ml", "test.hTml", -1); - addRow(".h[!T]ml", "test.html", 4); - addRow(".h[!T]m[!L]", "test.htmL", -1); - addRow(".h[!T]m[!L]", "test.html", 4); - addRow(".h[][!]", "test.h]ml", 4); - addRow(".h[][!]", "test.h[ml", 4); - addRow(".h[][!]", "test.h!ml", 4); - - addRow("foo/*/bar", "Qt/foo/baz/bar", 3); - addRow("foo/(*)/bar", "Qt/foo/baz/bar", -1); - addRow("foo/(*)/bar", "Qt/foo/(baz)/bar", 3); - addRow("foo/?/bar", "Qt/foo/Q/bar", 3); - addRow("foo/?/bar", "Qt/foo/Qt/bar", -1); - addRow("foo/(?)/bar", "Qt/foo/Q/bar", -1); - addRow("foo/(?)/bar", "Qt/foo/(Q)/bar", 3); + addRow("*.html", "test.html", 0); + addRow("*.h", "test.cpp", -1); + addRow("*.???l", "test.html", 0); + addRow("*?", "test.html", 0); + addRow("*?ml", "test.html", 0); + addRow("*[*]", "test.html", -1); + addRow("*[?]","test.html", -1); + addRow("*[?]ml","test.h?ml", 0); + addRow("*[[]ml","test.h[ml", 0); + addRow("*[]]ml","test.h]ml", 0); + addRow("*.h[a-z]ml", "test.html", 0); + addRow("*.h[A-Z]ml", "test.html", -1); + addRow("*.h[A-Z]ml", "test.hTml", 0); + addRow("*.h[!A-Z]ml", "test.hTml", -1); + addRow("*.h[!A-Z]ml", "test.html", 0); + addRow("*.h[!T]ml", "test.hTml", -1); + addRow("*.h[!T]ml", "test.html", 0); + addRow("*.h[!T]m[!L]", "test.htmL", -1); + addRow("*.h[!T]m[!L]", "test.html", 0); + addRow("*.h[][!]ml", "test.h]ml", 0); + addRow("*.h[][!]ml", "test.h[ml", 0); + addRow("*.h[][!]ml", "test.h!ml", 0); + + addRow("foo/*/bar", "foo/baz/bar", 0); + addRow("foo/(*)/bar", "foo/baz/bar", -1); + addRow("foo/(*)/bar", "foo/(baz)/bar", 0); + addRow("foo/?/bar", "foo/Q/bar", 0); + addRow("foo/?/bar", "foo/Qt/bar", -1); + addRow("foo/(?)/bar", "foo/Q/bar", -1); + addRow("foo/(?)/bar", "foo/(Q)/bar", 0); #ifdef Q_OS_WIN - addRow("foo\\*\\bar", "Qt\\foo\\baz\\bar", 3); - addRow("foo\\(*)\\bar", "Qt\\foo\\baz\\bar", -1); - addRow("foo\\(*)\\bar", "Qt\\foo\\(baz)\\bar", 3); - addRow("foo\\?\\bar", "Qt\\foo\\Q\\bar", 3); - addRow("foo\\?\\bar", "Qt\\foo\\Qt\\bar", -1); - addRow("foo\\(?)\\bar", "Qt\\foo\\Q\\bar", -1); - addRow("foo\\(?)\\bar", "Qt\\foo\\(Q)\\bar", 3); + addRow("foo\\*\\bar", "foo\\baz\\bar", 0); + addRow("foo\\(*)\\bar", "foo\\baz\\bar", -1); + addRow("foo\\(*)\\bar", "foo\\(baz)\\bar", 0); + addRow("foo\\?\\bar", "foo\\Q\\bar", 0); + addRow("foo\\?\\bar", "foo\\Qt\\bar", -1); + addRow("foo\\(?)\\bar", "foo\\Q\\bar", -1); + addRow("foo\\(?)\\bar", "foo\\(Q)\\bar", 0); #endif } -- cgit v1.2.3 From 50d53533e5ab1923865a9f80cb8b093ab477ae81 Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 12 Dec 2018 09:41:49 +0100 Subject: QCommandLineParser: show application name in error messages Change-Id: I2c39759294ca0a11a59b9a38207bf1aef941b070 Fixes: QTBUG-58490 Reviewed-by: Thiago Macieira --- .../qcommandlineparser/tst_qcommandlineparser.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 62c29229e1..7980f1f8f4 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -74,6 +74,7 @@ private slots: void testHelpOption_data(); void testHelpOption(); void testQuoteEscaping(); + void testUnknownOption(); }; static char *empty_argv[] = { 0 }; @@ -648,6 +649,27 @@ void tst_QCommandLineParser::testQuoteEscaping() #endif // QT_CONFIG(process) } +void tst_QCommandLineParser::testUnknownOption() +{ +#if !QT_CONFIG(process) + QSKIP("This test requires QProcess support"); +#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) + QSKIP("Deploying executable applications to file system on Android not supported."); +#else + QCoreApplication app(empty_argc, empty_argv); + QProcess process; + process.start("testhelper/qcommandlineparser_test_helper", QStringList() << + QString::number(QCommandLineParser::ParseAsLongOptions) << + "-unknown-option"); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + process.setReadChannel(QProcess::StandardError); + QString output = process.readAll(); + QVERIFY2(output.contains("qcommandlineparser_test_helper"), qPrintable(output)); // separate in case of .exe extension + QVERIFY2(output.contains(": Unknown option 'unknown-option'"), qPrintable(output)); +#endif // QT_CONFIG(process) +} + QTEST_APPLESS_MAIN(tst_QCommandLineParser) #include "tst_qcommandlineparser.moc" -- cgit v1.2.3 From ff835a5030f3ec0aaa91ad0332739ca3259804e8 Mon Sep 17 00:00:00 2001 From: Luca Beldi Date: Thu, 6 Dec 2018 08:48:35 +0000 Subject: Fix QStringListModel::setData to check for actual changes QStringListModel::setData documentation states that "The dataChanged() signal is emitted if the item is changed." This patch actually respects the doc. setData will check that the data actually changed before sending the dataChanged signal. [ChangeLog][QtCore][QStringListModel] setData will now emit the dataChanged() signal only if the string set is different from the one already contained in the model Change-Id: I4308a6f3b4851203fb899c5e29a36076e0c32f2f Reviewed-by: David Faure --- .../qstringlistmodel/tst_qstringlistmodel.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp index 9a54c0a70d..1b40e77648 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp @@ -81,6 +81,8 @@ private slots: void setData_emits_both_roles_data(); void setData_emits_both_roles(); + void setData_emits_on_change_only(); + void supportedDragDropActions(); }; @@ -246,6 +248,24 @@ void tst_QStringListModel::setData_emits_both_roles() expected); } +void tst_QStringListModel::setData_emits_on_change_only() +{ + QStringListModel model(QStringList{QStringLiteral("one"), QStringLiteral("two")}); + QSignalSpy dataChangedSpy(&model, &QAbstractItemModel::dataChanged); + QVERIFY(dataChangedSpy.isValid()); + const QModelIndex modelIdx = model.index(0, 0); + const QString newStringData = QStringLiteral("test"); + QVERIFY(model.setData(modelIdx, newStringData)); + QCOMPARE(dataChangedSpy.count(), 1); + const QList spyList = dataChangedSpy.takeFirst(); + QCOMPARE(spyList.at(0).value(), modelIdx); + QCOMPARE(spyList.at(1).value(), modelIdx); + const QVector expectedRoles{Qt::DisplayRole, Qt::EditRole}; + QCOMPARE(spyList.at(2).value >(), expectedRoles); + QVERIFY(model.setData(modelIdx, newStringData)); + QVERIFY(dataChangedSpy.isEmpty()); +} + void tst_QStringListModel::supportedDragDropActions() { QStringListModel model; -- cgit v1.2.3 From 8c2ca29045498be5fd74b8a4df633e7edae211c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Thu, 15 Nov 2018 09:51:25 +0200 Subject: Revert "Blacklist tst_QTimer::basic_chrono on macOS" Incorrectly blacklisted. This reverts commit 40a7c57ba990dfd58814a4a9dc69948991458cd4. Task-number: QTBUG-61013 Change-Id: I7d9dc4a4b1c8d7ff77ab75c61027b908ffb74552 Reviewed-by: Liang Qi --- tests/auto/corelib/kernel/qtimer/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/BLACKLIST b/tests/auto/corelib/kernel/qtimer/BLACKLIST index b355bc22c2..e5136624d8 100644 --- a/tests/auto/corelib/kernel/qtimer/BLACKLIST +++ b/tests/auto/corelib/kernel/qtimer/BLACKLIST @@ -1,5 +1,3 @@ [remainingTime] windows osx -[basic_chrono] -osx ci -- cgit v1.2.3 From ecdccce8e468784e050b65052da193bb40e2d9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 4 Jan 2019 13:48:56 +0100 Subject: Fix warnings about uninitialized variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qtbase/src/corelib/kernel/qmetatype.cpp: In static member function ‘static void QMetaType::destroy(int, void*)’: qtbase/src/corelib/kernel/qmetatype.cpp:2599:27: error: ‘info.QMetaType::m_destructor’ may be used uninitialized in this function [-Werror=maybe-uninitialized] if (m_typedDestructor && !m_destructor) ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ qtbase/src/corelib/kernel/qmetatype.cpp:1868:15: note: ‘info.QMetaType::m_destructor’ was declared here QMetaType info(type); ^~~~ qtbase/src/corelib/kernel/qmetatype.cpp:2600:26: error: ‘info.QMetaType::m_typedDestructor’ may be used uninitialized in this function [-Werror=maybe-uninitialized] m_typedDestructor(m_typeId, data); ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ qtbase/src/corelib/kernel/qmetatype.cpp:1868:15: note: ‘info.QMetaType::m_typedDestructor’ was declared here QMetaType info(type); ^~~~ The extended (not inlined) function may be called on a half initialized invalid instance. Change-Id: I26d677a8ad2bd0c5846233f06393e774d377936d Reviewed-by: Liang Qi Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 5d9b5ca95c..e6fac74ccc 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -123,6 +123,7 @@ private slots: void compareCustomType(); void compareCustomEqualOnlyType(); void customDebugStream(); + void unknownType(); }; struct BaseGenericType @@ -2529,6 +2530,16 @@ void tst_QMetaType::customDebugStream() qDebug() << v1; } +void tst_QMetaType::unknownType() +{ + QMetaType invalid(QMetaType::UnknownType); + QVERIFY(!invalid.create()); + QVERIFY(!invalid.sizeOf()); + QVERIFY(!invalid.metaObject()); + int buffer = 0xBAD; + invalid.construct(&buffer); + QCOMPARE(buffer, 0xBAD); +} // Compile-time test, it should be possible to register function pointer types class Undefined; -- cgit v1.2.3 From dd5e7f1a52c51061ad54e870df7f8e04c0f06fbe Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 5 Nov 2018 16:55:08 +0100 Subject: Use a more robust test for absolute paths in QDir Its filePath() and absoluteFilePath() don't trust its own isAbsolute(), due to some infelicities on MS-Win; and kludged round a consequent problem with resource paths; but other virtual file systems weren't catered for. Replace the convoluted test there with a static bool function (so that future kludges in this area shall only need to edit one place; and can document why they're needed) and use a more robust test that handles all virtual file systems (by asking QFileInfo) but falls back to QFileSystemEntry to work round the known infelicities on MS-Win. Add regression test for asset library paths issue on iOS. Ammends 27f1f84c1c2. Moved a couple of local variables to after the early return, since it doesn't need them, in the process. Task-number: QTBUG-70237 Change-Id: Ib3954826df40ccf816beebe5c3751497e3bf6433 Reviewed-by: Edward Welbourne Reviewed-by: Andy Shaw --- tests/auto/corelib/io/qdir/Info.plist | 41 +++++++++++++++++++++++++++++++++ tests/auto/corelib/io/qdir/qdir.pro | 1 + tests/auto/corelib/io/qdir/tst_qdir.cpp | 5 ++++ 3 files changed, 47 insertions(+) create mode 100644 tests/auto/corelib/io/qdir/Info.plist (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qdir/Info.plist b/tests/auto/corelib/io/qdir/Info.plist new file mode 100644 index 0000000000..7dc5622bde --- /dev/null +++ b/tests/auto/corelib/io/qdir/Info.plist @@ -0,0 +1,41 @@ + + + + + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleGetInfoString + Created by Qt/QMake + CFBundleIconFile + ${ASSETCATALOG_COMPILER_APPICON_NAME} + CFBundleIdentifier + ${PRODUCT_BUNDLE_IDENTIFIER} + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${QMAKE_SHORT_VERSION} + CFBundleSignature + ${QMAKE_PKGINFO_TYPEINFO} + CFBundleVersion + ${QMAKE_FULL_VERSION} + LSRequiresIPhoneOS + + MinimumOSVersion + ${IPHONEOS_DEPLOYMENT_TARGET} + UILaunchStoryboardName + LaunchScreen + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + NSPhotoLibraryUsageDescription + Enables use of assets file engine + + diff --git a/tests/auto/corelib/io/qdir/qdir.pro b/tests/auto/corelib/io/qdir/qdir.pro index 2252e71cd8..a8b106e250 100644 --- a/tests/auto/corelib/io/qdir/qdir.pro +++ b/tests/auto/corelib/io/qdir/qdir.pro @@ -3,6 +3,7 @@ TARGET = tst_qdir QT = core core-private testlib SOURCES = tst_qdir.cpp RESOURCES += qdir.qrc +ios: QMAKE_INFO_PLIST = Info.plist TESTDATA += testdir testData searchdir resources entrylist types tst_qdir.cpp diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index af9c6be432..34588b19bc 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -1523,6 +1523,11 @@ void tst_QDir::filePath_data() QTest::newRow("rel-rel") << "relative" << "path" << "relative/path"; QTest::newRow("empty-empty") << "" << "" << "."; QTest::newRow("resource") << ":/prefix" << "foo.bar" << ":/prefix/foo.bar"; +#ifdef Q_OS_IOS + QTest::newRow("assets-rel") << "assets-library:/" << "foo/bar.baz" << "assets-library:/foo/bar.baz"; + QTest::newRow("assets-abs") << "assets-library:/" << "/foo/bar.baz" << "/foo/bar.baz"; + QTest::newRow("abs-assets") << "/some/path" << "assets-library:/foo/bar.baz" << "assets-library:/foo/bar.baz"; +#endif #ifdef Q_OS_WIN QTest::newRow("abs-LTUNC") << "Q:/path" << "\\/leaning\\tooth/pick" << "\\/leaning\\tooth/pick"; QTest::newRow("LTUNC-slash") << "\\/leaning\\tooth/pick" << "/path" << "//leaning/tooth/path"; -- cgit v1.2.3 From c365fa49d85810c6ad09bb5f43b5081cd7543bf1 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 19 Dec 2016 13:50:17 +0100 Subject: fix out-of-bounds access on trailing percent sign in tr() argument tr() recognizes %n and %Ln. it offers no way to escape lone percent signs, which implies that they must be interpreted verbatim, which is what the code actually does. except that it would run off the end if the % appeared at the end of the string. Fixes: QTBUG-57171 Done-with: Mateusz Starzycki Change-Id: Icf81925c482be1ea66ec8daafb3e92ad17ea7fab Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp | 6 ++++++ tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h | 1 + 2 files changed, 7 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index a53501b9dd..6adb393ddd 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -928,6 +928,12 @@ void tst_QCoreApplication::threadedEventDelivery() thread.start(); QVERIFY(thread.wait(1000)); QCOMPARE(receiver.recordedEvents.contains(QEvent::User + 1), eventsReceived); + +} + +void tst_QCoreApplication::testTrWithPercantegeAtTheEnd() +{ + QCoreApplication::translate("testcontext", "this will crash%", "testdisamb", 3); } #if QT_CONFIG(library) diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h index 105cca5174..2a23cf0751 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -59,6 +59,7 @@ private slots: void applicationEventFilters_auxThread(); void threadedEventDelivery_data(); void threadedEventDelivery(); + void testTrWithPercantegeAtTheEnd(); #if QT_CONFIG(library) void addRemoveLibPaths(); #endif -- cgit v1.2.3 From 9d2923c1b048b519c352c40bf26328dacef9304e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 18 Jan 2019 20:52:36 +0100 Subject: tst_QString: fix localeAwareCompare() when using ICU tst_QString::localeAwareCompare() is failing since ab448f731ecd8437c7c5c8b96a0e7f419ec3a7ca because the 'C' locale no longer initializes ICU and falls back to simple QString comparison. Fix it by explicitly setting the locale for the testdata to en_US so the QCollator is properly initialized. Task-number: QTBUG-73116 Change-Id: I9d4d55e666c5c52f93298dedb7e22da01a25318d Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 50 ++++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index f429bda804..c78cd2276f 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -5521,35 +5521,35 @@ void tst_QString::localeAwareCompare_data() // console.log("\u1111\u1171\u11B6".localeCompare("\ud4db") // example from Unicode 5.0, section 3.7, definition D70 - QTest::newRow("normalize1") << QString() << QString::fromUtf8("o\xCC\x88") << QString::fromUtf8("\xC3\xB6") << 0; + QTest::newRow("normalize1") << QString("en_US") << QString::fromUtf8("o\xCC\x88") << QString::fromUtf8("\xC3\xB6") << 0; // examples from Unicode 5.0, chapter 3.11 - QTest::newRow("normalize2") << QString() << QString::fromUtf8("\xC3\xA4\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; - QTest::newRow("normalize3") << QString() << QString::fromUtf8("a\xCC\x88\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; - QTest::newRow("normalize4") << QString() << QString::fromUtf8("\xE1\xBA\xA1\xCC\x88") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; - QTest::newRow("normalize5") << QString() << QString::fromUtf8("\xC3\xA4\xCC\x86") << QString::fromUtf8("a\xCC\x88\xCC\x86") << 0; - QTest::newRow("normalize6") << QString() << QString::fromUtf8("\xC4\x83\xCC\x88") << QString::fromUtf8("a\xCC\x86\xCC\x88") << 0; + QTest::newRow("normalize2") << QString("en_US") << QString::fromUtf8("\xC3\xA4\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize3") << QString("en_US") << QString::fromUtf8("a\xCC\x88\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize4") << QString("en_US") << QString::fromUtf8("\xE1\xBA\xA1\xCC\x88") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize5") << QString("en_US") << QString::fromUtf8("\xC3\xA4\xCC\x86") << QString::fromUtf8("a\xCC\x88\xCC\x86") << 0; + QTest::newRow("normalize6") << QString("en_US") << QString::fromUtf8("\xC4\x83\xCC\x88") << QString::fromUtf8("a\xCC\x86\xCC\x88") << 0; // example from Unicode 5.0, chapter 3.12 - QTest::newRow("normalize7") << QString() << QString::fromUtf8("\xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6") << QString::fromUtf8("\xED\x93\x9B") << 0; + QTest::newRow("normalize7") << QString("en_US") << QString::fromUtf8("\xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6") << QString::fromUtf8("\xED\x93\x9B") << 0; // examples from UTS 10, Unicode Collation Algorithm - QTest::newRow("normalize8") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("\xC3\x85") << 0; - QTest::newRow("normalize9") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; - QTest::newRow("normalize10") << QString() << QString::fromUtf8("x\xCC\x9B\xCC\xA3") << QString::fromUtf8("x\xCC\xA3\xCC\x9B") << 0; - QTest::newRow("normalize11") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xE1\xBB\xA5\xCC\x9B") << 0; - QTest::newRow("normalize12") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\x9B\xCC\xA3") << 0; - QTest::newRow("normalize13") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xC6\xB0\xCC\xA3") << 0; - QTest::newRow("normalize14") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\xA3\xCC\x9B") << 0; + QTest::newRow("normalize8") << QString("en_US") << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("\xC3\x85") << 0; + QTest::newRow("normalize9") << QString("en_US") << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize10") << QString("en_US") << QString::fromUtf8("x\xCC\x9B\xCC\xA3") << QString::fromUtf8("x\xCC\xA3\xCC\x9B") << 0; + QTest::newRow("normalize11") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xE1\xBB\xA5\xCC\x9B") << 0; + QTest::newRow("normalize12") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\x9B\xCC\xA3") << 0; + QTest::newRow("normalize13") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xC6\xB0\xCC\xA3") << 0; + QTest::newRow("normalize14") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\xA3\xCC\x9B") << 0; // examples from UAX 15, Unicode Normalization Forms - QTest::newRow("normalize15") << QString() << QString::fromUtf8("\xC3\x87") << QString::fromUtf8("C\xCC\xA7") << 0; - QTest::newRow("normalize16") << QString() << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; - QTest::newRow("normalize17") << QString() << QString::fromUtf8("\xEA\xB0\x80") << QString::fromUtf8("\xE1\x84\x80\xE1\x85\xA1") << 0; - QTest::newRow("normalize18") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; - QTest::newRow("normalize19") << QString() << QString::fromUtf8("\xE2\x84\xA6") << QString::fromUtf8("\xCE\xA9") << 0; - QTest::newRow("normalize20") << QString() << QString::fromUtf8("\xC3\x85") << QString::fromUtf8("A\xCC\x8A") << 0; - QTest::newRow("normalize21") << QString() << QString::fromUtf8("\xC3\xB4") << QString::fromUtf8("o\xCC\x82") << 0; - QTest::newRow("normalize22") << QString() << QString::fromUtf8("\xE1\xB9\xA9") << QString::fromUtf8("s\xCC\xA3\xCC\x87") << 0; - QTest::newRow("normalize23") << QString() << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("d\xCC\xA3\xCC\x87") << 0; - QTest::newRow("normalize24") << QString() << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("\xE1\xB8\x8D\xCC\x87") << 0; - QTest::newRow("normalize25") << QString() << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize15") << QString("en_US") << QString::fromUtf8("\xC3\x87") << QString::fromUtf8("C\xCC\xA7") << 0; + QTest::newRow("normalize16") << QString("en_US") << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize17") << QString("en_US") << QString::fromUtf8("\xEA\xB0\x80") << QString::fromUtf8("\xE1\x84\x80\xE1\x85\xA1") << 0; + QTest::newRow("normalize18") << QString("en_US") << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize19") << QString("en_US") << QString::fromUtf8("\xE2\x84\xA6") << QString::fromUtf8("\xCE\xA9") << 0; + QTest::newRow("normalize20") << QString("en_US") << QString::fromUtf8("\xC3\x85") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize21") << QString("en_US") << QString::fromUtf8("\xC3\xB4") << QString::fromUtf8("o\xCC\x82") << 0; + QTest::newRow("normalize22") << QString("en_US") << QString::fromUtf8("\xE1\xB9\xA9") << QString::fromUtf8("s\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize23") << QString("en_US") << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("d\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize24") << QString("en_US") << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("\xE1\xB8\x8D\xCC\x87") << 0; + QTest::newRow("normalize25") << QString("en_US") << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; } -- cgit v1.2.3 From 76dfda1ad12cc42cdd832aed1edbe5f76b0cbb2d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 21 Jan 2019 13:46:11 +0100 Subject: Use RAII to handle setting of default locale in tst_QString Various tests were setting the default locale and relying on cleanup() to "restore" the C locale; which needn't actually be the locale we started out in and, in any case, was the wrong locale for some tests. So handle this via an RAII class that records the actual prior locale and restores it on destruction. Fixes: QTBUG-73116 Change-Id: If44f7cb8c6e0ce81be396ac1ea8bab7038a86729 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index c78cd2276f..e8ed22e427 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -319,10 +319,18 @@ class tst_QString : public QObject template void insert_impl() const { insert_impl(); } void insert_data(bool emptyIsNoop = false); + + class TransientDefaultLocale + { + const QLocale prior; // Records what *was* the default before we set it. + public: + TransientDefaultLocale(const QLocale &transient) { revise(transient); } + void revise(const QLocale &transient) { QLocale::setDefault(transient); } + ~TransientDefaultLocale() { QLocale::setDefault(prior); } + }; + public: tst_QString(); -public slots: - void cleanup(); private slots: void fromStdString(); void toStdString(); @@ -654,11 +662,6 @@ tst_QString::tst_QString() QTextCodec::setCodecForLocale(QTextCodec::codecForName("ISO 8859-1")); } -void tst_QString::cleanup() -{ - QLocale::setDefault(QString("C")); -} - void tst_QString::remove_uint_uint_data() { replace_uint_uint_data(); @@ -4750,7 +4753,7 @@ void tst_QString::arg() is all messed up, because Qt Test itself uses QString::arg(). */ - QLocale::setDefault(QString("de_DE")); + TransientDefaultLocale transient(QString("de_DE")); QString s4( "[%0]" ); QString s5( "[%1]" ); @@ -4898,13 +4901,11 @@ void tst_QString::arg() QCOMPARE(QString("%1").arg(-1., 3, 'g', -1, QChar('x')), QLatin1String("x-1")); QCOMPARE(QString("%1").arg(-100., 3, 'g', -1, QChar('x')), QLatin1String("-100")); - QLocale::setDefault(QString("ar")); + transient.revise(QString("ar")); QCOMPARE( QString("%L1").arg(12345.6789, 10, 'g', 7, QLatin1Char('0')), QString::fromUtf8("\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xac\xd9\xa3\xd9\xa4\xd9\xa5\xd9\xab\xd9\xa6\xd9\xa8") ); // "٠١٢٬٣٤٥٫٦٨" QCOMPARE( QString("%L1").arg(123456789, 13, 10, QLatin1Char('0')), QString("\xd9\xa0\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xac\xd9\xa4\xd9\xa5\xd9\xa6\xd9\xac\xd9\xa7\xd9\xa8\xd9\xa9") ); // ٠٠١٢٣٬٤٥٦٬٧٨٩ - - QLocale::setDefault(QLocale::system()); } void tst_QString::number() @@ -6594,14 +6595,14 @@ void tst_QString::arg_locale() QLocale l(QLocale::English, QLocale::UnitedKingdom); QString str("*%L1*%L2*"); - QLocale::setDefault(l); + TransientDefaultLocale transient(l); QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123,456*1,234.56*")); l.setNumberOptions(QLocale::OmitGroupSeparator); - QLocale::setDefault(l); + transient.revise(l); QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123456*1234.56*")); - QLocale::setDefault(QLocale::C); + transient.revise(QLocale::C); QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123456*1234.56*")); } @@ -6615,7 +6616,7 @@ void tst_QString::toUpperLower_icu() QCOMPARE(s.toUpper(), QString::fromLatin1("I")); QCOMPARE(s.toLower(), QString::fromLatin1("i")); - QLocale::setDefault(QLocale(QLocale::Turkish, QLocale::Turkey)); + TransientDefaultLocale transient(QLocale(QLocale::Turkish, QLocale::Turkey)); QCOMPARE(s.toUpper(), QString::fromLatin1("I")); QCOMPARE(s.toLower(), QString::fromLatin1("i")); @@ -6639,8 +6640,6 @@ void tst_QString::toUpperLower_icu() // nothing should happen here QCOMPARE(l.toLower(sup), sup); QCOMPARE(l.toLower(QString::fromLatin1("i")), QString::fromLatin1("i")); - - // the cleanup function will restore the default locale } #endif -- cgit v1.2.3 From 9f8589befe99f3c4eecf27d9972abfbbc2fead9c Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 18 Jan 2019 20:52:36 +0100 Subject: tst_QString: fix localeAwareCompare() when using ICU tst_QString::localeAwareCompare() is failing since ab448f731ecd8437c7c5c8b96a0e7f419ec3a7ca because the 'C' locale no longer initializes ICU and falls back to simple QString comparison. Fix it by explicitly setting the locale for the testdata to en_US so the QCollator is properly initialized. Task-number: QTBUG-73116 Change-Id: I9d4d55e666c5c52f93298dedb7e22da01a25318d Reviewed-by: Thiago Macieira (cherry picked from commit 9d2923c1b048b519c352c40bf26328dacef9304e) Reviewed-by: Christian Ehrlicher Reviewed-by: Jani Heikkinen --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 50 ++++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index f429bda804..c78cd2276f 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -5521,35 +5521,35 @@ void tst_QString::localeAwareCompare_data() // console.log("\u1111\u1171\u11B6".localeCompare("\ud4db") // example from Unicode 5.0, section 3.7, definition D70 - QTest::newRow("normalize1") << QString() << QString::fromUtf8("o\xCC\x88") << QString::fromUtf8("\xC3\xB6") << 0; + QTest::newRow("normalize1") << QString("en_US") << QString::fromUtf8("o\xCC\x88") << QString::fromUtf8("\xC3\xB6") << 0; // examples from Unicode 5.0, chapter 3.11 - QTest::newRow("normalize2") << QString() << QString::fromUtf8("\xC3\xA4\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; - QTest::newRow("normalize3") << QString() << QString::fromUtf8("a\xCC\x88\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; - QTest::newRow("normalize4") << QString() << QString::fromUtf8("\xE1\xBA\xA1\xCC\x88") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; - QTest::newRow("normalize5") << QString() << QString::fromUtf8("\xC3\xA4\xCC\x86") << QString::fromUtf8("a\xCC\x88\xCC\x86") << 0; - QTest::newRow("normalize6") << QString() << QString::fromUtf8("\xC4\x83\xCC\x88") << QString::fromUtf8("a\xCC\x86\xCC\x88") << 0; + QTest::newRow("normalize2") << QString("en_US") << QString::fromUtf8("\xC3\xA4\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize3") << QString("en_US") << QString::fromUtf8("a\xCC\x88\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize4") << QString("en_US") << QString::fromUtf8("\xE1\xBA\xA1\xCC\x88") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize5") << QString("en_US") << QString::fromUtf8("\xC3\xA4\xCC\x86") << QString::fromUtf8("a\xCC\x88\xCC\x86") << 0; + QTest::newRow("normalize6") << QString("en_US") << QString::fromUtf8("\xC4\x83\xCC\x88") << QString::fromUtf8("a\xCC\x86\xCC\x88") << 0; // example from Unicode 5.0, chapter 3.12 - QTest::newRow("normalize7") << QString() << QString::fromUtf8("\xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6") << QString::fromUtf8("\xED\x93\x9B") << 0; + QTest::newRow("normalize7") << QString("en_US") << QString::fromUtf8("\xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6") << QString::fromUtf8("\xED\x93\x9B") << 0; // examples from UTS 10, Unicode Collation Algorithm - QTest::newRow("normalize8") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("\xC3\x85") << 0; - QTest::newRow("normalize9") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; - QTest::newRow("normalize10") << QString() << QString::fromUtf8("x\xCC\x9B\xCC\xA3") << QString::fromUtf8("x\xCC\xA3\xCC\x9B") << 0; - QTest::newRow("normalize11") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xE1\xBB\xA5\xCC\x9B") << 0; - QTest::newRow("normalize12") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\x9B\xCC\xA3") << 0; - QTest::newRow("normalize13") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xC6\xB0\xCC\xA3") << 0; - QTest::newRow("normalize14") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\xA3\xCC\x9B") << 0; + QTest::newRow("normalize8") << QString("en_US") << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("\xC3\x85") << 0; + QTest::newRow("normalize9") << QString("en_US") << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize10") << QString("en_US") << QString::fromUtf8("x\xCC\x9B\xCC\xA3") << QString::fromUtf8("x\xCC\xA3\xCC\x9B") << 0; + QTest::newRow("normalize11") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xE1\xBB\xA5\xCC\x9B") << 0; + QTest::newRow("normalize12") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\x9B\xCC\xA3") << 0; + QTest::newRow("normalize13") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xC6\xB0\xCC\xA3") << 0; + QTest::newRow("normalize14") << QString("en_US") << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\xA3\xCC\x9B") << 0; // examples from UAX 15, Unicode Normalization Forms - QTest::newRow("normalize15") << QString() << QString::fromUtf8("\xC3\x87") << QString::fromUtf8("C\xCC\xA7") << 0; - QTest::newRow("normalize16") << QString() << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; - QTest::newRow("normalize17") << QString() << QString::fromUtf8("\xEA\xB0\x80") << QString::fromUtf8("\xE1\x84\x80\xE1\x85\xA1") << 0; - QTest::newRow("normalize18") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; - QTest::newRow("normalize19") << QString() << QString::fromUtf8("\xE2\x84\xA6") << QString::fromUtf8("\xCE\xA9") << 0; - QTest::newRow("normalize20") << QString() << QString::fromUtf8("\xC3\x85") << QString::fromUtf8("A\xCC\x8A") << 0; - QTest::newRow("normalize21") << QString() << QString::fromUtf8("\xC3\xB4") << QString::fromUtf8("o\xCC\x82") << 0; - QTest::newRow("normalize22") << QString() << QString::fromUtf8("\xE1\xB9\xA9") << QString::fromUtf8("s\xCC\xA3\xCC\x87") << 0; - QTest::newRow("normalize23") << QString() << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("d\xCC\xA3\xCC\x87") << 0; - QTest::newRow("normalize24") << QString() << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("\xE1\xB8\x8D\xCC\x87") << 0; - QTest::newRow("normalize25") << QString() << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize15") << QString("en_US") << QString::fromUtf8("\xC3\x87") << QString::fromUtf8("C\xCC\xA7") << 0; + QTest::newRow("normalize16") << QString("en_US") << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize17") << QString("en_US") << QString::fromUtf8("\xEA\xB0\x80") << QString::fromUtf8("\xE1\x84\x80\xE1\x85\xA1") << 0; + QTest::newRow("normalize18") << QString("en_US") << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize19") << QString("en_US") << QString::fromUtf8("\xE2\x84\xA6") << QString::fromUtf8("\xCE\xA9") << 0; + QTest::newRow("normalize20") << QString("en_US") << QString::fromUtf8("\xC3\x85") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize21") << QString("en_US") << QString::fromUtf8("\xC3\xB4") << QString::fromUtf8("o\xCC\x82") << 0; + QTest::newRow("normalize22") << QString("en_US") << QString::fromUtf8("\xE1\xB9\xA9") << QString::fromUtf8("s\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize23") << QString("en_US") << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("d\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize24") << QString("en_US") << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("\xE1\xB8\x8D\xCC\x87") << 0; + QTest::newRow("normalize25") << QString("en_US") << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; } -- cgit v1.2.3 From e0567d137df4ff3978f767fa723ae05a7b0ab546 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 27 Jul 2018 17:46:04 +0200 Subject: Add QStringList::indexOf/lastIndexOf for QStringView and QLatin1String Change-Id: I42eac69c1f7ab88441d464b9d325139defe32b03 Reviewed-by: Thiago Macieira --- .../corelib/tools/qstringlist/tst_qstringlist.cpp | 64 ++++++++++++++++------ 1 file changed, 48 insertions(+), 16 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index a3aec4c299..42bdf62a93 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -43,7 +43,9 @@ private slots: void removeDuplicates(); void removeDuplicates_data(); void contains(); + void indexOf_data(); void indexOf(); + void lastIndexOf_data(); void lastIndexOf(); void indexOf_regExp(); @@ -141,20 +143,52 @@ void tst_QStringList::lastIndexOf_regExp() } +void tst_QStringList::indexOf_data() +{ + QTest::addColumn("search"); + QTest::addColumn("from"); + QTest::addColumn("expectedResult"); + + QTest::newRow("harald") << "harald" << 0 << 0; + QTest::newRow("trond") << "trond" << 0 << 1; + QTest::newRow("vohi") << "vohi" << 0 << 2; + QTest::newRow("harald-1") << "harald" << 1 << 3; + + QTest::newRow("hans") << "hans" << 0 << -1; + QTest::newRow("trond-1") << "trond" << 2 << -1; + QTest::newRow("harald-2") << "harald" << -1 << 3; + QTest::newRow("vohi-1") << "vohi" << -3 << 2; +} + void tst_QStringList::indexOf() { QStringList list; list << "harald" << "trond" << "vohi" << "harald"; - QCOMPARE(list.indexOf("harald"), 0); - QCOMPARE(list.indexOf("trond"), 1); - QCOMPARE(list.indexOf("vohi"), 2); - QCOMPARE(list.indexOf("harald", 1), 3); + QFETCH(QString, search); + QFETCH(int, from); + QFETCH(int, expectedResult); - QCOMPARE(list.indexOf("hans"), -1); - QCOMPARE(list.indexOf("trond", 2), -1); - QCOMPARE(list.indexOf("harald", -1), 3); - QCOMPARE(list.indexOf("vohi", -3), 2); + QCOMPARE(list.indexOf(search, from), expectedResult); + QCOMPARE(list.indexOf(QStringView(search), from), expectedResult); + QCOMPARE(list.indexOf(QLatin1String(search.toLatin1()), from), expectedResult); +} + +void tst_QStringList::lastIndexOf_data() +{ + QTest::addColumn("search"); + QTest::addColumn("from"); + QTest::addColumn("expectedResult"); + + QTest::newRow("harald") << "harald" << -1 << 3; + QTest::newRow("trond") << "trond" << -1 << 1; + QTest::newRow("vohi") << "vohi" << -1 << 2; + QTest::newRow("harald-1") << "harald" << 2 << 0; + + QTest::newRow("hans") << "hans" << -1 << -1; + QTest::newRow("vohi-1") << "vohi" << 1 << -1; + QTest::newRow("vohi-2") << "vohi" << -1 << 2; + QTest::newRow("vohi-3") << "vohi" << -3 << -1; } void tst_QStringList::lastIndexOf() @@ -162,15 +196,13 @@ void tst_QStringList::lastIndexOf() QStringList list; list << "harald" << "trond" << "vohi" << "harald"; - QCOMPARE(list.lastIndexOf("harald"), 3); - QCOMPARE(list.lastIndexOf("trond"), 1); - QCOMPARE(list.lastIndexOf("vohi"), 2); - QCOMPARE(list.lastIndexOf("harald", 2), 0); + QFETCH(QString, search); + QFETCH(int, from); + QFETCH(int, expectedResult); - QCOMPARE(list.lastIndexOf("hans"), -1); - QCOMPARE(list.lastIndexOf("vohi", 1), -1); - QCOMPARE(list.lastIndexOf("vohi", -1), 2); - QCOMPARE(list.lastIndexOf("vohi", -3), -1); + QCOMPARE(list.lastIndexOf(search, from), expectedResult); + QCOMPARE(list.lastIndexOf(QStringView(search), from), expectedResult); + QCOMPARE(list.lastIndexOf(QLatin1String(search.toLatin1()), from), expectedResult); } void tst_QStringList::filter() -- cgit v1.2.3 From 25fc90e48b279d61dfcedb3ecfe7818e29eca341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 19 Dec 2018 16:46:47 +0100 Subject: Allow more fine grained control over QMetaEnum debug output Useful in contexts such as other QDebug operators, where the class is already known, and the full scope of the enum is not needed. Change-Id: Ibd04b1fd4f0f914c7224a007fc248d4ebabcde3e Reviewed-by: Thiago Macieira --- .../corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 49 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 9855bec520..68e9040ce2 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -324,6 +324,7 @@ private slots: void signal(); void signalIndex_data(); void signalIndex(); + void enumDebugStream_data(); void enumDebugStream(); void inherits_data(); @@ -1741,16 +1742,52 @@ void tst_QMetaObject::signalIndex() SignalTestHelper::signalIndex(mm)); } +void tst_QMetaObject::enumDebugStream_data() +{ + QTest::addColumn("verbosity"); + QTest::addColumn("normalEnumMsg"); + QTest::addColumn("scopedEnumMsg"); + QTest::addColumn("globalEnumMsg"); + + QTest::newRow("verbosity=0") << 0 + << "WindowTitleHint Window Desktop WindowSystemMenuHint"; + << "hello MyEnum2 world" + << "hello MyScopedEnum::Enum3 scoped world" + + QTest::newRow("verbosity=1") << 1 + << "WindowType::WindowTitleHint WindowType::Window WindowType::Desktop WindowType::WindowSystemMenuHint"; + << "hello MyEnum::MyEnum2 world" + << "hello MyScopedEnum::Enum3 scoped world" + + QTest::newRow("verbosity=2") << 2 + << "Qt::WindowTitleHint Qt::Window Qt::Desktop Qt::WindowSystemMenuHint"; + << "hello MyNamespace::MyClass::MyEnum2 world" + << "hello MyNamespace::MyClass::MyScopedEnum::Enum3 scoped world" + + QTest::newRow("verbosity=3") << 3 + << "Qt::WindowType::WindowTitleHint Qt::WindowType::Window Qt::WindowType::Desktop Qt::WindowType::WindowSystemMenuHint"; + << "hello MyNamespace::MyClass::MyEnum::MyEnum2 world" + << "hello MyNamespace::MyClass::MyScopedEnum::Enum3 scoped world" +} + void tst_QMetaObject::enumDebugStream() { - QTest::ignoreMessage(QtDebugMsg, "hello MyNamespace::MyClass::MyEnum2 world "); - qDebug() << "hello" << MyNamespace::MyClass::MyEnum2 << "world"; + QFETCH(int, verbosity); + QFETCH(QString, normalEnumMsg); + QFETCH(QString, scopedEnumMsg); + QFETCH(QString, globalEnumMsg); + + QTest::ignoreMessage(QtDebugMsg, qPrintable(normalEnumMsg)); + qDebug().verbosity(verbosity) << "hello" << MyNamespace::MyClass::MyEnum2 << "world"; + + QTest::ignoreMessage(QtDebugMsg, qPrintable(scopedEnumMsg)); + qDebug().verbosity(verbosity) << "hello" << MyNamespace::MyClass::MyScopedEnum::Enum3 << "scoped world"; - QTest::ignoreMessage(QtDebugMsg, "hello MyNamespace::MyClass::MyScopedEnum::Enum3 scoped world "); - qDebug() << "hello" << MyNamespace::MyClass::MyScopedEnum::Enum3 << "scoped world"; + QTest::ignoreMessage(QtDebugMsg, qPrintable(globalEnumMsg)); + qDebug().verbosity(verbosity) << Qt::WindowTitleHint << Qt::Window << Qt::Desktop << Qt::WindowSystemMenuHint; - QTest::ignoreMessage(QtDebugMsg, "Qt::WindowTitleHint Qt::Window Qt::Desktop Qt::WindowSystemMenuHint"); - qDebug() << Qt::WindowTitleHint << Qt::Window << Qt::Desktop << Qt::WindowSystemMenuHint; + if (verbosity != 2) + return; QTest::ignoreMessage(QtDebugMsg, "hello QFlags(MyFlag1) world"); MyNamespace::MyClass::MyFlags f1 = MyNamespace::MyClass::MyFlag1; -- cgit v1.2.3 From 237c3972fd8869698cea69ff57f751c982bec487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 19 Dec 2018 20:13:02 +0100 Subject: Allow more fine grained control over QFlags debug output Useful in contexts such as other QDebug operators, where the class is already known, and the full scope of the flags is not needed. Change-Id: I546381b1722c9c846e2412e56763563b8f625212 Reviewed-by: Thiago Macieira --- .../corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 65 ++++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 68e9040ce2..467d299526 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -1748,35 +1748,68 @@ void tst_QMetaObject::enumDebugStream_data() QTest::addColumn("normalEnumMsg"); QTest::addColumn("scopedEnumMsg"); QTest::addColumn("globalEnumMsg"); + QTest::addColumn("normalFlagMsg"); + QTest::addColumn("normalFlagsMsg"); + QTest::addColumn("scopedFlagMsg"); + QTest::addColumn("scopedFlagsMsg"); + QTest::addColumn("flagAsEnumMsg"); QTest::newRow("verbosity=0") << 0 - << "WindowTitleHint Window Desktop WindowSystemMenuHint"; << "hello MyEnum2 world" << "hello MyScopedEnum::Enum3 scoped world" + << "WindowTitleHint Window Desktop WindowSystemMenuHint" + << "hello MyFlag1 world" + << "MyFlag1 MyFlag2|MyFlag3" + << "MyScopedFlag(MyFlag2)" + << "MyScopedFlag(MyFlag2|MyFlag3)" + << "MyFlag1"; QTest::newRow("verbosity=1") << 1 - << "WindowType::WindowTitleHint WindowType::Window WindowType::Desktop WindowType::WindowSystemMenuHint"; << "hello MyEnum::MyEnum2 world" << "hello MyScopedEnum::Enum3 scoped world" + << "WindowType::WindowTitleHint WindowType::Window WindowType::Desktop WindowType::WindowSystemMenuHint" + << "hello MyFlag(MyFlag1) world" + << "MyFlag(MyFlag1) MyFlag(MyFlag2|MyFlag3)" + << "MyScopedFlag(MyFlag2)" + << "MyScopedFlag(MyFlag2|MyFlag3)" + << "MyFlag::MyFlag1"; QTest::newRow("verbosity=2") << 2 - << "Qt::WindowTitleHint Qt::Window Qt::Desktop Qt::WindowSystemMenuHint"; << "hello MyNamespace::MyClass::MyEnum2 world" << "hello MyNamespace::MyClass::MyScopedEnum::Enum3 scoped world" + << "Qt::WindowTitleHint Qt::Window Qt::Desktop Qt::WindowSystemMenuHint" + << "hello QFlags(MyFlag1) world" + << "QFlags(MyFlag1) QFlags(MyFlag2|MyFlag3)" + << "QFlags(MyFlag2)" + << "QFlags(MyFlag2|MyFlag3)" + << "MyNamespace::MyClass::MyFlag1"; QTest::newRow("verbosity=3") << 3 - << "Qt::WindowType::WindowTitleHint Qt::WindowType::Window Qt::WindowType::Desktop Qt::WindowType::WindowSystemMenuHint"; << "hello MyNamespace::MyClass::MyEnum::MyEnum2 world" << "hello MyNamespace::MyClass::MyScopedEnum::Enum3 scoped world" + << "Qt::WindowType::WindowTitleHint Qt::WindowType::Window Qt::WindowType::Desktop Qt::WindowType::WindowSystemMenuHint" + << "hello QFlags(MyFlag1) world" + << "QFlags(MyFlag1) QFlags(MyFlag2|MyFlag3)" + << "QFlags(MyFlag2)" + << "QFlags(MyFlag2|MyFlag3)" + << "MyNamespace::MyClass::MyFlag::MyFlag1"; } void tst_QMetaObject::enumDebugStream() { QFETCH(int, verbosity); + QFETCH(QString, normalEnumMsg); QFETCH(QString, scopedEnumMsg); QFETCH(QString, globalEnumMsg); + QFETCH(QString, normalFlagMsg); + QFETCH(QString, normalFlagsMsg); + QFETCH(QString, scopedFlagMsg); + QFETCH(QString, scopedFlagsMsg); + QFETCH(QString, flagAsEnumMsg); + + // Enums QTest::ignoreMessage(QtDebugMsg, qPrintable(normalEnumMsg)); qDebug().verbosity(verbosity) << "hello" << MyNamespace::MyClass::MyEnum2 << "world"; @@ -1786,29 +1819,27 @@ void tst_QMetaObject::enumDebugStream() QTest::ignoreMessage(QtDebugMsg, qPrintable(globalEnumMsg)); qDebug().verbosity(verbosity) << Qt::WindowTitleHint << Qt::Window << Qt::Desktop << Qt::WindowSystemMenuHint; - if (verbosity != 2) - return; - - QTest::ignoreMessage(QtDebugMsg, "hello QFlags(MyFlag1) world"); + // Flags + QTest::ignoreMessage(QtDebugMsg, qPrintable(normalFlagMsg)); MyNamespace::MyClass::MyFlags f1 = MyNamespace::MyClass::MyFlag1; - qDebug() << "hello" << f1 << "world"; + qDebug().verbosity(verbosity) << "hello" << f1 << "world"; MyNamespace::MyClass::MyFlags f2 = MyNamespace::MyClass::MyFlag2 | MyNamespace::MyClass::MyFlag3; - QTest::ignoreMessage(QtDebugMsg, "QFlags(MyFlag1) QFlags(MyFlag2|MyFlag3)"); - qDebug() << f1 << f2; + QTest::ignoreMessage(QtDebugMsg, qPrintable(normalFlagsMsg)); + qDebug().verbosity(verbosity) << f1 << f2; - QTest::ignoreMessage(QtDebugMsg, "QFlags(MyFlag2)"); + QTest::ignoreMessage(QtDebugMsg, qPrintable(scopedFlagMsg)); MyNamespace::MyClass::MyScopedFlags f3 = MyNamespace::MyClass::MyScopedFlag::MyFlag2; - qDebug() << f3; + qDebug().verbosity(verbosity) << f3; - QTest::ignoreMessage(QtDebugMsg, "QFlags(MyFlag2|MyFlag3)"); + QTest::ignoreMessage(QtDebugMsg, qPrintable(scopedFlagsMsg)); f3 |= MyNamespace::MyClass::MyScopedFlag::MyFlag3; - qDebug() << f3; + qDebug().verbosity(verbosity) << f3; // Single flag recognized as enum: - QTest::ignoreMessage(QtDebugMsg, "MyNamespace::MyClass::MyFlag1"); + QTest::ignoreMessage(QtDebugMsg, qPrintable(flagAsEnumMsg)); MyNamespace::MyClass::MyFlag f4 = MyNamespace::MyClass::MyFlag1; - qDebug() << f4; + qDebug().verbosity(verbosity) << f4; } void tst_QMetaObject::inherits_data() -- cgit v1.2.3 From 5eab68bbee6c9633f0702c87c05e119ec4d910e0 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 17 Jan 2019 21:07:35 +0100 Subject: QProcess: mark obsolete functions as deprecated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QProcess::finished(int)/readChannelMode()/setReadChannelMode() are obsolete but were not marked as deprecated. Explicit mark them as deprecated so they can be removed with Qt6. Change-Id: Iedbfd80a3c987f35caf93181e9277913a18961d9 Reviewed-by: Thiago Macieira Reviewed-by: Mårten Nordheim --- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index e0aa577154..c51994c1c1 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -185,12 +185,12 @@ void tst_QProcess::getSetCheck() { QProcess obj1; // ProcessChannelMode QProcess::readChannelMode() - // void QProcess::setReadChannelMode(ProcessChannelMode) - obj1.setReadChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); + // void QProcess::setProcessChannelMode(ProcessChannelMode) + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.readChannelMode()); - obj1.setReadChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.readChannelMode()); - obj1.setReadChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::ForwardedChannels), obj1.readChannelMode()); // ProcessChannel QProcess::readChannel() @@ -913,7 +913,7 @@ public: switch (n) { case 0: - setReadChannelMode(QProcess::MergedChannels); + setProcessChannelMode(QProcess::MergedChannels); connect(this, &QIODevice::readyRead, this, &SoftExitProcess::terminateSlot); break; case 1: @@ -929,7 +929,7 @@ public: this, &SoftExitProcess::terminateSlot); break; case 4: - setReadChannelMode(QProcess::MergedChannels); + setProcessChannelMode(QProcess::MergedChannels); connect(this, SIGNAL(channelReadyRead(int)), this, SLOT(terminateSlot())); break; default: @@ -1025,7 +1025,7 @@ void tst_QProcess::softExitInSlots() void tst_QProcess::mergedChannels() { QProcess process; - process.setReadChannelMode(QProcess::MergedChannels); + process.setProcessChannelMode(QProcess::MergedChannels); QCOMPARE(process.readChannelMode(), QProcess::MergedChannels); process.start("testProcessEcho2/testProcessEcho2"); @@ -1951,7 +1951,7 @@ void tst_QProcess::setStandardOutputFile() // run the process QProcess process; - process.setReadChannelMode(channelMode); + process.setProcessChannelMode(channelMode); if (channelToTest == QProcess::StandardOutput) process.setStandardOutputFile(file.fileName(), mode); else @@ -2037,7 +2037,7 @@ void tst_QProcess::setStandardOutputProcess() QFETCH(bool, merged); QFETCH(bool, waitForBytesWritten); - source.setReadChannelMode(merged ? QProcess::MergedChannels : QProcess::SeparateChannels); + source.setProcessChannelMode(merged ? QProcess::MergedChannels : QProcess::SeparateChannels); source.setStandardOutputProcess(&sink); source.start("testProcessEcho2/testProcessEcho2"); -- cgit v1.2.3 From 7c69f6171ddc76d22e4f6e433be69c5cf365db8f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 17 Jan 2019 22:00:08 +0100 Subject: QFile/QFileInfo: mark readLink() as deprecated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QFile/QFileInfo::readLink() functions are obsolete but were not marked as deprecated. Explicit mark them as deprecated so they can be removed with Qt6. Change-Id: I52424dc5441e1f5b01015713df990bbec5186caa Reviewed-by: Thiago Macieira Reviewed-by: Friedemann Kleint Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 2 +- tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 3e29475636..714c96b5e5 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -2022,7 +2022,7 @@ static void stateCheck(const QFileInfo &info, const QString &dirname, const QStr QVERIFY(!info.isRoot()); QCOMPARE(info.isNativePath(), !filename.isEmpty()); - QCOMPARE(info.readLink(), QString()); + QCOMPARE(info.symLinkTarget(), QString()); QCOMPARE(info.ownerId(), uint(-2)); QCOMPARE(info.groupId(), uint(-2)); QCOMPARE(info.owner(), QString()); diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index dbc3d68e93..cf4ab4902d 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -376,7 +376,7 @@ void tst_QTemporaryFile::io() before.setSecsSinceEpoch(before.toSecsSinceEpoch()); QVERIFY(file.open()); - QVERIFY(file.readLink().isEmpty()); // it's not a link! + QVERIFY(file.symLinkTarget().isEmpty()); // it's not a link! QFile::Permissions perm = file.permissions(); QVERIFY(perm & QFile::ReadOwner); QVERIFY(file.setPermissions(perm)); -- cgit v1.2.3 From e85f43fd4ded62ab4b63185fba54f308d73306fd Mon Sep 17 00:00:00 2001 From: Christian Andersen Date: Sun, 27 Jan 2019 18:19:21 +0100 Subject: tst_QTimer: relax time requirement on remaining time Before this the remaining time in the two tests 'remainingTime' and 'basic_chrono' had to be within the interval [100,200]. This relaxes that to [50,200]. This test seems to be failing a lot when staging changes in gerrit. I can reproduce some of the problem when putting a lot of load on my system and running the tests, then remaining time is very random. Also removes the blacklist of remaingTime on Windows and macOS, as basic_chrono and remaningTime tests are basically the same. The tests also fails on Linux some times in gerrit. I was also thinking one could: - blacklist both tests - remove interval requirements; just check remaining time is [0,200] - remove the tests Task-number: QTBUG-61013 Change-Id: I5c8f0754d059598e023fe8e5d511f4a50bb4bac2 Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qtimer/BLACKLIST | 3 --- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 tests/auto/corelib/kernel/qtimer/BLACKLIST (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/BLACKLIST b/tests/auto/corelib/kernel/qtimer/BLACKLIST deleted file mode 100644 index e5136624d8..0000000000 --- a/tests/auto/corelib/kernel/qtimer/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -[remainingTime] -windows -osx diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 8d194dafc1..cd78da725c 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -133,14 +133,14 @@ void tst_QTimer::remainingTime() QCOMPARE(timeoutSpy.count(), 0); int remainingTime = timer.remainingTime(); - QVERIFY2(qAbs(remainingTime - 150) < 50, qPrintable(QString::number(remainingTime))); + QVERIFY2(remainingTime >= 50 && remainingTime <= 200, qPrintable(QString::number(remainingTime))); QVERIFY(timeoutSpy.wait()); QCOMPARE(timeoutSpy.count(), 1); // the timer is still active, so it should have a non-zero remaining time remainingTime = timer.remainingTime(); - QVERIFY2(remainingTime > 150, qPrintable(QString::number(remainingTime))); + QVERIFY2(remainingTime >= 50, qPrintable(QString::number(remainingTime))); } void tst_QTimer::remainingTimeDuringActivation_data() @@ -228,7 +228,7 @@ void tst_QTimer::basic_chrono() QCOMPARE(timeoutSpy.count(), 0); milliseconds rt = timer.remainingTimeAsDuration(); - QVERIFY2(qAbs(rt.count() - 150) < 50, qPrintable(QString::number(rt.count()))); + QVERIFY2(rt.count() >= 50 && rt.count() <= 200, qPrintable(QString::number(rt.count()))); timeoutSpy.clear(); timer.setSingleShot(true); -- cgit v1.2.3 From 6a7e2fedefba69b338d859cba091cd8678e2dcc1 Mon Sep 17 00:00:00 2001 From: Christian Andersen Date: Sun, 27 Jan 2019 17:41:15 +0100 Subject: Windows: improve QTimer::remainingTime when called before processEvents This checks that intenalHwnd in QEventDispatcherWin32::remainingTime is initialized. If calling remaningTime, before createInternalHwnd is called, the timeout member in the WinTimerInfo struct is not initialized and contains a random value. This adds a check for that and in that case returns the requested timer interval as the timer has not yet been started. createInternalHwnd is called on the first request to process events. It also adds a test for checking the remaining time. But the issue can only be seen if solely running the remainingTimeInitial test in tst_QTimer. If running the test along side another test the other test likely calls processEvents indirectly, which hides the issue. I don't know if this is an issue in practice (the bug has been there for as long a the git history goes back, 2011), but it causes the basic_chrono test to fail if run as the only test. Change-Id: I05c35105da778912dedf8d749aa7c953841d986e Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index cd78da725c..3b10547dc4 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -51,6 +51,8 @@ private slots: void singleShotTimeout(); void timeout(); void remainingTime(); + void remainingTimeInitial_data(); + void remainingTimeInitial(); void remainingTimeDuringActivation_data(); void remainingTimeDuringActivation(); void basic_chrono(); @@ -143,6 +145,33 @@ void tst_QTimer::remainingTime() QVERIFY2(remainingTime >= 50, qPrintable(QString::number(remainingTime))); } +void tst_QTimer::remainingTimeInitial_data() +{ + QTest::addColumn("startTimeMs"); + QTest::addColumn("timerType"); + + QTest::addRow("precise time 0ms") << 0 << Qt::PreciseTimer; + QTest::addRow("precise time 1ms") << 1 << Qt::PreciseTimer; + QTest::addRow("precise time 10ms") << 10 << Qt::PreciseTimer; + + QTest::addRow("coarse time 0ms") << 0 << Qt::CoarseTimer; + QTest::addRow("coarse time 1ms") << 1 << Qt::CoarseTimer; + QTest::addRow("coarse time 10ms") << 10 << Qt::CoarseTimer; +} + +void tst_QTimer::remainingTimeInitial() +{ + QFETCH(int, startTimeMs); + QFETCH(Qt::TimerType, timerType); + + QTimer timer; + timer.setTimerType(timerType); + timer.start(startTimeMs); + + const int rt = timer.remainingTime(); + QVERIFY2(rt >= 0 && rt <= startTimeMs, qPrintable(QString::number(rt))); +} + void tst_QTimer::remainingTimeDuringActivation_data() { QTest::addColumn("singleShot"); -- cgit v1.2.3 From 112278d3d719ebb3ade00a8e63eb16abd4a29550 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 28 Jan 2019 14:40:44 +0100 Subject: Avoid test failures in tst_qtimezone.cpp and Windows 10 1809 The test started to fail now also for latest Windows 10 Update Restone 2. It's unclear why the test was succeeding before, since this seems a generic Windows API issue. Task-number: QTBUG-64985 Task-number: QTQAINFRA-2255 Change-Id: I804f6a61c63ea70157353d1aee9027d0735073ab Reviewed-by: Edward Welbourne --- tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index d335dae7bc..a25fd39693 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -508,8 +508,7 @@ void tst_QTimeZone::transitionEachZone() #ifdef USING_WIN_TZ // See QTBUG-64985: MS's TZ APIs' misdescription of Europe/Samara leads // to mis-disambiguation of its fall-back here. - if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7 - && zone == "Europe/Samara" && i == -3) { + if (zone == "Europe/Samara" && i == -3) { continue; } #endif -- cgit v1.2.3 From 49ca66583a46f136b48d31fc5488b5ad69fe7e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Mon, 21 Jan 2019 12:07:05 +0200 Subject: Expand blacklisting of qthreadpool to cover linux distros Task-number: QTBUG-38594 Change-Id: I07dccf8ac6ab07e61ddf6090037ea344449724f8 Reviewed-by: Heikki Halmet --- tests/auto/corelib/thread/qthreadpool/BLACKLIST | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/thread/qthreadpool/BLACKLIST b/tests/auto/corelib/thread/qthreadpool/BLACKLIST index 1c392ce96c..fc49731687 100644 --- a/tests/auto/corelib/thread/qthreadpool/BLACKLIST +++ b/tests/auto/corelib/thread/qthreadpool/BLACKLIST @@ -1,2 +1,3 @@ [expiryTimeoutRace] osx +linux -- cgit v1.2.3 From 5d885c8325f1c1567d08b580399dfd6ce4c5ab97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Mon, 21 Jan 2019 12:29:32 +0200 Subject: Blacklist qtimer/basic_chrono on macos due to flakiness Task-number: QTBUG-73168 Change-Id: I56b45b7f474bdad73f6cd8514b42475e6107b6be Reviewed-by: Kai Koehne --- tests/auto/corelib/kernel/qtimer/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/BLACKLIST b/tests/auto/corelib/kernel/qtimer/BLACKLIST index e5136624d8..c31e15f171 100644 --- a/tests/auto/corelib/kernel/qtimer/BLACKLIST +++ b/tests/auto/corelib/kernel/qtimer/BLACKLIST @@ -1,3 +1,5 @@ [remainingTime] windows osx +[basic_chrono] +macos -- cgit v1.2.3 From c066656aff4841f9095e77754fa7533f7bbbb66a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 7 Feb 2019 17:04:49 +0100 Subject: Avoid read-outside-array error by QStringRef over-reach Constructing a QStringRef directly from the string, offset and a length is UB if the offset + length exceeds the string's length. Thanks to Robert Loehning and libFuzzer for finding this. QString::midRef (as correctly used in both changed uses of QStringRef, since 432d3b69629) takes care of that for us. Changed one UB case and a matching but correct case, for consistency. In the process, deduplicate a QStringList look-up. Added tests to exercise the code (but the one that exercises the formerly UB case doesn't crash before the fix, so isn't very useful; the invalid read is only outside the array it's scanning, not outside allocated memory). Change-Id: I7051bbbc0267dd7ec0a8f75eee2034d0b7eb75a2 Reviewed-by: Anton Kudryavtsev Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 943805e228..b128ccebc5 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -2401,6 +2401,19 @@ void tst_QDateTime::fromStringStringFormat_data() QTest::newRow("late") << QString("9999-12-31T23:59:59.999Z") << QString("yyyy-MM-ddThh:mm:ss.zZ") << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999)); + // Separators match /([^aAdhHMmstyz]*)/ + QTest::newRow("oddly-separated") // To show broken-separator's format is valid. + << QStringLiteral("2018 wilful long working block relief 12-19T21:09 cruel blurb encore flux") + << QStringLiteral("yyyy wilful long working block relief MM-ddThh:mm cruel blurb encore flux") + << QDateTime(QDate(2018, 12, 19), QTime(21, 9)); + QTest::newRow("broken-separator") + << QStringLiteral("2018 wilful") + << QStringLiteral("yyyy wilful long working block relief MM-ddThh:mm cruel blurb encore flux") + << invalidDateTime(); + QTest::newRow("broken-terminator") + << QStringLiteral("2018 wilful long working block relief 12-19T21:09 cruel") + << QStringLiteral("yyyy wilful long working block relief MM-ddThh:mm cruel blurb encore flux") + << invalidDateTime(); } void tst_QDateTime::fromStringStringFormat() -- cgit v1.2.3 From 484eec96f9b2235780119526faeb6d69536f509c Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 19 Jan 2019 15:32:07 +0100 Subject: Add a couple of tests in QObject::tst_qobject For destructors of functor connected to signals Change-Id: I3f8b18fee7507f3cb72e36a2f9e6ef7f37dbeea1 Reviewed-by: Lars Knoll --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 165 ++++++++++++++++++++++ 1 file changed, 165 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 31268c5cf3..b823ca2aab 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -154,6 +154,8 @@ private slots: void mutableFunctor(); void checkArgumentsForNarrowing(); void nullReceiver(); + void functorReferencesConnection(); + void disconnectDisconnects(); }; struct QObjectCreatedOnShutdown @@ -7487,6 +7489,169 @@ void tst_QObject::nullReceiver() QVERIFY(!connect(&o, SIGNAL(destroyed()), nullObj, SLOT(deleteLater()))); } +void tst_QObject::functorReferencesConnection() +{ + countedStructObjectsCount = 0; + QMetaObject::Connection globalCon; + { + GetSenderObject obj; + CountedStruct counted(&obj); + QCOMPARE(countedStructObjectsCount, 1); + auto c = QSharedPointer::create(); + int slotCalled = 0; + *c = connect(&obj, &GetSenderObject::aSignal, &obj, [&slotCalled, c, counted] { + QObject::disconnect(*c); + slotCalled++; + }); + globalCon = *c; // keep a handle to the connection somewhere; + QVERIFY(globalCon); + QCOMPARE(countedStructObjectsCount, 2); + obj.triggerSignal(); + QCOMPARE(slotCalled, 1); + QCOMPARE(countedStructObjectsCount, 1); + QVERIFY(!globalCon); + obj.triggerSignal(); + QCOMPARE(slotCalled, 1); + QCOMPARE(countedStructObjectsCount, 1); + } + QCOMPARE(countedStructObjectsCount, 0); + + { + GetSenderObject obj; + CountedStruct counted(&obj); + QCOMPARE(countedStructObjectsCount, 1); + auto *rec = new QObject; + int slotCalled = 0; + globalCon = connect(&obj, &GetSenderObject::aSignal, rec, [&slotCalled, rec, counted] { + delete rec; + slotCalled++; + }); + QCOMPARE(countedStructObjectsCount, 2); + obj.triggerSignal(); + QCOMPARE(slotCalled, 1); + QCOMPARE(countedStructObjectsCount, 1); + QVERIFY(!globalCon); + obj.triggerSignal(); + QCOMPARE(slotCalled, 1); + QCOMPARE(countedStructObjectsCount, 1); + } + QCOMPARE(countedStructObjectsCount, 0); + { + int slotCalled = 0; + QEventLoop eventLoop; + { + // Sender will be destroyed when the labda goes out of scope lambda, so it will exit the event loop + auto sender = QSharedPointer::create(); + connect(sender.data(), &QObject::destroyed, &eventLoop, &QEventLoop::quit, Qt::QueuedConnection); + globalCon = connect(sender.data(), &GetSenderObject::aSignal, this, [&slotCalled, sender, &globalCon, this] { + ++slotCalled; + // This signal will be connected, but should never be called as the sender will be destroyed before + auto c2 = connect(sender.data(), &GetSenderObject::aSignal, [] { QFAIL("Should not be called"); }); + QVERIFY(c2); + QVERIFY(QObject::disconnect(sender.data(), nullptr, this, nullptr)); + QVERIFY(!globalCon); // this connection has been disconnected + QVERIFY(c2); // sender should not have been deleted yet, only after the emission is done + }); + QMetaObject::invokeMethod(sender.data(), &GetSenderObject::triggerSignal, Qt::QueuedConnection); + QMetaObject::invokeMethod(sender.data(), &GetSenderObject::triggerSignal, Qt::QueuedConnection); + QMetaObject::invokeMethod(sender.data(), &GetSenderObject::triggerSignal, Qt::QueuedConnection); + } + eventLoop.exec(); + QCOMPARE(slotCalled, 1); + } + + { + GetSenderObject obj; + CountedStruct counted(&obj); + QCOMPARE(countedStructObjectsCount, 1); + auto c1 = QSharedPointer::create(); + auto c2 = QSharedPointer::create(); + int slot1Called = 0; + int slot3Called = 0; + *c1 = connect(&obj, &GetSenderObject::aSignal, &obj, [&slot1Called, &slot3Called, &obj, c1, c2, counted] { + auto c3 = connect(&obj, &GetSenderObject::aSignal, [counted, &slot3Called] { + slot3Called++; + }); + // top-level + the one in the 3 others lambdas + QCOMPARE(countedStructObjectsCount, 4); + QObject::disconnect(*c2); + // the one in the c2's lambda is gone + QCOMPARE(countedStructObjectsCount, 3); + slot1Called++; + }); + connect(&obj, &GetSenderObject::aSignal, [] {}); // just a dummy signal to fill the connection list + *c2 = connect(&obj, &GetSenderObject::aSignal, [counted, c2] { QFAIL("should not be called"); }); + QVERIFY(c1 && c2); + QCOMPARE(countedStructObjectsCount, 3); // top-level + c1 + c2 + obj.triggerSignal(); + QCOMPARE(slot1Called, 1); + QCOMPARE(slot3Called, 0); + QCOMPARE(countedStructObjectsCount, 3); // top-level + c1 + c3 + QObject::disconnect(*c1); + QCOMPARE(countedStructObjectsCount, 2); // top-level + c3 + obj.triggerSignal(); + QCOMPARE(slot1Called, 1); + QCOMPARE(slot3Called, 1); + } + { + struct DestroyEmit { + Q_DISABLE_COPY(DestroyEmit); + explicit DestroyEmit(SenderObject *obj) : obj(obj) {} + SenderObject *obj; + ~DestroyEmit() { + obj->emitSignal1(); + } + }; + SenderObject obj; + int slot1Called = 0; + int slot2Called = 0; + int slot3Called = 0; + auto c1 = QSharedPointer::create(); + auto de = QSharedPointer::create(&obj); + *c1 = connect(&obj, &SenderObject::signal1, [&slot1Called, &slot3Called, de, c1, &obj] { + connect(&obj, &SenderObject::signal1, [&slot3Called] { slot3Called++; }); + slot1Called++; + QObject::disconnect(*c1); + }); + de.clear(); + connect(&obj, &SenderObject::signal1, [&slot2Called] { slot2Called++; }); + obj.emitSignal1(); + QCOMPARE(slot1Called, 1); + QCOMPARE(slot2Called, 2); // because also called from ~DestroyEmit + QCOMPARE(slot3Called, 1); + } +} + +void tst_QObject::disconnectDisconnects() +{ + // Test what happens if the destructor of an functor slot also disconnects more slot; + + SenderObject s1; + QScopedPointer receiver(new QObject); + + auto s2 = QSharedPointer::create(); + QPointer s2_tracker = s2.data(); + int count = 0; + connect(&s1, &SenderObject::signal1, [&count] { count++; }); // α + connect(&s1, &SenderObject::signal1, receiver.data(), [s2] { QFAIL("!!"); }); // β + connect(s2.data(), &SenderObject::signal1, receiver.data(), [] { QFAIL("!!"); }); + connect(&s1, &SenderObject::signal2, receiver.data(), [] { QFAIL("!!"); }); + connect(s2.data(), &SenderObject::signal2, receiver.data(), [] { QFAIL("!!"); }); + connect(&s1, &SenderObject::signal1, [&count] { count++; }); // γ + connect(&s1, &SenderObject::signal2, [&count] { count++; }); // δ + s2.clear(); + + QVERIFY(s2_tracker); + receiver + .reset(); // this will delete the receiver which must also delete s2 as β is disconnected + QVERIFY(!s2_tracker); + // test that the data structures are still in order + s1.emitSignal1(); + QCOMPARE(count, 2); // α + γ + s1.emitSignal2(); + QCOMPARE(count, 3); // + δ +} + // Test for QtPrivate::HasQ_OBJECT_Macro Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro::Value); Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro::Value); -- cgit v1.2.3 From 8fe36801930872ef4a57e2ff7d7f935de12a33e9 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 1 Feb 2019 15:16:00 +0100 Subject: Add cmdline feature to qmake [ChangeLog][qmake] A new feature "cmdline" was added that implies "CONFIG += console" and "CONFIG -= app_bundle". Task-number: QTBUG-27079 Change-Id: I6e52b07c9341c904bb1424fc717057432f9360e1 Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/global/qlogging/app/app.pro | 3 +-- .../io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro | 3 +-- .../corelib/io/qprocess/fileWriterProcess/fileWriterProcess.pro | 3 +-- tests/auto/corelib/io/qprocess/testDetached/testDetached.pro | 3 +-- tests/auto/corelib/io/qprocess/testExitCodes/testExitCodes.pro | 4 ++-- tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro | 3 +-- .../io/qprocess/testForwardingHelper/testForwardingHelper.pro | 4 ++-- tests/auto/corelib/io/qprocess/testGuiProcess/testGuiProcess.pro | 3 +-- .../auto/corelib/io/qprocess/testProcessCrash/testProcessCrash.pro | 4 ++-- .../testProcessDeadWhileReading/testProcessDeadWhileReading.pro | 4 ++-- tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro | 4 ++-- tests/auto/corelib/io/qprocess/testProcessEcho/testProcessEcho.pro | 4 ++-- .../auto/corelib/io/qprocess/testProcessEcho2/testProcessEcho2.pro | 4 ++-- .../auto/corelib/io/qprocess/testProcessEcho3/testProcessEcho3.pro | 4 ++-- .../io/qprocess/testProcessEnvironment/testProcessEnvironment.pro | 6 +----- tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro | 4 ++-- .../corelib/io/qprocess/testProcessNormal/testProcessNormal.pro | 4 ++-- .../corelib/io/qprocess/testProcessOutput/testProcessOutput.pro | 4 ++-- tests/auto/corelib/io/qprocess/testProcessSpacesArgs/nospace.pro | 4 ++-- tests/auto/corelib/io/qprocess/testProcessSpacesArgs/onespace.pro | 4 ++-- tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro | 4 ++-- .../testSetNamedPipeHandleState/testSetNamedPipeHandleState.pro | 4 ++-- .../io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro | 3 +-- tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro | 4 ++-- tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro | 6 +----- .../qtextstream/readAllStdinProcess/readAllStdinProcess.pro | 3 +-- .../qtextstream/readLineStdinProcess/readLineStdinProcess.pro | 3 +-- .../corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro | 3 +-- .../auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro | 3 +-- .../testhelper/qcommandlineparser_test_helper.pro | 3 +-- tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro | 3 +-- tests/auto/corelib/tools/qsharedpointer/externaltests.cpp | 3 +-- 32 files changed, 48 insertions(+), 70 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qlogging/app/app.pro b/tests/auto/corelib/global/qlogging/app/app.pro index b90b685749..3ada382ff4 100644 --- a/tests/auto/corelib/global/qlogging/app/app.pro +++ b/tests/auto/corelib/global/qlogging/app/app.pro @@ -14,8 +14,7 @@ QT = core DESTDIR = ./ -CONFIG -= app_bundle -CONFIG += console +CONFIG += cmdline SOURCES += main.cpp DEFINES += QT_MESSAGELOGCONTEXT diff --git a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro index 3ac3be9c9b..97135d279e 100644 --- a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro +++ b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro @@ -1,7 +1,6 @@ TARGET = qlockfile_test_helper SOURCES += qlockfile_test_helper.cpp -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline QT = core DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/fileWriterProcess/fileWriterProcess.pro b/tests/auto/corelib/io/qprocess/fileWriterProcess/fileWriterProcess.pro index 947dc916f2..2744491151 100644 --- a/tests/auto/corelib/io/qprocess/fileWriterProcess/fileWriterProcess.pro +++ b/tests/auto/corelib/io/qprocess/fileWriterProcess/fileWriterProcess.pro @@ -1,5 +1,4 @@ SOURCES = main.cpp -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline QT = core DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testDetached/testDetached.pro b/tests/auto/corelib/io/qprocess/testDetached/testDetached.pro index 8d1fcba624..3d80b668df 100644 --- a/tests/auto/corelib/io/qprocess/testDetached/testDetached.pro +++ b/tests/auto/corelib/io/qprocess/testDetached/testDetached.pro @@ -1,6 +1,5 @@ SOURCES = main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline INSTALLS = DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testExitCodes/testExitCodes.pro b/tests/auto/corelib/io/qprocess/testExitCodes/testExitCodes.pro index b08371804f..5eaf8dc881 100644 --- a/tests/auto/corelib/io/qprocess/testExitCodes/testExitCodes.pro +++ b/tests/auto/corelib/io/qprocess/testExitCodes/testExitCodes.pro @@ -1,5 +1,5 @@ SOURCES += main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro b/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro index 45b498c32a..4d91e0cf36 100644 --- a/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro +++ b/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro @@ -1,5 +1,4 @@ SOURCES = main.cpp -CONFIG -= app_bundle -CONFIG += console +CONFIG += cmdline DESTDIR = ./ QT = core diff --git a/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro b/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro index e236e05c7d..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro +++ b/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro @@ -1,4 +1,4 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testGuiProcess/testGuiProcess.pro b/tests/auto/corelib/io/qprocess/testGuiProcess/testGuiProcess.pro index 8778da7ffe..ef438d6399 100644 --- a/tests/auto/corelib/io/qprocess/testGuiProcess/testGuiProcess.pro +++ b/tests/auto/corelib/io/qprocess/testGuiProcess/testGuiProcess.pro @@ -1,5 +1,4 @@ SOURCES += main.cpp QT += widgets -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessCrash/testProcessCrash.pro b/tests/auto/corelib/io/qprocess/testProcessCrash/testProcessCrash.pro index 7ccc976efc..640ce4cd09 100644 --- a/tests/auto/corelib/io/qprocess/testProcessCrash/testProcessCrash.pro +++ b/tests/auto/corelib/io/qprocess/testProcessCrash/testProcessCrash.pro @@ -1,5 +1,5 @@ SOURCES = main.cpp -CONFIG += console -CONFIG -= qt app_bundle +CONFIG += cmdline +CONFIG -= qt DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessDeadWhileReading/testProcessDeadWhileReading.pro b/tests/auto/corelib/io/qprocess/testProcessDeadWhileReading/testProcessDeadWhileReading.pro index fbb3411d47..c7be60a82d 100644 --- a/tests/auto/corelib/io/qprocess/testProcessDeadWhileReading/testProcessDeadWhileReading.pro +++ b/tests/auto/corelib/io/qprocess/testProcessDeadWhileReading/testProcessDeadWhileReading.pro @@ -1,5 +1,5 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro b/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro index 98fe78c8b9..ab1394a5c9 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro @@ -1,6 +1,6 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline win32:!mingw:!equals(TEMPLATE_PREFIX, "vc"):QMAKE_CXXFLAGS += /GS- DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessEcho/testProcessEcho.pro b/tests/auto/corelib/io/qprocess/testProcessEcho/testProcessEcho.pro index e236e05c7d..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEcho/testProcessEcho.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEcho/testProcessEcho.pro @@ -1,4 +1,4 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessEcho2/testProcessEcho2.pro b/tests/auto/corelib/io/qprocess/testProcessEcho2/testProcessEcho2.pro index e236e05c7d..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEcho2/testProcessEcho2.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEcho2/testProcessEcho2.pro @@ -1,4 +1,4 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessEcho3/testProcessEcho3.pro b/tests/auto/corelib/io/qprocess/testProcessEcho3/testProcessEcho3.pro index e236e05c7d..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEcho3/testProcessEcho3.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEcho3/testProcessEcho3.pro @@ -1,4 +1,4 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessEnvironment/testProcessEnvironment.pro b/tests/auto/corelib/io/qprocess/testProcessEnvironment/testProcessEnvironment.pro index a07ae00605..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEnvironment/testProcessEnvironment.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEnvironment/testProcessEnvironment.pro @@ -1,8 +1,4 @@ SOURCES = main.cpp CONFIG -= qt -CONFIG += console +CONFIG += cmdline DESTDIR = ./ - -mac { - CONFIG -= app_bundle -} diff --git a/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro b/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro index e236e05c7d..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro +++ b/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro @@ -1,4 +1,4 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro b/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro index c6db9d1bac..7e1119c117 100644 --- a/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro +++ b/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro @@ -1,6 +1,6 @@ SOURCES = main.cpp -CONFIG += console -CONFIG -= qt app_bundle +CONFIG += cmdline +CONFIG -= qt DESTDIR = ./ QT = core diff --git a/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro b/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro index 95191098bd..0bbb6b3c0e 100644 --- a/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro +++ b/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro @@ -1,5 +1,5 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ QT = core diff --git a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/nospace.pro b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/nospace.pro index dd7e8e4a85..7954a2f74b 100644 --- a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/nospace.pro +++ b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/nospace.pro @@ -1,6 +1,6 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ OBJECTS_DIR = $${OBJECTS_DIR}-nospace DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/onespace.pro b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/onespace.pro index d18a683e1c..44a365c9a5 100644 --- a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/onespace.pro +++ b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/onespace.pro @@ -1,6 +1,6 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ OBJECTS_DIR = $${OBJECTS_DIR}-onespace diff --git a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro index 8b16f65e34..bd2db9fb6d 100644 --- a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro +++ b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro @@ -1,6 +1,6 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ OBJECTS_DIR = $${OBJECTS_DIR}-twospaces diff --git a/tests/auto/corelib/io/qprocess/testSetNamedPipeHandleState/testSetNamedPipeHandleState.pro b/tests/auto/corelib/io/qprocess/testSetNamedPipeHandleState/testSetNamedPipeHandleState.pro index e236e05c7d..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testSetNamedPipeHandleState/testSetNamedPipeHandleState.pro +++ b/tests/auto/corelib/io/qprocess/testSetNamedPipeHandleState/testSetNamedPipeHandleState.pro @@ -1,4 +1,4 @@ SOURCES = main.cpp -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro b/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro index 21a115b536..4d91e0cf36 100644 --- a/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro +++ b/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro @@ -1,5 +1,4 @@ SOURCES = main.cpp -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ QT = core diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro index 80e8bcad98..2cfcb4794e 100644 --- a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro +++ b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro @@ -6,7 +6,7 @@ unix { SOURCES = main_unix.cpp } -CONFIG -= qt app_bundle -CONFIG += console +CONFIG -= qt +CONFIG += cmdline DESTDIR = ./ QT = core diff --git a/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro b/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro index afa4f32a85..48f28c4c8b 100644 --- a/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro +++ b/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro @@ -1,9 +1,5 @@ SOURCES = main.cpp CONFIG -= qt -CONFIG += console +CONFIG += cmdline DESTDIR = "../test Space In Name" - -mac { - CONFIG -= app_bundle -} QT = core diff --git a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro index 4a4c091dcb..f2b5aa619f 100644 --- a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro +++ b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro @@ -1,7 +1,6 @@ SOURCES += main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ # This app is testdata for tst_qtextstream diff --git a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro index 4a4c091dcb..f2b5aa619f 100644 --- a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro +++ b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro @@ -1,7 +1,6 @@ SOURCES += main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ # This app is testdata for tst_qtextstream diff --git a/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro b/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro index 4a4c091dcb..f2b5aa619f 100644 --- a/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro +++ b/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro @@ -1,7 +1,6 @@ SOURCES += main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ # This app is testdata for tst_qtextstream diff --git a/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro index d5c09ebc84..57bd78bcee 100644 --- a/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro +++ b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro @@ -9,8 +9,7 @@ debug_and_release { TARGET = ../crashOnExit_helper } QT = core -CONFIG -= app_bundle -CONFIG += console +CONFIG += cmdline # This app is testdata for tst_qthreadstorage target.path = $$[QT_INSTALL_TESTS]/tst_qthreadstorage/$$TARGET diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.pro b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.pro index dce1ac0d37..5020658835 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.pro +++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.pro @@ -1,5 +1,4 @@ -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline QT = core DESTDIR = ./ diff --git a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro index b61f51d53a..3e283c05a4 100644 --- a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro +++ b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro @@ -1,8 +1,7 @@ SOURCES += syslocaleapp.cpp DESTDIR = ./ -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline QT = core diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp index 4dc620e6ab..d1bb89f549 100644 --- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp @@ -470,9 +470,8 @@ namespace QTest { "TEMPLATE = app\n" "\n" "TARGET = externaltest\n" - "CONFIG -= app_bundle\n" // for the Mac "CONFIG -= debug_and_release\n" - "CONFIG += console\n" + "CONFIG += cmdline\n" "DESTDIR = .\n" "OBJECTS_DIR = .\n" "UI_DIR = .\n" -- cgit v1.2.3 From 0f163887b526d00ccdcead907dde042aa370fc16 Mon Sep 17 00:00:00 2001 From: Juha Karjalainen Date: Tue, 19 Feb 2019 13:57:47 +0200 Subject: Fix blacklisting tst_QTimer::basic_chrono() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Blacklisting did not work as blacklist should have contained osx instead macos Change-Id: Ifd76a38d371ccce545eb5df030aaa819b00a5b48 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/kernel/qtimer/BLACKLIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/BLACKLIST b/tests/auto/corelib/kernel/qtimer/BLACKLIST index c31e15f171..16cbab4587 100644 --- a/tests/auto/corelib/kernel/qtimer/BLACKLIST +++ b/tests/auto/corelib/kernel/qtimer/BLACKLIST @@ -2,4 +2,4 @@ windows osx [basic_chrono] -macos +osx -- cgit v1.2.3 From d8cf721d60b488c1966e0ae224b669a9fc9f3e42 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 20 Feb 2019 13:25:33 +0100 Subject: Update the DNS public suffix list from publicsuffix.org Regular update in preparation for 5.13, adding tests for additions since 5.9.4/5.10.1/5.11.0's update 7e946030 (the last to record its upstream version sha1). Corrected the license header: it's now published under MPL 2.0 (not 1.1); and our secondary licensing of it is as LGPL3. Deferred full header over-haul until we've worked one out in detail. [ChangeLog][Third-Party Code] Updated DNS public suffix list Task-number: QTBUG-72623 Change-Id: Iabdbbbfd79624830396c2a6fe0a73389bd6ce5b7 Reviewed-by: Kai Koehne Reviewed-by: Qt CI Bot --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 4f173d2dfd..3ee6a656b0 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3402,6 +3402,21 @@ void tst_QUrl::effectiveTLDs_data() QTest::newRow("yes16") << QUrl::fromEncoded("http://anything.pagespeedmobilizer.com") << ".pagespeedmobilizer.com"; QTest::newRow("yes17") << QUrl::fromEncoded("http://anything.eu-central-1.compute.amazonaws.com") << ".eu-central-1.compute.amazonaws.com"; QTest::newRow("yes18") << QUrl::fromEncoded("http://anything.ltd.hk") << ".ltd.hk"; + QTest::newRow("trentino.it") + << QUrl::fromEncoded("http://any.thing.trentino.it") << ".trentino.it"; + QTest::newRow("net.ni") << QUrl::fromEncoded("http://test.net.ni") << ".net.ni"; + QTest::newRow("dyn.cosidns.de") + << QUrl::fromEncoded("http://test.dyn.cosidns.de") << ".dyn.cosidns.de"; + QTest::newRow("freeddns.org") + << QUrl::fromEncoded("http://test.freeddns.org") << ".freeddns.org"; + QTest::newRow("app.os.stg.fedoraproject.org") + << QUrl::fromEncoded("http://test.app.os.stg.fedoraproject.org") + << ".app.os.stg.fedoraproject.org"; + QTest::newRow("development.run") << QUrl::fromEncoded("http://test.development.run") << ".development.run"; + QTest::newRow("crafting.xyz") << QUrl::fromEncoded("http://test.crafting.xyz") << ".crafting.xyz"; + QTest::newRow("nym.ie") << QUrl::fromEncoded("http://shamus.nym.ie") << ".nym.ie"; + QTest::newRow("vapor.cloud") << QUrl::fromEncoded("http://test.vapor.cloud") << ".vapor.cloud"; + QTest::newRow("official.academy") << QUrl::fromEncoded("http://acredited.official.academy") << ".official.academy"; } void tst_QUrl::effectiveTLDs() -- cgit v1.2.3 From 47bb74fd156edb93d85c88db4d6ff98648bce275 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 13 Sep 2018 16:42:06 +0100 Subject: Fix build with -no-gui on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some directories that depend on QtGui were being included without the appropriate check for qtHaveModule(gui). Change-Id: I7c348c74464d44cbd35a027f188f8a23bb2021d9 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov --- tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro index 541e73636c..3745782dfc 100644 --- a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro +++ b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro @@ -9,7 +9,7 @@ SUBDIRS = lib \ tst.depends += almostplugin SUBDIRS += almostplugin } -macos:qtConfig(private_tests) { +macos:qtConfig(private_tests):qtHaveModule(gui) { tst.depends += machtest SUBDIRS += machtest } -- cgit v1.2.3 From 332f295743019a5b70eb923d6ad93352b0cb4079 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 2 Mar 2019 21:27:56 +0100 Subject: QtBase: replace deprecated QString functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace deprecated QString functions in examples and tests: - QString::sprintf() - QString::null - QString::fromAscii Change-Id: I4404d17c1a65496c9079e8a7300e72a5b3740fe5 Reviewed-by: Luca Beldi Reviewed-by: Friedemann Kleint Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 132 +++++++++------------ .../auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 3 +- 2 files changed, 56 insertions(+), 79 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index e8ed22e427..e25c9e8395 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -482,8 +482,8 @@ private slots: void indexOf2(); void indexOf3_data(); // void indexOf3(); - void sprintf(); - void sprintfS(); + void asprintf(); + void asprintfS(); void fill(); void truncate(); void chop_data(); @@ -612,7 +612,7 @@ QString verifyZeroTermination(const QString &str) int strSize = str.size(); QChar strTerminator = str.constData()[strSize]; if (QChar('\0') != strTerminator) - return QString::fromAscii( + return QString::fromLatin1( "*** Result ('%1') not null-terminated: 0x%2 ***").arg(str) .arg(strTerminator.unicode(), 4, 16, QChar('0')); @@ -625,11 +625,11 @@ QString verifyZeroTermination(const QString &str) const_cast(strData)[strSize] = QChar('x'); if (QChar('x') != str.constData()[strSize]) { - return QString::fromAscii("*** Failed to replace null-terminator in " + return QString::fromLatin1("*** Failed to replace null-terminator in " "result ('%1') ***").arg(str); } if (str != strCopy) { - return QString::fromAscii( "*** Result ('%1') differs from its copy " + return QString::fromLatin1( "*** Result ('%1') differs from its copy " "after null-terminator was replaced ***").arg(str); } const_cast(strData)[strSize] = QChar('\0'); // Restore sanity @@ -1075,9 +1075,8 @@ void tst_QString::isNull() QString a; QVERIFY(a.isNull()); - const char *zero = 0; - a.sprintf( zero ); - QVERIFY(!a.isNull()); + const char *zero = nullptr; + QVERIFY(!QString::asprintf(zero).isNull()); } QT_WARNING_POP @@ -1263,75 +1262,66 @@ static inline const void *ptrValue(quintptr v) return reinterpret_cast(v); } -void tst_QString::sprintf() +void tst_QString::asprintf() { QString a; - a.sprintf("COMPARE"); - QCOMPARE(a, QLatin1String("COMPARE")); - a.sprintf("%%%d",1); - QCOMPARE(a, QLatin1String("%1")); - QCOMPARE(a.sprintf("X%dY",2), QLatin1String("X2Y")); - QCOMPARE(a.sprintf("X%9iY", 50000 ), QLatin1String("X 50000Y")); - QCOMPARE(a.sprintf("X%-9sY","hello"), QLatin1String("Xhello Y")); - QCOMPARE(a.sprintf("X%-9iY", 50000 ), QLatin1String("X50000 Y")); - QCOMPARE(a.sprintf("%lf", 1.23), QLatin1String("1.230000")); - QCOMPARE(a.sprintf("%lf", 1.23456789), QLatin1String("1.234568")); - QCOMPARE(a.sprintf("%p", ptrValue(0xbfffd350)), QLatin1String("0xbfffd350")); - QCOMPARE(a.sprintf("%p", ptrValue(0)), QLatin1String("0x0")); + QCOMPARE(QString::asprintf("COMPARE"), QLatin1String("COMPARE")); + QCOMPARE(QString::asprintf("%%%d", 1), QLatin1String("%1")); + QCOMPARE(QString::asprintf("X%dY",2), QLatin1String("X2Y")); + QCOMPARE(QString::asprintf("X%9iY", 50000 ), QLatin1String("X 50000Y")); + QCOMPARE(QString::asprintf("X%-9sY","hello"), QLatin1String("Xhello Y")); + QCOMPARE(QString::asprintf("X%-9iY", 50000 ), QLatin1String("X50000 Y")); + QCOMPARE(QString::asprintf("%lf", 1.23), QLatin1String("1.230000")); + QCOMPARE(QString::asprintf("%lf", 1.23456789), QLatin1String("1.234568")); + QCOMPARE(QString::asprintf("%p", ptrValue(0xbfffd350)), QLatin1String("0xbfffd350")); + QCOMPARE(QString::asprintf("%p", ptrValue(0)), QLatin1String("0x0")); int i = 6; long l = -2; float f = 4.023f; - QString S1; - S1.sprintf("%d %ld %f",i,l,f); - QCOMPARE(S1, QLatin1String("6 -2 4.023000")); + QCOMPARE(QString::asprintf("%d %ld %f", i, l, f), QLatin1String("6 -2 4.023000")); double d = -514.25683; - S1.sprintf("%f",d); - QCOMPARE(S1, QLatin1String("-514.256830")); + QCOMPARE(QString::asprintf("%f", d), QLatin1String("-514.256830")); } -void tst_QString::sprintfS() +void tst_QString::asprintfS() { - QString a; - QCOMPARE(a.sprintf("%.3s", "Hello" ), QLatin1String("Hel")); - QCOMPARE(a.sprintf("%10.3s", "Hello" ), QLatin1String(" Hel")); - QCOMPARE(a.sprintf("%.10s", "Hello" ), QLatin1String("Hello")); - QCOMPARE(a.sprintf("%10.10s", "Hello" ), QLatin1String(" Hello")); - QCOMPARE(a.sprintf("%-10.10s", "Hello" ), QLatin1String("Hello ")); - QCOMPARE(a.sprintf("%-10.3s", "Hello" ), QLatin1String("Hel ")); - QCOMPARE(a.sprintf("%-5.5s", "Hello" ), QLatin1String("Hello")); + QCOMPARE(QString::asprintf("%.3s", "Hello" ), QLatin1String("Hel")); + QCOMPARE(QString::asprintf("%10.3s", "Hello" ), QLatin1String(" Hel")); + QCOMPARE(QString::asprintf("%.10s", "Hello" ), QLatin1String("Hello")); + QCOMPARE(QString::asprintf("%10.10s", "Hello" ), QLatin1String(" Hello")); + QCOMPARE(QString::asprintf("%-10.10s", "Hello" ), QLatin1String("Hello ")); + QCOMPARE(QString::asprintf("%-10.3s", "Hello" ), QLatin1String("Hel ")); + QCOMPARE(QString::asprintf("%-5.5s", "Hello" ), QLatin1String("Hello")); // Check utf8 conversion for %s - QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString::fromLatin1("\366\344\374\326\304\334\370\346\345\330\306\305")); + QCOMPARE(QString::asprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString::fromLatin1("\366\344\374\326\304\334\370\346\345\330\306\305")); int n1; - a.sprintf("%s%n%s", "hello", &n1, "goodbye"); + QCOMPARE(QString::asprintf("%s%n%s", "hello", &n1, "goodbye"), QString("hellogoodbye")); QCOMPARE(n1, 5); - QCOMPARE(a, QString("hellogoodbye")); qlonglong n2; - a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz"); + QCOMPARE(QString::asprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz"), QString("foobarwhiz")); QCOMPARE((int)n2, 6); - QCOMPARE(a, QString("foobarwhiz")); { // %ls - QCOMPARE(a.sprintf("%.3ls", qUtf16Printable("Hello")), QLatin1String("Hel")); - QCOMPARE(a.sprintf("%10.3ls", qUtf16Printable("Hello")), QLatin1String(" Hel")); - QCOMPARE(a.sprintf("%.10ls", qUtf16Printable("Hello")), QLatin1String("Hello")); - QCOMPARE(a.sprintf("%10.10ls", qUtf16Printable("Hello")), QLatin1String(" Hello")); - QCOMPARE(a.sprintf("%-10.10ls", qUtf16Printable("Hello")), QLatin1String("Hello ")); - QCOMPARE(a.sprintf("%-10.3ls", qUtf16Printable("Hello")), QLatin1String("Hel ")); - QCOMPARE(a.sprintf("%-5.5ls", qUtf16Printable("Hello")), QLatin1String("Hello")); + QCOMPARE(QString::asprintf("%.3ls", qUtf16Printable("Hello")), QLatin1String("Hel")); + QCOMPARE(QString::asprintf("%10.3ls", qUtf16Printable("Hello")), QLatin1String(" Hel")); + QCOMPARE(QString::asprintf("%.10ls", qUtf16Printable("Hello")), QLatin1String("Hello")); + QCOMPARE(QString::asprintf("%10.10ls", qUtf16Printable("Hello")), QLatin1String(" Hello")); + QCOMPARE(QString::asprintf("%-10.10ls", qUtf16Printable("Hello")), QLatin1String("Hello ")); + QCOMPARE(QString::asprintf("%-10.3ls", qUtf16Printable("Hello")), QLatin1String("Hel ")); + QCOMPARE(QString::asprintf("%-5.5ls", qUtf16Printable("Hello")), QLatin1String("Hello")); // Check utf16 is preserved for %ls - QCOMPARE(a.sprintf("%ls", + QCOMPARE(QString::asprintf("%ls", qUtf16Printable("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205")), QLatin1String("\366\344\374\326\304\334\370\346\345\330\306\305")); int n; - a.sprintf("%ls%n%s", qUtf16Printable("hello"), &n, "goodbye"); + QCOMPARE(QString::asprintf("%ls%n%s", qUtf16Printable("hello"), &n, "goodbye"), QLatin1String("hellogoodbye")); QCOMPARE(n, 5); - QCOMPARE(a, QLatin1String("hellogoodbye")); } } @@ -3789,7 +3779,7 @@ void tst_QString::startsWith() QVERIFY( !a.startsWith("C") ); QVERIFY( !a.startsWith("ABCDEF") ); QVERIFY( a.startsWith("") ); - QVERIFY( a.startsWith(QString::null) ); + QVERIFY( a.startsWith(QString()) ); QVERIFY( a.startsWith('A') ); QVERIFY( a.startsWith(QLatin1Char('A')) ); QVERIFY( a.startsWith(QChar('A')) ); @@ -3816,7 +3806,7 @@ void tst_QString::startsWith() QVERIFY( !a.startsWith("c", Qt::CaseInsensitive) ); QVERIFY( !a.startsWith("abcdef", Qt::CaseInsensitive) ); QVERIFY( a.startsWith("", Qt::CaseInsensitive) ); - QVERIFY( a.startsWith(QString::null, Qt::CaseInsensitive) ); + QVERIFY( a.startsWith(QString(), Qt::CaseInsensitive) ); QVERIFY( a.startsWith('a', Qt::CaseInsensitive) ); QVERIFY( a.startsWith('A', Qt::CaseInsensitive) ); QVERIFY( a.startsWith(QLatin1Char('a'), Qt::CaseInsensitive) ); @@ -3855,7 +3845,7 @@ void tst_QString::startsWith() a = ""; QVERIFY( a.startsWith("") ); - QVERIFY( a.startsWith(QString::null) ); + QVERIFY( a.startsWith(QString()) ); QVERIFY( !a.startsWith("ABC") ); QVERIFY( a.startsWith(QLatin1String("")) ); @@ -3868,7 +3858,7 @@ void tst_QString::startsWith() a = QString(); QVERIFY( !a.startsWith("") ); - QVERIFY( a.startsWith(QString::null) ); + QVERIFY( a.startsWith(QString()) ); QVERIFY( !a.startsWith("ABC") ); QVERIFY( !a.startsWith(QLatin1String("")) ); @@ -3897,7 +3887,7 @@ void tst_QString::endsWith() QVERIFY( !a.endsWith("C") ); QVERIFY( !a.endsWith("ABCDEF") ); QVERIFY( a.endsWith("") ); - QVERIFY( a.endsWith(QString::null) ); + QVERIFY( a.endsWith(QString()) ); QVERIFY( a.endsWith('B') ); QVERIFY( a.endsWith(QLatin1Char('B')) ); QVERIFY( a.endsWith(QChar('B')) ); @@ -3924,7 +3914,7 @@ void tst_QString::endsWith() QVERIFY( !a.endsWith("c", Qt::CaseInsensitive) ); QVERIFY( !a.endsWith("abcdef", Qt::CaseInsensitive) ); QVERIFY( a.endsWith("", Qt::CaseInsensitive) ); - QVERIFY( a.endsWith(QString::null, Qt::CaseInsensitive) ); + QVERIFY( a.endsWith(QString(), Qt::CaseInsensitive) ); QVERIFY( a.endsWith('b', Qt::CaseInsensitive) ); QVERIFY( a.endsWith('B', Qt::CaseInsensitive) ); QVERIFY( a.endsWith(QLatin1Char('b'), Qt::CaseInsensitive) ); @@ -3966,7 +3956,7 @@ void tst_QString::endsWith() a = ""; QVERIFY( a.endsWith("") ); - QVERIFY( a.endsWith(QString::null) ); + QVERIFY( a.endsWith(QString()) ); QVERIFY( !a.endsWith("ABC") ); QVERIFY( !a.endsWith(QLatin1Char(0)) ); QVERIFY( !a.endsWith(QLatin1Char('x')) ); @@ -3978,7 +3968,7 @@ void tst_QString::endsWith() a = QString(); QVERIFY( !a.endsWith("") ); - QVERIFY( a.endsWith(QString::null) ); + QVERIFY( a.endsWith(QString()) ); QVERIFY( !a.endsWith("ABC") ); QVERIFY( !a.endsWith(QLatin1String("")) ); @@ -4838,7 +4828,7 @@ void tst_QString::arg() QCOMPARE( QString("%1").arg("hello", 10), QLatin1String(" hello") ); QCOMPARE( QString("%1%1").arg("hello"), QLatin1String("hellohello") ); QCOMPARE( QString("%2%1").arg("hello"), QLatin1String("%2hello") ); - QCOMPARE( QString("%1%1").arg(QString::null), QLatin1String("") ); + QCOMPARE( QString("%1%1").arg(QString()), QLatin1String("") ); QCOMPARE( QString("%2%1").arg(""), QLatin1String("%2") ); QCOMPARE( QString("%2 %L1").arg(12345.6789).arg(12345.6789), @@ -4934,9 +4924,7 @@ void tst_QString::doubleOut() QCOMPARE(QString::number(micro), expect); QCOMPARE(QString("%1").arg(micro), expect); { - QString text; - text.sprintf("%g", micro); - QCOMPARE(text, expect); + QCOMPARE(QString::asprintf("%g", micro), expect); } { QString text; @@ -5480,8 +5468,6 @@ void tst_QString::tortureSprintfDouble() { const SprintfDoubleData *data = g_sprintf_double_data; - QString s; - for (; data->fmt != 0; ++data) { double d; char *buff = (char *)&d; @@ -5496,7 +5482,7 @@ void tst_QString::tortureSprintfDouble() for (uint i = 0; i < 8; ++i) buff[7 - i] = data->bytes[i]; # endif - s.sprintf(data->fmt, d); + const QString s = QString::asprintf(data->fmt, d); #ifdef QT_NO_FPU // reduced precision when running with hardfloats in qemu if (d - 0.1 < 1e12) QSKIP("clib sprintf doesn't fill with 0's on this platform"); @@ -6450,32 +6436,24 @@ void tst_QString::QCharRefDetaching() const void tst_QString::sprintfZU() const { { - QString string; size_t s = 6; - string.sprintf("%zu", s); - QCOMPARE(string, QString::fromLatin1("6")); + QCOMPARE(QString::asprintf("%zu", s), QString::fromLatin1("6")); } { - QString string; - string.sprintf("%s\n", "foo"); - QCOMPARE(string, QString::fromLatin1("foo\n")); + QCOMPARE(QString::asprintf("%s\n", "foo"), QString::fromLatin1("foo\n")); } { /* This code crashed. I don't know how to reduce it further. In other words, * both %zu and %s needs to be present. */ size_t s = 6; - QString string; - string.sprintf("%zu%s", s, "foo"); - QCOMPARE(string, QString::fromLatin1("6foo")); + QCOMPARE(QString::asprintf("%zu%s", s, "foo"), QString::fromLatin1("6foo")); } { size_t s = 6; - QString string; - string.sprintf("%zu %s\n", s, "foo"); - QCOMPARE(string, QString::fromLatin1("6 foo\n")); + QCOMPARE(QString::asprintf("%zu %s\n", s, "foo"), QString::fromLatin1("6 foo\n")); } } diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index a25fd39693..fc4cb717ec 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -480,11 +480,10 @@ void tst_QTimeZone::transitionEachZone_data() { 1288488600, -4, 8, 2010 } // 2010-10-31 01:30 UTC; Europe, Russia }; - QString name; const auto zones = QTimeZone::availableTimeZoneIds(); for (int k = sizeof(table) / sizeof(table[0]); k-- > 0; ) { for (const QByteArray &zone : zones) { - name.sprintf("%s@%d", zone.constData(), table[k].year); + const QString name = QString::asprintf("%s@%d", zone.constData(), table[k].year); QTest::newRow(name.toUtf8().constData()) << zone << table[k].baseSecs -- cgit v1.2.3 From 1b5dbebb935dca88c74aceb3cde4367ac63f6c34 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 4 Mar 2019 13:44:48 +0100 Subject: Deprecation-fix: don't use QDir::operator=(const QString &) Use setPath() instead, as advised in the deprecation warning. Change-Id: I2f22220885938808c8efb85720ad10f7e05801ff Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 34588b19bc..b703a8839f 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -2045,7 +2045,7 @@ void tst_QDir::detachingOperations() QCOMPARE(dir2.nameFilters(), nameFilters); QCOMPARE(dir2.sorting(), sorting); - dir2 = path1; + dir2.setPath(path1); QCOMPARE(dir2.path(), path1); QCOMPARE(dir2.filter(), filter); QCOMPARE(dir2.nameFilters(), nameFilters); -- cgit v1.2.3 From c9ff943f8f006a64aaae6c98c316235d6fc78956 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 4 Mar 2019 13:19:27 +0100 Subject: Restructure tst_QDir::mkdirRmdir_data() Iterate over a struct array rather than having a list of strings to pull things out of, by individual index; this makes it easy to include the non-existence check for directories in the same loop. In the process, give the absolute-path tests a prefix to mirror the relative- prefix on their partners. This prepares the way for adding more test-cases. Change-Id: Id839caedf92387dfa9b94f31253410285f72ff70 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 34588b19bc..6cca360fef 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -349,21 +349,21 @@ void tst_QDir::mkdirRmdir_data() QTest::addColumn("path"); QTest::addColumn("recurse"); - QStringList dirs; - dirs << "testdir/one" - << "testdir/two/three/four" - << "testdir/../testdir/three"; - QTest::newRow("plain") << QDir::currentPath() + "/" + dirs.at(0) << false; - QTest::newRow("recursive") << QDir::currentPath() + "/" + dirs.at(1) << true; - QTest::newRow("with-..") << QDir::currentPath() + "/" + dirs.at(2) << false; - - QTest::newRow("relative-plain") << dirs.at(0) << false; - QTest::newRow("relative-recursive") << dirs.at(1) << true; - QTest::newRow("relative-with-..") << dirs.at(2) << false; - - // Ensure that none of these directories already exist - for (int i = 0; i < dirs.count(); ++i) - QVERIFY(!QFile::exists(dirs.at(i))); + const struct { + const char *name; // shall have a prefix added + const char *path; // relative + bool recurse; + } cases[] = { + { "plain", "testdir/one", false }, + { "recursive", "testdir/two/three/four", true }, + { "with-..", "testdir/../testdir/three", false }, + }; + + for (const auto &it : cases) { + QVERIFY(!QFile::exists(it.path)); + QTest::addRow("absolute-%s", it.name) << (QDir::currentPath() + "/") + it.path << it.recurse; + QTest::addRow("relative-%s", it.name) << QString::fromLatin1(it.path) << it.recurse; + } } void tst_QDir::mkdirRmdir() -- cgit v1.2.3 From 75c6bd54d7e056e2818f942f9e40b897f575fd34 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 6 Mar 2019 10:00:09 +0100 Subject: Avoid copying QByteArray created via fromRawData in toDouble qt_asciiToDouble accepts a length parameter, so we can just pass that through. No need for explicitly null-terminating, which is where the copy of the data would be made. Change-Id: I4e7921541f03295a2fae6171b35157084ff3ed8c Fixes: QTBUG-65748 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 1ed41793dc..d9e03439b8 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -1361,6 +1361,9 @@ void tst_QByteArray::toDouble_data() QTest::newRow("trailing spaces") << QByteArray("1.2345 \n\r\t") << 1.2345 << true; QTest::newRow("leading junk") << QByteArray("x1.2345") << 0.0 << false; QTest::newRow("trailing junk") << QByteArray("1.2345x") << 0.0 << false; + + QTest::newRow("raw, null plus junk") << QByteArray::fromRawData("1.2\0 junk", 9) << 0.0 << false; + QTest::newRow("raw, null-terminator not included") << QByteArray::fromRawData("2.3", 3) << 2.3 << true; } void tst_QByteArray::toDouble() -- cgit v1.2.3 From b35eec360d4d88d094094fb54c101fad6cee5768 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 12 Mar 2019 02:40:01 -0700 Subject: QStringMatcher: add QStringView support While touching the code, deduplicate some methods. Change-Id: I28f469f0e9ae000a34466b0ecc604b5f3bd09e63 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp b/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp index 8a55f54449..2d577bb0ab 100644 --- a/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp +++ b/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp @@ -100,6 +100,11 @@ void tst_QStringMatcher::indexIn() matcher.setPattern(needle); QCOMPARE(matcher.indexIn(haystack, from), indexIn); + + const auto needleSV = QStringView(needle); + QStringMatcher matcherSV(needleSV); + + QCOMPARE(matcherSV.indexIn(QStringView(haystack), from), indexIn); } void tst_QStringMatcher::setCaseSensitivity_data() @@ -128,6 +133,7 @@ void tst_QStringMatcher::setCaseSensitivity() matcher.setCaseSensitivity(static_cast (cs)); QCOMPARE(matcher.indexIn(haystack, from), indexIn); + QCOMPARE(matcher.indexIn(QStringView(haystack), from), indexIn); } void tst_QStringMatcher::assignOperator() -- cgit v1.2.3 From 097bf6fdd234ca7e5707610edfd3c804b3ba2a52 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 13 Mar 2019 21:47:27 +0100 Subject: Fix compilation of qCDebug("", ...) with QT_NO_DEBUG_OUTPUT ... and fix QT_NO_INFO_OUTPUT, QT_NO_WARNING_OUTPUT alongside. Fixes: QTBUG-74359 Change-Id: I2167dc943ae8c52602e08e24ca815d95f82a5db8 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp index 17c51eaaf4..569c610e24 100644 --- a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp +++ b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp @@ -53,6 +53,7 @@ void tst_QNoDebug::noDebugOutput() const // should do nothing qDebug() << "foo"; qCDebug(cat) << "foo"; + qCDebug(cat, "foo"); // qWarning still works, though QTest::ignoreMessage(QtWarningMsg, "bar"); -- cgit v1.2.3 From 368eb2ecec7cc54ea987de00df7caa52a0d4503a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 13 Mar 2019 19:30:53 +0100 Subject: Refine and extend tst_qnumeric's checks on infinity and NaN Renamed the test, since it covers both, verified slightly more and added checks that QCOMPARE() copes as intended. Fixed some minor coding-style defects in the process. Change-Id: I49c2ffa0568a29e9e4b7f7395d4cacdeb0401da0 Reviewed-by: Thiago Macieira --- .../auto/corelib/global/qnumeric/tst_qnumeric.cpp | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index 03300c6dbe..f37dcbbbba 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -42,7 +42,7 @@ class tst_QNumeric: public QObject private slots: void fuzzyCompare_data(); void fuzzyCompare(); - void qNan(); + void qNanInf(); void floatDistance_data(); void floatDistance(); void floatDistance_double_data(); @@ -91,7 +91,7 @@ void tst_QNumeric::fuzzyCompare() # pragma GCC optimize "no-fast-math" #endif -void tst_QNumeric::qNan() +void tst_QNumeric::qNanInf() { #if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ < 404) QSKIP("Non-conformant fast math mode is enabled, cannot run test"); @@ -99,9 +99,16 @@ void tst_QNumeric::qNan() double nan = qQNaN(); QVERIFY(!(0 > nan)); QVERIFY(!(0 < nan)); + QVERIFY(!(0 == nan)); + QVERIFY(!(nan == nan)); QVERIFY(qIsNaN(nan)); QVERIFY(qIsNaN(nan + 1)); QVERIFY(qIsNaN(-nan)); + QVERIFY(qIsNaN(1.0 / nan)); + QVERIFY(qIsNaN(0.0 / nan)); + QVERIFY(qIsNaN(0.0 * nan)); + QCOMPARE(nan, nan); + QCOMPARE(nan, -nan); Q_STATIC_ASSERT(sizeof(double) == 8); #ifdef Q_LITTLE_ENDIAN @@ -113,17 +120,27 @@ void tst_QNumeric::qNan() QVERIFY(!qIsFinite(nan)); QVERIFY(!qIsInf(nan)); QVERIFY(qIsNaN(nan)); + QVERIFY(qIsNaN(-nan)); + QVERIFY(!(nan == nan)); + QVERIFY(qIsNaN(0.0 * nan)); + QCOMPARE(nan, nan); + QCOMPARE(nan, -nan); + QCOMPARE(nan, qQNaN()); double inf = qInf(); QVERIFY(inf > 0); QVERIFY(-inf < 0); QVERIFY(qIsInf(inf)); + QCOMPARE(inf, inf); + QCOMPARE(-inf, -inf); QVERIFY(qIsInf(-inf)); - QVERIFY(qIsInf(2*inf)); - QCOMPARE(1/inf, 0.0); - QVERIFY(qIsNaN(0*nan)); - QVERIFY(qIsNaN(0*inf)); - QVERIFY(qFuzzyCompare(1/inf, 0.0)); + QVERIFY(qIsInf(inf + 1)); + QVERIFY(qIsInf(inf - 1)); + QVERIFY(qIsInf(inf * 2.0)); + QVERIFY(qIsInf(inf / 2.0)); + QVERIFY(qFuzzyCompare(1.0 / inf, 0.0)); + QCOMPARE(1.0 / inf, 0.0); + QVERIFY(qIsNaN(0.0 * inf)); } void tst_QNumeric::floatDistance_data() -- cgit v1.2.3 From 84aea6c091d020a37c2b452a6f56ca27b3b2c7cb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 13 Mar 2019 18:49:04 +0100 Subject: Add qFpClassify() to mirror std::fpclassify() The rules of std don't permit us to add an overload for fpclassify(qfloat16), so we need our own equivalent that we *can* overload. Deploy it in the few places we use fpclassify(). Extended qnumeric's testing to cover qFpClassify(). Change-Id: Ie5a0a5cc24599d1571404c573d33c682b0d305a5 Reviewed-by: Thiago Macieira Reviewed-by: Paul Wicking --- .../auto/corelib/global/qnumeric/tst_qnumeric.cpp | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index f37dcbbbba..e567e465f7 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -43,6 +43,7 @@ private slots: void fuzzyCompare_data(); void fuzzyCompare(); void qNanInf(); + void classifyfp(); void floatDistance_data(); void floatDistance(); void floatDistance_double_data(); @@ -123,6 +124,7 @@ void tst_QNumeric::qNanInf() QVERIFY(qIsNaN(-nan)); QVERIFY(!(nan == nan)); QVERIFY(qIsNaN(0.0 * nan)); + QCOMPARE(qFpClassify(nan), FP_NAN); QCOMPARE(nan, nan); QCOMPARE(nan, -nan); QCOMPARE(nan, qQNaN()); @@ -143,6 +145,34 @@ void tst_QNumeric::qNanInf() QVERIFY(qIsNaN(0.0 * inf)); } +void tst_QNumeric::classifyfp() +{ + QCOMPARE(qFpClassify(qQNaN()), FP_NAN); + + QCOMPARE(qFpClassify(qInf()), FP_INFINITE); + QCOMPARE(qFpClassify(-qInf()), FP_INFINITE); + QCOMPARE(qFpClassify(DBL_MAX * 2.0), FP_INFINITE); + QCOMPARE(qFpClassify(FLT_MAX * 2.f), FP_INFINITE); + QCOMPARE(qFpClassify(DBL_MAX * -2.0), FP_INFINITE); + QCOMPARE(qFpClassify(FLT_MAX * -2.f), FP_INFINITE); + + QCOMPARE(qFpClassify(1.0), FP_NORMAL); + QCOMPARE(qFpClassify(DBL_MAX), FP_NORMAL); + QCOMPARE(qFpClassify(-DBL_MAX), FP_NORMAL); + QCOMPARE(qFpClassify(DBL_MIN), FP_NORMAL); + QCOMPARE(qFpClassify(-DBL_MIN), FP_NORMAL); + QCOMPARE(qFpClassify(DBL_MIN / 2.0), FP_SUBNORMAL); + QCOMPARE(qFpClassify(DBL_MIN / -2.0), FP_SUBNORMAL); + + QCOMPARE(qFpClassify(1.f), FP_NORMAL); + QCOMPARE(qFpClassify(FLT_MAX), FP_NORMAL); + QCOMPARE(qFpClassify(-FLT_MAX), FP_NORMAL); + QCOMPARE(qFpClassify(FLT_MIN), FP_NORMAL); + QCOMPARE(qFpClassify(-FLT_MIN), FP_NORMAL); + QCOMPARE(qFpClassify(FLT_MIN / 2.f), FP_SUBNORMAL); + QCOMPARE(qFpClassify(FLT_MIN / -2.f), FP_SUBNORMAL); +} + void tst_QNumeric::floatDistance_data() { QTest::addColumn("val1"); -- cgit v1.2.3 From 3c4e202fe4ada03473fc29dd36d9c8f9c0c3c6d5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 18 Mar 2019 18:30:33 +0100 Subject: Make tst_QTemporaryFile::fileTemplate() more informative on failure A QCOMPARE(..., true) isn't much use; and failure would have set the object's .errorString(), which seems like it'd be worth reporting, so use QVERIFY2() instead. Change-Id: I2f3f9379984694891de81d2ffebc696d91eec70f Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index cf4ab4902d..67d8c55b04 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -215,7 +215,7 @@ void tst_QTemporaryFile::fileTemplate() if (!fileTemplate.isEmpty()) file.setFileTemplate(fileTemplate); - QCOMPARE(file.open(), true); + QVERIFY2(file.open(), qPrintable(file.errorString())); QString fileName = QFileInfo(file).fileName(); if (prefix.length()) -- cgit v1.2.3 From c45f2eab8553a40d7185ed95b4ab3e45e95c8d70 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 20 Mar 2019 15:35:10 +0100 Subject: Silence the item model tests Introduce a logging category for the qDebug()-output. Add a meta type registration for QList, fixing numerous warnings like: WARN : tst_QItemModel::remove(QStandardItemModel:invalid start, valid count 5) QSignalSpy: Unable to handle parameter 'parents' of type 'QList' of method 'layoutChanged', use qRegisterMetaType to register it. Fix a Clang warning about potential misuse of operator , Task-number: QTBUG-73864 Change-Id: I60998403a44f5df8767926951ee13d1ed1e93c37 Reviewed-by: David Faure --- .../itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp | 5 ++++- tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp | 3 ++- .../qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp | 6 ++++-- .../qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp index 262c6dd9c8..c76052a38b 100644 --- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -32,10 +32,13 @@ #include #include #include +#include #include "dynamictreemodel.h" #include "qidentityproxymodel.h" +Q_LOGGING_CATEGORY(lcItemModels, "qt.corelib.tests.itemmodels") + class DataChangedModel : public QAbstractListModel { public: @@ -390,7 +393,7 @@ void dump(QAbstractItemModel* model, QString const& indent = " - ", QModelIndex for (auto row = 0; row < model->rowCount(parent); ++row) { auto idx = model->index(row, 0, parent); - qDebug() << (indent + idx.data().toString()); + qCDebug(lcItemModels) << (indent + idx.data().toString()); dump(model, indent + "- ", idx); } } diff --git a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp index 7cd220e684..af52852b99 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp @@ -125,6 +125,7 @@ private: tst_QItemModel::tst_QItemModel() { qRegisterMetaType(); + qRegisterMetaType>(); } void tst_QItemModel::init() @@ -181,7 +182,7 @@ void tst_QItemModel::nonDestructiveBasicTest() currentModel->hasChildren(QModelIndex()); currentModel->hasIndex(0, 0); currentModel->headerData(0, Qt::Horizontal); - currentModel->index(0,0), QModelIndex(); + currentModel->index(0,0); currentModel->itemData(QModelIndex()); QVariant cache; currentModel->match(QModelIndex(), -1, cache); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index 82cd26971b..50e87f21ac 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp @@ -38,6 +38,8 @@ #include +Q_LOGGING_CATEGORY(lcItemModels, "qt.corelib.tests.itemmodels") + // Testing get/set functions void tst_QSortFilterProxyModel::getSetCheck() { @@ -4277,7 +4279,7 @@ public: QModelIndex index(int, int, const QModelIndex& parent = QModelIndex()) const override { // QTBUG-44962: Would we always expect the parent to belong to the model - qDebug() << parent.model() << this; + qCDebug(lcItemModels) << parent.model() << this; Q_ASSERT(!parent.isValid() || parent.model() == this); quintptr parentId = (parent.isValid()) ? parent.internalId() : 0; @@ -4363,7 +4365,7 @@ void tst_QSortFilterProxyModel::sourceLayoutChangeLeavesValidPersistentIndexes() // The use of qDebug here makes sufficient use of the heap to // cause corruption at runtime with normal use on linux (before // the fix). valgrind confirms the fix. - qDebug() << persistentIndex.parent(); + qCDebug(lcItemModels) << persistentIndex.parent(); QVERIFY(persistentIndex.parent().isValid()); } diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h index 82d4b7344e..d598a60932 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h @@ -186,4 +186,6 @@ private: Q_DECLARE_METATYPE(QAbstractItemModel::LayoutChangeHint) +Q_DECLARE_LOGGING_CATEGORY(lcItemModels) + #endif // TST_QSORTFILTERPROXYMODEL_H -- cgit v1.2.3 From 758151d077536eb8fe2cd1a3252dec5619b9789f Mon Sep 17 00:00:00 2001 From: Timo Lang Date: Wed, 20 Mar 2019 09:50:51 +0100 Subject: QVariant: Fix isNull() == true after downcasting QObject* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QtCore][QVariant] Fixed a bug that caused isNull() to be true after downcasting a QObject* payload using convert(). Fixes: QTBUG-73196 Change-Id: Ifda15952f873d7142c95609b69ac424bbf16b723 Reviewed-by: Thiago Macieira Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 4da34c407e..a9162a6a6f 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2761,6 +2761,14 @@ void tst_QVariant::qvariant_cast_QObject_derived() QCOMPARE(data.value(), object); QCOMPARE(data.value(), object); } + { + QObject *object = new CustomQObjectDerivedNoMetaType(this); + QVariant data = QVariant::fromValue(object); + QVERIFY(data.canConvert()); + QVERIFY(data.convert(qMetaTypeId())); + QCOMPARE(data.value(), object); + QCOMPARE(data.isNull(), false); + } } struct QObjectWrapper -- cgit v1.2.3 From 3c4721488af0f33515911d07033d3f9981952543 Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Thu, 7 Mar 2019 17:34:16 +0200 Subject: QVector: Add assignment from std::initializer_list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I88a66e4b78ca6f40c328070f275e7163fb0d691c Reviewed-by: Ville Voutilainen Reviewed-by: Giuseppe D'Angelo Reviewed-by: Lars Knoll Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/tools/qvector/tst_qvector.cpp | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index a7faeb5ca5..2278e0ba13 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -206,6 +206,9 @@ private slots: void assignmentInt() const; void assignmentMovable() const; void assignmentCustom() const; + void assignFromInitializerListInt() const; + void assignFromInitializerListMovable() const; + void assignFromInitializerListCustom() const; void addInt() const; void addMovable() const; void addCustom() const; @@ -330,6 +333,7 @@ private: template void copyConstructor() const; template void add() const; template void append() const; + template void assignFromInitializerList() const; template void capacity() const; template void clear() const; template void count() const; @@ -542,6 +546,44 @@ void tst_QVector::assignmentCustom() const testAssignment(); } +template +void tst_QVector::assignFromInitializerList() const +{ +#ifdef Q_COMPILER_INITIALIZER_LISTS + T val1(SimpleValue::at(1)); + T val2(SimpleValue::at(2)); + T val3(SimpleValue::at(3)); + + QVector v1 = {val1, val2, val3}; + QCOMPARE(v1, QVector() << val1 << val2 << val3); + QCOMPARE(v1, (QVector {val1, val2, val3})); + + v1 = {}; + QCOMPARE(v1.size(), 0); +#else + QSKIP("This test requires support for C++11 initializer lists."); +#endif +} + +void tst_QVector::assignFromInitializerListInt() const +{ + assignFromInitializerList(); +} + +void tst_QVector::assignFromInitializerListMovable() const +{ + const int instancesCount = Movable::counter.loadAcquire(); + assignFromInitializerList(); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); +} + +void tst_QVector::assignFromInitializerListCustom() const +{ + const int instancesCount = Custom::counter.loadAcquire(); + assignFromInitializerList(); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); +} + template void tst_QVector::add() const { -- cgit v1.2.3 From 03fadc26e7617aece89949bc7d0acf50f6f050a9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 21 Mar 2019 15:07:48 +0100 Subject: Fix broken data for time-zones with no transitions While an invalid time-zone shall have no transitions, so may various constant zones, like UTC. The TZ data may include only the POSIX rule for such a zone, in which case we should use it, even if there are no transitions. Broke out a piece of repeated code as a common method, in the process, since I was complicating it further. Added test for the case that revealed this; and made sure we see a warning if any of the checkOffset() tests gets skipped because its zone is unsupported. Fixes: QTBUG-74614 Change-Id: Ic8e039a2a9b3f4e0f567585682a94f4b494b558d Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index a25fd39693..eff9835776 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -539,6 +539,8 @@ void tst_QTimeZone::checkOffset_data() int year, month, day, hour, min, sec; int std, dst; } table[] = { + // Zone with no transitions (QTBUG-74614, when TZ backend uses minimalist data) + { "Etc/UTC", "epoch", 1970, 1, 1, 0, 0, 0, 0, 0 }, // Kiev: regression test for QTBUG-64122 (on MS): { "Europe/Kiev", "summer", 2017, 10, 27, 12, 0, 0, 2 * 3600, 3600 }, { "Europe/Kiev", "winter", 2017, 10, 29, 12, 0, 0, 2 * 3600, 0 } @@ -551,6 +553,8 @@ void tst_QTimeZone::checkOffset_data() << QDateTime(QDate(entry.year, entry.month, entry.day), QTime(entry.hour, entry.min, entry.sec), zone) << entry.dst + entry.std << entry.std << entry.dst; + } else { + qWarning("Skipping %s@%s test as zone is invalid", entry.zone, entry.nick); } } } -- cgit v1.2.3 From b01248ebbd42dd05d45fa655852169978beec40e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 20 Mar 2019 11:32:53 +0100 Subject: Fix tree recursion in QAbstractItemModel::match() Recurse down the sibling at column 0 of the index instead down the index. Change-Id: Ie78d8b28eab7438ca3f83ee0df177115ca82806e Fixes: QTBUG-73864 Reviewed-by: David Faure --- .../tst_qsortfilterproxymodel.cpp | 39 ++++++++++++++++++++++ .../tst_qsortfilterproxymodel.h | 1 + 2 files changed, 40 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index 50e87f21ac..ccce5a44e5 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp @@ -2363,6 +2363,45 @@ void tst_QSortFilterProxyModel::match() QCOMPARE(indexes.at(i).row(), expectedProxyItems.at(i)); } +QList createStandardItemList(const QString &prefix, int n) +{ + QList result; + for (int i = 0; i < n; ++i) + result.append(new QStandardItem(prefix + QString::number(i))); + return result; +} + +// QTBUG-73864, recursive search in a tree model. + +void tst_QSortFilterProxyModel::matchTree() +{ + QStandardItemModel model(0, 2); + // Header00 Header01 + // Header10 Header11 + // Item00 Item01 + // Item10 Item11 + model.appendRow(createStandardItemList(QLatin1String("Header0"), 2)); + auto headerRow = createStandardItemList(QLatin1String("Header1"), 2); + model.appendRow(headerRow); + headerRow.first()->appendRow(createStandardItemList(QLatin1String("Item0"), 2)); + headerRow.first()->appendRow(createStandardItemList(QLatin1String("Item1"), 2)); + + auto item11 = model.match(model.index(1, 1), Qt::DisplayRole, QLatin1String("Item11"), 20, + Qt::MatchRecursive).value(0); + QVERIFY(item11.isValid()); + QCOMPARE(item11.data().toString(), QLatin1String("Item11")); + + // Repeat in proxy model + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + auto proxyItem11 = proxy.match(proxy.index(1, 1), Qt::DisplayRole, QLatin1String("Item11"), 20, + Qt::MatchRecursive).value(0); + QVERIFY(proxyItem11.isValid()); + QCOMPARE(proxyItem11.data().toString(), QLatin1String("Item11")); + + QCOMPARE(proxy.mapToSource(proxyItem11).internalId(), item11.internalId()); +} + void tst_QSortFilterProxyModel::insertIntoChildrenlessItem() { QStandardItemModel model; diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h index d598a60932..8ae97165b8 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h @@ -109,6 +109,7 @@ private slots: void selectionFilteredOut(); void match_data(); void match(); + void matchTree(); void insertIntoChildrenlessItem(); void invalidateMappedChildren(); void insertRowIntoFilteredParent(); -- cgit v1.2.3 From 85a9009f258e130a7bd4aaaa252724ea5fb58e79 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 15 Mar 2019 11:01:31 +0100 Subject: QPixmap: More safe failing if qApp is not a QGuiApplication It can happen that QDataStream is fed a QVariant that contains a QPixmap representation, that will make the application crash when trying to restore it This is specially important for cases in which applications expose dbus interfaces with QVariantMaps Change-Id: Ife4feaef30f30e7e27d88464bd6b2a247f743123 Reported-by: Fabian Vogt Reviewed-by: Fabian Vogt Reviewed-by: Mitch Curtis Reviewed-by: Thiago Macieira --- .../qdatastream_core_pixmap.pro | 4 ++ .../tst_qdatastream_core_pixmap.cpp | 68 ++++++++++++++++++++++ tests/auto/corelib/serialization/serialization.pro | 1 + 3 files changed, 73 insertions(+) create mode 100644 tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro create mode 100644 tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro b/tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro new file mode 100644 index 0000000000..7e003304af --- /dev/null +++ b/tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qdatastream_core_pixmap +QT += testlib +SOURCES = tst_qdatastream_core_pixmap.cpp diff --git a/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp b/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp new file mode 100644 index 0000000000..c931016a61 --- /dev/null +++ b/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_QDataStream : public QObject +{ +Q_OBJECT + +private slots: + void stream_with_pixmap(); + +}; + +void tst_QDataStream::stream_with_pixmap() +{ + // This is a QVariantMap with a 3x3 red QPixmap and two strings inside + const QByteArray ba = QByteArray::fromBase64("AAAAAwAAAAIAegAAAAoAAAAACgB0AGgAZQByAGUAAAACAHAAAABBAAAAAAGJUE5HDQoaCgAAAA1JSERSAAAAAwAAAAMIAgAAANlKIugAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAQSURBVAiZY/zPAAVMDJgsAB1bAQXZn5ieAAAAAElFTkSuQmCCAAAAAgBhAAAACgAAAAAKAGgAZQBsAGwAbw=="); + QImage dummy; // Needed to make sure qtGui is loaded + + QTest::ignoreMessage(QtWarningMsg, "QPixmap::fromImageInPlace: QPixmap cannot be created without a QGuiApplication"); + + QVariantMap map; + QDataStream d(ba); + d.setVersion(QDataStream::Qt_5_12); + d >> map; + + QCOMPARE(map["a"].toString(), QString("hello")); + QCOMPARE(map["p"].value(), QPixmap()); // the pixmap is null because this is not a QGuiApplication + QCOMPARE(map["z"].toString(), QString("there")); +} + +QTEST_GUILESS_MAIN(tst_QDataStream) + +#include "tst_qdatastream_core_pixmap.moc" + diff --git a/tests/auto/corelib/serialization/serialization.pro b/tests/auto/corelib/serialization/serialization.pro index 9187de1bc5..9638178cdc 100644 --- a/tests/auto/corelib/serialization/serialization.pro +++ b/tests/auto/corelib/serialization/serialization.pro @@ -6,6 +6,7 @@ SUBDIRS = \ qcborvalue \ qcborvalue_json \ qdatastream \ + qdatastream_core_pixmap \ qtextstream \ qxmlstream -- cgit v1.2.3 From 1e70781e7f0b012fcfbf85f86c24f3b46e362d4e Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 22 Mar 2019 11:18:14 +0100 Subject: Stabilize tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning The test is flaky which was uncovered by the upcoming QTimer::singleShot optimization patches: When the Emitter's thread is started and executes the timout functor before the state machine is started, then the state machine will never see the emitSignalWithNoArg signal and thus never transition to the final state and finish. This patch ensures that the code in the background thread is only run after the state machine was started to fix this flakyness. Change-Id: I6f91a2420165662ece75e550a6d73fe098137d4c Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Kari Oikarinen --- .../auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 810698fb4e..55a672aae1 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -6680,13 +6680,13 @@ void tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning() } emitter; initialState.addTransition(&emitter, &Emitter::signalWithNoArg, &finalState); - QTimer::singleShot(0, [&]() { - metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg"); - metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg"); - }); machine.addState(&initialState); machine.addState(&finalState); machine.setInitialState(&initialState); + connect(&machine, &QStateMachine::started, &emitter, [&]() { + metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg"); + metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg"); + }); connect(&machine, &QStateMachine::finished, &emitter.thread, &QThread::quit); machine.start(); QSignalSpy emittedSpy(&emitter, &SignalEmitter::signalWithNoArg); -- cgit v1.2.3 From 461e89ee1a53f7669e0215f9015380c4a9d62371 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 24 Oct 2018 16:49:45 +0200 Subject: Clean up QTextStream functions They are the only Qt symbols neither prefixed with q or with the Qt namespace. This changes preserves source and binary compatibility while making it possible to define conflicting symbols. Change-Id: I6d4181206e63faa922fa0c8b644e0a4b88826a97 Reviewed-by: Ulf Hermann --- .../serialization/qtextstream/tst_qtextstream.cpp | 97 +++++++++++----------- 1 file changed, 50 insertions(+), 47 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 8bb35554c8..af97d4a003 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -1102,7 +1102,7 @@ void tst_QTextStream::hexTest() QByteArray array; QTextStream stream(&array); - stream << showbase << hex << number; + stream << Qt::showbase << Qt::hex << number; stream.flush(); QCOMPARE(array, data); } @@ -1132,7 +1132,7 @@ void tst_QTextStream::binTest() QByteArray array; QTextStream stream(&array); - stream << showbase << bin << number; + stream << Qt::showbase << Qt::bin << number; stream.flush(); QCOMPARE(array.constData(), data.constData()); } @@ -1155,7 +1155,7 @@ void tst_QTextStream::octTest() QByteArray array; QTextStream stream(&array); - stream << showbase << oct << number; + stream << Qt::showbase << Qt::oct << number; stream.flush(); QCOMPARE(array, data); } @@ -1196,7 +1196,7 @@ void tst_QTextStream::ws_manipulator() QTextStream stream(&string); char a, b, c, d; - stream >> a >> ws >> b >> ws >> c >> ws >> d; + stream >> a >> Qt::ws >> b >> Qt::ws >> c >> Qt::ws >> d; QCOMPARE(a, 'a'); QCOMPARE(b, 'b'); QCOMPARE(c, 'c'); @@ -1623,18 +1623,18 @@ void tst_QTextStream::forcePoint() { QString str; QTextStream stream(&str); - stream << fixed << forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; + stream << Qt::fixed << Qt::forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; QCOMPARE(str, QString("1.000000 1 0 -1.000000 -1")); str.clear(); stream.seek(0); - stream << scientific << forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; + stream << Qt::scientific << Qt::forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; QCOMPARE(str, QString("1.000000e+00 1 0 -1.000000e+00 -1")); str.clear(); stream.seek(0); stream.setRealNumberNotation(QTextStream::SmartNotation); - stream << forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; + stream << Qt::forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; QCOMPARE(str, QString("1.00000 1 0 -1.00000 -1")); } @@ -1644,7 +1644,7 @@ void tst_QTextStream::forceSign() { QString str; QTextStream stream(&str); - stream << forcesign << 1.2 << ' ' << -1.2 << ' ' << 0; + stream << Qt::forcesign << 1.2 << ' ' << -1.2 << ' ' << 0; QCOMPARE(str, QString("+1.2 -1.2 +0")); } @@ -1663,19 +1663,22 @@ void tst_QTextStream::read0d0d0a() Q_DECLARE_METATYPE(QTextStreamFunction); +// Also tests that we can have namespaces that conflict with our QTextStream constants. +namespace ws { QTextStream &noop(QTextStream &s) { return s; } +} void tst_QTextStream::numeralCase_data() { - QTextStreamFunction noop_ = noop; - QTextStreamFunction bin_ = bin; - QTextStreamFunction oct_ = oct; - QTextStreamFunction hex_ = hex; - QTextStreamFunction base = showbase; - QTextStreamFunction ucb = uppercasebase; - QTextStreamFunction lcb = lowercasebase; - QTextStreamFunction ucd = uppercasedigits; - QTextStreamFunction lcd = lowercasedigits; + QTextStreamFunction noop_ = ws::noop; + QTextStreamFunction bin = Qt::bin; + QTextStreamFunction oct = Qt::oct; + QTextStreamFunction hex = Qt::hex; + QTextStreamFunction base = Qt::showbase; + QTextStreamFunction ucb = Qt::uppercasebase; + QTextStreamFunction lcb = Qt::lowercasebase; + QTextStreamFunction ucd = Qt::uppercasedigits; + QTextStreamFunction lcd = Qt::lowercasedigits; QTest::addColumn("func1"); QTest::addColumn("func2"); @@ -1686,30 +1689,30 @@ void tst_QTextStream::numeralCase_data() QTest::newRow("dec 1") << noop_ << noop_ << noop_ << noop_ << 31 << "31"; QTest::newRow("dec 2") << noop_ << base << noop_ << noop_ << 31 << "31"; - QTest::newRow("hex 1") << hex_ << noop_ << noop_ << noop_ << 31 << "1f"; - QTest::newRow("hex 2") << hex_ << noop_ << noop_ << lcd << 31 << "1f"; - QTest::newRow("hex 3") << hex_ << noop_ << ucb << noop_ << 31 << "1f"; - QTest::newRow("hex 4") << hex_ << noop_ << noop_ << ucd << 31 << "1F"; - QTest::newRow("hex 5") << hex_ << noop_ << lcb << ucd << 31 << "1F"; - QTest::newRow("hex 6") << hex_ << noop_ << ucb << ucd << 31 << "1F"; - QTest::newRow("hex 7") << hex_ << base << noop_ << noop_ << 31 << "0x1f"; - QTest::newRow("hex 8") << hex_ << base << lcb << lcd << 31 << "0x1f"; - QTest::newRow("hex 9") << hex_ << base << ucb << noop_ << 31 << "0X1f"; - QTest::newRow("hex 10") << hex_ << base << ucb << lcd << 31 << "0X1f"; - QTest::newRow("hex 11") << hex_ << base << noop_ << ucd << 31 << "0x1F"; - QTest::newRow("hex 12") << hex_ << base << lcb << ucd << 31 << "0x1F"; - QTest::newRow("hex 13") << hex_ << base << ucb << ucd << 31 << "0X1F"; - - QTest::newRow("bin 1") << bin_ << noop_ << noop_ << noop_ << 31 << "11111"; - QTest::newRow("bin 2") << bin_ << base << noop_ << noop_ << 31 << "0b11111"; - QTest::newRow("bin 3") << bin_ << base << lcb << noop_ << 31 << "0b11111"; - QTest::newRow("bin 4") << bin_ << base << ucb << noop_ << 31 << "0B11111"; - QTest::newRow("bin 5") << bin_ << base << noop_ << ucd << 31 << "0b11111"; - QTest::newRow("bin 6") << bin_ << base << lcb << ucd << 31 << "0b11111"; - QTest::newRow("bin 7") << bin_ << base << ucb << ucd << 31 << "0B11111"; - - QTest::newRow("oct 1") << oct_ << noop_ << noop_ << noop_ << 31 << "37"; - QTest::newRow("oct 2") << oct_ << base << noop_ << noop_ << 31 << "037"; + QTest::newRow("hex 1") << hex << noop_ << noop_ << noop_ << 31 << "1f"; + QTest::newRow("hex 2") << hex << noop_ << noop_ << lcd << 31 << "1f"; + QTest::newRow("hex 3") << hex << noop_ << ucb << noop_ << 31 << "1f"; + QTest::newRow("hex 4") << hex << noop_ << noop_ << ucd << 31 << "1F"; + QTest::newRow("hex 5") << hex << noop_ << lcb << ucd << 31 << "1F"; + QTest::newRow("hex 6") << hex << noop_ << ucb << ucd << 31 << "1F"; + QTest::newRow("hex 7") << hex << base << noop_ << noop_ << 31 << "0x1f"; + QTest::newRow("hex 8") << hex << base << lcb << lcd << 31 << "0x1f"; + QTest::newRow("hex 9") << hex << base << ucb << noop_ << 31 << "0X1f"; + QTest::newRow("hex 10") << hex << base << ucb << lcd << 31 << "0X1f"; + QTest::newRow("hex 11") << hex << base << noop_ << ucd << 31 << "0x1F"; + QTest::newRow("hex 12") << hex << base << lcb << ucd << 31 << "0x1F"; + QTest::newRow("hex 13") << hex << base << ucb << ucd << 31 << "0X1F"; + + QTest::newRow("bin 1") << bin << noop_ << noop_ << noop_ << 31 << "11111"; + QTest::newRow("bin 2") << bin << base << noop_ << noop_ << 31 << "0b11111"; + QTest::newRow("bin 3") << bin << base << lcb << noop_ << 31 << "0b11111"; + QTest::newRow("bin 4") << bin << base << ucb << noop_ << 31 << "0B11111"; + QTest::newRow("bin 5") << bin << base << noop_ << ucd << 31 << "0b11111"; + QTest::newRow("bin 6") << bin << base << lcb << ucd << 31 << "0b11111"; + QTest::newRow("bin 7") << bin << base << ucb << ucd << 31 << "0B11111"; + + QTest::newRow("oct 1") << oct << noop_ << noop_ << noop_ << 31 << "37"; + QTest::newRow("oct 2") << oct << base << noop_ << noop_ << 31 << "037"; } void tst_QTextStream::numeralCase() @@ -1782,9 +1785,9 @@ void tst_QTextStream::nanInf() QString s; QTextStream out(&s); out << qInf() << ' ' << -qInf() << ' ' << qQNaN() - << uppercasedigits << ' ' + << Qt::uppercasedigits << ' ' << qInf() << ' ' << -qInf() << ' ' << qQNaN() - << flush; + << Qt::flush; QCOMPARE(s, QString("inf -inf nan INF -INF NAN")); } @@ -1859,9 +1862,9 @@ void tst_QTextStream::writeSeekWriteNoBOM() int number = 0; QString sizeStr = QLatin1String("Size=") + QString::number(number).rightJustified(10, QLatin1Char('0')); - stream << sizeStr << endl; - stream << "Version=" << QString::number(14) << endl; - stream << "blah blah blah" << endl; + stream << sizeStr << Qt::endl; + stream << "Version=" << QString::number(14) << Qt::endl; + stream << "blah blah blah" << Qt::endl; stream.flush(); QCOMPARE(out.buffer().constData(), "Size=0000000000\nVersion=14\nblah blah blah\n"); @@ -1871,7 +1874,7 @@ void tst_QTextStream::writeSeekWriteNoBOM() stream.seek(0); sizeStr = QLatin1String("Size=") + QString::number(number).rightJustified(10, QLatin1Char('0')); - stream << sizeStr << endl; + stream << sizeStr << Qt::endl; stream.flush(); // Check buffer is still OK -- cgit v1.2.3 From 4054759aecd06313a775c8c71748ec52ca7dc27d Mon Sep 17 00:00:00 2001 From: Mikhail Svetkin Date: Fri, 8 Mar 2019 15:38:33 +0100 Subject: core: Add deduction guides for QPair [ChangeLog][QtCore] Added support of deduction guides for QPair Change-Id: I41a798390dc2c925b0f8432ba12aa345724de2d7 Reviewed-by: Martin Smith Reviewed-by: Thiago Macieira Reviewed-by: Ville Voutilainen --- tests/auto/corelib/tools/qpair/qpair.pro | 3 +++ tests/auto/corelib/tools/qpair/tst_qpair.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qpair/qpair.pro b/tests/auto/corelib/tools/qpair/qpair.pro index 659be887d3..d684a24a57 100644 --- a/tests/auto/corelib/tools/qpair/qpair.pro +++ b/tests/auto/corelib/tools/qpair/qpair.pro @@ -2,3 +2,6 @@ CONFIG += testcase TARGET = tst_qpair QT = core testlib SOURCES = tst_qpair.cpp + +# Force C++17 if available (needed due to Q_COMPILER_DEDUCTION_GUIDES) +contains(QT_CONFIG, c++1z): CONFIG += c++1z diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp index dedc353e67..3c972329bc 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -39,6 +39,7 @@ private Q_SLOTS: void testConstexpr(); void testConversions(); void taskQTBUG_48780_pairContainingCArray(); + void testDeducationRules(); }; class C { C() {} char _[4]; }; @@ -202,5 +203,30 @@ void tst_QPair::taskQTBUG_48780_pairContainingCArray() Q_UNUSED(pair); } +void tst_QPair::testDeducationRules() +{ +#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606 + QPair p1{1, 2}; + static_assert(std::is_same::value); + static_assert(std::is_same::value); + QCOMPARE(p1.first, 1); + QCOMPARE(p1.second, 2); + + QPair p2{QString("string"), 2}; + static_assert(std::is_same::value); + static_assert(std::is_same::value); + QCOMPARE(p2.first, "string"); + QCOMPARE(p2.second, 2); + + QPair p3(p2); + static_assert(std::is_same::value); + static_assert(std::is_same::value); + QCOMPARE(p3.first, "string"); + QCOMPARE(p3.second, 2); +#else + QSKIP("Unsupported"); +#endif +} + QTEST_APPLESS_MAIN(tst_QPair) #include "tst_qpair.moc" -- cgit v1.2.3 From 66e147309698d8cc5ce7da10d4cd2e1e216c3786 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 25 Mar 2019 15:29:17 +0100 Subject: Use move more consistently in QScopedValueRollback Use move on the existing value as well so the constructor makes more of a difference. Change-Id: Iee2080da7b7d2d88eb108f0448c61423c7256979 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Thiago Macieira --- .../tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp index 656dd6a6e3..9b607db608 100644 --- a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp +++ b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void rollbackToPreviousCommit(); void exceptions(); void earlyExitScope(); + void moveOnly(); private: void earlyExitScope_helper(int exitpoint, int &member); }; @@ -190,5 +191,17 @@ void tst_QScopedValueRollback::earlyExitScope_helper(int exitpoint, int& member) r.commit(); } +void tst_QScopedValueRollback::moveOnly() +{ + std::unique_ptr uniquePtr; + std::unique_ptr newVal(new int(5)); + QVERIFY(!uniquePtr); + { + QScopedValueRollback> r(uniquePtr, std::move(newVal)); + QVERIFY(uniquePtr); + } + QVERIFY(!uniquePtr); +} + QTEST_MAIN(tst_QScopedValueRollback) #include "tst_qscopedvaluerollback.moc" -- cgit v1.2.3 From 7d74404325118bb1551c38b3bae418b42db843a1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 13 Mar 2019 19:15:27 +0100 Subject: Replace a misguided test with a valid one The code had min and max of an integral type and tested min + min / 2, which naturally overflowed, provoking a compiler warning. The test was meant to be testing min - min / 2; but min is even, so this is just min / 2; and doubling that won't overflow (which is what the test is about). As it happens, min + min / 2 is in fact max - max / 2, which *would* be a good value to test, since max is odd. So add a test for that and remove the broken test. Change-Id: Iec34acbf0d5d7993d41ff844875dc10480b8eb1f Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index e567e465f7..0a84b1fdd8 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -508,13 +508,13 @@ template static void mulOverflow_template() QCOMPARE(mul_overflow(Int(max / 2), Int(3), &r), true); QCOMPARE(mul_overflow(mid1, Int(mid2 + 1), &r), true); QCOMPARE(mul_overflow(Int(max / 2 + 2), Int(2), &r), true); + QCOMPARE(mul_overflow(Int(max - max / 2), Int(2), &r), true); QCOMPARE(mul_overflow(Int(1ULL << (std::numeric_limits::digits - 1)), Int(2), &r), true); if (min) { QCOMPARE(mul_overflow(min, Int(2), &r), true); QCOMPARE(mul_overflow(Int(min / 2), Int(3), &r), true); QCOMPARE(mul_overflow(Int(min / 2 - 1), Int(2), &r), true); - QCOMPARE(mul_overflow(Int(min + min/2), Int(2), &r), true); } #endif } -- cgit v1.2.3 From 79f17db87932a6f1871e475a0610a248e941d9c2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 26 Mar 2019 15:40:26 +0100 Subject: Suppress warnings about deprecated methods in their tests Fixed the other tests that used the methods, so that they now get the data from QLocale instead; and added the missing feature #if-ery, as these are textdate methods. Change-Id: I896f356bdf88037db23590c71d0aeb0b8722bfa7 Reviewed-by: Mitch Curtis --- tests/auto/corelib/tools/qdate/tst_qdate.cpp | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp index ce1e5730dd..c17af8741b 100644 --- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp @@ -83,6 +83,7 @@ private slots: void negativeYear() const; void printNegativeYear() const; void roundtripGermanLocale() const; +#if QT_CONFIG(textdate) void shortDayName() const; void standaloneShortDayName() const; void longDayName() const; @@ -91,6 +92,7 @@ private slots: void standaloneShortMonthName() const; void longMonthName() const; void standaloneLongMonthName() const; +#endif // textdate void roundtrip() const; void qdebug() const; private: @@ -1038,18 +1040,18 @@ void tst_QDate::fromStringFormat_data() // Undo this (inline the C-locale versions) for ### Qt 6 // Get localized names: - QString january = QDate::longMonthName(1); - QString february = QDate::longMonthName(2); - QString march = QDate::longMonthName(3); - QString august = QDate::longMonthName(8); - QString mon = QDate::shortDayName(1); - QString monday = QDate::longDayName(1); - QString tuesday = QDate::longDayName(2); - QString wednesday = QDate::longDayName(3); - QString thursday = QDate::longDayName(4); - QString friday = QDate::longDayName(5); - QString saturday = QDate::longDayName(6); - QString sunday = QDate::longDayName(7); + QString january = QLocale::system().monthName(1, QLocale::LongFormat); + QString february = QLocale::system().monthName(2, QLocale::LongFormat); + QString march = QLocale::system().monthName(3, QLocale::LongFormat); + QString august = QLocale::system().monthName(8, QLocale::LongFormat); + QString mon = QLocale::system().dayName(1, QLocale::ShortFormat); + QString monday = QLocale::system().dayName(1, QLocale::LongFormat); + QString tuesday = QLocale::system().dayName(2, QLocale::LongFormat); + QString wednesday = QLocale::system().dayName(3, QLocale::LongFormat); + QString thursday = QLocale::system().dayName(4, QLocale::LongFormat); + QString friday = QLocale::system().dayName(5, QLocale::LongFormat); + QString saturday = QLocale::system().dayName(6, QLocale::LongFormat); + QString sunday = QLocale::system().dayName(7, QLocale::LongFormat); QTest::newRow("data0") << QString("") << QString("") << defDate(); QTest::newRow("data1") << QString(" ") << QString("") << invalidDate(); @@ -1305,6 +1307,10 @@ void tst_QDate::roundtripGermanLocale() const theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); } +#if QT_CONFIG(textdate) +QT_WARNING_PUSH // the methods tested here are all deprecated +QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") + void tst_QDate::shortDayName() const { QCOMPARE(QDate::shortDayName(0), QString()); @@ -1432,6 +1438,8 @@ void tst_QDate::standaloneLongMonthName() const QCOMPARE(QDate::longMonthName(i, QDate::StandaloneFormat), locale.standaloneMonthName(i, QLocale::LongFormat)); } } +QT_WARNING_POP +#endif // textdate void tst_QDate::roundtrip() const { -- cgit v1.2.3 From 6e0b5dadc7e91be786411809f1f9667c239168e2 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 9 Jan 2019 19:12:46 +0100 Subject: Change cleanup mechanism for orphaned connections Put all connections that get disconnected into a singly linked orphaned list. Whenever the refcount on the connectionData drops down to one, this list can safely be cleared, even with the planned removal of locking in activate(). Use an id integer in the connection to acoid activating newly added connections. Fixes: QTBUG-72649 Change-Id: Ide3d116ae7fc9ca497598c1c2b71d43b4339c92d Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index b823ca2aab..f51fb9bf49 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -3411,12 +3411,11 @@ void tst_QObject::disconnectSelfInSlotAndDeleteAfterEmit() void tst_QObject::dumpObjectInfo() { QObject a, b; - QObject::connect(&a, SIGNAL(destroyed(QObject*)), &b, SLOT(deleteLater())); - a.disconnect(&b); + QObject::connect(&a, &QObject::destroyed, &b, &QObject::deleteLater); QTest::ignoreMessage(QtDebugMsg, "OBJECT QObject::unnamed"); QTest::ignoreMessage(QtDebugMsg, " SIGNALS OUT"); QTest::ignoreMessage(QtDebugMsg, " signal: destroyed(QObject*)"); - QTest::ignoreMessage(QtDebugMsg, " "); + QTest::ignoreMessage(QtDebugMsg, " "); QTest::ignoreMessage(QtDebugMsg, " SIGNALS IN"); QTest::ignoreMessage(QtDebugMsg, " "); a.dumpObjectInfo(); // should not crash @@ -7575,8 +7574,6 @@ void tst_QObject::functorReferencesConnection() // top-level + the one in the 3 others lambdas QCOMPARE(countedStructObjectsCount, 4); QObject::disconnect(*c2); - // the one in the c2's lambda is gone - QCOMPARE(countedStructObjectsCount, 3); slot1Called++; }); connect(&obj, &GetSenderObject::aSignal, [] {}); // just a dummy signal to fill the connection list -- cgit v1.2.3 From a9cd08c3f398b5721483a4c443944cc90a3c3902 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 25 Mar 2019 12:34:02 +0100 Subject: Fix memory leak in auto test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2e8d8cc0f248122b06c7c8313d8effac887adaa8 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/thread/qthread/tst_qthread.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index d73dcc1b6d..f72b662c94 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -1330,6 +1330,8 @@ void tst_QThread::quitLock() QCOMPARE(job->thread(), &thread); loop.exec(); QVERIFY(exitThreadCalled); + + delete job; } void tst_QThread::create() -- cgit v1.2.3 From bab398aba3019cbc6a947bef7708c41efc807777 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 25 Mar 2019 14:50:00 +0100 Subject: Fix memory leak in auto test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie4412b8d8c67e9516225f6fe5b67afed91dcdad5 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 838431cd5a..27b49602fc 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -1322,6 +1322,7 @@ void tst_QThreadPool::waitForDoneAfterTake() QRunnable *runnable = createTask(emptyFunct); manager.start(runnable); QVERIFY(manager.tryTake(runnable)); + delete runnable; } // Add another runnable that will not be removed -- cgit v1.2.3 From f3002b6e205463305502600df95b1ae509e47a9b Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 26 Mar 2019 19:20:24 +0100 Subject: Use the QTime API less clumsily Various patterns seem to have been copied, notably counting time from QTime(0, 0) rather than using QTime::msecsSinceStartOfDay() and its setter. Unsuitable value types also put in an appearance, and QTime()'s parameters after the first two default to 0 anyway. Corrected a lie in QTime()'s default constructor doc; it does not work the same as QTime(0, 0) at all. Change-Id: Icf1a10052a049e68fd0f665958f36dbe75ac46d5 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qtime/tst_qtime.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index 3e5724213e..3403c5bf7f 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -95,8 +95,9 @@ void tst_QTime::addSecs_data() QTest::newRow("Data0") << QTime(0,0,0) << 200 << QTime(0,3,20); QTest::newRow("Data1") << QTime(0,0,0) << 20 << QTime(0,0,20); - QTest::newRow("overflow") << QTime(0,0,0) << (INT_MAX / 1000 + 1) - << QTime(0,0,0).addSecs((INT_MAX / 1000 + 1) % 86400); + QTest::newRow("overflow") + << QTime(0,0,0) << (INT_MAX / 1000 + 1) + << QTime::fromMSecsSinceStartOfDay(((INT_MAX / 1000 + 1) % 86400) * 1000); } void tst_QTime::addSecs() -- cgit v1.2.3 From 954b73445cfbfef01207d51d1b986c6dd796c6d0 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 1 Apr 2019 15:22:15 +0200 Subject: Refine underflow check in QLocaleData::convertDoubleToFloat() A string can parse as a non-zero double that's smaller than the smallest float yet be a faithful representation of the smallest float. So rather than testing for non-zero doubles less than the smallest float, test for non-zero doubles that cast to float zero; these underflow. This means small values close below the smallest float shall round up to it, rather than down to zero, requiring a tweak to an existing test. Added a test for the boundary case (and tidied the test data). Fixes: QTBUG-74833 Change-Id: I4cb30b3c0e54683574b98253505607caaf88fbfb Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 43 +++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 5d344834e6..279ee2e8a0 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -952,29 +952,42 @@ void tst_QLocale::stringToDouble() void tst_QLocale::stringToFloat_data() { + using Bounds = std::numeric_limits; toReal_data(); - if (std::numeric_limits::has_infinity) { - double huge = std::numeric_limits::infinity(); - QTest::newRow("C inf") << QString("C") << QString("inf") << true << huge; - QTest::newRow("C +inf") << QString("C") << QString("+inf") << true << +huge; - QTest::newRow("C -inf") << QString("C") << QString("-inf") << true << -huge; + const QString C(QStringLiteral("C")); + if (Bounds::has_infinity) { + double huge = Bounds::infinity(); + QTest::newRow("C inf") << C << QString("inf") << true << huge; + QTest::newRow("C +inf") << C << QString("+inf") << true << +huge; + QTest::newRow("C -inf") << C << QString("-inf") << true << -huge; // Overflow float, but not double: - QTest::newRow("C big") << QString("C") << QString("3.5e38") << false << huge; - QTest::newRow("C -big") << QString("C") << QString("-3.5e38") << false << -huge; + QTest::newRow("C big") << C << QString("3.5e38") << false << huge; + QTest::newRow("C -big") << C << QString("-3.5e38") << false << -huge; // Overflow double, too: - QTest::newRow("C huge") << QString("C") << QString("2e308") << false << huge; - QTest::newRow("C -huge") << QString("C") << QString("-2e308") << false << -huge; + QTest::newRow("C huge") << C << QString("2e308") << false << huge; + QTest::newRow("C -huge") << C << QString("-2e308") << false << -huge; } - if (std::numeric_limits::has_quiet_NaN) - QTest::newRow("C qnan") << QString("C") << QString("NaN") << true << double(std::numeric_limits::quiet_NaN()); + if (Bounds::has_quiet_NaN) + QTest::newRow("C qnan") << C << QString("NaN") << true << double(Bounds::quiet_NaN()); + + // Minimal float: shouldn't underflow + QTest::newRow("C float min") + << C << QLocale::c().toString(Bounds::denorm_min()) << true << double(Bounds::denorm_min()); + QTest::newRow("C float -min") + << C << QLocale::c().toString(-Bounds::denorm_min()) << true << -double(Bounds::denorm_min()); // Underflow float, but not double: - QTest::newRow("C small") << QString("C") << QString("1e-45") << false << 0.; - QTest::newRow("C -small") << QString("C") << QString("-1e-45") << false << 0.; + QTest::newRow("C small") << C << QString("7e-46") << false << 0.; + QTest::newRow("C -small") << C << QString("-7e-46") << false << 0.; + using Double = std::numeric_limits; + QTest::newRow("C double min") + << C << QLocale::c().toString(Double::denorm_min()) << false << 0.0; + QTest::newRow("C double -min") + << C << QLocale::c().toString(-Double::denorm_min()) << false << 0.0; // Underflow double, too: - QTest::newRow("C tiny") << QString("C") << QString("2e-324") << false << 0.; - QTest::newRow("C -tiny") << QString("C") << QString("-2e-324") << false << 0.; + QTest::newRow("C tiny") << C << QString("2e-324") << false << 0.; + QTest::newRow("C -tiny") << C << QString("-2e-324") << false << 0.; } void tst_QLocale::stringToFloat() -- cgit v1.2.3 From b5f76eeb5310211f128ff312223f641711198af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 29 Mar 2019 13:10:26 +0100 Subject: Add missing test to project file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test was never used or compiled, it has to be fine to add it :-) Change-Id: If210c19515a545a6dbaef18a16dc018c0348070d Reviewed-by: Mårten Nordheim --- tests/auto/corelib/tools/tools.pro | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index 2a975e67d1..c6da33cce0 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -46,6 +46,7 @@ SUBDIRS=\ qringbuffer \ qscopedpointer \ qscopedvaluerollback \ + qscopeguard \ qset \ qsharedpointer \ qsize \ -- cgit v1.2.3 From 90c86d738e0f36eaa48c7f81f6f5cc035a339d6b Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 4 Apr 2019 10:53:57 +0200 Subject: QCommandLineParser: warn if defining a duplicate option Fixes: QTBUG-74907 Change-Id: I3741a5241515dfaf4353458a9ef13ceaeb9fea0b Reviewed-by: Thiago Macieira --- .../tools/qcommandlineparser/tst_qcommandlineparser.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 7980f1f8f4..811e9a0010 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -44,6 +44,7 @@ private slots: // In-process tests void testInvalidOptions(); + void testDuplicateOption(); void testPositionalArguments(); void testBooleanOption_data(); void testBooleanOption(); @@ -104,6 +105,15 @@ void tst_QCommandLineParser::testInvalidOptions() QVERIFY(!parser.addOption(QCommandLineOption(QStringLiteral("-v"), QStringLiteral("Displays version information.")))); } +void tst_QCommandLineParser::testDuplicateOption() +{ + QCoreApplication app(empty_argc, empty_argv); + QCommandLineParser parser; + QVERIFY(parser.addOption(QCommandLineOption(QStringLiteral("h"), QStringLiteral("Hostname."), QStringLiteral("hostname")))); + QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: already having an option named \"h\""); + parser.addHelpOption(); +} + void tst_QCommandLineParser::testPositionalArguments() { QCoreApplication app(empty_argc, empty_argv); -- cgit v1.2.3 From 6b66108c1ffc48ee1dc06c4e25d9210bf2d41084 Mon Sep 17 00:00:00 2001 From: Paolo Dastoli Date: Sat, 16 Feb 2019 15:23:31 +0100 Subject: Add serializer/deserializer for Enumeration Enum class are serialized using the declared size. [ChangeLog][QtCore][QDataStream] Enumerations can now be serialized through QDataStream without the need of manually defining streaming operators. Change-Id: Iae9a63eb62b5a5615b657766a3c4c66ba4d98d0e Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Paolo Dastoli Reviewed-by: Thiago Macieira --- .../serialization/qdatastream/tst_qdatastream.cpp | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index d204727bbd..19cdd42a74 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -181,6 +181,8 @@ private slots: void streamRealDataTypes(); + void enumTest(); + void floatingPointPrecision(); void compatibility_Qt3(); @@ -3409,6 +3411,90 @@ void tst_QDataStream::floatingPointNaN() } } +void tst_QDataStream::enumTest() +{ + QByteArray ba; + + enum class E1 : qint8 + { + A, + B, + C + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E1::A; + QCOMPARE(ba.size(), int(sizeof(E1))); + } + { + QDataStream stream(ba); + E1 e; + stream >> e; + QCOMPARE(e, E1::A); + } + ba.clear(); + + enum class E2 : qint16 + { + A, + B, + C + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E2::B; + QCOMPARE(ba.size(), int(sizeof(E2))); + } + { + QDataStream stream(ba); + E2 e; + stream >> e; + QCOMPARE(e, E2::B); + } + ba.clear(); + + enum class E4 : qint32 + { + A, + B, + C + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E4::C; + QCOMPARE(ba.size(), int(sizeof(E4))); + } + { + QDataStream stream(ba); + E4 e; + stream >> e; + QCOMPARE(e, E4::C); + } + ba.clear(); + + + enum E + { + A, + B, + C, + D + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E::D; + QCOMPARE(ba.size(), 4); + } + { + QDataStream stream(ba); + E e; + stream >> e; + QCOMPARE(e, E::D); + } + ba.clear(); + +} + void tst_QDataStream::floatingPointPrecision() { QByteArray ba; -- cgit v1.2.3 From 82ad4be4a2e0c2bccb6cd8ea2440aefee4ec48ec Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 27 Mar 2019 17:01:40 +0000 Subject: Fix various uncommon cases in QTzTimeZonePrivate backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Includes a fixup for 03fadc26e7617aece89949bc7d0acf50f6f050a9, which removed the check on empty transition list, needed when no data are available. Ensured that such a data-free zone would in fact be noticed as invalid during init(). Fixed handling of times before the epoch (we still want to consult a POSIX rule, if that's all that's available) while ensuring we (as documented) ignore DST for such times. Fixed handling of large times (milliseconds since epoch outside int range) when looking up POSIX rules. Gave QTimeZonePrivate a YearRange enum (to be moved to QTimeZone once this merges up to dev) so as to eliminate a magic number (and avoid adding another). Moved year-munging in POSIX rules after the one early return, which doesn't need the year range. Added test-cases for the distant past/future (just checking UTC's offsets; SLES has a minimal version of the UTC data-file that triggers the bugs fixed here for them). Fixes: QTBUG-74666 Fixes: QTBUG-74550 Change-Id: Ief7b7e55c62cf11064700934f404b2fc283614e1 Reviewed-by: Tony Sarajärvi Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index eff9835776..bb6c48a2ed 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -539,8 +539,13 @@ void tst_QTimeZone::checkOffset_data() int year, month, day, hour, min, sec; int std, dst; } table[] = { - // Zone with no transitions (QTBUG-74614, when TZ backend uses minimalist data) + // Zone with no transitions (QTBUG-74614, QTBUG-74666, when TZ backend uses minimal data) { "Etc/UTC", "epoch", 1970, 1, 1, 0, 0, 0, 0, 0 }, + { "Etc/UTC", "pre_int32", 1901, 12, 13, 20, 45, 51, 0, 0 }, + { "Etc/UTC", "post_int32", 2038, 1, 19, 3, 14, 9, 0, 0 }, + { "Etc/UTC", "post_uint32", 2106, 2, 7, 6, 28, 17, 0, 0 }, + { "Etc/UTC", "initial", -292275056, 5, 16, 16, 47, 5, 0, 0 }, + { "Etc/UTC", "final", 292278994, 8, 17, 7, 12, 55, 0, 0 }, // Kiev: regression test for QTBUG-64122 (on MS): { "Europe/Kiev", "summer", 2017, 10, 27, 12, 0, 0, 2 * 3600, 3600 }, { "Europe/Kiev", "winter", 2017, 10, 29, 12, 0, 0, 2 * 3600, 0 } -- cgit v1.2.3 From 1ef274fb947f86731d062df2128718cc8a0cf643 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 2 Apr 2019 11:51:14 +0200 Subject: Replace qMove with std::move Change-Id: I67df3ae6b5db0a158f86e75b99f422bd13853bc9 Reviewed-by: Thiago Macieira Reviewed-by: Joerg Bornemann --- .../itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp | 2 +- .../corelib/thread/qatomicinteger/tst_qatomicinteger.cpp | 8 ++++---- tests/auto/corelib/tools/collections/tst_collections.cpp | 2 +- tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp | 16 ++++++++-------- .../corelib/tools/qbytearraylist/tst_qbytearraylist.cpp | 10 +++++----- .../tools/qcontiguouscache/tst_qcontiguouscache.cpp | 2 +- .../corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 4 ++-- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 16 ++++++++-------- .../corelib/tools/qversionnumber/tst_qversionnumber.cpp | 12 ++++++------ 9 files changed, 36 insertions(+), 36 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp index 0b8686560c..3919472b96 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp @@ -333,7 +333,7 @@ template C sorted(C c) { std::sort(c.begin(), c.end()); - return qMove(c); + return std::move(c); } void tst_QStringListModel::setData_emits_both_roles() diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp index 32e5b8ee56..3a98732f9d 100644 --- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp +++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp @@ -291,10 +291,10 @@ void tst_QAtomicIntegerXX::copy() QCOMPARE(copy2.load(), atomic.load()); // move - QAtomicInteger copy3(qMove(copy)); + QAtomicInteger copy3(std::move(copy)); QCOMPARE(copy3.load(), atomic.load()); - QAtomicInteger copy4 = qMove(copy2); + QAtomicInteger copy4 = std::move(copy2); QCOMPARE(copy4.load(), atomic.load()); } @@ -317,11 +317,11 @@ void tst_QAtomicIntegerXX::assign() // move QAtomicInteger copy3; - copy3 = qMove(copy); + copy3 = std::move(copy); QCOMPARE(copy3.load(), atomic.load()); QAtomicInteger copy4; - copy4 = qMove(copy2); + copy4 = std::move(copy2); QCOMPARE(copy4.load(), atomic.load()); } diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index b40b1f0624..104de4d783 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -2425,7 +2425,7 @@ void testContainer() c1 = newInstance(); QVERIFY(c1.size() == 4); QVERIFY(c1 == newInstance()); - Container c2 = qMove(c1); + Container c2 = std::move(c1); QVERIFY(c2.size() == 4); QVERIFY(c2 == newInstance()); } diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index d9e03439b8..2dbf86c2f5 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -2245,28 +2245,28 @@ void tst_QByteArray::toUpperLower() QCOMPARE(input.toLower(), lower); QByteArray copy = input; - QCOMPARE(qMove(copy).toUpper(), upper); + QCOMPARE(std::move(copy).toUpper(), upper); copy = input; copy.detach(); - QCOMPARE(qMove(copy).toUpper(), upper); + QCOMPARE(std::move(copy).toUpper(), upper); copy = input; - QCOMPARE(qMove(copy).toLower(), lower); + QCOMPARE(std::move(copy).toLower(), lower); copy = input; copy.detach(); - QCOMPARE(qMove(copy).toLower(), lower); + QCOMPARE(std::move(copy).toLower(), lower); copy = lower; - QCOMPARE(qMove(copy).toLower(), lower); + QCOMPARE(std::move(copy).toLower(), lower); copy = lower; copy.detach(); - QCOMPARE(qMove(copy).toLower(), lower); + QCOMPARE(std::move(copy).toLower(), lower); copy = upper; - QCOMPARE(qMove(copy).toUpper(), upper); + QCOMPARE(std::move(copy).toUpper(), upper); copy = upper; copy.detach(); - QCOMPARE(qMove(copy).toUpper(), upper); + QCOMPARE(std::move(copy).toUpper(), upper); } void tst_QByteArray::isUpper() diff --git a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp index 2d2c536453..a28bbc12c8 100644 --- a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp +++ b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp @@ -194,22 +194,22 @@ void tst_QByteArrayList::operator_plus() const { QByteArrayList bal1 = lhs; const QByteArrayList bal2 = rhs; - QCOMPARE(qMove(bal1) + bal2, expectedResult); + QCOMPARE(std::move(bal1) + bal2, expectedResult); } { QList lba1 = lhs; const QByteArrayList bal2 = rhs; - QCOMPARE(qMove(lba1) + bal2, expectedResult); + QCOMPARE(std::move(lba1) + bal2, expectedResult); } { QByteArrayList bal1 = lhs; const QList lba2 = rhs; - QCOMPARE(qMove(bal1) + lba2, expectedResult); + QCOMPARE(std::move(bal1) + lba2, expectedResult); } { QList lba1 = lhs; const QList lba2 = rhs; - QCOMPARE(qMove(lba1) + lba2, QList(expectedResult)); // check we don't mess with old code + QCOMPARE(std::move(lba1) + lba2, QList(expectedResult)); // check we don't mess with old code } // operator += for const lvalues @@ -232,7 +232,7 @@ void tst_QByteArrayList::operator_plus() const QByteArrayList t1 = lhs; QByteArrayList t2 = rhs; - QCOMPARE(qMove(t1) + t2, expectedResult); + QCOMPARE(std::move(t1) + t2, expectedResult); } void tst_QByteArrayList::operator_plus_data() const diff --git a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp index 31a5f93822..9b45e17a28 100644 --- a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp +++ b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp @@ -68,7 +68,7 @@ void tst_QContiguousCache::assignment() // copy: cc1 = cc2; // move: - cc1 = qMove(cc2); + cc1 = std::move(cc2); } void tst_QContiguousCache::empty() diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index ade9c5e754..ebec83403a 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -573,10 +573,10 @@ void tst_QSharedPointer::useOfForwardDeclared() // move assignment: QSharedPointer sp4; - sp4 = qMove(sp); + sp4 = std::move(sp); // and move constuction: - QSharedPointer sp5 = qMove(sp2); + QSharedPointer sp5 = std::move(sp2); // swapping: sp4.swap(sp3); diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index e25c9e8395..d891ef7e12 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -2202,12 +2202,12 @@ void tst_QString::toUpper() // call rvalue-ref while shared (the original mustn't change) QString copy = s; - QCOMPARE(qMove(copy).toUpper(), QString("GROSSSTRASSE")); + QCOMPARE(std::move(copy).toUpper(), QString("GROSSSTRASSE")); QCOMPARE(s, QString::fromUtf8("Gro\xc3\x9fstra\xc3\x9f""e")); // call rvalue-ref version on detached case copy.clear(); - QCOMPARE(qMove(s).toUpper(), QString("GROSSSTRASSE")); + QCOMPARE(std::move(s).toUpper(), QString("GROSSSTRASSE")); } QString lower, upper; @@ -2417,11 +2417,11 @@ void tst_QString::trimmed() QCOMPARE(a.trimmed(), QLatin1String("a")); a="Text"; - QCOMPARE(qMove(a).trimmed(), QLatin1String("Text")); + QCOMPARE(std::move(a).trimmed(), QLatin1String("Text")); a=" "; - QCOMPARE(qMove(a).trimmed(), QLatin1String("")); + QCOMPARE(std::move(a).trimmed(), QLatin1String("")); a=" a "; - QCOMPARE(qMove(a).trimmed(), QLatin1String("a")); + QCOMPARE(std::move(a).trimmed(), QLatin1String("a")); } void tst_QString::simplified_data() @@ -2476,13 +2476,13 @@ void tst_QString::simplified() // without detaching: QString copy1 = full; - QCOMPARE(qMove(full).simplified(), simple); + QCOMPARE(std::move(full).simplified(), simple); QCOMPARE(full, orig_full); // force a detach if (!full.isEmpty()) full[0] = full[0]; - QCOMPARE(qMove(full).simplified(), simple); + QCOMPARE(std::move(full).simplified(), simple); } void tst_QString::insert_data(bool emptyIsNoop) @@ -4524,7 +4524,7 @@ void tst_QString::toLatin1Roundtrip() // try the rvalue version of toLatin1() QString s = unicodesrc; - QCOMPARE(qMove(s).toLatin1(), latin1); + QCOMPARE(std::move(s).toLatin1(), latin1); // and verify that the moved-from object can still be used s = "foo"; diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp index 05579dce6e..aaf40a9c2e 100644 --- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp +++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp @@ -436,7 +436,7 @@ void tst_QVersionNumber::normalized() QFETCH(QVersionNumber, expected); QCOMPARE(version.normalized(), expected); - QCOMPARE(qMove(version).normalized(), expected); + QCOMPARE(std::move(version).normalized(), expected); } void tst_QVersionNumber::isNormalized_data() @@ -590,21 +590,21 @@ void tst_QVersionNumber::moveSemantics() // QVersionNumber(QVersionNumber &&) { QVersionNumber v1(1, 2, 3); - QVersionNumber v2 = qMove(v1); + QVersionNumber v2 = std::move(v1); QCOMPARE(v2, QVersionNumber(1, 2, 3)); } // QVersionNumber &operator=(QVersionNumber &&) { QVersionNumber v1(1, 2, 3); QVersionNumber v2; - v2 = qMove(v1); + v2 = std::move(v1); QCOMPARE(v2, QVersionNumber(1, 2, 3)); } // QVersionNumber(QVector &&) { QVector segments = QVector() << 1 << 2 << 3; QVersionNumber v1(segments); - QVersionNumber v2(qMove(segments)); + QVersionNumber v2(std::move(segments)); QVERIFY(!v1.isNull()); QVERIFY(!v2.isNull()); QCOMPARE(v1, v2); @@ -620,7 +620,7 @@ void tst_QVersionNumber::moveSemantics() QVERIFY(!v.isNull()); QVERIFY(!nv.isNull()); QVERIFY(nv.isNormalized()); - nv = qMove(v).normalized(); + nv = std::move(v).normalized(); QVERIFY(!nv.isNull()); QVERIFY(nv.isNormalized()); } @@ -632,7 +632,7 @@ void tst_QVersionNumber::moveSemantics() segments = v.segments(); QVERIFY(!v.isNull()); QVERIFY(!segments.empty()); - segments = qMove(v).segments(); + segments = std::move(v).segments(); QVERIFY(!segments.empty()); } #endif -- cgit v1.2.3 From 4628e5cded8b1b4f064b75f23436bc6fc66ce043 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 2 Apr 2019 11:56:33 +0200 Subject: Remove handling of missing very old compiler feature check Removes handling of missing Q_COMPILER_NULLPTR, Q_COMPILER_AUTODECL, Q_COMPILER_LAMBDA, Q_COMPILER_VARIADIC_MACROS and Q_COMPILER_AUTO_FUNCTION. We haven't supported any compilers without these for a long time. Change-Id: I3df88206516a25763e2c28b083733780f35a8764 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qlogging/tst_qlogging.cpp | 8 -------- .../corelib/io/qloggingcategory/tst_qloggingcategory.cpp | 4 ---- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 8 +++----- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 12 +----------- tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp | 6 ------ tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp | 4 ---- .../auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 6 ------ tests/auto/corelib/tools/qstring/tst_qstring.cpp | 4 ++-- 8 files changed, 6 insertions(+), 46 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index d3ed1a6d0d..f212fe6f27 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -254,19 +254,15 @@ public: int rvalue() && { ADD("TestClass1::rvalue"); return 0; } int const_rvalue() const && { ADD("TestClass1::const_rvalue"); return 0; } #endif -#ifdef Q_COMPILER_DECLTYPE int decltype_param(int x = 0, decltype(x) = 0) { ADD("TestClass1::decltype_param"); return x; } template int decltype_template_param(T x = 0, decltype(x) = 0) { ADD("TestClass1::decltype_template_param"); return x; } template void decltype_template_param2(T x, decltype(x + QString())) { ADD("TestClass1::decltype_template_param2"); } -# ifdef Q_COMPILER_AUTO_FUNCTION auto decltype_return(int x = 0) -> decltype(x) { ADD("TestClass1::decltype_return"); return x; } template auto decltype_template_return(T x = 0) -> decltype(x) { ADD("TestClass1::decltype_template_return"); return x; } -# endif -#endif public: TestClass1() @@ -323,15 +319,11 @@ public: std::move(*this).rvalue(); std::move(*this).const_rvalue(); #endif -#ifdef Q_COMPILER_DECLTYPE decltype_param(); decltype_template_param(0); decltype_template_param2(QByteArray(), QString()); -# ifdef Q_COMPILER_AUTO_FUNCTION decltype_return(); decltype_template_return(0); -# endif -#endif } }; diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp index 11a9b3f189..08635d34c5 100644 --- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp +++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp @@ -369,11 +369,9 @@ private slots: } Q_LOGGING_CATEGORY(TST_MACRO_1, "tst.macro.1") -#ifdef Q_COMPILER_VARIADIC_MACROS Q_LOGGING_CATEGORY(TST_MACRO_2, "tst.macro.2", QtDebugMsg) Q_LOGGING_CATEGORY(TST_MACRO_3, "tst.macro.3", QtFatalMsg) Q_LOGGING_CATEGORY(TST_MACRO_4, "tst.macro.4", QtInfoMsg) -#endif void QLoggingCategoryMacro() { @@ -384,7 +382,6 @@ private slots: QCOMPARE(cat1.isWarningEnabled(), true); QCOMPARE(cat1.isCriticalEnabled(), true); -#ifdef Q_COMPILER_VARIADIC_MACROS const QLoggingCategory &cat2 = TST_MACRO_2(); QCOMPARE(cat2.categoryName(), "tst.macro.2"); QCOMPARE(cat2.isDebugEnabled(), true); @@ -405,7 +402,6 @@ private slots: QCOMPARE(cat4.isInfoEnabled(), true); QCOMPARE(cat4.isWarningEnabled(), true); QCOMPARE(cat4.isCriticalEnabled(), true); -#endif } void qCDebugMacros() diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index e2bb7dab2a..28458c43c7 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1499,7 +1499,7 @@ public: typedef MyObject* MyObjectPtr; Q_DECLARE_METATYPE(MyObjectPtr) -#if defined(Q_COMPILER_VARIADIC_MACROS) && !defined(TST_QMETATYPE_BROKEN_COMPILER) +#if !defined(TST_QMETATYPE_BROKEN_COMPILER) static QByteArray createTypeName(const char *begin, const char *va) { QByteArray tn(begin); @@ -1697,7 +1697,7 @@ void tst_QMetaType::automaticTemplateRegistration() QVERIFY(qRegisterMetaType("UnregisteredTypeList") > 0); } -#if defined(Q_COMPILER_VARIADIC_MACROS) && !defined(TST_QMETATYPE_BROKEN_COMPILER) +#if !defined(TST_QMETATYPE_BROKEN_COMPILER) #define FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ F(bool) \ @@ -1776,7 +1776,7 @@ void tst_QMetaType::automaticTemplateRegistration() CREATE_AND_VERIFY_CONTAINER(QHash, void*, void*) CREATE_AND_VERIFY_CONTAINER(QHash, const void*, const void*) -#endif // Q_COMPILER_VARIADIC_MACROS +#endif // !defined(TST_QMETATYPE_BROKEN_COMPILER) #define TEST_OWNING_SMARTPOINTER(SMARTPOINTER, ELEMENT_TYPE, FLAG_TEST, FROMVARIANTFUNCTION) \ { \ @@ -2565,9 +2565,7 @@ Q_DECLARE_METATYPE(UndefinedFunction0); Q_DECLARE_METATYPE(UndefinedFunction1); Q_DECLARE_METATYPE(UndefinedFunction2); Q_DECLARE_METATYPE(UndefinedFunction3); -#ifdef Q_COMPILER_VARIADIC_TEMPLATES Q_DECLARE_METATYPE(UndefinedFunction4); -#endif QTEST_MAIN(tst_QMetaType) #include "tst_qmetatype.moc" diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index f51fb9bf49..4a27b5bffe 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6029,7 +6029,6 @@ void tst_QObject::connectFunctorArgDifference() QStringListModel model; connect(&model, &QStringListModel::rowsInserted, SlotFunctor()); -#if defined(Q_COMPILER_LAMBDA) connect(&timer, &QTimer::timeout, [=](){}); connect(&timer, &QTimer::objectNameChanged, [=](const QString &){}); connect(qApp, &QCoreApplication::aboutToQuit, [=](){}); @@ -6037,7 +6036,6 @@ void tst_QObject::connectFunctorArgDifference() connect(&timer, &QTimer::objectNameChanged, [=](){}); connect(&model, &QStringListModel::rowsInserted, [=](){}); connect(&model, &QStringListModel::rowsInserted, [=](const QModelIndex &){}); -#endif QVERIFY(true); } @@ -6075,7 +6073,6 @@ void tst_QObject::connectFunctorQueued() e.exec(); QCOMPARE(status, 2); -#if defined(Q_COMPILER_LAMBDA) status = 1; connect(&obj, &SenderObject::signal1, this, [&status] { status = 2; }, Qt::QueuedConnection); @@ -6083,7 +6080,6 @@ void tst_QObject::connectFunctorQueued() QCOMPARE(status, 1); e.exec(); QCOMPARE(status, 2); -#endif } void tst_QObject::connectFunctorWithContext() @@ -6117,7 +6113,6 @@ void tst_QObject::connectFunctorWithContext() e.exec(); QCOMPARE(status, 2); -#if defined(Q_COMPILER_LAMBDA) status = 1; connect(&obj, &SenderObject::signal1, this, [this, &status, &obj] { status = 2; QCOMPARE(sender(), &obj); }, Qt::QueuedConnection); @@ -6125,7 +6120,6 @@ void tst_QObject::connectFunctorWithContext() QCOMPARE(status, 1); e.exec(); QCOMPARE(status, 2); -#endif // Free context->deleteLater(); @@ -6435,7 +6429,7 @@ void connectFunctorOverload_impl(Signal signal, int expOverload, QList void tst_QObject::connectFunctorOverloads() { -#if defined (Q_COMPILER_DECLTYPE) && defined (Q_COMPILER_VARIADIC_TEMPLATES) +#if defined (Q_COMPILER_VARIADIC_TEMPLATES) connectFunctorOverload_impl(&FunctorArgDifferenceObject::signal_ii, 1, (QList() << 1 << 2)); connectFunctorOverload_impl(&FunctorArgDifferenceObject::signal_iiS, 1, @@ -6609,7 +6603,6 @@ void tst_QObject::disconnectDoesNotLeakFunctor() } QCOMPARE(countedStructObjectsCount, 0); { -#if defined(Q_COMPILER_LAMBDA) CountedStruct s; QCOMPARE(countedStructObjectsCount, 1); QTimer timer; @@ -6619,7 +6612,6 @@ void tst_QObject::disconnectDoesNotLeakFunctor() QCOMPARE(countedStructObjectsCount, 2); QVERIFY(QObject::disconnect(c)); QCOMPARE(countedStructObjectsCount, 1); -#endif // Q_COMPILER_LAMBDA } QCOMPARE(countedStructObjectsCount, 0); } @@ -6667,7 +6659,6 @@ void tst_QObject::contextDoesNotLeakFunctor() } QCOMPARE(countedStructObjectsCount, 0); { -#if defined(Q_COMPILER_LAMBDA) CountedStruct s; QEventLoop e; ContextObject *context = new ContextObject; @@ -6680,7 +6671,6 @@ void tst_QObject::contextDoesNotLeakFunctor() context->deleteLater(); e.exec(); QCOMPARE(countedStructObjectsCount, 1); -#endif // Q_COMPILER_LAMBDA } QCOMPARE(countedStructObjectsCount, 0); } diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index a00c962510..2d1ae07b35 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -78,9 +78,7 @@ private slots: void fromRawData_data(); void fromRawData(); void literals(); -#if defined(Q_COMPILER_VARIADIC_MACROS) && defined(Q_COMPILER_LAMBDA) void variadicLiterals(); -#endif #ifdef Q_COMPILER_RVALUE_REFS void rValueReferences(); #endif @@ -1618,9 +1616,7 @@ void tst_QArrayData::literals() QCOMPARE(v.size(), size_t(11)); // v.capacity() is unspecified, for now -#if defined(Q_COMPILER_VARIADIC_MACROS) && defined(Q_COMPILER_LAMBDA) QVERIFY(v.isStatic()); -#endif #if !defined(QT_NO_UNSHARABLE_CONTAINERS) QVERIFY(v.isSharable()); @@ -1633,7 +1629,6 @@ void tst_QArrayData::literals() } } -#if defined(Q_COMPILER_VARIADIC_MACROS) && defined(Q_COMPILER_LAMBDA) // Variadic Q_ARRAY_LITERAL need to be available in the current configuration. void tst_QArrayData::variadicLiterals() { @@ -1682,7 +1677,6 @@ void tst_QArrayData::variadicLiterals() QCOMPARE(const_(v)[i], i); } } -#endif #ifdef Q_COMPILER_RVALUE_REFS // std::remove_reference is in C++11, but requires library support diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 2dbf86c2f5..987b3058e3 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -138,9 +138,7 @@ private slots: void reserveExtended(); void movablity_data(); void movablity(); -#if defined(Q_COMPILER_LAMBDA) void literals(); -#endif void toUpperLower_data(); void toUpperLower(); void isUpper(); @@ -2192,7 +2190,6 @@ void tst_QByteArray::movablity() QVERIFY(true); } -#if defined(Q_COMPILER_LAMBDA) // Only tested on c++0x compliant compiler or gcc void tst_QByteArray::literals() { @@ -2213,7 +2210,6 @@ void tst_QByteArray::literals() QVERIFY(str2.constData() == s); QVERIFY(str2.data() != s); } -#endif void tst_QByteArray::toUpperLower_data() { diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index ebec83403a..19b2aa02f3 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -89,9 +89,7 @@ private slots: #endif void constCorrectness(); void customDeleter(); -#ifdef Q_COMPILER_LAMBDA void lambdaCustomDeleter(); -#endif void creating(); void creatingCvQualified(); void creatingVariadic(); @@ -1670,7 +1668,6 @@ void tst_QSharedPointer::customDeleter() safetyCheck(); } -#ifdef Q_COMPILER_LAMBDA // The compiler needs to be in C++11 mode and to support lambdas void tst_QSharedPointer::lambdaCustomDeleter() { @@ -1698,7 +1695,6 @@ void tst_QSharedPointer::lambdaCustomDeleter() } safetyCheck(); } -#endif void customQObjectDeleterFn(QObject *obj) { @@ -2233,11 +2229,9 @@ void tst_QSharedPointer::invalidConstructs_data() << &QTest::QExternalTest::tryCompileFail << "struct IncompatibleCustomDeleter { void operator()(int *); };\n" "QSharedPointer ptr(new Data, IncompatibleCustomDeleter());\n"; -#ifdef Q_COMPILER_LAMBDA QTest::newRow("incompatible-custom-lambda-deleter") << &QTest::QExternalTest::tryCompileFail << "QSharedPointer ptr(new Data, [](int *) {});\n"; -#endif } void tst_QSharedPointer::invalidConstructs() diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index d891ef7e12..79f5a8c46d 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -578,7 +578,7 @@ private slots: #ifdef QT_USE_ICU void toUpperLower_icu(); #endif -#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA) +#if !defined(QT_NO_UNICODE_LITERAL) void literals(); #endif void eightBitLiterals_data(); @@ -6621,7 +6621,7 @@ void tst_QString::toUpperLower_icu() } #endif -#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA) +#if !defined(QT_NO_UNICODE_LITERAL) // Only tested on c++0x compliant compiler or gcc void tst_QString::literals() { -- cgit v1.2.3 From 5c90a9699871006d51fdd83bd38c8c8ea5dfa26e Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 2 Apr 2019 13:07:05 +0200 Subject: Remove handling of missing Q_COMPILER_CLASS_ENUM Change-Id: I1fd6d601e49e803b4c3308fb0ca41136c628afbc Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qflags/tst_qflags.cpp | 6 ------ tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 20 +++++--------------- 2 files changed, 5 insertions(+), 21 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 72b086350e..8265d21350 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -142,7 +142,6 @@ void tst_QFlags::signedness() std::is_signed::value)); } -#if defined(Q_COMPILER_CLASS_ENUM) enum class MyStrictEnum { StrictZero, StrictOne, StrictTwo, StrictFour=4 }; Q_DECLARE_FLAGS( MyStrictFlags, MyStrictEnum ) Q_DECLARE_OPERATORS_FOR_FLAGS( MyStrictFlags ) @@ -154,11 +153,9 @@ Q_STATIC_ASSERT( !QTypeInfo::isComplex ); Q_STATIC_ASSERT( !QTypeInfo::isStatic ); Q_STATIC_ASSERT( !QTypeInfo::isLarge ); Q_STATIC_ASSERT( !QTypeInfo::isPointer ); -#endif void tst_QFlags::classEnum() { -#if defined(Q_COMPILER_CLASS_ENUM) // The main aim of the test is making sure it compiles // The QCOMPARE are there as an extra MyStrictEnum e1 = MyStrictEnum::StrictOne; @@ -257,7 +254,6 @@ void tst_QFlags::classEnum() // Just to make sure it compiles if (false) qDebug() << f3; -#endif } void tst_QFlags::initializerLists() @@ -268,12 +264,10 @@ void tst_QFlags::initializerLists() QVERIFY(bts.testFlag(Qt::RightButton)); QVERIFY(!bts.testFlag(Qt::MiddleButton)); -#if defined(Q_COMPILER_CLASS_ENUM) MyStrictNoOpFlags flags = { MyStrictNoOpEnum::StrictOne, MyStrictNoOpEnum::StrictFour }; QVERIFY(flags.testFlag(MyStrictNoOpEnum::StrictOne)); QVERIFY(flags.testFlag(MyStrictNoOpEnum::StrictFour)); QVERIFY(!flags.testFlag(MyStrictNoOpEnum::StrictTwo)); -#endif // Q_COMPILER_CLASS_ENUM #else QSKIP("This test requires C++11 initializer_list support."); diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index a9162a6a6f..6ae8fd0010 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -59,12 +59,6 @@ class CustomNonQObject; -#if defined(Q_COMPILER_CLASS_ENUM) -#define ENUM_SIZE(X) : X -#else -#define ENUM_SIZE(X) -#endif - class tst_QVariant : public QObject { Q_OBJECT @@ -82,15 +76,15 @@ public: enum MetaEnumTest_Enum1 : qint64 { MetaEnumTest_Enum1_value = 42, MetaEnumTest_Enum1_bigValue = (Q_INT64_C(1) << 33) + 50 }; Q_ENUM(MetaEnumTest_Enum1) - enum MetaEnumTest_Enum3 ENUM_SIZE(qint64) { MetaEnumTest_Enum3_value = -47, MetaEnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5, MetaEnumTest_Enum3_bigNegValue = -(Q_INT64_C(1) << 56) - 3 }; + enum MetaEnumTest_Enum3 : qint64 { MetaEnumTest_Enum3_value = -47, MetaEnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5, MetaEnumTest_Enum3_bigNegValue = -(Q_INT64_C(1) << 56) - 3 }; Q_ENUM(MetaEnumTest_Enum3) - enum MetaEnumTest_Enum4 ENUM_SIZE(quint64) { MetaEnumTest_Enum4_value = 47, MetaEnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 }; + enum MetaEnumTest_Enum4 : quint64 { MetaEnumTest_Enum4_value = 47, MetaEnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 }; Q_ENUM(MetaEnumTest_Enum4) - enum MetaEnumTest_Enum5 ENUM_SIZE(uint) { MetaEnumTest_Enum5_value = 47 }; + enum MetaEnumTest_Enum5 : uint { MetaEnumTest_Enum5_value = 47 }; Q_ENUM(MetaEnumTest_Enum5) - enum MetaEnumTest_Enum6 ENUM_SIZE(uchar) { MetaEnumTest_Enum6_value = 47 }; + enum MetaEnumTest_Enum6 : uchar { MetaEnumTest_Enum6_value = 47 }; Q_ENUM(MetaEnumTest_Enum6) - enum MetaEnumTest_Enum8 ENUM_SIZE(short) { MetaEnumTest_Enum8_value = 47 }; + enum MetaEnumTest_Enum8 : short { MetaEnumTest_Enum8_value = 47 }; Q_ENUM(MetaEnumTest_Enum8) private slots: @@ -4700,7 +4694,6 @@ Q_DECLARE_METATYPE(EnumTest_Enum0) enum EnumTest_Enum1 : qint64 { EnumTest_Enum1_value = 42, EnumTest_Enum1_bigValue = (Q_INT64_C(1) << 33) + 50 }; Q_DECLARE_METATYPE(EnumTest_Enum1) -#if defined(Q_COMPILER_CLASS_ENUM) enum EnumTest_Enum3 : qint64 { EnumTest_Enum3_value = -47, EnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5 }; Q_DECLARE_METATYPE(EnumTest_Enum3) enum EnumTest_Enum4 : quint64 { EnumTest_Enum4_value = 47, EnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 }; @@ -4713,7 +4706,6 @@ enum class EnumTest_Enum7 { EnumTest_Enum7_value = 47, ensureSignedEnum7 = -1 }; Q_DECLARE_METATYPE(EnumTest_Enum7) enum EnumTest_Enum8 : short { EnumTest_Enum8_value = 47 }; Q_DECLARE_METATYPE(EnumTest_Enum8) -#endif template void testVariant(Enum value, bool *ok) { @@ -4772,7 +4764,6 @@ void tst_QVariant::enums() QVERIFY(ok); testVariant(EnumTest_Enum1_bigValue, &ok); QVERIFY(ok); -#if defined(Q_COMPILER_CLASS_ENUM) testVariant(EnumTest_Enum3::EnumTest_Enum3_value, &ok); QVERIFY(ok); testVariant(EnumTest_Enum3::EnumTest_Enum3_bigValue, &ok); @@ -4791,7 +4782,6 @@ void tst_QVariant::enums() QVERIFY(ok); testVariant(EnumTest_Enum3::EnumTest_Enum3_value, &ok); QVERIFY(ok); -#endif } template void testVariantMeta(Enum value, bool *ok, const char *string) -- cgit v1.2.3 From 946d868619fe19c494fd2b7bb6694b29e17203d1 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 20 Nov 2018 21:55:13 +0100 Subject: QEasyingCurve: fix data stream operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now, QEasingCurve was not streaming all it's internal state. Therefore, doing store/reload operation through QDataStream would not yield the same curve as the original. This patch fixes it. [ChangeLog][QtCore][QEasingCurve] QEasingCurve now properly streams all the data needed to QDataStream. Change-Id: I1619501f5b4237983c8c68e148745a5e58863f55 Fixes: QTBUG-68181 Reviewed-by: Jan Arve Sæther --- .../tools/qeasingcurve/tst_qeasingcurve.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp index 0196dd2d23..c21d0afacb 100644 --- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp +++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp @@ -55,6 +55,8 @@ private slots: void testCbrtFloat(); void cpp11(); void quadraticEquation(); + void streamInOut_data(); + void streamInOut(); }; void tst_QEasingCurve::type() @@ -879,5 +881,36 @@ void tst_QEasingCurve::quadraticEquation() { } } +void tst_QEasingCurve::streamInOut_data() +{ + QTest::addColumn("version"); + QTest::addColumn("equality"); + + QTest::newRow("5.11") << int(QDataStream::Qt_5_11) << false; + QTest::newRow("5.13") << int(QDataStream::Qt_5_13) << true; +} + +void tst_QEasingCurve::streamInOut() +{ + QFETCH(int, version); + QFETCH(bool, equality); + + QEasingCurve orig; + orig.addCubicBezierSegment(QPointF(0.43, 0.0025), QPointF(0.38, 0.51), QPointF(0.57, 0.99)); + + QEasingCurve copy; + + QByteArray data; + QDataStream dsw(&data,QIODevice::WriteOnly); + QDataStream dsr(&data,QIODevice::ReadOnly); + + dsw.setVersion(version); + dsr.setVersion(version); + dsw << orig; + dsr >> copy; + + QCOMPARE(copy == orig, equality); +} + QTEST_MAIN(tst_QEasingCurve) #include "tst_qeasingcurve.moc" -- cgit v1.2.3 From 58b4e0736919e0504f5ca5307ad7aefa894a6f38 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 11 Jan 2018 17:46:24 +0100 Subject: Optimize QTimer::singleShot(0, ...) when taking PMF or Functor callable QTimer::singleShot is optimized for zero timeouts when using the API taking a string method name. This optimization was not used for the API taking a PMF or functor. This patch adds it, making the various API calls behave similarly from a performance point of view. The approach taken here requires a QObject context object. If none is available, e.g. a nullptr was passed explicitly, or the QTimer::singleShot(O, Functor) API was used, the optimization could not easily be applied. This is not only bad from a performance POV, but also poses as a potential source for heisenbugs: Using the different API versions of QTimer::singleShot would use different code paths internally, which then would not ensure the expected slot call order. This problem actually existed already when mixing the string-based slot syntax with PMF/functors in the QTimer::singleShot API. This patch overcomes this hurdle and fixes all of the above: When we encounter a 0ms single shot timer, and no QObject context object is available, we fall back to the main thread, or create a temporary QObject for any other thread. The updated and extended benchmark shows that this is still a significant performance improvement over using a timer: ********* Start testing of qtimer_vs_qmetaobject ********* Config: Using QtTest library 5.14.0, Qt 5.14.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 8.2.1 20181127) PASS : qtimer_vs_qmetaobject::initTestCase() PASS : qtimer_vs_qmetaobject::bench(singleShot_slot) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_slot": 7.48 msecs per iteration (total: 748, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(singleShot_pmf) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_pmf": 7.20 msecs per iteration (total: 720, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(singleShot_functor) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_functor": 6.79 msecs per iteration (total: 679, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(singleShot_functor_noctx) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_functor_noctx": 6.92 msecs per iteration (total: 693, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(invokeMethod_string) RESULT : qtimer_vs_qmetaobject::bench():"invokeMethod_string": 7.34 msecs per iteration (total: 735, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(invokeMethod_pmf) RESULT : qtimer_vs_qmetaobject::bench():"invokeMethod_pmf": 6.90 msecs per iteration (total: 690, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(invokeMethod_functor) RESULT : qtimer_vs_qmetaobject::bench():"invokeMethod_functor": 6.62 msecs per iteration (total: 662, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_slot) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_slot": 7.45 msecs per iteration (total: 745, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_pmf) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_pmf": 7.46 msecs per iteration (total: 747, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_functor) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_functor": 6.70 msecs per iteration (total: 671, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_functor_noctx) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_functor_noctx": 13.75 msecs per iteration (total: 1,376, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(invokeMethod_string) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"invokeMethod_string": 7.05 msecs per iteration (total: 706, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(invokeMethod_pmf) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"invokeMethod_pmf": 6.70 msecs per iteration (total: 670, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(invokeMethod_functor) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"invokeMethod_functor": 6.58 msecs per iteration (total: 658, iterations: 100) PASS : qtimer_vs_qmetaobject::cleanupTestCase() Totals: 16 passed, 0 failed, 0 skipped, 0 blacklisted, 20977ms ********* Finished testing of qtimer_vs_qmetaobject ********* Without the change to qtimer.cpp, the results are: ********* Start testing of qtimer_vs_qmetaobject ********* Config: Using QtTest library 5.14.0, Qt 5.14.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 8.2.1 20181127) PASS : qtimer_vs_qmetaobject::initTestCase() PASS : qtimer_vs_qmetaobject::bench(singleShot_slot) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_slot": 7.45 msecs per iteration (total: 745, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(singleShot_pmf) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_pmf": 112.84 msecs per iteration (total: 11,285, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(singleShot_functor) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_functor": 115.62 msecs per iteration (total: 11,563, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(singleShot_functor_noctx) RESULT : qtimer_vs_qmetaobject::bench():"singleShot_functor_noctx": 110.81 msecs per iteration (total: 11,082, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(invokeMethod_string) RESULT : qtimer_vs_qmetaobject::bench():"invokeMethod_string": 7.04 msecs per iteration (total: 704, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(invokeMethod_pmf) RESULT : qtimer_vs_qmetaobject::bench():"invokeMethod_pmf": 6.62 msecs per iteration (total: 662, iterations: 100) PASS : qtimer_vs_qmetaobject::bench(invokeMethod_functor) RESULT : qtimer_vs_qmetaobject::bench():"invokeMethod_functor": 6.62 msecs per iteration (total: 662, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_slot) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_slot": 7.45 msecs per iteration (total: 746, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_pmf) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_pmf": 118.42 msecs per iteration (total: 11,842, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_functor) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_functor": 119.35 msecs per iteration (total: 11,936, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(singleShot_functor_noctx) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"singleShot_functor_noctx": 130.96 msecs per iteration (total: 13,096, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(invokeMethod_string) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"invokeMethod_string": 8.08 msecs per iteration (total: 808, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(invokeMethod_pmf) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"invokeMethod_pmf": 6.79 msecs per iteration (total: 680, iterations: 100) PASS : qtimer_vs_qmetaobject::benchBackgroundThread(invokeMethod_functor) RESULT : qtimer_vs_qmetaobject::benchBackgroundThread():"invokeMethod_functor": 7.49 msecs per iteration (total: 749, iterations: 100) PASS : qtimer_vs_qmetaobject::cleanupTestCase() Totals: 16 passed, 0 failed, 0 skipped, 0 blacklisted, 153995ms ********* Finished testing of qtimer_vs_qmetaobject ********* Additionally, this patch adds a unit test to verify that the slot call order for 0ms single shot timers is followed while mixing the various API versions. It fails without this patch but passes now. Finally, another test is added to verify that using QTimer::singleShot before a QCoreApplication was constructed is still working properly. Change-Id: I0d6211554b6198cb3e527be9ec3adc572b1b54ee Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 123 +++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 3b10547dc4..d06059bbe5 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -73,7 +73,12 @@ private slots: void recurseOnTimeoutAndStopTimer(); void singleShotToFunctors(); void singleShot_chrono(); + void singleShot_static(); void crossThreadSingleShotToFunctor(); + void timerOrder(); + void timerOrder_data(); + void timerOrderBackgroundThread(); + void timerOrderBackgroundThread_data() { timerOrder_data(); } void dontBlockEvents(); void postedEventsShouldNotStarveTimers(); @@ -1033,5 +1038,121 @@ void tst_QTimer::callOnTimeout() QVERIFY(!connection); } -QTEST_MAIN(tst_QTimer) +class OrderHelper : public QObject +{ + Q_OBJECT +public: + enum CallType + { + String, + PMF, + Functor, + FunctorNoCtx + }; + Q_ENUM(CallType) + QVector calls; + + void triggerCall(CallType callType) + { + switch (callType) + { + case String: + QTimer::singleShot(0, this, SLOT(stringSlot())); + break; + case PMF: + QTimer::singleShot(0, this, &OrderHelper::pmfSlot); + break; + case Functor: + QTimer::singleShot(0, this, [this]() { functorSlot(); }); + break; + case FunctorNoCtx: + QTimer::singleShot(0, [this]() { functorNoCtxSlot(); }); + break; + } + } + +public slots: + void stringSlot() { calls << String; } + void pmfSlot() { calls << PMF; } + void functorSlot() { calls << Functor; } + void functorNoCtxSlot() { calls << FunctorNoCtx; } +}; + +Q_DECLARE_METATYPE(OrderHelper::CallType) + +void tst_QTimer::timerOrder() +{ + QFETCH(QVector, calls); + + OrderHelper helper; + + for (const auto call : calls) + helper.triggerCall(call); + + QTRY_COMPARE(helper.calls, calls); +} + +void tst_QTimer::timerOrder_data() +{ + QTest::addColumn>("calls"); + + QVector calls = { + OrderHelper::String, OrderHelper::PMF, + OrderHelper::Functor, OrderHelper::FunctorNoCtx + }; + std::sort(calls.begin(), calls.end()); + + int permutation = 0; + do { + QTest::addRow("permutation=%d", permutation) << calls; + ++permutation; + } while (std::next_permutation(calls.begin(), calls.end())); +} + +void tst_QTimer::timerOrderBackgroundThread() +{ +#if !QT_CONFIG(cxx11_future) + QSKIP("This test requires QThread::create"); +#else + auto *thread = QThread::create([this]() { timerOrder(); }); + thread->start(); + QVERIFY(thread->wait()); + delete thread; +#endif +} + +struct StaticSingleShotUser +{ + StaticSingleShotUser() + { + for (auto call : calls()) + helper.triggerCall(call); + } + OrderHelper helper; + + static QVector calls() + { + return {OrderHelper::String, OrderHelper::PMF, + OrderHelper::Functor, OrderHelper::FunctorNoCtx}; + } +}; + +static StaticSingleShotUser *s_staticSingleShotUser = nullptr; + +void tst_QTimer::singleShot_static() +{ + QCoreApplication::processEvents(); + QCOMPARE(s_staticSingleShotUser->helper.calls, s_staticSingleShotUser->calls()); +} + +// NOTE: to prevent any static initialization order fiasco, we handle QTEST_MAIN +// ourselves, but instantiate the staticSingleShotUser before qApp + +int main(int argc, char *argv[]) +{ + StaticSingleShotUser staticSingleShotUser; + s_staticSingleShotUser = &staticSingleShotUser; + QTEST_MAIN_IMPL(tst_QTimer) +} + #include "tst_qtimer.moc" -- cgit v1.2.3 From f7949df24319cda7363aed354ca6d60dc6512788 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 8 Apr 2019 09:58:08 +0200 Subject: tst_QUrl: Fix left-over temporary directory on Windows The test changes the current directory to the test directory in fromUserInputWithCwd(), but did not restore it, causing: Totals 898 passed, 0 failed, 1 skipped, 0 blacklisted, 368ms ********* Finished testing of tst_QUrl ********* QTemporaryDir Unable to remove "C:\\TEMP\\tst_qurl-ryVxqu" most likely due to the presence of read-only files. Restore the old directory at the end to fix this. Change-Id: I62669868f3c6d97dd38ebac76515428c14b7e1e7 Reviewed-by: David Faure --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 4f173d2dfd..d697dae9dd 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -47,6 +47,7 @@ class tst_QUrl : public QObject private slots: void initTestCase(); + void cleanupTestCase(); void effectiveTLDs_data(); void effectiveTLDs(); void getSetCheck(); @@ -188,6 +189,7 @@ private slots: private: void testThreadingHelper(); + const QString m_currentPath = QDir::currentPath(); QTemporaryDir m_tempDir; }; @@ -196,6 +198,12 @@ void tst_QUrl::initTestCase() QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString())); } +void tst_QUrl::cleanupTestCase() +{ + // Restore working directory changed in fromUserInputWithCwd() + QDir::setCurrent(m_currentPath); +} + // Testing get/set functions void tst_QUrl::getSetCheck() { -- cgit v1.2.3 From 95f787bfdc890c259e8b347bdad9123d534efe0f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 9 Apr 2019 13:33:15 +0200 Subject: Replace Q_DECL_NOTHROW with noexcept the remaining places The first replacement had missed objective-C++ code some places ourside the src dir. In C-files Q_DECL_NOTHROW is replaced with Q_DECL_NOEXCEPT as we still need to turn it off when compiled in C mode, but can get rid of the old NOTHROW moniker. Change-Id: I6370f57066679c5120d0265a69e7e378e09d4759 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qglobal/qglobal.c | 2 +- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 22 +++++++++++----------- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 2 +- .../serialization/qxmlstream/tst_qxmlstream.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qglobal/qglobal.c b/tests/auto/corelib/global/qglobal/qglobal.c index 0719c4b921..c7124454d0 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.c +++ b/tests/auto/corelib/global/qglobal/qglobal.c @@ -85,7 +85,7 @@ int tst_QtVersion() return QT_VERSION; } -const char *tst_qVersion() Q_DECL_NOTHROW +const char *tst_qVersion() Q_DECL_NOEXCEPT { #if !defined(QT_NAMESPACE) return qVersion(); diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 4a27b5bffe..e0394a5d25 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -4794,13 +4794,13 @@ class LotsOfSignalsAndSlots: public QObject public slots: void slot_v() {} - void slot_v_noexcept() Q_DECL_NOTHROW {} + void slot_v_noexcept() noexcept {} void slot_vi(int) {} - void slot_vi_noexcept() Q_DECL_NOTHROW {} + void slot_vi_noexcept() noexcept {} void slot_vii(int, int) {} void slot_viii(int, int, int) {} int slot_i() { return 0; } - int slot_i_noexcept() Q_DECL_NOTHROW { return 0; } + int slot_i_noexcept() noexcept { return 0; } int slot_ii(int) { return 0; } int slot_iii(int, int) { return 0; } int slot_iiii(int, int, int) { return 0; } @@ -4814,18 +4814,18 @@ class LotsOfSignalsAndSlots: public QObject void slot_vPFvvE(fptr) {} void const_slot_v() const {}; - void const_slot_v_noexcept() const Q_DECL_NOTHROW {} + void const_slot_v_noexcept() const noexcept {} void const_slot_vi(int) const {}; - void const_slot_vi_noexcept(int) const Q_DECL_NOTHROW {} + void const_slot_vi_noexcept(int) const noexcept {} static void static_slot_v() {} - static void static_slot_v_noexcept() Q_DECL_NOTHROW {} + static void static_slot_v_noexcept() noexcept {} static void static_slot_vi(int) {} - static void static_slot_vi_noexcept(int) Q_DECL_NOTHROW {} + static void static_slot_vi_noexcept(int) noexcept {} static void static_slot_vii(int, int) {} static void static_slot_viii(int, int, int) {} static int static_slot_i() { return 0; } - static int static_slot_i_noexcept() Q_DECL_NOTHROW { return 0; } + static int static_slot_i_noexcept() noexcept { return 0; } static int static_slot_ii(int) { return 0; } static int static_slot_iii(int, int) { return 0; } static int static_slot_iiii(int, int, int) { return 0; } @@ -4988,11 +4988,11 @@ void tst_QObject::connectCxx0xTypeMatching() } -void receiverFunction_noexcept() Q_DECL_NOTHROW {} -struct Functor_noexcept { void operator()() Q_DECL_NOTHROW {} }; +void receiverFunction_noexcept() noexcept {} +struct Functor_noexcept { void operator()() noexcept {} }; void tst_QObject::connectCxx17Noexcept() { - // this is about connecting signals to slots with the Q_DECL_NOTHROW qualifier + // this is about connecting signals to slots with the noexcept qualifier // as semantics changed due to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html typedef LotsOfSignalsAndSlots Foo; Foo obj; diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index d06059bbe5..b7c87418c7 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -773,7 +773,7 @@ public: quitEventLoop_noexcept(); } - static void quitEventLoop_noexcept() Q_DECL_NOTHROW + static void quitEventLoop_noexcept() noexcept { QVERIFY(!_e.isNull()); _e->quit(); diff --git a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp index 8fdf91b090..e4d50607b7 100644 --- a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp @@ -253,7 +253,7 @@ public: qFatal("%s: aId must not be an empty string", Q_FUNC_INFO); } - void swap(MissedBaseline &other) Q_DECL_NOTHROW + void swap(MissedBaseline &other) noexcept { qSwap(id, other.id); qSwap(expected, other.expected); -- cgit v1.2.3 From 5f2afe18ccb0bbe258d4016ef65218cd3656cac2 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Tue, 9 Apr 2019 13:38:06 +0200 Subject: Fix QMetaObject::newInstance on non-QObject meta object QMetaObject::newInstance returns a QObject, thus it's not possible to create a new instance of a Q_GADGET using this function. Previously, we returned a non-null QObject pointer for such scenarios, which then leads to crashes when one tries to use it. Now, we check whether the meta object inherits QObject's meta object, and error out early otherwise. Change-Id: I7b1fb6c8d48b3e98161894be2f281a491963345e Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 9855bec520..cfe1443fd3 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -40,6 +40,13 @@ struct MyStruct int i; }; +class MyGadget +{ + Q_GADGET +public: + Q_INVOKABLE MyGadget() {} +}; + namespace MyNamespace { // Used in tst_QMetaObject::checkScope class MyClass : public QObject @@ -1207,6 +1214,12 @@ void tst_QMetaObject::invokeMetaConstructor() QCOMPARE(obj2->parent(), (QObject*)&obj); QVERIFY(qobject_cast(obj2) != 0); } + // gadget shouldn't return a valid pointer + { + QCOMPARE(MyGadget::staticMetaObject.constructorCount(), 1); + QTest::ignoreMessage(QtWarningMsg, "QMetaObject::newInstance: type MyGadget does not inherit QObject"); + QVERIFY(!MyGadget::staticMetaObject.newInstance()); + } } void tst_QMetaObject::invokeTypedefTypes() -- cgit v1.2.3