2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef tst_qscriptvalue_h
21 #define tst_qscriptvalue_h
23 #include "qscriptengine.h"
24 #include "qscriptvalue.h"
25 #include <QtCore/qnumeric.h>
26 #include <QtTest/qtest.h>
28 Q_DECLARE_METATYPE(QScriptValue
*);
29 Q_DECLARE_METATYPE(QScriptValue
);
31 class tst_QScriptValue
: public QObject
{
36 virtual ~tst_QScriptValue();
39 void toStringSimple_data();
40 void toStringSimple();
41 void copyConstructor_data();
42 void copyConstructor();
43 void assignOperator_data();
44 void assignOperator();
46 void constructors_data();
51 // Generated test functions.
55 void isBoolean_data();
61 void isFunction_data();
73 void isUndefined_data();
88 void toBoolean_data();
91 void toInteger_data();
100 void toUInt16_data();
104 typedef void (tst_QScriptValue::*InitDataFunction
)();
105 typedef void (tst_QScriptValue::*DefineDataFunction
)(const char*);
106 void dataHelper(InitDataFunction init
, DefineDataFunction define
);
107 QTestData
& newRow(const char* tag
);
109 typedef void (tst_QScriptValue::*TestFunction
)(const char*, const QScriptValue
&);
110 void testHelper(TestFunction fun
);
112 // Generated functions
114 void initScriptValues();
116 void isBool_initData();
117 void isBool_makeData(const char* expr
);
118 void isBool_test(const char* expr
, const QScriptValue
& value
);
120 void isBoolean_initData();
121 void isBoolean_makeData(const char* expr
);
122 void isBoolean_test(const char* expr
, const QScriptValue
& value
);
124 void isNumber_initData();
125 void isNumber_makeData(const char* expr
);
126 void isNumber_test(const char* expr
, const QScriptValue
&);
128 void isFunction_initData();
129 void isFunction_makeData(const char* expr
);
130 void isFunction_test(const char* expr
, const QScriptValue
& value
);
132 void isNull_initData();
133 void isNull_makeData(const char* expr
);
134 void isNull_test(const char* expr
, const QScriptValue
& value
);
136 void isObject_initData();
137 void isObject_makeData(const char* expr
);
138 void isObject_test(const char* expr
, const QScriptValue
& value
);
140 void isString_initData();
141 void isString_makeData(const char* expr
);
142 void isString_test(const char* expr
, const QScriptValue
& value
);
144 void isUndefined_initData();
145 void isUndefined_makeData(const char* expr
);
146 void isUndefined_test(const char* expr
, const QScriptValue
& value
);
148 void isValid_initData();
149 void isValid_makeData(const char* expr
);
150 void isValid_test(const char* expr
, const QScriptValue
& value
);
152 void toString_initData();
153 void toString_makeData(const char*);
154 void toString_test(const char*, const QScriptValue
&);
156 void toNumber_initData();
157 void toNumber_makeData(const char*);
158 void toNumber_test(const char*, const QScriptValue
&);
160 void toBool_initData();
161 void toBool_makeData(const char*);
162 void toBool_test(const char*, const QScriptValue
&);
164 void toBoolean_initData();
165 void toBoolean_makeData(const char*);
166 void toBoolean_test(const char*, const QScriptValue
&);
168 void toInteger_initData();
169 void toInteger_makeData(const char*);
170 void toInteger_test(const char*, const QScriptValue
&);
172 void toInt32_initData();
173 void toInt32_makeData(const char*);
174 void toInt32_test(const char*, const QScriptValue
&);
176 void toUInt32_initData();
177 void toUInt32_makeData(const char*);
178 void toUInt32_test(const char*, const QScriptValue
&);
180 void toUInt16_initData();
181 void toUInt16_makeData(const char*);
182 void toUInt16_test(const char*, const QScriptValue
&);
185 QScriptEngine
* engine
;
186 QHash
<QString
, QScriptValue
> m_values
;
187 QString m_currentExpression
;
190 #define DEFINE_TEST_FUNCTION(name) \
191 void tst_QScriptValue::name##_data() { dataHelper(&tst_QScriptValue::name##_initData, &tst_QScriptValue::name##_makeData); } \
192 void tst_QScriptValue::name() { testHelper(&tst_QScriptValue::name##_test); }
196 #endif // tst_qscriptvalue_h