diff options
Diffstat (limited to 'tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp')
-rw-r--r-- | tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp index d913bcdf9a..321896a8f3 100644 --- a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp +++ b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp @@ -59,6 +59,7 @@ private slots: void dataAndEditing(); void omitTableModelColumnIndex(); void complexRow(); + void appendRowWithDouble(); }; void tst_QQmlTableModel::appendRemoveRow() @@ -975,6 +976,76 @@ void tst_QQmlTableModel::complexRow() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); } +void tst_QQmlTableModel::appendRowWithDouble() +{ + QQuickView view(testFileUrl("intAndDouble.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>(); + QVERIFY(model); + QCOMPARE(model->rowCount(), 2); + QCOMPARE(model->columnCount(), 2); + + QSignalSpy columnCountSpy(model, SIGNAL(columnCountChanged())); + QVERIFY(columnCountSpy.isValid()); + + QSignalSpy rowCountSpy(model, SIGNAL(rowCountChanged())); + QVERIFY(rowCountSpy.isValid()); + + QQuickTableView *tableView = view.rootObject()->property("tableView").value<QQuickTableView*>(); + QVERIFY(tableView); + QCOMPARE(tableView->rows(), 2); + QCOMPARE(tableView->columns(), 2); + + QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendBanana")); + QCOMPARE(model->rowCount(), 3); + QCOMPARE(model->columnCount(), 2); + const QHash<int, QByteArray> roleNames = model->roleNames(); + const int roleKey = roleNames.key("display"); + QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleKey).toString(), + QLatin1String("1")); + QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleKey).toString(), + QLatin1String("Banana")); + QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleKey).toDouble(), 3.5); + QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleKey).toString(), + QLatin1String("3.5")); + QCOMPARE(columnCountSpy.count(), 0); + QCOMPARE(rowCountSpy.count(), 1); + QTRY_COMPARE(tableView->rows(), 3); + QCOMPARE(tableView->columns(), 2); + + rowCountSpy.clear(); + + QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendStrawberry")); + QCOMPARE(model->rowCount(), 4); + QCOMPARE(model->columnCount(), 2); + QCOMPARE(model->data(model->index(3, 0, QModelIndex()), roleKey).toString(), + QLatin1String("Strawberry")); + QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleKey).toDouble(), 5); + QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleKey).toString(), + QLatin1String("5")); + QCOMPARE(columnCountSpy.count(), 0); + QCOMPARE(rowCountSpy.count(), 1); + QTRY_COMPARE(tableView->rows(), 4); + QCOMPARE(tableView->columns(), 2); + + rowCountSpy.clear(); + QTest::ignoreMessage(QtWarningMsg, + QRegularExpression(".*appendRow\\(\\): failed converting value " + "QVariant\\(QString, \"Invalid\"\\) set at column 1 with " + "role \"QString\" to \"int\"")); + QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendInvalid")); + // Nothing should change + QCOMPARE(model->rowCount(), 4); + QCOMPARE(model->columnCount(), 2); + QCOMPARE(columnCountSpy.count(), 0); + QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(tableView->rows(), 4); + QCOMPARE(tableView->columns(), 2); +} + QTEST_MAIN(tst_QQmlTableModel) #include "tst_qqmltablemodel.moc" |