1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 #define DEFINE_TEST_VALUE(expr) m_values.insert(QString::fromLatin1(#expr), expr)
53 
54 Q_DECLARE_METATYPE(QVariant)
Q_DECLARE_METATYPE(QScriptValue)55 Q_DECLARE_METATYPE(QScriptValue)
56 
57 class tst_QScriptValueGenerated : public QObject
58 {
59     Q_OBJECT
60 
61 public:
62     tst_QScriptValueGenerated();
63     virtual ~tst_QScriptValueGenerated();
64 
65 private slots:
66     // Generated test functions
67     void isArray_data();
68     void isArray();
69 
70     void isBool_data();
71     void isBool();
72 
73     void isBoolean_data();
74     void isBoolean();
75 
76     void isDate_data();
77     void isDate();
78 
79     void isError_data();
80     void isError();
81 
82     void isFunction_data();
83     void isFunction();
84 
85     void isNull_data();
86     void isNull();
87 
88     void isNumber_data();
89     void isNumber();
90 
91     void isObject_data();
92     void isObject();
93 
94     void isQMetaObject_data();
95     void isQMetaObject();
96 
97     void isQObject_data();
98     void isQObject();
99 
100     void isRegExp_data();
101     void isRegExp();
102 
103     void isString_data();
104     void isString();
105 
106     void isUndefined_data();
107     void isUndefined();
108 
109     void isValid_data();
110     void isValid();
111 
112     void isVariant_data();
113     void isVariant();
114 
115     void toBool_data();
116     void toBool();
117 
118     void toBoolean_data();
119     void toBoolean();
120 
121 //    void toDateTime_data();
122 //    void toDateTime();
123 
124     void toInt32_data();
125     void toInt32();
126 
127     void toInteger_data();
128     void toInteger();
129 
130     void toNumber_data();
131     void toNumber();
132 
133 //    void toQMetaObject_data();
134 //    void toQMetaObject();
135 
136 //    void toQObject_data();
137 //    void toQObject();
138 
139 //    void toRegExp_data();
140 //    void toRegExp();
141 
142     void toString_data();
143     void toString();
144 
145     void toUInt16_data();
146     void toUInt16();
147 
148     void toUInt32_data();
149     void toUInt32();
150 
151 //    void toVariant_data();
152 //    void toVariant();
153 
154     void equals_data();
155     void equals();
156 
157     void strictlyEquals_data();
158     void strictlyEquals();
159 
160     void lessThan_data();
161     void lessThan();
162 
163     void instanceOf_data();
164     void instanceOf();
165 
166     void assignAndCopyConstruct_data();
167     void assignAndCopyConstruct();
168 
169     void qscriptvalue_castQString_data();
170     void qscriptvalue_castQString();
171 
172     void qscriptvalue_castqsreal_data();
173     void qscriptvalue_castqsreal();
174 
175     void qscriptvalue_castbool_data();
176     void qscriptvalue_castbool();
177 
178     void qscriptvalue_castqint32_data();
179     void qscriptvalue_castqint32();
180 
181     void qscriptvalue_castquint32_data();
182     void qscriptvalue_castquint32();
183 
184     void qscriptvalue_castquint16_data();
185     void qscriptvalue_castquint16();
186 
187 private:
188     typedef void (tst_QScriptValueGenerated::*InitDataFunction)();
189     typedef void (tst_QScriptValueGenerated::*DefineDataFunction)(const char *);
190     void dataHelper(InitDataFunction init, DefineDataFunction define);
191     QTestData &newRow(const char *tag);
192 
193     typedef void (tst_QScriptValueGenerated::*TestFunction)(const char *, const QScriptValue &);
194     void testHelper(TestFunction fun);
195 
196     // Generated functions
197 
198     void initScriptValues();
199 
200     void isArray_initData();
201     void isArray_makeData(const char *expr);
202     void isArray_test(const char *expr, const QScriptValue &value);
203 
204     void isBool_initData();
205     void isBool_makeData(const char *expr);
206     void isBool_test(const char *expr, const QScriptValue &value);
207 
208     void isBoolean_initData();
209     void isBoolean_makeData(const char *expr);
210     void isBoolean_test(const char *expr, const QScriptValue &value);
211 
212     void isDate_initData();
213     void isDate_makeData(const char *expr);
214     void isDate_test(const char *expr, const QScriptValue &value);
215 
216     void isError_initData();
217     void isError_makeData(const char *expr);
218     void isError_test(const char *expr, const QScriptValue &value);
219 
220     void isFunction_initData();
221     void isFunction_makeData(const char *expr);
222     void isFunction_test(const char *expr, const QScriptValue &value);
223 
224     void isNull_initData();
225     void isNull_makeData(const char *expr);
226     void isNull_test(const char *expr, const QScriptValue &value);
227 
228     void isNumber_initData();
229     void isNumber_makeData(const char *expr);
230     void isNumber_test(const char *expr, const QScriptValue &value);
231 
232     void isObject_initData();
233     void isObject_makeData(const char *expr);
234     void isObject_test(const char *expr, const QScriptValue &value);
235 
236     void isQMetaObject_initData();
237     void isQMetaObject_makeData(const char *expr);
238     void isQMetaObject_test(const char *expr, const QScriptValue &value);
239 
240     void isQObject_initData();
241     void isQObject_makeData(const char *expr);
242     void isQObject_test(const char *expr, const QScriptValue &value);
243 
244     void isRegExp_initData();
245     void isRegExp_makeData(const char *expr);
246     void isRegExp_test(const char *expr, const QScriptValue &value);
247 
248     void isString_initData();
249     void isString_makeData(const char *expr);
250     void isString_test(const char *expr, const QScriptValue &value);
251 
252     void isUndefined_initData();
253     void isUndefined_makeData(const char *expr);
254     void isUndefined_test(const char *expr, const QScriptValue &value);
255 
256     void isValid_initData();
257     void isValid_makeData(const char *expr);
258     void isValid_test(const char *expr, const QScriptValue &value);
259 
260     void isVariant_initData();
261     void isVariant_makeData(const char *expr);
262     void isVariant_test(const char *expr, const QScriptValue &value);
263 
264     void toBool_initData();
265     void toBool_makeData(const char *);
266     void toBool_test(const char *, const QScriptValue &value);
267 
268     void toBoolean_initData();
269     void toBoolean_makeData(const char *);
270     void toBoolean_test(const char *, const QScriptValue &value);
271 
272     void toDateTime_initData();
273     void toDateTime_makeData(const char *);
274     void toDateTime_test(const char *, const QScriptValue &value);
275 
276     void toInt32_initData();
277     void toInt32_makeData(const char *);
278     void toInt32_test(const char *, const QScriptValue &value);
279 
280     void toInteger_initData();
281     void toInteger_makeData(const char *);
282     void toInteger_test(const char *, const QScriptValue &value);
283 
284     void toNumber_initData();
285     void toNumber_makeData(const char *);
286     void toNumber_test(const char *, const QScriptValue &value);
287 
288     void toQMetaObject_initData();
289     void toQMetaObject_makeData(const char *);
290     void toQMetaObject_test(const char *, const QScriptValue &value);
291 
292     void toQObject_initData();
293     void toQObject_makeData(const char *);
294     void toQObject_test(const char *, const QScriptValue &value);
295 
296     void toRegExp_initData();
297     void toRegExp_makeData(const char *);
298     void toRegExp_test(const char *, const QScriptValue &value);
299 
300     void toString_initData();
301     void toString_makeData(const char *);
302     void toString_test(const char *, const QScriptValue &value);
303 
304     void toUInt16_initData();
305     void toUInt16_makeData(const char *);
306     void toUInt16_test(const char *, const QScriptValue &value);
307 
308     void toUInt32_initData();
309     void toUInt32_makeData(const char *);
310     void toUInt32_test(const char *, const QScriptValue &value);
311 
312     void toVariant_initData();
313     void toVariant_makeData(const char *);
314     void toVariant_test(const char *, const QScriptValue &value);
315 
316     void equals_initData();
317     void equals_makeData(const char *);
318     void equals_test(const char *, const QScriptValue &value);
319 
320     void strictlyEquals_initData();
321     void strictlyEquals_makeData(const char *);
322     void strictlyEquals_test(const char *, const QScriptValue &value);
323 
324     void lessThan_initData();
325     void lessThan_makeData(const char *);
326     void lessThan_test(const char *, const QScriptValue &value);
327 
328     void instanceOf_initData();
329     void instanceOf_makeData(const char *);
330     void instanceOf_test(const char *, const QScriptValue &value);
331 
332     void assignAndCopyConstruct_initData();
333     void assignAndCopyConstruct_makeData(const char *);
334     void assignAndCopyConstruct_test(const char *, const QScriptValue &value);
335 
336     void qscriptvalue_castQString_initData();
337     void qscriptvalue_castQString_makeData(const char *);
338     void qscriptvalue_castQString_test(const char *, const QScriptValue &value);
339 
340     void qscriptvalue_castqsreal_initData();
341     void qscriptvalue_castqsreal_makeData(const char *);
342     void qscriptvalue_castqsreal_test(const char *, const QScriptValue &value);
343 
344     void qscriptvalue_castbool_initData();
345     void qscriptvalue_castbool_makeData(const char *);
346     void qscriptvalue_castbool_test(const char *, const QScriptValue &value);
347 
348     void qscriptvalue_castqint32_initData();
349     void qscriptvalue_castqint32_makeData(const char *);
350     void qscriptvalue_castqint32_test(const char *, const QScriptValue &value);
351 
352     void qscriptvalue_castquint32_initData();
353     void qscriptvalue_castquint32_makeData(const char *);
354     void qscriptvalue_castquint32_test(const char *, const QScriptValue &value);
355 
356     void qscriptvalue_castquint16_initData();
357     void qscriptvalue_castquint16_makeData(const char *);
358     void qscriptvalue_castquint16_test(const char *, const QScriptValue &value);
359 
360 private:
361     QScriptEngine *engine;
362     QHash<QString, QScriptValue> m_values;
363     QString m_currentExpression;
364 };
365 
366 #define DEFINE_TEST_FUNCTION(name) \
367 void tst_QScriptValueGenerated::name##_data() { dataHelper(&tst_QScriptValueGenerated::name##_initData, &tst_QScriptValueGenerated::name##_makeData); } \
368 void tst_QScriptValueGenerated::name() { testHelper(&tst_QScriptValueGenerated::name##_test); }
369 
370 #endif
371