summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-02-10 01:09:56 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-02-10 01:09:56 (GMT)
commit0b18256d4d2d1c732845c4cba15af3231dbe8751 (patch)
treedd4283457a735da1daf700c1f4f802dfbdddd448 /tests/auto
parent4adf3144d79cf3affe2b83dabf5333134b6ec6f7 (diff)
parent3387c33fca6e518a5e08a48780f6268aeface839 (diff)
downloadQt-0b18256d4d2d1c732845c4cba15af3231dbe8751.zip
Qt-0b18256d4d2d1c732845c4cba15af3231dbe8751.tar.gz
Qt-0b18256d4d2d1c732845c4cba15af3231dbe8751.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/animations/tst_animations.cpp1
-rw-r--r--tests/auto/declarative/pathview/tst_pathview.cpp309
-rw-r--r--tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml2
-rw-r--r--tests/auto/declarative/qmlgraphicspathview/data/pathview.qml (renamed from tests/auto/declarative/pathview/data/pathview.qml)0
-rw-r--r--tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp93
-rw-r--r--tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp4
6 files changed, 91 insertions, 318 deletions
diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp
index 239c344..5026f6f 100644
--- a/tests/auto/declarative/animations/tst_animations.cpp
+++ b/tests/auto/declarative/animations/tst_animations.cpp
@@ -424,6 +424,7 @@ void tst_animations::properties()
QmlGraphicsRectangle *myRect = rect->findChild<QmlGraphicsRectangle*>("TheRect");
QVERIFY(myRect);
QTest::qWait(waitDuration);
+ QEXPECT_FAIL("", "QTBUG-8072", Continue);
QTIMED_COMPARE(myRect->x(),qreal(100));
QTIMED_COMPARE(myRect->y(),qreal(100));
}
diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp
deleted file mode 100644
index 360228b..0000000
--- a/tests/auto/declarative/pathview/tst_pathview.cpp
+++ /dev/null
@@ -1,309 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include <QtTest/QtTest>
-#include <private/qlistmodelinterface_p.h>
-#include <qmlview.h>
-#include <private/qmlgraphicspathview_p.h>
-#include <private/qmlgraphicstext_p.h>
-#include <private/qmlgraphicsrectangle_p.h>
-#include <qmlcontext.h>
-#include <qmlexpression.h>
-
-class tst_QmlGraphicsPathView : public QObject
-{
- Q_OBJECT
-public:
- tst_QmlGraphicsPathView();
-
-private slots:
- void items();
- void pathMoved();
- void limitedItems();
-
-private:
- QmlView *createView(const QString &filename);
- template<typename T>
- T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1);
-};
-
-class TestModel : public QListModelInterface
-{
- Q_OBJECT
-public:
- TestModel(QObject *parent = 0) : QListModelInterface(parent) {}
- ~TestModel() {}
-
- enum Roles { Name, Number };
-
- QString name(int index) const { return list.at(index).first; }
- QString number(int index) const { return list.at(index).second; }
-
- int count() const { return list.count(); }
-
- QList<int> roles() const { return QList<int>() << Name << Number; }
- QString toString(int role) const {
- switch(role) {
- case Name:
- return "name";
- case Number:
- return "number";
- default:
- return "";
- }
- }
-
- QHash<int, QVariant> data(int index, const QList<int> &roles) const {
- QHash<int,QVariant> returnHash;
-
- for (int i = 0; i < roles.size(); ++i) {
- int role = roles.at(i);
- QVariant info;
- switch(role) {
- case Name:
- info = list.at(index).first;
- break;
- case Number:
- info = list.at(index).second;
- break;
- default:
- break;
- }
- returnHash.insert(role, info);
- }
- return returnHash;
- }
-
- QVariant data(int index, int role) const {
- if (role == 0)
- return list.at(index).first;
- if (role == 1)
- return list.at(index).second;
- return QVariant();
- }
-
- void addItem(const QString &name, const QString &number) {
- list.append(QPair<QString,QString>(name, number));
- emit itemsInserted(list.count()-1, 1);
- }
-
- void insertItem(int index, const QString &name, const QString &number) {
- list.insert(index, QPair<QString,QString>(name, number));
- emit itemsInserted(index, 1);
- }
-
- void removeItem(int index) {
- list.removeAt(index);
- emit itemsRemoved(index, 1);
- }
-
- void modifyItem(int index, const QString &name, const QString &number) {
- list[index] = QPair<QString,QString>(name, number);
- emit itemsChanged(index, 1, roles());
- }
-
-private:
- QList<QPair<QString,QString> > list;
-};
-
-tst_QmlGraphicsPathView::tst_QmlGraphicsPathView()
-{
-}
-
-void tst_QmlGraphicsPathView::items()
-{
- QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
-
- TestModel model;
- model.addItem("Fred", "12345");
- model.addItem("John", "2345");
- model.addItem("Bob", "54321");
-
- QmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->execute();
- qApp->processEvents();
-
- QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
- QVERIFY(pathview != 0);
-
- QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible
-
- for (int i = 0; i < model.count(); ++i) {
- QmlGraphicsText *name = findItem<QmlGraphicsText>(pathview, "textName", i);
- QVERIFY(name != 0);
- QCOMPARE(name->text(), model.name(i));
- QmlGraphicsText *number = findItem<QmlGraphicsText>(pathview, "textNumber", i);
- QVERIFY(number != 0);
- QCOMPARE(number->text(), model.number(i));
- }
-
- delete canvas;
-}
-
-void tst_QmlGraphicsPathView::pathMoved()
-{
- QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
-
- TestModel model;
- model.addItem("Ben", "12345");
- model.addItem("Bohn", "2345");
- model.addItem("Bob", "54321");
- model.addItem("Bill", "4321");
-
- QmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->execute();
- qApp->processEvents();
-
- QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
- QVERIFY(pathview != 0);
-
- QmlGraphicsRectangle *firstItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 0);
- QVERIFY(firstItem);
- QmlGraphicsPath *path = qobject_cast<QmlGraphicsPath*>(pathview->path());
- QVERIFY(path);
- QPointF start = path->pointAt(0.0);
- QPointF offset;//Center of item is at point, but pos is from corner
- offset.setX(firstItem->width()/2);
- offset.setY(firstItem->height()/2);
- QCOMPARE(firstItem->pos() + offset, start);
- pathview->setOffset(10);
- QTest::qWait(1000);//Moving is animated?
-
- for(int i=0; i<model.count(); i++){
- QmlGraphicsRectangle *curItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", i);
- QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25));
- }
-
- pathview->setOffset(100);
- QTest::qWait(1000);//Moving is animated?
- QCOMPARE(firstItem->pos() + offset, start);
-
- delete canvas;
-}
-
-void tst_QmlGraphicsPathView::limitedItems()
-{
- QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
-
- TestModel model;
- for(int i=0; i<100; i++)
- model.addItem("Bob", QString::number(i));
-
- QmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->execute();
- qApp->processEvents();
-
- QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
- QVERIFY(pathview != 0);
-
- pathview->setPathItemCount(10);
- QCOMPARE(pathview->pathItemCount(), 10);
-
- QmlGraphicsRectangle *testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 0);
- QVERIFY(testItem != 0);
- testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 9);
- QVERIFY(testItem != 0);
- testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 10);
- QVERIFY(testItem == 0);
-
- pathview->setCurrentIndex(50);
- QTest::qWait(5100);//Moving is animated and it's travelling far - should be reconsidered.
- testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 0);
- QVERIFY(testItem == 0);
- testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 1);
- QVERIFY(testItem == 0);
- testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 9);
- QVERIFY(testItem == 0);
- testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 50);
- QVERIFY(testItem != 0);
-}
-
-QmlView *tst_QmlGraphicsPathView::createView(const QString &filename)
-{
- QmlView *canvas = new QmlView(0);
- canvas->setFixedSize(240,320);
-
- QFile file(filename);
- file.open(QFile::ReadOnly);
- QString qml = file.readAll();
- canvas->setQml(qml, filename);
-
- return canvas;
-}
-
-/*
- Find an item with the specified objectName. If index is supplied then the
- item must also evaluate the {index} expression equal to index
-*/
-template<typename T>
-T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index)
-{
- const QMetaObject &mo = T::staticMetaObject;
- for (int i = 0; i < parent->children().count(); ++i) {
- QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->children().at(i));
- if(!item)
- continue;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
- if (index != -1) {
- QmlExpression e(qmlContext(item), "index", item);
- e.setTrackChange(false);
- if (e.value().toInt() == index)
- return static_cast<T*>(item);
- } else {
- return static_cast<T*>(item);
- }
- }
- item = findItem<T>(item, objectName, index);
- if (item)
- return static_cast<T*>(item);
- }
-
- return 0;
-}
-
-QTEST_MAIN(tst_QmlGraphicsPathView)
-
-#include "tst_pathview.moc"
diff --git a/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml
index 9d08e5d..8d07db2 100644
--- a/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml
+++ b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml
@@ -8,7 +8,7 @@ PathView {
function checkProperties() {
testObject.error = false;
- if (testObject.useModel && view.model != itemModel) {
+ if (testObject.useModel && pathview.model != testData) {
console.log("model property incorrect");
testObject.error = true;
}
diff --git a/tests/auto/declarative/pathview/data/pathview.qml b/tests/auto/declarative/qmlgraphicspathview/data/pathview.qml
index 8fa8d59..8fa8d59 100644
--- a/tests/auto/declarative/pathview/data/pathview.qml
+++ b/tests/auto/declarative/qmlgraphicspathview/data/pathview.qml
diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp
index e60ac5c..09b12b8 100644
--- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp
+++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp
@@ -47,6 +47,7 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qmlview.h>
#include <QtDeclarative/private/qmlgraphicstext_p.h>
+#include <QtDeclarative/private/qmlgraphicsrectangle_p.h>
#include <QAbstractListModel>
#include <QFile>
#include <private/qmlvaluetype_p.h>
@@ -60,10 +61,12 @@ public:
private slots:
void initValues();
+ void items();
void dataModel();
void pathview2();
void pathview3();
void path();
+ void pathMoved();
private:
QmlView *createView(const QString &filename);
@@ -186,6 +189,38 @@ void tst_QmlGraphicsPathView::initValues()
QCOMPARE(obj->pathItemCount(), -1);
}
+void tst_QmlGraphicsPathView::items()
+{
+ QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
+
+ TestModel model;
+ model.addItem("Fred", "12345");
+ model.addItem("John", "2345");
+ model.addItem("Bob", "54321");
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
+ QVERIFY(pathview != 0);
+
+ QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible
+
+ for (int i = 0; i < model.count(); ++i) {
+ QmlGraphicsText *name = findItem<QmlGraphicsText>(pathview, "textName", i);
+ QVERIFY(name != 0);
+ QCOMPARE(name->text(), model.name(i));
+ QmlGraphicsText *number = findItem<QmlGraphicsText>(pathview, "textNumber", i);
+ QVERIFY(number != 0);
+ QCOMPARE(number->text(), model.number(i));
+ }
+
+ delete canvas;
+}
+
void tst_QmlGraphicsPathView::pathview2()
{
QmlEngine engine;
@@ -323,6 +358,11 @@ void tst_QmlGraphicsPathView::dataModel()
itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count();
QCOMPARE(itemCount, 5);
+ QmlGraphicsRectangle *testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 4);
+ QVERIFY(testItem != 0);
+ testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 5);
+ QVERIFY(testItem == 0);
+
model.insertItem(2, "pink", "2");
itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count();
@@ -342,6 +382,49 @@ void tst_QmlGraphicsPathView::dataModel()
delete canvas;
}
+void tst_QmlGraphicsPathView::pathMoved()
+{
+ QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
+
+ TestModel model;
+ model.addItem("Ben", "12345");
+ model.addItem("Bohn", "2345");
+ model.addItem("Bob", "54321");
+ model.addItem("Bill", "4321");
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
+ QVERIFY(pathview != 0);
+
+ QmlGraphicsRectangle *firstItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 0);
+ QVERIFY(firstItem);
+ QmlGraphicsPath *path = qobject_cast<QmlGraphicsPath*>(pathview->path());
+ QVERIFY(path);
+ QPointF start = path->pointAt(0.0);
+ QPointF offset;//Center of item is at point, but pos is from corner
+ offset.setX(firstItem->width()/2);
+ offset.setY(firstItem->height()/2);
+ QCOMPARE(firstItem->pos() + offset, start);
+ pathview->setOffset(10);
+ QTest::qWait(1000);//Moving is animated?
+
+ for(int i=0; i<model.count(); i++){
+ QmlGraphicsRectangle *curItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", i);
+ QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25));
+ }
+
+ pathview->setOffset(100);
+ QTest::qWait(1000);//Moving is animated?
+ QCOMPARE(firstItem->pos() + offset, start);
+
+ delete canvas;
+}
+
QmlView *tst_QmlGraphicsPathView::createView(const QString &filename)
{
QmlView *canvas = new QmlView(0);
@@ -363,9 +446,9 @@ template<typename T>
T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index)
{
const QMetaObject &mo = T::staticMetaObject;
- //qDebug() << parent->QGraphicsObject::children().count() << "children";
- for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) {
- QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i));
+ //qDebug() << parent->childItems().count() << "children";
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->childItems().at(i));
if(!item)
continue;
//qDebug() << "try" << item;
@@ -393,8 +476,8 @@ QList<T*> tst_QmlGraphicsPathView::findItems(QmlGraphicsItem *parent, const QStr
QList<T*> items;
const QMetaObject &mo = T::staticMetaObject;
//qDebug() << parent->QGraphicsObject::children().count() << "children";
- for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) {
- QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i));
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->childItems().at(i));
if(!item)
continue;
//qDebug() << "try" << item;
diff --git a/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp
index 7fd6780..50de8d5 100644
--- a/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp
+++ b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp
@@ -122,9 +122,7 @@ void tst_qmlpixmapcache::single()
QFETCH(bool, neterror);
if (neterror) {
- QString expected = "Network error loading \""
- +target.toString()+"\" \"Error downloading "
- +target.toString()+" - server replied: Not Found\" ";
+ QString expected = "\"Error downloading " + target.toString() + " - server replied: Not Found\" ";
QTest::ignoreMessage(QtWarningMsg, expected.toLatin1());
} else if (!exists) {
QString expected = "Cannot open QUrl( \"" + target.toString() + "\" ) ";