|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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 #ifndef TST_QSCRIPTVALUE_H |
|
43 #define TST_QSCRIPTVALUE_H |
|
44 |
|
45 #include <QtCore/qobject.h> |
|
46 #include <QtCore/qnumeric.h> |
|
47 #include <QtScript/qscriptclass.h> |
|
48 #include <QtScript/qscriptengine.h> |
|
49 #include <QtScript/qscriptvalue.h> |
|
50 #include <QtTest/QtTest> |
|
51 |
|
52 Q_DECLARE_METATYPE(QVariant) |
|
53 Q_DECLARE_METATYPE(QScriptValue) |
|
54 |
|
55 class tst_QScriptValue : public QObject |
|
56 { |
|
57 Q_OBJECT |
|
58 |
|
59 public: |
|
60 tst_QScriptValue(); |
|
61 virtual ~tst_QScriptValue(); |
|
62 |
|
63 private slots: |
|
64 // Generated test functions |
|
65 void isArray_data(); |
|
66 void isArray(); |
|
67 |
|
68 void isBool_data(); |
|
69 void isBool(); |
|
70 |
|
71 void isBoolean_data(); |
|
72 void isBoolean(); |
|
73 |
|
74 void isDate_data(); |
|
75 void isDate(); |
|
76 |
|
77 void isError_data(); |
|
78 void isError(); |
|
79 |
|
80 void isFunction_data(); |
|
81 void isFunction(); |
|
82 |
|
83 void isNull_data(); |
|
84 void isNull(); |
|
85 |
|
86 void isNumber_data(); |
|
87 void isNumber(); |
|
88 |
|
89 void isObject_data(); |
|
90 void isObject(); |
|
91 |
|
92 // void isQMetaObject_data(); |
|
93 // void isQMetaObject(); |
|
94 |
|
95 // void isQObject_data(); |
|
96 // void isQObject(); |
|
97 |
|
98 void isRegExp_data(); |
|
99 void isRegExp(); |
|
100 |
|
101 void isString_data(); |
|
102 void isString(); |
|
103 |
|
104 void isUndefined_data(); |
|
105 void isUndefined(); |
|
106 |
|
107 void isValid_data(); |
|
108 void isValid(); |
|
109 |
|
110 // void isVariant_data(); |
|
111 // void isVariant(); |
|
112 |
|
113 void toBool_data(); |
|
114 void toBool(); |
|
115 |
|
116 void toBoolean_data(); |
|
117 void toBoolean(); |
|
118 |
|
119 // void toDateTime_data(); |
|
120 // void toDateTime(); |
|
121 |
|
122 void toInt32_data(); |
|
123 void toInt32(); |
|
124 |
|
125 void toInteger_data(); |
|
126 void toInteger(); |
|
127 |
|
128 void toNumber_data(); |
|
129 void toNumber(); |
|
130 |
|
131 // void toQMetaObject_data(); |
|
132 // void toQMetaObject(); |
|
133 |
|
134 // void toQObject_data(); |
|
135 // void toQObject(); |
|
136 |
|
137 // void toRegExp_data(); |
|
138 // void toRegExp(); |
|
139 |
|
140 void toString_data(); |
|
141 void toString(); |
|
142 |
|
143 void toUInt16_data(); |
|
144 void toUInt16(); |
|
145 |
|
146 void toUInt32_data(); |
|
147 void toUInt32(); |
|
148 |
|
149 // void toVariant_data(); |
|
150 // void toVariant(); |
|
151 |
|
152 void equals_data(); |
|
153 void equals(); |
|
154 |
|
155 void strictlyEquals_data(); |
|
156 void strictlyEquals(); |
|
157 |
|
158 void lessThan_data(); |
|
159 void lessThan(); |
|
160 |
|
161 void instanceOf_data(); |
|
162 void instanceOf(); |
|
163 |
|
164 void assignAndCopyConstruct_data(); |
|
165 void assignAndCopyConstruct(); |
|
166 |
|
167 void qscriptvalue_castQString_data(); |
|
168 void qscriptvalue_castQString(); |
|
169 |
|
170 void qscriptvalue_castqsreal_data(); |
|
171 void qscriptvalue_castqsreal(); |
|
172 |
|
173 void qscriptvalue_castbool_data(); |
|
174 void qscriptvalue_castbool(); |
|
175 |
|
176 void qscriptvalue_castqint32_data(); |
|
177 void qscriptvalue_castqint32(); |
|
178 |
|
179 void qscriptvalue_castquint32_data(); |
|
180 void qscriptvalue_castquint32(); |
|
181 |
|
182 void qscriptvalue_castquint16_data(); |
|
183 void qscriptvalue_castquint16(); |
|
184 |
|
185 // Non-generated test functions |
|
186 |
|
187 void toObject(); |
|
188 void ctor(); |
|
189 |
|
190 void toString_old(); |
|
191 void toNumber_old(); |
|
192 void toBoolean_old(); |
|
193 void toBool_old(); |
|
194 void toInteger_old(); |
|
195 void toInt32_old(); |
|
196 void toUInt32_old(); |
|
197 void toUInt16_old(); |
|
198 void toVariant_old(); |
|
199 void toQObject_old(); |
|
200 void toDateTime_old(); |
|
201 void toRegExp_old(); |
|
202 void instanceOf_old(); |
|
203 void isArray_old(); |
|
204 void isDate_old(); |
|
205 void isError_old(); |
|
206 void isRegExp_old(); |
|
207 |
|
208 void lessThan_old(); |
|
209 void equals_old(); |
|
210 void strictlyEquals_old(); |
|
211 |
|
212 void getSetPrototype(); |
|
213 void getSetScope(); |
|
214 void getSetProperty(); |
|
215 void arrayElementGetterSetter(); |
|
216 void getSetData(); |
|
217 void getSetScriptClass(); |
|
218 void call(); |
|
219 void construct(); |
|
220 void castToPointer(); |
|
221 void prettyPrinter_data(); |
|
222 void prettyPrinter(); |
|
223 void engineDeleted(); |
|
224 void valueOfWithClosure(); |
|
225 void objectId(); |
|
226 |
|
227 private: |
|
228 typedef void (tst_QScriptValue::*InitDataFunction)(); |
|
229 typedef void (tst_QScriptValue::*DefineDataFunction)(const char *); |
|
230 void dataHelper(InitDataFunction init, DefineDataFunction define); |
|
231 QTestData &newRow(const char *tag); |
|
232 |
|
233 typedef void (tst_QScriptValue::*TestFunction)(const char *, const QScriptValue &); |
|
234 void testHelper(TestFunction fun); |
|
235 |
|
236 // Generated functions |
|
237 |
|
238 void initScriptValues(); |
|
239 |
|
240 void isArray_initData(); |
|
241 void isArray_makeData(const char *expr); |
|
242 void isArray_test(const char *expr, const QScriptValue &value); |
|
243 |
|
244 void isBool_initData(); |
|
245 void isBool_makeData(const char *expr); |
|
246 void isBool_test(const char *expr, const QScriptValue &value); |
|
247 |
|
248 void isBoolean_initData(); |
|
249 void isBoolean_makeData(const char *expr); |
|
250 void isBoolean_test(const char *expr, const QScriptValue &value); |
|
251 |
|
252 void isDate_initData(); |
|
253 void isDate_makeData(const char *expr); |
|
254 void isDate_test(const char *expr, const QScriptValue &value); |
|
255 |
|
256 void isError_initData(); |
|
257 void isError_makeData(const char *expr); |
|
258 void isError_test(const char *expr, const QScriptValue &value); |
|
259 |
|
260 void isFunction_initData(); |
|
261 void isFunction_makeData(const char *expr); |
|
262 void isFunction_test(const char *expr, const QScriptValue &value); |
|
263 |
|
264 void isNull_initData(); |
|
265 void isNull_makeData(const char *expr); |
|
266 void isNull_test(const char *expr, const QScriptValue &value); |
|
267 |
|
268 void isNumber_initData(); |
|
269 void isNumber_makeData(const char *expr); |
|
270 void isNumber_test(const char *expr, const QScriptValue &value); |
|
271 |
|
272 void isObject_initData(); |
|
273 void isObject_makeData(const char *expr); |
|
274 void isObject_test(const char *expr, const QScriptValue &value); |
|
275 |
|
276 void isQMetaObject_initData(); |
|
277 void isQMetaObject_makeData(const char *expr); |
|
278 void isQMetaObject_test(const char *expr, const QScriptValue &value); |
|
279 |
|
280 void isQObject_initData(); |
|
281 void isQObject_makeData(const char *expr); |
|
282 void isQObject_test(const char *expr, const QScriptValue &value); |
|
283 |
|
284 void isRegExp_initData(); |
|
285 void isRegExp_makeData(const char *expr); |
|
286 void isRegExp_test(const char *expr, const QScriptValue &value); |
|
287 |
|
288 void isString_initData(); |
|
289 void isString_makeData(const char *expr); |
|
290 void isString_test(const char *expr, const QScriptValue &value); |
|
291 |
|
292 void isUndefined_initData(); |
|
293 void isUndefined_makeData(const char *expr); |
|
294 void isUndefined_test(const char *expr, const QScriptValue &value); |
|
295 |
|
296 void isValid_initData(); |
|
297 void isValid_makeData(const char *expr); |
|
298 void isValid_test(const char *expr, const QScriptValue &value); |
|
299 |
|
300 void isVariant_initData(); |
|
301 void isVariant_makeData(const char *expr); |
|
302 void isVariant_test(const char *expr, const QScriptValue &value); |
|
303 |
|
304 void toBool_initData(); |
|
305 void toBool_makeData(const char *); |
|
306 void toBool_test(const char *, const QScriptValue &value); |
|
307 |
|
308 void toBoolean_initData(); |
|
309 void toBoolean_makeData(const char *); |
|
310 void toBoolean_test(const char *, const QScriptValue &value); |
|
311 |
|
312 void toDateTime_initData(); |
|
313 void toDateTime_makeData(const char *); |
|
314 void toDateTime_test(const char *, const QScriptValue &value); |
|
315 |
|
316 void toInt32_initData(); |
|
317 void toInt32_makeData(const char *); |
|
318 void toInt32_test(const char *, const QScriptValue &value); |
|
319 |
|
320 void toInteger_initData(); |
|
321 void toInteger_makeData(const char *); |
|
322 void toInteger_test(const char *, const QScriptValue &value); |
|
323 |
|
324 void toNumber_initData(); |
|
325 void toNumber_makeData(const char *); |
|
326 void toNumber_test(const char *, const QScriptValue &value); |
|
327 |
|
328 void toQMetaObject_initData(); |
|
329 void toQMetaObject_makeData(const char *); |
|
330 void toQMetaObject_test(const char *, const QScriptValue &value); |
|
331 |
|
332 void toQObject_initData(); |
|
333 void toQObject_makeData(const char *); |
|
334 void toQObject_test(const char *, const QScriptValue &value); |
|
335 |
|
336 void toRegExp_initData(); |
|
337 void toRegExp_makeData(const char *); |
|
338 void toRegExp_test(const char *, const QScriptValue &value); |
|
339 |
|
340 void toString_initData(); |
|
341 void toString_makeData(const char *); |
|
342 void toString_test(const char *, const QScriptValue &value); |
|
343 |
|
344 void toUInt16_initData(); |
|
345 void toUInt16_makeData(const char *); |
|
346 void toUInt16_test(const char *, const QScriptValue &value); |
|
347 |
|
348 void toUInt32_initData(); |
|
349 void toUInt32_makeData(const char *); |
|
350 void toUInt32_test(const char *, const QScriptValue &value); |
|
351 |
|
352 void toVariant_initData(); |
|
353 void toVariant_makeData(const char *); |
|
354 void toVariant_test(const char *, const QScriptValue &value); |
|
355 |
|
356 void equals_initData(); |
|
357 void equals_makeData(const char *); |
|
358 void equals_test(const char *, const QScriptValue &value); |
|
359 |
|
360 void strictlyEquals_initData(); |
|
361 void strictlyEquals_makeData(const char *); |
|
362 void strictlyEquals_test(const char *, const QScriptValue &value); |
|
363 |
|
364 void lessThan_initData(); |
|
365 void lessThan_makeData(const char *); |
|
366 void lessThan_test(const char *, const QScriptValue &value); |
|
367 |
|
368 void instanceOf_initData(); |
|
369 void instanceOf_makeData(const char *); |
|
370 void instanceOf_test(const char *, const QScriptValue &value); |
|
371 |
|
372 void assignAndCopyConstruct_initData(); |
|
373 void assignAndCopyConstruct_makeData(const char *); |
|
374 void assignAndCopyConstruct_test(const char *, const QScriptValue &value); |
|
375 |
|
376 void qscriptvalue_castQString_initData(); |
|
377 void qscriptvalue_castQString_makeData(const char *); |
|
378 void qscriptvalue_castQString_test(const char *, const QScriptValue &value); |
|
379 |
|
380 void qscriptvalue_castqsreal_initData(); |
|
381 void qscriptvalue_castqsreal_makeData(const char *); |
|
382 void qscriptvalue_castqsreal_test(const char *, const QScriptValue &value); |
|
383 |
|
384 void qscriptvalue_castbool_initData(); |
|
385 void qscriptvalue_castbool_makeData(const char *); |
|
386 void qscriptvalue_castbool_test(const char *, const QScriptValue &value); |
|
387 |
|
388 void qscriptvalue_castqint32_initData(); |
|
389 void qscriptvalue_castqint32_makeData(const char *); |
|
390 void qscriptvalue_castqint32_test(const char *, const QScriptValue &value); |
|
391 |
|
392 void qscriptvalue_castquint32_initData(); |
|
393 void qscriptvalue_castquint32_makeData(const char *); |
|
394 void qscriptvalue_castquint32_test(const char *, const QScriptValue &value); |
|
395 |
|
396 void qscriptvalue_castquint16_initData(); |
|
397 void qscriptvalue_castquint16_makeData(const char *); |
|
398 void qscriptvalue_castquint16_test(const char *, const QScriptValue &value); |
|
399 |
|
400 private: |
|
401 QScriptEngine *engine; |
|
402 QHash<QString, QScriptValue> m_values; |
|
403 QString m_currentExpression; |
|
404 }; |
|
405 |
|
406 #define DEFINE_TEST_FUNCTION(name) \ |
|
407 void tst_QScriptValue::name##_data() { dataHelper(&tst_QScriptValue::name##_initData, &tst_QScriptValue::name##_makeData); } \ |
|
408 void tst_QScriptValue::name() { testHelper(&tst_QScriptValue::name##_test); } |
|
409 |
|
410 #endif |