aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-06-03 15:28:51 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-06-04 17:02:55 +0200
commit11a11d1280b1634628b9c4a92a0fc420ee8a3a81 (patch)
treeb48d9608ef3f08123cdeea605068342131b32b44 /tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
parent52e07d564b65ed6ce26955a676c7692ad67686c1 (diff)
parentfea26bb2941c3f24c4a5f3ad5efc1b85e0123ff3 (diff)
Merge remote-tracking branch 'origin/stable' into dev
The merge conflict is about the removal of "d1" from the register set on ARM, but that was already done in dev in commit ddb33ee9ba9e1344caa9be5dbf4b534c3ede692e The change in src/quick/scenegraph/coreapi/qsgrenderer.cpp with commit 2414f1675eab163b22dcc4e8ded80ed04d06369b was reverted to what it was before, per Laszlo's advice. Conflicts: src/qml/jit/qv4isel_masm.cpp Change-Id: I7bce546c5cdee01e37853a476d82279d4e72948b
Diffstat (limited to 'tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp')
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index 22404aa862..ede80b355a 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -132,6 +132,7 @@ private slots:
void empty_element_warning_data();
void datetime();
void datetime_data();
+ void about_to_be_signals();
};
bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1306,6 +1307,134 @@ void tst_qqmllistmodel::datetime()
QVERIFY(expected == dtResult);
}
+class RowTester : public QObject
+{
+ Q_OBJECT
+public:
+ RowTester(QAbstractItemModel *model) : QObject(model), model(model)
+ {
+ reset();
+ connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(rowsAboutToBeInserted()));
+ connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted()));
+ connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(rowsAboutToBeRemoved()));
+ connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved()));
+ connect(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(rowsAboutToBeMoved()));
+ connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(rowsMoved()));
+ }
+
+ void reset()
+ {
+ rowsAboutToBeInsertedCalls = 0;
+ rowsAboutToBeInsertedCount = 0;
+ rowsInsertedCalls = 0;
+ rowsInsertedCount = 0;
+ rowsAboutToBeRemovedCalls = 0;
+ rowsAboutToBeRemovedCount = 0;
+ rowsRemovedCalls = 0;
+ rowsRemovedCount = 0;
+ rowsAboutToBeMovedCalls = 0;
+ rowsAboutToBeMovedData.clear();
+ rowsMovedCalls = 0;
+ rowsMovedData.clear();
+ }
+
+ int rowsAboutToBeInsertedCalls;
+ int rowsAboutToBeInsertedCount;
+ int rowsInsertedCalls;
+ int rowsInsertedCount;
+ int rowsAboutToBeRemovedCalls;
+ int rowsAboutToBeRemovedCount;
+ int rowsRemovedCalls;
+ int rowsRemovedCount;
+ int rowsAboutToBeMovedCalls;
+ QVariantList rowsAboutToBeMovedData;
+ int rowsMovedCalls;
+ QVariantList rowsMovedData;
+
+private slots:
+ void rowsAboutToBeInserted()
+ {
+ rowsAboutToBeInsertedCalls++;
+ rowsAboutToBeInsertedCount = model->rowCount();
+ }
+
+ void rowsInserted()
+ {
+ rowsInsertedCalls++;
+ rowsInsertedCount = model->rowCount();
+ }
+
+ void rowsAboutToBeRemoved()
+ {
+ rowsAboutToBeRemovedCalls++;
+ rowsAboutToBeRemovedCount = model->rowCount();
+ }
+
+ void rowsRemoved()
+ {
+ rowsRemovedCalls++;
+ rowsRemovedCount = model->rowCount();
+ }
+
+ void rowsAboutToBeMoved()
+ {
+ rowsAboutToBeMovedCalls++;
+ for (int i = 0; i < model->rowCount(); ++i)
+ rowsAboutToBeMovedData += model->data(model->index(i, 0), 0);
+ }
+
+ void rowsMoved()
+ {
+ rowsMovedCalls++;
+ for (int i = 0; i < model->rowCount(); ++i)
+ rowsMovedData += model->data(model->index(i, 0), 0);
+ }
+
+private:
+ QAbstractItemModel *model;
+};
+
+void tst_qqmllistmodel::about_to_be_signals()
+{
+ QQmlEngine engine;
+ QQmlListModel model;
+ QQmlEngine::setContextForObject(&model,engine.rootContext());
+
+ RowTester tester(&model);
+
+ QQmlExpression e1(engine.rootContext(), &model, "{append({'test':0})}");
+ e1.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeInsertedCalls, 1);
+ QCOMPARE(tester.rowsAboutToBeInsertedCount, 0);
+ QCOMPARE(tester.rowsInsertedCalls, 1);
+ QCOMPARE(tester.rowsInsertedCount, 1);
+
+ QQmlExpression e2(engine.rootContext(), &model, "{append({'test':1})}");
+ e2.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeInsertedCalls, 2);
+ QCOMPARE(tester.rowsAboutToBeInsertedCount, 1);
+ QCOMPARE(tester.rowsInsertedCalls, 2);
+ QCOMPARE(tester.rowsInsertedCount, 2);
+
+ QQmlExpression e3(engine.rootContext(), &model, "{move(0, 1, 1)}");
+ e3.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeMovedCalls, 1);
+ QCOMPARE(tester.rowsAboutToBeMovedData, QVariantList() << 0.0 << 1.0);
+ QCOMPARE(tester.rowsMovedCalls, 1);
+ QCOMPARE(tester.rowsMovedData, QVariantList() << 1.0 << 0.0);
+
+ QQmlExpression e4(engine.rootContext(), &model, "{remove(0, 2)}");
+ e4.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeRemovedCalls, 1);
+ QCOMPARE(tester.rowsAboutToBeRemovedCount, 2);
+ QCOMPARE(tester.rowsRemovedCalls, 1);
+ QCOMPARE(tester.rowsRemovedCount, 0);
+}
+
QTEST_MAIN(tst_qqmllistmodel)
#include "tst_qqmllistmodel.moc"