author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
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 |
|
14 |
** this package. |
|
15 |
** |
|
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. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qscriptengine.h> |
|
46 |
#include <qscriptcontext.h> |
|
47 |
#include <qscriptvalueiterator.h> |
|
48 |
#include <qwidget.h> |
|
49 |
#include <qpushbutton.h> |
|
50 |
#include <qlineedit.h> |
|
51 |
||
52 |
//TESTED_CLASS= |
|
53 |
//TESTED_FILES=script/qscriptextqobject_p.h script/qscriptextqobject.cpp |
|
54 |
||
55 |
struct CustomType |
|
56 |
{ |
|
57 |
#if defined (Q_CC_NOKIAX86) |
|
58 |
// Compiler crash workaround |
|
59 |
CustomType() {} |
|
60 |
#endif |
|
61 |
QString string; |
|
62 |
}; |
|
63 |
Q_DECLARE_METATYPE(CustomType) |
|
64 |
||
65 |
Q_DECLARE_METATYPE(QBrush*) |
|
66 |
Q_DECLARE_METATYPE(QObjectList) |
|
67 |
Q_DECLARE_METATYPE(QList<int>) |
|
68 |
Q_DECLARE_METATYPE(Qt::BrushStyle) |
|
69 |
Q_DECLARE_METATYPE(QDir) |
|
70 |
||
71 |
static void dirFromScript(const QScriptValue &in, QDir &out) |
|
72 |
{ |
|
73 |
QScriptValue path = in.property("path"); |
|
74 |
if (!path.isValid()) |
|
75 |
in.engine()->currentContext()->throwError("No path"); |
|
76 |
else |
|
77 |
out.setPath(path.toString()); |
|
78 |
} |
|
79 |
||
80 |
namespace MyNS |
|
81 |
{ |
|
82 |
class A : public QObject |
|
83 |
{ |
|
84 |
Q_OBJECT |
|
85 |
public: |
|
86 |
enum Type { |
|
87 |
Foo, |
|
88 |
Bar |
|
89 |
}; |
|
90 |
Q_ENUMS(Type) |
|
91 |
public Q_SLOTS: |
|
92 |
int slotTakingScopedEnumArg(MyNS::A::Type t) { |
|
93 |
return t; |
|
94 |
} |
|
95 |
}; |
|
96 |
} |
|
97 |
||
98 |
class MyQObject : public QObject |
|
99 |
{ |
|
100 |
Q_OBJECT |
|
101 |
||
102 |
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty) |
|
103 |
Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty) |
|
104 |
Q_PROPERTY(QVariantList variantListProperty READ variantListProperty WRITE setVariantListProperty) |
|
105 |
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty) |
|
106 |
Q_PROPERTY(QStringList stringListProperty READ stringListProperty WRITE setStringListProperty) |
|
107 |
Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty) |
|
108 |
Q_PROPERTY(QBrush brushProperty READ brushProperty WRITE setBrushProperty) |
|
109 |
Q_PROPERTY(double hiddenProperty READ hiddenProperty WRITE setHiddenProperty SCRIPTABLE false) |
|
110 |
Q_PROPERTY(int writeOnlyProperty WRITE setWriteOnlyProperty) |
|
111 |
Q_PROPERTY(int readOnlyProperty READ readOnlyProperty) |
|
112 |
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) |
|
113 |
Q_PROPERTY(CustomType propWithCustomType READ propWithCustomType WRITE setPropWithCustomType) |
|
114 |
Q_PROPERTY(Policy enumProperty READ enumProperty WRITE setEnumProperty) |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
115 |
Q_PROPERTY(Ability flagsProperty READ flagsProperty WRITE setFlagsProperty) |
0 | 116 |
Q_ENUMS(Policy Strategy) |
117 |
Q_FLAGS(Ability) |
|
118 |
||
119 |
public: |
|
120 |
enum Policy { |
|
121 |
FooPolicy = 0, |
|
122 |
BarPolicy, |
|
123 |
BazPolicy |
|
124 |
}; |
|
125 |
||
126 |
enum Strategy { |
|
127 |
FooStrategy = 10, |
|
128 |
BarStrategy, |
|
129 |
BazStrategy |
|
130 |
}; |
|
131 |
||
132 |
enum AbilityFlag { |
|
133 |
NoAbility = 0x000, |
|
134 |
FooAbility = 0x001, |
|
135 |
BarAbility = 0x080, |
|
136 |
BazAbility = 0x200, |
|
137 |
AllAbility = FooAbility | BarAbility | BazAbility |
|
138 |
}; |
|
139 |
||
140 |
Q_DECLARE_FLAGS(Ability, AbilityFlag) |
|
141 |
||
142 |
MyQObject(QObject *parent = 0) |
|
143 |
: QObject(parent), |
|
144 |
m_intValue(123), |
|
145 |
m_variantValue(QLatin1String("foo")), |
|
146 |
m_variantListValue(QVariantList() << QVariant(123) << QVariant(QLatin1String("foo"))), |
|
147 |
m_stringValue(QLatin1String("bar")), |
|
148 |
m_stringListValue(QStringList() << QLatin1String("zig") << QLatin1String("zag")), |
|
149 |
m_brushValue(QColor(10, 20, 30, 40)), |
|
150 |
m_hiddenValue(456.0), |
|
151 |
m_writeOnlyValue(789), |
|
152 |
m_readOnlyValue(987), |
|
153 |
m_enumValue(BarPolicy), |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
154 |
m_flagsValue(FooAbility), |
0 | 155 |
m_qtFunctionInvoked(-1) |
156 |
{ } |
|
157 |
||
158 |
int intProperty() const |
|
159 |
{ return m_intValue; } |
|
160 |
void setIntProperty(int value) |
|
161 |
{ m_intValue = value; } |
|
162 |
||
163 |
QVariant variantProperty() const |
|
164 |
{ return m_variantValue; } |
|
165 |
void setVariantProperty(const QVariant &value) |
|
166 |
{ m_variantValue = value; } |
|
167 |
||
168 |
QVariantList variantListProperty() const |
|
169 |
{ return m_variantListValue; } |
|
170 |
void setVariantListProperty(const QVariantList &value) |
|
171 |
{ m_variantListValue = value; } |
|
172 |
||
173 |
QString stringProperty() const |
|
174 |
{ return m_stringValue; } |
|
175 |
void setStringProperty(const QString &value) |
|
176 |
{ m_stringValue = value; } |
|
177 |
||
178 |
QStringList stringListProperty() const |
|
179 |
{ return m_stringListValue; } |
|
180 |
void setStringListProperty(const QStringList &value) |
|
181 |
{ m_stringListValue = value; } |
|
182 |
||
183 |
QByteArray byteArrayProperty() const |
|
184 |
{ return m_byteArrayValue; } |
|
185 |
void setByteArrayProperty(const QByteArray &value) |
|
186 |
{ m_byteArrayValue = value; } |
|
187 |
||
188 |
QBrush brushProperty() const |
|
189 |
{ return m_brushValue; } |
|
190 |
Q_INVOKABLE void setBrushProperty(const QBrush &value) |
|
191 |
{ m_brushValue = value; } |
|
192 |
||
193 |
double hiddenProperty() const |
|
194 |
{ return m_hiddenValue; } |
|
195 |
void setHiddenProperty(double value) |
|
196 |
{ m_hiddenValue = value; } |
|
197 |
||
198 |
int writeOnlyProperty() const |
|
199 |
{ return m_writeOnlyValue; } |
|
200 |
void setWriteOnlyProperty(int value) |
|
201 |
{ m_writeOnlyValue = value; } |
|
202 |
||
203 |
int readOnlyProperty() const |
|
204 |
{ return m_readOnlyValue; } |
|
205 |
||
206 |
QKeySequence shortcut() const |
|
207 |
{ return m_shortcut; } |
|
208 |
void setShortcut(const QKeySequence &seq) |
|
209 |
{ m_shortcut = seq; } |
|
210 |
||
211 |
CustomType propWithCustomType() const |
|
212 |
{ return m_customType; } |
|
213 |
void setPropWithCustomType(const CustomType &c) |
|
214 |
{ m_customType = c; } |
|
215 |
||
216 |
Policy enumProperty() const |
|
217 |
{ return m_enumValue; } |
|
218 |
void setEnumProperty(Policy policy) |
|
219 |
{ m_enumValue = policy; } |
|
220 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
221 |
Ability flagsProperty() const |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
222 |
{ return m_flagsValue; } |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
223 |
void setFlagsProperty(Ability ability) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
224 |
{ m_flagsValue = ability; } |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
225 |
|
0 | 226 |
int qtFunctionInvoked() const |
227 |
{ return m_qtFunctionInvoked; } |
|
228 |
||
229 |
QVariantList qtFunctionActuals() const |
|
230 |
{ return m_actuals; } |
|
231 |
||
232 |
void resetQtFunctionInvoked() |
|
233 |
{ m_qtFunctionInvoked = -1; m_actuals.clear(); } |
|
234 |
||
235 |
void clearConnectedSignal() |
|
236 |
{ m_connectedSignal = QByteArray(); } |
|
237 |
void clearDisconnectedSignal() |
|
238 |
{ m_disconnectedSignal = QByteArray(); } |
|
239 |
QByteArray connectedSignal() const |
|
240 |
{ return m_connectedSignal; } |
|
241 |
QByteArray disconnectedSignal() const |
|
242 |
{ return m_disconnectedSignal; } |
|
243 |
||
244 |
Q_INVOKABLE void myInvokable() |
|
245 |
{ m_qtFunctionInvoked = 0; } |
|
246 |
Q_INVOKABLE void myInvokableWithIntArg(int arg) |
|
247 |
{ m_qtFunctionInvoked = 1; m_actuals << arg; } |
|
248 |
Q_INVOKABLE void myInvokableWithLonglongArg(qlonglong arg) |
|
249 |
{ m_qtFunctionInvoked = 2; m_actuals << arg; } |
|
250 |
Q_INVOKABLE void myInvokableWithFloatArg(float arg) |
|
251 |
{ m_qtFunctionInvoked = 3; m_actuals << arg; } |
|
252 |
Q_INVOKABLE void myInvokableWithDoubleArg(double arg) |
|
253 |
{ m_qtFunctionInvoked = 4; m_actuals << arg; } |
|
254 |
Q_INVOKABLE void myInvokableWithStringArg(const QString &arg) |
|
255 |
{ m_qtFunctionInvoked = 5; m_actuals << arg; } |
|
256 |
Q_INVOKABLE void myInvokableWithIntArgs(int arg1, int arg2) |
|
257 |
{ m_qtFunctionInvoked = 6; m_actuals << arg1 << arg2; } |
|
258 |
Q_INVOKABLE int myInvokableReturningInt() |
|
259 |
{ m_qtFunctionInvoked = 7; return 123; } |
|
260 |
Q_INVOKABLE qlonglong myInvokableReturningLongLong() |
|
261 |
{ m_qtFunctionInvoked = 39; return 456; } |
|
262 |
Q_INVOKABLE QString myInvokableReturningString() |
|
263 |
{ m_qtFunctionInvoked = 8; return QLatin1String("ciao"); } |
|
264 |
Q_INVOKABLE QVariant myInvokableReturningVariant() |
|
265 |
{ m_qtFunctionInvoked = 60; return 123; } |
|
266 |
Q_INVOKABLE QScriptValue myInvokableReturningScriptValue() |
|
267 |
{ m_qtFunctionInvoked = 61; return 456; } |
|
268 |
Q_INVOKABLE void myInvokableWithIntArg(int arg1, int arg2) // overload |
|
269 |
{ m_qtFunctionInvoked = 9; m_actuals << arg1 << arg2; } |
|
270 |
Q_INVOKABLE void myInvokableWithEnumArg(Policy policy) |
|
271 |
{ m_qtFunctionInvoked = 10; m_actuals << policy; } |
|
272 |
Q_INVOKABLE void myInvokableWithQualifiedEnumArg(MyQObject::Policy policy) |
|
273 |
{ m_qtFunctionInvoked = 36; m_actuals << policy; } |
|
274 |
Q_INVOKABLE Policy myInvokableReturningEnum() |
|
275 |
{ m_qtFunctionInvoked = 37; return BazPolicy; } |
|
276 |
Q_INVOKABLE MyQObject::Strategy myInvokableReturningQualifiedEnum() |
|
277 |
{ m_qtFunctionInvoked = 38; return BazStrategy; } |
|
278 |
Q_INVOKABLE QVector<int> myInvokableReturningVectorOfInt() |
|
279 |
{ m_qtFunctionInvoked = 11; return QVector<int>(); } |
|
280 |
Q_INVOKABLE void myInvokableWithVectorOfIntArg(const QVector<int> &) |
|
281 |
{ m_qtFunctionInvoked = 12; } |
|
282 |
Q_INVOKABLE QObject *myInvokableReturningQObjectStar() |
|
283 |
{ m_qtFunctionInvoked = 13; return this; } |
|
284 |
Q_INVOKABLE QObjectList myInvokableWithQObjectListArg(const QObjectList &lst) |
|
285 |
{ m_qtFunctionInvoked = 14; m_actuals << qVariantFromValue(lst); return lst; } |
|
286 |
Q_INVOKABLE QVariant myInvokableWithVariantArg(const QVariant &v) |
|
287 |
{ m_qtFunctionInvoked = 15; m_actuals << v; return v; } |
|
288 |
Q_INVOKABLE QVariantMap myInvokableWithVariantMapArg(const QVariantMap &vm) |
|
289 |
{ m_qtFunctionInvoked = 16; m_actuals << vm; return vm; } |
|
290 |
Q_INVOKABLE QList<int> myInvokableWithListOfIntArg(const QList<int> &lst) |
|
291 |
{ m_qtFunctionInvoked = 17; m_actuals << qVariantFromValue(lst); return lst; } |
|
292 |
Q_INVOKABLE QObject* myInvokableWithQObjectStarArg(QObject *obj) |
|
293 |
{ m_qtFunctionInvoked = 18; m_actuals << qVariantFromValue(obj); return obj; } |
|
294 |
Q_INVOKABLE QBrush myInvokableWithQBrushArg(const QBrush &brush) |
|
295 |
{ m_qtFunctionInvoked = 19; m_actuals << qVariantFromValue(brush); return brush; } |
|
296 |
Q_INVOKABLE void myInvokableWithBrushStyleArg(Qt::BrushStyle style) |
|
297 |
{ m_qtFunctionInvoked = 43; m_actuals << qVariantFromValue(style); } |
|
298 |
Q_INVOKABLE void myInvokableWithVoidStarArg(void *arg) |
|
299 |
{ m_qtFunctionInvoked = 44; m_actuals << qVariantFromValue(arg); } |
|
300 |
Q_INVOKABLE void myInvokableWithAmbiguousArg(int arg) |
|
301 |
{ m_qtFunctionInvoked = 45; m_actuals << qVariantFromValue(arg); } |
|
302 |
Q_INVOKABLE void myInvokableWithAmbiguousArg(uint arg) |
|
303 |
{ m_qtFunctionInvoked = 46; m_actuals << qVariantFromValue(arg); } |
|
304 |
Q_INVOKABLE void myInvokableWithDefaultArgs(int arg1, const QString &arg2 = "") |
|
305 |
{ m_qtFunctionInvoked = 47; m_actuals << qVariantFromValue(arg1) << qVariantFromValue(arg2); } |
|
306 |
Q_INVOKABLE QObject& myInvokableReturningRef() |
|
307 |
{ m_qtFunctionInvoked = 48; return *this; } |
|
308 |
Q_INVOKABLE const QObject& myInvokableReturningConstRef() const |
|
309 |
{ const_cast<MyQObject*>(this)->m_qtFunctionInvoked = 49; return *this; } |
|
310 |
Q_INVOKABLE void myInvokableWithPointArg(const QPoint &arg) |
|
311 |
{ const_cast<MyQObject*>(this)->m_qtFunctionInvoked = 50; m_actuals << qVariantFromValue(arg); } |
|
312 |
Q_INVOKABLE void myInvokableWithPointArg(const QPointF &arg) |
|
313 |
{ const_cast<MyQObject*>(this)->m_qtFunctionInvoked = 51; m_actuals << qVariantFromValue(arg); } |
|
314 |
Q_INVOKABLE void myInvokableWithMyQObjectArg(MyQObject *arg) |
|
315 |
{ m_qtFunctionInvoked = 52; m_actuals << qVariantFromValue((QObject*)arg); } |
|
316 |
Q_INVOKABLE MyQObject* myInvokableReturningMyQObject() |
|
317 |
{ m_qtFunctionInvoked = 53; return this; } |
|
318 |
Q_INVOKABLE void myInvokableWithConstMyQObjectArg(const MyQObject *arg) |
|
319 |
{ m_qtFunctionInvoked = 54; m_actuals << qVariantFromValue((QObject*)arg); } |
|
320 |
Q_INVOKABLE void myInvokableWithQDirArg(const QDir &arg) |
|
321 |
{ m_qtFunctionInvoked = 55; m_actuals << qVariantFromValue(arg); } |
|
322 |
Q_INVOKABLE QScriptValue myInvokableWithScriptValueArg(const QScriptValue &arg) |
|
323 |
{ m_qtFunctionInvoked = 56; return arg; } |
|
324 |
Q_INVOKABLE QObject* myInvokableReturningMyQObjectAsQObject() |
|
325 |
{ m_qtFunctionInvoked = 57; return this; } |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
326 |
Q_INVOKABLE Ability myInvokableWithFlagsArg(Ability arg) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
327 |
{ m_qtFunctionInvoked = 58; m_actuals << int(arg); return arg; } |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
328 |
Q_INVOKABLE MyQObject::Ability myInvokableWithQualifiedFlagsArg(MyQObject::Ability arg) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
329 |
{ m_qtFunctionInvoked = 59; m_actuals << int(arg); return arg; } |
0 | 330 |
|
331 |
Q_INVOKABLE QObjectList findObjects() const |
|
332 |
{ return findChildren<QObject *>(); } |
|
333 |
Q_INVOKABLE QList<int> myInvokableNumbers() const |
|
334 |
{ return QList<int>() << 1 << 2 << 3; } |
|
335 |
||
336 |
void emitMySignal() |
|
337 |
{ emit mySignal(); } |
|
338 |
void emitMySignalWithIntArg(int arg) |
|
339 |
{ emit mySignalWithIntArg(arg); } |
|
340 |
void emitMySignal2(bool arg) |
|
341 |
{ emit mySignal2(arg); } |
|
342 |
void emitMySignal2() |
|
343 |
{ emit mySignal2(); } |
|
344 |
void emitMyOverloadedSignal(int arg) |
|
345 |
{ emit myOverloadedSignal(arg); } |
|
346 |
void emitMyOverloadedSignal(const QString &arg) |
|
347 |
{ emit myOverloadedSignal(arg); } |
|
348 |
void emitMyOtherOverloadedSignal(const QString &arg) |
|
349 |
{ emit myOtherOverloadedSignal(arg); } |
|
350 |
void emitMyOtherOverloadedSignal(int arg) |
|
351 |
{ emit myOtherOverloadedSignal(arg); } |
|
352 |
void emitMySignalWithDefaultArgWithArg(int arg) |
|
353 |
{ emit mySignalWithDefaultArg(arg); } |
|
354 |
void emitMySignalWithDefaultArg() |
|
355 |
{ emit mySignalWithDefaultArg(); } |
|
356 |
void emitMySignalWithVariantArg(const QVariant &arg) |
|
357 |
{ emit mySignalWithVariantArg(arg); } |
|
358 |
void emitMySignalWithScriptEngineArg(QScriptEngine *arg) |
|
359 |
{ emit mySignalWithScriptEngineArg(arg); } |
|
360 |
||
361 |
public Q_SLOTS: |
|
362 |
void mySlot() |
|
363 |
{ m_qtFunctionInvoked = 20; } |
|
364 |
void mySlotWithIntArg(int arg) |
|
365 |
{ m_qtFunctionInvoked = 21; m_actuals << arg; } |
|
366 |
void mySlotWithDoubleArg(double arg) |
|
367 |
{ m_qtFunctionInvoked = 22; m_actuals << arg; } |
|
368 |
void mySlotWithStringArg(const QString &arg) |
|
369 |
{ m_qtFunctionInvoked = 23; m_actuals << arg; } |
|
370 |
||
371 |
void myOverloadedSlot() |
|
372 |
{ m_qtFunctionInvoked = 24; } |
|
373 |
void myOverloadedSlot(QObject *arg) |
|
374 |
{ m_qtFunctionInvoked = 41; m_actuals << qVariantFromValue(arg); } |
|
375 |
void myOverloadedSlot(bool arg) |
|
376 |
{ m_qtFunctionInvoked = 25; m_actuals << arg; } |
|
377 |
void myOverloadedSlot(const QStringList &arg) |
|
378 |
{ m_qtFunctionInvoked = 42; m_actuals << arg; } |
|
379 |
void myOverloadedSlot(double arg) |
|
380 |
{ m_qtFunctionInvoked = 26; m_actuals << arg; } |
|
381 |
void myOverloadedSlot(float arg) |
|
382 |
{ m_qtFunctionInvoked = 27; m_actuals << arg; } |
|
383 |
void myOverloadedSlot(int arg) |
|
384 |
{ m_qtFunctionInvoked = 28; m_actuals << arg; } |
|
385 |
void myOverloadedSlot(const QString &arg) |
|
386 |
{ m_qtFunctionInvoked = 29; m_actuals << arg; } |
|
387 |
void myOverloadedSlot(const QColor &arg) |
|
388 |
{ m_qtFunctionInvoked = 30; m_actuals << arg; } |
|
389 |
void myOverloadedSlot(const QBrush &arg) |
|
390 |
{ m_qtFunctionInvoked = 31; m_actuals << arg; } |
|
391 |
void myOverloadedSlot(const QDateTime &arg) |
|
392 |
{ m_qtFunctionInvoked = 32; m_actuals << arg; } |
|
393 |
void myOverloadedSlot(const QDate &arg) |
|
394 |
{ m_qtFunctionInvoked = 33; m_actuals << arg; } |
|
395 |
void myOverloadedSlot(const QRegExp &arg) |
|
396 |
{ m_qtFunctionInvoked = 34; m_actuals << arg; } |
|
397 |
void myOverloadedSlot(const QVariant &arg) |
|
398 |
{ m_qtFunctionInvoked = 35; m_actuals << arg; } |
|
399 |
||
400 |
virtual int myVirtualSlot(int arg) |
|
401 |
{ m_qtFunctionInvoked = 58; return arg; } |
|
402 |
||
403 |
void qscript_call(int arg) |
|
404 |
{ m_qtFunctionInvoked = 40; m_actuals << arg; } |
|
405 |
||
406 |
protected Q_SLOTS: |
|
407 |
void myProtectedSlot() { m_qtFunctionInvoked = 36; } |
|
408 |
||
409 |
private Q_SLOTS: |
|
410 |
void myPrivateSlot() { } |
|
411 |
||
412 |
Q_SIGNALS: |
|
413 |
void mySignal(); |
|
414 |
void mySignalWithIntArg(int arg); |
|
415 |
void mySignalWithDoubleArg(double arg); |
|
416 |
void mySignal2(bool arg = false); |
|
417 |
void myOverloadedSignal(int arg); |
|
418 |
void myOverloadedSignal(const QString &arg); |
|
419 |
void myOtherOverloadedSignal(const QString &arg); |
|
420 |
void myOtherOverloadedSignal(int arg); |
|
421 |
void mySignalWithDefaultArg(int arg = 123); |
|
422 |
void mySignalWithVariantArg(const QVariant &arg); |
|
423 |
void mySignalWithScriptEngineArg(QScriptEngine *arg); |
|
424 |
||
425 |
protected: |
|
426 |
void connectNotify(const char *signal) { |
|
427 |
m_connectedSignal = signal; |
|
428 |
} |
|
429 |
void disconnectNotify(const char *signal) { |
|
430 |
m_disconnectedSignal = signal; |
|
431 |
} |
|
432 |
||
433 |
protected: |
|
434 |
int m_intValue; |
|
435 |
QVariant m_variantValue; |
|
436 |
QVariantList m_variantListValue; |
|
437 |
QString m_stringValue; |
|
438 |
QStringList m_stringListValue; |
|
439 |
QByteArray m_byteArrayValue; |
|
440 |
QBrush m_brushValue; |
|
441 |
double m_hiddenValue; |
|
442 |
int m_writeOnlyValue; |
|
443 |
int m_readOnlyValue; |
|
444 |
QKeySequence m_shortcut; |
|
445 |
CustomType m_customType; |
|
446 |
Policy m_enumValue; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
447 |
Ability m_flagsValue; |
0 | 448 |
int m_qtFunctionInvoked; |
449 |
QVariantList m_actuals; |
|
450 |
QByteArray m_connectedSignal; |
|
451 |
QByteArray m_disconnectedSignal; |
|
452 |
}; |
|
453 |
||
454 |
Q_DECLARE_METATYPE(MyQObject*) |
|
455 |
Q_DECLARE_METATYPE(MyQObject::Policy) |
|
456 |
||
457 |
class MyOtherQObject : public MyQObject |
|
458 |
{ |
|
459 |
Q_OBJECT |
|
460 |
public: |
|
461 |
MyOtherQObject(QObject *parent = 0) |
|
462 |
: MyQObject(parent) |
|
463 |
{ } |
|
464 |
public Q_SLOTS: |
|
465 |
virtual int myVirtualSlot(int arg) |
|
466 |
{ m_qtFunctionInvoked = 59; return arg; } |
|
467 |
}; |
|
468 |
||
469 |
class MyEnumTestQObject : public QObject |
|
470 |
{ |
|
471 |
Q_OBJECT |
|
472 |
Q_PROPERTY(QString p1 READ p1) |
|
473 |
Q_PROPERTY(QString p2 READ p2) |
|
474 |
Q_PROPERTY(QString p3 READ p3 SCRIPTABLE false) |
|
475 |
Q_PROPERTY(QString p4 READ p4) |
|
476 |
Q_PROPERTY(QString p5 READ p5 SCRIPTABLE false) |
|
477 |
Q_PROPERTY(QString p6 READ p6) |
|
478 |
public: |
|
479 |
MyEnumTestQObject(QObject *parent = 0) |
|
480 |
: QObject(parent) { } |
|
481 |
QString p1() const { return QLatin1String("p1"); } |
|
482 |
QString p2() const { return QLatin1String("p2"); } |
|
483 |
QString p3() const { return QLatin1String("p3"); } |
|
484 |
QString p4() const { return QLatin1String("p4"); } |
|
485 |
QString p5() const { return QLatin1String("p5"); } |
|
486 |
QString p6() const { return QLatin1String("p5"); } |
|
487 |
public Q_SLOTS: |
|
488 |
void mySlot() { } |
|
489 |
void myOtherSlot() { } |
|
490 |
Q_SIGNALS: |
|
491 |
void mySignal(); |
|
492 |
}; |
|
493 |
||
494 |
class tst_QScriptExtQObject : public QObject |
|
495 |
{ |
|
496 |
Q_OBJECT |
|
497 |
||
498 |
public: |
|
499 |
tst_QScriptExtQObject(); |
|
500 |
virtual ~tst_QScriptExtQObject(); |
|
501 |
||
502 |
public slots: |
|
503 |
void init(); |
|
504 |
void cleanup(); |
|
505 |
||
506 |
protected slots: |
|
507 |
void onSignalHandlerException(const QScriptValue &exception) |
|
508 |
{ |
|
509 |
m_signalHandlerException = exception; |
|
510 |
} |
|
511 |
||
512 |
private slots: |
|
513 |
void registeredTypes(); |
|
514 |
void getSetStaticProperty(); |
|
515 |
void getSetDynamicProperty(); |
|
516 |
void getSetChildren(); |
|
517 |
void callQtInvokable(); |
|
518 |
void connectAndDisconnect(); |
|
519 |
void connectAndDisconnectWithBadArgs(); |
|
520 |
void cppConnectAndDisconnect(); |
|
521 |
void classEnums(); |
|
522 |
void classConstructor(); |
|
523 |
void overrideInvokable(); |
|
524 |
void transferInvokable(); |
|
525 |
void findChild(); |
|
526 |
void findChildren(); |
|
527 |
void overloadedSlots(); |
|
528 |
void enumerate_data(); |
|
529 |
void enumerate(); |
|
530 |
void enumerateSpecial(); |
|
531 |
void wrapOptions(); |
|
532 |
void prototypes(); |
|
533 |
void objectDeleted(); |
|
534 |
void connectToDestroyedSignal(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
535 |
void emitAfterReceiverDeleted(); |
0 | 536 |
|
537 |
private: |
|
538 |
QScriptEngine *m_engine; |
|
539 |
MyQObject *m_myObject; |
|
540 |
QScriptValue m_signalHandlerException; |
|
541 |
}; |
|
542 |
||
543 |
tst_QScriptExtQObject::tst_QScriptExtQObject() |
|
544 |
{ |
|
545 |
} |
|
546 |
||
547 |
tst_QScriptExtQObject::~tst_QScriptExtQObject() |
|
548 |
{ |
|
549 |
} |
|
550 |
||
551 |
void tst_QScriptExtQObject::init() |
|
552 |
{ |
|
553 |
m_engine = new QScriptEngine(); |
|
554 |
m_myObject = new MyQObject(); |
|
555 |
m_engine->globalObject().setProperty("myObject", m_engine->newQObject(m_myObject)); |
|
556 |
m_engine->globalObject().setProperty("global", m_engine->globalObject()); |
|
557 |
} |
|
558 |
||
559 |
void tst_QScriptExtQObject::cleanup() |
|
560 |
{ |
|
561 |
delete m_engine; |
|
562 |
delete m_myObject; |
|
563 |
} |
|
564 |
||
565 |
// this test has to be first and test that some types are automatically registered |
|
566 |
void tst_QScriptExtQObject::registeredTypes() |
|
567 |
{ |
|
568 |
QScriptEngine e; |
|
569 |
QObject *t = new MyQObject; |
|
570 |
QObject *c = new QObject(t); |
|
571 |
c->setObjectName ("child1"); |
|
572 |
||
573 |
e.globalObject().setProperty("MyTest", e.newQObject(t)); |
|
574 |
||
575 |
QScriptValue v1 = e.evaluate("MyTest.findObjects()[0].objectName;"); |
|
576 |
QCOMPARE(v1.toString(), c->objectName()); |
|
577 |
||
578 |
QScriptValue v2 = e.evaluate("MyTest.myInvokableNumbers()"); |
|
579 |
QCOMPARE(qscriptvalue_cast<QList<int> >(v2), (QList<int>() << 1 << 2 << 3)); |
|
580 |
} |
|
581 |
||
582 |
||
583 |
static QScriptValue getSetProperty(QScriptContext *ctx, QScriptEngine *) |
|
584 |
{ |
|
585 |
if (ctx->argumentCount() != 0) |
|
586 |
ctx->callee().setProperty("value", ctx->argument(0)); |
|
587 |
return ctx->callee().property("value"); |
|
588 |
} |
|
589 |
||
590 |
static QScriptValue policyToScriptValue(QScriptEngine *engine, const MyQObject::Policy &policy) |
|
591 |
{ |
|
592 |
return qScriptValueFromValue(engine, policy); |
|
593 |
} |
|
594 |
||
595 |
static void policyFromScriptValue(const QScriptValue &value, MyQObject::Policy &policy) |
|
596 |
{ |
|
597 |
QString str = value.toString(); |
|
598 |
if (str == QLatin1String("red")) |
|
599 |
policy = MyQObject::FooPolicy; |
|
600 |
else if (str == QLatin1String("green")) |
|
601 |
policy = MyQObject::BarPolicy; |
|
602 |
else if (str == QLatin1String("blue")) |
|
603 |
policy = MyQObject::BazPolicy; |
|
604 |
else |
|
605 |
policy = (MyQObject::Policy)-1; |
|
606 |
} |
|
607 |
||
608 |
void tst_QScriptExtQObject::getSetStaticProperty() |
|
609 |
{ |
|
610 |
QCOMPARE(m_engine->evaluate("myObject.noSuchProperty").isUndefined(), true); |
|
611 |
||
612 |
// initial value (set in MyQObject constructor) |
|
613 |
QCOMPARE(m_engine->evaluate("myObject.intProperty") |
|
614 |
.strictlyEquals(QScriptValue(m_engine, 123.0)), true); |
|
615 |
QCOMPARE(m_engine->evaluate("myObject.variantProperty") |
|
616 |
.toVariant(), QVariant(QLatin1String("foo"))); |
|
617 |
QCOMPARE(m_engine->evaluate("myObject.stringProperty") |
|
618 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("bar"))), true); |
|
619 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty").isArray(), true); |
|
620 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty.length") |
|
621 |
.strictlyEquals(QScriptValue(m_engine, 2)), true); |
|
622 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty[0]") |
|
623 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
624 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty[1]") |
|
625 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("foo"))), true); |
|
626 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty").isArray(), true); |
|
627 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty.length") |
|
628 |
.strictlyEquals(QScriptValue(m_engine, 2)), true); |
|
629 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[0]").isString(), true); |
|
630 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[0]").toString(), |
|
631 |
QLatin1String("zig")); |
|
632 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[1]").isString(), true); |
|
633 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[1]").toString(), |
|
634 |
QLatin1String("zag")); |
|
635 |
||
636 |
// default flags for "normal" properties |
|
637 |
{ |
|
638 |
QScriptValue mobj = m_engine->globalObject().property("myObject"); |
|
639 |
QVERIFY(!(mobj.propertyFlags("intProperty") & QScriptValue::ReadOnly)); |
|
640 |
QVERIFY(mobj.propertyFlags("intProperty") & QScriptValue::Undeletable); |
|
641 |
QVERIFY(mobj.propertyFlags("intProperty") & QScriptValue::PropertyGetter); |
|
642 |
QVERIFY(mobj.propertyFlags("intProperty") & QScriptValue::PropertySetter); |
|
643 |
QVERIFY(!(mobj.propertyFlags("intProperty") & QScriptValue::SkipInEnumeration)); |
|
644 |
QVERIFY(mobj.propertyFlags("intProperty") & QScriptValue::QObjectMember); |
|
645 |
||
646 |
QVERIFY(!(mobj.propertyFlags("mySlot") & QScriptValue::ReadOnly)); |
|
647 |
QVERIFY(!(mobj.propertyFlags("mySlot") & QScriptValue::Undeletable)); |
|
648 |
QVERIFY(!(mobj.propertyFlags("mySlot") & QScriptValue::SkipInEnumeration)); |
|
649 |
QVERIFY(mobj.propertyFlags("mySlot") & QScriptValue::QObjectMember); |
|
650 |
||
651 |
// signature-based property |
|
652 |
QVERIFY(!(mobj.propertyFlags("mySlot()") & QScriptValue::ReadOnly)); |
|
653 |
QVERIFY(!(mobj.propertyFlags("mySlot()") & QScriptValue::Undeletable)); |
|
654 |
QVERIFY(!(mobj.propertyFlags("mySlot()") & QScriptValue::SkipInEnumeration)); |
|
655 |
QVERIFY(mobj.propertyFlags("mySlot()") & QScriptValue::QObjectMember); |
|
656 |
} |
|
657 |
||
658 |
// property change in C++ should be reflected in script |
|
659 |
m_myObject->setIntProperty(456); |
|
660 |
QCOMPARE(m_engine->evaluate("myObject.intProperty") |
|
661 |
.strictlyEquals(QScriptValue(m_engine, 456)), true); |
|
662 |
m_myObject->setIntProperty(789); |
|
663 |
QCOMPARE(m_engine->evaluate("myObject.intProperty") |
|
664 |
.strictlyEquals(QScriptValue(m_engine, 789)), true); |
|
665 |
||
666 |
m_myObject->setVariantProperty(QLatin1String("bar")); |
|
667 |
QVERIFY(m_engine->evaluate("myObject.variantProperty") |
|
668 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("bar")))); |
|
669 |
m_myObject->setVariantProperty(42); |
|
670 |
QCOMPARE(m_engine->evaluate("myObject.variantProperty") |
|
671 |
.toVariant(), QVariant(42)); |
|
672 |
m_myObject->setVariantProperty(qVariantFromValue(QBrush())); |
|
673 |
QVERIFY(m_engine->evaluate("myObject.variantProperty").isVariant()); |
|
674 |
||
675 |
m_myObject->setStringProperty(QLatin1String("baz")); |
|
676 |
QCOMPARE(m_engine->evaluate("myObject.stringProperty") |
|
677 |
.equals(QScriptValue(m_engine, QLatin1String("baz"))), true); |
|
678 |
m_myObject->setStringProperty(QLatin1String("zab")); |
|
679 |
QCOMPARE(m_engine->evaluate("myObject.stringProperty") |
|
680 |
.equals(QScriptValue(m_engine, QLatin1String("zab"))), true); |
|
681 |
||
682 |
// property change in script should be reflected in C++ |
|
683 |
QCOMPARE(m_engine->evaluate("myObject.intProperty = 123") |
|
684 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
685 |
QCOMPARE(m_engine->evaluate("myObject.intProperty") |
|
686 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
687 |
QCOMPARE(m_myObject->intProperty(), 123); |
|
688 |
QCOMPARE(m_engine->evaluate("myObject.intProperty = 'ciao!';" |
|
689 |
"myObject.intProperty") |
|
690 |
.strictlyEquals(QScriptValue(m_engine, 0)), true); |
|
691 |
QCOMPARE(m_myObject->intProperty(), 0); |
|
692 |
QCOMPARE(m_engine->evaluate("myObject.intProperty = '123';" |
|
693 |
"myObject.intProperty") |
|
694 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
695 |
QCOMPARE(m_myObject->intProperty(), 123); |
|
696 |
||
697 |
QCOMPARE(m_engine->evaluate("myObject.stringProperty = 'ciao'") |
|
698 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("ciao"))), true); |
|
699 |
QCOMPARE(m_engine->evaluate("myObject.stringProperty") |
|
700 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("ciao"))), true); |
|
701 |
QCOMPARE(m_myObject->stringProperty(), QLatin1String("ciao")); |
|
702 |
QCOMPARE(m_engine->evaluate("myObject.stringProperty = 123;" |
|
703 |
"myObject.stringProperty") |
|
704 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("123"))), true); |
|
705 |
QCOMPARE(m_myObject->stringProperty(), QLatin1String("123")); |
|
706 |
QVERIFY(m_engine->evaluate("myObject.stringProperty = null;" |
|
707 |
"myObject.stringProperty") |
|
708 |
.strictlyEquals(QScriptValue(m_engine, QString()))); |
|
709 |
QCOMPARE(m_myObject->stringProperty(), QString()); |
|
710 |
QVERIFY(m_engine->evaluate("myObject.stringProperty = undefined;" |
|
711 |
"myObject.stringProperty") |
|
712 |
.strictlyEquals(QScriptValue(m_engine, QString()))); |
|
713 |
QCOMPARE(m_myObject->stringProperty(), QString()); |
|
714 |
||
715 |
QCOMPARE(m_engine->evaluate("myObject.variantProperty = 'foo';" |
|
716 |
"myObject.variantProperty.valueOf()").toString(), QLatin1String("foo")); |
|
717 |
QCOMPARE(m_myObject->variantProperty(), QVariant(QLatin1String("foo"))); |
|
718 |
QVERIFY(m_engine->evaluate("myObject.variantProperty = undefined;" |
|
719 |
"myObject.variantProperty").isUndefined()); |
|
720 |
QVERIFY(!m_myObject->variantProperty().isValid()); |
|
721 |
QVERIFY(m_engine->evaluate("myObject.variantProperty = null;" |
|
722 |
"myObject.variantProperty").isUndefined()); |
|
723 |
QVERIFY(!m_myObject->variantProperty().isValid()); |
|
724 |
QCOMPARE(m_engine->evaluate("myObject.variantProperty = 42;" |
|
725 |
"myObject.variantProperty").toNumber(), 42.0); |
|
726 |
QCOMPARE(m_myObject->variantProperty().toDouble(), 42.0); |
|
727 |
||
728 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty = [1, 'two', true];" |
|
729 |
"myObject.variantListProperty.length") |
|
730 |
.strictlyEquals(QScriptValue(m_engine, 3)), true); |
|
731 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty[0]") |
|
732 |
.strictlyEquals(QScriptValue(m_engine, 1)), true); |
|
733 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty[1]") |
|
734 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("two"))), true); |
|
735 |
QCOMPARE(m_engine->evaluate("myObject.variantListProperty[2]") |
|
736 |
.strictlyEquals(QScriptValue(m_engine, true)), true); |
|
737 |
{ |
|
738 |
QVariantList vl = qscriptvalue_cast<QVariantList>(m_engine->evaluate("myObject.variantListProperty")); |
|
739 |
QCOMPARE(vl, QVariantList() |
|
740 |
<< QVariant(1) |
|
741 |
<< QVariant(QLatin1String("two")) |
|
742 |
<< QVariant(true)); |
|
743 |
} |
|
744 |
||
745 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty = [1, 'two', true];" |
|
746 |
"myObject.stringListProperty.length") |
|
747 |
.strictlyEquals(QScriptValue(m_engine, 3)), true); |
|
748 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[0]").isString(), true); |
|
749 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[0]").toString(), |
|
750 |
QLatin1String("1")); |
|
751 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[1]").isString(), true); |
|
752 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[1]").toString(), |
|
753 |
QLatin1String("two")); |
|
754 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[2]").isString(), true); |
|
755 |
QCOMPARE(m_engine->evaluate("myObject.stringListProperty[2]").toString(), |
|
756 |
QLatin1String("true")); |
|
757 |
{ |
|
758 |
QStringList sl = qscriptvalue_cast<QStringList>(m_engine->evaluate("myObject.stringListProperty")); |
|
759 |
QCOMPARE(sl, QStringList() |
|
760 |
<< QLatin1String("1") |
|
761 |
<< QLatin1String("two") |
|
762 |
<< QLatin1String("true")); |
|
763 |
} |
|
764 |
||
765 |
// test setting properties where we can't convert the type natively but where the |
|
766 |
// types happen to be compatible variant types already |
|
767 |
{ |
|
768 |
QKeySequence sequence(Qt::ControlModifier + Qt::AltModifier + Qt::Key_Delete); |
|
769 |
QScriptValue mobj = m_engine->globalObject().property("myObject"); |
|
770 |
||
771 |
QVERIFY(m_myObject->shortcut().isEmpty()); |
|
772 |
mobj.setProperty("shortcut", m_engine->newVariant(sequence)); |
|
773 |
QVERIFY(m_myObject->shortcut() == sequence); |
|
774 |
} |
|
775 |
{ |
|
776 |
CustomType t; t.string = "hello"; |
|
777 |
QScriptValue mobj = m_engine->globalObject().property("myObject"); |
|
778 |
||
779 |
QVERIFY(m_myObject->propWithCustomType().string.isEmpty()); |
|
780 |
mobj.setProperty("propWithCustomType", m_engine->newVariant(qVariantFromValue(t))); |
|
781 |
QVERIFY(m_myObject->propWithCustomType().string == t.string); |
|
782 |
} |
|
783 |
||
784 |
// test that we do value conversion if necessary when setting properties |
|
785 |
{ |
|
786 |
QScriptValue br = m_engine->evaluate("myObject.brushProperty"); |
|
787 |
QVERIFY(br.isVariant()); |
|
788 |
QVERIFY(!br.strictlyEquals(m_engine->evaluate("myObject.brushProperty"))); |
|
789 |
QCOMPARE(qscriptvalue_cast<QBrush>(br), m_myObject->brushProperty()); |
|
790 |
QCOMPARE(qscriptvalue_cast<QColor>(br), m_myObject->brushProperty().color()); |
|
791 |
||
792 |
QColor newColor(40, 30, 20, 10); |
|
793 |
QScriptValue val = qScriptValueFromValue(m_engine, newColor); |
|
794 |
m_engine->globalObject().setProperty("myColor", val); |
|
795 |
QScriptValue ret = m_engine->evaluate("myObject.brushProperty = myColor"); |
|
796 |
QCOMPARE(ret.strictlyEquals(val), true); |
|
797 |
br = m_engine->evaluate("myObject.brushProperty"); |
|
798 |
QCOMPARE(qscriptvalue_cast<QBrush>(br), QBrush(newColor)); |
|
799 |
QCOMPARE(qscriptvalue_cast<QColor>(br), newColor); |
|
800 |
||
801 |
m_engine->globalObject().setProperty("myColor", QScriptValue()); |
|
802 |
} |
|
803 |
||
804 |
// try to delete |
|
805 |
QCOMPARE(m_engine->evaluate("delete myObject.intProperty").toBoolean(), false); |
|
806 |
QCOMPARE(m_engine->evaluate("myObject.intProperty").toNumber(), 123.0); |
|
807 |
||
808 |
QCOMPARE(m_engine->evaluate("delete myObject.variantProperty").toBoolean(), false); |
|
809 |
QCOMPARE(m_engine->evaluate("myObject.variantProperty").toNumber(), 42.0); |
|
810 |
||
811 |
// non-scriptable property |
|
812 |
QCOMPARE(m_myObject->hiddenProperty(), 456.0); |
|
813 |
QCOMPARE(m_engine->evaluate("myObject.hiddenProperty").isUndefined(), true); |
|
814 |
QCOMPARE(m_engine->evaluate("myObject.hiddenProperty = 123;" |
|
815 |
"myObject.hiddenProperty").toInt32(), 123); |
|
816 |
QCOMPARE(m_myObject->hiddenProperty(), 456.0); |
|
817 |
||
818 |
// write-only property |
|
819 |
QCOMPARE(m_myObject->writeOnlyProperty(), 789); |
|
820 |
QCOMPARE(m_engine->evaluate("myObject.writeOnlyProperty").isUndefined(), true); |
|
821 |
QCOMPARE(m_engine->evaluate("myObject.writeOnlyProperty = 123;" |
|
822 |
"myObject.writeOnlyProperty").isUndefined(), true); |
|
823 |
QCOMPARE(m_myObject->writeOnlyProperty(), 123); |
|
824 |
||
825 |
// read-only property |
|
826 |
QCOMPARE(m_myObject->readOnlyProperty(), 987); |
|
827 |
QCOMPARE(m_engine->evaluate("myObject.readOnlyProperty").toInt32(), 987); |
|
828 |
QCOMPARE(m_engine->evaluate("myObject.readOnlyProperty = 654;" |
|
829 |
"myObject.readOnlyProperty").toInt32(), 987); |
|
830 |
QCOMPARE(m_myObject->readOnlyProperty(), 987); |
|
831 |
{ |
|
832 |
QScriptValue mobj = m_engine->globalObject().property("myObject"); |
|
833 |
QCOMPARE(mobj.propertyFlags("readOnlyProperty") & QScriptValue::ReadOnly, |
|
834 |
QScriptValue::ReadOnly); |
|
835 |
} |
|
836 |
||
837 |
// enum property |
|
838 |
QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy); |
|
839 |
{ |
|
840 |
QScriptValue val = m_engine->evaluate("myObject.enumProperty"); |
|
841 |
QVERIFY(val.isNumber()); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
842 |
QCOMPARE(val.toInt32(), int(MyQObject::BarPolicy)); |
0 | 843 |
} |
844 |
m_engine->evaluate("myObject.enumProperty = 2"); |
|
845 |
QCOMPARE(m_myObject->enumProperty(), MyQObject::BazPolicy); |
|
846 |
m_engine->evaluate("myObject.enumProperty = 'BarPolicy'"); |
|
847 |
QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy); |
|
848 |
m_engine->evaluate("myObject.enumProperty = 'ScoobyDoo'"); |
|
849 |
// ### ouch! Shouldn't QMetaProperty::write() rather not change the value...? |
|
850 |
QCOMPARE(m_myObject->enumProperty(), (MyQObject::Policy)-1); |
|
851 |
// enum property with custom conversion |
|
852 |
qScriptRegisterMetaType<MyQObject::Policy>(m_engine, policyToScriptValue, policyFromScriptValue); |
|
853 |
m_engine->evaluate("myObject.enumProperty = 'red'"); |
|
854 |
QCOMPARE(m_myObject->enumProperty(), MyQObject::FooPolicy); |
|
855 |
m_engine->evaluate("myObject.enumProperty = 'green'"); |
|
856 |
QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy); |
|
857 |
m_engine->evaluate("myObject.enumProperty = 'blue'"); |
|
858 |
QCOMPARE(m_myObject->enumProperty(), MyQObject::BazPolicy); |
|
859 |
m_engine->evaluate("myObject.enumProperty = 'nada'"); |
|
860 |
QCOMPARE(m_myObject->enumProperty(), (MyQObject::Policy)-1); |
|
861 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
862 |
// flags property |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
863 |
QCOMPARE(m_myObject->flagsProperty(), MyQObject::FooAbility); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
864 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
865 |
QScriptValue val = m_engine->evaluate("myObject.flagsProperty"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
866 |
QVERIFY(val.isNumber()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
867 |
QCOMPARE(val.toInt32(), int(MyQObject::FooAbility)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
868 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
869 |
m_engine->evaluate("myObject.flagsProperty = 0x80"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
870 |
QCOMPARE(m_myObject->flagsProperty(), MyQObject::BarAbility); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
871 |
m_engine->evaluate("myObject.flagsProperty = 0x81"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
872 |
QCOMPARE(m_myObject->flagsProperty(), MyQObject::Ability(MyQObject::FooAbility | MyQObject::BarAbility)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
873 |
m_engine->evaluate("myObject.flagsProperty = 123"); // bogus values are accepted |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
874 |
QCOMPARE(int(m_myObject->flagsProperty()), 123); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
875 |
m_engine->evaluate("myObject.flagsProperty = 'BazAbility'"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
876 |
QCOMPARE(m_myObject->flagsProperty(), MyQObject::BazAbility); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
877 |
m_engine->evaluate("myObject.flagsProperty = 'ScoobyDoo'"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
878 |
// ### ouch! Shouldn't QMetaProperty::write() rather not change the value...? |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
879 |
QCOMPARE(m_myObject->flagsProperty(), (MyQObject::Ability)-1); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
880 |
|
0 | 881 |
// auto-dereferencing of pointers |
882 |
{ |
|
883 |
QBrush b = QColor(0xCA, 0xFE, 0xBA, 0xBE); |
|
884 |
QBrush *bp = &b; |
|
885 |
QScriptValue bpValue = m_engine->newVariant(qVariantFromValue(bp)); |
|
886 |
m_engine->globalObject().setProperty("brushPointer", bpValue); |
|
887 |
{ |
|
888 |
QScriptValue ret = m_engine->evaluate("myObject.setBrushProperty(brushPointer)"); |
|
889 |
QCOMPARE(ret.isUndefined(), true); |
|
890 |
QCOMPARE(qscriptvalue_cast<QBrush>(m_engine->evaluate("myObject.brushProperty")), b); |
|
891 |
} |
|
892 |
{ |
|
893 |
b = QColor(0xDE, 0xAD, 0xBE, 0xEF); |
|
894 |
QScriptValue ret = m_engine->evaluate("myObject.brushProperty = brushPointer"); |
|
895 |
QCOMPARE(ret.strictlyEquals(bpValue), true); |
|
896 |
QCOMPARE(qscriptvalue_cast<QBrush>(m_engine->evaluate("myObject.brushProperty")), b); |
|
897 |
} |
|
898 |
m_engine->globalObject().setProperty("brushPointer", QScriptValue()); |
|
899 |
} |
|
900 |
||
901 |
// install custom property getter+setter |
|
902 |
{ |
|
903 |
QScriptValue mobj = m_engine->globalObject().property("myObject"); |
|
904 |
mobj.setProperty("intProperty", m_engine->newFunction(getSetProperty), |
|
905 |
QScriptValue::PropertyGetter | QScriptValue::PropertySetter); |
|
906 |
QVERIFY(mobj.property("intProperty").toInt32() != 321); |
|
907 |
mobj.setProperty("intProperty", 321); |
|
908 |
QCOMPARE(mobj.property("intProperty").toInt32(), 321); |
|
909 |
} |
|
910 |
||
911 |
// method properties are persistent |
|
912 |
{ |
|
913 |
QScriptValue slot = m_engine->evaluate("myObject.mySlot"); |
|
914 |
QVERIFY(slot.isFunction()); |
|
915 |
QScriptValue sameSlot = m_engine->evaluate("myObject.mySlot"); |
|
916 |
QVERIFY(sameSlot.strictlyEquals(slot)); |
|
917 |
sameSlot = m_engine->evaluate("myObject[mySlot()]"); |
|
918 |
QEXPECT_FAIL("", "Signature-based method lookup creates new function wrapper object", Continue); |
|
919 |
QVERIFY(sameSlot.strictlyEquals(slot)); |
|
920 |
} |
|
921 |
} |
|
922 |
||
923 |
void tst_QScriptExtQObject::getSetDynamicProperty() |
|
924 |
{ |
|
925 |
// initially the object does not have the property |
|
926 |
QCOMPARE(m_engine->evaluate("myObject.hasOwnProperty('dynamicProperty')") |
|
927 |
.strictlyEquals(QScriptValue(m_engine, false)), true); |
|
928 |
||
929 |
// add a dynamic property in C++ |
|
930 |
QCOMPARE(m_myObject->setProperty("dynamicProperty", 123), false); |
|
931 |
QCOMPARE(m_engine->evaluate("myObject.hasOwnProperty('dynamicProperty')") |
|
932 |
.strictlyEquals(QScriptValue(m_engine, true)), true); |
|
933 |
QCOMPARE(m_engine->evaluate("myObject.dynamicProperty") |
|
934 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
935 |
||
936 |
// check the flags |
|
937 |
{ |
|
938 |
QScriptValue mobj = m_engine->globalObject().property("myObject"); |
|
939 |
QVERIFY(!(mobj.propertyFlags("dynamicProperty") & QScriptValue::ReadOnly)); |
|
940 |
QVERIFY(!(mobj.propertyFlags("dynamicProperty") & QScriptValue::Undeletable)); |
|
941 |
QVERIFY(!(mobj.propertyFlags("dynamicProperty") & QScriptValue::SkipInEnumeration)); |
|
942 |
QVERIFY(mobj.propertyFlags("dynamicProperty") & QScriptValue::QObjectMember); |
|
943 |
} |
|
944 |
||
945 |
// property change in script should be reflected in C++ |
|
946 |
QCOMPARE(m_engine->evaluate("myObject.dynamicProperty = 'foo';" |
|
947 |
"myObject.dynamicProperty") |
|
948 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("foo"))), true); |
|
949 |
QCOMPARE(m_myObject->property("dynamicProperty").toString(), QLatin1String("foo")); |
|
950 |
||
951 |
// delete the property |
|
952 |
QCOMPARE(m_engine->evaluate("delete myObject.dynamicProperty").toBoolean(), true); |
|
953 |
QCOMPARE(m_myObject->property("dynamicProperty").isValid(), false); |
|
954 |
QCOMPARE(m_engine->evaluate("myObject.dynamicProperty").isUndefined(), true); |
|
955 |
QCOMPARE(m_engine->evaluate("myObject.hasOwnProperty('dynamicProperty')").toBoolean(), false); |
|
956 |
} |
|
957 |
||
958 |
void tst_QScriptExtQObject::getSetChildren() |
|
959 |
{ |
|
960 |
QScriptValue mobj = m_engine->evaluate("myObject"); |
|
961 |
||
962 |
// initially the object does not have the child |
|
963 |
QCOMPARE(m_engine->evaluate("myObject.hasOwnProperty('child')") |
|
964 |
.strictlyEquals(QScriptValue(m_engine, false)), true); |
|
965 |
||
966 |
// add a child |
|
967 |
MyQObject *child = new MyQObject(m_myObject); |
|
968 |
child->setObjectName("child"); |
|
969 |
QCOMPARE(m_engine->evaluate("myObject.hasOwnProperty('child')") |
|
970 |
.strictlyEquals(QScriptValue(m_engine, true)), true); |
|
971 |
||
972 |
QVERIFY(mobj.propertyFlags("child") & QScriptValue::ReadOnly); |
|
973 |
QVERIFY(mobj.propertyFlags("child") & QScriptValue::Undeletable); |
|
974 |
QVERIFY(mobj.propertyFlags("child") & QScriptValue::SkipInEnumeration); |
|
975 |
QVERIFY(!(mobj.propertyFlags("child") & QScriptValue::QObjectMember)); |
|
976 |
||
977 |
{ |
|
978 |
QScriptValue scriptChild = m_engine->evaluate("myObject.child"); |
|
979 |
QVERIFY(scriptChild.isQObject()); |
|
980 |
QCOMPARE(scriptChild.toQObject(), (QObject*)child); |
|
981 |
QScriptValue sameChild = m_engine->evaluate("myObject.child"); |
|
982 |
QVERIFY(sameChild.strictlyEquals(scriptChild)); |
|
983 |
} |
|
984 |
||
985 |
// add a grandchild |
|
986 |
MyQObject *grandChild = new MyQObject(child); |
|
987 |
grandChild->setObjectName("grandChild"); |
|
988 |
QCOMPARE(m_engine->evaluate("myObject.child.hasOwnProperty('grandChild')") |
|
989 |
.strictlyEquals(QScriptValue(m_engine, true)), true); |
|
990 |
||
991 |
// delete grandchild |
|
992 |
delete grandChild; |
|
993 |
QCOMPARE(m_engine->evaluate("myObject.child.hasOwnProperty('grandChild')") |
|
994 |
.strictlyEquals(QScriptValue(m_engine, false)), true); |
|
995 |
||
996 |
// delete child |
|
997 |
delete child; |
|
998 |
QCOMPARE(m_engine->evaluate("myObject.hasOwnProperty('child')") |
|
999 |
.strictlyEquals(QScriptValue(m_engine, false)), true); |
|
1000 |
||
1001 |
} |
|
1002 |
||
1003 |
Q_DECLARE_METATYPE(QVector<int>) |
|
1004 |
Q_DECLARE_METATYPE(QVector<double>) |
|
1005 |
Q_DECLARE_METATYPE(QVector<QString>) |
|
1006 |
||
1007 |
template <class T> |
|
1008 |
static QScriptValue qobjectToScriptValue(QScriptEngine *engine, T* const &in) |
|
1009 |
{ return engine->newQObject(in); } |
|
1010 |
||
1011 |
template <class T> |
|
1012 |
static void qobjectFromScriptValue(const QScriptValue &object, T* &out) |
|
1013 |
{ out = qobject_cast<T*>(object.toQObject()); } |
|
1014 |
||
1015 |
void tst_QScriptExtQObject::callQtInvokable() |
|
1016 |
{ |
|
1017 |
m_myObject->resetQtFunctionInvoked(); |
|
1018 |
QCOMPARE(m_engine->evaluate("myObject.myInvokable()").isUndefined(), true); |
|
1019 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 0); |
|
1020 |
QCOMPARE(m_myObject->qtFunctionActuals(), QVariantList()); |
|
1021 |
||
1022 |
// extra arguments should silently be ignored |
|
1023 |
m_myObject->resetQtFunctionInvoked(); |
|
1024 |
QCOMPARE(m_engine->evaluate("myObject.myInvokable(10, 20, 30)").isUndefined(), true); |
|
1025 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 0); |
|
1026 |
QCOMPARE(m_myObject->qtFunctionActuals(), QVariantList()); |
|
1027 |
||
1028 |
m_myObject->resetQtFunctionInvoked(); |
|
1029 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithIntArg(123)").isUndefined(), true); |
|
1030 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 1); |
|
1031 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1032 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1033 |
||
1034 |
m_myObject->resetQtFunctionInvoked(); |
|
1035 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithIntArg('123')").isUndefined(), true); |
|
1036 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 1); |
|
1037 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1038 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1039 |
||
1040 |
m_myObject->resetQtFunctionInvoked(); |
|
1041 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithLonglongArg(123)").isUndefined(), true); |
|
1042 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 2); |
|
1043 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1044 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toLongLong(), qlonglong(123)); |
|
1045 |
||
1046 |
m_myObject->resetQtFunctionInvoked(); |
|
1047 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithFloatArg(123.5)").isUndefined(), true); |
|
1048 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 3); |
|
1049 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1050 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toDouble(), 123.5); |
|
1051 |
||
1052 |
m_myObject->resetQtFunctionInvoked(); |
|
1053 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithDoubleArg(123.5)").isUndefined(), true); |
|
1054 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 4); |
|
1055 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1056 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toDouble(), 123.5); |
|
1057 |
||
1058 |
m_myObject->resetQtFunctionInvoked(); |
|
1059 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithStringArg('ciao')").isUndefined(), true); |
|
1060 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 5); |
|
1061 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1062 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toString(), QLatin1String("ciao")); |
|
1063 |
||
1064 |
m_myObject->resetQtFunctionInvoked(); |
|
1065 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithStringArg(123)").isUndefined(), true); |
|
1066 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 5); |
|
1067 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1068 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toString(), QLatin1String("123")); |
|
1069 |
||
1070 |
m_myObject->resetQtFunctionInvoked(); |
|
1071 |
QVERIFY(m_engine->evaluate("myObject.myInvokableWithStringArg(null)").isUndefined()); |
|
1072 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 5); |
|
1073 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1074 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).type(), QVariant::String); |
|
1075 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toString(), QString()); |
|
1076 |
||
1077 |
m_myObject->resetQtFunctionInvoked(); |
|
1078 |
QVERIFY(m_engine->evaluate("myObject.myInvokableWithStringArg(undefined)").isUndefined()); |
|
1079 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 5); |
|
1080 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1081 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).type(), QVariant::String); |
|
1082 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toString(), QString()); |
|
1083 |
||
1084 |
m_myObject->resetQtFunctionInvoked(); |
|
1085 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithIntArgs(123, 456)").isUndefined(), true); |
|
1086 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 6); |
|
1087 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 2); |
|
1088 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1089 |
QCOMPARE(m_myObject->qtFunctionActuals().at(1).toInt(), 456); |
|
1090 |
||
1091 |
m_myObject->resetQtFunctionInvoked(); |
|
1092 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableReturningInt()") |
|
1093 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
1094 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 7); |
|
1095 |
QCOMPARE(m_myObject->qtFunctionActuals(), QVariantList()); |
|
1096 |
||
1097 |
m_myObject->resetQtFunctionInvoked(); |
|
1098 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableReturningLongLong()") |
|
1099 |
.strictlyEquals(QScriptValue(m_engine, 456)), true); |
|
1100 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 39); |
|
1101 |
QCOMPARE(m_myObject->qtFunctionActuals(), QVariantList()); |
|
1102 |
||
1103 |
m_myObject->resetQtFunctionInvoked(); |
|
1104 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableReturningString()") |
|
1105 |
.strictlyEquals(QScriptValue(m_engine, QLatin1String("ciao"))), true); |
|
1106 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 8); |
|
1107 |
QCOMPARE(m_myObject->qtFunctionActuals(), QVariantList()); |
|
1108 |
||
1109 |
m_myObject->resetQtFunctionInvoked(); |
|
1110 |
QVERIFY(m_engine->evaluate("myObject.myInvokableReturningVariant()") |
|
1111 |
.strictlyEquals(QScriptValue(m_engine, 123))); |
|
1112 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 60); |
|
1113 |
||
1114 |
m_myObject->resetQtFunctionInvoked(); |
|
1115 |
QVERIFY(m_engine->evaluate("myObject.myInvokableReturningScriptValue()") |
|
1116 |
.strictlyEquals(QScriptValue(m_engine, 456))); |
|
1117 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 61); |
|
1118 |
||
1119 |
m_myObject->resetQtFunctionInvoked(); |
|
1120 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithIntArg(123, 456)").isUndefined(), true); |
|
1121 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 9); |
|
1122 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 2); |
|
1123 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1124 |
QCOMPARE(m_myObject->qtFunctionActuals().at(1).toInt(), 456); |
|
1125 |
||
1126 |
m_myObject->resetQtFunctionInvoked(); |
|
1127 |
QVERIFY(m_engine->evaluate("myObject.myInvokableWithVoidStarArg(null)").isUndefined()); |
|
1128 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 44); |
|
1129 |
m_myObject->resetQtFunctionInvoked(); |
|
1130 |
QVERIFY(m_engine->evaluate("myObject.myInvokableWithVoidStarArg(123)").isError()); |
|
1131 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
1132 |
||
1133 |
m_myObject->resetQtFunctionInvoked(); |
|
1134 |
{ |
|
1135 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithAmbiguousArg(123)"); |
|
1136 |
QVERIFY(ret.isError()); |
|
1137 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: ambiguous call of overloaded function myInvokableWithAmbiguousArg(); candidates were\n myInvokableWithAmbiguousArg(int)\n myInvokableWithAmbiguousArg(uint)")); |
|
1138 |
} |
|
1139 |
||
1140 |
m_myObject->resetQtFunctionInvoked(); |
|
1141 |
{ |
|
1142 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithDefaultArgs(123, 'hello')"); |
|
1143 |
QVERIFY(ret.isUndefined()); |
|
1144 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 47); |
|
1145 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 2); |
|
1146 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1147 |
QCOMPARE(m_myObject->qtFunctionActuals().at(1).toString(), QLatin1String("hello")); |
|
1148 |
} |
|
1149 |
||
1150 |
m_myObject->resetQtFunctionInvoked(); |
|
1151 |
{ |
|
1152 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithDefaultArgs(456)"); |
|
1153 |
QVERIFY(ret.isUndefined()); |
|
1154 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 47); |
|
1155 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 2); |
|
1156 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 456); |
|
1157 |
QCOMPARE(m_myObject->qtFunctionActuals().at(1).toString(), QString()); |
|
1158 |
} |
|
1159 |
||
1160 |
{ |
|
1161 |
QScriptValue fun = m_engine->evaluate("myObject.myInvokableWithPointArg"); |
|
1162 |
QVERIFY(fun.isFunction()); |
|
1163 |
m_myObject->resetQtFunctionInvoked(); |
|
1164 |
{ |
|
1165 |
QScriptValue ret = fun.call(m_engine->evaluate("myObject"), |
|
1166 |
QScriptValueList() << qScriptValueFromValue(m_engine, QPoint(10, 20))); |
|
1167 |
QVERIFY(ret.isUndefined()); |
|
1168 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 50); |
|
1169 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1170 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toPoint(), QPoint(10, 20)); |
|
1171 |
} |
|
1172 |
m_myObject->resetQtFunctionInvoked(); |
|
1173 |
{ |
|
1174 |
QScriptValue ret = fun.call(m_engine->evaluate("myObject"), |
|
1175 |
QScriptValueList() << qScriptValueFromValue(m_engine, QPointF(30, 40))); |
|
1176 |
QVERIFY(ret.isUndefined()); |
|
1177 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 51); |
|
1178 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1179 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toPointF(), QPointF(30, 40)); |
|
1180 |
} |
|
1181 |
} |
|
1182 |
||
1183 |
// calling function that returns (const)ref |
|
1184 |
m_myObject->resetQtFunctionInvoked(); |
|
1185 |
{ |
|
1186 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningRef()"); |
|
1187 |
QVERIFY(ret.isUndefined()); |
|
1188 |
QVERIFY(!m_engine->hasUncaughtException()); |
|
1189 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 48); |
|
1190 |
} |
|
1191 |
m_myObject->resetQtFunctionInvoked(); |
|
1192 |
{ |
|
1193 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningConstRef()"); |
|
1194 |
QVERIFY(ret.isUndefined()); |
|
1195 |
QVERIFY(!m_engine->hasUncaughtException()); |
|
1196 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 49); |
|
1197 |
} |
|
1198 |
||
1199 |
// first time we expect failure because the metatype is not registered |
|
1200 |
m_myObject->resetQtFunctionInvoked(); |
|
1201 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableReturningVectorOfInt()").isError(), true); |
|
1202 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
1203 |
||
1204 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithVectorOfIntArg(0)").isError(), true); |
|
1205 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
1206 |
||
1207 |
// now we register it, and it should work |
|
1208 |
qScriptRegisterSequenceMetaType<QVector<int> >(m_engine); |
|
1209 |
{ |
|
1210 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningVectorOfInt()"); |
|
1211 |
QCOMPARE(ret.isArray(), true); |
|
1212 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 11); |
|
1213 |
} |
|
1214 |
||
1215 |
{ |
|
1216 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVectorOfIntArg(myObject.myInvokableReturningVectorOfInt())"); |
|
1217 |
QCOMPARE(ret.isUndefined(), true); |
|
1218 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 12); |
|
1219 |
} |
|
1220 |
||
1221 |
m_myObject->resetQtFunctionInvoked(); |
|
1222 |
{ |
|
1223 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningQObjectStar()"); |
|
1224 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 13); |
|
1225 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 0); |
|
1226 |
QCOMPARE(ret.isQObject(), true); |
|
1227 |
QCOMPARE(ret.toQObject(), (QObject *)m_myObject); |
|
1228 |
} |
|
1229 |
||
1230 |
m_myObject->resetQtFunctionInvoked(); |
|
1231 |
{ |
|
1232 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQObjectListArg([myObject])"); |
|
1233 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 14); |
|
1234 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1235 |
QCOMPARE(ret.isArray(), true); |
|
1236 |
QCOMPARE(ret.property(QLatin1String("length")) |
|
1237 |
.strictlyEquals(QScriptValue(m_engine, 1)), true); |
|
1238 |
QCOMPARE(ret.property(QLatin1String("0")).isQObject(), true); |
|
1239 |
QCOMPARE(ret.property(QLatin1String("0")).toQObject(), (QObject *)m_myObject); |
|
1240 |
} |
|
1241 |
||
1242 |
m_myObject->resetQtFunctionInvoked(); |
|
1243 |
{ |
|
1244 |
m_myObject->setVariantProperty(QVariant(123)); |
|
1245 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantArg(myObject.variantProperty)"); |
|
1246 |
QVERIFY(ret.isNumber()); |
|
1247 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 15); |
|
1248 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1249 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0), m_myObject->variantProperty()); |
|
1250 |
QVERIFY(ret.strictlyEquals(QScriptValue(m_engine, 123))); |
|
1251 |
} |
|
1252 |
||
1253 |
m_myObject->resetQtFunctionInvoked(); |
|
1254 |
{ |
|
1255 |
m_myObject->setVariantProperty(qVariantFromValue(QBrush())); |
|
1256 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantArg(myObject.variantProperty)"); |
|
1257 |
QVERIFY(ret.isVariant()); |
|
1258 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 15); |
|
1259 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1260 |
QCOMPARE(ret.toVariant(), m_myObject->qtFunctionActuals().at(0)); |
|
1261 |
QCOMPARE(ret.toVariant(), m_myObject->variantProperty()); |
|
1262 |
} |
|
1263 |
||
1264 |
m_myObject->resetQtFunctionInvoked(); |
|
1265 |
{ |
|
1266 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantArg(123)"); |
|
1267 |
QVERIFY(ret.isNumber()); |
|
1268 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 15); |
|
1269 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1270 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0), QVariant(123)); |
|
1271 |
QVERIFY(ret.strictlyEquals(QScriptValue(m_engine, 123))); |
|
1272 |
} |
|
1273 |
||
1274 |
m_myObject->resetQtFunctionInvoked(); |
|
1275 |
{ |
|
1276 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantArg('ciao')"); |
|
1277 |
QVERIFY(ret.isString()); |
|
1278 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 15); |
|
1279 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1280 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0), QVariant(QString::fromLatin1("ciao"))); |
|
1281 |
QVERIFY(ret.strictlyEquals(QScriptValue(m_engine, QString::fromLatin1("ciao")))); |
|
1282 |
} |
|
1283 |
||
1284 |
m_myObject->resetQtFunctionInvoked(); |
|
1285 |
{ |
|
1286 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantArg(null)"); |
|
1287 |
QVERIFY(ret.isUndefined()); // invalid QVariant is converted to Undefined |
|
1288 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 15); |
|
1289 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1290 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0), QVariant()); |
|
1291 |
} |
|
1292 |
||
1293 |
m_myObject->resetQtFunctionInvoked(); |
|
1294 |
{ |
|
1295 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantArg(undefined)"); |
|
1296 |
QVERIFY(ret.isUndefined()); |
|
1297 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 15); |
|
1298 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1299 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0), QVariant()); |
|
1300 |
} |
|
1301 |
||
1302 |
m_engine->globalObject().setProperty("fishy", m_engine->newVariant(123)); |
|
1303 |
m_engine->evaluate("myObject.myInvokableWithStringArg(fishy)"); |
|
1304 |
||
1305 |
m_myObject->resetQtFunctionInvoked(); |
|
1306 |
{ |
|
1307 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithVariantMapArg({ a:123, b:'ciao' })"); |
|
1308 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 16); |
|
1309 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1310 |
QVariant v = m_myObject->qtFunctionActuals().at(0); |
|
1311 |
QCOMPARE(v.userType(), int(QMetaType::QVariantMap)); |
|
1312 |
QVariantMap vmap = qvariant_cast<QVariantMap>(v); |
|
1313 |
QCOMPARE(vmap.keys().size(), 2); |
|
1314 |
QCOMPARE(vmap.keys().at(0), QLatin1String("a")); |
|
1315 |
QCOMPARE(vmap.value("a"), QVariant(123)); |
|
1316 |
QCOMPARE(vmap.keys().at(1), QLatin1String("b")); |
|
1317 |
QCOMPARE(vmap.value("b"), QVariant("ciao")); |
|
1318 |
||
1319 |
QCOMPARE(ret.isObject(), true); |
|
1320 |
QCOMPARE(ret.property("a").strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
1321 |
QCOMPARE(ret.property("b").strictlyEquals(QScriptValue(m_engine, "ciao")), true); |
|
1322 |
} |
|
1323 |
||
1324 |
m_myObject->resetQtFunctionInvoked(); |
|
1325 |
{ |
|
1326 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithListOfIntArg([1, 5])"); |
|
1327 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 17); |
|
1328 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1329 |
QVariant v = m_myObject->qtFunctionActuals().at(0); |
|
1330 |
QCOMPARE(v.userType(), qMetaTypeId<QList<int> >()); |
|
1331 |
QList<int> ilst = qvariant_cast<QList<int> >(v); |
|
1332 |
QCOMPARE(ilst.size(), 2); |
|
1333 |
QCOMPARE(ilst.at(0), 1); |
|
1334 |
QCOMPARE(ilst.at(1), 5); |
|
1335 |
||
1336 |
QCOMPARE(ret.isArray(), true); |
|
1337 |
QCOMPARE(ret.property("0").strictlyEquals(QScriptValue(m_engine, 1)), true); |
|
1338 |
QCOMPARE(ret.property("1").strictlyEquals(QScriptValue(m_engine, 5)), true); |
|
1339 |
} |
|
1340 |
||
1341 |
m_myObject->resetQtFunctionInvoked(); |
|
1342 |
{ |
|
1343 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQObjectStarArg(myObject)"); |
|
1344 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 18); |
|
1345 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1346 |
QVariant v = m_myObject->qtFunctionActuals().at(0); |
|
1347 |
QCOMPARE(v.userType(), int(QMetaType::QObjectStar)); |
|
1348 |
QCOMPARE(qvariant_cast<QObject*>(v), (QObject *)m_myObject); |
|
1349 |
||
1350 |
QCOMPARE(ret.isQObject(), true); |
|
1351 |
QCOMPARE(qscriptvalue_cast<QObject*>(ret), (QObject *)m_myObject); |
|
1352 |
} |
|
1353 |
||
1354 |
m_myObject->resetQtFunctionInvoked(); |
|
1355 |
{ |
|
1356 |
// no implicit conversion from integer to QObject* |
|
1357 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQObjectStarArg(123)"); |
|
1358 |
QCOMPARE(ret.isError(), true); |
|
1359 |
} |
|
1360 |
||
1361 |
m_myObject->resetQtFunctionInvoked(); |
|
1362 |
{ |
|
1363 |
QScriptValue fun = m_engine->evaluate("myObject.myInvokableWithQBrushArg"); |
|
1364 |
QVERIFY(fun.isFunction()); |
|
1365 |
QColor color(10, 20, 30, 40); |
|
1366 |
// QColor should be converted to a QBrush |
|
1367 |
QScriptValue ret = fun.call(QScriptValue(), QScriptValueList() |
|
1368 |
<< qScriptValueFromValue(m_engine, color)); |
|
1369 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 19); |
|
1370 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1371 |
QVariant v = m_myObject->qtFunctionActuals().at(0); |
|
1372 |
QCOMPARE(v.userType(), int(QMetaType::QBrush)); |
|
1373 |
QCOMPARE(qvariant_cast<QColor>(v), color); |
|
1374 |
||
1375 |
QCOMPARE(qscriptvalue_cast<QColor>(ret), color); |
|
1376 |
} |
|
1377 |
||
1378 |
// private slots should not be part of the QObject binding |
|
1379 |
QCOMPARE(m_engine->evaluate("myObject.myPrivateSlot").isUndefined(), true); |
|
1380 |
||
1381 |
// protected slots should be fine |
|
1382 |
m_myObject->resetQtFunctionInvoked(); |
|
1383 |
m_engine->evaluate("myObject.myProtectedSlot()"); |
|
1384 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 36); |
|
1385 |
||
1386 |
// call with too few arguments |
|
1387 |
{ |
|
1388 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithIntArg()"); |
|
1389 |
QVERIFY(ret.isError()); |
|
1390 |
QCOMPARE(ret.toString(), QLatin1String("SyntaxError: too few arguments in call to myInvokableWithIntArg(); candidates are\n myInvokableWithIntArg(int,int)\n myInvokableWithIntArg(int)")); |
|
1391 |
} |
|
1392 |
||
1393 |
// call function where not all types have been registered |
|
1394 |
m_myObject->resetQtFunctionInvoked(); |
|
1395 |
{ |
|
1396 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithBrushStyleArg(0)"); |
|
1397 |
QVERIFY(ret.isError()); |
|
1398 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: cannot call myInvokableWithBrushStyleArg(): argument 1 has unknown type `Qt::BrushStyle' (register the type with qScriptRegisterMetaType())")); |
|
1399 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
1400 |
} |
|
1401 |
||
1402 |
// call function with incompatible argument type |
|
1403 |
m_myObject->resetQtFunctionInvoked(); |
|
1404 |
{ |
|
1405 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQBrushArg(null)"); |
|
1406 |
QVERIFY(ret.isError()); |
|
1407 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: incompatible type of argument(s) in call to myInvokableWithQBrushArg(); candidates were\n myInvokableWithQBrushArg(QBrush)")); |
|
1408 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
1409 |
} |
|
1410 |
||
1411 |
// ability to call a slot with QObject-based arguments, even if those types haven't been registered |
|
1412 |
m_myObject->resetQtFunctionInvoked(); |
|
1413 |
{ |
|
1414 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithMyQObjectArg(myObject)"); |
|
1415 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 52); |
|
1416 |
QVERIFY(ret.isUndefined()); |
|
1417 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1418 |
QCOMPARE(qvariant_cast<QObject*>(m_myObject->qtFunctionActuals().at(0)), (QObject*)m_myObject); |
|
1419 |
} |
|
1420 |
||
1421 |
// inability to call a slot returning QObject-based type, when that type hasn't been registered |
|
1422 |
m_myObject->resetQtFunctionInvoked(); |
|
1423 |
{ |
|
1424 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningMyQObject()"); |
|
1425 |
QVERIFY(ret.isError()); |
|
1426 |
QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: cannot call myInvokableReturningMyQObject(): unknown return type `MyQObject*' (register the type with qScriptRegisterMetaType())")); |
|
1427 |
} |
|
1428 |
||
1429 |
// ability to call a slot returning QObject-based type when that type has been registered |
|
1430 |
qRegisterMetaType<MyQObject*>("MyQObject*"); |
|
1431 |
m_myObject->resetQtFunctionInvoked(); |
|
1432 |
{ |
|
1433 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningMyQObject()"); |
|
1434 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 53); |
|
1435 |
QVERIFY(ret.isVariant()); |
|
1436 |
QCOMPARE(*reinterpret_cast<MyQObject* const *>(ret.toVariant().constData()), m_myObject); |
|
1437 |
} |
|
1438 |
||
1439 |
// ability to call a slot with QObject-based argument, when the argument is const |
|
1440 |
m_myObject->resetQtFunctionInvoked(); |
|
1441 |
{ |
|
1442 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithConstMyQObjectArg(myObject)"); |
|
1443 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 54); |
|
1444 |
QVERIFY(ret.isUndefined()); |
|
1445 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1446 |
QCOMPARE(qvariant_cast<QObject*>(m_myObject->qtFunctionActuals().at(0)), (QObject*)m_myObject); |
|
1447 |
} |
|
1448 |
||
1449 |
// QScriptValue arguments should be passed on without conversion |
|
1450 |
m_myObject->resetQtFunctionInvoked(); |
|
1451 |
{ |
|
1452 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithScriptValueArg(123)"); |
|
1453 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 56); |
|
1454 |
QVERIFY(ret.isNumber()); |
|
1455 |
QCOMPARE(ret.toInt32(), 123); |
|
1456 |
} |
|
1457 |
m_myObject->resetQtFunctionInvoked(); |
|
1458 |
{ |
|
1459 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithScriptValueArg('ciao')"); |
|
1460 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 56); |
|
1461 |
QVERIFY(ret.isString()); |
|
1462 |
QCOMPARE(ret.toString(), QString::fromLatin1("ciao")); |
|
1463 |
} |
|
1464 |
m_myObject->resetQtFunctionInvoked(); |
|
1465 |
{ |
|
1466 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithScriptValueArg(this)"); |
|
1467 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 56); |
|
1468 |
QVERIFY(ret.isObject()); |
|
1469 |
QVERIFY(ret.strictlyEquals(m_engine->globalObject())); |
|
1470 |
} |
|
1471 |
||
1472 |
// the prototype specified by a conversion function should not be "down-graded" |
|
1473 |
m_myObject->resetQtFunctionInvoked(); |
|
1474 |
{ |
|
1475 |
QScriptValue qobjectProto = m_engine->newObject(); |
|
1476 |
qScriptRegisterMetaType<QObject*>(m_engine, qobjectToScriptValue, |
|
1477 |
qobjectFromScriptValue, qobjectProto); |
|
1478 |
QScriptValue myQObjectProto = m_engine->newObject(); |
|
1479 |
myQObjectProto.setPrototype(qobjectProto); |
|
1480 |
qScriptRegisterMetaType<MyQObject*>(m_engine, qobjectToScriptValue, |
|
1481 |
qobjectFromScriptValue, myQObjectProto); |
|
1482 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningMyQObjectAsQObject()"); |
|
1483 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 57); |
|
1484 |
QVERIFY(ret.isQObject()); |
|
1485 |
QVERIFY(ret.prototype().strictlyEquals(myQObjectProto)); |
|
1486 |
||
1487 |
qScriptRegisterMetaType<QObject*>(m_engine, 0, 0, QScriptValue()); |
|
1488 |
qScriptRegisterMetaType<MyQObject*>(m_engine, 0, 0, QScriptValue()); |
|
1489 |
} |
|
1490 |
||
1491 |
// detect exceptions during argument conversion |
|
1492 |
m_myObject->resetQtFunctionInvoked(); |
|
1493 |
{ |
|
1494 |
QScriptValue (*dummy)(QScriptEngine *, const QDir &) = 0; |
|
1495 |
qScriptRegisterMetaType<QDir>(m_engine, dummy, dirFromScript); |
|
1496 |
{ |
|
1497 |
QVERIFY(!m_engine->hasUncaughtException()); |
|
1498 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQDirArg({})"); |
|
1499 |
QVERIFY(m_engine->hasUncaughtException()); |
|
1500 |
QVERIFY(ret.isError()); |
|
1501 |
QCOMPARE(ret.toString(), QString::fromLatin1("Error: No path")); |
|
1502 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
1503 |
} |
|
1504 |
m_engine->clearExceptions(); |
|
1505 |
{ |
|
1506 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQDirArg({path:'.'})"); |
|
1507 |
QVERIFY(!m_engine->hasUncaughtException()); |
|
1508 |
QVERIFY(ret.isUndefined()); |
|
1509 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 55); |
|
1510 |
} |
|
1511 |
} |
|
1512 |
||
1513 |
// qscript_call() |
|
1514 |
{ |
|
1515 |
m_myObject->resetQtFunctionInvoked(); |
|
1516 |
QScriptValue ret = m_engine->evaluate("new myObject(123)"); |
|
1517 |
QVERIFY(ret.isError()); |
|
1518 |
QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Result of expression 'myObject' [MyQObject(name = \"\")] is not a constructor.")); |
|
1519 |
} |
|
1520 |
{ |
|
1521 |
m_myObject->resetQtFunctionInvoked(); |
|
1522 |
QScriptValue ret = m_engine->evaluate("myObject(123)"); |
|
1523 |
QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Result of expression 'myObject' [MyQObject(name = \"\")] is not a function.")); |
|
1524 |
} |
|
1525 |
||
1526 |
// task 233624 |
|
1527 |
{ |
|
1528 |
MyNS::A a; |
|
1529 |
m_engine->globalObject().setProperty("anObject", m_engine->newQObject(&a)); |
|
1530 |
QScriptValue ret = m_engine->evaluate("anObject.slotTakingScopedEnumArg(1)"); |
|
1531 |
QVERIFY(!ret.isError()); |
|
1532 |
QVERIFY(ret.isNumber()); |
|
1533 |
QCOMPARE(ret.toInt32(), 1); |
|
1534 |
m_engine->globalObject().setProperty("anObject", QScriptValue()); |
|
1535 |
} |
|
1536 |
||
1537 |
// virtual slot redeclared in subclass (task 236467) |
|
1538 |
{ |
|
1539 |
MyOtherQObject moq; |
|
1540 |
m_engine->globalObject().setProperty("myOtherQObject", m_engine->newQObject(&moq)); |
|
1541 |
moq.resetQtFunctionInvoked(); |
|
1542 |
QScriptValue ret = m_engine->evaluate("myOtherQObject.myVirtualSlot(123)"); |
|
1543 |
QCOMPARE(moq.qtFunctionInvoked(), 59); |
|
1544 |
QVERIFY(!ret.isError()); |
|
1545 |
QVERIFY(ret.isNumber()); |
|
1546 |
QCOMPARE(ret.toInt32(), 123); |
|
1547 |
} |
|
1548 |
} |
|
1549 |
||
1550 |
void tst_QScriptExtQObject::connectAndDisconnect() |
|
1551 |
{ |
|
1552 |
// connect(function) |
|
1553 |
QCOMPARE(m_engine->evaluate("myObject.mySignal.connect(123)").isError(), true); |
|
1554 |
||
1555 |
m_engine->evaluate("myHandler = function() { global.gotSignal = true; global.signalArgs = arguments; global.slotThisObject = this; }"); |
|
1556 |
||
1557 |
m_myObject->clearConnectedSignal(); |
|
1558 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(myHandler)").isUndefined()); |
|
1559 |
QCOMPARE(m_myObject->connectedSignal().constData(), SIGNAL(mySignal())); |
|
1560 |
||
1561 |
m_engine->evaluate("gotSignal = false"); |
|
1562 |
m_engine->evaluate("myObject.mySignal()"); |
|
1563 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1564 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 0.0); |
|
1565 |
QVERIFY(m_engine->evaluate("slotThisObject").strictlyEquals(m_engine->globalObject())); |
|
1566 |
||
1567 |
m_engine->evaluate("gotSignal = false"); |
|
1568 |
m_myObject->emitMySignal(); |
|
1569 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1570 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 0.0); |
|
1571 |
||
1572 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.connect(myHandler)").isUndefined()); |
|
1573 |
||
1574 |
m_engine->evaluate("gotSignal = false"); |
|
1575 |
m_myObject->emitMySignalWithIntArg(123); |
|
1576 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1577 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
1578 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toNumber(), 123.0); |
|
1579 |
||
1580 |
m_myObject->clearDisconnectedSignal(); |
|
1581 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(myHandler)").isUndefined()); |
|
1582 |
QCOMPARE(m_myObject->disconnectedSignal().constData(), SIGNAL(mySignal())); |
|
1583 |
||
1584 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(myHandler)").isError()); |
|
1585 |
||
1586 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.connect(myHandler)").isUndefined()); |
|
1587 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.disconnect(myHandler)").isUndefined()); |
|
1588 |
||
1589 |
m_engine->evaluate("gotSignal = false"); |
|
1590 |
m_myObject->emitMySignal2(false); |
|
1591 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1592 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
1593 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toBoolean(), false); |
|
1594 |
||
1595 |
m_engine->evaluate("gotSignal = false"); |
|
1596 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.connect(myHandler)").isUndefined()); |
|
1597 |
m_myObject->emitMySignal2(true); |
|
1598 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1599 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
1600 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toBoolean(), true); |
|
1601 |
||
1602 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.disconnect(myHandler)").isUndefined()); |
|
1603 |
||
1604 |
QVERIFY(m_engine->evaluate("myObject['mySignal2()'].connect(myHandler)").isUndefined()); |
|
1605 |
||
1606 |
m_engine->evaluate("gotSignal = false"); |
|
1607 |
m_myObject->emitMySignal2(); |
|
1608 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1609 |
||
1610 |
QVERIFY(m_engine->evaluate("myObject['mySignal2()'].disconnect(myHandler)").isUndefined()); |
|
1611 |
||
1612 |
// connecting to signal with default args should pick the most generic version (i.e. with all args) |
|
1613 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithDefaultArg.connect(myHandler)").isUndefined()); |
|
1614 |
m_engine->evaluate("gotSignal = false"); |
|
1615 |
m_myObject->emitMySignalWithDefaultArgWithArg(456); |
|
1616 |
QVERIFY(m_engine->evaluate("gotSignal").toBoolean()); |
|
1617 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toInt32(), 1); |
|
1618 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toInt32(), 456); |
|
1619 |
||
1620 |
m_engine->evaluate("gotSignal = false"); |
|
1621 |
m_myObject->emitMySignalWithDefaultArg(); |
|
1622 |
QVERIFY(m_engine->evaluate("gotSignal").toBoolean()); |
|
1623 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toInt32(), 1); |
|
1624 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toInt32(), 123); |
|
1625 |
||
1626 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithDefaultArg.disconnect(myHandler)").isUndefined()); |
|
1627 |
||
1628 |
m_engine->evaluate("gotSignal = false"); |
|
1629 |
// connecting to overloaded signal should throw an error |
|
1630 |
{ |
|
1631 |
QScriptValue ret = m_engine->evaluate("myObject.myOverloadedSignal.connect(myHandler)"); |
|
1632 |
QVERIFY(ret.isError()); |
|
1633 |
QCOMPARE(ret.toString(), QString::fromLatin1("Error: Function.prototype.connect: ambiguous connect to MyQObject::myOverloadedSignal(); candidates are\n" |
|
1634 |
" myOverloadedSignal(int)\n" |
|
1635 |
" myOverloadedSignal(QString)\n" |
|
1636 |
"Use e.g. object['myOverloadedSignal(QString)'].connect() to connect to a particular overload")); |
|
1637 |
} |
|
1638 |
m_myObject->emitMyOverloadedSignal(123); |
|
1639 |
QVERIFY(!m_engine->evaluate("gotSignal").toBoolean()); |
|
1640 |
m_myObject->emitMyOverloadedSignal("ciao"); |
|
1641 |
QVERIFY(!m_engine->evaluate("gotSignal").toBoolean()); |
|
1642 |
||
1643 |
m_engine->evaluate("gotSignal = false"); |
|
1644 |
{ |
|
1645 |
QScriptValue ret = m_engine->evaluate("myObject.myOtherOverloadedSignal.connect(myHandler)"); |
|
1646 |
QVERIFY(ret.isError()); |
|
1647 |
QCOMPARE(ret.toString(), QString::fromLatin1("Error: Function.prototype.connect: ambiguous connect to MyQObject::myOtherOverloadedSignal(); candidates are\n" |
|
1648 |
" myOtherOverloadedSignal(QString)\n" |
|
1649 |
" myOtherOverloadedSignal(int)\n" |
|
1650 |
"Use e.g. object['myOtherOverloadedSignal(int)'].connect() to connect to a particular overload")); |
|
1651 |
} |
|
1652 |
m_myObject->emitMyOtherOverloadedSignal("ciao"); |
|
1653 |
QVERIFY(!m_engine->evaluate("gotSignal").toBoolean()); |
|
1654 |
m_myObject->emitMyOtherOverloadedSignal(123); |
|
1655 |
QVERIFY(!m_engine->evaluate("gotSignal").toBoolean()); |
|
1656 |
||
1657 |
// signal with QVariant arg: argument conversion should work |
|
1658 |
m_myObject->clearConnectedSignal(); |
|
1659 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithVariantArg.connect(myHandler)").isUndefined()); |
|
1660 |
QCOMPARE(m_myObject->connectedSignal().constData(), SIGNAL(mySignalWithVariantArg(QVariant))); |
|
1661 |
m_engine->evaluate("gotSignal = false"); |
|
1662 |
m_myObject->emitMySignalWithVariantArg(123); |
|
1663 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1664 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1665 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toNumber(), 123.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1666 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithVariantArg.disconnect(myHandler)").isUndefined()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1667 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1668 |
// signal with argument type that's unknown to the meta-type system |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1669 |
m_myObject->clearConnectedSignal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1670 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithScriptEngineArg.connect(myHandler)").isUndefined()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1671 |
QCOMPARE(m_myObject->connectedSignal().constData(), SIGNAL(mySignalWithScriptEngineArg(QScriptEngine*))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1672 |
m_engine->evaluate("gotSignal = false"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1673 |
QTest::ignoreMessage(QtWarningMsg, "QScriptEngine: Unable to handle unregistered datatype 'QScriptEngine*' when invoking handler of signal MyQObject::mySignalWithScriptEngineArg(QScriptEngine*)"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1674 |
m_myObject->emitMySignalWithScriptEngineArg(m_engine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1675 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1676 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1677 |
QVERIFY(m_engine->evaluate("signalArgs[0]").isUndefined()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1678 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithScriptEngineArg.disconnect(myHandler)").isUndefined()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1679 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1680 |
// signal with QVariant arg: argument conversion should work |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1681 |
m_myObject->clearConnectedSignal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1682 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithVariantArg.connect(myHandler)").isUndefined()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1683 |
QCOMPARE(m_myObject->connectedSignal().constData(), SIGNAL(mySignalWithVariantArg(QVariant))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1684 |
m_engine->evaluate("gotSignal = false"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1685 |
m_myObject->emitMySignalWithVariantArg(123); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1686 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1687 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
0 | 1688 |
QVERIFY(m_engine->evaluate("signalArgs[0]").isNumber()); |
1689 |
QCOMPARE(m_engine->evaluate("signalArgs[0]").toNumber(), 123.0); |
|
1690 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithVariantArg.disconnect(myHandler)").isUndefined()); |
|
1691 |
||
1692 |
// signal with argument type that's unknown to the meta-type system |
|
1693 |
m_myObject->clearConnectedSignal(); |
|
1694 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithScriptEngineArg.connect(myHandler)").isUndefined()); |
|
1695 |
QCOMPARE(m_myObject->connectedSignal().constData(), SIGNAL(mySignalWithScriptEngineArg(QScriptEngine*))); |
|
1696 |
m_engine->evaluate("gotSignal = false"); |
|
1697 |
QTest::ignoreMessage(QtWarningMsg, "QScriptEngine: Unable to handle unregistered datatype 'QScriptEngine*' when invoking handler of signal MyQObject::mySignalWithScriptEngineArg(QScriptEngine*)"); |
|
1698 |
m_myObject->emitMySignalWithScriptEngineArg(m_engine); |
|
1699 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1700 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
1701 |
QVERIFY(m_engine->evaluate("signalArgs[0]").isUndefined()); |
|
1702 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithScriptEngineArg.disconnect(myHandler)").isUndefined()); |
|
1703 |
||
1704 |
// connect(object, function) |
|
1705 |
m_engine->evaluate("otherObject = { name:'foo' }"); |
|
1706 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(otherObject, myHandler)").isUndefined()); |
|
1707 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(otherObject, myHandler)").isUndefined()); |
|
1708 |
m_engine->evaluate("gotSignal = false"); |
|
1709 |
m_myObject->emitMySignal(); |
|
1710 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), false); |
|
1711 |
||
1712 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(otherObject, myHandler)").isError()); |
|
1713 |
||
1714 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(otherObject, myHandler)").isUndefined()); |
|
1715 |
m_engine->evaluate("gotSignal = false"); |
|
1716 |
m_myObject->emitMySignal(); |
|
1717 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1718 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 0.0); |
|
1719 |
QVERIFY(m_engine->evaluate("slotThisObject").strictlyEquals(m_engine->evaluate("otherObject"))); |
|
1720 |
QCOMPARE(m_engine->evaluate("slotThisObject").property("name").toString(), QLatin1String("foo")); |
|
1721 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(otherObject, myHandler)").isUndefined()); |
|
1722 |
||
1723 |
m_engine->evaluate("yetAnotherObject = { name:'bar', func : function() { } }"); |
|
1724 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.connect(yetAnotherObject, myHandler)").isUndefined()); |
|
1725 |
m_engine->evaluate("gotSignal = false"); |
|
1726 |
m_myObject->emitMySignal2(true); |
|
1727 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1728 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
1729 |
QVERIFY(m_engine->evaluate("slotThisObject").strictlyEquals(m_engine->evaluate("yetAnotherObject"))); |
|
1730 |
QCOMPARE(m_engine->evaluate("slotThisObject").property("name").toString(), QLatin1String("bar")); |
|
1731 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.disconnect(yetAnotherObject, myHandler)").isUndefined()); |
|
1732 |
||
1733 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.connect(myObject, myHandler)").isUndefined()); |
|
1734 |
m_engine->evaluate("gotSignal = false"); |
|
1735 |
m_myObject->emitMySignal2(true); |
|
1736 |
QCOMPARE(m_engine->evaluate("gotSignal").toBoolean(), true); |
|
1737 |
QCOMPARE(m_engine->evaluate("signalArgs.length").toNumber(), 1.0); |
|
1738 |
QCOMPARE(m_engine->evaluate("slotThisObject").toQObject(), (QObject *)m_myObject); |
|
1739 |
QVERIFY(m_engine->evaluate("myObject.mySignal2.disconnect(myObject, myHandler)").isUndefined()); |
|
1740 |
||
1741 |
// connect(obj, string) |
|
1742 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(yetAnotherObject, 'func')").isUndefined()); |
|
1743 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(myObject, 'mySlot')").isUndefined()); |
|
1744 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(yetAnotherObject, 'func')").isUndefined()); |
|
1745 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(myObject, 'mySlot')").isUndefined()); |
|
1746 |
||
1747 |
// check that emitting signals from script works |
|
1748 |
||
1749 |
// no arguments |
|
1750 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(myObject.mySlot)").isUndefined()); |
|
1751 |
m_myObject->resetQtFunctionInvoked(); |
|
1752 |
QCOMPARE(m_engine->evaluate("myObject.mySignal()").isUndefined(), true); |
|
1753 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 20); |
|
1754 |
QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(myObject.mySlot)").isUndefined()); |
|
1755 |
||
1756 |
// one argument |
|
1757 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.connect(myObject.mySlotWithIntArg)").isUndefined()); |
|
1758 |
m_myObject->resetQtFunctionInvoked(); |
|
1759 |
QCOMPARE(m_engine->evaluate("myObject.mySignalWithIntArg(123)").isUndefined(), true); |
|
1760 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 21); |
|
1761 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1762 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1763 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.disconnect(myObject.mySlotWithIntArg)").isUndefined()); |
|
1764 |
||
1765 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.connect(myObject.mySlotWithDoubleArg)").isUndefined()); |
|
1766 |
m_myObject->resetQtFunctionInvoked(); |
|
1767 |
QCOMPARE(m_engine->evaluate("myObject.mySignalWithIntArg(123)").isUndefined(), true); |
|
1768 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 22); |
|
1769 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1770 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toDouble(), 123.0); |
|
1771 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.disconnect(myObject.mySlotWithDoubleArg)").isUndefined()); |
|
1772 |
||
1773 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.connect(myObject.mySlotWithStringArg)").isUndefined()); |
|
1774 |
m_myObject->resetQtFunctionInvoked(); |
|
1775 |
QCOMPARE(m_engine->evaluate("myObject.mySignalWithIntArg(123)").isUndefined(), true); |
|
1776 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 23); |
|
1777 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1778 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toString(), QLatin1String("123")); |
|
1779 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.disconnect(myObject.mySlotWithStringArg)").isUndefined()); |
|
1780 |
||
1781 |
// connecting to overloaded slot |
|
1782 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.connect(myObject.myOverloadedSlot)").isUndefined()); |
|
1783 |
m_myObject->resetQtFunctionInvoked(); |
|
1784 |
QCOMPARE(m_engine->evaluate("myObject.mySignalWithIntArg(123)").isUndefined(), true); |
|
1785 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 26); // double overload |
|
1786 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1787 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 123); |
|
1788 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.disconnect(myObject.myOverloadedSlot)").isUndefined()); |
|
1789 |
||
1790 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.connect(myObject['myOverloadedSlot(int)'])").isUndefined()); |
|
1791 |
m_myObject->resetQtFunctionInvoked(); |
|
1792 |
QCOMPARE(m_engine->evaluate("myObject.mySignalWithIntArg(456)").isUndefined(), true); |
|
1793 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 28); // int overload |
|
1794 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
1795 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), 456); |
|
1796 |
QVERIFY(m_engine->evaluate("myObject.mySignalWithIntArg.disconnect(myObject['myOverloadedSlot(int)'])").isUndefined()); |
|
1797 |
||
1798 |
// when the wrapper dies, the connection stays alive |
|
1799 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(myObject.mySlot)").isUndefined()); |
|
1800 |
m_myObject->resetQtFunctionInvoked(); |
|
1801 |
m_myObject->emitMySignal(); |
|
1802 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 20); |
|
1803 |
m_engine->evaluate("myObject = null"); |
|
1804 |
m_engine->collectGarbage(); |
|
1805 |
m_myObject->resetQtFunctionInvoked(); |
|
1806 |
m_myObject->emitMySignal(); |
|
1807 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 20); |
|
1808 |
} |
|
1809 |
||
1810 |
void tst_QScriptExtQObject::connectAndDisconnectWithBadArgs() |
|
1811 |
{ |
|
1812 |
{ |
|
1813 |
QScriptValue ret = m_engine->evaluate("(function() { }).connect()"); |
|
1814 |
QVERIFY(ret.isError()); |
|
1815 |
QCOMPARE(ret.toString(), QLatin1String("Error: Function.prototype.connect: no arguments given")); |
|
1816 |
} |
|
1817 |
{ |
|
1818 |
QScriptValue ret = m_engine->evaluate("var o = { }; o.connect = Function.prototype.connect; o.connect()"); |
|
1819 |
QVERIFY(ret.isError()); |
|
1820 |
QCOMPARE(ret.toString(), QLatin1String("Error: Function.prototype.connect: no arguments given")); |
|
1821 |
} |
|
1822 |
||
1823 |
{ |
|
1824 |
QScriptValue ret = m_engine->evaluate("(function() { }).connect(123)"); |
|
1825 |
QVERIFY(ret.isError()); |
|
1826 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.connect: this object is not a signal")); |
|
1827 |
} |
|
1828 |
{ |
|
1829 |
QScriptValue ret = m_engine->evaluate("var o = { }; o.connect = Function.prototype.connect; o.connect(123)"); |
|
1830 |
QVERIFY(ret.isError()); |
|
1831 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.connect: this object is not a signal")); |
|
1832 |
} |
|
1833 |
||
1834 |
{ |
|
1835 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokable.connect(123)"); |
|
1836 |
QVERIFY(ret.isError()); |
|
1837 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.connect: MyQObject::myInvokable() is not a signal")); |
|
1838 |
} |
|
1839 |
{ |
|
1840 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokable.connect(function() { })"); |
|
1841 |
QVERIFY(ret.isError()); |
|
1842 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.connect: MyQObject::myInvokable() is not a signal")); |
|
1843 |
} |
|
1844 |
||
1845 |
{ |
|
1846 |
QScriptValue ret = m_engine->evaluate("myObject.mySignal.connect(123)"); |
|
1847 |
QVERIFY(ret.isError()); |
|
1848 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.connect: target is not a function")); |
|
1849 |
} |
|
1850 |
||
1851 |
{ |
|
1852 |
QScriptValue ret = m_engine->evaluate("(function() { }).disconnect()"); |
|
1853 |
QVERIFY(ret.isError()); |
|
1854 |
QCOMPARE(ret.toString(), QLatin1String("Error: Function.prototype.disconnect: no arguments given")); |
|
1855 |
} |
|
1856 |
{ |
|
1857 |
QScriptValue ret = m_engine->evaluate("var o = { }; o.disconnect = Function.prototype.disconnect; o.disconnect()"); |
|
1858 |
QVERIFY(ret.isError()); |
|
1859 |
QCOMPARE(ret.toString(), QLatin1String("Error: Function.prototype.disconnect: no arguments given")); |
|
1860 |
} |
|
1861 |
||
1862 |
{ |
|
1863 |
QScriptValue ret = m_engine->evaluate("(function() { }).disconnect(123)"); |
|
1864 |
QVERIFY(ret.isError()); |
|
1865 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.disconnect: this object is not a signal")); |
|
1866 |
} |
|
1867 |
{ |
|
1868 |
QScriptValue ret = m_engine->evaluate("var o = { }; o.disconnect = Function.prototype.disconnect; o.disconnect(123)"); |
|
1869 |
QVERIFY(ret.isError()); |
|
1870 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.disconnect: this object is not a signal")); |
|
1871 |
} |
|
1872 |
||
1873 |
{ |
|
1874 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokable.disconnect(123)"); |
|
1875 |
QVERIFY(ret.isError()); |
|
1876 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.disconnect: MyQObject::myInvokable() is not a signal")); |
|
1877 |
} |
|
1878 |
{ |
|
1879 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokable.disconnect(function() { })"); |
|
1880 |
QVERIFY(ret.isError()); |
|
1881 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.disconnect: MyQObject::myInvokable() is not a signal")); |
|
1882 |
} |
|
1883 |
||
1884 |
{ |
|
1885 |
QScriptValue ret = m_engine->evaluate("myObject.mySignal.disconnect(123)"); |
|
1886 |
QVERIFY(ret.isError()); |
|
1887 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Function.prototype.disconnect: target is not a function")); |
|
1888 |
} |
|
1889 |
||
1890 |
{ |
|
1891 |
QScriptValue ret = m_engine->evaluate("myObject.mySignal.disconnect(function() { })"); |
|
1892 |
QVERIFY(ret.isError()); |
|
1893 |
QCOMPARE(ret.toString(), QLatin1String("Error: Function.prototype.disconnect: failed to disconnect from MyQObject::mySignal()")); |
|
1894 |
} |
|
1895 |
} |
|
1896 |
||
1897 |
void tst_QScriptExtQObject::cppConnectAndDisconnect() |
|
1898 |
{ |
|
1899 |
QScriptEngine eng; |
|
1900 |
QLineEdit edit; |
|
1901 |
QLineEdit edit2; |
|
1902 |
QScriptValue fun = eng.evaluate("function fun(text) { signalObject = this; signalArg = text; }; fun"); |
|
1903 |
QVERIFY(fun.isFunction()); |
|
1904 |
for (int z = 0; z < 2; ++z) { |
|
1905 |
QScriptValue receiver; |
|
1906 |
if (z == 0) |
|
1907 |
receiver = QScriptValue(); |
|
1908 |
else |
|
1909 |
receiver = eng.newObject(); |
|
1910 |
for (int y = 0; y < 2; ++y) { |
|
1911 |
QVERIFY(qScriptConnect(&edit, SIGNAL(textChanged(const QString &)), receiver, fun)); |
|
1912 |
QVERIFY(qScriptConnect(&edit2, SIGNAL(textChanged(const QString &)), receiver, fun)); |
|
1913 |
// check signal emission |
|
1914 |
for (int x = 0; x < 4; ++x) { |
|
1915 |
QLineEdit *ed = (x < 2) ? &edit : &edit2; |
|
1916 |
ed->setText((x % 2) ? "foo" : "bar"); |
|
1917 |
{ |
|
1918 |
QScriptValue ret = eng.globalObject().property("signalObject"); |
|
1919 |
if (receiver.isObject()) |
|
1920 |
QVERIFY(ret.strictlyEquals(receiver)); |
|
1921 |
else |
|
1922 |
QVERIFY(ret.strictlyEquals(eng.globalObject())); |
|
1923 |
} |
|
1924 |
{ |
|
1925 |
QScriptValue ret = eng.globalObject().property("signalArg"); |
|
1926 |
QVERIFY(ret.isString()); |
|
1927 |
QCOMPARE(ret.toString(), ed->text()); |
|
1928 |
} |
|
1929 |
eng.collectGarbage(); |
|
1930 |
} |
|
1931 |
||
1932 |
// check disconnect |
|
1933 |
QVERIFY(qScriptDisconnect(&edit, SIGNAL(textChanged(const QString &)), receiver, fun)); |
|
1934 |
eng.globalObject().setProperty("signalObject", QScriptValue()); |
|
1935 |
eng.globalObject().setProperty("signalArg", QScriptValue()); |
|
1936 |
edit.setText("something else"); |
|
1937 |
QVERIFY(!eng.globalObject().property("signalObject").isValid()); |
|
1938 |
QVERIFY(!eng.globalObject().property("signalArg").isValid()); |
|
1939 |
QVERIFY(!qScriptDisconnect(&edit, SIGNAL(textChanged(const QString &)), receiver, fun)); |
|
1940 |
||
1941 |
// other object's connection should remain |
|
1942 |
edit2.setText(edit.text()); |
|
1943 |
{ |
|
1944 |
QScriptValue ret = eng.globalObject().property("signalObject"); |
|
1945 |
if (receiver.isObject()) |
|
1946 |
QVERIFY(ret.strictlyEquals(receiver)); |
|
1947 |
else |
|
1948 |
QVERIFY(ret.strictlyEquals(eng.globalObject())); |
|
1949 |
} |
|
1950 |
{ |
|
1951 |
QScriptValue ret = eng.globalObject().property("signalArg"); |
|
1952 |
QVERIFY(ret.isString()); |
|
1953 |
QCOMPARE(ret.toString(), edit2.text()); |
|
1954 |
} |
|
1955 |
||
1956 |
// disconnect other object too |
|
1957 |
QVERIFY(qScriptDisconnect(&edit2, SIGNAL(textChanged(const QString &)), receiver, fun)); |
|
1958 |
eng.globalObject().setProperty("signalObject", QScriptValue()); |
|
1959 |
eng.globalObject().setProperty("signalArg", QScriptValue()); |
|
1960 |
edit2.setText("even more different"); |
|
1961 |
QVERIFY(!eng.globalObject().property("signalObject").isValid()); |
|
1962 |
QVERIFY(!eng.globalObject().property("signalArg").isValid()); |
|
1963 |
QVERIFY(!qScriptDisconnect(&edit2, SIGNAL(textChanged(const QString &)), receiver, fun)); |
|
1964 |
} |
|
1965 |
} |
|
1966 |
||
1967 |
// make sure we don't crash when engine is deleted |
|
1968 |
{ |
|
1969 |
QScriptEngine *eng2 = new QScriptEngine; |
|
1970 |
QScriptValue fun2 = eng2->evaluate("(function(text) { signalObject = this; signalArg = text; })"); |
|
1971 |
QVERIFY(fun2.isFunction()); |
|
1972 |
QVERIFY(qScriptConnect(&edit, SIGNAL(textChanged(const QString &)), QScriptValue(), fun2)); |
|
1973 |
delete eng2; |
|
1974 |
edit.setText("ciao"); |
|
1975 |
QVERIFY(!qScriptDisconnect(&edit, SIGNAL(textChanged(const QString &)), QScriptValue(), fun2)); |
|
1976 |
} |
|
1977 |
||
1978 |
// mixing script-side and C++-side connect |
|
1979 |
{ |
|
1980 |
eng.globalObject().setProperty("edit", eng.newQObject(&edit)); |
|
1981 |
QVERIFY(eng.evaluate("edit.textChanged.connect(fun)").isUndefined()); |
|
1982 |
QVERIFY(qScriptDisconnect(&edit, SIGNAL(textChanged(const QString &)), QScriptValue(), fun)); |
|
1983 |
||
1984 |
QVERIFY(qScriptConnect(&edit, SIGNAL(textChanged(const QString &)), QScriptValue(), fun)); |
|
1985 |
QVERIFY(eng.evaluate("edit.textChanged.disconnect(fun)").isUndefined()); |
|
1986 |
} |
|
1987 |
||
1988 |
// signalHandlerException() |
|
1989 |
{ |
|
1990 |
connect(&eng, SIGNAL(signalHandlerException(QScriptValue)), |
|
1991 |
this, SLOT(onSignalHandlerException(QScriptValue))); |
|
1992 |
||
1993 |
eng.globalObject().setProperty("edit", eng.newQObject(&edit)); |
|
1994 |
QScriptValue fun = eng.evaluate("(function() { nonExistingFunction(); })"); |
|
1995 |
QVERIFY(fun.isFunction()); |
|
1996 |
QVERIFY(qScriptConnect(&edit, SIGNAL(textChanged(const QString &)), QScriptValue(), fun)); |
|
1997 |
||
1998 |
m_signalHandlerException = QScriptValue(); |
|
1999 |
QScriptValue ret = eng.evaluate("edit.text = 'trigger a signal handler exception from script'"); |
|
2000 |
QVERIFY(ret.isError()); |
|
2001 |
QVERIFY(m_signalHandlerException.strictlyEquals(ret)); |
|
2002 |
||
2003 |
m_signalHandlerException = QScriptValue(); |
|
2004 |
edit.setText("trigger a signal handler exception from C++"); |
|
2005 |
QVERIFY(m_signalHandlerException.isError()); |
|
2006 |
||
2007 |
QVERIFY(qScriptDisconnect(&edit, SIGNAL(textChanged(const QString &)), QScriptValue(), fun)); |
|
2008 |
||
2009 |
m_signalHandlerException = QScriptValue(); |
|
2010 |
eng.evaluate("edit.text = 'no more exception from script'"); |
|
2011 |
QVERIFY(!m_signalHandlerException.isValid()); |
|
2012 |
edit.setText("no more exception from C++"); |
|
2013 |
QVERIFY(!m_signalHandlerException.isValid()); |
|
2014 |
||
2015 |
disconnect(&eng, SIGNAL(signalHandlerException(QScriptValue)), |
|
2016 |
this, SLOT(onSignalHandlerException(QScriptValue))); |
|
2017 |
} |
|
2018 |
||
2019 |
// check that connectNotify() and disconnectNotify() are called (task 232987) |
|
2020 |
{ |
|
2021 |
m_myObject->clearConnectedSignal(); |
|
2022 |
QVERIFY(qScriptConnect(m_myObject, SIGNAL(mySignal()), QScriptValue(), fun)); |
|
2023 |
QCOMPARE(m_myObject->connectedSignal().constData(), SIGNAL(mySignal())); |
|
2024 |
||
2025 |
m_myObject->clearDisconnectedSignal(); |
|
2026 |
QVERIFY(qScriptDisconnect(m_myObject, SIGNAL(mySignal()), QScriptValue(), fun)); |
|
2027 |
QCOMPARE(m_myObject->disconnectedSignal().constData(), SIGNAL(mySignal())); |
|
2028 |
} |
|
2029 |
||
2030 |
// bad args |
|
2031 |
QVERIFY(!qScriptConnect(0, SIGNAL(foo()), QScriptValue(), fun)); |
|
2032 |
QVERIFY(!qScriptConnect(&edit, 0, QScriptValue(), fun)); |
|
2033 |
QVERIFY(!qScriptConnect(&edit, SIGNAL(foo()), QScriptValue(), fun)); |
|
2034 |
QVERIFY(!qScriptConnect(&edit, SIGNAL(textChanged(QString)), QScriptValue(), QScriptValue())); |
|
2035 |
QVERIFY(!qScriptDisconnect(0, SIGNAL(foo()), QScriptValue(), fun)); |
|
2036 |
QVERIFY(!qScriptDisconnect(&edit, 0, QScriptValue(), fun)); |
|
2037 |
QVERIFY(!qScriptDisconnect(&edit, SIGNAL(foo()), QScriptValue(), fun)); |
|
2038 |
QVERIFY(!qScriptDisconnect(&edit, SIGNAL(textChanged(QString)), QScriptValue(), QScriptValue())); |
|
2039 |
{ |
|
2040 |
QScriptEngine eng2; |
|
2041 |
QScriptValue receiverInDifferentEngine = eng2.newObject(); |
|
2042 |
QVERIFY(!qScriptConnect(&edit, SIGNAL(textChanged(QString)), receiverInDifferentEngine, fun)); |
|
2043 |
QVERIFY(!qScriptDisconnect(&edit, SIGNAL(textChanged(QString)), receiverInDifferentEngine, fun)); |
|
2044 |
} |
|
2045 |
} |
|
2046 |
||
2047 |
void tst_QScriptExtQObject::classEnums() |
|
2048 |
{ |
|
2049 |
QScriptValue myClass = m_engine->newQMetaObject(m_myObject->metaObject(), m_engine->undefinedValue()); |
|
2050 |
m_engine->globalObject().setProperty("MyQObject", myClass); |
|
2051 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2052 |
QVERIFY(m_engine->evaluate("MyQObject.FooPolicy").isNumber()); // no strong typing |
0 | 2053 |
QCOMPARE(static_cast<MyQObject::Policy>(m_engine->evaluate("MyQObject.FooPolicy").toInt32()), |
2054 |
MyQObject::FooPolicy); |
|
2055 |
QCOMPARE(static_cast<MyQObject::Policy>(m_engine->evaluate("MyQObject.BarPolicy").toInt32()), |
|
2056 |
MyQObject::BarPolicy); |
|
2057 |
QCOMPARE(static_cast<MyQObject::Policy>(m_engine->evaluate("MyQObject.BazPolicy").toInt32()), |
|
2058 |
MyQObject::BazPolicy); |
|
2059 |
||
2060 |
QCOMPARE(static_cast<MyQObject::Strategy>(m_engine->evaluate("MyQObject.FooStrategy").toInt32()), |
|
2061 |
MyQObject::FooStrategy); |
|
2062 |
QCOMPARE(static_cast<MyQObject::Strategy>(m_engine->evaluate("MyQObject.BarStrategy").toInt32()), |
|
2063 |
MyQObject::BarStrategy); |
|
2064 |
QCOMPARE(static_cast<MyQObject::Strategy>(m_engine->evaluate("MyQObject.BazStrategy").toInt32()), |
|
2065 |
MyQObject::BazStrategy); |
|
2066 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2067 |
QVERIFY(m_engine->evaluate("MyQObject.NoAbility").isNumber()); // no strong typing |
0 | 2068 |
QCOMPARE(MyQObject::Ability(m_engine->evaluate("MyQObject.NoAbility").toInt32()), |
2069 |
MyQObject::NoAbility); |
|
2070 |
QCOMPARE(MyQObject::Ability(m_engine->evaluate("MyQObject.FooAbility").toInt32()), |
|
2071 |
MyQObject::FooAbility); |
|
2072 |
QCOMPARE(MyQObject::Ability(m_engine->evaluate("MyQObject.BarAbility").toInt32()), |
|
2073 |
MyQObject::BarAbility); |
|
2074 |
QCOMPARE(MyQObject::Ability(m_engine->evaluate("MyQObject.BazAbility").toInt32()), |
|
2075 |
MyQObject::BazAbility); |
|
2076 |
QCOMPARE(MyQObject::Ability(m_engine->evaluate("MyQObject.AllAbility").toInt32()), |
|
2077 |
MyQObject::AllAbility); |
|
2078 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2079 |
// Constructors for flags are not provided |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2080 |
QVERIFY(m_engine->evaluate("MyQObject.Ability").isUndefined()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2081 |
|
0 | 2082 |
QScriptValue::PropertyFlags expectedEnumFlags = QScriptValue::ReadOnly | QScriptValue::Undeletable; |
2083 |
QCOMPARE(myClass.propertyFlags("FooPolicy"), expectedEnumFlags); |
|
2084 |
QCOMPARE(myClass.propertyFlags("BarPolicy"), expectedEnumFlags); |
|
2085 |
QCOMPARE(myClass.propertyFlags("BazPolicy"), expectedEnumFlags); |
|
2086 |
||
2087 |
// enums from Qt are inherited through prototype |
|
2088 |
QCOMPARE(static_cast<Qt::FocusPolicy>(m_engine->evaluate("MyQObject.StrongFocus").toInt32()), |
|
2089 |
Qt::StrongFocus); |
|
2090 |
QCOMPARE(static_cast<Qt::Key>(m_engine->evaluate("MyQObject.Key_Left").toInt32()), |
|
2091 |
Qt::Key_Left); |
|
2092 |
||
2093 |
QCOMPARE(m_engine->evaluate("MyQObject.className()").toString(), QLatin1String("MyQObject")); |
|
2094 |
||
2095 |
qRegisterMetaType<MyQObject::Policy>("Policy"); |
|
2096 |
||
2097 |
m_myObject->resetQtFunctionInvoked(); |
|
2098 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithEnumArg(MyQObject.BazPolicy)").isUndefined(), true); |
|
2099 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 10); |
|
2100 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
2101 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::BazPolicy)); |
|
2102 |
||
2103 |
m_myObject->resetQtFunctionInvoked(); |
|
2104 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithEnumArg('BarPolicy')").isUndefined(), true); |
|
2105 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 10); |
|
2106 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
2107 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::BarPolicy)); |
|
2108 |
||
2109 |
m_myObject->resetQtFunctionInvoked(); |
|
2110 |
QVERIFY(m_engine->evaluate("myObject.myInvokableWithEnumArg('NoSuchPolicy')").isError()); |
|
2111 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
2112 |
||
2113 |
m_myObject->resetQtFunctionInvoked(); |
|
2114 |
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithQualifiedEnumArg(MyQObject.BazPolicy)").isUndefined(), true); |
|
2115 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 36); |
|
2116 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
|
2117 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::BazPolicy)); |
|
2118 |
||
2119 |
m_myObject->resetQtFunctionInvoked(); |
|
2120 |
{ |
|
2121 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningEnum()"); |
|
2122 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 37); |
|
2123 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 0); |
|
2124 |
QCOMPARE(ret.isVariant(), true); |
|
2125 |
} |
|
2126 |
m_myObject->resetQtFunctionInvoked(); |
|
2127 |
{ |
|
2128 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningQualifiedEnum()"); |
|
2129 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 38); |
|
2130 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 0); |
|
2131 |
QCOMPARE(ret.isNumber(), true); |
|
2132 |
} |
|
2133 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2134 |
m_myObject->resetQtFunctionInvoked(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2135 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2136 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithFlagsArg(MyQObject.FooAbility)"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2137 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 58); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2138 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2139 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::FooAbility)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2140 |
QCOMPARE(ret.isNumber(), true); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2141 |
QCOMPARE(ret.toInt32(), int(MyQObject::FooAbility)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2142 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2143 |
m_myObject->resetQtFunctionInvoked(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2144 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2145 |
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQualifiedFlagsArg(MyQObject.BarAbility)"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2146 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 59); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2147 |
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2148 |
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::BarAbility)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2149 |
QCOMPARE(ret.isNumber(), true); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2150 |
QCOMPARE(ret.toInt32(), int(MyQObject::BarAbility)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2151 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2152 |
|
0 | 2153 |
// enum properties are not deletable or writable |
2154 |
QVERIFY(!m_engine->evaluate("delete MyQObject.BazPolicy").toBool()); |
|
2155 |
myClass.setProperty("BazPolicy", QScriptValue()); |
|
2156 |
QCOMPARE(static_cast<MyQObject::Policy>(myClass.property("BazPolicy").toInt32()), |
|
2157 |
MyQObject::BazPolicy); |
|
2158 |
myClass.setProperty("BazPolicy", MyQObject::FooPolicy); |
|
2159 |
QCOMPARE(static_cast<MyQObject::Policy>(myClass.property("BazPolicy").toInt32()), |
|
2160 |
MyQObject::BazPolicy); |
|
2161 |
} |
|
2162 |
||
2163 |
QT_BEGIN_NAMESPACE |
|
2164 |
Q_SCRIPT_DECLARE_QMETAOBJECT(MyQObject, QObject*) |
|
2165 |
Q_SCRIPT_DECLARE_QMETAOBJECT(QObject, QObject*) |
|
2166 |
QT_END_NAMESPACE |
|
2167 |
||
2168 |
class ConstructorTest : public QObject |
|
2169 |
{ |
|
2170 |
Q_OBJECT |
|
2171 |
public: |
|
2172 |
Q_INVOKABLE ConstructorTest(QObject *parent) |
|
2173 |
: QObject(parent) |
|
2174 |
{ |
|
2175 |
setProperty("ctorIndex", 0); |
|
2176 |
} |
|
2177 |
Q_INVOKABLE ConstructorTest(int arg, QObject *parent = 0) |
|
2178 |
: QObject(parent) |
|
2179 |
{ |
|
2180 |
setProperty("ctorIndex", 1); |
|
2181 |
setProperty("arg", arg); |
|
2182 |
} |
|
2183 |
Q_INVOKABLE ConstructorTest(const QString &arg, QObject *parent = 0) |
|
2184 |
: QObject(parent) |
|
2185 |
{ |
|
2186 |
setProperty("ctorIndex", 2); |
|
2187 |
setProperty("arg", arg); |
|
2188 |
} |
|
2189 |
Q_INVOKABLE ConstructorTest(int arg, const QString &arg2, QObject *parent = 0) |
|
2190 |
: QObject(parent) |
|
2191 |
{ |
|
2192 |
setProperty("ctorIndex", 3); |
|
2193 |
setProperty("arg", arg); |
|
2194 |
setProperty("arg2", arg2); |
|
2195 |
} |
|
2196 |
Q_INVOKABLE ConstructorTest(const QBrush &arg, QObject *parent = 0) |
|
2197 |
: QObject(parent) |
|
2198 |
{ |
|
2199 |
setProperty("ctorIndex", 4); |
|
2200 |
setProperty("arg", arg); |
|
2201 |
} |
|
2202 |
}; |
|
2203 |
||
2204 |
void tst_QScriptExtQObject::classConstructor() |
|
2205 |
{ |
|
2206 |
QScriptValue myClass = qScriptValueFromQMetaObject<MyQObject>(m_engine); |
|
2207 |
m_engine->globalObject().setProperty("MyQObject", myClass); |
|
2208 |
||
2209 |
QScriptValue myObj = m_engine->evaluate("myObj = MyQObject()"); |
|
2210 |
QObject *qobj = myObj.toQObject(); |
|
2211 |
QVERIFY(qobj != 0); |
|
2212 |
QCOMPARE(qobj->metaObject()->className(), "MyQObject"); |
|
2213 |
QCOMPARE(qobj->parent(), (QObject *)0); |
|
2214 |
||
2215 |
QScriptValue qobjectClass = qScriptValueFromQMetaObject<QObject>(m_engine); |
|
2216 |
m_engine->globalObject().setProperty("QObject", qobjectClass); |
|
2217 |
||
2218 |
QScriptValue otherObj = m_engine->evaluate("otherObj = QObject(myObj)"); |
|
2219 |
QObject *qqobj = otherObj.toQObject(); |
|
2220 |
QVERIFY(qqobj != 0); |
|
2221 |
QCOMPARE(qqobj->metaObject()->className(), "QObject"); |
|
2222 |
QCOMPARE(qqobj->parent(), qobj); |
|
2223 |
||
2224 |
delete qobj; |
|
2225 |
||
2226 |
// Q_INVOKABLE constructors |
|
2227 |
{ |
|
2228 |
QScriptValue klazz = m_engine->newQMetaObject(&ConstructorTest::staticMetaObject); |
|
2229 |
{ |
|
2230 |
QScriptValue obj = klazz.construct(); |
|
2231 |
QVERIFY(obj.isError()); |
|
2232 |
QCOMPARE(obj.toString(), QString::fromLatin1("SyntaxError: too few arguments in call to ConstructorTest(); candidates are\n" |
|
2233 |
" ConstructorTest(QBrush)\n" |
|
2234 |
" ConstructorTest(QBrush,QObject*)\n" |
|
2235 |
" ConstructorTest(int,QString)\n" |
|
2236 |
" ConstructorTest(int,QString,QObject*)\n" |
|
2237 |
" ConstructorTest(QString)\n" |
|
2238 |
" ConstructorTest(QString,QObject*)\n" |
|
2239 |
" ConstructorTest(int)\n" |
|
2240 |
" ConstructorTest(int,QObject*)\n" |
|
2241 |
" ConstructorTest(QObject*)")); |
|
2242 |
} |
|
2243 |
{ |
|
2244 |
QObject objobj; |
|
2245 |
QScriptValue arg = m_engine->newQObject(&objobj); |
|
2246 |
QScriptValue obj = klazz.construct(QScriptValueList() << arg); |
|
2247 |
QVERIFY(!obj.isError()); |
|
2248 |
QVERIFY(obj.instanceOf(klazz)); |
|
2249 |
QVERIFY(obj.property("ctorIndex").isNumber()); |
|
2250 |
QCOMPARE(obj.property("ctorIndex").toInt32(), 0); |
|
2251 |
} |
|
2252 |
{ |
|
2253 |
int arg = 123; |
|
2254 |
QScriptValue obj = klazz.construct(QScriptValueList() << arg); |
|
2255 |
QVERIFY(!obj.isError()); |
|
2256 |
QVERIFY(obj.instanceOf(klazz)); |
|
2257 |
QVERIFY(obj.property("ctorIndex").isNumber()); |
|
2258 |
QCOMPARE(obj.property("ctorIndex").toInt32(), 1); |
|
2259 |
QVERIFY(obj.property("arg").isNumber()); |
|
2260 |
QCOMPARE(obj.property("arg").toInt32(), arg); |
|
2261 |
} |
|
2262 |
{ |
|
2263 |
QString arg = "foo"; |
|
2264 |
QScriptValue obj = klazz.construct(QScriptValueList() << arg); |
|
2265 |
QVERIFY(!obj.isError()); |
|
2266 |
QVERIFY(obj.instanceOf(klazz)); |
|
2267 |
QVERIFY(obj.property("ctorIndex").isNumber()); |
|
2268 |
QCOMPARE(obj.property("ctorIndex").toInt32(), 2); |
|
2269 |
QVERIFY(obj.property("arg").isString()); |
|
2270 |
QCOMPARE(obj.property("arg").toString(), arg); |
|
2271 |
} |
|
2272 |
{ |
|
2273 |
int arg = 123; |
|
2274 |
QString arg2 = "foo"; |
|
2275 |
QScriptValue obj = klazz.construct(QScriptValueList() << arg << arg2); |
|
2276 |
QVERIFY(!obj.isError()); |
|
2277 |
QVERIFY(obj.instanceOf(klazz)); |
|
2278 |
QVERIFY(obj.property("ctorIndex").isNumber()); |
|
2279 |
QCOMPARE(obj.property("ctorIndex").toInt32(), 3); |
|
2280 |
QVERIFY(obj.property("arg").isNumber()); |
|
2281 |
QCOMPARE(obj.property("arg").toInt32(), arg); |
|
2282 |
QVERIFY(obj.property("arg2").isString()); |
|
2283 |
QCOMPARE(obj.property("arg2").toString(), arg2); |
|
2284 |
} |
|
2285 |
{ |
|
2286 |
QBrush arg(Qt::red); |
|
2287 |
QScriptValue obj = klazz.construct(QScriptValueList() << qScriptValueFromValue(m_engine, arg)); |
|
2288 |
QVERIFY(!obj.isError()); |
|
2289 |
QVERIFY(obj.instanceOf(klazz)); |
|
2290 |
QVERIFY(obj.property("ctorIndex").isNumber()); |
|
2291 |
QCOMPARE(obj.property("ctorIndex").toInt32(), 4); |
|
2292 |
QVERIFY(obj.property("arg").isVariant()); |
|
2293 |
QCOMPARE(qvariant_cast<QBrush>(obj.property("arg").toVariant()), arg); |
|
2294 |
} |
|
2295 |
{ |
|
2296 |
QDir arg; |
|
2297 |
QScriptValue obj = klazz.construct(QScriptValueList() |
|
2298 |
<< qScriptValueFromValue(m_engine, arg)); |
|
2299 |
QVERIFY(obj.isError()); |
|
2300 |
QCOMPARE(obj.toString(), QString::fromLatin1("TypeError: ambiguous call of overloaded function ConstructorTest(); candidates were\n" |
|
2301 |
" ConstructorTest(int)\n" |
|
2302 |
" ConstructorTest(QString)")); |
|
2303 |
} |
|
2304 |
} |
|
2305 |
} |
|
2306 |
||
2307 |
void tst_QScriptExtQObject::overrideInvokable() |
|
2308 |
{ |
|
2309 |
m_myObject->resetQtFunctionInvoked(); |
|
2310 |
m_engine->evaluate("myObject.myInvokable()"); |
|
2311 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 0); |
|
2312 |
||
2313 |
m_myObject->resetQtFunctionInvoked(); |
|
2314 |
m_engine->evaluate("myObject.myInvokable = function() { global.a = 123; }"); |
|
2315 |
m_engine->evaluate("myObject.myInvokable()"); |
|
2316 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
2317 |
QCOMPARE(m_engine->evaluate("global.a").toNumber(), 123.0); |
|
2318 |
||
2319 |
m_engine->evaluate("myObject.myInvokable = function() { global.a = 456; }"); |
|
2320 |
m_engine->evaluate("myObject.myInvokable()"); |
|
2321 |
QCOMPARE(m_myObject->qtFunctionInvoked(), -1); |
|
2322 |
QCOMPARE(m_engine->evaluate("global.a").toNumber(), 456.0); |
|
2323 |
||
2324 |
m_engine->evaluate("delete myObject.myInvokable"); |
|
2325 |
m_engine->evaluate("myObject.myInvokable()"); |
|
2326 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 0); |
|
2327 |
||
2328 |
m_myObject->resetQtFunctionInvoked(); |
|
2329 |
m_engine->evaluate("myObject.myInvokable = myObject.myInvokableWithIntArg"); |
|
2330 |
m_engine->evaluate("myObject.myInvokable(123)"); |
|
2331 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 1); |
|
2332 |
||
2333 |
m_engine->evaluate("delete myObject.myInvokable"); |
|
2334 |
m_myObject->resetQtFunctionInvoked(); |
|
2335 |
// this form (with the '()') is read-only |
|
2336 |
m_engine->evaluate("myObject['myInvokable()'] = function() { global.a = 123; }"); |
|
2337 |
m_engine->evaluate("myObject.myInvokable()"); |
|
2338 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 0); |
|
2339 |
} |
|
2340 |
||
2341 |
void tst_QScriptExtQObject::transferInvokable() |
|
2342 |
{ |
|
2343 |
m_myObject->resetQtFunctionInvoked(); |
|
2344 |
m_engine->evaluate("myObject.foozball = myObject.myInvokable"); |
|
2345 |
m_engine->evaluate("myObject.foozball()"); |
|
2346 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 0); |
|
2347 |
m_myObject->resetQtFunctionInvoked(); |
|
2348 |
m_engine->evaluate("myObject.foozball = myObject.myInvokableWithIntArg"); |
|
2349 |
m_engine->evaluate("myObject.foozball(123)"); |
|
2350 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 1); |
|
2351 |
m_myObject->resetQtFunctionInvoked(); |
|
2352 |
m_engine->evaluate("myObject.myInvokable = myObject.myInvokableWithIntArg"); |
|
2353 |
m_engine->evaluate("myObject.myInvokable(123)"); |
|
2354 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 1); |
|
2355 |
||
2356 |
MyOtherQObject other; |
|
2357 |
m_engine->globalObject().setProperty( |
|
2358 |
"myOtherObject", m_engine->newQObject(&other)); |
|
2359 |
m_engine->evaluate("myOtherObject.foo = myObject.foozball"); |
|
2360 |
other.resetQtFunctionInvoked(); |
|
2361 |
m_engine->evaluate("myOtherObject.foo(456)"); |
|
2362 |
QCOMPARE(other.qtFunctionInvoked(), 1); |
|
2363 |
} |
|
2364 |
||
2365 |
void tst_QScriptExtQObject::findChild() |
|
2366 |
{ |
|
2367 |
QObject *child = new QObject(m_myObject); |
|
2368 |
child->setObjectName(QLatin1String("myChildObject")); |
|
2369 |
||
2370 |
{ |
|
2371 |
QScriptValue result = m_engine->evaluate("myObject.findChild('noSuchChild')"); |
|
2372 |
QCOMPARE(result.isNull(), true); |
|
2373 |
} |
|
2374 |
||
2375 |
{ |
|
2376 |
QScriptValue result = m_engine->evaluate("myObject.findChild('myChildObject')"); |
|
2377 |
QCOMPARE(result.isQObject(), true); |
|
2378 |
QCOMPARE(result.toQObject(), child); |
|
2379 |
} |
|
2380 |
||
2381 |
delete child; |
|
2382 |
} |
|
2383 |
||
2384 |
void tst_QScriptExtQObject::findChildren() |
|
2385 |
{ |
|
2386 |
QObject *child = new QObject(m_myObject); |
|
2387 |
child->setObjectName(QLatin1String("myChildObject")); |
|
2388 |
||
2389 |
{ |
|
2390 |
QScriptValue result = m_engine->evaluate("myObject.findChildren('noSuchChild')"); |
|
2391 |
QCOMPARE(result.isArray(), true); |
|
2392 |
QCOMPARE(result.property(QLatin1String("length")).toNumber(), 0.0); |
|
2393 |
} |
|
2394 |
||
2395 |
{ |
|
2396 |
QScriptValue result = m_engine->evaluate("myObject.findChildren('myChildObject')"); |
|
2397 |
QCOMPARE(result.isArray(), true); |
|
2398 |
QCOMPARE(result.property(QLatin1String("length")).toNumber(), 1.0); |
|
2399 |
QCOMPARE(result.property(QLatin1String("0")).toQObject(), child); |
|
2400 |
} |
|
2401 |
||
2402 |
QObject *namelessChild = new QObject(m_myObject); |
|
2403 |
||
2404 |
{ |
|
2405 |
QScriptValue result = m_engine->evaluate("myObject.findChildren('myChildObject')"); |
|
2406 |
QCOMPARE(result.isArray(), true); |
|
2407 |
QCOMPARE(result.property(QLatin1String("length")).toNumber(), 1.0); |
|
2408 |
QCOMPARE(result.property(QLatin1String("0")).toQObject(), child); |
|
2409 |
} |
|
2410 |
||
2411 |
QObject *anotherChild = new QObject(m_myObject); |
|
2412 |
anotherChild->setObjectName(QLatin1String("anotherChildObject")); |
|
2413 |
||
2414 |
{ |
|
2415 |
QScriptValue result = m_engine->evaluate("myObject.findChildren('anotherChildObject')"); |
|
2416 |
QCOMPARE(result.isArray(), true); |
|
2417 |
QCOMPARE(result.property(QLatin1String("length")).toNumber(), 1.0); |
|
2418 |
QCOMPARE(result.property(QLatin1String("0")).toQObject(), anotherChild); |
|
2419 |
} |
|
2420 |
||
2421 |
anotherChild->setObjectName(QLatin1String("myChildObject")); |
|
2422 |
{ |
|
2423 |
QScriptValue result = m_engine->evaluate("myObject.findChildren('myChildObject')"); |
|
2424 |
QCOMPARE(result.isArray(), true); |
|
2425 |
QCOMPARE(result.property(QLatin1String("length")).toNumber(), 2.0); |
|
2426 |
QObject *o1 = result.property(QLatin1String("0")).toQObject(); |
|
2427 |
QObject *o2 = result.property(QLatin1String("1")).toQObject(); |
|
2428 |
if (o1 != child) { |
|
2429 |
QCOMPARE(o1, anotherChild); |
|
2430 |
QCOMPARE(o2, child); |
|
2431 |
} else { |
|
2432 |
QCOMPARE(o1, child); |
|
2433 |
QCOMPARE(o2, anotherChild); |
|
2434 |
} |
|
2435 |
} |
|
2436 |
||
2437 |
// find all |
|
2438 |
{ |
|
2439 |
QScriptValue result = m_engine->evaluate("myObject.findChildren()"); |
|
2440 |
QVERIFY(result.isArray()); |
|
2441 |
int count = 3; |
|
2442 |
QCOMPARE(result.property("length").toInt32(), count); |
|
2443 |
for (int i = 0; i < 3; ++i) { |
|
2444 |
QObject *o = result.property(i).toQObject(); |
|
2445 |
if (o == namelessChild || o == child || o == anotherChild) |
|
2446 |
--count; |
|
2447 |
} |
|
2448 |
QVERIFY(count == 0); |
|
2449 |
} |
|
2450 |
||
2451 |
// matchall regexp |
|
2452 |
{ |
|
2453 |
QScriptValue result = m_engine->evaluate("myObject.findChildren(/.*/)"); |
|
2454 |
QVERIFY(result.isArray()); |
|
2455 |
int count = 3; |
|
2456 |
QCOMPARE(result.property("length").toInt32(), count); |
|
2457 |
for (int i = 0; i < 3; ++i) { |
|
2458 |
QObject *o = result.property(i).toQObject(); |
|
2459 |
if (o == namelessChild || o == child || o == anotherChild) |
|
2460 |
--count; |
|
2461 |
} |
|
2462 |
QVERIFY(count == 0); |
|
2463 |
} |
|
2464 |
||
2465 |
// matchall regexp my* |
|
2466 |
{ |
|
2467 |
QScriptValue result = m_engine->evaluate("myObject.findChildren(new RegExp(\"^my.*\"))"); |
|
2468 |
QCOMPARE(result.isArray(), true); |
|
2469 |
QCOMPARE(result.property(QLatin1String("length")).toNumber(), 2.0); |
|
2470 |
QObject *o1 = result.property(QLatin1String("0")).toQObject(); |
|
2471 |
QObject *o2 = result.property(QLatin1String("1")).toQObject(); |
|
2472 |
if (o1 != child) { |
|
2473 |
QCOMPARE(o1, anotherChild); |
|
2474 |
QCOMPARE(o2, child); |
|
2475 |
} else { |
|
2476 |
QCOMPARE(o1, child); |
|
2477 |
QCOMPARE(o2, anotherChild); |
|
2478 |
} |
|
2479 |
} |
|
2480 |
delete anotherChild; |
|
2481 |
delete namelessChild; |
|
2482 |
delete child; |
|
2483 |
} |
|
2484 |
||
2485 |
void tst_QScriptExtQObject::overloadedSlots() |
|
2486 |
{ |
|
2487 |
// should pick myOverloadedSlot(double) |
|
2488 |
m_myObject->resetQtFunctionInvoked(); |
|
2489 |
m_engine->evaluate("myObject.myOverloadedSlot(10)"); |
|
2490 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 26); |
|
2491 |
||
2492 |
// should pick myOverloadedSlot(double) |
|
2493 |
m_myObject->resetQtFunctionInvoked(); |
|
2494 |
m_engine->evaluate("myObject.myOverloadedSlot(10.0)"); |
|
2495 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 26); |
|
2496 |
||
2497 |
// should pick myOverloadedSlot(QString) |
|
2498 |
m_myObject->resetQtFunctionInvoked(); |
|
2499 |
m_engine->evaluate("myObject.myOverloadedSlot('10')"); |
|
2500 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 29); |
|
2501 |
||
2502 |
// should pick myOverloadedSlot(bool) |
|
2503 |
m_myObject->resetQtFunctionInvoked(); |
|
2504 |
m_engine->evaluate("myObject.myOverloadedSlot(true)"); |
|
2505 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 25); |
|
2506 |
||
2507 |
// should pick myOverloadedSlot(QDateTime) |
|
2508 |
m_myObject->resetQtFunctionInvoked(); |
|
2509 |
m_engine->evaluate("myObject.myOverloadedSlot(new Date())"); |
|
2510 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 32); |
|
2511 |
||
2512 |
// should pick myOverloadedSlot(QRegExp) |
|
2513 |
m_myObject->resetQtFunctionInvoked(); |
|
2514 |
m_engine->evaluate("myObject.myOverloadedSlot(new RegExp())"); |
|
2515 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 34); |
|
2516 |
||
2517 |
// should pick myOverloadedSlot(QVariant) |
|
2518 |
m_myObject->resetQtFunctionInvoked(); |
|
2519 |
QScriptValue f = m_engine->evaluate("myObject.myOverloadedSlot"); |
|
2520 |
f.call(QScriptValue(), QScriptValueList() << m_engine->newVariant(QVariant("ciao"))); |
|
2521 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 35); |
|
2522 |
||
2523 |
// should pick myOverloadedSlot(QObject*) |
|
2524 |
m_myObject->resetQtFunctionInvoked(); |
|
2525 |
m_engine->evaluate("myObject.myOverloadedSlot(myObject)"); |
|
2526 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 41); |
|
2527 |
||
2528 |
// should pick myOverloadedSlot(QObject*) |
|
2529 |
m_myObject->resetQtFunctionInvoked(); |
|
2530 |
m_engine->evaluate("myObject.myOverloadedSlot(null)"); |
|
2531 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 41); |
|
2532 |
||
2533 |
// should pick myOverloadedSlot(QStringList) |
|
2534 |
m_myObject->resetQtFunctionInvoked(); |
|
2535 |
m_engine->evaluate("myObject.myOverloadedSlot(['hello'])"); |
|
2536 |
QCOMPARE(m_myObject->qtFunctionInvoked(), 42); |
|
2537 |
} |
|
2538 |
||
2539 |
void tst_QScriptExtQObject::enumerate_data() |
|
2540 |
{ |
|
2541 |
QTest::addColumn<int>("wrapOptions"); |
|
2542 |
QTest::addColumn<QStringList>("expectedNames"); |
|
2543 |
||
2544 |
QTest::newRow( "enumerate all" ) |
|
2545 |
<< 0 |
|
2546 |
<< (QStringList() |
|
2547 |
// meta-object-defined properties: |
|
2548 |
// inherited |
|
2549 |
<< "objectName" |
|
2550 |
// non-inherited |
|
2551 |
<< "p1" << "p2" << "p4" << "p6" |
|
2552 |
// dynamic properties |
|
2553 |
<< "dp1" << "dp2" << "dp3" |
|
2554 |
// inherited slots |
|
2555 |
<< "destroyed(QObject*)" << "destroyed()" |
|
2556 |
<< "deleteLater()" |
|
2557 |
// not included because it's private: |
|
2558 |
// << "_q_reregisterTimers(void*)" |
|
2559 |
// signals |
|
2560 |
<< "mySignal()" |
|
2561 |
// slots |
|
2562 |
<< "mySlot()" << "myOtherSlot()"); |
|
2563 |
||
2564 |
QTest::newRow( "don't enumerate inherited properties" ) |
|
2565 |
<< int(QScriptEngine::ExcludeSuperClassProperties) |
|
2566 |
<< (QStringList() |
|
2567 |
// meta-object-defined properties: |
|
2568 |
// non-inherited |
|
2569 |
<< "p1" << "p2" << "p4" << "p6" |
|
2570 |
// dynamic properties |
|
2571 |
<< "dp1" << "dp2" << "dp3" |
|
2572 |
// inherited slots |
|
2573 |
<< "destroyed(QObject*)" << "destroyed()" |
|
2574 |
<< "deleteLater()" |
|
2575 |
// not included because it's private: |
|
2576 |
// << "_q_reregisterTimers(void*)" |
|
2577 |
// signals |
|
2578 |
<< "mySignal()" |
|
2579 |
// slots |
|
2580 |
<< "mySlot()" << "myOtherSlot()"); |
|
2581 |
||
2582 |
QTest::newRow( "don't enumerate inherited methods" ) |
|
2583 |
<< int(QScriptEngine::ExcludeSuperClassMethods) |
|
2584 |
<< (QStringList() |
|
2585 |
// meta-object-defined properties: |
|
2586 |
// inherited |
|
2587 |
<< "objectName" |
|
2588 |
// non-inherited |
|
2589 |
<< "p1" << "p2" << "p4" << "p6" |
|
2590 |
// dynamic properties |
|
2591 |
<< "dp1" << "dp2" << "dp3" |
|
2592 |
// signals |
|
2593 |
<< "mySignal()" |
|
2594 |
// slots |
|
2595 |
<< "mySlot()" << "myOtherSlot()"); |
|
2596 |
||
2597 |
QTest::newRow( "don't enumerate inherited members" ) |
|
2598 |
<< int(QScriptEngine::ExcludeSuperClassMethods |
|
2599 |
| QScriptEngine::ExcludeSuperClassProperties) |
|
2600 |
<< (QStringList() |
|
2601 |
// meta-object-defined properties |
|
2602 |
<< "p1" << "p2" << "p4" << "p6" |
|
2603 |
// dynamic properties |
|
2604 |
<< "dp1" << "dp2" << "dp3" |
|
2605 |
// signals |
|
2606 |
<< "mySignal()" |
|
2607 |
// slots |
|
2608 |
<< "mySlot()" << "myOtherSlot()"); |
|
2609 |
||
2610 |
QTest::newRow( "enumerate properties, not methods" ) |
|
2611 |
<< int(QScriptEngine::SkipMethodsInEnumeration) |
|
2612 |
<< (QStringList() |
|
2613 |
// meta-object-defined properties: |
|
2614 |
// inherited |
|
2615 |
<< "objectName" |
|
2616 |
// non-inherited |
|
2617 |
<< "p1" << "p2" << "p4" << "p6" |
|
2618 |
// dynamic properties |
|
2619 |
<< "dp1" << "dp2" << "dp3"); |
|
2620 |
||
2621 |
QTest::newRow( "don't enumerate inherited properties + methods" ) |
|
2622 |
<< int(QScriptEngine::ExcludeSuperClassProperties |
|
2623 |
| QScriptEngine::SkipMethodsInEnumeration) |
|
2624 |
<< (QStringList() |
|
2625 |
// meta-object-defined properties: |
|
2626 |
// non-inherited |
|
2627 |
<< "p1" << "p2" << "p4" << "p6" |
|
2628 |
// dynamic properties |
|
2629 |
<< "dp1" << "dp2" << "dp3"); |
|
2630 |
||
2631 |
QTest::newRow( "don't enumerate inherited members" ) |
|
2632 |
<< int(QScriptEngine::ExcludeSuperClassContents) |
|
2633 |
<< (QStringList() |
|
2634 |
// meta-object-defined properties |
|
2635 |
<< "p1" << "p2" << "p4" << "p6" |
|
2636 |
// dynamic properties |
|
2637 |
<< "dp1" << "dp2" << "dp3" |
|
2638 |
// signals |
|
2639 |
<< "mySignal()" |
|
2640 |
// slots |
|
2641 |
<< "mySlot()" << "myOtherSlot()"); |
|
2642 |
||
2643 |
QTest::newRow( "don't enumerate deleteLater()" ) |
|
2644 |
<< int(QScriptEngine::ExcludeDeleteLater) |
|
2645 |
<< (QStringList() |
|
2646 |
// meta-object-defined properties: |
|
2647 |
// inherited |
|
2648 |
<< "objectName" |
|
2649 |
// non-inherited |
|
2650 |
<< "p1" << "p2" << "p4" << "p6" |
|
2651 |
// dynamic properties |
|
2652 |
<< "dp1" << "dp2" << "dp3" |
|
2653 |
// inherited slots |
|
2654 |
<< "destroyed(QObject*)" << "destroyed()" |
|
2655 |
// not included because it's private: |
|
2656 |
// << "_q_reregisterTimers(void*)" |
|
2657 |
// signals |
|
2658 |
<< "mySignal()" |
|
2659 |
// slots |
|
2660 |
<< "mySlot()" << "myOtherSlot()"); |
|
2661 |
} |
|
2662 |
||
2663 |
void tst_QScriptExtQObject::enumerate() |
|
2664 |
{ |
|
2665 |
QFETCH( int, wrapOptions ); |
|
2666 |
QFETCH( QStringList, expectedNames ); |
|
2667 |
||
2668 |
QScriptEngine eng; |
|
2669 |
MyEnumTestQObject enumQObject; |
|
2670 |
// give it some dynamic properties |
|
2671 |
enumQObject.setProperty("dp1", "dp1"); |
|
2672 |
enumQObject.setProperty("dp2", "dp2"); |
|
2673 |
enumQObject.setProperty("dp3", "dp3"); |
|
2674 |
QScriptValue obj = eng.newQObject(&enumQObject, QScriptEngine::QtOwnership, |
|
2675 |
QScriptEngine::QObjectWrapOptions(wrapOptions)); |
|
2676 |
||
2677 |
// enumerate in script |
|
2678 |
{ |
|
2679 |
eng.globalObject().setProperty("myEnumObject", obj); |
|
2680 |
eng.evaluate("var enumeratedProperties = []"); |
|
2681 |
eng.evaluate("for (var p in myEnumObject) { enumeratedProperties.push(p); }"); |
|
2682 |
QStringList result = qscriptvalue_cast<QStringList>(eng.evaluate("enumeratedProperties")); |
|
2683 |
QCOMPARE(result.size(), expectedNames.size()); |
|
2684 |
for (int i = 0; i < expectedNames.size(); ++i) |
|
2685 |
QCOMPARE(result.at(i), expectedNames.at(i)); |
|
2686 |
} |
|
2687 |
// enumerate in C++ |
|
2688 |
{ |
|
2689 |
QScriptValueIterator it(obj); |
|
2690 |
QStringList result; |
|
2691 |
while (it.hasNext()) { |
|
2692 |
it.next(); |
|
2693 |
QCOMPARE(it.flags(), obj.propertyFlags(it.name())); |
|
2694 |
result.append(it.name()); |
|
2695 |
} |
|
2696 |
QCOMPARE(result.size(), expectedNames.size()); |
|
2697 |
for (int i = 0; i < expectedNames.size(); ++i) |
|
2698 |
QCOMPARE(result.at(i), expectedNames.at(i)); |
|
2699 |
} |
|
2700 |
} |
|
2701 |
||
2702 |
class SpecialEnumTestObject : public QObject |
|
2703 |
{ |
|
2704 |
Q_OBJECT |
|
2705 |
// overriding a property in the super-class to make it non-scriptable |
|
2706 |
Q_PROPERTY(QString objectName READ objectName SCRIPTABLE false) |
|
2707 |
public: |
|
2708 |
SpecialEnumTestObject(QObject *parent = 0) |
|
2709 |
: QObject(parent) {} |
|
2710 |
}; |
|
2711 |
||
2712 |
class SpecialEnumTestObject2 : public QObject |
|
2713 |
{ |
|
2714 |
Q_OBJECT |
|
2715 |
// overriding a property in the super-class to make it non-designable (but still scriptable) |
|
2716 |
Q_PROPERTY(QString objectName READ objectName DESIGNABLE false) |
|
2717 |
public: |
|
2718 |
SpecialEnumTestObject2(QObject *parent = 0) |
|
2719 |
: QObject(parent) {} |
|
2720 |
}; |
|
2721 |
||
2722 |
void tst_QScriptExtQObject::enumerateSpecial() |
|
2723 |
{ |
|
2724 |
QScriptEngine eng; |
|
2725 |
{ |
|
2726 |
SpecialEnumTestObject testObj; |
|
2727 |
QScriptValueIterator it(eng.newQObject(&testObj)); |
|
2728 |
bool objectNameEncountered = false; |
|
2729 |
while (it.hasNext()) { |
|
2730 |
it.next(); |
|
2731 |
if (it.name() == QLatin1String("objectName")) { |
|
2732 |
objectNameEncountered = true; |
|
2733 |
break; |
|
2734 |
} |
|
2735 |
} |
|
2736 |
QVERIFY(!objectNameEncountered); |
|
2737 |
} |
|
2738 |
{ |
|
2739 |
SpecialEnumTestObject2 testObj; |
|
2740 |
testObj.setObjectName("foo"); |
|
2741 |
QScriptValueList values; |
|
2742 |
QScriptValueIterator it(eng.newQObject(&testObj)); |
|
2743 |
while (it.hasNext()) { |
|
2744 |
it.next(); |
|
2745 |
if (it.name() == "objectName") |
|
2746 |
values.append(it.value()); |
|
2747 |
} |
|
2748 |
QCOMPARE(values.size(), 1); |
|
2749 |
QCOMPARE(values.at(0).toString(), QString::fromLatin1("foo")); |
|
2750 |
} |
|
2751 |
} |
|
2752 |
||
2753 |
void tst_QScriptExtQObject::wrapOptions() |
|
2754 |
{ |
|
2755 |
QCOMPARE(m_myObject->setProperty("dynamicProperty", 123), false); |
|
2756 |
MyQObject *child = new MyQObject(m_myObject); |
|
2757 |
child->setObjectName("child"); |
|
2758 |
// exclude child objects |
|
2759 |
{ |
|
2760 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2761 |
QScriptEngine::ExcludeChildObjects); |
|
2762 |
QCOMPARE(obj.property("child").isValid(), false); |
|
2763 |
obj.setProperty("child", QScriptValue(m_engine, 123)); |
|
2764 |
QCOMPARE(obj.property("child") |
|
2765 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
2766 |
} |
|
2767 |
// don't auto-create dynamic properties |
|
2768 |
{ |
|
2769 |
QScriptValue obj = m_engine->newQObject(m_myObject); |
|
2770 |
QVERIFY(!m_myObject->dynamicPropertyNames().contains("anotherDynamicProperty")); |
|
2771 |
obj.setProperty("anotherDynamicProperty", QScriptValue(m_engine, 123)); |
|
2772 |
QVERIFY(!m_myObject->dynamicPropertyNames().contains("anotherDynamicProperty")); |
|
2773 |
QCOMPARE(obj.property("anotherDynamicProperty") |
|
2774 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
2775 |
} |
|
2776 |
// auto-create dynamic properties |
|
2777 |
{ |
|
2778 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2779 |
QScriptEngine::AutoCreateDynamicProperties); |
|
2780 |
QVERIFY(!m_myObject->dynamicPropertyNames().contains("anotherDynamicProperty")); |
|
2781 |
obj.setProperty("anotherDynamicProperty", QScriptValue(m_engine, 123)); |
|
2782 |
QVERIFY(m_myObject->dynamicPropertyNames().contains("anotherDynamicProperty")); |
|
2783 |
QCOMPARE(obj.property("anotherDynamicProperty") |
|
2784 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
2785 |
// task 236685 |
|
2786 |
{ |
|
2787 |
QScriptValue obj2 = m_engine->newObject(); |
|
2788 |
obj2.setProperty("notADynamicProperty", 456); |
|
2789 |
obj.setPrototype(obj2); |
|
2790 |
QScriptValue ret = obj.property("notADynamicProperty"); |
|
2791 |
QVERIFY(ret.isNumber()); |
|
2792 |
QVERIFY(ret.strictlyEquals(obj2.property("notADynamicProperty"))); |
|
2793 |
} |
|
2794 |
} |
|
2795 |
// don't exclude super-class properties |
|
2796 |
{ |
|
2797 |
QScriptValue obj = m_engine->newQObject(m_myObject); |
|
2798 |
QVERIFY(obj.property("objectName").isValid()); |
|
2799 |
QVERIFY(obj.propertyFlags("objectName") & QScriptValue::QObjectMember); |
|
2800 |
} |
|
2801 |
// exclude super-class properties |
|
2802 |
{ |
|
2803 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2804 |
QScriptEngine::ExcludeSuperClassProperties); |
|
2805 |
QVERIFY(!obj.property("objectName").isValid()); |
|
2806 |
QVERIFY(!(obj.propertyFlags("objectName") & QScriptValue::QObjectMember)); |
|
2807 |
QVERIFY(obj.property("intProperty").isValid()); |
|
2808 |
QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember); |
|
2809 |
} |
|
2810 |
// don't exclude super-class methods |
|
2811 |
{ |
|
2812 |
QScriptValue obj = m_engine->newQObject(m_myObject); |
|
2813 |
QVERIFY(obj.property("deleteLater").isValid()); |
|
2814 |
QVERIFY(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember); |
|
2815 |
} |
|
2816 |
// exclude super-class methods |
|
2817 |
{ |
|
2818 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2819 |
QScriptEngine::ExcludeSuperClassMethods); |
|
2820 |
QVERIFY(!obj.property("deleteLater").isValid()); |
|
2821 |
QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember)); |
|
2822 |
QVERIFY(obj.property("mySlot").isValid()); |
|
2823 |
QVERIFY(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember); |
|
2824 |
} |
|
2825 |
// exclude all super-class contents |
|
2826 |
{ |
|
2827 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2828 |
QScriptEngine::ExcludeSuperClassContents); |
|
2829 |
QVERIFY(!obj.property("deleteLater").isValid()); |
|
2830 |
QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember)); |
|
2831 |
QVERIFY(obj.property("mySlot").isValid()); |
|
2832 |
QVERIFY(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember); |
|
2833 |
||
2834 |
QVERIFY(!obj.property("objectName").isValid()); |
|
2835 |
QVERIFY(!(obj.propertyFlags("objectName") & QScriptValue::QObjectMember)); |
|
2836 |
QVERIFY(obj.property("intProperty").isValid()); |
|
2837 |
QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember); |
|
2838 |
} |
|
2839 |
// exclude deleteLater() |
|
2840 |
{ |
|
2841 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2842 |
QScriptEngine::ExcludeDeleteLater); |
|
2843 |
QVERIFY(!obj.property("deleteLater").isValid()); |
|
2844 |
QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember)); |
|
2845 |
QVERIFY(obj.property("mySlot").isValid()); |
|
2846 |
QVERIFY(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember); |
|
2847 |
||
2848 |
QVERIFY(obj.property("objectName").isValid()); |
|
2849 |
QVERIFY(obj.propertyFlags("objectName") & QScriptValue::QObjectMember); |
|
2850 |
QVERIFY(obj.property("intProperty").isValid()); |
|
2851 |
QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember); |
|
2852 |
} |
|
2853 |
// exclude all that we can |
|
2854 |
{ |
|
2855 |
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership, |
|
2856 |
QScriptEngine::ExcludeSuperClassMethods |
|
2857 |
| QScriptEngine::ExcludeSuperClassProperties |
|
2858 |
| QScriptEngine::ExcludeChildObjects); |
|
2859 |
QVERIFY(!obj.property("deleteLater").isValid()); |
|
2860 |
QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember)); |
|
2861 |
QVERIFY(obj.property("mySlot").isValid()); |
|
2862 |
QVERIFY(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember); |
|
2863 |
||
2864 |
QVERIFY(!obj.property("objectName").isValid()); |
|
2865 |
QVERIFY(!(obj.propertyFlags("objectName") & QScriptValue::QObjectMember)); |
|
2866 |
QVERIFY(obj.property("intProperty").isValid()); |
|
2867 |
QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember); |
|
2868 |
||
2869 |
QCOMPARE(obj.property("child").isValid(), false); |
|
2870 |
obj.setProperty("child", QScriptValue(m_engine, 123)); |
|
2871 |
QCOMPARE(obj.property("child") |
|
2872 |
.strictlyEquals(QScriptValue(m_engine, 123)), true); |
|
2873 |
} |
|
2874 |
||
2875 |
delete child; |
|
2876 |
} |
|
2877 |
||
2878 |
Q_DECLARE_METATYPE(QWidget*) |
|
2879 |
Q_DECLARE_METATYPE(QPushButton*) |
|
2880 |
||
2881 |
void tst_QScriptExtQObject::prototypes() |
|
2882 |
{ |
|
2883 |
QScriptEngine eng; |
|
2884 |
QScriptValue widgetProto = eng.newQObject(new QWidget(), QScriptEngine::ScriptOwnership); |
|
2885 |
eng.setDefaultPrototype(qMetaTypeId<QWidget*>(), widgetProto); |
|
2886 |
QPushButton *pbp = new QPushButton(); |
|
2887 |
QScriptValue buttonProto = eng.newQObject(pbp, QScriptEngine::ScriptOwnership); |
|
2888 |
buttonProto.setPrototype(widgetProto); |
|
2889 |
eng.setDefaultPrototype(qMetaTypeId<QPushButton*>(), buttonProto); |
|
2890 |
QPushButton *pb = new QPushButton(); |
|
2891 |
QScriptValue button = eng.newQObject(pb, QScriptEngine::ScriptOwnership); |
|
2892 |
QVERIFY(button.prototype().strictlyEquals(buttonProto)); |
|
2893 |
||
2894 |
buttonProto.setProperty("text", QScriptValue(&eng, "prototype button")); |
|
2895 |
QCOMPARE(pbp->text(), QLatin1String("prototype button")); |
|
2896 |
button.setProperty("text", QScriptValue(&eng, "not the prototype button")); |
|
2897 |
QCOMPARE(pb->text(), QLatin1String("not the prototype button")); |
|
2898 |
QCOMPARE(pbp->text(), QLatin1String("prototype button")); |
|
2899 |
||
2900 |
buttonProto.setProperty("objectName", QScriptValue(&eng, "prototype button")); |
|
2901 |
QCOMPARE(pbp->objectName(), QLatin1String("prototype button")); |
|
2902 |
button.setProperty("objectName", QScriptValue(&eng, "not the prototype button")); |
|
2903 |
QCOMPARE(pb->objectName(), QLatin1String("not the prototype button")); |
|
2904 |
QCOMPARE(pbp->objectName(), QLatin1String("prototype button")); |
|
2905 |
} |
|
2906 |
||
2907 |
void tst_QScriptExtQObject::objectDeleted() |
|
2908 |
{ |
|
2909 |
QScriptEngine eng; |
|
2910 |
MyQObject *qobj = new MyQObject(); |
|
2911 |
QScriptValue v = eng.newQObject(qobj); |
|
2912 |
v.setProperty("objectName", QScriptValue(&eng, "foo")); |
|
2913 |
QCOMPARE(qobj->objectName(), QLatin1String("foo")); |
|
2914 |
v.setProperty("intProperty", QScriptValue(&eng, 123)); |
|
2915 |
QCOMPARE(qobj->intProperty(), 123); |
|
2916 |
qobj->resetQtFunctionInvoked(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2917 |
QScriptValue invokable = v.property("myInvokable"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2918 |
invokable.call(v); |
0 | 2919 |
QCOMPARE(qobj->qtFunctionInvoked(), 0); |
2920 |
||
2921 |
// now delete the object |
|
2922 |
delete qobj; |
|
2923 |
||
2924 |
// the documented behavior is: isQObject() should still return true, |
|
2925 |
// but toQObject() should return 0 |
|
2926 |
QVERIFY(v.isQObject()); |
|
2927 |
QCOMPARE(v.toQObject(), (QObject *)0); |
|
2928 |
||
2929 |
// any attempt to access properties of the object should result in an exception |
|
2930 |
{ |
|
2931 |
QScriptValue ret = v.property("objectName"); |
|
2932 |
QVERIFY(ret.isError()); |
|
2933 |
QCOMPARE(ret.toString(), QLatin1String("Error: cannot access member `objectName' of deleted QObject")); |
|
2934 |
} |
|
2935 |
{ |
|
2936 |
eng.evaluate("Object"); |
|
2937 |
QVERIFY(!eng.hasUncaughtException()); |
|
2938 |
v.setProperty("objectName", QScriptValue(&eng, "foo")); |
|
2939 |
QVERIFY(eng.hasUncaughtException()); |
|
2940 |
QVERIFY(eng.uncaughtException().isError()); |
|
2941 |
QCOMPARE(eng.uncaughtException().toString(), QLatin1String("Error: cannot access member `objectName' of deleted QObject")); |
|
2942 |
} |
|
2943 |
||
2944 |
{ |
|
2945 |
QScriptValue ret = v.call(); |
|
2946 |
QVERIFY(!ret.isValid()); |
|
2947 |
} |
|
2948 |
||
2949 |
// myInvokableWithIntArg is not stored in member table (since we've not accessed it) |
|
2950 |
{ |
|
2951 |
QScriptValue ret = v.property("myInvokableWithIntArg"); |
|
2952 |
QVERIFY(ret.isError()); |
|
2953 |
QCOMPARE(ret.toString(), QLatin1String("Error: cannot access member `myInvokableWithIntArg' of deleted QObject")); |
|
2954 |
} |
|
2955 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2956 |
// Meta-method wrappers are still valid, but throw error when called |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2957 |
QVERIFY(invokable.isFunction()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2958 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2959 |
QScriptValue ret = invokable.call(v); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2960 |
QVERIFY(ret.isError()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2961 |
QCOMPARE(ret.toString(), QString::fromLatin1("Error: cannot call function of deleted QObject")); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2962 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2963 |
|
0 | 2964 |
// access from script |
2965 |
eng.globalObject().setProperty("o", v); |
|
2966 |
{ |
|
2967 |
QScriptValue ret = eng.evaluate("o()"); |
|
2968 |
QVERIFY(ret.isError()); |
|
2969 |
QCOMPARE(ret.toString(), QLatin1String("TypeError: Result of expression 'o' [] is not a function.")); |
|
2970 |
} |
|
2971 |
{ |
|
2972 |
QScriptValue ret = eng.evaluate("o.objectName"); |
|
2973 |
QVERIFY(ret.isError()); |
|
2974 |
QCOMPARE(ret.toString(), QLatin1String("Error: cannot access member `objectName' of deleted QObject")); |
|
2975 |
} |
|
2976 |
{ |
|
2977 |
QScriptValue ret = eng.evaluate("o.myInvokable()"); |
|
2978 |
QVERIFY(ret.isError()); |
|
2979 |
QCOMPARE(ret.toString(), QLatin1String("Error: cannot access member `myInvokable' of deleted QObject")); |
|
2980 |
} |
|
2981 |
{ |
|
2982 |
QScriptValue ret = eng.evaluate("o.myInvokableWithIntArg(10)"); |
|
2983 |
QVERIFY(ret.isError()); |
|
2984 |
QCOMPARE(ret.toString(), QLatin1String("Error: cannot access member `myInvokableWithIntArg' of deleted QObject")); |
|
2985 |
} |
|
2986 |
} |
|
2987 |
||
2988 |
void tst_QScriptExtQObject::connectToDestroyedSignal() |
|
2989 |
{ |
|
2990 |
// ### the following test currently depends on signal emission order |
|
2991 |
#if 0 |
|
2992 |
{ |
|
2993 |
// case 1: deleted when the engine is not doing GC |
|
2994 |
QScriptEngine eng; |
|
2995 |
QObject *obj = new QObject(); |
|
2996 |
eng.globalObject().setProperty("o", eng.newQObject(obj, QScriptEngine::QtOwnership)); |
|
2997 |
eng.evaluate("o.destroyed.connect(function() { wasDestroyed = true; })"); |
|
2998 |
eng.evaluate("wasDestroyed = false"); |
|
2999 |
delete obj; |
|
3000 |
QVERIFY(eng.evaluate("wasDestroyed").toBoolean()); |
|
3001 |
} |
|
3002 |
{ |
|
3003 |
// case 2: deleted when the engine is doing GC |
|
3004 |
QScriptEngine eng; |
|
3005 |
QObject *obj = new QObject(); |
|
3006 |
eng.globalObject().setProperty("o", eng.newQObject(obj, QScriptEngine::ScriptOwnership)); |
|
3007 |
eng.evaluate("o.destroyed.connect(function() { wasDestroyed = true; })"); |
|
3008 |
eng.evaluate("wasDestroyed = false"); |
|
3009 |
eng.evaluate("o = null"); |
|
3010 |
eng.collectGarbage(); |
|
3011 |
QVERIFY(eng.evaluate("wasDestroyed").toBoolean()); |
|
3012 |
} |
|
3013 |
{ |
|
3014 |
// case 3: deleted when the engine is destroyed |
|
3015 |
QScriptEngine eng; |
|
3016 |
QObject *obj = new QObject(); |
|
3017 |
eng.globalObject().setProperty("o", eng.newQObject(obj, QScriptEngine::ScriptOwnership)); |
|
3018 |
eng.evaluate("o.destroyed.connect(function() { })"); |
|
3019 |
// the signal handler won't get called -- we don't want to crash |
|
3020 |
} |
|
3021 |
#endif |
|
3022 |
} |
|
3023 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3024 |
void tst_QScriptExtQObject::emitAfterReceiverDeleted() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3025 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3026 |
for (int x = 0; x < 2; ++x) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3027 |
MyQObject *obj = new MyQObject; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3028 |
QScriptValue scriptObj = m_engine->newQObject(obj); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3029 |
if (x == 0) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3030 |
// Connecting from JS |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3031 |
m_engine->globalObject().setProperty("obj", scriptObj); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3032 |
QVERIFY(m_engine->evaluate("myObject.mySignal.connect(obj, 'mySlot()')").isUndefined()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3033 |
} else { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3034 |
// Connecting from C++ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3035 |
qScriptConnect(m_myObject, SIGNAL(mySignal()), scriptObj, scriptObj.property("mySlot")); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3036 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3037 |
delete obj; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3038 |
QSignalSpy signalHandlerExceptionSpy(m_engine, SIGNAL(signalHandlerException(QScriptValue))); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3039 |
QVERIFY(!m_engine->hasUncaughtException()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3040 |
m_myObject->emitMySignal(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3041 |
QCOMPARE(signalHandlerExceptionSpy.count(), 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3042 |
QVERIFY(!m_engine->hasUncaughtException()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3043 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3044 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3045 |
|
0 | 3046 |
QTEST_MAIN(tst_QScriptExtQObject) |
3047 |
#include "tst_qscriptextqobject.moc" |