aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-05-03 14:10:50 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-05-09 11:16:32 +0000
commit5e9fc09f17d5a91f09423d6f41a4cd53266cffac (patch)
treec9c5f8000b5cafbcf48db7566648ae1668225b2a /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parent3b806a18cc665b5ae0e12d45fe170bfc3f00352a (diff)
tests, qquicktableview: check that the expected number of delegate items are created
Change-Id: I96bc282a6678954d73cf5a15241ac30f43964dcb Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp101
1 files changed, 91 insertions, 10 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 3a615e1c3b..ea97ec8e52 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -30,6 +30,7 @@
#include <QtQuick/qquickview.h>
#include <QtQuick/private/qquicktableview_p.h>
+#include <QtQuick/private/qquicktableview_p_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcontext.h>
@@ -48,16 +49,22 @@
using namespace QQuickViewTestUtil;
using namespace QQuickVisualTestUtil;
-#define CREATE_VAR_FROM_PROPERTY(name, T) \
- T *name = view->rootObject()->property(#name).value<T *>(); \
- QVERIFY(name)
+static const char* kTableViewPropName = "tableView";
+static const char* kDelegateObjectName = "tableViewDelegate";
#define LOAD_TABLEVIEW(fileName) \
QScopedPointer<QQuickView> view(createView()); \
view->setSource(testFileUrl(fileName)); \
view->show(); \
QVERIFY(QTest::qWaitForWindowActive(view.data())); \
- CREATE_VAR_FROM_PROPERTY(tableView, QQuickTableView)
+ auto tableView = view->rootObject()->property(kTableViewPropName).value<QQuickTableView *>(); \
+ QVERIFY(tableView); \
+ auto tableViewPrivate = QQuickTableViewPrivate::get(tableView); \
+ Q_UNUSED(tableViewPrivate)
+
+#define WAIT_UNTIL_POLISHED \
+ QVERIFY(tableViewPrivate->polishScheduled); \
+ QTRY_VERIFY(!tableViewPrivate->polishScheduled)
class tst_QQuickTableView : public QQmlDataTest
{
@@ -68,7 +75,12 @@ public:
private slots:
void initTestCase() override;
- void setAndGetQAIM();
+ void setAndGetModel_data();
+ void setAndGetModel();
+ void emptyModel_data();
+ void emptyModel();
+ void countDelegateItems_data();
+ void countDelegateItems();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -81,14 +93,83 @@ void tst_QQuickTableView::initTestCase()
qmlRegisterType<TestModel>("TestModel", 0, 1, "TestModel");
}
-void tst_QQuickTableView::setAndGetQAIM()
+void tst_QQuickTableView::setAndGetModel_data()
+{
+ QTest::addColumn<QVariant>("model");
+
+ QTest::newRow("QAIM 1x1") << TestModelAsVariant(1, 1);
+ QTest::newRow("Number model 1") << QVariant::fromValue(1);
+ QTest::newRow("QStringList 1") << QVariant::fromValue(QStringList() << "one");
+}
+
+void tst_QQuickTableView::setAndGetModel()
+{
+ // Test that we can set and get different kind of models
+ QFETCH(QVariant, model);
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ tableView->setModel(model);
+ QCOMPARE(model, tableView->model());
+}
+
+void tst_QQuickTableView::emptyModel_data()
+{
+ QTest::addColumn<QVariant>("model");
+
+ QTest::newRow("QAIM") << TestModelAsVariant(0, 0);
+ QTest::newRow("Number model") << QVariant::fromValue(0);
+ QTest::newRow("QStringList") << QVariant::fromValue(QStringList());
+}
+
+void tst_QQuickTableView::emptyModel()
{
+ // Check that if we assign an empty model to
+ // TableView, no delegate items will be created.
+ QFETCH(QVariant, model);
LOAD_TABLEVIEW("plaintableview.qml");
- TestModel model(2, 2);
- tableView->setModel(QVariant::fromValue<QObject *>(&model));
- auto returnModel = tableView->model().value<TestModel *>();
- QCOMPARE(&model, returnModel);
+ tableView->setModel(model);
+ WAIT_UNTIL_POLISHED;
+ QCOMPARE(tableViewPrivate->loadedItems.count(), 0);
+}
+
+void tst_QQuickTableView::countDelegateItems_data()
+{
+ QTest::addColumn<QVariant>("model");
+ QTest::addColumn<int>("count");
+
+ QTest::newRow("QAIM 1x1") << TestModelAsVariant(1, 1) << 1;
+ QTest::newRow("QAIM 2x1") << TestModelAsVariant(2, 1) << 2;
+ QTest::newRow("QAIM 1x2") << TestModelAsVariant(1, 2) << 2;
+ QTest::newRow("QAIM 2x2") << TestModelAsVariant(2, 2) << 4;
+ QTest::newRow("QAIM 4x4") << TestModelAsVariant(4, 4) << 16;
+
+ QTest::newRow("Number model 1") << QVariant::fromValue(1) << 1;
+ QTest::newRow("Number model 4") << QVariant::fromValue(4) << 4;
+
+ QTest::newRow("QStringList 1") << QVariant::fromValue(QStringList() << "one") << 1;
+ QTest::newRow("QStringList 4") << QVariant::fromValue(QStringList() << "one" << "two" << "three" << "four") << 4;
+}
+
+void tst_QQuickTableView::countDelegateItems()
+{
+ // Assign different models of various sizes, and check that the number of
+ // delegate items in the view matches the size of the model. Note that for
+ // this test to be valid, all items must be within the visible area of the view.
+ QFETCH(QVariant, model);
+ QFETCH(int, count);
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ tableView->setModel(model);
+ WAIT_UNTIL_POLISHED;
+
+ // Check that tableview internals contain the expected number of items
+ auto const items = tableViewPrivate->loadedItems;
+ QCOMPARE(items.count(), count);
+
+ // Check that this also matches the items found in the view
+ auto foundItems = findItems<QQuickItem>(tableView, kDelegateObjectName);
+ QCOMPARE(foundItems.count(), count);
}
QTEST_MAIN(tst_QQuickTableView)