• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3 
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.
8 
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.
13 
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.
18 */
19 
20 #ifndef tst_qscriptvalue_h
21 #define tst_qscriptvalue_h
22 
23 #include "qscriptengine.h"
24 #include "qscriptvalue.h"
25 #include <QtCore/qnumeric.h>
26 #include <QtTest/qtest.h>
27 
28 Q_DECLARE_METATYPE(QScriptValue*);
29 Q_DECLARE_METATYPE(QScriptValue);
30 
31 class tst_QScriptValue : public QObject {
32     Q_OBJECT
33 
34 public:
35     tst_QScriptValue();
36     virtual ~tst_QScriptValue();
37 
38 private slots:
39     void toString_data();
40     void toString();
41     void copyConstructor_data();
42     void copyConstructor();
43     void assignOperator_data();
44     void assignOperator();
45     void dataSharing();
46     void constructors_data();
47     void constructors();
48     void call();
49     void ctor();
50 
51     // Generated test functions.
52     void isBool_data();
53     void isBool();
54 
55     void isBoolean_data();
56     void isBoolean();
57 
58     void isNumber_data();
59     void isNumber();
60 
61     void isFunction_data();
62     void isFunction();
63 
64     void isNull_data();
65     void isNull();
66 
67     void isObject_data();
68     void isObject();
69 
70     void isString_data();
71     void isString();
72 
73     void isUndefined_data();
74     void isUndefined();
75 
76     void isValid_data();
77     void isValid();
78 
79     void toNumber_data();
80     void toNumber();
81 
82     void toBool_data();
83     void toBool();
84 
85     void toBoolean_data();
86     void toBoolean();
87 
88 private:
89     typedef void (tst_QScriptValue::*InitDataFunction)();
90     typedef void (tst_QScriptValue::*DefineDataFunction)(const char*);
91     void dataHelper(InitDataFunction init, DefineDataFunction define);
92     QTestData& newRow(const char* tag);
93 
94     typedef void (tst_QScriptValue::*TestFunction)(const char*, const QScriptValue&);
95     void testHelper(TestFunction fun);
96 
97     // Generated functions
98 
99     void initScriptValues();
100 
101     void isBool_initData();
102     void isBool_makeData(const char* expr);
103     void isBool_test(const char* expr, const QScriptValue& value);
104 
105     void isBoolean_initData();
106     void isBoolean_makeData(const char* expr);
107     void isBoolean_test(const char* expr, const QScriptValue& value);
108 
109     void isNumber_initData();
110     void isNumber_makeData(const char* expr);
111     void isNumber_test(const char* expr, const QScriptValue&);
112 
113     void isFunction_initData();
114     void isFunction_makeData(const char* expr);
115     void isFunction_test(const char* expr, const QScriptValue& value);
116 
117     void isNull_initData();
118     void isNull_makeData(const char* expr);
119     void isNull_test(const char* expr, const QScriptValue& value);
120 
121     void isObject_initData();
122     void isObject_makeData(const char* expr);
123     void isObject_test(const char* expr, const QScriptValue& value);
124 
125     void isString_initData();
126     void isString_makeData(const char* expr);
127     void isString_test(const char* expr, const QScriptValue& value);
128 
129     void isUndefined_initData();
130     void isUndefined_makeData(const char* expr);
131     void isUndefined_test(const char* expr, const QScriptValue& value);
132 
133     void isValid_initData();
134     void isValid_makeData(const char* expr);
135     void isValid_test(const char* expr, const QScriptValue& value);
136 
137     void toNumber_initData();
138     void toNumber_makeData(const char*);
139     void toNumber_test(const char*, const QScriptValue&);
140 
141     void toBool_initData();
142     void toBool_makeData(const char*);
143     void toBool_test(const char*, const QScriptValue&);
144 
145     void toBoolean_initData();
146     void toBoolean_makeData(const char*);
147     void toBoolean_test(const char*, const QScriptValue&);
148 
149 private:
150     QScriptEngine* engine;
151     QHash<QString, QScriptValue> m_values;
152     QString m_currentExpression;
153 };
154 
155 #define DEFINE_TEST_FUNCTION(name) \
156 void tst_QScriptValue::name##_data() { dataHelper(&tst_QScriptValue::name##_initData, &tst_QScriptValue::name##_makeData); } \
157 void tst_QScriptValue::name() { testHelper(&tst_QScriptValue::name##_test); }
158 
159 
160 
161 #endif // tst_qscriptvalue_h
162