summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-12-22 17:16:48 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-28 04:48:11 +0100
commitea415e20607016651f3cef02dff109235d84eb4d (patch)
tree8c954afe7d078b0ca742a1f2249ccc5a9ddf1b82 /tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
parent1e7296f3f2e7346f52e8f70d4e531405a248aa8b (diff)
Cleanup corelib autotests.
When using QSignalSpy, always verify that the signal spy is valid. This will cause the test to give a meaningful failure when spying on a non-existant signal. Without this change, tests that spy on a signal to ensure that it is not emitted (i.e. by comparing the spy count to zero) could pass erroneously if something went wrong when creating the signal spy, as an invalid QSignalSpy will always return a count of zero. Change-Id: I41f4a63d9f0de9190a86de237662dc96be802446 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp')
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index cc8299e28f..6d3e8906c9 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -1504,6 +1504,7 @@ void tst_QSortFilterProxyModel::filterCurrent()
view.show();
view.setModel(&proxy);
QSignalSpy spy(view.selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)));
+ QVERIFY(spy.isValid());
view.setCurrentIndex(proxy.index(0, 0));
QCOMPARE(spy.count(), 1);
@@ -1628,6 +1629,11 @@ void tst_QSortFilterProxyModel::removeSourceRows()
QSignalSpy aboutToRemoveSpy(&proxy, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)));
QSignalSpy aboutToInsertSpy(&proxy, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)));
+ QVERIFY(removeSpy.isValid());
+ QVERIFY(insertSpy.isValid());
+ QVERIFY(aboutToRemoveSpy.isValid());
+ QVERIFY(aboutToInsertSpy.isValid());
+
model.removeRows(start, count, QModelIndex());
QCOMPARE(aboutToRemoveSpy.count(), expectedRemovedProxyIntervals.count());
@@ -1802,6 +1808,9 @@ void tst_QSortFilterProxyModel::changeFilter()
QSignalSpy initialRemoveSpy(&proxy, SIGNAL(rowsRemoved(QModelIndex, int, int)));
QSignalSpy initialInsertSpy(&proxy, SIGNAL(rowsInserted(QModelIndex, int, int)));
+ QVERIFY(initialRemoveSpy.isValid());
+ QVERIFY(initialInsertSpy.isValid());
+
proxy.setFilterRegExp(initialFilter);
QCOMPARE(initialRemoveSpy.count(), initialRemoveIntervals.count());
@@ -1823,6 +1832,9 @@ void tst_QSortFilterProxyModel::changeFilter()
QSignalSpy finalRemoveSpy(&proxy, SIGNAL(rowsRemoved(QModelIndex, int, int)));
QSignalSpy finalInsertSpy(&proxy, SIGNAL(rowsInserted(QModelIndex, int, int)));
+ QVERIFY(finalRemoveSpy.isValid());
+ QVERIFY(finalInsertSpy.isValid());
+
proxy.setFilterRegExp(finalFilter);
QCOMPARE(finalRemoveSpy.count(), finalRemoveIntervals.count());
@@ -1971,6 +1983,9 @@ void tst_QSortFilterProxyModel::changeSourceData()
QSignalSpy removeSpy(&proxy, SIGNAL(rowsRemoved(QModelIndex, int, int)));
QSignalSpy insertSpy(&proxy, SIGNAL(rowsInserted(QModelIndex, int, int)));
+ QVERIFY(removeSpy.isValid());
+ QVERIFY(insertSpy.isValid());
+
{
QModelIndex index = model.index(row, 0, QModelIndex());
model.setData(index, newValue, Qt::DisplayRole);
@@ -2065,6 +2080,7 @@ void tst_QSortFilterProxyModel::selectionFilteredOut()
view.show();
view.setModel(&proxy);
QSignalSpy spy(view.selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)));
+ QVERIFY(spy.isValid());
view.setCurrentIndex(proxy.index(0, 0));
QCOMPARE(spy.count(), 1);
@@ -2181,6 +2197,9 @@ void tst_QSortFilterProxyModel::insertIntoChildrenlessItem()
QSignalSpy colsInsertedSpy(&proxy, SIGNAL(columnsInserted(const QModelIndex&, int, int)));
QSignalSpy rowsInsertedSpy(&proxy, SIGNAL(rowsInserted(const QModelIndex&, int, int)));
+ QVERIFY(colsInsertedSpy.isValid());
+ QVERIFY(rowsInsertedSpy.isValid());
+
(void)proxy.rowCount(QModelIndex()); // force mapping of "a", "b", "c"
QCOMPARE(colsInsertedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 0);
@@ -2256,6 +2275,7 @@ void tst_QSortFilterProxyModel::insertRowIntoFilteredParent()
proxy.setSourceModel(&model);
QSignalSpy spy(&proxy, SIGNAL(rowsInserted(const QModelIndex&, int, int)));
+ QVERIFY(spy.isValid());
QStandardItem *itemA = new QStandardItem();
model.appendRow(itemA); // A will be filtered
@@ -2286,6 +2306,9 @@ void tst_QSortFilterProxyModel::filterOutParentAndFilterInChild()
QSignalSpy removedSpy(&proxy, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
QSignalSpy insertedSpy(&proxy, SIGNAL(rowsInserted(const QModelIndex&, int, int)));
+ QVERIFY(removedSpy.isValid());
+ QVERIFY(insertedSpy.isValid());
+
proxy.setFilterRegExp("C"); // A and B will be filtered out, C filtered in
// we should now have been notified that the subtree represented by itemA has been removed
@@ -2882,6 +2905,9 @@ void tst_QSortFilterProxyModel::taskQTBUG_7537_appearsAndSort()
QSignalSpy spyAbout1(&proxyModel, SIGNAL(layoutAboutToBeChanged()));
QSignalSpy spyChanged1(&proxyModel, SIGNAL(layoutChanged()));
+ QVERIFY(spyAbout1.isValid());
+ QVERIFY(spyChanged1.isValid());
+
//introducing secondProxyModel to test the layoutChange when many items appears at once
QSortFilterProxyModel secondProxyModel;
secondProxyModel.setSourceModel(&proxyModel);
@@ -2891,6 +2917,9 @@ void tst_QSortFilterProxyModel::taskQTBUG_7537_appearsAndSort()
QSignalSpy spyAbout2(&secondProxyModel, SIGNAL(layoutAboutToBeChanged()));
QSignalSpy spyChanged2(&secondProxyModel, SIGNAL(layoutChanged()));
+ QVERIFY(spyAbout2.isValid());
+ QVERIFY(spyChanged2.isValid());
+
proxyModel.updateXX();
QApplication::processEvents();
//now rows should be visible, and sorted
@@ -3248,16 +3277,27 @@ void tst_QSortFilterProxyModel::testParentLayoutChanged()
QSignalSpy dataChangedSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ QVERIFY(dataChangedSpy.isValid());
+
// Verify that the no-arg signal is still emitted.
QSignalSpy layoutAboutToBeChangedSpy(&proxy, SIGNAL(layoutAboutToBeChanged()));
QSignalSpy layoutChangedSpy(&proxy, SIGNAL(layoutChanged()));
+ QVERIFY(layoutAboutToBeChangedSpy.isValid());
+ QVERIFY(layoutChangedSpy.isValid());
+
QSignalSpy parentsAboutToBeChangedSpy(&proxy, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>)));
QSignalSpy parentsChangedSpy(&proxy, SIGNAL(layoutChanged(QList<QPersistentModelIndex>)));
+ QVERIFY(parentsAboutToBeChangedSpy.isValid());
+ QVERIFY(parentsChangedSpy.isValid());
+
QSignalSpy proxy2ParentsAboutToBeChangedSpy(&proxy2, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>)));
QSignalSpy proxy2ParentsChangedSpy(&proxy2, SIGNAL(layoutChanged(QList<QPersistentModelIndex>)));
+ QVERIFY(proxy2ParentsAboutToBeChangedSpy.isValid());
+ QVERIFY(proxy2ParentsChangedSpy.isValid());
+
QStandardItem *item = model.invisibleRootItem()->child(1)->child(1);
// Ensure mapped:
@@ -3426,6 +3466,17 @@ void tst_QSortFilterProxyModel::moveSourceRows()
QSignalSpy filterBothBeforeParentLayoutSpy(&filterBothProxy, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>)));
QSignalSpy filterBothAfterParentLayoutSpy(&filterBothProxy, SIGNAL(layoutChanged(QList<QPersistentModelIndex>)));
+ QVERIFY(modelBeforeSpy.isValid());
+ QVERIFY(modelAfterSpy.isValid());
+ QVERIFY(proxyBeforeMoveSpy.isValid());
+ QVERIFY(proxyAfterMoveSpy.isValid());
+ QVERIFY(proxyBeforeParentLayoutSpy.isValid());
+ QVERIFY(proxyAfterParentLayoutSpy.isValid());
+ QVERIFY(filterBeforeParentLayoutSpy.isValid());
+ QVERIFY(filterAfterParentLayoutSpy.isValid());
+ QVERIFY(filterBothBeforeParentLayoutSpy.isValid());
+ QVERIFY(filterBothAfterParentLayoutSpy.isValid());
+
{
ModelMoveCommand moveCommand(&model, 0);
moveCommand.setAncestorRowNumbers(QList<int>() << 2);