1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
44
#include <QQmlContext>
45
#include <QQmlComponent>
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();
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
QQmlComponent 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"