From d3a4230757931a704f36dd1eb4917a5ce61f80b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 12 Feb 2013 12:32:29 +0100 Subject: Make QVector instances counter thread safe Change-Id: I7c7aa1eb0f8e91c43023882a3734e908be4ba4fe Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qvector/tst_qvector.cpp | 201 ++++++++++++----------- 1 file changed, 101 insertions(+), 100 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 7c1e22689e..c5ed44b952 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include +#include #include struct Movable { @@ -47,21 +48,21 @@ struct Movable { : i(input) , state(Constructed) { - ++counter; + counter.fetchAndAddRelaxed(1); } Movable(const Movable &other) : i(other.i) , state(Constructed) { check(other.state, Constructed); - ++counter; + counter.fetchAndAddRelaxed(1); } ~Movable() { check(state, Constructed); i = 0; - --counter; + counter.fetchAndAddRelaxed(-1); state = Destructed; } @@ -80,7 +81,7 @@ struct Movable { return *this; } char i; - static int counter; + static QAtomicInt counter; private: enum State { Constructed = 106, Destructed = 110 }; State state; @@ -91,7 +92,7 @@ private: } }; -int Movable::counter = 0; +QAtomicInt Movable::counter = 0; QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE); QT_END_NAMESPACE @@ -103,21 +104,21 @@ struct Custom { , that(this) , state(Constructed) { - ++counter; + counter.fetchAndAddRelaxed(1); } Custom(const Custom &other) : that(this) , state(Constructed) { check(&other); - ++counter; + counter.fetchAndAddRelaxed(1); this->i = other.i; } ~Custom() { check(this); i = 0; - --counter; + counter.fetchAndAddRelaxed(-1); state = Destructed; } @@ -135,7 +136,7 @@ struct Custom { i = other.i; return *this; } - static int counter; + static QAtomicInt counter; char i; // used to identify orgin of an instance private: @@ -151,7 +152,7 @@ private: QCOMPARE(c->state, Constructed); } }; -int Custom::counter = 0; +QAtomicInt Custom::counter = 0; Q_DECLARE_METATYPE(Custom); @@ -415,16 +416,16 @@ void tst_QVector::copyConstructorInt() const void tst_QVector::copyConstructorMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); copyConstructor(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::copyConstructorCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); copyConstructor(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -465,16 +466,16 @@ void tst_QVector::addInt() const void tst_QVector::addMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); add(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::addCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); add(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -523,16 +524,16 @@ void tst_QVector::appendInt() const void tst_QVector::appendMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); append(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::appendCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); append(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::at() const @@ -602,16 +603,16 @@ void tst_QVector::capacityInt() const void tst_QVector::capacityMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); capacity(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::capacityCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); capacity(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -633,16 +634,16 @@ void tst_QVector::clearInt() const void tst_QVector::clearMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); clear(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::clearCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); clear(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::constData() const @@ -717,16 +718,16 @@ void tst_QVector::countInt() const void tst_QVector::countMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); count(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::countCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); count(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::data() const @@ -771,16 +772,16 @@ void tst_QVector::emptyInt() const void tst_QVector::emptyMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); empty(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::emptyCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); empty(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::endsWith() const @@ -826,16 +827,16 @@ void tst_QVector::eraseEmptyInt() const void tst_QVector::eraseEmptyMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); eraseEmpty(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::eraseEmptyCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); eraseEmpty(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -863,16 +864,16 @@ void tst_QVector::eraseEmptyReservedInt() const void tst_QVector::eraseEmptyReservedMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); eraseEmptyReserved(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::eraseEmptyReservedCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); eraseEmptyReserved(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -986,30 +987,30 @@ void tst_QVector::eraseIntShared() const void tst_QVector::eraseMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); erase(false); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::eraseMovableShared() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); erase(true); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::eraseCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); erase(false); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::eraseCustomShared() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); erase(true); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template void tst_QVector::eraseReserved() const @@ -1062,16 +1063,16 @@ void tst_QVector::eraseReservedInt() const void tst_QVector::eraseReservedMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); eraseReserved(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::eraseReservedCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); eraseReserved(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -1102,16 +1103,16 @@ void tst_QVector::fillInt() const void tst_QVector::fillMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); fill(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::fillCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); fill(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::first() const @@ -1152,16 +1153,16 @@ void tst_QVector::fromListInt() const void tst_QVector::fromListMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); fromList(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::fromListCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); fromList(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::fromStdVector() const @@ -1338,16 +1339,16 @@ void tst_QVector::prependInt() const void tst_QVector::prependMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); prepend(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::prependCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); prepend(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -1374,16 +1375,16 @@ void tst_QVector::removeInt() const void tst_QVector::removeMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); remove(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::removeCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); remove(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::resizePOD_data() const @@ -1510,7 +1511,7 @@ void tst_QVector::resizeComplexMovable_data() const void tst_QVector::resizeComplexMovable() const { - const int items = Movable::counter; + const int items = Movable::counter.loadAcquire(); { QFETCH(QVector, vector); QFETCH(int, size); @@ -1529,7 +1530,7 @@ void tst_QVector::resizeComplexMovable() const QCOMPARE(vector.size(), 0); QVERIFY(vector.capacity() <= capacity); } - QCOMPARE(items, Movable::counter); + QCOMPARE(items, Movable::counter.loadAcquire()); } void tst_QVector::resizeComplex_data() const @@ -1585,7 +1586,7 @@ void tst_QVector::resizeComplex_data() const void tst_QVector::resizeComplex() const { - const int items = Custom::counter; + const int items = Custom::counter.loadAcquire(); { QFETCH(QVector, vector); QFETCH(int, size); @@ -1604,12 +1605,12 @@ void tst_QVector::resizeComplex() const QVERIFY(vector.isEmpty()); QVERIFY(vector.capacity() <= capacity); } - QCOMPARE(Custom::counter, items); + QCOMPARE(Custom::counter.loadAcquire(), items); } void tst_QVector::resizeCtorAndDtor() const { - const int items = Custom::counter; + const int items = Custom::counter.loadAcquire(); { QVector null; QVector empty(0, '0'); @@ -1631,7 +1632,7 @@ void tst_QVector::resizeCtorAndDtor() const nonEmpty.resize(0); nonEmptyReserved.resize(2); } - QCOMPARE(Custom::counter, items); + QCOMPARE(Custom::counter.loadAcquire(), items); } template @@ -1661,16 +1662,16 @@ void tst_QVector::sizeInt() const void tst_QVector::sizeMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); size(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::sizeCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); size(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } // ::squeeze() is tested in ::capacity(). @@ -1720,16 +1721,16 @@ void tst_QVector::swapInt() const void tst_QVector::swapMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); swap(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::swapCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); swap(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::toList() const @@ -1947,16 +1948,16 @@ void tst_QVector::initializeListInt() void tst_QVector::initializeListMovable() { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); initializeList(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::initializeListCustom() { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); initializeList(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } void tst_QVector::const_shared_null() @@ -2084,16 +2085,16 @@ void tst_QVector::setSharableInt() void tst_QVector::setSharableMovable() { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); setSharable(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::setSharableCustom() { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); setSharable(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } template @@ -2200,16 +2201,16 @@ void tst_QVector::detachInt() const void tst_QVector::detachMovable() const { - const int instancesCount = Movable::counter; + const int instancesCount = Movable::counter.loadAcquire(); detach(); - QCOMPARE(instancesCount, Movable::counter); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); } void tst_QVector::detachCustom() const { - const int instancesCount = Custom::counter; + const int instancesCount = Custom::counter.loadAcquire(); detach(); - QCOMPARE(instancesCount, Custom::counter); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } QTEST_APPLESS_MAIN(tst_QVector) -- cgit v1.2.3 From dacc222d5a3327fb27d69e57d99111cdf9084304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 12 Feb 2013 14:08:48 +0100 Subject: Fix QVector detaching in one thread while another destroys it. The patch adds handling for a case when a QVector is shared between two threads. In such scenario detaching in one thread could collide with destruction in the other one, causing a memory leak or assert in debug mode. Task-number: QTBUG-29134 Change-Id: Idbff250d9cfc6cf83174954ea91dbf41f8ea4aa4 Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qvector/tst_qvector.cpp | 78 +++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index c5ed44b952..7738a2c797 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -41,6 +41,8 @@ #include #include +#include +#include #include struct Movable { @@ -272,6 +274,9 @@ private slots: void detachInt() const; void detachMovable() const; void detachCustom() const; + void detachThreadSafetyInt() const; + void detachThreadSafetyMovable() const; + void detachThreadSafetyCustom() const; private: template void copyConstructor() const; @@ -295,6 +300,7 @@ private: template void setSharable_data() const; template void setSharable() const; template void detach() const; + template void detachThreadSafety() const; }; @@ -2213,5 +2219,75 @@ void tst_QVector::detachCustom() const QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } -QTEST_APPLESS_MAIN(tst_QVector) +static QAtomicPointer > detachThreadSafetyDataInt; +static QAtomicPointer > detachThreadSafetyDataMovable; +static QAtomicPointer > detachThreadSafetyDataCustom; + +template QAtomicPointer > *detachThreadSafetyData(); +template<> QAtomicPointer > *detachThreadSafetyData() { return &detachThreadSafetyDataInt; } +template<> QAtomicPointer > *detachThreadSafetyData() { return &detachThreadSafetyDataMovable; } +template<> QAtomicPointer > *detachThreadSafetyData() { return &detachThreadSafetyDataCustom; } + +static QSemaphore detachThreadSafetyLock; + +template +void tst_QVector::detachThreadSafety() const +{ + delete detachThreadSafetyData()->fetchAndStoreOrdered(new QVector(SimpleValue::vector(400))); + + static const uint threadsCount = 5; + + struct : QThread { + void run() Q_DECL_OVERRIDE + { + QVector copy(*detachThreadSafetyData()->load()); + QVERIFY(!copy.isDetached()); + detachThreadSafetyLock.release(); + detachThreadSafetyLock.acquire(100); + copy.detach(); + } + } threads[threadsCount]; + + for (uint i = 0; i < threadsCount; ++i) + threads[i].start(); + QThread::yieldCurrentThread(); + detachThreadSafetyLock.acquire(threadsCount); + + // destroy static original data + delete detachThreadSafetyData()->fetchAndStoreOrdered(0); + + QVERIFY(threadsCount < 100); + detachThreadSafetyLock.release(threadsCount * 100); + QThread::yieldCurrentThread(); + + for (uint i = 0; i < threadsCount; ++i) + threads[i].wait(); +} + +void tst_QVector::detachThreadSafetyInt() const +{ + for (uint i = 0; i < 128; ++i) + detachThreadSafety(); +} + +void tst_QVector::detachThreadSafetyMovable() const +{ + const int instancesCount = Movable::counter.loadAcquire(); + for (uint i = 0; i < 128; ++i) { + detachThreadSafety(); + QCOMPARE(Movable::counter.loadAcquire(), instancesCount); + } +} + +void tst_QVector::detachThreadSafetyCustom() const +{ + const int instancesCount = Custom::counter.loadAcquire(); + for (uint i = 0; i < 128; ++i) { + detachThreadSafety(); + QCOMPARE(Custom::counter.loadAcquire(), instancesCount); + } +} + + +QTEST_MAIN(tst_QVector) #include "tst_qvector.moc" -- cgit v1.2.3 From 70f6652ebd7153b4a381c30756e3e76fc3cab562 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 19 Feb 2013 23:51:31 +0100 Subject: Forward the 3rd parameter of dataChanged Change-Id: I94f893bf65cd150c3cb1099c91cb13882bcca79a Reviewed-by: Stephen Kelly --- .../tst_qidentityproxymodel.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp index c7e4664007..f750b7a9d4 100644 --- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -46,6 +46,20 @@ #include "dynamictreemodel.h" #include "qidentityproxymodel.h" +class DataChangedModel : public QAbstractListModel +{ +public: + int rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : 1; } + QVariant data(const QModelIndex&, int) const { return QVariant(); } + QModelIndex index(int row, int column, const QModelIndex &) const { return createIndex(row, column); } + + void changeData() + { + const QModelIndex idx = index(0, 0, QModelIndex()); + Q_EMIT dataChanged(idx, idx, QVector() << 1); + } +}; + class tst_QIdentityProxyModel : public QObject { Q_OBJECT @@ -63,6 +77,7 @@ private slots: void removeRows(); void moveRows(); void reset(); + void dataChanged(); protected: void verifyIdentity(QAbstractItemModel *model, const QModelIndex &parent = QModelIndex()); @@ -79,6 +94,7 @@ tst_QIdentityProxyModel::tst_QIdentityProxyModel() void tst_QIdentityProxyModel::initTestCase() { + qRegisterMetaType >(); m_model = new QStandardItemModel(0, 1); m_proxy = new QIdentityProxyModel(); } @@ -326,5 +342,27 @@ void tst_QIdentityProxyModel::reset() m_proxy->setSourceModel(0); } +void tst_QIdentityProxyModel::dataChanged() +{ + DataChangedModel model; + m_proxy->setSourceModel(&model); + + verifyIdentity(&model); + + QSignalSpy modelSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); + QSignalSpy proxySpy(m_proxy, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); + + QVERIFY(modelSpy.isValid()); + QVERIFY(proxySpy.isValid()); + + model.changeData(); + + QCOMPARE(modelSpy.first().at(2).value >(), QVector() << 1); + QVERIFY(modelSpy.first().at(2) == proxySpy.first().at(2)); + + verifyIdentity(&model); + m_proxy->setSourceModel(0); +} + QTEST_MAIN(tst_QIdentityProxyModel) #include "tst_qidentityproxymodel.moc" -- cgit v1.2.3 From b05f19f23217ebf982f021c71a04b1df73827c35 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 19 Feb 2013 16:56:30 +0100 Subject: moc: Fix infinite recursion in macro substitution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When performing macro argument substitution, one should keep the set of macro to exclude, else we can enter an infinite recursion. Testcase: #define M1(A) A #define M2 M1(M2) Task-number: QTBUG-29759 Change-Id: I564bbfed65e1c8599592eaf12c6d67285d2fd9ce Reviewed-by: Simon Hausmann Reviewed-by: Jędrzej Nowacki --- tests/auto/tools/moc/parse-defines.h | 5 +++++ tests/auto/tools/moc/tst_moc.cpp | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/tools/moc/parse-defines.h b/tests/auto/tools/moc/parse-defines.h index 3e5841835d..f12899e368 100644 --- a/tests/auto/tools/moc/parse-defines.h +++ b/tests/auto/tools/moc/parse-defines.h @@ -76,6 +76,9 @@ #endif +#define PD_ADD_SUFFIX(x) PD_DEFINE1(x,_SUFFIX) +#define PD_DEFINE_ITSELF PD_ADD_SUFFIX(PD_DEFINE_ITSELF) + PD_BEGIN_NAMESPACE class PD_CLASSNAME : public QObject @@ -128,6 +131,8 @@ public slots: void conditionSlot() {} #endif + void PD_DEFINE_ITSELF(int) {} + }; #undef QString diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index f0d1934a93..ee82dc0652 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -2772,7 +2772,6 @@ void tst_Moc::parseDefines() } if (!qstrcmp(mci.name(), "TestString2")) { ++count; - qDebug() << mci.value(); QVERIFY(!qstrcmp(mci.value(), "ParseDefine")); } if (!qstrcmp(mci.name(), "TestString3")) { @@ -2781,6 +2780,9 @@ void tst_Moc::parseDefines() } } QVERIFY(count == 3); + + index = mo->indexOfSlot("PD_DEFINE_ITSELF_SUFFIX(int)"); + QVERIFY(index != -1); } void tst_Moc::preprocessorOnly() -- cgit v1.2.3 From 7477d50fce9a0008ff4e050285e146ebc0c1e163 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 19 Feb 2013 20:00:28 +0100 Subject: Populate the cmake variables only one time. Since we're only including the Extras file one time, invoking set() for the include dirs again will overwrite the addition of include dirs in the extras file. We only need to populate these variables if not set anyway, so do that. Change-Id: I04dad0674778e79c8c12c18231b8ce6c92edf881 Reviewed-by: Alexander Neundorf Reviewed-by: Stephen Kelly --- .../test_multiple_find_package/CMakeLists.txt | 4 ++ .../auto/cmake/test_multiple_find_package/main.cpp | 47 ++++++++++++++++++++++ .../subdir1/CMakeLists.txt | 3 ++ 3 files changed, 54 insertions(+) create mode 100644 tests/auto/cmake/test_multiple_find_package/main.cpp (limited to 'tests') diff --git a/tests/auto/cmake/test_multiple_find_package/CMakeLists.txt b/tests/auto/cmake/test_multiple_find_package/CMakeLists.txt index dfac4ca3be..c0fdfd6b9a 100644 --- a/tests/auto/cmake/test_multiple_find_package/CMakeLists.txt +++ b/tests/auto/cmake/test_multiple_find_package/CMakeLists.txt @@ -5,5 +5,9 @@ project(test_multiple_find_package) find_package(Qt5Core REQUIRED) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + add_subdirectory(subdir1) +add_executable(exe1 "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp") +include_directories(${Qt5Core_INCLUDE_DIRS}) diff --git a/tests/auto/cmake/test_multiple_find_package/main.cpp b/tests/auto/cmake/test_multiple_find_package/main.cpp new file mode 100644 index 0000000000..82f1109395 --- /dev/null +++ b/tests/auto/cmake/test_multiple_find_package/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int,char**) +{ + return 0; +} diff --git a/tests/auto/cmake/test_multiple_find_package/subdir1/CMakeLists.txt b/tests/auto/cmake/test_multiple_find_package/subdir1/CMakeLists.txt index 86c05f5de5..0c7a113f50 100644 --- a/tests/auto/cmake/test_multiple_find_package/subdir1/CMakeLists.txt +++ b/tests/auto/cmake/test_multiple_find_package/subdir1/CMakeLists.txt @@ -1,2 +1,5 @@ find_package(Qt5Core REQUIRED) + +add_executable(exe2 "${CMAKE_CURRENT_SOURCE_DIR}/../main.cpp") +include_directories(${Qt5Core_INCLUDE_DIRS}) -- cgit v1.2.3 From 153d613353863987322db81f3c31e33541ef7226 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 10 Dec 2012 14:48:19 +0100 Subject: Transient QWindows centered; default-constructed geometry Default-constructed geometry does not mean put the window at 0,0, and it does not mean center the window on the screen: it means let the window manager position the window. If the window is explicitly positioned at 0,0 though, that is a higher priority than the transient hint; without this change, the transientFor property had no effect. On X11, transient means use center "gravity" to make the transient window exactly centered. But the user can still override the geometry of a transient window, as with any window. On OSX and Windows, neither transient window functionality nor smart initial positioning are provided, so a window with no position set will be centered on the screen, and a transient window will be put at the center of its transientParent. Change-Id: I4f5e37480eef5d105e45ffd60362a57f13ec55f5 Task-number: QTBUG-26903 Reviewed-by: Gunnar Sletta --- tests/auto/opengl/qgl/tst_qgl.cpp | 8 ++++++-- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 2 +- tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/opengl/qgl/tst_qgl.cpp b/tests/auto/opengl/qgl/tst_qgl.cpp index 6c5c90d737..3bae5d5103 100644 --- a/tests/auto/opengl/qgl/tst_qgl.cpp +++ b/tests/auto/opengl/qgl/tst_qgl.cpp @@ -78,7 +78,6 @@ private slots: void shareRegister(); void textureCleanup(); #endif - void graphicsViewClipping(); void partialGLWidgetUpdates_data(); void partialGLWidgetUpdates(); void glWidgetWithAlpha(); @@ -98,6 +97,7 @@ private slots: void destroyFBOAfterContext(); void threadImages(); void nullRectCrash(); + void graphicsViewClipping(); }; tst_QGL::tst_QGL() @@ -865,7 +865,11 @@ void tst_QGL::graphicsViewClipping() scene.setSceneRect(view.viewport()->rect()); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + #ifdef Q_OS_MAC + // The black rectangle jumps from the center to the upper left for some reason. + QTest::qWait(100); + #endif QImage image = viewport->grabFrameBuffer(); QImage expected = image; diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index c1927c9d1f..78fce7661e 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -5430,7 +5430,7 @@ void tst_QWidget::setToolTip() QScopedPointer popup(new QWidget(0, Qt::Popup)); popup->setObjectName(QString::fromLatin1("tst_qwidget setToolTip #%1").arg(pass)); popup->setWindowTitle(popup->objectName()); - popup->resize(150, 50); + popup->setGeometry(50, 50, 150, 50); QFrame *frame = new QFrame(popup.data()); frame->setGeometry(0, 0, 50, 50); frame->setFrameStyle(QFrame::Box | QFrame::Plain); diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 210e52f0aa..3fa669c1fb 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3902,6 +3902,11 @@ void tst_QLineEdit::inputMethod() // removing focus allows input method to commit preedit testWidget->setText(""); testWidget->activateWindow(); + // TODO setFocus should not be necessary here, because activateWindow + // should focus it, and the window is the QLineEdit. But the test can fail + // on Windows if we don't do this. If each test had a unique QLineEdit + // instance, maybe such problems would go away. + testWidget->setFocus(); QTRY_VERIFY(testWidget->hasFocus()); QTRY_COMPARE(qApp->focusObject(), testWidget); -- cgit v1.2.3 From fa5bd4ed981f107339194905dc3197a5e52eab3f Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 29 Oct 2012 19:32:47 +0100 Subject: Added transient window manual test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I05e657488bb05e1aa6343270946512c8793f1e68 Reviewed-by: Samuel Rødal --- tests/manual/transientwindow/main.cpp | 51 ++++++++++++++++++ tests/manual/transientwindow/mainwindow.cpp | 66 ++++++++++++++++++++++++ tests/manual/transientwindow/mainwindow.h | 64 +++++++++++++++++++++++ tests/manual/transientwindow/transientwindow.pro | 6 +++ 4 files changed, 187 insertions(+) create mode 100644 tests/manual/transientwindow/main.cpp create mode 100644 tests/manual/transientwindow/mainwindow.cpp create mode 100644 tests/manual/transientwindow/mainwindow.h create mode 100644 tests/manual/transientwindow/transientwindow.pro (limited to 'tests') diff --git a/tests/manual/transientwindow/main.cpp b/tests/manual/transientwindow/main.cpp new file mode 100644 index 0000000000..aebb051688 --- /dev/null +++ b/tests/manual/transientwindow/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/tests/manual/transientwindow/mainwindow.cpp b/tests/manual/transientwindow/mainwindow.cpp new file mode 100644 index 0000000000..25123c4936 --- /dev/null +++ b/tests/manual/transientwindow/mainwindow.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "mainwindow.h" +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), m_showButton("Toggle visible", this), m_window(0) +{ + connect(&m_showButton, SIGNAL(clicked()), this, SLOT(toggleVisible())); + setWindowTitle(QString::fromLatin1("Main Window")); + m_showButton.setVisible(true); + setMinimumSize(300, 200); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::toggleVisible() +{ + if (!m_window) { + m_window = new QWindow(); + m_window->setTransientParent(windowHandle()); + m_window->setMinimumSize(QSize(200, 100)); + m_window->setTitle("Transient Window"); + } + m_window->setVisible(!m_window->isVisible()); +} diff --git a/tests/manual/transientwindow/mainwindow.h b/tests/manual/transientwindow/mainwindow.h new file mode 100644 index 0000000000..352fc961e1 --- /dev/null +++ b/tests/manual/transientwindow/mainwindow.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); + +public slots: + void toggleVisible(); + +private: + QPushButton m_showButton; + QWindow* m_window; +}; + +#endif // MAINWINDOW_H diff --git a/tests/manual/transientwindow/transientwindow.pro b/tests/manual/transientwindow/transientwindow.pro new file mode 100644 index 0000000000..a07ee09dbc --- /dev/null +++ b/tests/manual/transientwindow/transientwindow.pro @@ -0,0 +1,6 @@ +QT += core gui widgets +TARGET = transientwindow +TEMPLATE = app +SOURCES += main.cpp\ + mainwindow.cpp +HEADERS += mainwindow.h -- cgit v1.2.3 From faefc09e93f99b86820ca50495351825059dc3c9 Mon Sep 17 00:00:00 2001 From: Fabian Bumberger Date: Thu, 21 Feb 2013 18:57:51 +0100 Subject: Fix qfile autotest on qnx This fixes the compilation of the qfile autotest on qnx. Change-Id: Iab099e8b754a4341152e338ff6e3d22a83c625e3 Reviewed-by: Thomas McGuire --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index df7b397481..6fa222dd72 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -82,6 +82,12 @@ QT_END_NAMESPACE # include #endif +#ifdef Q_OS_QNX +#ifdef open +#undef open +#endif +#endif + #include #include -- cgit v1.2.3 From f136701bc50b63b90281856c2ab5953a40f4b868 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 21 Feb 2013 00:01:30 +0100 Subject: Use the base implementation of QAbstractItemModel::sibling in QSIM. QStandardItemModel doesn't really benefit from a reimplementation of sibling, and the current implementation is buggy. Task-number: 29540 Change-Id: Icf8dca29b6e1394a378db5bf6abd884f2d7fd9b9 Reviewed-by: Olivier Goffart --- tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp index 5fb8df3f59..085dfd0461 100644 --- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp +++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp @@ -718,6 +718,8 @@ void tst_QStandardItemModel::checkChildren() QVERIFY(!model.hasChildren()); QCOMPARE(model.rowCount(), 0); QCOMPARE(model.columnCount(), 1); + + QVERIFY(!model.index(0,0).sibling(100,100).isValid()); } void tst_QStandardItemModel::data() -- cgit v1.2.3 From cd1e24587709d09c22256dede900629743cf6b6b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 26 Feb 2013 11:05:26 +0100 Subject: QStandardPaths: Use forward slash consistently. Task-number: QTBUG-29249 Change-Id: I027f9ae18544dc47e1378214244487c8a5ae704c Reviewed-by: Frederik Gladhorn Reviewed-by: Thiago Macieira --- .../auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index c4453fd5f2..f94c8eac4f 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #ifdef Q_OS_UNIX #include @@ -72,6 +73,7 @@ private slots: void testCustomRuntimeDirectory(); void testAllWritableLocations_data(); void testAllWritableLocations(); + void testCleanPath(); private: #ifdef Q_XDG_PLATFORM @@ -430,6 +432,18 @@ void tst_qstandardpaths::testAllWritableLocations() QCOMPARE(loc.endsWith(QLatin1Char('/')), false); } +void tst_qstandardpaths::testCleanPath() +{ + const QRegExp filter(QStringLiteral("\\\\")); + QVERIFY(filter.isValid()); + for (int i = 0; i <= QStandardPaths::GenericCacheLocation; ++i) { + const QStringList paths = QStandardPaths::standardLocations(QStandardPaths::StandardLocation(i)); + QVERIFY2(paths.filter(filter).isEmpty(), + qPrintable(QString::fromLatin1("Backslash found in %1 %2") + .arg(i).arg(paths.join(QLatin1Char(','))))); + } +} + QTEST_MAIN(tst_qstandardpaths) #include "tst_qstandardpaths.moc" -- cgit v1.2.3 From 7867f03f8a26f94c6e6e4386a28fddb875d29e36 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 27 Feb 2013 09:46:27 +0100 Subject: Stabilize tst_qprogressbar. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Wait for shown to ensure events are processed. - Move away from screen corners/potential task bar areas. Change-Id: I2c3aa9b675c6b33ca0da67ee99cc6f76c502098a Reviewed-by: Samuel Rødal --- tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp index 5ad9aa7690..0696aa11d2 100644 --- a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp @@ -113,7 +113,9 @@ void tst_QProgressBar::minMaxSameValue() QProgressBar bar; bar.setRange(10, 10); bar.setValue(10); + bar.move(300, 300); bar.show(); + QVERIFY(QTest::qWaitForWindowExposed(&bar)); } void tst_QProgressBar::destroyIndeterminate() @@ -123,7 +125,9 @@ void tst_QProgressBar::destroyIndeterminate() // it's deleted. QPointer bar = new QProgressBar; bar->setMaximum(0); + bar->move(300, 300); bar->show(); + QVERIFY(QTest::qWaitForWindowExposed(bar.data())); QEventLoop loop; QTimer::singleShot(500, bar, SLOT(deleteLater())); @@ -166,8 +170,10 @@ void tst_QProgressBar::format() ProgressBar bar; bar.setRange(0, 10); bar.setValue(1); + bar.move(300, 300); bar.show(); QVERIFY(QTest::qWaitForWindowExposed(&bar)); + QVERIFY(QTest::qWaitForWindowExposed(&bar)); QTest::qWait(20); bar.repainted = false; @@ -202,6 +208,7 @@ void tst_QProgressBar::setValueRepaint() pbar.setMinimum(0); pbar.setMaximum(10); pbar.setFormat("%v"); + pbar.move(300, 300); pbar.show(); QVERIFY(QTest::qWaitForWindowExposed(&pbar)); @@ -224,7 +231,9 @@ void tst_QProgressBar::setMinMaxRepaint() pbar.setMinimum(0); pbar.setMaximum(10); pbar.setFormat("%v"); + pbar.move(300, 300); pbar.show(); + qApp->setActiveWindow(&pbar); QVERIFY(QTest::qWaitForWindowActive(&pbar)); // No repaint when setting minimum to the current minimum @@ -319,7 +328,9 @@ void tst_QProgressBar::task245201_testChangeStyleAndDelete() QStyle *style = QStyleFactory::create(style1_str); bar->setStyle(style); + bar->move(300, 300); bar->show(); + QVERIFY(QTest::qWaitForWindowExposed(bar)); QStyle *style2 = QStyleFactory::create(style2_str); bar->setStyle(style2); QTest::qWait(10); -- cgit v1.2.3