aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativelistreference
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit885735d011472bcfbb96e688d9e64553d7fe9d4b (patch)
tree734963625eba643bf11bc4870a4c407809a6400a /tests/auto/declarative/qdeclarativelistreference
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'tests/auto/declarative/qdeclarativelistreference')
-rw-r--r--tests/auto/declarative/qdeclarativelistreference/data/MyType.qml5
-rw-r--r--tests/auto/declarative/qdeclarativelistreference/data/engineTypes.qml9
-rw-r--r--tests/auto/declarative/qdeclarativelistreference/data/variantToList.qml10
-rw-r--r--tests/auto/declarative/qdeclarativelistreference/qdeclarativelistreference.pro8
-rw-r--r--tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp579
5 files changed, 611 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelistreference/data/MyType.qml b/tests/auto/declarative/qdeclarativelistreference/data/MyType.qml
new file mode 100644
index 0000000000..0687ce3995
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistreference/data/MyType.qml
@@ -0,0 +1,5 @@
+import QtQuick 1.0
+
+QtObject {
+ property int a
+}
diff --git a/tests/auto/declarative/qdeclarativelistreference/data/engineTypes.qml b/tests/auto/declarative/qdeclarativelistreference/data/engineTypes.qml
new file mode 100644
index 0000000000..9ddc763356
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistreference/data/engineTypes.qml
@@ -0,0 +1,9 @@
+import QtQuick 1.0
+
+QtObject {
+ property list<MyType> myList
+
+ myList: [ MyType { a: 1 },
+ MyType { a: 9 } ]
+
+}
diff --git a/tests/auto/declarative/qdeclarativelistreference/data/variantToList.qml b/tests/auto/declarative/qdeclarativelistreference/data/variantToList.qml
new file mode 100644
index 0000000000..39a49e81fe
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistreference/data/variantToList.qml
@@ -0,0 +1,10 @@
+import QtQuick 1.0
+
+QtObject {
+ property list<QtObject> myList;
+ myList: QtObject {}
+
+ property variant value: myList
+ property int test: value.length
+}
+
diff --git a/tests/auto/declarative/qdeclarativelistreference/qdeclarativelistreference.pro b/tests/auto/declarative/qdeclarativelistreference/qdeclarativelistreference.pro
new file mode 100644
index 0000000000..f3e6f52947
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistreference/qdeclarativelistreference.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qdeclarativelistreference.cpp
+
+CONFIG += parallel_test
+
diff --git a/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp b/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp
new file mode 100644
index 0000000000..af699384c7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp
@@ -0,0 +1,579 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 <qtest.h>
+#include <QUrl>
+#include <QFileInfo>
+#include <QDir>
+#include <QDeclarativeEngine>
+#include <QDeclarativeComponent>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/qdeclarativeprivate.h>
+#include <QtDeclarative/qdeclarativeproperty.h>
+#include <QDebug>
+
+inline QUrl TEST_FILE(const QString &filename)
+{
+ QFileInfo fileInfo(__FILE__);
+ return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename));
+}
+
+inline QUrl TEST_FILE(const char *filename)
+{
+ return TEST_FILE(QLatin1String(filename));
+}
+
+class tst_qdeclarativelistreference : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qdeclarativelistreference() {}
+
+private slots:
+ void initTestCase();
+ void qmllistreference();
+ void qmllistreference_invalid();
+ void isValid();
+ void object();
+ void listElementType();
+ void canAppend();
+ void canAt();
+ void canClear();
+ void canCount();
+ void append();
+ void at();
+ void clear();
+ void count();
+ void copy();
+ void qmlmetaproperty();
+ void engineTypes();
+ void variantToList();
+};
+
+class TestType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDeclarativeListProperty<TestType> data READ dataProperty)
+ Q_PROPERTY(int intProperty READ intProperty)
+
+public:
+ TestType() : property(this, data) {}
+ QDeclarativeListProperty<TestType> dataProperty() { return property; }
+ int intProperty() const { return 10; }
+
+ QList<TestType *> data;
+ QDeclarativeListProperty<TestType> property;
+};
+
+void tst_qdeclarativelistreference::initTestCase()
+{
+ qmlRegisterType<TestType>();
+}
+
+void tst_qdeclarativelistreference::qmllistreference()
+{
+ TestType tt;
+
+ QDeclarativeListReference r(&tt, "data");
+ QVERIFY(r.isValid() == true);
+ QCOMPARE(r.count(), 0);
+
+ tt.data.append(&tt);
+ QCOMPARE(r.count(), 1);
+}
+
+void tst_qdeclarativelistreference::qmllistreference_invalid()
+{
+ TestType tt;
+
+ // Invalid
+ {
+ QDeclarativeListReference r;
+ QVERIFY(r.isValid() == false);
+ QVERIFY(r.object() == 0);
+ QVERIFY(r.listElementType() == 0);
+ QVERIFY(r.canAt() == false);
+ QVERIFY(r.canClear() == false);
+ QVERIFY(r.canCount() == false);
+ QVERIFY(r.append(0) == false);
+ QVERIFY(r.at(10) == 0);
+ QVERIFY(r.clear() == false);
+ QVERIFY(r.count() == 0);
+ }
+
+ // Non-property
+ {
+ QDeclarativeListReference r(&tt, "blah");
+ QVERIFY(r.isValid() == false);
+ QVERIFY(r.object() == 0);
+ QVERIFY(r.listElementType() == 0);
+ QVERIFY(r.canAt() == false);
+ QVERIFY(r.canClear() == false);
+ QVERIFY(r.canCount() == false);
+ QVERIFY(r.append(0) == false);
+ QVERIFY(r.at(10) == 0);
+ QVERIFY(r.clear() == false);
+ QVERIFY(r.count() == 0);
+ }
+
+ // Non-list property
+ {
+ QDeclarativeListReference r(&tt, "intProperty");
+ QVERIFY(r.isValid() == false);
+ QVERIFY(r.object() == 0);
+ QVERIFY(r.listElementType() == 0);
+ QVERIFY(r.canAt() == false);
+ QVERIFY(r.canClear() == false);
+ QVERIFY(r.canCount() == false);
+ QVERIFY(r.append(0) == false);
+ QVERIFY(r.at(10) == 0);
+ QVERIFY(r.clear() == false);
+ QVERIFY(r.count() == 0);
+ }
+}
+
+void tst_qdeclarativelistreference::isValid()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.isValid() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.isValid() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.isValid() == true);
+ delete tt;
+ QVERIFY(ref.isValid() == false);
+ }
+}
+
+void tst_qdeclarativelistreference::object()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.object() == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.object() == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.object() == tt);
+ delete tt;
+ QVERIFY(ref.object() == 0);
+ }
+}
+
+void tst_qdeclarativelistreference::listElementType()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.listElementType() == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.listElementType() == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.listElementType() == &TestType::staticMetaObject);
+ delete tt;
+ QVERIFY(ref.listElementType() == 0);
+ }
+}
+
+void tst_qdeclarativelistreference::canAppend()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.canAppend() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.canAppend() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.canAppend() == true);
+ delete tt;
+ QVERIFY(ref.canAppend() == false);
+ }
+
+ {
+ TestType tt;
+ tt.property.append = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.canAppend() == false);
+ }
+}
+
+void tst_qdeclarativelistreference::canAt()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.canAt() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.canAt() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.canAt() == true);
+ delete tt;
+ QVERIFY(ref.canAt() == false);
+ }
+
+ {
+ TestType tt;
+ tt.property.at = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.canAt() == false);
+ }
+}
+
+void tst_qdeclarativelistreference::canClear()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.canClear() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.canClear() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.canClear() == true);
+ delete tt;
+ QVERIFY(ref.canClear() == false);
+ }
+
+ {
+ TestType tt;
+ tt.property.clear = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.canClear() == false);
+ }
+}
+
+void tst_qdeclarativelistreference::canCount()
+{
+ TestType *tt = new TestType;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.canCount() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.canCount() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.canCount() == true);
+ delete tt;
+ QVERIFY(ref.canCount() == false);
+ }
+
+ {
+ TestType tt;
+ tt.property.count = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.canCount() == false);
+ }
+}
+
+void tst_qdeclarativelistreference::append()
+{
+ TestType *tt = new TestType;
+ QObject object;
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.append(tt) == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.append(tt) == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.append(tt) == true);
+ QVERIFY(tt->data.count() == 1);
+ QVERIFY(tt->data.at(0) == tt);
+ QVERIFY(ref.append(&object) == false);
+ QVERIFY(tt->data.count() == 1);
+ QVERIFY(tt->data.at(0) == tt);
+ QVERIFY(ref.append(0) == true);
+ QVERIFY(tt->data.count() == 2);
+ QVERIFY(tt->data.at(0) == tt);
+ QVERIFY(tt->data.at(1) == 0);
+ delete tt;
+ QVERIFY(ref.append(0) == false);
+ }
+
+ {
+ TestType tt;
+ tt.property.append = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.append(&tt) == false);
+ }
+}
+
+void tst_qdeclarativelistreference::at()
+{
+ TestType *tt = new TestType;
+ tt->data.append(tt);
+ tt->data.append(0);
+ tt->data.append(tt);
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.at(0) == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.at(0) == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.at(0) == tt);
+ QVERIFY(ref.at(1) == 0);
+ QVERIFY(ref.at(2) == tt);
+ delete tt;
+ QVERIFY(ref.at(0) == 0);
+ }
+
+ {
+ TestType tt;
+ tt.data.append(&tt);
+ tt.property.at = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.at(0) == 0);
+ }
+}
+
+void tst_qdeclarativelistreference::clear()
+{
+ TestType *tt = new TestType;
+ tt->data.append(tt);
+ tt->data.append(0);
+ tt->data.append(tt);
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.clear() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.clear() == false);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.clear() == true);
+ QVERIFY(tt->data.count() == 0);
+ delete tt;
+ QVERIFY(ref.clear() == false);
+ }
+
+ {
+ TestType tt;
+ tt.property.clear = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.clear() == false);
+ }
+}
+
+void tst_qdeclarativelistreference::count()
+{
+ TestType *tt = new TestType;
+ tt->data.append(tt);
+ tt->data.append(0);
+ tt->data.append(tt);
+
+ {
+ QDeclarativeListReference ref;
+ QVERIFY(ref.count() == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "blah");
+ QVERIFY(ref.count() == 0);
+ }
+
+ {
+ QDeclarativeListReference ref(tt, "data");
+ QVERIFY(ref.count() == 3);
+ tt->data.removeAt(1);
+ QVERIFY(ref.count() == 2);
+ delete tt;
+ QVERIFY(ref.count() == 0);
+ }
+
+ {
+ TestType tt;
+ tt.data.append(&tt);
+ tt.property.count = 0;
+ QDeclarativeListReference ref(&tt, "data");
+ QVERIFY(ref.count() == 0);
+ }
+}
+
+void tst_qdeclarativelistreference::copy()
+{
+ TestType tt;
+ tt.data.append(&tt);
+ tt.data.append(0);
+ tt.data.append(&tt);
+
+ QDeclarativeListReference *r1 = new QDeclarativeListReference(&tt, "data");
+ QVERIFY(r1->count() == 3);
+
+ QDeclarativeListReference r2(*r1);
+ QDeclarativeListReference r3;
+ r3 = *r1;
+
+ QVERIFY(r2.count() == 3);
+ QVERIFY(r3.count() == 3);
+
+ delete r1;
+
+ QVERIFY(r2.count() == 3);
+ QVERIFY(r3.count() == 3);
+
+ tt.data.removeAt(2);
+
+ QVERIFY(r2.count() == 2);
+ QVERIFY(r3.count() == 2);
+}
+
+void tst_qdeclarativelistreference::qmlmetaproperty()
+{
+ TestType tt;
+ tt.data.append(&tt);
+ tt.data.append(0);
+ tt.data.append(&tt);
+
+ QDeclarativeProperty prop(&tt, QLatin1String("data"));
+ QVariant v = prop.read();
+ QVERIFY(v.userType() == qMetaTypeId<QDeclarativeListReference>());
+ QDeclarativeListReference ref = qvariant_cast<QDeclarativeListReference>(v);
+ QVERIFY(ref.count() == 3);
+ QVERIFY(ref.listElementType() == &TestType::staticMetaObject);
+}
+
+void tst_qdeclarativelistreference::engineTypes()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, TEST_FILE("engineTypes.qml"));
+
+ QObject *o = component.create();
+ QVERIFY(o);
+
+ QDeclarativeProperty p1(o, QLatin1String("myList"));
+ QVERIFY(p1.propertyTypeCategory() == QDeclarativeProperty::Normal);
+
+ QDeclarativeProperty p2(o, QLatin1String("myList"), engine.rootContext());
+ QVERIFY(p2.propertyTypeCategory() == QDeclarativeProperty::List);
+ QVariant v = p2.read();
+ QVERIFY(v.userType() == qMetaTypeId<QDeclarativeListReference>());
+ QDeclarativeListReference ref = qvariant_cast<QDeclarativeListReference>(v);
+ QVERIFY(ref.count() == 2);
+ QVERIFY(ref.listElementType());
+ QVERIFY(ref.listElementType() != &QObject::staticMetaObject);
+
+ delete o;
+}
+
+void tst_qdeclarativelistreference::variantToList()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, TEST_FILE("variantToList.qml"));
+
+ QObject *o = component.create();
+ QVERIFY(o);
+
+ QVERIFY(o->property("value").userType() == qMetaTypeId<QDeclarativeListReference>());
+ QCOMPARE(o->property("test").toInt(), 1);
+
+ delete o;
+}
+
+QTEST_MAIN(tst_qdeclarativelistreference)
+
+#include "tst_qdeclarativelistreference.moc"