From f64d29ea65d002d1af3f24cc05f9859f629fa4fe Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 9 Dec 2011 16:07:37 +1000 Subject: Fix tests broken by a change in the signals emitted by AbstractItemModel QAbstractItemModel used to emit both layoutChanged() and rowsMoved() when items were moved. The VisualDataModel test expected both signals but was only interested in the move, and the grid view test had a bug in its test model that didn't was hidden by the change signal being emitted and causing bindings to be reevaluated. Change-Id: Id5d1b5768717f4a82f6eb4710ff3b4429529193e Reviewed-by: Alan Alpert --- .../qtquick2/qquickgridview/tst_qquickgridview.cpp | 45 ++++++++++++---------- .../tst_qquickvisualdatamodel.cpp | 32 ++++++--------- 2 files changed, 36 insertions(+), 41 deletions(-) (limited to 'tests') diff --git a/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp b/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp index 241e2e9dc0..b1edb2246b 100644 --- a/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp @@ -134,23 +134,28 @@ private: template void tst_qquickgridview_move(int from, int to, int n, T *items) { - if (n == 1) { - items->move(from, to); - } else { - T replaced; - int i=0; - typename T::ConstIterator it=items->begin(); it += from+n; - for (; ibegin(); it += from; - for (; ibegin(); t += from; - for (; f != replaced.end(); ++f, ++t) - *t = *f; - } + if (from > to) { + // Only move forwards - flip if backwards moving + int tfrom = from; + int tto = to; + from = tto; + to = tto+n; + n = tfrom-tto; + } + + T replaced; + int i=0; + typename T::ConstIterator it=items->begin(); it += from+n; + for (; ibegin(); it += from; + for (; ibegin(); t += from; + for (; f != replaced.end(); ++f, ++t) + *t = *f; } void tst_QQuickGridView::initTestCase() @@ -969,7 +974,7 @@ void tst_QQuickGridView::moved() QQuickText *name; QQuickText *number; - QQuickView *canvas = createView(); + QScopedPointer canvas(createView()); canvas->show(); TestModel model; @@ -997,7 +1002,7 @@ void tst_QQuickGridView::moved() model.moveItems(from, to, count); // wait for items to move - QTest::qWait(300); + QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); // Confirm items positioned correctly and indexes correct int firstVisibleIndex = qCeil(contentY / 60.0) * 3; @@ -1022,8 +1027,6 @@ void tst_QQuickGridView::moved() if (item == currentItem) QTRY_COMPARE(gridview->currentIndex(), i); } - - delete canvas; } void tst_QQuickGridView::moved_data() diff --git a/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 9e27a202b2..af3af57436 100644 --- a/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -688,26 +688,18 @@ void tst_qquickvisualdatamodel::qaimRowsMoved() QSignalSpy spy(obj, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool))); model.emitMove(sourceFirst, sourceLast, destinationChild); - // QAbstractItemModel also emits the changed signal when items are moved. - QCOMPARE(spy.count(), 2); - - bool move = false; - for (int i = 0; i < 2; ++i) { - QCOMPARE(spy[1].count(), 2); - QDeclarativeChangeSet changeSet = spy[i][0].value(); - if (!changeSet.changes().isEmpty()) - continue; - move = true; - QCOMPARE(changeSet.removes().count(), 1); - QCOMPARE(changeSet.removes().at(0).index, expectFrom); - QCOMPARE(changeSet.removes().at(0).count, expectCount); - QCOMPARE(changeSet.inserts().count(), 1); - QCOMPARE(changeSet.inserts().at(0).index, expectTo); - QCOMPARE(changeSet.inserts().at(0).count, expectCount); - QCOMPARE(changeSet.removes().at(0).moveId, changeSet.inserts().at(0).moveId); - QCOMPARE(spy[i][1].toBool(), false); - } - QVERIFY(move); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy[0].count(), 2); + QDeclarativeChangeSet changeSet = spy[0][0].value(); + QCOMPARE(changeSet.removes().count(), 1); + QCOMPARE(changeSet.removes().at(0).index, expectFrom); + QCOMPARE(changeSet.removes().at(0).count, expectCount); + QCOMPARE(changeSet.inserts().count(), 1); + QCOMPARE(changeSet.inserts().at(0).index, expectTo); + QCOMPARE(changeSet.inserts().at(0).count, expectCount); + QCOMPARE(changeSet.removes().at(0).moveId, changeSet.inserts().at(0).moveId); + QCOMPARE(spy[0][1].toBool(), false); delete obj; } -- cgit v1.2.3