~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
20
**
 
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.
 
28
**
 
29
** Other Usage
 
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.
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <qtest.h>
 
43
#include <private/qqmlpropertycache_p.h>
 
44
#include <QtQml/qqmlengine.h>
 
45
#include "../../shared/util.h"
 
46
 
 
47
class tst_qqmlpropertycache : public QObject
 
48
{
 
49
    Q_OBJECT
 
50
public:
 
51
    tst_qqmlpropertycache() {}
 
52
 
 
53
private slots:
 
54
    void properties();
 
55
    void propertiesDerived();
 
56
    void methods();
 
57
    void methodsDerived();
 
58
    void signalHandlers();
 
59
    void signalHandlersDerived();
 
60
 
 
61
private:
 
62
    QQmlEngine engine;
 
63
};
 
64
 
 
65
class BaseObject : public QObject
 
66
{
 
67
    Q_OBJECT
 
68
    Q_PROPERTY(int propertyA READ propertyA NOTIFY propertyAChanged)
 
69
    Q_PROPERTY(QString propertyB READ propertyB NOTIFY propertyBChanged)
 
70
public:
 
71
    BaseObject(QObject *parent = 0) : QObject(parent) {}
 
72
 
 
73
    int propertyA() const { return 0; }
 
74
    QString propertyB() const { return QString(); }
 
75
 
 
76
public Q_SLOTS:
 
77
    void slotA() {}
 
78
 
 
79
Q_SIGNALS:
 
80
    void propertyAChanged();
 
81
    void propertyBChanged();
 
82
    void signalA();
 
83
};
 
84
 
 
85
class DerivedObject : public BaseObject
 
86
{
 
87
    Q_OBJECT
 
88
    Q_PROPERTY(int propertyC READ propertyC NOTIFY propertyCChanged)
 
89
    Q_PROPERTY(QString propertyD READ propertyD NOTIFY propertyDChanged)
 
90
public:
 
91
    DerivedObject(QObject *parent = 0) : BaseObject(parent) {}
 
92
 
 
93
    int propertyC() const { return 0; }
 
94
    QString propertyD() const { return QString(); }
 
95
 
 
96
public Q_SLOTS:
 
97
    void slotB() {}
 
98
 
 
99
Q_SIGNALS:
 
100
    void propertyCChanged();
 
101
    void propertyDChanged();
 
102
    void signalB();
 
103
};
 
104
 
 
105
void tst_qqmlpropertycache::properties()
 
106
{
 
107
    QQmlEngine engine;
 
108
    DerivedObject object;
 
109
    const QMetaObject *metaObject = object.metaObject();
 
110
 
 
111
    QQmlRefPointer<QQmlPropertyCache> cache(new QQmlPropertyCache(&engine, metaObject));
 
112
    QQmlPropertyData *data;
 
113
 
 
114
    QVERIFY(data = cache->property(QLatin1String("propertyA")));
 
115
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyA"));
 
116
 
 
117
    QVERIFY(data = cache->property(QLatin1String("propertyB")));
 
118
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyB"));
 
119
 
 
120
    QVERIFY(data = cache->property(QLatin1String("propertyC")));
 
121
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyC"));
 
122
 
 
123
    QVERIFY(data = cache->property(QLatin1String("propertyD")));
 
124
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyD"));
 
125
}
 
126
 
 
127
void tst_qqmlpropertycache::propertiesDerived()
 
128
{
 
129
    QQmlEngine engine;
 
130
    DerivedObject object;
 
131
    const QMetaObject *metaObject = object.metaObject();
 
132
 
 
133
    QQmlRefPointer<QQmlPropertyCache> parentCache(new QQmlPropertyCache(&engine, &BaseObject::staticMetaObject));
 
134
    QQmlRefPointer<QQmlPropertyCache> cache(parentCache->copy());
 
135
    cache->append(&engine, object.metaObject());
 
136
    QQmlPropertyData *data;
 
137
 
 
138
    QVERIFY(data = cache->property(QLatin1String("propertyA")));
 
139
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyA"));
 
140
 
 
141
    QVERIFY(data = cache->property(QLatin1String("propertyB")));
 
142
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyB"));
 
143
 
 
144
    QVERIFY(data = cache->property(QLatin1String("propertyC")));
 
145
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyC"));
 
146
 
 
147
    QVERIFY(data = cache->property(QLatin1String("propertyD")));
 
148
    QCOMPARE(data->coreIndex, metaObject->indexOfProperty("propertyD"));
 
149
}
 
150
 
 
151
void tst_qqmlpropertycache::methods()
 
