From 3bd0fd8f97e7a33a874929a383a42e6c710bfff3 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 17 Dec 2016 06:20:06 +0000 Subject: QSFPM: Fix handling of source model layout change In sourceLayoutAboutToBeChanged the source model update is ignored if the affected parents are filtered out anyway. The same logic is attempted in the sourceLayoutChanged slot, but there the early-return logic is applied too late - the mapping is cleared before performing the early-return. Because pointers into the mapping are used in the internalPointer of QModelIndexes in this class, persistent indexes used later will segfault when attempting to dereference it. Additionally, if a parent becomes invalid as a result of the layoutChange, it would be filtered out by the condition in the loop, resulting in a different result in the comparison of emptiness of the parents container. Fix that by persisting the parent's container, and performing the test for early-return before clearing the mapping. Task-number: QTBUG-47711 Task-number: QTBUG-32981 Change-Id: If45e8a1c97d39454160f52041bc9ae7e337dce97 Reviewed-by: David Faure --- .../tst_qsortfilterproxymodel.cpp | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 38e3c6890d..6b98d9f4a3 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -145,6 +145,8 @@ private slots: void canDropMimeData(); void filterHint(); + void sourceLayoutChangeLeavesValidPersistentIndexes(); + protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); void checkHierarchy(const QStringList &data, const QAbstractItemModel *model); @@ -4181,5 +4183,129 @@ void tst_QSortFilterProxyModel::filterHint() QAbstractItemModel::NoLayoutChangeHint); } +/** + + Creates a model where each item has one child, to a set depth, + and the last item has no children. For a model created with + setDepth(4): + + - 1 + - - 2 + - - - 3 + - - - - 4 +*/ +class StepTreeModel : public QAbstractItemModel +{ + Q_OBJECT +public: + StepTreeModel(QObject * parent = 0) + : QAbstractItemModel(parent), m_depth(0) {} + + int columnCount(const QModelIndex& = QModelIndex()) const override { return 1; } + + int rowCount(const QModelIndex& parent = QModelIndex()) const override + { + quintptr parentId = (parent.isValid()) ? parent.internalId() : 0; + return (parentId < m_depth) ? 1 : 0; + } + + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override + { + if (role != Qt::DisplayRole) + return QVariant(); + + return QString::number(index.internalId()); + } + + QModelIndex index(int, int, const QModelIndex& parent = QModelIndex()) const override + { + quintptr parentId = (parent.isValid()) ? parent.internalId() : 0; + if (parentId >= m_depth) + return QModelIndex(); + + return createIndex(0, 0, parentId + 1); + } + + QModelIndex parent(const QModelIndex& index) const override + { + if (index.internalId() == 0) + return QModelIndex(); + + return createIndex(0, 0, index.internalId() - 1); + } + + void setDepth(quintptr depth) + { + int parentIdWithLayoutChange = (m_depth < depth) ? m_depth : depth; + + QList parentsOfLayoutChange; + parentsOfLayoutChange.push_back(createIndex(0, 0, parentIdWithLayoutChange)); + + layoutAboutToBeChanged(parentsOfLayoutChange); + + auto existing = persistentIndexList(); + + QList updated; + + for (auto idx : existing) { + if (indexDepth(idx) <= depth) + updated.push_back(idx); + else + updated.push_back({}); + } + + m_depth = depth; + + changePersistentIndexList(existing, updated); + + layoutChanged(parentsOfLayoutChange); + } + +private: + static quintptr indexDepth(QModelIndex const& index) + { + return (index.isValid()) ? 1 + indexDepth(index.parent()) : 0; + } + +private: + quintptr m_depth; +}; + +void tst_QSortFilterProxyModel::sourceLayoutChangeLeavesValidPersistentIndexes() +{ + StepTreeModel model; + Q_SET_OBJECT_NAME(model); + model.setDepth(4); + + QSortFilterProxyModel proxy1; + proxy1.setSourceModel(&model); + Q_SET_OBJECT_NAME(proxy1); + + proxy1.setFilterRegExp("1|2"); + + // The current state of things: + // model proxy + // - 1 - 1 + // - - 2 - - 2 + // - - - 3 + // - - - - 4 + + // The setDepth call below removes '4' with a layoutChanged call. + // Because the proxy filters that out anyway, the proxy doesn't need + // to emit any signals or update persistent indexes. + + QPersistentModelIndex persistentIndex = proxy1.index(0, 0, proxy1.index(0, 0)); + + model.setDepth(3); + + // Calling parent() causes the internalPointer to be used. + // Before fixing QTBUG-47711, that could be a dangling pointer. + // 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(); + QVERIFY(persistentIndex.parent().isValid()); +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" -- cgit v1.2.3 From 0874861bcc70313c343aba5e5566ed30b69eed1c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 19 Dec 2016 21:13:57 +0000 Subject: QSFPM: Remove data manipulation from move handlers Similar to the fix in the parent commit, incorrect updating of the internal data structures during layout changes can lead to dangling pointers being dereferenced later. Moves are treated as layoutChanges by this proxy by forwarding to the appropriate method. However, data is incorrectly cleared prior to that forwarding. Remove that, and let the layoutChange handling take appropriate action. Change-Id: Iee951e37152328a4e6a5fb8e5385c32a2fe4c0bd Reviewed-by: David Faure --- .../tst_qsortfilterproxymodel.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 6b98d9f4a3..7b6c470dc4 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -146,6 +146,7 @@ private slots: void filterHint(); void sourceLayoutChangeLeavesValidPersistentIndexes(); + void rowMoveLeavesValidPersistentIndexes(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -4307,5 +4308,50 @@ void tst_QSortFilterProxyModel::sourceLayoutChangeLeavesValidPersistentIndexes() QVERIFY(persistentIndex.parent().isValid()); } +void tst_QSortFilterProxyModel::rowMoveLeavesValidPersistentIndexes() +{ + DynamicTreeModel model; + Q_SET_OBJECT_NAME(model); + + QList ancestors; + for (auto i = 0; i < 5; ++i) + { + Q_UNUSED(i); + ModelInsertCommand insertCommand(&model); + insertCommand.setAncestorRowNumbers(ancestors); + insertCommand.setStartRow(0); + insertCommand.setEndRow(0); + insertCommand.doCommand(); + ancestors.push_back(0); + } + + QSortFilterProxyModel proxy1; + proxy1.setSourceModel(&model); + Q_SET_OBJECT_NAME(proxy1); + + proxy1.setFilterRegExp("1|2"); + + auto item5 = model.match(model.index(0, 0), Qt::DisplayRole, "5", 1, Qt::MatchRecursive).first(); + auto item3 = model.match(model.index(0, 0), Qt::DisplayRole, "3", 1, Qt::MatchRecursive).first(); + + Q_ASSERT(item5.isValid()); + Q_ASSERT(item3.isValid()); + + QPersistentModelIndex persistentIndex = proxy1.match(proxy1.index(0, 0), Qt::DisplayRole, "2", 1, Qt::MatchRecursive).first(); + + ModelMoveCommand moveCommand(&model, 0); + moveCommand.setAncestorRowNumbers(QList{0, 0, 0, 0}); + moveCommand.setStartRow(0); + moveCommand.setEndRow(0); + moveCommand.setDestRow(0); + moveCommand.setDestAncestors(QList{0, 0, 0}); + moveCommand.doCommand(); + + // Calling parent() causes the internalPointer to be used. + // Before fixing QTBUG-47711 (moveRows case), that could be + // a dangling pointer. + QVERIFY(persistentIndex.parent().isValid()); +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" -- cgit v1.2.3 From baad82d242a4d8c1af6c87faaa7f25584183fd53 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 20 Dec 2016 00:44:12 +0000 Subject: QIPM: Persist model indexes after emitting layoutChange, not before Callers can persist a QModelIndex which was not persisted before in a slot connected to the signal, and such a persisted index must be updated in the course of the layoutChange. Store the indexes to persist after emitting the signal. Task-number: QTBUG-32981 Change-Id: Ibee4c0d84817d72603a03fe5b22fdeefeac0695e Reviewed-by: David Faure --- .../tst_qidentityproxymodel.cpp | 76 ++++++++++++++++++++++ 1 file changed, 76 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 e946f3104a..564b8547b1 100644 --- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -68,6 +68,8 @@ private slots: void itemData(); + void persistIndexOnLayoutChange(); + protected: void verifyIdentity(QAbstractItemModel *model, const QModelIndex &parent = QModelIndex()); @@ -377,5 +379,79 @@ void tst_QIdentityProxyModel::itemData() QCOMPARE(proxy.itemData(topIndex).value(Qt::DisplayRole).toString(), QStringLiteral("Monday_appended")); } +void dump(QAbstractItemModel* model, QString const& indent = " - ", QModelIndex const& parent = {}) +{ + for (auto row = 0; row < model->rowCount(parent); ++row) + { + auto idx = model->index(row, 0, parent); + qDebug() << (indent + idx.data().toString()); + dump(model, indent + "- ", idx); + } +} + +void tst_QIdentityProxyModel::persistIndexOnLayoutChange() +{ + DynamicTreeModel model; + + QList ancestors; + for (auto i = 0; i < 3; ++i) + { + Q_UNUSED(i); + ModelInsertCommand insertCommand(&model); + insertCommand.setAncestorRowNumbers(ancestors); + insertCommand.setStartRow(0); + insertCommand.setEndRow(0); + insertCommand.doCommand(); + ancestors.push_back(0); + } + ModelInsertCommand insertCommand(&model); + insertCommand.setAncestorRowNumbers(ancestors); + insertCommand.setStartRow(0); + insertCommand.setEndRow(1); + insertCommand.doCommand(); + + // dump(&model); + // " - 1" + // " - - 2" + // " - - - 3" + // " - - - - 4" + // " - - - - 5" + + QIdentityProxyModel proxy; + proxy.setSourceModel(&model); + + QPersistentModelIndex persistentIndex; + + QPersistentModelIndex sourcePersistentIndex = model.match(model.index(0, 0), Qt::DisplayRole, "5", 1, Qt::MatchRecursive).first(); + + QCOMPARE(sourcePersistentIndex.data().toString(), QStringLiteral("5")); + + bool gotLayoutAboutToBeChanged = false; + bool gotLayoutChanged = false; + + QObject::connect(&proxy, &QAbstractItemModel::layoutAboutToBeChanged, &proxy, [&proxy, &persistentIndex, &gotLayoutAboutToBeChanged] + { + gotLayoutAboutToBeChanged = true; + persistentIndex = proxy.match(proxy.index(0, 0), Qt::DisplayRole, "5", 1, Qt::MatchRecursive).first(); + }); + + QObject::connect(&proxy, &QAbstractItemModel::layoutChanged, &proxy, [&proxy, &persistentIndex, &sourcePersistentIndex, &gotLayoutChanged] + { + gotLayoutChanged = true; + QCOMPARE(QModelIndex(persistentIndex), proxy.mapFromSource(sourcePersistentIndex)); + }); + + ModelChangeChildrenLayoutsCommand layoutChangeCommand(&model, 0); + + layoutChangeCommand.setAncestorRowNumbers(QList{0, 0, 0}); + layoutChangeCommand.setSecondAncestorRowNumbers(QList{0, 0}); + + layoutChangeCommand.doCommand(); + + QVERIFY(gotLayoutAboutToBeChanged); + QVERIFY(gotLayoutChanged); + QVERIFY(persistentIndex.isValid()); +} + QTEST_MAIN(tst_QIdentityProxyModel) #include "tst_qidentityproxymodel.moc" -- cgit v1.2.3 From 77a8e90cddcfa1c34518ef846a4838874a7bc0c7 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 29 Dec 2016 18:15:53 +0100 Subject: QHeaderView: fix restoreState() on a model with more columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When saving state for a 3-columns headerview and then restoring that state onto a 5-column headerview, the headerview shouldn't suddenly think it has 3 columns. Rather than making restoreState() fail, we adjust for the additional columns, so that we can still apply the customizations from the user to all other columns (hiding, moving, etc.). Change-Id: I3f220aa322ea8b629d2fe345f8cde13e0ea615d6 Reviewed-by: Thorbjørn Lund Martsum --- .../itemviews/qheaderview/tst_qheaderview.cpp | 82 +++++++++++++++++++--- 1 file changed, 72 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 32a324b888..1078dcc2e9 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -169,6 +169,9 @@ private slots: void moveSectionAndReset(); void moveSectionAndRemove(); void saveRestore(); + void restoreQt4State(); + void restoreToMoreColumns(); + void restoreBeforeSetModel(); void defaultSectionSizeTest(); void defaultSectionSizeTestStyles(); @@ -1523,11 +1526,11 @@ public: { return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); } - int rowCount(const QModelIndex & /* parent */) const + int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const { return 8; } - int columnCount(const QModelIndex &/*parent= QModelIndex()*/) const + int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return m_col_count; } @@ -1588,41 +1591,56 @@ void tst_QHeaderView::moveSectionAndRemove() QCOMPARE(v.count(), 0); } -void tst_QHeaderView::saveRestore() +static QByteArray savedState() { - SimpleModel m; + QStandardItemModel m(4, 4); QHeaderView h1(Qt::Horizontal); h1.setModel(&m); h1.swapSections(0, 2); h1.resizeSection(1, 10); h1.setSortIndicatorShown(true); - h1.setSortIndicator(1,Qt::DescendingOrder); - QByteArray s1 = h1.saveState(); + h1.setSortIndicator(2, Qt::DescendingOrder); + h1.setSectionHidden(3, true); + return h1.saveState(); +} + +void tst_QHeaderView::saveRestore() +{ + QStandardItemModel m(4, 4); + const QByteArray s1 = savedState(); QHeaderView h2(Qt::Vertical); QSignalSpy spy(&h2, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder))); h2.setModel(&m); - h2.restoreState(s1); + QVERIFY(h2.restoreState(s1)); QCOMPARE(spy.count(), 1); - QCOMPARE(spy.at(0).at(0).toInt(), 1); + QCOMPARE(spy.at(0).at(0).toInt(), 2); QCOMPARE(h2.logicalIndex(0), 2); QCOMPARE(h2.logicalIndex(2), 0); QCOMPARE(h2.sectionSize(1), 10); - QCOMPARE(h2.sortIndicatorSection(), 1); + QCOMPARE(h2.sortIndicatorSection(), 2); QCOMPARE(h2.sortIndicatorOrder(), Qt::DescendingOrder); QCOMPARE(h2.isSortIndicatorShown(), true); + QVERIFY(!h2.isSectionHidden(2)); + QVERIFY(h2.isSectionHidden(3)); + QCOMPARE(h2.hiddenSectionCount(), 1); QByteArray s2 = h2.saveState(); - QCOMPARE(s1, s2); + QVERIFY(!h2.restoreState(QByteArrayLiteral("Garbage"))); +} +void tst_QHeaderView::restoreQt4State() +{ // QTBUG-40462 // Setting from Qt4, where information about multiple sections were grouped together in one // sectionItem object + QStandardItemModel m(4, 10); + QHeaderView h2(Qt::Vertical); QByteArray settings_qt4 = QByteArray::fromHex("000000ff00000000000000010000000100000000010000000000000000000000000000" "0000000003e80000000a0101000100000000000000000000000064ffffffff00000081" @@ -1652,6 +1670,50 @@ void tst_QHeaderView::saveRestore() QCOMPARE(h2.saveState(), old_state); } +void tst_QHeaderView::restoreToMoreColumns() +{ + // Restore state onto a model with more columns + const QByteArray s1 = savedState(); + QHeaderView h4(Qt::Horizontal); + QStandardItemModel fiveColumnsModel(1, 5); + h4.setModel(&fiveColumnsModel); + QCOMPARE(fiveColumnsModel.columnCount(), 5); + QCOMPARE(h4.count(), 5); + QVERIFY(h4.restoreState(s1)); + QCOMPARE(fiveColumnsModel.columnCount(), 5); + QCOMPARE(h4.count(), 5); + QCOMPARE(h4.sectionSize(1), 10); + for (int i = 0; i < h4.count(); ++i) + QVERIFY(h4.sectionSize(i) > 0 || h4.isSectionHidden(i)); + QVERIFY(!h4.isSectionHidden(2)); + QVERIFY(h4.isSectionHidden(3)); + QCOMPARE(h4.hiddenSectionCount(), 1); + QCOMPARE(h4.sortIndicatorSection(), 2); + QCOMPARE(h4.sortIndicatorOrder(), Qt::DescendingOrder); +} + +void tst_QHeaderView::restoreBeforeSetModel() +{ + QHeaderView h2(Qt::Horizontal); + const QByteArray s1 = savedState(); + // First restore + QVERIFY(h2.restoreState(s1)); + // Then setModel + QStandardItemModel model(4, 4); + h2.setModel(&model); + + // Check the result + QCOMPARE(h2.logicalIndex(0), 2); + QCOMPARE(h2.logicalIndex(2), 0); + QCOMPARE(h2.sectionSize(1), 10); + QCOMPARE(h2.sortIndicatorSection(), 2); + QCOMPARE(h2.sortIndicatorOrder(), Qt::DescendingOrder); + QCOMPARE(h2.isSortIndicatorShown(), true); + QVERIFY(!h2.isSectionHidden(2)); + QVERIFY(h2.isSectionHidden(3)); + QCOMPARE(h2.hiddenSectionCount(), 1); +} + void tst_QHeaderView::defaultSectionSizeTest() { // Setup -- cgit v1.2.3 From 3986be6d98a09fa7854744253864a9e57486bbcf Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 2 Jan 2017 12:47:31 +0100 Subject: Improve reliability of network bearer tests May of the tests initiate a scan / update of the network configuration and expect the API to deliver exactly one update. This turns out to be a race condition as the update may be emitted multiple times, as QNetworkConfigurationManagerPrivate::updateConfigurations() is called via posted events (queued signal emissions) from the bearer thread, and so after creating the spy we may receive an update from _before_ and end up emitting the signal multiple times. Task-number: QTQAINFRA-1040 Change-Id: I931e2907f0cb86d48b4ab1a8795d75206035ea11 Reviewed-by: Thiago Macieira --- .../bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp | 4 ++-- .../tst_qnetworkconfigurationmanager.cpp | 10 +++++----- .../bearer/qnetworksession/test/tst_qnetworksession.cpp | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index 0a52dd0388..82fa5cab9c 100644 --- a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -114,7 +114,7 @@ void tst_QNetworkConfiguration::comparison() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList configs = manager.allConfigurations(QNetworkConfiguration::Discovered); QVERIFY(configs.count()); @@ -161,7 +161,7 @@ void tst_QNetworkConfiguration::isRoamingAvailable() //force update to get maximum list QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete foreach(QNetworkConfiguration c, configs) { diff --git a/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp b/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp index 838612f638..b251a65420 100644 --- a/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp +++ b/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp @@ -68,7 +68,7 @@ void tst_QNetworkConfigurationManager::allConfigurations() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList configs = manager.allConfigurations(); @@ -145,7 +145,7 @@ void tst_QNetworkConfigurationManager::defaultConfiguration() QNetworkConfigurationManager manager; QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList configs = manager.allConfigurations(); QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); @@ -175,7 +175,7 @@ void tst_QNetworkConfigurationManager::configurationFromIdentifier() //force an update to get maximum number of configs QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList configs = manager.allConfigurations(); @@ -203,7 +203,7 @@ protected: preScanConfigs = manager.allConfigurations(); QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete configs = manager.allConfigurations(); } public: @@ -229,7 +229,7 @@ void tst_QNetworkConfigurationManager::usedInThread() QList preScanConfigs = manager.allConfigurations(); QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList configs = manager.allConfigurations(); QCOMPARE(thread.configs, configs); //Don't compare pre scan configs, because these may be cached and therefore give different results diff --git a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp index 4ae511cf54..138a0859cd 100644 --- a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp +++ b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp @@ -106,7 +106,7 @@ void tst_QNetworkSession::initTestCase() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); lackeyDir = QFINDTESTDATA("lackey"); QVERIFY2(!lackeyDir.isEmpty(), qPrintable( @@ -1007,7 +1007,7 @@ QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfigur QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); mgr.updateConfigurations(); - QTRY_NOOP(updateSpy.count() == 1); + QTRY_NOOP(updateSpy.count() >= 1); if (updateSpy.count() != 1) { qDebug("tst_QNetworkSession::suitableConfiguration() failure: unable to update configurations"); return QNetworkConfiguration(); @@ -1052,7 +1052,7 @@ void updateConfigurations() QNetworkConfigurationManager mgr; QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); mgr.updateConfigurations(); - QTRY_NOOP(updateSpy.count() == 1); + QTRY_NOOP(updateSpy.count() >= 1); } // A convenience-function: updates and prints all available confiurations and their states -- cgit v1.2.3 From a8ae8e3130fe4953ebfd54bce15648f58cd3f5be Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 3 Mar 2017 14:06:49 +0100 Subject: QDateTime::fromString(): improve performance by 33% getMaximum() and getMinimum(), called during parsing, create new QDateTime instances, which on Linux end up calling mktime(). Making these static (for the common case of LocalTime spec) improves performance dramatically, when parsing several date/times. tests/benchmarks/corelib/tools/qdatetime/ (after fixing it to actually parse a valid date/time) says: RESULT : tst_QDateTime::fromString(): - 36,742,060 instruction reads per iteration (total: 36,742,060, iterations: 1) + 24,230,060 instruction reads per iteration (total: 24,230,060, iterations: 1) Change-Id: I0c3931285475bf19a5be8cba1486ed07cbf5e134 Reviewed-by: Thiago Macieira --- tests/benchmarks/corelib/tools/qdatetime/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/benchmarks/corelib/tools/qdatetime/main.cpp b/tests/benchmarks/corelib/tools/qdatetime/main.cpp index 8f43a412b7..2c1e3d97ae 100644 --- a/tests/benchmarks/corelib/tools/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/tools/qdatetime/main.cpp @@ -547,8 +547,9 @@ void tst_QDateTime::currentMSecsSinceEpoch() void tst_QDateTime::fromString() { - QString format = "yyy-MM-dd hh:mm:ss.zzz t"; - QString input = "2010-01-01 13:12:11.999 UTC"; + QString format = "yyyy-MM-dd hh:mm:ss.zzz"; + QString input = "2010-01-01 13:12:11.999"; + QVERIFY(QDateTime::fromString(input, format).isValid()); QBENCHMARK { for (int i = 0; i < 1000; ++i) QDateTime::fromString(input, format); -- cgit v1.2.3 From 2ed9a52ebf1dfb1a16ad65413bea01314010720d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 30 Nov 2016 16:37:15 +0100 Subject: Fix compilation without sharedmemory We have to enable qt_safe_ftok with either sharedmemory or systemsemaphore. In order to make the resulting QT_CONFIG work with the bootstrap library we switch the features off for bootstrapping. Some tests and examples have to be excluded when sharedmemory is not available. Change-Id: I3fc3926d160202b378be2293fba40201a4bf50c5 Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro b/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro index 69062a9741..3a4697750e 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro +++ b/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs -!winrt: SUBDIRS = sharedmemoryhelper - -SUBDIRS += test +qtConfig(sharedmemory) { + !winrt: SUBDIRS = sharedmemoryhelper + SUBDIRS += test +} -- cgit v1.2.3 From 0979c5304c32cdb868b22a021ce505d12d6b1967 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 9 Jan 2017 11:24:50 +0100 Subject: Drop unnecessary dependencies from some tests The future tests don't need QtConcurrent as QFuture and friends are in QtCore. The printdevice test doesn't use QtNetwork and the lancelot as well as the testlib tests don't use QtXml. Change-Id: I150ac99b36682aa23ad22ba943266eb0f0952838 Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/thread/qfuture/qfuture.pro | 2 +- tests/auto/corelib/thread/qfuturesynchronizer/qfuturesynchronizer.pro | 2 +- tests/auto/corelib/thread/qresultstore/qresultstore.pro | 2 +- tests/auto/other/lancelot/lancelot.pro | 2 +- tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro | 2 +- tests/auto/printsupport/kernel/qprinterinfo/qprinterinfo.pro | 2 +- tests/auto/testlib/selftests/test/test.pro | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/thread/qfuture/qfuture.pro b/tests/auto/corelib/thread/qfuture/qfuture.pro index ed9e189668..b1667760d6 100644 --- a/tests/auto/corelib/thread/qfuture/qfuture.pro +++ b/tests/auto/corelib/thread/qfuture/qfuture.pro @@ -1,5 +1,5 @@ CONFIG += testcase TARGET = tst_qfuture -QT = core core-private testlib concurrent +QT = core core-private testlib SOURCES = tst_qfuture.cpp DEFINES += QT_STRICT_ITERATORS diff --git a/tests/auto/corelib/thread/qfuturesynchronizer/qfuturesynchronizer.pro b/tests/auto/corelib/thread/qfuturesynchronizer/qfuturesynchronizer.pro index 5eebd12deb..0d20117ed0 100644 --- a/tests/auto/corelib/thread/qfuturesynchronizer/qfuturesynchronizer.pro +++ b/tests/auto/corelib/thread/qfuturesynchronizer/qfuturesynchronizer.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qfuturesynchronizer -QT = core testlib concurrent +QT = core testlib SOURCES = tst_qfuturesynchronizer.cpp diff --git a/tests/auto/corelib/thread/qresultstore/qresultstore.pro b/tests/auto/corelib/thread/qresultstore/qresultstore.pro index 2f6c18f64c..bbebe0976b 100644 --- a/tests/auto/corelib/thread/qresultstore/qresultstore.pro +++ b/tests/auto/corelib/thread/qresultstore/qresultstore.pro @@ -1,5 +1,5 @@ CONFIG += testcase TARGET = tst_qresultstore -QT = core-private testlib concurrent +QT = core-private testlib SOURCES = tst_qresultstore.cpp DEFINES += QT_STRICT_ITERATORS diff --git a/tests/auto/other/lancelot/lancelot.pro b/tests/auto/other/lancelot/lancelot.pro index e9c9af7143..b492611ca7 100644 --- a/tests/auto/other/lancelot/lancelot.pro +++ b/tests/auto/other/lancelot/lancelot.pro @@ -1,7 +1,7 @@ CONFIG += testcase CONFIG -= app_bundle TARGET = tst_lancelot -QT += xml testlib +QT += testlib SOURCES += tst_lancelot.cpp \ paintcommands.cpp diff --git a/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro b/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro index 56c1b60d94..a859f15fbb 100644 --- a/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro +++ b/tests/auto/printsupport/kernel/qprintdevice/qprintdevice.pro @@ -2,6 +2,6 @@ CONFIG += testcase TARGET = tst_qprintdevice SOURCES += tst_qprintdevice.cpp -QT += printsupport-private network testlib +QT += printsupport-private testlib DEFINES += QT_USE_USING_NAMESPACE diff --git a/tests/auto/printsupport/kernel/qprinterinfo/qprinterinfo.pro b/tests/auto/printsupport/kernel/qprinterinfo/qprinterinfo.pro index f397f48bb8..36261780fd 100644 --- a/tests/auto/printsupport/kernel/qprinterinfo/qprinterinfo.pro +++ b/tests/auto/printsupport/kernel/qprinterinfo/qprinterinfo.pro @@ -2,6 +2,6 @@ CONFIG += testcase TARGET = tst_qprinterinfo SOURCES += tst_qprinterinfo.cpp -QT += printsupport network testlib +QT += printsupport testlib DEFINES += QT_USE_USING_NAMESPACE diff --git a/tests/auto/testlib/selftests/test/test.pro b/tests/auto/testlib/selftests/test/test.pro index a2a1dd3f0b..a7487736b3 100644 --- a/tests/auto/testlib/selftests/test/test.pro +++ b/tests/auto/testlib/selftests/test/test.pro @@ -1,6 +1,6 @@ CONFIG += testcase SOURCES += ../tst_selftests.cpp -QT = core xml testlib-private +QT = core testlib-private TARGET = ../tst_selftests -- cgit v1.2.3 From ae42bf0f9b2b8c65ef509d5d0ecdd9a0535bb3d2 Mon Sep 17 00:00:00 2001 From: Jason Erb Date: Sun, 15 May 2016 12:16:50 -0400 Subject: Fixed Chinese language selection on iOS For language "Traditional Chinese" on iOS with region "US", the logic was formerly to attempt a match on country/language/script (fail), followed by country/language (which would result in script defaulting to "Simplified"). Now, the logic is to try language/script first if script is specified. Failing that, language/country will be attempted. Task-number: QTBUG-39639 Change-Id: I75a774b1e66686e95167ff221458a97a7ea2660d Reviewed-by: Konstantin Ritt Reviewed-by: Lars Knoll Reviewed-by: Jason Erb Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 39 +++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 8d9a789507..42bfb3603d 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -186,12 +186,50 @@ void tst_QLocale::ctor() QVERIFY(l.country() == default_country); } +#define TEST_CTOR(req_lang, req_script, req_country, exp_lang, exp_script, exp_country) \ + { \ + QLocale l(QLocale::req_lang, QLocale::req_script, QLocale::req_country); \ + QCOMPARE((int)l.language(), (int)exp_lang); \ + QCOMPARE((int)l.script(), (int)exp_script); \ + QCOMPARE((int)l.country(), (int)exp_country); \ + } + + // Exact matches + TEST_CTOR(Chinese, SimplifiedHanScript, China, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, TraditionalHanScript, Taiwan, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, TraditionalHanScript, HongKong, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::HongKong); + + // Best match for AnyCountry + TEST_CTOR(Chinese, SimplifiedHanScript, AnyCountry, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, TraditionalHanScript, AnyCountry, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + + // Best match for AnyScript (and change country to supported one, if necessary) + TEST_CTOR(Chinese, AnyScript, China, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, AnyScript, Taiwan, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, AnyScript, HongKong, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::HongKong); + TEST_CTOR(Chinese, AnyScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + + // Fully-specified not found; find best alternate country + TEST_CTOR(Chinese, SimplifiedHanScript, Taiwan, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, SimplifiedHanScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, TraditionalHanScript, China, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, TraditionalHanScript, UnitedStates, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + + // Fully-specified not found; find best alternate script + TEST_CTOR(Chinese, LatinScript, China, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, LatinScript, Taiwan, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + + // Fully-specified not found; find best alternate country and script + TEST_CTOR(Chinese, LatinScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + +#undef TEST_CTOR #define TEST_CTOR(req_lang, req_country, exp_lang, exp_country) \ { \ QLocale l(QLocale::req_lang, QLocale::req_country); \ QCOMPARE((int)l.language(), (int)exp_lang); \ QCOMPARE((int)l.country(), (int)exp_country); \ } + { QLocale l(QLocale::C, QLocale::AnyCountry); QCOMPARE(l.language(), QLocale::C); @@ -295,7 +333,6 @@ void tst_QLocale::ctor() TEST_CTOR(Uzbek, AnyCountry, QLocale::Uzbek, QLocale::Uzbekistan) #undef TEST_CTOR - #define TEST_CTOR(req_lc, exp_lang, exp_country) \ { \ QLocale l(req_lc); \ -- cgit v1.2.3 From f480196f1be061848275f259a2651973dc33b393 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 10 Jan 2017 09:36:50 +0100 Subject: tst_utf8: remove duplicate nonCharacters() data The population of data rows was factored into a separate file, qutf8data.cpp, in commit e20c4730. Merge commit 9bd03235 failed to track a conflicting change into the new file, and brought the code back into the tst_utf8.cpp, where it has been duplicating the utf8data data ever since. Change-Id: I4282685b882448f927289468bd7ab340a21ea0b3 Reviewed-by: David Faure Reviewed-by: Thiago Macieira --- tests/auto/corelib/codecs/utf8/tst_utf8.cpp | 33 ----------------------------- 1 file changed, 33 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp index 5666726a8c..8f78aa937c 100644 --- a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp +++ b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp @@ -237,39 +237,6 @@ void tst_Utf8::nonCharacters_data() QTest::addColumn("utf8"); QTest::addColumn("utf16"); - // Unicode has a couple of "non-characters" that one can use internally - // These characters may be used for interchange; - // see: http://www.unicode.org/versions/corrigendum9.html - // - // Those are the last two entries each Unicode Plane (U+FFFE, U+FFFF, - // U+1FFFE, U+1FFFF, etc.) as well as the entries between U+FDD0 and - // U+FDEF (inclusive) - - // U+FDD0 through U+FDEF - for (int i = 0; i < 32; ++i) { - char utf8[] = { char(0357), char(0267), char(0220 + i), 0 }; - QString utf16 = QChar(0xfdd0 + i); - QTest::newRow(qPrintable(QString::number(0xfdd0 + i, 16))) << QByteArray(utf8) << utf16; - } - - // the last two in Planes 1 through 16 - for (uint plane = 1; plane <= 16; ++plane) { - for (uint lower = 0xfffe; lower < 0x10000; ++lower) { - uint ucs4 = (plane << 16) | lower; - char utf8[] = { char(0xf0 | uchar(ucs4 >> 18)), - char(0x80 | (uchar(ucs4 >> 12) & 0x3f)), - char(0x80 | (uchar(ucs4 >> 6) & 0x3f)), - char(0x80 | (uchar(ucs4) & 0x3f)), - 0 }; - ushort utf16[] = { QChar::highSurrogate(ucs4), QChar::lowSurrogate(ucs4), 0 }; - - QTest::newRow(qPrintable(QString::number(ucs4, 16))) << QByteArray(utf8) << QString::fromUtf16(utf16); - } - } - - QTest::newRow("fffe") << QByteArray("\xEF\xBF\xBE") << QString(QChar(0xfffe)); - QTest::newRow("ffff") << QByteArray("\xEF\xBF\xBF") << QString(QChar(0xffff)); - extern void loadNonCharactersRows(); loadNonCharactersRows(); } -- cgit v1.2.3 From 62882ad2fe3d9f70c876d7a51a5aab4118ce1ba3 Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 10 Jan 2017 12:04:07 +0100 Subject: tst_qfont: clear style name in test font The test failed if qApp->font() had a styleName() set, when testing old serialization formats which didn't serialize it. Change-Id: If0236d354be144b3a990e074a22f796fffb1ed18 Reviewed-by: Simon Hausmann Reviewed-by: Konstantin Shegunov --- tests/auto/gui/text/qfont/tst_qfont.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index a6d8944656..06c0ba0819 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -358,6 +358,8 @@ void tst_QFont::serialize_data() // Versions <= Qt 2.1 had broken point size serialization, // so we set an integer point size. basicFont.setPointSize(9); + // Versions <= Qt 5.4 didn't serialize styleName, so clear it + basicFont.setStyleName(QString()); QFont font = basicFont; QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0; -- cgit v1.2.3 From 2bb01172a76f14b1f57010b79207f6b9a9bf3f53 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 9 Jan 2017 00:10:42 +0100 Subject: QFont: fix fromString(toString()) when application font has styleName The style name needs to be cleared if not present in the string, otherwise the style name from qApp->font() (which propagates to any default-constructed QFont) remains. Change-Id: I9b6522a39a38526cced8a11ed02ae32582026480 Reviewed-by: Simon Hausmann Reviewed-by: Konstantin Shegunov --- tests/auto/gui/text/qfont/tst_qfont.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 06c0ba0819..2603206ab0 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -63,6 +63,7 @@ private slots: void defaultFamily_data(); void defaultFamily(); void toAndFromString(); + void fromStringWithoutStyleName(); void sharing(); }; @@ -561,6 +562,19 @@ void tst_QFont::toAndFromString() } } +void tst_QFont::fromStringWithoutStyleName() +{ + QFont font1; + font1.fromString("Noto Sans,12,-1,5,50,0,0,0,0,0,Regular"); + + QFont font2 = font1; + const QString str = "Times,16,-1,5,50,0,0,0,0,0"; + font2.fromString(str); + + QCOMPARE(font2.toString(), str); +} + + void tst_QFont::sharing() { // QFontCache references the engineData -- cgit v1.2.3 From 5a1b4832a2704e7fb386d6b4c73dab85facdc40b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 10 Jan 2017 15:30:42 -0800 Subject: Adapt to the C++ SIC introduced by P0021: noexcept overloading C++17 adopts P0021R1[1], which makes noexcept be part of the function pointer's type and thus be overloadable. It contains some provisions for allowing a noexcept function pointer to cast implicitly to a non- noexcept function pointer, but that fails in the presence of templates and additional overloads that could match the type in question. Fortunately, the paper proposed a test macro, so we can change our sources now and be compatible with both C++14 and C++17 rules. This first failed with Clang 4.0 trunk. This source incompatibility is not our fault, it's the language's doing. [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html Task-number: QTBUG-58054 Change-Id: I2bc52f3c7a574209b213fffd14988cf0b875be63 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qobject/test/test.pro | 3 ++ tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 35 +++++++++++++++++++++++ tests/auto/corelib/kernel/qtimer/qtimer.pro | 3 ++ tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 8 ++++++ 4 files changed, 49 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qobject/test/test.pro b/tests/auto/corelib/kernel/qobject/test/test.pro index f3bc045455..4e77cb48c5 100644 --- a/tests/auto/corelib/kernel/qobject/test/test.pro +++ b/tests/auto/corelib/kernel/qobject/test/test.pro @@ -3,5 +3,8 @@ TARGET = ../tst_qobject QT = core-private network testlib SOURCES = ../tst_qobject.cpp +# Force C++17 if available (needed due to P0012R1) +contains(QT_CONFIG, c++1z): CONFIG += c++1z + !winrt: TEST_HELPER_INSTALLS = ../signalbug/signalbug DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 91810cdcd8..7b75438b19 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -120,6 +120,7 @@ private slots: void connectCxx0x(); void connectToStaticCxx0x(); void connectCxx0xTypeMatching(); + void connectCxx17Noexcept(); void connectConvert(); void connectWithReference(); void connectManyArguments(); @@ -4757,10 +4758,13 @@ class LotsOfSignalsAndSlots: public QObject public slots: void slot_v() {} + void slot_v_noexcept() Q_DECL_NOTHROW {} void slot_vi(int) {} + void slot_vi_noexcept() Q_DECL_NOTHROW {} 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_ii(int) { return 0; } int slot_iii(int, int) { return 0; } int slot_iiii(int, int, int) { return 0; } @@ -4774,13 +4778,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_vi(int) const {}; + void const_slot_vi_noexcept(int) const Q_DECL_NOTHROW {} static void static_slot_v() {} + static void static_slot_v_noexcept() Q_DECL_NOTHROW {} static void static_slot_vi(int) {} + static void static_slot_vi_noexcept(int) Q_DECL_NOTHROW {} 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_ii(int) { return 0; } static int static_slot_iii(int, int) { return 0; } static int static_slot_iiii(int, int, int) { return 0; } @@ -4943,6 +4952,32 @@ void tst_QObject::connectCxx0xTypeMatching() } +void receiverFunction_noexcept() Q_DECL_NOTHROW {} +struct Functor_noexcept { void operator()() Q_DECL_NOTHROW {} }; +void tst_QObject::connectCxx17Noexcept() +{ + // this is about connecting signals to slots with the Q_DECL_NOTHROW qualifier + // as semantics changed due to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html + typedef LotsOfSignalsAndSlots Foo; + Foo obj; + + QObject::connect(&obj, &Foo::signal_v, &obj, &Foo::slot_v_noexcept); + QObject::connect(&obj, &Foo::signal_v, &obj, &Foo::slot_i_noexcept); + QObject::connect(&obj, &Foo::signal_v, &obj, &Foo::slot_vi_noexcept); + + QObject::connect(&obj, &Foo::signal_vii, &Foo::static_slot_v_noexcept); + QObject::connect(&obj, &Foo::signal_vii, &Foo::static_slot_i_noexcept); + QObject::connect(&obj, &Foo::signal_vii, &Foo::static_slot_vi_noexcept); + + QVERIFY(QObject::connect(&obj, &Foo::signal_vi, &obj, &Foo::const_slot_vi_noexcept)); + QVERIFY(QObject::connect(&obj, &Foo::signal_vi, &obj, &Foo::const_slot_v_noexcept)); + + QObject::connect(&obj, &Foo::signal_v, receiverFunction_noexcept); + + Functor_noexcept fn; + QObject::connect(&obj, &Foo::signal_v, fn); +} + class StringVariant : public QObject { Q_OBJECT signals: diff --git a/tests/auto/corelib/kernel/qtimer/qtimer.pro b/tests/auto/corelib/kernel/qtimer/qtimer.pro index 8afdbb148e..b27d862bc5 100644 --- a/tests/auto/corelib/kernel/qtimer/qtimer.pro +++ b/tests/auto/corelib/kernel/qtimer/qtimer.pro @@ -2,3 +2,6 @@ CONFIG += testcase TARGET = tst_qtimer QT = core testlib SOURCES = tst_qtimer.cpp + +# Force C++17 if available +contains(QT_CONFIG, c++1z): CONFIG += c++1z diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index fe97695d19..29ff552f6a 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -766,6 +766,11 @@ class StaticEventLoop { public: static void quitEventLoop() + { + quitEventLoop_noexcept(); + } + + static void quitEventLoop_noexcept() Q_DECL_NOTHROW { QVERIFY(!_e.isNull()); _e->quit(); @@ -787,6 +792,9 @@ void tst_QTimer::singleShotToFunctors() QTimer::singleShot(0, &StaticEventLoop::quitEventLoop); QCOMPARE(_e->exec(), 0); + QTimer::singleShot(0, &StaticEventLoop::quitEventLoop_noexcept); + QCOMPARE(_e->exec(), 0); + QThread t1; QObject c1; c1.moveToThread(&t1); -- cgit v1.2.3 From 610c7da075789c1ae736c4a016ef822a4e500f29 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 21:37:49 +0200 Subject: Plug memleaks in tst_QStackedLayout QLayout::replaceWidget() doesn't delete the affected item, but returns it. Change-Id: Ibda96e4bf2432ad13ed2908c7d37547f46e29a37 Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qstackedlayout/tst_qstackedlayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qstackedlayout/tst_qstackedlayout.cpp b/tests/auto/widgets/kernel/qstackedlayout/tst_qstackedlayout.cpp index 835b6ca799..5be4846b3e 100644 --- a/tests/auto/widgets/kernel/qstackedlayout/tst_qstackedlayout.cpp +++ b/tests/auto/widgets/kernel/qstackedlayout/tst_qstackedlayout.cpp @@ -377,7 +377,7 @@ void tst_QStackedLayout::replaceWidget() QCOMPARE(stackLayout->indexOf(replaceFrom), 1); QCOMPARE(stackLayout->indexOf(replaceTo), -1); - stackLayout->replaceWidget(replaceFrom, replaceTo); + delete stackLayout->replaceWidget(replaceFrom, replaceTo); QCOMPARE(stackLayout->indexOf(replaceFrom), -1); QCOMPARE(stackLayout->indexOf(replaceTo), 1); -- cgit v1.2.3 From 4baf08653c69fe5a131dae4ea27ac4cd67743f6e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 09:02:03 +0100 Subject: QHostAddress: add missing docs qHash(QHostAddress) was added in Qt 5.0 (at least the version with uint seed = 0). op==(QHostAddress::SpecialAddress, QHostAddress) was there since QHostAddress was added before public history. Since QHostAddress does not have a \since, the I did not supply one for op==, either. Since the equality operator did not have unit-tests, added one. Change-Id: I954a0df02464338f08a12ca58d4cc0ceb013e67a Reviewed-by: Thiago Macieira --- tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp index 364e435d3d..a715c38f32 100644 --- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp +++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp @@ -271,6 +271,7 @@ void tst_QHostAddress::specialAddresses() //check special address equal to itself (QTBUG-22898), note two overloads of operator== QVERIFY(QHostAddress(address) == QHostAddress(address)); QVERIFY(QHostAddress(address) == address); + QVERIFY(address == QHostAddress(address)); QVERIFY(!(QHostAddress(address) != QHostAddress(address))); QVERIFY(!(QHostAddress(address) != address)); -- cgit v1.2.3 From 0243863382ab580a0d25c4df9e9bfa6e2f31c7cb Mon Sep 17 00:00:00 2001 From: Aleksei Ilin Date: Mon, 14 Nov 2016 20:27:38 +0300 Subject: Fix access incorrect index in QListView with batch layout The size of flowPositions is larger by one than the number of rows in the model so the last correct row number is flowPositions.count()-2, not flowPositions.count()-1. Change-Id: Idf8bbd155151d553947d5d299dd01ffaff0c95fa Task-number: QTBUG-47694 Reviewed-by: Alexander Volkov Reviewed-by: David Faure --- tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 0f1c5723d5..6eed21abb2 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -150,6 +150,7 @@ private slots: void horizontalScrollingByVerticalWheelEvents(); void taskQTBUG_7232_AllowUserToControlSingleStep(); void taskQTBUG_51086_skippingIndexesInSelectedIndexes(); + void taskQTBUG_47694_indexOutOfBoundBatchLayout(); }; // Testing get/set functions @@ -2486,5 +2487,18 @@ void tst_QListView::taskQTBUG_51086_skippingIndexesInSelectedIndexes() QVERIFY(!indexes.contains(data.index(8, 0))); } +void tst_QListView::taskQTBUG_47694_indexOutOfBoundBatchLayout() +{ + QListView view; + view.setLayoutMode(QListView::Batched); + int batchSize = view.batchSize(); + + QStandardItemModel model(batchSize + 1, 1); + + view.setModel(&model); + + view.scrollTo(model.index(batchSize - 1, 0)); +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" -- cgit v1.2.3 From 19a1a0871d4a9081646925c422fe32e900846c2e Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Mon, 16 Jan 2017 21:43:12 +0100 Subject: QSslDiffieHellmanParameters: simplify defaultParameters() construction This commit simplifies defaultParameters() to simply construct an empty QSslDiffieHellmanParameters and assigning the DER-form of the DH parameters to QSslDiffieHellmanParametersPrivate's derData field. This creates a valid QSslDiffieHellmanParameters instance, but skips any potentially expensive verification steps. The previous implementation of defaultParameters() would use the public fromEncoded() method to construct an instance of the default parameters. This triggers a verification of the passed-in data, which can be expensive. To ensure our defaultParameters() QSslDiffieHellmanParameters instance does pass verification, this commit adds an autotest to verify that. Fixes QTBUG-57815. Change-Id: I6b1d9dbbfde526b232c319195ddbad42326be27c Task-number: QTBUG-57815 Reviewed-by: Timur Pocheptsov --- .../tst_qssldiffiehellmanparameters.cpp | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp b/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp index f3b9003fbb..ddf503eed6 100644 --- a/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp +++ b/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp @@ -42,6 +42,13 @@ #include #include +// Default DH parameters, exported by qssldiffiehellmanparameters.cpp. +QT_BEGIN_NAMESPACE +extern Q_AUTOTEST_EXPORT const char *qssl_dhparams_default_base64; +QT_END_NAMESPACE + +QT_USE_NAMESPACE + class tst_QSslDiffieHellmanParameters : public QObject { Q_OBJECT @@ -54,6 +61,7 @@ private Q_SLOTS: void constructionPEM(); void unsafe512Bits(); void unsafeNonPrime(); + void defaultIsValid(); #endif }; @@ -157,6 +165,33 @@ void tst_QSslDiffieHellmanParameters::unsafeNonPrime() #endif } +void tst_QSslDiffieHellmanParameters::defaultIsValid() +{ + // The QSslDiffieHellmanParameters::defaultParameters() method takes a shortcut, + // by not verifying the passed-in parameters. Instead, it simply assigns the default + // DH parameters to the derData field of QSslDiffieHellmanParametersPrivate. + // + // This test ensures that our default parameters pass the internal verification tests + // by constructing, using fromEncoded(), a QSslDiffieHellmanParameters instance that + // we expect to be equivalent to the one returned by defaultParameters(). By using + // fromEncoded() we go through the internal verification mechanisms. Finally, to ensure + // the two instances are equivalent, we compare them. + + const auto dh = QSslDiffieHellmanParameters::fromEncoded( + QByteArray::fromBase64(QByteArray(qssl_dhparams_default_base64)), + QSsl::Der + ); + + const auto defaultdh = QSslDiffieHellmanParameters::defaultParameters(); + +#ifndef QT_NO_OPENSSL + QCOMPARE(dh.isEmpty(), false); + QCOMPARE(dh.isValid(), true); + QCOMPARE(dh.error(), QSslDiffieHellmanParameters::NoError); + QCOMPARE(dh, defaultdh); +#endif +} + #endif // QT_NO_SSL QTEST_MAIN(tst_QSslDiffieHellmanParameters) -- cgit v1.2.3 From 287f548d4c7cc594ffecc9c050dc5ec9fdaa6d37 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Wed, 2 Nov 2016 10:51:39 +0300 Subject: Make shortcuts work for platform menu bars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a platform menu bar is used, the QMenuBar is hidden, so shortcuts for QActions attached only to it do not work. Extend the macOS-specific code to treat such menubars as visible to other platforms, to make the shortcuts work. The exception is made for internal QMenuBar shortcuts, which are forwarded to the platform menu. A follow-up change will add support for this to QDBusPlatformMenu. The updateGeometries() method is called for platform menu bars too to make sure the internal shortcuts are registered even if the global menu is in use. Add two cases to the tst_QMenuBar::activatedCount() test to test both native and non-native menu bars when possible (it now passes with native menu bars too). Change-Id: I2d7128512719ac199cd3f8f7ba28333d04d84ed4 Reviewed-by: Tor Arne Vestbø --- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index b04fb7cd5d..f19d7619cc 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -93,6 +93,7 @@ private slots: #if !defined(Q_OS_DARWIN) void accel(); void activatedCount(); + void activatedCount_data(); void check_accelKeys(); void check_cursorKeys1(); @@ -144,8 +145,8 @@ protected slots: void slotForTaskQTBUG53205(); private: - TestMenu initSimpleMenuBar(QMenuBar *mb); - TestMenu initWindowWithSimpleMenuBar(QMainWindow &w); + TestMenu initSimpleMenuBar(QMenuBar *mb, bool forceNonNative = true); + TestMenu initWindowWithSimpleMenuBar(QMainWindow &w, bool forceNonNative = true); QAction *createCharacterAction(QMenu *menu, char lowerAscii); QMenu *addNumberedMenu(QMenuBar *mb, int n); TestMenu initComplexMenuBar(QMenuBar *mb); @@ -213,10 +214,10 @@ void tst_QMenuBar::cleanup() // Create a simple menu bar and connect its actions to onSimpleActivated(). -TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb) -{ +TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) { TestMenu result; - mb->setNativeMenuBar(false); + if (forceNonNative) + mb->setNativeMenuBar(false); connect(mb, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); QMenu *menu = mb->addMenu(QStringLiteral("&accel")); QAction *action = menu->addAction(QStringLiteral("menu1") ); @@ -239,11 +240,11 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb) return result; } -inline TestMenu tst_QMenuBar::initWindowWithSimpleMenuBar(QMainWindow &w) +inline TestMenu tst_QMenuBar::initWindowWithSimpleMenuBar(QMainWindow &w, bool forceNonNative) { w.resize(200, 200); centerOnScreen(&w); - return initSimpleMenuBar(w.menuBar()); + return initSimpleMenuBar(w.menuBar(), forceNonNative); } // add a menu with number n, set number as data. @@ -341,7 +342,8 @@ void tst_QMenuBar::activatedCount() { // create a popup menu with menu items set the accelerators later... QMainWindow w; - initWindowWithSimpleMenuBar(w); + QFETCH( bool, forceNonNative ); + initWindowWithSimpleMenuBar(w, forceNonNative); w.show(); QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); @@ -350,6 +352,13 @@ void tst_QMenuBar::activatedCount() //wait(5000); QCOMPARE( m_simpleActivatedCount, 2 ); //1 from the popupmenu and 1 from the menubar } + +void tst_QMenuBar::activatedCount_data() +{ + QTest::addColumn("forceNonNative"); + QTest::newRow( "forcing non-native menubar" ) << true; + QTest::newRow( "not forcing non-native menubar" ) << false; +} #endif void tst_QMenuBar::clear() -- cgit v1.2.3 From 578154c47dfeaf9eb7f7ed428b876314fc239350 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 20 Jan 2017 09:02:05 +0100 Subject: tst_QPauseAnimation: Use QTRY_COMPARE for checking the stopped state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use QTRY_COMPARE with a timeout to check for the stopped state unless BAD_TIMER_RESOLUTION is defined. This speeds up the test by 1s and prints diagnostic information should an interval be too short (as seems to be the case on macOS, currently). Change-Id: I8f884cd66ad33314124d3130d9f49606e6dfe9f3 Reviewed-by: Jędrzej Nowacki --- .../qpauseanimation/tst_qpauseanimation.cpp | 64 +++++++++------------- 1 file changed, 25 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp b/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp index 25b6216075..290c2abc98 100644 --- a/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp +++ b/tests/auto/corelib/animation/qpauseanimation/tst_qpauseanimation.cpp @@ -40,6 +40,16 @@ #ifdef BAD_TIMER_RESOLUTION static const char timerError[] = "On this platform, consistent timing is not working properly due to bad timer resolution"; + +# define WAIT_FOR_STOPPED(animation, duration) \ + QTest::qWait(duration); \ + if (animation.state() != QAbstractAnimation::Stopped) \ + QEXPECT_FAIL("", timerError, Abort); \ + QCOMPARE(animation.state(), QAbstractAnimation::Stopped) +#else +// Use QTRY_COMPARE with one additional timer tick +# define WAIT_FOR_STOPPED(animation, duration) \ + QTRY_COMPARE_WITH_TIMEOUT(animation.state(), QAbstractAnimation::Stopped, (duration)) #endif class TestablePauseAnimation : public QPauseAnimation @@ -108,11 +118,10 @@ void tst_QPauseAnimation::changeDirectionWhileRunning() TestablePauseAnimation animation; animation.setDuration(400); animation.start(); - QTest::qWait(100); - QCOMPARE(animation.state(), QAbstractAnimation::Running); + QTRY_COMPARE(animation.state(), QAbstractAnimation::Running); animation.setDirection(QAbstractAnimation::Backward); - QTest::qWait(animation.totalDuration() + 50); - QCOMPARE(animation.state(), QAbstractAnimation::Stopped); + const int expectedDuration = animation.totalDuration() + 100; + WAIT_FOR_STOPPED(animation, expectedDuration); } void tst_QPauseAnimation::noTimerUpdates_data() @@ -137,14 +146,9 @@ void tst_QPauseAnimation::noTimerUpdates() animation.setDuration(duration); animation.setLoopCount(loopCount); animation.start(); - QTest::qWait(animation.totalDuration() + 100); - -#ifdef BAD_TIMER_RESOLUTION - if (animation.state() != QAbstractAnimation::Stopped) - QEXPECT_FAIL("", timerError, Abort); -#endif + const int expectedDuration = animation.totalDuration() + 150; + WAIT_FOR_STOPPED(animation, expectedDuration); - QCOMPARE(animation.state(), QAbstractAnimation::Stopped); const int expectedLoopCount = 1 + loopCount; #ifdef BAD_TIMER_RESOLUTION @@ -166,13 +170,9 @@ void tst_QPauseAnimation::multiplePauseAnimations() animation.start(); animation2.start(); - QTest::qWait(animation.totalDuration() + 100); -#ifdef BAD_TIMER_RESOLUTION - if (animation.state() != QAbstractAnimation::Stopped) - QEXPECT_FAIL("", timerError, Abort); -#endif - QCOMPARE(animation.state(), QAbstractAnimation::Stopped); + const int expectedDuration = animation.totalDuration() + 150; + WAIT_FOR_STOPPED(animation, expectedDuration); #ifdef BAD_TIMER_RESOLUTION if (animation2.state() != QAbstractAnimation::Running) @@ -192,13 +192,7 @@ void tst_QPauseAnimation::multiplePauseAnimations() #endif QCOMPARE(animation2.m_updateCurrentTimeCount, 2); - QTest::qWait(550); - -#ifdef BAD_TIMER_RESOLUTION - if (animation2.state() != QAbstractAnimation::Stopped) - QEXPECT_FAIL("", timerError, Abort); -#endif - QCOMPARE(animation2.state(), QAbstractAnimation::Stopped); + WAIT_FOR_STOPPED(animation2, 600); #ifdef BAD_TIMER_RESOLUTION if (animation2.m_updateCurrentTimeCount != 3) @@ -229,13 +223,9 @@ void tst_QPauseAnimation::pauseAndPropertyAnimations() QCOMPARE(pause.state(), QAbstractAnimation::Running); QCOMPARE(pause.m_updateCurrentTimeCount, 2); - QTest::qWait(animation.totalDuration() + 100); + const int expectedDuration = animation.totalDuration() + 150; + WAIT_FOR_STOPPED(animation, expectedDuration); -#ifdef BAD_TIMER_RESOLUTION - if (animation.state() != QAbstractAnimation::Stopped) - QEXPECT_FAIL("", timerError, Abort); -#endif - QCOMPARE(animation.state(), QAbstractAnimation::Stopped); QCOMPARE(pause.state(), QAbstractAnimation::Stopped); QVERIFY(pause.m_updateCurrentTimeCount > 3); } @@ -405,13 +395,8 @@ void tst_QPauseAnimation::multipleSequentialGroups() // This is a pretty long animation so it tends to get rather out of sync // when using the consistent timer, so run for an extra half second for good // measure... - QTest::qWait(group.totalDuration() + 500); - -#ifdef BAD_TIMER_RESOLUTION - if (group.state() != QAbstractAnimation::Stopped) - QEXPECT_FAIL("", timerError, Abort); -#endif - QCOMPARE(group.state(), QAbstractAnimation::Stopped); + const int expectedDuration = group.totalDuration() + 550; + WAIT_FOR_STOPPED(group, expectedDuration); #ifdef BAD_TIMER_RESOLUTION if (subgroup1.state() != QAbstractAnimation::Stopped) @@ -449,8 +434,9 @@ void tst_QPauseAnimation::zeroDuration() TestablePauseAnimation animation; animation.setDuration(0); animation.start(); - QTest::qWait(animation.totalDuration() + 100); - QCOMPARE(animation.state(), QAbstractAnimation::Stopped); + const int expectedDuration = animation.totalDuration() + 150; + WAIT_FOR_STOPPED(animation, expectedDuration); + QCOMPARE(animation.m_updateCurrentTimeCount, 1); } -- cgit v1.2.3 From 45948967bd2442d27c7526ec6f74b0df3edbe40a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 23 Jan 2017 11:04:12 +0100 Subject: tst_QSocks5SocketEngine: Refactor tests Rewrite tcpSocketNonBlockingTest() and downloadBigFile() to use lambdas for the slots. This allows for removing the related member variables and slots of the test class and ensures no leaks of sockets or inconsistent values. Add an error handler printing the error message to the flaky downloadBigFile() test. Change-Id: Ieb64063c41e045a1a50a6d074bef01753ee319ef Reviewed-by: Timur Pocheptsov --- .../tst_qsocks5socketengine.cpp | 140 ++++++++------------- 1 file changed, 52 insertions(+), 88 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp index c945d77cda..18da122000 100644 --- a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp +++ b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp @@ -54,7 +54,6 @@ class tst_QSocks5SocketEngine : public QObject, public QAbstractSocketEngineRece private slots: void initTestCase(); - void init(); void construction(); void errorTest_data(); void errorTest(); @@ -74,13 +73,6 @@ private slots: void incomplete(); protected slots: - void tcpSocketNonBlocking_hostFound(); - void tcpSocketNonBlocking_connected(); - void tcpSocketNonBlocking_closed(); - void tcpSocketNonBlocking_readyRead(); - void tcpSocketNonBlocking_bytesWritten(qint64); - void exitLoopSlot(); - void downloadBigFileSlot(); void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); private: @@ -89,11 +81,6 @@ private: void closeNotification() { } void exceptionNotification() { } void connectionNotification() { } - QTcpSocket *tcpSocketNonBlocking_socket; - QStringList tcpSocketNonBlocking_data; - qint64 tcpSocketNonBlocking_totalWritten; - QTcpSocket *tmpSocket; - qint64 bytesAvailable; }; class MiniSocks5ResponseHandler : public QObject @@ -153,12 +140,6 @@ void tst_QSocks5SocketEngine::initTestCase() QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); } -void tst_QSocks5SocketEngine::init() -{ - tmpSocket = 0; - bytesAvailable = 0; -} - //--------------------------------------------------------------------------- void tst_QSocks5SocketEngine::construction() { @@ -631,13 +612,27 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest() { QSocks5SocketEngineHandler socks5; + qint64 tcpSocketNonBlocking_totalWritten = 0; + QStringList tcpSocketNonBlocking_data; QTcpSocket socket; - connect(&socket, SIGNAL(hostFound()), SLOT(tcpSocketNonBlocking_hostFound())); - connect(&socket, SIGNAL(connected()), SLOT(tcpSocketNonBlocking_connected())); - connect(&socket, SIGNAL(disconnected()), SLOT(tcpSocketNonBlocking_closed())); - connect(&socket, SIGNAL(bytesWritten(qint64)), SLOT(tcpSocketNonBlocking_bytesWritten(qint64))); - connect(&socket, SIGNAL(readyRead()), SLOT(tcpSocketNonBlocking_readyRead())); - tcpSocketNonBlocking_socket = &socket; + connect(&socket, &QAbstractSocket::hostFound, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + connect(&socket, &QAbstractSocket::connected, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + connect(&socket, &QIODevice::bytesWritten, + [&tcpSocketNonBlocking_totalWritten] (qint64 written) + { + tcpSocketNonBlocking_totalWritten += written; + QTestEventLoop::instance().exitLoop(); + }); + + connect(&socket, &QIODevice::readyRead, + [&tcpSocketNonBlocking_data, &socket] () + { + while (socket.canReadLine()) + tcpSocketNonBlocking_data.append(socket.readLine()); + QTestEventLoop::instance().exitLoop(); + }); // Connect socket.connectToHost(QtNetworkSettings::serverName(), 143); @@ -725,62 +720,50 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest() QCOMPARE(socket.state(), QTcpSocket::UnconnectedState); } -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_hostFound() -{ - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_connected() -{ - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_readyRead() -{ - while (tcpSocketNonBlocking_socket->canReadLine()) - tcpSocketNonBlocking_data.append(tcpSocketNonBlocking_socket->readLine()); - - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_bytesWritten(qint64 written) -{ - tcpSocketNonBlocking_totalWritten += written; - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_closed() -{ -} - //---------------------------------------------------------------------------------- void tst_QSocks5SocketEngine::downloadBigFile() { QSocks5SocketEngineHandler socks5; - if (tmpSocket) - delete tmpSocket; - tmpSocket = new QTcpSocket; - - connect(tmpSocket, SIGNAL(connected()), SLOT(exitLoopSlot())); - connect(tmpSocket, SIGNAL(readyRead()), SLOT(downloadBigFileSlot())); - - tmpSocket->connectToHost(QtNetworkSettings::serverName(), 80); + QTcpSocket socket; + qint64 bytesAvailable = 0; + connect(&socket, &QAbstractSocket::connected, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + connect(&socket, &QIODevice::readyRead, + [&socket, &bytesAvailable] () + { + const QByteArray tmp = socket.readAll(); + int correction = tmp.indexOf(char(0), 0); //skip header + if (correction == -1) + correction = 0; + bytesAvailable += (tmp.size() - correction); + if (bytesAvailable >= 10000000) + QTestEventLoop::instance().exitLoop(); + }); + + connect(&socket, QOverload::of(&QAbstractSocket::error), + [&socket] (QAbstractSocket::SocketError errorCode) + { + qWarning().noquote().nospace() << QTest::currentTestFunction() + << ": error " << errorCode << ": " << socket.errorString(); + }); + + socket.connectToHost(QtNetworkSettings::serverName(), 80); QTestEventLoop::instance().enterLoop(30); if (QTestEventLoop::instance().timeout()) QFAIL("Network operation timed out"); QByteArray hostName = QtNetworkSettings::serverName().toLatin1(); - QCOMPARE(tmpSocket->state(), QAbstractSocket::ConnectedState); - QVERIFY(tmpSocket->write("GET /qtest/mediumfile HTTP/1.0\r\n") > 0); - QVERIFY(tmpSocket->write("HOST: ") > 0); - QVERIFY(tmpSocket->write(hostName.data()) > 0); - QVERIFY(tmpSocket->write("\r\n") > 0); - QVERIFY(tmpSocket->write("\r\n") > 0); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + QVERIFY(socket.write("GET /qtest/mediumfile HTTP/1.0\r\n") > 0); + QVERIFY(socket.write("HOST: ") > 0); + QVERIFY(socket.write(hostName.data()) > 0); + QVERIFY(socket.write("\r\n") > 0); + QVERIFY(socket.write("\r\n") > 0); + - bytesAvailable = 0; QTime stopWatch; stopWatch.start(); @@ -791,31 +774,12 @@ void tst_QSocks5SocketEngine::downloadBigFile() QCOMPARE(bytesAvailable, qint64(10000000)); - QCOMPARE(tmpSocket->state(), QAbstractSocket::ConnectedState); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); /*qDebug("\t\t%.1fMB/%.1fs: %.1fMB/s", bytesAvailable / (1024.0 * 1024.0), stopWatch.elapsed() / 1024.0, (bytesAvailable / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));*/ - - delete tmpSocket; - tmpSocket = 0; -} - -void tst_QSocks5SocketEngine::exitLoopSlot() -{ - QTestEventLoop::instance().exitLoop(); -} - - -void tst_QSocks5SocketEngine::downloadBigFileSlot() -{ - QByteArray tmp=tmpSocket->readAll(); - int correction=tmp.indexOf((char)0,0); //skip header - if (correction==-1) correction=0; - bytesAvailable += (tmp.size()-correction); - if (bytesAvailable >= 10000000) - QTestEventLoop::instance().exitLoop(); } void tst_QSocks5SocketEngine::passwordAuth() -- cgit v1.2.3 From 59780d132aa114f8b7edfb17a24b91d09e38236d Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Mon, 23 Jan 2017 15:25:38 -0800 Subject: Cocoa: fix crash regression in qt_mac_create_nsimage() The regression was introduced in d8857f21ac264. The original change was meant to fix support for SVG icons, but failed to take into account a valid QIcon with no sizes, but which is also unable to create a pixmap for the requested size. Task-number: QTBUG-58344 Change-Id: I7ac1dbfaf6e3dab8581fe4b33c814e2517fcdba8 Reviewed-by: Andy Shaw --- tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index f19d7619cc..e3af0135e7 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -136,6 +136,7 @@ private slots: void QTBUG_57404_existingMenuItemException(); #endif void taskQTBUG55966_subMenuRemoved(); + void QTBUG_58344_invalidIcon(); void platformMenu(); @@ -1594,5 +1595,14 @@ void tst_QMenuBar::taskQTBUG55966_subMenuRemoved() QTest::qWait(500); } +void tst_QMenuBar::QTBUG_58344_invalidIcon() +{ + QMenuBar menuBar; + QMenu menu("menu"); + menu.addAction(QIcon("crash.png"), "crash"); + menuBar.addMenu(&menu); + // No crash, all fine. +} + QTEST_MAIN(tst_QMenuBar) #include "tst_qmenubar.moc" -- cgit v1.2.3 From a8a74fe81acab07bfe068bff398555804629a88c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 25 Jan 2017 11:21:32 +0100 Subject: Stabilize tst_QPropertyAnimation::noStartValue() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the qWait() and introduce a QTRY_COMPARE() checking for the end value first. Task-number: QTBUG-58402 Change-Id: I2d3758178de5f67881008f28c406076ad27c4a90 Reviewed-by: Jędrzej Nowacki --- .../corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp index c1a8fde504..b0b0a307e9 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp @@ -441,10 +441,8 @@ void tst_QPropertyAnimation::noStartValue() a.setDuration(250); a.start(); - QTest::qWait(300); - - QTRY_COMPARE(o.values.first(), 42); - QCOMPARE(o.values.last(), 420); + QTRY_COMPARE(o.values.value(o.values.size() - 1, -1), 420); + QCOMPARE(o.values.first(), 42); } void tst_QPropertyAnimation::noStartValueWithLoop() -- cgit v1.2.3 From 374a173d1417a9f8c313088420cb1b792fe45977 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 18 Jan 2017 15:14:45 +0100 Subject: Improve QTest::qWait() precision and switch to QDeadlineTimer Do not wait up to the timeout ms after already having waited several times. At the same time upgrade to using the QDeadlineTimer which is designed for this purpose. Change-Id: Iaf5e4f4655605d5143ce91040c6eb6706752e504 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp index 383f357206..b68c582732 100644 --- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp +++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp @@ -189,7 +189,7 @@ void tst_QTimeLine::frameRate() void tst_QTimeLine::value() { - QTimeLine timeLine(5000); + QTimeLine timeLine(4500); // Should be at least 5% under 5000ms QCOMPARE(timeLine.currentValue(), 0.0); // Default speed -- cgit v1.2.3 From f823af43f243b1848fd4a838847317d0ff6d4fdf Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 10 Nov 2016 14:57:04 +0100 Subject: QVariant of nullptr should always be null Implements isNull for QVariants of a nullptr so they always return true to isNull(), instead of depending on how they were constructed. Task-number: QTBUG-58296 Change-Id: Ibddec795cdadedef7e17d22c265c29e752d8f99f Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 75fa424ab1..3a51e67768 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -400,6 +400,17 @@ void tst_QVariant::isNull() QVERIFY( !varLL.isNull() ); QVariant var7(QString::null); QVERIFY(var7.isNull()); + var7 = QVariant::fromValue(QString::null); + QVERIFY(var7.isNull()); + + QVariant var8(QMetaType::Nullptr, nullptr); + QVERIFY(var8.isNull()); + var8 = QVariant::fromValue(nullptr); + QVERIFY(var8.isNull()); + QVariant var9 = QVariant(QJsonValue(QJsonValue::Null)); + QVERIFY(var9.isNull()); + var9 = QVariant::fromValue(QJsonValue(QJsonValue::Null)); + QVERIFY(var9.isNull()); } void tst_QVariant::swap() -- cgit v1.2.3 From 17e672a67ed2ba6c8ec3952ff4ab255cb45fcce6 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 11 Nov 2016 13:33:20 +0100 Subject: Use QImage::reinterpretAsFormat in QPixmap Use the new QImage method instead of operating on private API. At the same time the code is improved to ensure the QImage is detached. Change-Id: Ia015c0bb18d7bc62da38397594730254843e5a0d Reviewed-by: Eirik Aavitsland --- tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index ad7de09c48..72609d4095 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -99,6 +99,7 @@ private slots: void task_51271(); void convertFromImageNoDetach(); + void convertFromImageNoDetach2(); void convertFromImageDetach(); void convertFromImageCacheKey(); @@ -766,6 +767,33 @@ void tst_QPixmap::convertFromImageNoDetach() QCOMPARE(constOrig.bits(), constCopy.bits()); } +void tst_QPixmap::convertFromImageNoDetach2() +{ + QPixmap randomPixmap(10, 10); + if (randomPixmap.handle()->classId() != QPlatformPixmap::RasterClass) + QSKIP("Test only valid for raster pixmaps"); + + //first get the screen format + QImage::Format screenFormat = randomPixmap.toImage().format(); + QVERIFY(screenFormat != QImage::Format_Invalid); + if (screenFormat != QImage::Format_RGB32 && + screenFormat != QImage::Format_ARGB32_Premultiplied) + QSKIP("Test only valid for platforms with RGB32 pixmaps"); + + QImage orig(100,100, QImage::Format_ARGB32_Premultiplied); + orig.fill(Qt::white); + + const uchar *origBits = orig.constBits(); + + QPixmap pix = QPixmap::fromImage(std::move(orig)); + QImage copy = pix.toImage(); + + QVERIFY(!copy.hasAlphaChannel()); + QCOMPARE(copy.format(), QImage::Format_RGB32); + + QCOMPARE(origBits, copy.constBits()); +} + void tst_QPixmap::convertFromImageDetach() { QImage img(10,10, QImage::Format_RGB32); -- cgit v1.2.3 From fa15162700a18ff243de46954bb613988c199ce7 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 24 Jan 2017 17:06:03 +0100 Subject: Fix QString comparison on Aarch64 There was an off-by-one error in the while loop for aarch64: we start counting at 0 for the first position, so the last valid input position is "a+7", not 8. This wasn't covered by the tests, nor was the SSE2 version, so now there are also tests for both versions. Change-Id: I7eb8c5708e6179f45ea56885b0e66e1a37969c1d Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 414ba2d8cf..6ed7b74277 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -6070,6 +6070,14 @@ void tst_QString::compare_data() lower += QChar(QChar::lowSurrogate(0x10428)); QTest::newRow("data8") << upper << lower << -1 << 0; + QTest::newRow("vectorized-boundaries-7") << QString("1234567") << QString("abcdefg") << -1 << -1; + QTest::newRow("vectorized-boundaries-8") << QString("12345678") << QString("abcdefgh") << -1 << -1; + QTest::newRow("vectorized-boundaries-9") << QString("123456789") << QString("abcdefghi") << -1 << -1; + + QTest::newRow("vectorized-boundaries-15") << QString("123456789012345") << QString("abcdefghiklmnop") << -1 << -1; + QTest::newRow("vectorized-boundaries-16") << QString("1234567890123456") << QString("abcdefghiklmnopq") << -1 << -1; + QTest::newRow("vectorized-boundaries-17") << QString("12345678901234567") << QString("abcdefghiklmnopqr") << -1 << -1; + // embedded nulls // These don't work as of now. It's OK that these don't work since \0 is not a valid unicode /*QTest::newRow("data10") << QString(QByteArray("\0", 1)) << QString(QByteArray("\0", 1)) << 0 << 0; -- cgit v1.2.3 From a9603a4088ec055c3d1588c14e09e14bf7e2a0e8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 10:22:59 +0100 Subject: tst_qgraphicsview: use new QTest::addRow() more ... for calculated test data names. That involved removing the leading ", " from test name literals (folding it into the format string) and porting from some QString code to QByteArray to make the result usable with addRow(), which does not support %ls... Change-Id: Icb2344778203f10939ae46b9e46872101f3878a9 Reviewed-by: Friedemann Kleint Reviewed-by: Edward Welbourne --- .../qgraphicsview/tst_qgraphicsview.cpp | 8 +- .../qgraphicsview/tst_qgraphicsview_2.cpp | 210 ++++++++++----------- 2 files changed, 109 insertions(+), 109 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index c8bdcbde09..5ab24d6878 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -2885,7 +2885,7 @@ public: void tst_QGraphicsView::scrollBarRanges() { - QFETCH(QString, style); + QFETCH(QByteArray, style); QFETCH(QSize, viewportSize); QFETCH(QRectF, sceneRect); QFETCH(ScrollBarCount, sceneRectOffsetFactors); @@ -2898,7 +2898,7 @@ void tst_QGraphicsView::scrollBarRanges() QFETCH(ExpectedValueDescription, vmax); QFETCH(bool, useStyledPanel); - if (useStyledPanel && style == QStringLiteral("Macintosh") && platformName == QStringLiteral("cocoa")) + if (useStyledPanel && style == "Macintosh" && platformName == QStringLiteral("cocoa")) QSKIP("Insignificant on OSX"); QScopedPointer stylePtr; @@ -2909,10 +2909,10 @@ void tst_QGraphicsView::scrollBarRanges() view.setTransform(transform); view.setFrameStyle(useStyledPanel ? QFrame::StyledPanel : QFrame::NoFrame); - if (style == QString("motif")) + if (style == "motif") stylePtr.reset(new FauxMotifStyle); else - stylePtr.reset(QStyleFactory::create(style)); + stylePtr.reset(QStyleFactory::create(QLatin1String(style))); view.setStyle(stylePtr.data()); view.setStyleSheet(" "); // enables style propagation ;-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp index 875f671e76..9550655868 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp @@ -44,9 +44,8 @@ Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(Qt::ScrollBarPolicy) Q_DECLARE_METATYPE(ScrollBarCount) -static void _scrollBarRanges_addTestData(const QString &style, bool styled) +static void _scrollBarRanges_addTestData(const QByteArray &style, bool styled) { - const QString styleString = styled ? style + ", Styled" : style; const int viewWidth = 250; const int viewHeight = 100; @@ -59,7 +58,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription hmin, hmax, vmin, vmax; } data [] = { { - ", 1", + "1", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -71,7 +70,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 2", + "2", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -83,7 +82,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 3", + "3", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -95,7 +94,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100, 1, 1), }, { - ", 4", + "4", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -107,7 +106,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 5", + "5", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -119,7 +118,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 6", + "6", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -131,7 +130,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 7", + "7", QRectF(0, 0, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -143,7 +142,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1, 1, 1), }, { - ", 8", + "8", QRectF(0, 0, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -155,7 +154,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1, 1, 1), }, { - ", 9", + "9", QRectF(0, 0, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -167,7 +166,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(101, 1, 1), }, { - ", 10", + "10", QRectF(-101, -101, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -179,7 +178,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 11", + "11", QRectF(-101, -101, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -191,7 +190,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 12", + "12", QRectF(-101, -101, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -203,7 +202,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 13", + "13", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -215,7 +214,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 2, 1), }, { - ", 14", + "14", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -227,7 +226,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 2, 1), }, { - ", 15", + "15", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 1, 1), 1, @@ -239,7 +238,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100, 2, 1), }, { - ", 16", + "16", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -251,7 +250,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 17", + "17", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -263,7 +262,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 18", + "18", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(-1, -1, 1, 1), 1, @@ -275,7 +274,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 1 x2", + "1 x2", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -287,7 +286,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight, 1, 1), }, { - ", 2 x2", + "2 x2", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -299,7 +298,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight, 1, 1), }, { - ", 3 x2", + "3 x2", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -311,7 +310,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight + 200, 1, 1), }, { - ", 4 x2", + "4 x2", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -323,7 +322,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200, 1, 1), }, { - ", 5 x2", + "5 x2", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -335,7 +334,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200, 1, 1), }, { - ", 6 x2", + "6 x2", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -347,7 +346,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight, 1, 1), }, { - ", 1 No ScrollBars", + "1 No ScrollBars", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -359,7 +358,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 2 No ScrollBars", + "2 No ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -371,7 +370,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 3 No ScrollBars", + "3 No ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -383,7 +382,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100), }, { - ", 4 No ScrollBars", + "4 No ScrollBars", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -395,7 +394,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 5 No ScrollBars", + "5 No ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -407,7 +406,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 6 No ScrollBars", + "6 No ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -419,7 +418,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 7 No ScrollBars", + "7 No ScrollBars", QRectF(0, 0, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -431,7 +430,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1), }, { - ", 8 No ScrollBars", + "8 No ScrollBars", QRectF(0, 0, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -443,7 +442,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1), }, { - ", 9 No ScrollBars", + "9 No ScrollBars", QRectF(0, 0, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -455,7 +454,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(101), }, { - ", 10 No ScrollBars", + "10 No ScrollBars", QRectF(-101, -101, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -467,7 +466,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 11 No ScrollBars", + "11 No ScrollBars", QRectF(-101, -101, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -479,7 +478,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 12 No ScrollBars", + "12 No ScrollBars", QRectF(-101, -101, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -491,7 +490,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 13 No ScrollBars", + "13 No ScrollBars", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -503,7 +502,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1), }, { - ", 14 No ScrollBars", + "14 No ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -515,7 +514,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1), }, { - ", 15 No ScrollBars", + "15 No ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 1, 1), 1, @@ -527,7 +526,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100, 1), }, { - ", 16 No ScrollBars", + "16 No ScrollBars", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -539,7 +538,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 17 No ScrollBars", + "17 No ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -551,7 +550,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 18 No ScrollBars", + "18 No ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(-1, -1, 1, 1), 1, @@ -563,7 +562,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 1 x2 No ScrollBars", + "1 x2 No ScrollBars", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -575,7 +574,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight), }, { - ", 2 x2 No ScrollBars", + "2 x2 No ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -587,7 +586,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight), }, { - ", 3 x2 No ScrollBars", + "3 x2 No ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -599,7 +598,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight + 200), }, { - ", 4 x2 No ScrollBars", + "4 x2 No ScrollBars", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -611,7 +610,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200), }, { - ", 5 x2 No ScrollBars", + "5 x2 No ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -623,7 +622,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200), }, { - ", 6 x2 No ScrollBars", + "6 x2 No ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -635,7 +634,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight), }, { - ", 1 Always ScrollBars", + "1 Always ScrollBars", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -647,7 +646,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 2 Always ScrollBars", + "2 Always ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -659,7 +658,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 3 Always ScrollBars", + "3 Always ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -671,7 +670,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100, 1, 1), }, { - ", 4 Always ScrollBars", + "4 Always ScrollBars", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -683,7 +682,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 5 Always ScrollBars", + "5 Always ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -695,7 +694,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 6 Always ScrollBars", + "6 Always ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -707,7 +706,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 7 Always ScrollBars", + "7 Always ScrollBars", QRectF(0, 0, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -719,7 +718,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1, 1, 1), }, { - ", 8 Always ScrollBars", + "8 Always ScrollBars", QRectF(0, 0, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -731,7 +730,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1, 1, 1), }, { - ", 9 Always ScrollBars", + "9 Always ScrollBars", QRectF(0, 0, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -743,7 +742,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(101, 1, 1), }, { - ", 10 Always ScrollBars", + "10 Always ScrollBars", QRectF(-101, -101, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -755,7 +754,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 11 Always ScrollBars", + "11 Always ScrollBars", QRectF(-101, -101, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -767,7 +766,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 12 Always ScrollBars", + "12 Always ScrollBars", QRectF(-101, -101, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -779,7 +778,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 13 Always ScrollBars", + "13 Always ScrollBars", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -791,7 +790,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 2, 1), }, { - ", 14 Always ScrollBars", + "14 Always ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -803,7 +802,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 2, 1), }, { - ", 15 Always ScrollBars", + "15 Always ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 1, 1), 1, @@ -815,7 +814,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100, 2, 1), }, { - ", 16 Always ScrollBars", + "16 Always ScrollBars", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -827,7 +826,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 17 Always ScrollBars", + "17 Always ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -839,7 +838,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100, 1, 1), }, { - ", 18 Always ScrollBars", + "18 Always ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(-1, -1, 1, 1), 1, @@ -851,7 +850,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1, 1), }, { - ", 1 x2 Always ScrollBars", + "1 x2 Always ScrollBars", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -863,7 +862,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight, 1, 1), }, { - ", 2 x2 Always ScrollBars", + "2 x2 Always ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -875,7 +874,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight, 1, 1), }, { - ", 3 x2 Always ScrollBars", + "3 x2 Always ScrollBars", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -887,7 +886,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight + 200, 1, 1), }, { - ", 4 x2 Always ScrollBars", + "4 x2 Always ScrollBars", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -899,7 +898,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200, 1, 1), }, { - ", 5 x2 Always ScrollBars", + "5 x2 Always ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -911,7 +910,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200, 1, 1), }, { - ", 6 x2 Always ScrollBars", + "6 x2 Always ScrollBars", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -923,7 +922,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight, 1, 1), }, { - ", 1 Vertical Only", + "1 Vertical Only", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -935,7 +934,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 2 Vertical Only", + "2 Vertical Only", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -947,7 +946,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 3 Vertical Only", + "3 Vertical Only", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -959,7 +958,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100), }, { - ", 4 Vertical Only", + "4 Vertical Only", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -971,7 +970,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 5 Vertical Only", + "5 Vertical Only", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 1, @@ -983,7 +982,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 6 Vertical Only", + "6 Vertical Only", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 1, @@ -995,7 +994,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 7 Vertical Only", + "7 Vertical Only", QRectF(0, 0, viewWidth + 1, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -1007,7 +1006,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1), }, { - ", 8 Vertical Only", + "8 Vertical Only", QRectF(0, 0, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -1019,7 +1018,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(1), }, { - ", 9 Vertical Only", + "9 Vertical Only", QRectF(0, 0, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -1031,7 +1030,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(101), }, { - ", 10 Vertical Only", + "10 Vertical Only", QRectF(-101, -101, viewWidth + 1, viewHeight +1), ScrollBarCount(0, 0, 0, 0), 1, @@ -1043,7 +1042,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 11 Vertical Only", + "11 Vertical Only", QRectF(-101, -101, viewWidth + 51, viewHeight + 1), ScrollBarCount(0, 0, 0, 0), 1, @@ -1055,7 +1054,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 12 Vertical Only", + "12 Vertical Only", QRectF(-101, -101, viewWidth + 51, viewHeight + 101), ScrollBarCount(0, 0, 0, 0), 1, @@ -1067,7 +1066,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 13 Vertical Only", + "13 Vertical Only", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -1079,7 +1078,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1), }, { - ", 14 Vertical Only", + "14 Vertical Only", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 1, 1), 1, @@ -1091,7 +1090,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(0, 1), }, { - ", 15 Vertical Only", + "15 Vertical Only", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 1, 1), 1, @@ -1103,7 +1102,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(100, 1), }, { - ", 16 Vertical Only", + "16 Vertical Only", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -1115,7 +1114,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 17 Vertical Only", + "17 Vertical Only", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(-1, -1, 1, 1), 1, @@ -1127,7 +1126,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(-100), }, { - ", 18 Vertical Only", + "18 Vertical Only", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(-1, -1, 1, 1), 1, @@ -1139,7 +1138,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(), }, { - ", 1 x2 Vertical Only", + "1 x2 Vertical Only", QRectF(0, 0, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -1151,7 +1150,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight), }, { - ", 2 x2 Vertical Only", + "2 x2 Vertical Only", QRectF(0, 0, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -1163,7 +1162,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight), }, { - ", 3 x2 Vertical Only", + "3 x2 Vertical Only", QRectF(0, 0, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -1175,7 +1174,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight + 200), }, { - ", 4 x2 Vertical Only", + "4 x2 Vertical Only", QRectF(-100, -100, viewWidth, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -1187,7 +1186,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200), }, { - ", 5 x2 Vertical Only", + "5 x2 Vertical Only", QRectF(-100, -100, viewWidth + 50, viewHeight), ScrollBarCount(0, 0, 0, 0), 2, @@ -1199,7 +1198,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) ExpectedValueDescription(viewHeight - 200), }, { - ", 6 x2 Vertical Only", + "6 x2 Vertical Only", QRectF(-100, -100, viewWidth + 50, viewHeight + 100), ScrollBarCount(0, 0, 0, 0), 2, @@ -1215,7 +1214,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) const QSize viewSize(viewWidth, viewHeight); for (const Data &e : data) { - QTest::newRow(qPrintable(styleString + QLatin1String(e.name))) + QTest::addRow("%s%s, %s", style.data(), styled ? ", Styled" : "", e.name) << style << viewSize << e.sceneRect << e.sceneRectOffsetFactors @@ -1229,7 +1228,7 @@ static void _scrollBarRanges_addTestData(const QString &style, bool styled) void _scrollBarRanges_data() { - QTest::addColumn("style"); + QTest::addColumn("style"); QTest::addColumn("viewportSize"); QTest::addColumn("sceneRect"); QTest::addColumn("sceneRectOffsetFactors"); @@ -1242,14 +1241,15 @@ void _scrollBarRanges_data() QTest::addColumn("vmax"); QTest::addColumn("useStyledPanel"); - foreach (const QString &style, QStyleFactory::keys()) { - _scrollBarRanges_addTestData(style, false); - _scrollBarRanges_addTestData(style, true); + const auto styles = QStyleFactory::keys(); + for (const QString &style : styles) { + _scrollBarRanges_addTestData(style.toLatin1(), false); + _scrollBarRanges_addTestData(style.toLatin1(), true); } const QScreen *screen = QGuiApplication::primaryScreen(); if (screen && qFuzzyCompare((double)screen->logicalDotsPerInchX(), 96.0)) { - _scrollBarRanges_addTestData(QString("motif"), false); - _scrollBarRanges_addTestData(QString("motif"), true); + _scrollBarRanges_addTestData("motif", false); + _scrollBarRanges_addTestData("motif", true); } } -- cgit v1.2.3 From 1f814caca3836c43a415c219ef57b1d046321635 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 10:39:50 +0100 Subject: Plug memleaks in tst_QAbstractItemView Styles need to be deleted manually... Change-Id: Ic4193d22a57801127e994062cade7cb9ef6f34d8 Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index bd6733e2d0..426db265ae 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -1567,7 +1567,7 @@ void tst_QAbstractItemView::testChangeEditorState() QTableView view; view.setEditTriggers(QAbstractItemView::CurrentChanged); - view.setItemDelegate(new StateChangeDelegate); + view.setItemDelegate(new StateChangeDelegate(&view)); view.setModel(&model); centerOnScreen(&view); moveCursorAway(&view); @@ -1941,7 +1941,8 @@ void tst_QAbstractItemView::QTBUG50102_SH_ItemView_ScrollMode() QCOMPARE(view.horizontalScrollMode(), styleScrollMode); // Change style, get new value - view.setStyle(new ScrollModeProxyStyle(styleScrollMode)); + ScrollModeProxyStyle proxyStyle1(styleScrollMode); + view.setStyle(&proxyStyle1); auto proxyScrollMode = static_cast(view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view, 0)); QVERIFY(styleScrollMode != proxyScrollMode); QCOMPARE(view.verticalScrollMode(), proxyScrollMode); @@ -1953,7 +1954,8 @@ void tst_QAbstractItemView::QTBUG50102_SH_ItemView_ScrollMode() QCOMPARE(view.horizontalScrollMode(), proxyScrollMode); // Change style, won't change value for vertical, will change for horizontal - view.setStyle(new ScrollModeProxyStyle(proxyScrollMode)); + ScrollModeProxyStyle proxyStyle2(proxyScrollMode); + view.setStyle(&proxyStyle2); QCOMPARE(view.verticalScrollMode(), proxyScrollMode); QCOMPARE(view.horizontalScrollMode(), styleScrollMode); } -- cgit v1.2.3 From 9064d0b8a8da8ddb2223c405e5a1359288d49714 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 11:34:57 +0100 Subject: tst_QTreeWidget: plug memleaks Taken QTreeWidgetItems need to be deleted, as do items created without a parent, and widgets without parent. Change-Id: I7ffa69903af9a1b92ba308f9f9416aec1d6d975f Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../itemviews/qtreewidget/tst_qtreewidget.cpp | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index fcffaa0eb9..f20805f97e 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -554,16 +554,16 @@ void tst_QTreeWidget::removeChild() QFETCH(int, childCount); QFETCH(int, removeAt); - QTreeWidgetItem *root = new QTreeWidgetItem; + const QScopedPointer root(new QTreeWidgetItem); for (int i = 0; i < childCount; ++i) - new QTreeWidgetItem(root, QStringList(QString::number(i))); + new QTreeWidgetItem(root.data(), QStringList(QString::number(i))); QCOMPARE(root->childCount(), childCount); for (int j = 0; j < childCount; ++j) QCOMPARE(root->child(j)->text(0), QString::number(j)); - QTreeWidgetItem *remove = root->child(removeAt); - root->removeChild(remove); + const QScopedPointer remove(root->child(removeAt)); + root->removeChild(remove.data()); QCOMPARE(root->childCount(), childCount - 1); for (int k = 0; k < childCount; ++k) { @@ -574,7 +574,6 @@ void tst_QTreeWidget::removeChild() else if (k > removeAt) QCOMPARE(root->child(k - 1)->text(0), QString::number(k)); } - delete root; } void tst_QTreeWidget::setItemHidden() @@ -1954,9 +1953,9 @@ void tst_QTreeWidget::itemData() void tst_QTreeWidget::enableDisable() { - QTreeWidgetItem *itm = new QTreeWidgetItem(); + const QScopedPointer itm(new QTreeWidgetItem); for (int i = 0; i < 10; ++i) - new QTreeWidgetItem(itm); + new QTreeWidgetItem(itm.data()); // make sure all items are enabled QVERIFY(itm->flags() & Qt::ItemIsEnabled); @@ -2720,7 +2719,10 @@ void tst_QTreeWidget::setDisabled() children.append(new QTreeWidgetItem()); children.append(new QTreeWidgetItem()); children.append(new QTreeWidgetItem()); - i1 = top->takeChild(0); + { + const QScopedPointer taken(top->takeChild(0)); + QCOMPARE(taken.data(), i1); + } top->addChildren(children); QCOMPARE(top->child(0)->isDisabled(), false); @@ -2732,16 +2734,21 @@ void tst_QTreeWidget::setDisabled() QCOMPARE(top->child(1)->isDisabled(), true); QCOMPARE(top->child(1)->isDisabled(), true); - children = top->takeChildren(); - QCOMPARE(children.at(0)->isDisabled(), false); - QCOMPARE(children.at(1)->isDisabled(), false); - QCOMPARE(children.at(1)->isDisabled(), false); + struct Deleter { + QList items; + explicit Deleter(QList items) : items(std::move(items)) {} + ~Deleter() { qDeleteAll(items); } + }; + const Deleter takenChildren(top->takeChildren()); + QCOMPARE(takenChildren.items[0]->isDisabled(), false); + QCOMPARE(takenChildren.items[1]->isDisabled(), false); + QCOMPARE(takenChildren.items[1]->isDisabled(), false); } void tst_QTreeWidget::removeSelectedItem() { - QTreeWidget *w = new QTreeWidget(); + const QScopedPointer w(new QTreeWidget); w->setSortingEnabled(true); QTreeWidgetItem *first = new QTreeWidgetItem(); @@ -2767,15 +2774,13 @@ void tst_QTreeWidget::removeSelectedItem() QCOMPARE(selModel->hasSelection(), true); QCOMPARE(selModel->selectedRows().count(), 1); - QTreeWidgetItem *taken = w->takeTopLevelItem(2); + const QScopedPointer taken(w->takeTopLevelItem(2)); QCOMPARE(taken->text(0), QLatin1String("C")); QCOMPARE(selModel->hasSelection(), false); QCOMPARE(selModel->selectedRows().count(), 0); QItemSelection sel = selModel->selection(); QCOMPARE(selModel->isSelected(w->model()->index(0,0)), false); - - delete w; } class AnotherTreeWidget : public QTreeWidget @@ -2934,11 +2939,11 @@ void tst_QTreeWidget::sortAndSelect() void tst_QTreeWidget::defaultRowSizes() { - QTreeWidget *tw = new QTreeWidget(); + const QScopedPointer tw(new QTreeWidget); tw->setIconSize(QSize(50, 50)); tw->setColumnCount(6); for (int i=0; i<10; ++i) { - QTreeWidgetItem *it = new QTreeWidgetItem(tw); + auto it = new QTreeWidgetItem(tw.data()); for (int j=0; jcolumnCount() - 1; ++j) { it->setText(j, "This is a test"); } -- cgit v1.2.3 From 7e6e92063324e589aa01928efae72b16f2823481 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 11:45:25 +0100 Subject: Plug memleaks in tst_QTreeView Forgot to delete QAIMs without parent. Change-Id: I9c914e841123ee250fb977c45a84870463288d9b Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 80ef0879cc..e2886cfcfe 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -3796,25 +3796,24 @@ void tst_QTreeView::task248022_changeSelection() void tst_QTreeView::task245654_changeModelAndExpandAll() { QTreeView view; - QStandardItemModel *model = new QStandardItemModel; + QScopedPointer model(new QStandardItemModel); QStandardItem *top = new QStandardItem("top"); QStandardItem *sub = new QStandardItem("sub"); top->appendRow(sub); model->appendRow(top); - view.setModel(model); + view.setModel(model.data()); view.expandAll(); QApplication::processEvents(); QVERIFY(view.isExpanded(top->index())); //now let's try to delete the model //then repopulate and expand again - delete model; - model = new QStandardItemModel; + model.reset(new QStandardItemModel); top = new QStandardItem("top"); sub = new QStandardItem("sub"); top->appendRow(sub); model->appendRow(top); - view.setModel(model); + view.setModel(model.data()); view.expandAll(); QApplication::processEvents(); QVERIFY(view.isExpanded(top->index())); -- cgit v1.2.3 From e4b19bfb94630c7da37d150955ccc246498966cf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 15:04:34 +0100 Subject: Plug memleaks in tst_QHeaderView The char* returned from QTest::toString() calls must be manually delete[]ed. Change-Id: Iad078e8741e3e97693b1a417693f414b3fb3ec09 Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 1078dcc2e9..7bfec2831d 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -2523,7 +2523,8 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare const bool sanity_checks = true; if (sanity_checks) { QString msg = QString("sanity problem at ") + sline; - char *verifytext = QTest::toString(msg); + const QScopedArrayPointer holder(QTest::toString(msg)); + const auto verifytext = holder.data(); QVERIFY2(m_tableview->model()->rowCount() == view->count() , verifytext); QVERIFY2(view->visualIndex(lastindex + 1) <= 0, verifytext); // there is no such index in model @@ -2555,7 +2556,8 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare msg += istr(chk_visual) + istr(chk_logical) + istr(chk_sizes) + istr(chk_hidden_size) + istr(chk_lookup_visual) + istr(chk_lookup_logical) + istr(header_lenght, false) + "};"; - char *verifytext = QTest::toString(msg); + const QScopedArrayPointer holder(QTest::toString(msg)); + const auto verifytext = holder.data(); QVERIFY2(chk_visual == x[0], verifytext); QVERIFY2(chk_logical == x[1], verifytext); -- cgit v1.2.3 From e15cb86b3bc2cb1ed777a741f4b9e23fdb829249 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 15:07:46 +0100 Subject: Plug remaining memleaks in tests/auto/widgets/itemviews ... on Linux AMD64 builds. Pass QObject parents to QObjects otherwise leaked. Change-Id: Ia4f0ad2fdc4ef62a3d35a2cfca74965f79692da3 Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp | 2 +- tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp | 2 +- tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 0720a4f766..5b353bb2ae 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -1350,7 +1350,7 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck() } QTableView view; view.setModel(&model); - view.setItemDelegate(new TestItemDelegate); + view.setItemDelegate(new TestItemDelegate(&view)); view.show(); view.selectAll(); QVERIFY(QTest::qWaitForWindowExposed(&view)); diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 6eed21abb2..a89f8f3c8a 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -1488,7 +1488,7 @@ void tst_QListView::task203585_selectAll() //we make sure that "select all" doesn't select the hidden items QListView view; view.setSelectionMode(QAbstractItemView::ExtendedSelection); - view.setModel(new QStringListModel( QStringList() << "foo")); + view.setModel(new QStringListModel(QStringList() << "foo", &view)); view.setRowHidden(0, true); view.selectAll(); QVERIFY(view.selectionModel()->selectedIndexes().isEmpty()); diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index eb93e4c167..6547bb8985 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -1629,7 +1629,7 @@ void tst_QListWidget::QTBUG14363_completerWithAnyKeyPressedEditTriggers() { QListWidget listWidget; listWidget.setEditTriggers(QAbstractItemView::AnyKeyPressed); - listWidget.setItemDelegate(new ItemDelegate); + listWidget.setItemDelegate(new ItemDelegate(&listWidget)); QListWidgetItem *item = new QListWidgetItem(QLatin1String("select an item (don't start editing)"), &listWidget); item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsEditable); new QListWidgetItem(QLatin1String("try to type the letter 'c'"), &listWidget); -- cgit v1.2.3 From 940d667eb41958de120ee759323c67bd7385af0d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 4 Oct 2016 19:49:58 +0200 Subject: Plug leaks in tests/auto/dbus In tst_QDBusMetaObject::types(), hold a QMetaObject obtained from QDBusMetaObject::createMetaObject() in a QScopedPointer instead of leaking it. Use correct return value type. This fixes the remaining errors in GCC 6.1 Linux ASan runs of tests/auto/dbus. Change-Id: I1df7f8e42d45f40ecf381fe7b684a8ab5ebee675 Reviewed-by: Alex Blasche Reviewed-by: Thiago Macieira --- tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp b/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp index cb1c9401ba..a4afae4b46 100644 --- a/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp +++ b/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp @@ -370,8 +370,7 @@ void tst_QDBusMetaObject::types() QDBusError error; - QMetaObject *result = QDBusMetaObject::createMetaObject("local.Interface", xml, - map, error); + const QScopedPointer result(QDBusMetaObject::createMetaObject("local.Interface", xml, map, error)); QVERIFY2(result, qPrintable(error.message())); QCOMPARE(result->enumeratorCount(), 0); -- cgit v1.2.3 From 8d752b5151c9890b76d50c4a479ab32dd0eca10c Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 26 Jan 2017 10:28:41 +0100 Subject: Accept all formatting characters as valid input Amends 7896ae052ad2c0c6ae2ebfc64cc2f525185198a8. The previous change focused only on ZWJ and ZWNJ, but there are many other formatting characters that we need to support and that may be rejected by the German keyboard-hack. This opens up for all characters in the Other_Format category. Task-number: QTBUG-58364 Change-Id: Idd967a9ae5b12060c851f6030b7e019508561696 Reviewed-by: Simon Hausmann Reviewed-by: Lars Knoll --- .../gui/text/qinputcontrol/tst_qinputcontrol.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp b/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp index ad5ba6affb..173e137d17 100644 --- a/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp +++ b/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp @@ -59,6 +59,28 @@ void tst_QInputControl::isAcceptableInput_data() QTest::newRow("printable-hebrew") << QString(QChar(0x2135)) << Qt::KeyboardModifiers() << true; QTest::newRow("private-use-area") << QString(QChar(0xE832)) << Qt::KeyboardModifiers() << true; QTest::newRow("multiple-printable") << QStringLiteral("foobar") << Qt::KeyboardModifiers() << true; + QTest::newRow("rlm") << QString(QChar(0x200F)) << Qt::KeyboardModifiers() << true; + QTest::newRow("rlm-with-ctrl") << QString(QChar(0x200F)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("rlm-with-ctrl-shift") << QString(QChar(0x200F)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + QTest::newRow("lrm") << QString(QChar(0x200E)) << Qt::KeyboardModifiers() << true; + QTest::newRow("lrm-with-ctrl") << QString(QChar(0x200E)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("lrm-with-ctrl-shift") << QString(QChar(0x200E)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + QTest::newRow("rlo") << QString(QChar(0x202E)) << Qt::KeyboardModifiers() << true; + QTest::newRow("rlo-with-ctrl") << QString(QChar(0x202E)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("rlo-with-ctrl-shift") << QString(QChar(0x202E)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + QTest::newRow("lro") << QString(QChar(0x202D)) << Qt::KeyboardModifiers() << true; + QTest::newRow("lro-with-ctrl") << QString(QChar(0x202D)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("lro-with-ctrl-shift") << QString(QChar(0x202D)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + QTest::newRow("lre") << QString(QChar(0x202B)) << Qt::KeyboardModifiers() << true; + QTest::newRow("lre-with-ctrl") << QString(QChar(0x202B)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("lre-with-ctrl-shift") << QString(QChar(0x202B)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + QTest::newRow("rle") << QString(QChar(0x202A)) << Qt::KeyboardModifiers() << true; + QTest::newRow("rle-with-ctrl") << QString(QChar(0x202A)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("rle-with-ctrl-shift") << QString(QChar(0x202A)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + QTest::newRow("pdf") << QString(QChar(0x202C)) << Qt::KeyboardModifiers() << true; + QTest::newRow("pdf-with-ctrl") << QString(QChar(0x202C)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true; + QTest::newRow("pdf-with-ctrl-shift") << QString(QChar(0x202C)) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << true; + } void tst_QInputControl::isAcceptableInput() -- cgit v1.2.3 From c2cecf08d5abf8324fc066bde5f0a07f3e59a622 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Jan 2017 09:11:57 +0100 Subject: QHostAddress: add missing op!=(SpecialAddress, QHostAddress) The equality operator was supplied, but this one was missing. [ChangeLog][QtNetwork][QHostAddress] Added op!=(SpecialAddress, QHostAddress). Change-Id: Iad9c55fa0ee7a8e97d5e4ea4be0605b8b74649d1 Reviewed-by: Thiago Macieira --- tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp index a715c38f32..bc3f5650ba 100644 --- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp +++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp @@ -274,6 +274,7 @@ void tst_QHostAddress::specialAddresses() QVERIFY(address == QHostAddress(address)); QVERIFY(!(QHostAddress(address) != QHostAddress(address))); QVERIFY(!(QHostAddress(address) != address)); + QVERIFY(!(address != QHostAddress(address))); { QHostAddress ha; -- cgit v1.2.3 From 2ccb7ecbca3f27663d96c7582e80c8af18500eda Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 16 Aug 2016 13:37:58 +0200 Subject: tests/auto/corelib/animation: clean up - port from inefficient QLists to QVector - mark types held in Qt containers (incl. QVariant) as Q_MOVABLE/PRIMITIVE_TYPE - remove pointless user-defined copy special members which prevent the class from having nothrow move special members Fixes errors reported by my local tree's static checks. Change-Id: If3910484cea81a8e2c5ab737908c9443f75782c5 Reviewed-by: Lars Knoll --- .../qparallelanimationgroup/tst_qparallelanimationgroup.cpp | 3 +++ .../animation/qpropertyanimation/tst_qpropertyanimation.cpp | 12 ++++-------- .../tst_qsequentialanimationgroup.cpp | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp b/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp index a8d64f1cd9..18a6268ec0 100644 --- a/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp +++ b/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp @@ -786,6 +786,9 @@ struct AnimState { int time; int state; }; +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(AnimState, Q_MOVABLE_TYPE); +QT_END_NAMESPACE #define Running QAbstractAnimation::Running #define Stopped QAbstractAnimation::Stopped diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp index c1a8fde504..9e0648d194 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp @@ -427,7 +427,7 @@ public: void setOle(int v) { o = v; values << v; } int o; - QList values; + QVector values; }; void tst_QPropertyAnimation::noStartValue() @@ -674,19 +674,15 @@ struct Number Number(int n) : n(n) {} - Number(const Number &other) - : n(other.n){} - - Number &operator=(const Number &other) { - n = other.n; - return *this; - } bool operator==(const Number &other) const { return n == other.n; } int n; }; +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(Number, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE Q_DECLARE_METATYPE(Number) diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp index 6d66f05835..06e9fe7a66 100644 --- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp +++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp @@ -563,7 +563,7 @@ void tst_QSequentialAnimationGroup::seekingBackwards() QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped); } -typedef QList StateList; +typedef QVector StateList; static bool compareStates(const QSignalSpy& spy, const StateList &expectedStates) { -- cgit v1.2.3 From ce3402b5efc929b99d6ecb27f47e671cdcfae393 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 19 Jan 2015 11:29:52 +0100 Subject: QSizePolicy: add some constexpr Also add a basic test for constexpr expressions involving QSizePolicy. GCC < 4.8.0 has problems with initializing variant members in constexpr ctors: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54922 Instead of revoking its Q_COMPILER_CONSTEXPR, which is a source-incompatible change, simply note the fact so we can selectively provide constexpr for QSizePolicy. Change-Id: Iba8e5a7cdf847d73e8e2b6bb6211fb3c9846aa0a Reviewed-by: Thiago Macieira --- tests/auto/widgets/kernel/qsizepolicy/qsizepolicy.pro | 1 + tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qsizepolicy/qsizepolicy.pro b/tests/auto/widgets/kernel/qsizepolicy/qsizepolicy.pro index 84629c7c0a..d325bc4aeb 100644 --- a/tests/auto/widgets/kernel/qsizepolicy/qsizepolicy.pro +++ b/tests/auto/widgets/kernel/qsizepolicy/qsizepolicy.pro @@ -1,4 +1,5 @@ CONFIG += testcase +contains(QT_CONFIG, c++14): CONFIG += c++14 TARGET = tst_qsizepolicy QT += widgets widgets-private testlib diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp index cd5aa03689..15bd0a8c1c 100644 --- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp +++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp @@ -41,6 +41,7 @@ class tst_QSizePolicy : public QObject private Q_SLOTS: void cleanup() { QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void qtest(); + void constExpr(); void defaultValues(); void getSetCheck_data() { data(); } void getSetCheck(); @@ -102,6 +103,19 @@ void tst_QSizePolicy::qtest() #undef CHECK2 } +void tst_QSizePolicy::constExpr() +{ +/* gcc < 4.8.0 has problems with init'ing variant members in constexpr ctors */ +/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54922 */ +#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) || defined(Q_CC_CLANG) || Q_CC_GNU >= 408 + // check that certain ctors are constexpr (compile-only): + { Q_CONSTEXPR QSizePolicy sp; Q_UNUSED(sp); } + { Q_CONSTEXPR QSizePolicy sp = QSizePolicy(); Q_UNUSED(sp); } +#else + QSKIP("QSizePolicy cannot be constexpr with this version of the compiler."); +#endif +} + void tst_QSizePolicy::defaultValues() { { -- cgit v1.2.3 From 8b9b27bced5227fae0f44a92a24183f38c944c02 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Dec 2014 16:19:27 +0100 Subject: QSizePolicy: add a transposed() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some situations, this allows for nicer code. It's also possible to make this constexpr in C++11, whereas the mutable transpose() would require C++14-style constexpr. The new function should also be faster, since it just swaps the member variables. Because of constexpr-function limitations, the way the return value is constructed needs to depend on the level of the compiler's C++11 support. This is not the only class that requires uniform init to provide a fully constexpr interface (QUuid and QBasicAtomic come to mind), so this should probably be generalized across Qt at some point. Added tests. [ChangeLog][QtWidgets][QSizePolicy] Added transposed() method. Change-Id: Ic1077a0d5a861e7c63bd1daeeb42b97c3a2f71ef Reviewed-by: Sérgio Martins --- .../widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp index 15bd0a8c1c..98b765a6c6 100644 --- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp +++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp @@ -45,6 +45,8 @@ private Q_SLOTS: void defaultValues(); void getSetCheck_data() { data(); } void getSetCheck(); + void transposed_data() { data(); } + void transposed(); void dataStream(); void horizontalStretch(); void verticalStretch(); @@ -161,6 +163,26 @@ void tst_QSizePolicy::getSetCheck() QCOMPARE(sp.expandingDirections(), ed); } +void tst_QSizePolicy::transposed() +{ + FETCH_TEST_DATA; + + const QSizePolicy tr = sp.transposed(); + + QCOMPARE(tr.horizontalPolicy(), vp); // swapped + QCOMPARE(tr.verticalPolicy(), hp); // swapped + QCOMPARE(tr.horizontalStretch(), vst); // swapped + QCOMPARE(tr.verticalStretch(), hst); // swapped + QCOMPARE(tr.controlType(), ct); // not swapped + QCOMPARE(tr.hasHeightForWidth(), hfw); // not swapped (historic behavior) + QCOMPARE(tr.hasWidthForHeight(), wfh); // not swapped (historic behavior) + QCOMPARE(tr.expandingDirections(), ed); // swapped + + // destructive test - keep last: + sp.transpose(); + QCOMPARE(sp, tr); +} + static void makeRow(QSizePolicy sp, QSizePolicy::Policy hp, QSizePolicy::Policy vp, int hst, int vst, QSizePolicy::ControlType ct, bool hfw, bool wfh, Qt::Orientations orients) -- cgit v1.2.3 From 36f8816555da28b01d38032b4d298300681c61a5 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 27 Jan 2017 15:21:57 +0100 Subject: Fix 2 clang warnings The first one was already suppressed for GCC, so also do that for clang: /Users/erik/dev/qt5-dev/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp:1076:16: warning: format string is not a string literal (potentially insecure) [-Wformat-security] a.sprintf( zero ); ^~~~ /Users/erik/dev/qt5-dev/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp:1076:16: note: treat the string as an argument to avoid this a.sprintf( zero ); ^ "%s", The second one could also occur with other compilers, so fix it in a generic way. /Users/erik/dev/qt5-dev/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp:6382:5: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result] string.repeated(3); ^~~~~~~~~~~~~~~ ~ 2 warnings generated. Change-Id: Id999179e795580a37b5be673ee54d6fa1a006dd7 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 6ed7b74277..727eda7456 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1066,6 +1066,7 @@ void tst_QString::acc_01() QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wformat-security") +QT_WARNING_DISABLE_CLANG("-Wformat-security") void tst_QString::isNull() { @@ -6345,7 +6346,7 @@ void tst_QString::repeatedSignature() const { /* repated() should be a const member. */ const QString string; - string.repeated(3); + (void) string.repeated(3); } void tst_QString::repeated() const -- cgit v1.2.3 From e5d303cb9fb3ade3fae6d3f14a5f4fe139af63c9 Mon Sep 17 00:00:00 2001 From: Glen Mabey Date: Tue, 31 Jan 2017 04:42:13 +0000 Subject: tst_qvariant: fix comparison ambiguity for QMetaEnum value Under certain circumstances, VS2015 reported ambiguous options in using the operator>(Enum,int) operator. This change adds a static_cast to remove any ambiguity. In the process of testing this change, a gap in the existing logic was identified: the handling (just in the test code) of large negative enum values. Consequently, and additional test case was added, and additional if-conditions were added to account for that case. Change-Id: Ife2c471ba4caa4b9a0107722042114e58145c4d0 Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 3a51e67768..2a9b9c0a7f 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -80,7 +80,7 @@ public: enum MetaEnumTest_Enum1 { 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 }; + 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 }; Q_ENUM(MetaEnumTest_Enum3) enum MetaEnumTest_Enum4 ENUM_SIZE(quint64) { MetaEnumTest_Enum4_value = 47, MetaEnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 }; Q_ENUM(MetaEnumTest_Enum4) @@ -4671,7 +4671,7 @@ template void testVariant(Enum value, bool *ok) QVERIFY(var2.convert(QMetaType::Int)); QCOMPARE(var2.value(), static_cast(value)); - if (static_cast(value) <= INT_MAX) { + if ((static_cast(value) <= INT_MAX) && (static_cast(value) >= INT_MIN)) { int intValue = static_cast(value); QVariant intVar = intValue; QVERIFY(intVar.canConvert()); @@ -4732,7 +4732,7 @@ template void testVariantMeta(Enum value, bool *ok, const char *s QVariant strVar = QString::fromLatin1(string); QVERIFY(strVar.canConvert()); - if (value > INT_MAX) { + if ((static_cast(value) > INT_MAX) || (static_cast(value) < INT_MIN)) { QEXPECT_FAIL("", "QMetaEnum api uses 'int' as return type QTBUG-27451", Abort); *ok = true; } @@ -4754,6 +4754,7 @@ void tst_QVariant::metaEnums() METAENUMS_TEST(MetaEnumTest_Enum1_bigValue); METAENUMS_TEST(MetaEnumTest_Enum3_value); METAENUMS_TEST(MetaEnumTest_Enum3_bigValue); + METAENUMS_TEST(MetaEnumTest_Enum3_bigNegValue); METAENUMS_TEST(MetaEnumTest_Enum4_value); METAENUMS_TEST(MetaEnumTest_Enum4_bigValue); METAENUMS_TEST(MetaEnumTest_Enum5_value); -- cgit v1.2.3 From 3ab7016632c825949f32b72d06ac324b6672b9f6 Mon Sep 17 00:00:00 2001 From: Glen Mabey Date: Sat, 22 Jun 2013 19:43:46 -0500 Subject: New qfloat16 class This constitutes a fairly complete submission of an entirely new floating point type which conforms to IEEE 754 as a 16-bit storage class. Conversion between qfloat16 and float is currently performed through a sequence of lookup tables. Global-level functions qRound(), qRound64(), qFuzzyCompare(), qFuzzyIsNull(), and qIsNull() each with a qfloat16 parameter have been included for completeness. [ChangeLog][QtCore] Added new qfloat16 class. Change-Id: Ia52eb27846965c14f8140c00faf5ba33c9443976 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/global.pro | 1 + tests/auto/corelib/global/qfloat16/qfloat16.pro | 4 + .../auto/corelib/global/qfloat16/tst_qfloat16.cpp | 266 +++++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 tests/auto/corelib/global/qfloat16/qfloat16.pro create mode 100644 tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp (limited to 'tests') diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro index 219e9de818..b4cc8035e6 100644 --- a/tests/auto/corelib/global/global.pro +++ b/tests/auto/corelib/global/global.pro @@ -5,6 +5,7 @@ SUBDIRS=\ qgetputenv \ qglobal \ qnumeric \ + qfloat16 \ qrand \ qlogging \ qtendian \ diff --git a/tests/auto/corelib/global/qfloat16/qfloat16.pro b/tests/auto/corelib/global/qfloat16/qfloat16.pro new file mode 100644 index 0000000000..42081181b4 --- /dev/null +++ b/tests/auto/corelib/global/qfloat16/qfloat16.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qfloat16 +QT = core testlib +SOURCES = tst_qfloat16.cpp diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp new file mode 100644 index 0000000000..c894a9c897 --- /dev/null +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -0,0 +1,266 @@ +/**************************************************************************** +** +** Copyright (C) 2016 by Southwest Research Institute (R) +** Contact: http://www.qt-project.org/legal +** +** 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 + +class tst_qfloat16: public QObject +{ + Q_OBJECT + +private slots: + void fuzzyCompare_data(); + void fuzzyCompare(); + void ltgt_data(); + void ltgt(); + void qNan(); + void float_cast(); + void float_cast_data(); + void promotionTests(); +}; + +void tst_qfloat16::fuzzyCompare_data() +{ + QTest::addColumn("val1"); + QTest::addColumn("val2"); + QTest::addColumn("fuzEqual"); + QTest::addColumn("isEqual"); + + QTest::newRow("zero") << qfloat16(0.0f) << qfloat16(0.0f) << true << true; + QTest::newRow("ten") << qfloat16(1e1f) << qfloat16(1e1f) << true << true; + QTest::newRow("large") << qfloat16(1e4f) << qfloat16(1e4f) << true << true; + QTest::newRow("small") << qfloat16(1e-5f) << qfloat16(1e-5f) << true << true; + QTest::newRow("eps") << qfloat16(10.01f) << qfloat16(10.02f) << true << false; + QTest::newRow("eps2") << qfloat16(1024.f) << qfloat16(1033.f) << true << false; + + QTest::newRow("mis1") << qfloat16(0.0f) << qfloat16(1.0f) << false << false; + QTest::newRow("mis2") << qfloat16(0.0f) << qfloat16(1e7f) << false << false; + QTest::newRow("mis3") << qfloat16(0.0f) << qfloat16(1e-4f) << false << false; + QTest::newRow("mis4") << qfloat16(1e8f) << qfloat16(1e-8f) << false << false; + QTest::newRow("mis5") << qfloat16(1e-4f) << qfloat16(1e-5) << false << false; + QTest::newRow("mis6") << qfloat16(1024.f) << qfloat16(1034.f) << false << false; +} + +void tst_qfloat16::fuzzyCompare() +{ + QFETCH(qfloat16, val1); + QFETCH(qfloat16, val2); + QFETCH(bool, fuzEqual); + QFETCH(bool, isEqual); + + if (!isEqual && (val1==val2)) + qWarning() << "Identical arguments provided unintentionally!"; + + if (fuzEqual) { + QVERIFY(::qFuzzyCompare(val1, val2)); + QVERIFY(::qFuzzyCompare(val2, val1)); + QVERIFY(::qFuzzyCompare(-val1, -val2)); + QVERIFY(::qFuzzyCompare(-val2, -val1)); + } else { + QVERIFY(!::qFuzzyCompare(val1, val2)); + QVERIFY(!::qFuzzyCompare(val2, val1)); + QVERIFY(!::qFuzzyCompare(-val1, -val2)); + QVERIFY(!::qFuzzyCompare(-val2, -val1)); + } +} + +void tst_qfloat16::ltgt_data() +{ + QTest::addColumn("val1"); + QTest::addColumn("val2"); + + QTest::newRow("zero") << 0.0f << 0.0f; + QTest::newRow("ten") << 10.0f << 10.0f; + QTest::newRow("large") << 100000.0f << 100000.0f; + QTest::newRow("small") << 0.0000001f << 0.0000001f; + QTest::newRow("eps") << 10.000000000000001f << 10.00000000000002f; + QTest::newRow("eps2") << 10.000000000000001f << 10.000000000000009f; + + QTest::newRow("mis1") << 0.0f << 1.0f; + QTest::newRow("mis2") << 0.0f << 10000000.0f; + QTest::newRow("mis3") << 0.0f << 0.0001f; + QTest::newRow("mis4") << 100000000.0f << 0.000000001f; + QTest::newRow("mis5") << 0.0001f << 0.00001f; + + QTest::newRow("45,23") << 45.f << 23.f; + QTest::newRow("1000,76") << 1000.f << 76.f; +} + +void tst_qfloat16::ltgt() +{ + QFETCH(float, val1); + QFETCH(float, val2); + + QCOMPARE(qfloat16(val1) == qfloat16(val2), val1 == val2); + QCOMPARE(qfloat16(val1) < qfloat16(val2), val1 < val2); + QCOMPARE(qfloat16(val1) <= qfloat16(val2), val1 <= val2); + QCOMPARE(qfloat16(val1) > qfloat16(val2), val1 > val2); + QCOMPARE(qfloat16(val1) >= qfloat16(val2), val1 >= val2); + + QCOMPARE(qfloat16(val1) == qfloat16(-val2), val1 == -val2); + QCOMPARE(qfloat16(val1) < qfloat16(-val2), val1 < -val2); + QCOMPARE(qfloat16(val1) <= qfloat16(-val2), val1 <= -val2); + QCOMPARE(qfloat16(val1) > qfloat16(-val2), val1 > -val2); + QCOMPARE(qfloat16(val1) >= qfloat16(-val2), val1 >= -val2); + + QCOMPARE(qfloat16(-val1) == qfloat16(val2), -val1 == val2); + QCOMPARE(qfloat16(-val1) < qfloat16(val2), -val1 < val2); + QCOMPARE(qfloat16(-val1) <= qfloat16(val2), -val1 <= val2); + QCOMPARE(qfloat16(-val1) > qfloat16(val2), -val1 > val2); + QCOMPARE(qfloat16(-val1) >= qfloat16(val2), -val1 >= val2); + + QCOMPARE(qfloat16(-val1) == qfloat16(-val2), -val1 == -val2); + QCOMPARE(qfloat16(-val1) < qfloat16(-val2), -val1 < -val2); + QCOMPARE(qfloat16(-val1) <= qfloat16(-val2), -val1 <= -val2); + QCOMPARE(qfloat16(-val1) > qfloat16(-val2), -val1 > -val2); + QCOMPARE(qfloat16(-val1) >= qfloat16(-val2), -val1 >= -val2); +} + +#if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ >= 404) + // turn -ffast-math off +# pragma GCC optimize "no-fast-math" +#endif + +void tst_qfloat16::qNan() +{ +#if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ < 404) + QSKIP("Non-conformant fast math mode is enabled, cannot run test"); +#endif + qfloat16 nan = qQNaN(); + QVERIFY(!(0. > nan)); + QVERIFY(!(0. < nan)); + QVERIFY(qIsNaN(nan)); + QVERIFY(qIsNaN(nan + 1.f)); + QVERIFY(qIsNaN(-nan)); + qfloat16 inf = qInf(); + QVERIFY(inf > qfloat16(0)); + QVERIFY(-inf < qfloat16(0)); + QVERIFY(qIsInf(inf)); + QVERIFY(qIsInf(-inf)); + QVERIFY(qIsInf(2.f*inf)); + QVERIFY(qIsInf(inf*2.f)); + QCOMPARE(qfloat16(1.f/inf), qfloat16(0.f)); +#ifdef Q_CC_INTEL + QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue); +#endif + QVERIFY(qIsNaN(nan*0.f)); +#ifdef Q_CC_INTEL + QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue); +#endif + QVERIFY(qIsNaN(inf*0.f)); + QVERIFY(qFuzzyCompare(qfloat16(1.f/inf), qfloat16(0.0))); +} + +void tst_qfloat16::float_cast_data() +{ + QTest::addColumn("val"); + + QTest::newRow("zero") << 0.f; + QTest::newRow("one") << 1e0f; + QTest::newRow("ten") << 1e1f; + QTest::newRow("hund") << 1e2f; + QTest::newRow("thou") << 1e3f; + QTest::newRow("tthou") << 1e4f; + //QTest::newRow("hthou") << 1e5f; + //QTest::newRow("mil") << 1e6f; + //QTest::newRow("tmil") << 1e7f; + //QTest::newRow("hmil") << 1e8f; +} + +void tst_qfloat16::float_cast() +{ + QFETCH(float, val); + + QVERIFY(qFuzzyCompare(float(qfloat16(val)),val)); + QVERIFY(qFuzzyCompare(float(qfloat16(-val)),-val)); +} + +void tst_qfloat16::promotionTests() +{ + QCOMPARE(sizeof(qfloat16),sizeof(qfloat16(1.f)+qfloat16(1.f))); + QCOMPARE(sizeof(qfloat16),sizeof(qfloat16(1.f)-qfloat16(1.f))); + QCOMPARE(sizeof(qfloat16),sizeof(qfloat16(1.f)*qfloat16(1.f))); + QCOMPARE(sizeof(qfloat16),sizeof(qfloat16(1.f)/qfloat16(1.f))); + + QCOMPARE(sizeof(float),sizeof(1.f+qfloat16(1.f))); + QCOMPARE(sizeof(float),sizeof(1.f-qfloat16(1.f))); + QCOMPARE(sizeof(float),sizeof(1.f*qfloat16(1.f))); + QCOMPARE(sizeof(float),sizeof(1.f/qfloat16(1.f))); + + QCOMPARE(sizeof(float),sizeof(qfloat16(1.f)+1.f)); + QCOMPARE(sizeof(float),sizeof(qfloat16(1.f)-1.f)); + QCOMPARE(sizeof(float),sizeof(qfloat16(1.f)*1.f)); + QCOMPARE(sizeof(float),sizeof(qfloat16(1.f)/1.f)); + + QCOMPARE(sizeof(double),sizeof(1.+qfloat16(1.f))); + QCOMPARE(sizeof(double),sizeof(1.-qfloat16(1.f))); + QCOMPARE(sizeof(double),sizeof(1.*qfloat16(1.f))); + QCOMPARE(sizeof(double),sizeof(1./qfloat16(1.f))); + + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)+1.)); + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)-1.)); + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)*1.)); + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)/1.)); + + QCOMPARE(sizeof(long double),sizeof((long double)(1.)+qfloat16(1.f))); + QCOMPARE(sizeof(long double),sizeof((long double)(1.)-qfloat16(1.f))); + QCOMPARE(sizeof(long double),sizeof((long double)(1.)*qfloat16(1.f))); + QCOMPARE(sizeof(long double),sizeof((long double)(1.)/qfloat16(1.f))); + + QCOMPARE(sizeof(long double),sizeof(qfloat16(1.f)+(long double)(1.))); + QCOMPARE(sizeof(long double),sizeof(qfloat16(1.f)-(long double)(1.))); + QCOMPARE(sizeof(long double),sizeof(qfloat16(1.f)*(long double)(1.))); + QCOMPARE(sizeof(long double),sizeof(qfloat16(1.f)/(long double)(1.))); + + QCOMPARE(sizeof(double),sizeof(1+qfloat16(1.f))); + QCOMPARE(sizeof(double),sizeof(1-qfloat16(1.f))); + QCOMPARE(sizeof(double),sizeof(1*qfloat16(1.f))); + QCOMPARE(sizeof(double),sizeof(1/qfloat16(1.f))); + + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)+1)); + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)-1)); + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)*1)); + QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)/1)); +} + +QTEST_APPLESS_MAIN(tst_qfloat16) +#include "tst_qfloat16.moc" -- cgit v1.2.3