summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-11-11 03:40:16 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-11-11 03:40:16 (GMT)
commit8768193ce3a3dc26508a911e189a084ed72d019a (patch)
treee449ce0bfc37316918dd2414c38a81ddf9c84fb9 /tests/auto
parent0de7d028b8ec71109d4d3eba7d15d704e42d76da (diff)
downloadQt-8768193ce3a3dc26508a911e189a084ed72d019a.zip
Qt-8768193ce3a3dc26508a911e189a084ed72d019a.tar.gz
Qt-8768193ce3a3dc26508a911e189a084ed72d019a.tar.bz2
Autotests.
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/layouts/data/layouts.qml2
-rw-r--r--tests/auto/declarative/layouts/tst_layouts.cpp13
-rw-r--r--tests/auto/declarative/numberformatter/tst_numberformatter.cpp2
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml10
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp49
5 files changed, 72 insertions, 4 deletions
diff --git a/tests/auto/declarative/layouts/data/layouts.qml b/tests/auto/declarative/layouts/data/layouts.qml
index b0ee63b..00d785d 100644
--- a/tests/auto/declarative/layouts/data/layouts.qml
+++ b/tests/auto/declarative/layouts/data/layouts.qml
@@ -6,7 +6,7 @@ Item {
height:300
GraphicsObjectContainer {
- anchors.fill:parent
+ anchors.fill: parent
synchronizedResizing: true
QGraphicsWidget {
diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp
index 1c2330d..0f832bf 100644
--- a/tests/auto/declarative/layouts/tst_layouts.cpp
+++ b/tests/auto/declarative/layouts/tst_layouts.cpp
@@ -43,6 +43,7 @@
#include <qmlview.h>
#include <private/qmlgraphicslayoutitem_p.h>
#include <qmlexpression.h>
+#include <QStyle>
class tst_QmlGraphicsLayouts : public QObject
{
@@ -74,7 +75,12 @@ void tst_QmlGraphicsLayouts::test_qml()
QmlGraphicsLayoutItem *right = static_cast<QmlGraphicsLayoutItem*>(canvas->root()->findChild<QmlGraphicsItem*>("right"));
QVERIFY(right != 0);
- qreal gvMargin = 9.0;
+ qreal l = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
+ qreal r = QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin);
+ qreal t = QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
+ qreal b = QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin);
+ QVERIFY2(l == r && r == t && t == b, "Test assumes equal margins.");
+ qreal gvMargin = l;
//Preferred Size
canvas->root()->setWidth(300 + 2*gvMargin);
canvas->root()->setHeight(300 + 2*gvMargin);
@@ -116,6 +122,7 @@ void tst_QmlGraphicsLayouts::test_qml()
QCOMPARE(right->width(), 400.0);
QCOMPARE(right->height(), 300.0);
+ delete canvas;
}
void tst_QmlGraphicsLayouts::test_cpp()
@@ -129,8 +136,8 @@ QmlView *tst_QmlGraphicsLayouts::createView(const QString &filename)
QFile file(filename);
file.open(QFile::ReadOnly);
- QString xml = file.readAll();
- canvas->setQml(xml, filename);
+ QString qml = file.readAll();
+ canvas->setQml(qml, filename);
return canvas;
}
diff --git a/tests/auto/declarative/numberformatter/tst_numberformatter.cpp b/tests/auto/declarative/numberformatter/tst_numberformatter.cpp
index 152d6e3..1d68f35 100644
--- a/tests/auto/declarative/numberformatter/tst_numberformatter.cpp
+++ b/tests/auto/declarative/numberformatter/tst_numberformatter.cpp
@@ -212,6 +212,8 @@ void tst_numberformat::text()
QCOMPARE(formatter->format(), format);
QCOMPARE(formatter->text(), text);
+
+ delete formatter;
}
QTEST_MAIN(tst_numberformat)
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml b/tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml
new file mode 100644
index 0000000..26c533f
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml
@@ -0,0 +1,10 @@
+import Qt 4.6
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "/name/string()" } //starts with '/'
+ XmlRole { name: "type"; query: "type" } //no type
+ XmlRole { name: "age"; query: "age/" } //ends with '/'
+ XmlRole { name: "size"; query: "size/number()" } //wrong type
+}
diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
index 4898686..71bc4f9 100644
--- a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
+++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
@@ -56,6 +56,8 @@ private slots:
void missingFields();
void cdata();
void attributes();
+ void roles();
+ void roleErrors();
private:
QmlEngine engine;
@@ -76,6 +78,8 @@ void tst_qmlxmllistmodel::buildModel()
QCOMPARE(data.value(Qt::UserRole+1).toString(), QLatin1String("Dog"));
QCOMPARE(data.value(Qt::UserRole+2).toInt(), 9);
QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium"));
+
+ delete listModel;
}
void tst_qmlxmllistmodel::missingFields()
@@ -95,6 +99,8 @@ void tst_qmlxmllistmodel::missingFields()
data = listModel->data(7, roles);
QVERIFY(data.count() == 5);
QCOMPARE(data.value(Qt::UserRole+2).toString(), QLatin1String(""));
+
+ delete listModel;
}
void tst_qmlxmllistmodel::cdata()
@@ -109,6 +115,8 @@ void tst_qmlxmllistmodel::cdata()
QHash<int, QVariant> data = listModel->data(2, roles);
QVERIFY(data.count() == 1);
QVERIFY(data.value(Qt::UserRole+2).toString().startsWith(QLatin1String("<html>")));
+
+ delete listModel;
}
void tst_qmlxmllistmodel::attributes()
@@ -123,8 +131,49 @@ void tst_qmlxmllistmodel::attributes()
QHash<int, QVariant> data = listModel->data(2, roles);
QVERIFY(data.count() == 1);
QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Vegetable Soup"));
+
+ delete listModel;
+}
+
+void tst_qmlxmllistmodel::roles()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model.qml"));
+ QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create());
+ QVERIFY(listModel != 0);
+ QTRY_COMPARE(listModel->count(), 9);
+
+ QList<int> roles = listModel->roles();
+ QCOMPARE(roles.count(), 4);
+ QCOMPARE(listModel->toString(roles.at(0)), QLatin1String("name"));
+ QCOMPARE(listModel->toString(roles.at(1)), QLatin1String("type"));
+ QCOMPARE(listModel->toString(roles.at(2)), QLatin1String("age"));
+ QCOMPARE(listModel->toString(roles.at(3)), QLatin1String("size"));
+
+ delete listModel;
}
+void tst_qmlxmllistmodel::roleErrors()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/roleErrors.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QML QmlXmlListModelRole (file://" SRCDIR "/data/roleErrors.qml:6:5) An XmlRole query must not start with '/'");
+ //### make sure we receive all expected warning messages.
+ QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create());
+ QVERIFY(listModel != 0);
+ QTRY_COMPARE(listModel->count(), 9);
+
+ QList<int> roles;
+ roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3;
+ QHash<int, QVariant> data = listModel->data(3, roles);
+ QVERIFY(data.count() == 4);
+
+ //### should any of these return valid values?
+ QCOMPARE(data.value(Qt::UserRole), QVariant());
+ QCOMPARE(data.value(Qt::UserRole+1), QVariant());
+ QCOMPARE(data.value(Qt::UserRole+2), QVariant());
+ QCOMPARE(data.value(Qt::UserRole+3), QVariant());
+
+ delete listModel;
+}
QTEST_MAIN(tst_qmlxmllistmodel)