aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2012-06-26 09:47:43 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-26 04:29:34 +0200
commit895ec534acb63eacd625e2f320cb266dbff3fdb3 (patch)
tree694a151a3611b832cb68c133b2a18f0d57200785 /tests
parent9fd34288efdbb5c77d002408dd83bccbd654292f (diff)
Add warning if defining a ListModel with no roles.
When static ListElement types are declared, the role names are inferred from them at compile time. If they are all empty, it's not possible to add roles to the model, so warn the user of this case. Task-number: QTBUG-21438 Change-Id: Ib4ac30e160c44a5a57ebd1c49fccc2b3db5f0977 Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
index 89e88869e3..e94fe81024 100644
--- a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
+++ b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
@@ -123,6 +123,8 @@ private slots:
void role_mode_data();
void role_mode();
void string_to_list_crash();
+ void empty_element_warning();
+ void empty_element_warning_data();
};
bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1189,6 +1191,41 @@ void tst_qquicklistmodel::string_to_list_crash()
e.evaluate();
}
+void tst_qquicklistmodel::empty_element_warning_data()
+{
+ QTest::addColumn<QString>("qml");
+ QTest::addColumn<bool>("warning");
+
+ QTest::newRow("empty") << "import QtQuick 2.0\nListModel {}" << false;
+ QTest::newRow("withid") << "import QtQuick 2.0\nListModel { id: model }" << false;
+ QTest::newRow("emptyElement") << "import QtQuick 2.0\nListModel { ListElement {} }" << true;
+ QTest::newRow("emptyElements") << "import QtQuick 2.0\nListModel { ListElement {} ListElement {} }" << true;
+ QTest::newRow("role1") << "import QtQuick 2.0\nListModel { ListElement {a:1} }" << false;
+ QTest::newRow("role2") << "import QtQuick 2.0\nListModel { ListElement {} ListElement {a:1} ListElement {} }" << false;
+ QTest::newRow("role3") << "import QtQuick 2.0\nListModel { ListElement {} ListElement {a:1} ListElement {b:2} }" << false;
+}
+
+void tst_qquicklistmodel::empty_element_warning()
+{
+ QFETCH(QString, qml);
+ QFETCH(bool, warning);
+
+ if (warning) {
+ QString warningString = QLatin1String("file:dummy.qml:2:1: QML ListModel: All ListElement declarations are empty, no roles can be created unless dynamicRoles is set.");
+ QTest::ignoreMessage(QtWarningMsg, warningString.toLatin1());
+ }
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(qml.toUtf8(), QUrl::fromLocalFile(QString("dummy.qml")));
+ QVERIFY(!component.isError());
+
+ QObject *obj = component.create();
+ QVERIFY(obj != 0);
+
+ delete obj;
+}
+
QTEST_MAIN(tst_qquicklistmodel)
#include "tst_qquicklistmodel.moc"