1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeContext>
45 #include <QDeclarativeComponent>
48 #include "testtypes.h"
50 class tst_binding : public QObject
56 virtual ~tst_binding();
60 void cleanupTestCase();
63 void objectproperty_data();
64 void objectproperty();
65 void basicproperty_data();
71 QDeclarativeEngine engine;
72 MyQmlObject tstObject;
75 tst_binding::tst_binding()
79 tst_binding::~tst_binding()
83 void tst_binding::initTestCase()
86 engine.rootContext()->setContextProperty("tstObject", &tstObject);
89 void tst_binding::cleanupTestCase()
93 #define COMPONENT(filename, binding) \
94 QDeclarativeComponent c(&engine); \
97 QVERIFY(f.open(QIODevice::ReadOnly)); \
98 QByteArray data = f.readAll(); \
99 data.replace("###", binding.toUtf8()); \
100 c.setData(data, QUrl()); \
101 QVERIFY(c.isReady()); \
104 void tst_binding::objectproperty_data()
106 QTest::addColumn<QString>("file");
107 QTest::addColumn<QString>("binding");
109 QTest::newRow("object.value") << SRCDIR "/data/objectproperty.txt" << "object.value";
110 QTest::newRow("object.value + 10") << SRCDIR "/data/objectproperty.txt" << "object.value + 10";
113 void tst_binding::objectproperty()
115 QFETCH(QString, file);
116 QFETCH(QString, binding);
118 COMPONENT(file, binding);
123 MyQmlObject *object = qobject_cast<MyQmlObject *>(c.create());
124 QVERIFY(object != 0);
125 object->setObject(&object2);
128 object->setObject(&object1);
129 object->setObject(&object2);
133 void tst_binding::basicproperty_data()
135 QTest::addColumn<QString>("file");
136 QTest::addColumn<QString>("binding");
138 QTest::newRow("value") << SRCDIR "/data/localproperty.txt" << "value";
139 QTest::newRow("value + 10") << SRCDIR "/data/localproperty.txt" << "value + 10";
140 QTest::newRow("value + value + 10") << SRCDIR "/data/localproperty.txt" << "value + value + 10";
142 QTest::newRow("myObject.value") << SRCDIR "/data/idproperty.txt" << "myObject.value";
143 QTest::newRow("myObject.value + 10") << SRCDIR "/data/idproperty.txt" << "myObject.value + 10";
144 QTest::newRow("myObject.value + myObject.value + 10") << SRCDIR "/data/idproperty.txt" << "myObject.value + myObject.value + 10";
147 void tst_binding::basicproperty()
149 QFETCH(QString, file);
150 QFETCH(QString, binding);
152 COMPONENT(file, binding);
154 MyQmlObject *object = qobject_cast<MyQmlObject *>(c.create());
155 QVERIFY(object != 0);
156 object->setValue(10);
163 void tst_binding::creation_data()
165 QTest::addColumn<QString>("file");
166 QTest::addColumn<QString>("binding");
168 QTest::newRow("constant") << SRCDIR "/data/creation.txt" << "10";
169 QTest::newRow("ownProperty") << SRCDIR "/data/creation.txt" << "myObject.value";
170 QTest::newRow("declaredProperty") << SRCDIR "/data/creation.txt" << "myObject.myValue";
171 QTest::newRow("contextProperty") << SRCDIR "/data/creation.txt" << "tstObject.value";
174 void tst_binding::creation()
176 QFETCH(QString, file);
177 QFETCH(QString, binding);
179 COMPONENT(file, binding);
182 QObject *o = c.create();
187 QTEST_MAIN(tst_binding)
188 #include "tst_binding.moc"