1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
47 #include "testtypes.h"
52 // In Symbian OS test data is located in applications private dir
56 class tst_binding : public QObject
62 virtual ~tst_binding();
66 void cleanupTestCase();
69 void objectproperty_data();
70 void objectproperty();
71 void basicproperty_data();
75 QDeclarativeEngine engine;
78 tst_binding::tst_binding()
82 tst_binding::~tst_binding()
86 void tst_binding::initTestCase()
91 void tst_binding::cleanupTestCase()
95 #define COMPONENT(filename, binding) \
96 QDeclarativeComponent c(&engine); \
99 QVERIFY(f.open(QIODevice::ReadOnly)); \
100 QByteArray data = f.readAll(); \
101 data.replace("###", binding.toUtf8()); \
102 c.setData(data, QUrl()); \
103 QVERIFY(c.isReady()); \
106 void tst_binding::objectproperty_data()
108 QTest::addColumn<QString>("file");
109 QTest::addColumn<QString>("binding");
111 QTest::newRow("object.value") << SRCDIR "/data/objectproperty.txt" << "object.value";
112 QTest::newRow("object.value + 10") << SRCDIR "/data/objectproperty.txt" << "object.value + 10";
115 void tst_binding::objectproperty()
117 QFETCH(QString, file);
118 QFETCH(QString, binding);
120 COMPONENT(file, binding);
125 MyQmlObject *object = qobject_cast<MyQmlObject *>(c.create());
126 QVERIFY(object != 0);
127 object->setObject(&object2);
130 object->setObject(&object1);
131 object->setObject(&object2);
135 void tst_binding::basicproperty_data()
137 QTest::addColumn<QString>("file");
138 QTest::addColumn<QString>("binding");
140 QTest::newRow("value") << SRCDIR "/data/localproperty.txt" << "value";
141 QTest::newRow("value + 10") << SRCDIR "/data/localproperty.txt" << "value + 10";
142 QTest::newRow("value + value + 10") << SRCDIR "/data/localproperty.txt" << "value + value + 10";
144 QTest::newRow("myObject.value") << SRCDIR "/data/idproperty.txt" << "myObject.value";
145 QTest::newRow("myObject.value + 10") << SRCDIR "/data/idproperty.txt" << "myObject.value + 10";
146 QTest::newRow("myObject.value + myObject.value + 10") << SRCDIR "/data/idproperty.txt" << "myObject.value + myObject.value + 10";
149 void tst_binding::basicproperty()
151 QFETCH(QString, file);
152 QFETCH(QString, binding);
154 COMPONENT(file, binding);
156 MyQmlObject *object = qobject_cast<MyQmlObject *>(c.create());
157 QVERIFY(object != 0);
158 object->setValue(10);
165 QTEST_MAIN(tst_binding)
166 #include "tst_binding.moc"