152
{
 
153
    QQmlEngine engine;
 
154
    DerivedObject object;
 
155
    const QMetaObject *metaObject = object.metaObject();
 
156
 
 
157
    QQmlRefPointer<QQmlPropertyCache> cache(new QQmlPropertyCache(&engine, metaObject));
 
158
    QQmlPropertyData *data;
 
159
 
 
160
    QVERIFY(data = cache->property(QLatin1String("slotA")));
 
161
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotA()"));
 
162
 
 
163
    QVERIFY(data = cache->property(QLatin1String("slotB")));
 
164
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotB()"));
 
165
 
 
166
    QVERIFY(data = cache->property(QLatin1String("signalA")));
 
167
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
 
168
 
 
169
    QVERIFY(data = cache->property(QLatin1String("signalB")));
 
170
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
 
171
 
 
172
    QVERIFY(data = cache->property(QLatin1String("propertyAChanged")));
 
173
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
 
174
 
 
175
    QVERIFY(data = cache->property(QLatin1String("propertyBChanged")));
 
176
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
 
177
 
 
178
    QVERIFY(data = cache->property(QLatin1String("propertyCChanged")));
 
179
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
 
180
 
 
181
    QVERIFY(data = cache->property(QLatin1String("propertyDChanged")));
 
182
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
 
183
}
 
184
 
 
185
void tst_qqmlpropertycache::methodsDerived()
 
186
{
 
187
    QQmlEngine engine;
 
188
    DerivedObject object;
 
189
    const QMetaObject *metaObject = object.metaObject();
 
190
 
 
191
    QQmlRefPointer<QQmlPropertyCache> parentCache(new QQmlPropertyCache(&engine, &BaseObject::staticMetaObject));
 
192
    QQmlRefPointer<QQmlPropertyCache> cache(parentCache->copy());
 
193
    cache->append(&engine, object.metaObject());
 
194
    QQmlPropertyData *data;
 
195
 
 
196
    QVERIFY(data = cache->property(QLatin1String("slotA")));
 
197
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotA()"));
 
198
 
 
199
    QVERIFY(data = cache->property(QLatin1String("slotB")));
 
200
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("slotB()"));
 
201
 
 
202
    QVERIFY(data = cache->property(QLatin1String("signalA")));
 
203
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
 
204
 
 
205
    QVERIFY(data = cache->property(QLatin1String("signalB")));
 
206
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
 
207
 
 
208
    QVERIFY(data = cache->property(QLatin1String("propertyAChanged")));
 
209
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
 
210
 
 
211
    QVERIFY(data = cache->property(QLatin1String("propertyBChanged")));
 
212
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
 
213
 
 
214
    QVERIFY(data = cache->property(QLatin1String("propertyCChanged")));
 
215
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
 
216
 
 
217
    QVERIFY(data = cache->property(QLatin1String("propertyDChanged")));
 
218
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
 
219
}
 
220
 
 
221
void tst_qqmlpropertycache::signalHandlers()
 
222
{
 
223
    QQmlEngine engine;
 
224
    DerivedObject object;
 
225
    const QMetaObject *metaObject = object.metaObject();
 
226
 
 
227
    QQmlRefPointer<QQmlPropertyCache> cache(new QQmlPropertyCache(&engine, metaObject));
 
228
    QQmlPropertyData *data;
 
229
 
 
230
    QVERIFY(data = cache->property(QLatin1String("onSignalA")));
 
231
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
 
232
 
 
233
    QVERIFY(data = cache->property(QLatin1String("onSignalB")));
 
234
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
 
235
 
 
236
    QVERIFY(data = cache->property(QLatin1String("onPropertyAChanged")));
 
237
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
 
238
 
 
239
    QVERIFY(data = cache->property(QLatin1String("onPropertyBChanged")));
 
240
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
 
241
 
 
242
    QVERIFY(data = cache->property(QLatin1String("onPropertyCChanged")));
 
243
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
 
244
 
 
245
    QVERIFY(data = cache->property(QLatin1String("onPropertyDChanged")));
 
246
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
 
247
}
 
248
 
 
249
void tst_qqmlpropertycache::signalHandlersDerived()
 
250
{
 
251
    QQmlEngine engine;
 
252
    DerivedObject object;
 
253
    const QMetaObject *metaObject = object.metaObject();
 
254
 
 
255
    QQmlRefPointer<QQmlPropertyCache> parentCache(new QQmlPropertyCache(&engine, &BaseObject::staticMetaObject));
 
256
    QQmlRefPointer<QQmlPropertyCache> cache(parentCache->copy());
 
257
    cache->append(&engine, object.metaObject());
 
258
    QQmlPropertyData *data;
 
259
 
 
260
    QVERIFY(data = cache->property(QLatin1String("onSignalA")));
 
261
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalA()"));
 
262
 
 
263
    QVERIFY(data = cache->property(QLatin1String("onSignalB")));
 
264
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("signalB()"));
 
265
 
 
266
    QVERIFY(data = cache->property(QLatin1String("onPropertyAChanged")));
 
267
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyAChanged()"));
 
268
 
 
269
    QVERIFY(data = cache->property(QLatin1String("onPropertyBChanged")));
 
270
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyBChanged()"));
 
271
 
 
272
    QVERIFY(data = cache->property(QLatin1String("onPropertyCChanged")));
 
273
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyCChanged()"));
 
274
 
 
275
    QVERIFY(data = cache->property(QLatin1String("onPropertyDChanged")));
 
276
    QCOMPARE(data->coreIndex, metaObject->indexOfMethod("propertyDChanged()"));
 
277
}
 
278
 
 
279
QTEST_MAIN(tst_qqmlpropertycache)
 
280
 
 
281
#include "tst_qqmlpropertycache.moc"