diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2011-12-22 17:16:48 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-28 04:48:11 +0100 |
commit | ea415e20607016651f3cef02dff109235d84eb4d (patch) | |
tree | 8c954afe7d078b0ca742a1f2249ccc5a9ddf1b82 /tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp | |
parent | 1e7296f3f2e7346f52e8f70d4e531405a248aa8b (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/qabstractitemmodel/tst_qabstractitemmodel.cpp')
-rw-r--r-- | tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 199d96c0d1..5028728fd6 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -720,6 +720,9 @@ void tst_QAbstractItemModel::removeRows() QSignalSpy rowsAboutToBeRemovedSpy(&model, SIGNAL(rowsAboutToBeRemoved( const QModelIndex &, int , int ))); QSignalSpy rowsRemovedSpy(&model, SIGNAL(rowsRemoved( const QModelIndex &, int, int ))); + QVERIFY(rowsAboutToBeRemovedSpy.isValid()); + QVERIFY(rowsRemovedSpy.isValid()); + QCOMPARE(model.removeRows(6, 4), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 1); @@ -732,6 +735,9 @@ void tst_QAbstractItemModel::removeColumns() QSignalSpy columnsAboutToBeRemovedSpy(&model, SIGNAL(columnsAboutToBeRemoved( const QModelIndex &, int , int ))); QSignalSpy columnsRemovedSpy(&model, SIGNAL(columnsRemoved( const QModelIndex &, int, int ))); + QVERIFY(columnsAboutToBeRemovedSpy.isValid()); + QVERIFY(columnsRemovedSpy.isValid()); + QCOMPARE(model.removeColumns(6, 4), true); QCOMPARE(columnsAboutToBeRemovedSpy.count(), 1); QCOMPARE(columnsRemovedSpy.count(), 1); @@ -744,6 +750,9 @@ void tst_QAbstractItemModel::insertRows() QSignalSpy rowsAboutToBeInsertedSpy(&model, SIGNAL(rowsAboutToBeInserted( const QModelIndex &, int , int ))); QSignalSpy rowsInsertedSpy(&model, SIGNAL(rowsInserted( const QModelIndex &, int, int ))); + QVERIFY(rowsAboutToBeInsertedSpy.isValid()); + QVERIFY(rowsInsertedSpy.isValid()); + QCOMPARE(model.insertRows(6, 4), true); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsInsertedSpy.count(), 1); @@ -756,6 +765,9 @@ void tst_QAbstractItemModel::insertColumns() QSignalSpy columnsAboutToBeInsertedSpy(&model, SIGNAL(columnsAboutToBeInserted( const QModelIndex &, int , int ))); QSignalSpy columnsInsertedSpy(&model, SIGNAL(columnsInserted( const QModelIndex &, int, int ))); + QVERIFY(columnsAboutToBeInsertedSpy.isValid()); + QVERIFY(columnsInsertedSpy.isValid()); + QCOMPARE(model.insertColumns(6, 4), true); QCOMPARE(columnsAboutToBeInsertedSpy.count(), 1); QCOMPARE(columnsInsertedSpy.count(), 1); @@ -766,6 +778,7 @@ void tst_QAbstractItemModel::reset() QtTestModel model(10, 10); QSignalSpy resetSpy(&model, SIGNAL(modelReset())); + QVERIFY(resetSpy.isValid()); model.reset(); QCOMPARE(resetSpy.count(), 1); } @@ -894,6 +907,9 @@ void tst_QAbstractItemModel::testMoveSameParentDown() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setNumCols(4); if (!topLevel) @@ -1019,6 +1035,8 @@ void tst_QAbstractItemModel::testMoveSameParentUp() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setNumCols(4); @@ -1180,6 +1198,9 @@ void tst_QAbstractItemModel::testMoveToGrandParent() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + QPersistentModelIndex persistentSource = sourceIndex; ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); @@ -1329,6 +1350,9 @@ void tst_QAbstractItemModel::testMoveToSibling() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + QPersistentModelIndex persistentDest = destIndex; ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); @@ -1489,6 +1513,9 @@ void tst_QAbstractItemModel::testMoveToUncle() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setAncestorRowNumbers(QList<int>() << 9); moveCommand->setNumCols(4); @@ -1604,6 +1631,9 @@ void tst_QAbstractItemModel::testMoveToDescendants() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + ModelMoveCommand *moveCommand; QList<int> ancestors; while (ancestors.size() < depth) @@ -1670,6 +1700,9 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange() QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setNumCols(4); moveCommand->setStartRow(startRow); @@ -1755,6 +1788,8 @@ void tst_QAbstractItemModel::testReset() QSignalSpy beforeResetSpy(m_model, SIGNAL(modelAboutToBeReset())); QSignalSpy afterResetSpy(m_model, SIGNAL(modelReset())); + QVERIFY(beforeResetSpy.isValid()); + QVERIFY(afterResetSpy.isValid()); QSortFilterProxyModel *nullProxy = new QSortFilterProxyModel(this); nullProxy->setSourceModel(m_model); @@ -1821,6 +1856,9 @@ void tst_QAbstractItemModel::testDataChanged() QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>))); QSignalSpy withoutRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); + QVERIFY(withRoles.isValid()); + QVERIFY(withoutRoles.isValid()); + model.emitSignals(); QCOMPARE(withRoles.size(), withoutRoles.size()); @@ -1920,6 +1958,9 @@ void tst_QAbstractItemModel::testChildrenLayoutsChanged() QSignalSpy beforeSpy(&model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>))); QSignalSpy afterSpy(&model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + ModelChangeChildrenLayoutsCommand *changeCommand = new ModelChangeChildrenLayoutsCommand(&model, this); changeCommand->setAncestorRowNumbers(QList<int>() << 2); changeCommand->setSecondAncestorRowNumbers(QList<int>() << 5); @@ -1984,6 +2025,9 @@ void tst_QAbstractItemModel::testChildrenLayoutsChanged() QSignalSpy beforeSpy(&model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>))); QSignalSpy afterSpy(&model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>))); + QVERIFY(beforeSpy.isValid()); + QVERIFY(afterSpy.isValid()); + // Because the arguments in the signal are persistent, we need to check them for the aboutToBe // case at emission time - before they get updated. SignalArgumentChecker checker(p1, p2); |