1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <private/qdeclarativepropertycache_p.h>
44 #include <QtDeclarative/qdeclarativeengine.h>
45 #include "../../shared/util.h"
47 class tst_qdeclarativepropertycache : public QObject
51 tst_qdeclarativepropertycache() {}
55 void propertiesDerived();
57 void methodsDerived();
58 void signalHandlers();
59 void signalHandlersDerived();
62 QDeclarativeEngine engine;
65 class BaseObject : public QObject
68 Q_PROPERTY(int propertyA READ propertyA NOTIFY propertyAChanged)
69 Q_PROPERTY(QString propertyB READ propertyB NOTIFY propertyBChanged)
71 BaseObject(QObject *parent = 0) : QObject(parent) {}
73 int propertyA() const { return 0; }
74 QString propertyB() const { return QString(); }
80 void propertyAChanged();
81 void propertyBChanged();
85 class DerivedObject : public BaseObject
88 Q_PROPERTY(int propertyC READ propertyC NOTIFY propertyCChanged)
89 Q_PROPERTY(QString propertyD READ propertyD NOTIFY propertyDChanged)
91 DerivedObject(QObject *parent = 0) : BaseObject(parent) {}
93 int propertyC() const { return 0; }
94 QString propertyD() const { return QString(); }
100 void propertyCChanged();
101 void propertyDChanged();
105 void tst_qdeclarativepropertycache::properties()
107 QDeclarativeEngine engine;
108 DerivedObject object;
109 const QMetaObject *metaObject = object.metaObject();
111 QDeclarativeRefPointer<QDeclarativePropertyCache> cache(new QDeclarativePropertyCache(&engine, metaObject));
112 QDeclarativePropertyData *data;
114 QVERIFY(data = cache->property(QLatin1String("propertyA")));
115 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyA"));
117 QVERIFY(data = cache->property(QLatin1String("propertyB")));
118 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyB"));
120 QVERIFY(data = cache->property(QLatin1String("propertyC")));
121 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyC"));
123 QVERIFY(data = cache->property(QLatin1String("propertyD")));
124 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyD"));
127 void tst_qdeclarativepropertycache::propertiesDerived()
129 QDeclarativeEngine engine;
130 DerivedObject object;
131 const QMetaObject *metaObject = object.metaObject();
133 QDeclarativeRefPointer<QDeclarativePropertyCache> parentCache(new QDeclarativePropertyCache(&engine, &BaseObject::staticMetaObject));
134 QDeclarativeRefPointer<QDeclarativePropertyCache> cache(parentCache->copy());
135 cache->append(&engine, object.metaObject());
136 QDeclarativePropertyData *data;
138 QVERIFY(data = cache->property(QLatin1String("propertyA")));
139 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyA"));
141 QVERIFY(data = cache->property(QLatin1String("propertyB")));
142 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyB"));
144 QVERIFY(data = cache->property(QLatin1String("propertyC")));
145 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyC"));
147 QVERIFY(data = cache->property(QLatin1String("propertyD")));
148 QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyD"));
151 void tst_qdeclarativepropertycache::methods()
153 QDeclarativeEngine engine;
154 DerivedObject object;
155 const QMetaObject *metaObject = object.metaObject();
157 QDeclarativeRefPointer<QDeclarativePropertyCache> cache(new QDeclarativePropertyCache(&engine, metaObject));
158 QDeclarativePropertyData *data;
160 QVERIFY(data = cache->property(QLatin1String("slotA")));
161 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotA()"));
163 QVERIFY(data = cache->property(QLatin1String("slotB")));
164 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotB()"));
166 QVERIFY(data = cache->property(QLatin1String("signalA")));
167 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
169 QVERIFY(data = cache->property(QLatin1String("signalB")));
170 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
172 QVERIFY(data = cache->property(QLatin1String("propertyAChanged")));
173 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
175 QVERIFY(data = cache->property(QLatin1String("propertyBChanged")));
176 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
178 QVERIFY(data = cache->property(QLatin1String("propertyCChanged")));
179 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
181 QVERIFY(data = cache->property(QLatin1String("propertyDChanged")));
182 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
185 void tst_qdeclarativepropertycache::methodsDerived()
187 QDeclarativeEngine engine;
188 DerivedObject object;
189 const QMetaObject *metaObject = object.metaObject();
191 QDeclarativeRefPointer<QDeclarativePropertyCache> parentCache(new QDeclarativePropertyCache(&engine, &BaseObject::staticMetaObject));
192 QDeclarativeRefPointer<QDeclarativePropertyCache> cache(parentCache->copy());
193 cache->append(&engine, object.metaObject());
194 QDeclarativePropertyData *data;
196 QVERIFY(data = cache->property(QLatin1String("slotA")));
197 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotA()"));
199 QVERIFY(data = cache->property(QLatin1String("slotB")));
200 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotB()"));
202 QVERIFY(data = cache->property(QLatin1String("signalA")));
203 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
205 QVERIFY(data = cache->property(QLatin1String("signalB")));
206 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
208 QVERIFY(data = cache->property(QLatin1String("propertyAChanged")));
209 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
211 QVERIFY(data = cache->property(QLatin1String("propertyBChanged")));
212 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
214 QVERIFY(data = cache->property(QLatin1String("propertyCChanged")));
215 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
217 QVERIFY(data = cache->property(QLatin1String("propertyDChanged")));
218 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
221 void tst_qdeclarativepropertycache::signalHandlers()
223 QDeclarativeEngine engine;
224 DerivedObject object;
225 const QMetaObject *metaObject = object.metaObject();
227 QDeclarativeRefPointer<QDeclarativePropertyCache> cache(new QDeclarativePropertyCache(&engine, metaObject));
228 QDeclarativePropertyData *data;
230 QVERIFY(data = cache->property(QLatin1String("onSignalA")));
231 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
233 QVERIFY(data = cache->property(QLatin1String("onSignalB")));
234 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
236 QVERIFY(data = cache->property(QLatin1String("onPropertyAChanged")));
237 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
239 QVERIFY(data = cache->property(QLatin1String("onPropertyBChanged")));
240 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
242 QVERIFY(data = cache->property(QLatin1String("onPropertyCChanged")));
243 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
245 QVERIFY(data = cache->property(QLatin1String("onPropertyDChanged")));
246 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
249 void tst_qdeclarativepropertycache::signalHandlersDerived()
251 QDeclarativeEngine engine;
252 DerivedObject object;
253 const QMetaObject *metaObject = object.metaObject();
255 QDeclarativeRefPointer<QDeclarativePropertyCache> parentCache(new QDeclarativePropertyCache(&engine, &BaseObject::staticMetaObject));
256 QDeclarativeRefPointer<QDeclarativePropertyCache> cache(parentCache->copy());
257 cache->append(&engine, object.metaObject());
258 QDeclarativePropertyData *data;
260 QVERIFY(data = cache->property(QLatin1String("onSignalA")));
261 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
263 QVERIFY(data = cache->property(QLatin1String("onSignalB")));
264 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
266 QVERIFY(data = cache->property(QLatin1String("onPropertyAChanged")));
267 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
269 QVERIFY(data = cache->property(QLatin1String("onPropertyBChanged")));
270 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
272 QVERIFY(data = cache->property(QLatin1String("onPropertyCChanged")));
273 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
275 QVERIFY(data = cache->property(QLatin1String("onPropertyDChanged")));
276 QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
279 QTEST_MAIN(tst_qdeclarativepropertycache)
281 #include "tst_qdeclarativepropertycache.moc"