author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
#include <QByteArray> |
|
45 |
||
46 |
#include <QtScript> |
|
47 |
||
48 |
#if defined(Q_OS_SYMBIAN) |
|
49 |
# define SRCDIR "" |
|
50 |
#endif |
|
51 |
||
52 |
//TESTED_CLASS= |
|
53 |
//TESTED_FILES= |
|
54 |
||
55 |
// Uncomment the following define to have the autotest generate |
|
56 |
// addExpectedFailure() code for all the tests that fail. |
|
57 |
// This is useful when a whole new test (sub)suite is added. |
|
58 |
// The code is stored in addexpectedfailures.cpp. |
|
59 |
// Paste the contents into this file after the existing |
|
60 |
// addExpectedFailure() calls. |
|
61 |
||
62 |
//#define GENERATE_ADDEXPECTEDFAILURE_CODE |
|
63 |
||
64 |
static QString readFile(const QString &filename) |
|
65 |
{ |
|
66 |
QFile file(filename); |
|
67 |
if (!file.open(QFile::ReadOnly)) |
|
68 |
return QString(); |
|
69 |
QTextStream stream(&file); |
|
70 |
stream.setCodec("UTF-8"); |
|
71 |
return stream.readAll(); |
|
72 |
} |
|
73 |
||
74 |
static void appendCString(QVector<char> *v, const char *s) |
|
75 |
{ |
|
76 |
char c; |
|
77 |
do { |
|
78 |
c = *(s++); |
|
79 |
*v << c; |
|
80 |
} while (c != '\0'); |
|
81 |
} |
|
82 |
||
83 |
struct ExpectedFailure |
|
84 |
{ |
|
85 |
ExpectedFailure(const QString &name, const QString &act, |
|
86 |
const QString &exp, const QString &msg) |
|
87 |
: testName(name), actual(act), expected(exp), message(msg) |
|
88 |
{ } |
|
89 |
||
90 |
QString testName; |
|
91 |
QString actual; |
|
92 |
QString expected; |
|
93 |
QString message; |
|
94 |
}; |
|
95 |
||
96 |
class tst_Suite : public QObject |
|
97 |
{ |
|
98 |
||
99 |
public: |
|
100 |
tst_Suite(); |
|
101 |
virtual ~tst_Suite(); |
|
102 |
||
103 |
static QMetaObject staticMetaObject; |
|
104 |
virtual const QMetaObject *metaObject() const; |
|
105 |
virtual void *qt_metacast(const char *); |
|
106 |
virtual int qt_metacall(QMetaObject::Call, int, void **argv); |
|
107 |
||
108 |
private: |
|
109 |
void addExpectedFailure(const QString &testName, const QString &actual, |
|
110 |
const QString &expected, const QString &message); |
|
111 |
bool isExpectedFailure(const QString &testName, const QString &actual, |
|
112 |
const QString &expected, QString *message) const; |
|
113 |
void addTestExclusion(const QString &testName, const QString &message); |
|
114 |
void addTestExclusion(const QRegExp &rx, const QString &message); |
|
115 |
bool isExcludedTest(const QString &testName, QString *message) const; |
|
116 |
||
117 |
QDir testsDir; |
|
118 |
QStringList testNames; |
|
119 |
QList<ExpectedFailure> expectedFailures; |
|
120 |
QList<QPair<QRegExp, QString> > testExclusions; |
|
121 |
QString mjsunitContents; |
|
122 |
#ifdef GENERATE_ADDEXPECTEDFAILURE_CODE |
|
123 |
QString generatedAddExpectedFailureCode; |
|
124 |
#endif |
|
125 |
}; |
|
126 |
||
127 |
QMetaObject tst_Suite::staticMetaObject; |
|
128 |
||
129 |
Q_GLOBAL_STATIC(QVector<uint>, qt_meta_data_tst_Suite) |
|
130 |
Q_GLOBAL_STATIC(QVector<char>, qt_meta_stringdata_tst_Suite) |
|
131 |
||
132 |
const QMetaObject *tst_Suite::metaObject() const |
|
133 |
{ |
|
134 |
return &staticMetaObject; |
|
135 |
} |
|
136 |
||
137 |
void *tst_Suite::qt_metacast(const char *_clname) |
|
138 |
{ |
|
139 |
if (!_clname) return 0; |
|
140 |
if (!strcmp(_clname, qt_meta_stringdata_tst_Suite()->constData())) |
|
141 |
return static_cast<void*>(const_cast<tst_Suite*>(this)); |
|
142 |
return QObject::qt_metacast(_clname); |
|
143 |
} |
|
144 |
||
145 |
static QScriptValue qscript_fail(QScriptContext *ctx, QScriptEngine *eng) |
|
146 |
{ |
|
147 |
QScriptValue realFail = ctx->callee().data(); |
|
148 |
Q_ASSERT(realFail.isFunction()); |
|
149 |
QScriptValue ret = realFail.call(ctx->thisObject(), ctx->argumentsObject()); |
|
150 |
Q_ASSERT(eng->hasUncaughtException()); |
|
151 |
ret.setProperty("expected", ctx->argument(0)); |
|
152 |
ret.setProperty("actual", ctx->argument(1)); |
|
153 |
QScriptContextInfo info(ctx->parentContext()->parentContext()); |
|
154 |
ret.setProperty("lineNumber", info.lineNumber()); |
|
155 |
return ret; |
|
156 |
} |
|
157 |
||
158 |
int tst_Suite::qt_metacall(QMetaObject::Call _c, int _id, void **_a) |
|
159 |
{ |
|
160 |
_id = QObject::qt_metacall(_c, _id, _a); |
|
161 |
if (_id < 0) |
|
162 |
return _id; |
|
163 |
if (_c == QMetaObject::InvokeMetaMethod) { |
|
164 |
QString name = testNames.at(_id); |
|
165 |
QString path = testsDir.absoluteFilePath(name + ".js"); |
|
166 |
QString excludeMessage; |
|
167 |
if (isExcludedTest(name, &excludeMessage)) { |
|
168 |
QTest::qSkip(excludeMessage.toLatin1(), QTest::SkipAll, path.toLatin1(), -1); |
|
169 |
} else { |
|
170 |
QScriptEngine engine; |
|
171 |
engine.evaluate(mjsunitContents).toString(); |
|
172 |
if (engine.hasUncaughtException()) { |
|
173 |
QStringList bt = engine.uncaughtExceptionBacktrace(); |
|
174 |
QString err = engine.uncaughtException().toString(); |
|
175 |
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n"))); |
|
176 |
} else { |
|
177 |
QScriptValue fakeFail = engine.newFunction(qscript_fail); |
|
178 |
fakeFail.setData(engine.globalObject().property("fail")); |
|
179 |
engine.globalObject().setProperty("fail", fakeFail); |
|
180 |
QString contents = readFile(path); |
|
181 |
QScriptValue ret = engine.evaluate(contents); |
|
182 |
if (engine.hasUncaughtException()) { |
|
183 |
if (!ret.isError()) { |
|
184 |
Q_ASSERT(ret.instanceOf(engine.globalObject().property("MjsUnitAssertionError"))); |
|
185 |
QString actual = ret.property("actual").toString(); |
|
186 |
QString expected = ret.property("expected").toString(); |
|
187 |
int lineNumber = ret.property("lineNumber").toInt32(); |
|
188 |
QString failMessage; |
|
189 |
if (isExpectedFailure(name, actual, expected, &failMessage)) { |
|
190 |
QTest::qExpectFail("", failMessage.toLatin1(), |
|
191 |
QTest::Continue, path.toLatin1(), |
|
192 |
lineNumber); |
|
193 |
} |
|
194 |
#ifdef GENERATE_ADDEXPECTEDFAILURE_CODE |
|
195 |
else { |
|
196 |
generatedAddExpectedFailureCode.append( |
|
197 |
" addExpectedFailure(\"" + name |
|
198 |
+ "\", \"" + actual + "\", \"" + expected |
|
199 |
+ "\", willFixInNextReleaseMessage);\n"); |
|
200 |
} |
|
201 |
#endif |
|
202 |
QTest::qCompare(actual, expected, "actual", "expect", |
|
203 |
path.toLatin1(), lineNumber); |
|
204 |
} else { |
|
205 |
int lineNumber = ret.property("lineNumber").toInt32(); |
|
206 |
QTest::qExpectFail("", ret.toString().toLatin1(), |
|
207 |
QTest::Continue, path.toLatin1(), lineNumber); |
|
208 |
QTest::qVerify(false, ret.toString().toLatin1(), "", path.toLatin1(), lineNumber); |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
_id -= testNames.size(); |
|
214 |
} |
|
215 |
return _id; |
|
216 |
} |
|
217 |
||
218 |
tst_Suite::tst_Suite() |
|
219 |
{ |
|
220 |
testsDir = QDir(SRCDIR); |
|
221 |
bool testsFound = testsDir.cd("tests"); |
|
222 |
if (!testsFound) { |
|
223 |
qWarning("*** no tests/ dir!"); |
|
224 |
} else { |
|
225 |
if (!testsDir.exists("mjsunit.js")) |
|
226 |
qWarning("*** no tests/mjsunit.js file!"); |
|
227 |
else { |
|
228 |
mjsunitContents = readFile(testsDir.absoluteFilePath("mjsunit.js")); |
|
229 |
if (mjsunitContents.isEmpty()) |
|
230 |
qWarning("*** tests/mjsunit.js is empty!"); |
|
231 |
} |
|
232 |
} |
|
233 |
QString willFixInNextReleaseMessage = QString::fromLatin1("Will fix in next release"); |
|
234 |
addExpectedFailure("arguments-enum", "2", "0", willFixInNextReleaseMessage); |
|
235 |
addExpectedFailure("const-redecl", "undefined", "TypeError", willFixInNextReleaseMessage); |
|
236 |
addExpectedFailure("global-const-var-conflicts", "false", "true", willFixInNextReleaseMessage); |
|
237 |
addExpectedFailure("string-lastindexof", "0", "-1", "test is wrong?"); |
|
238 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
239 |
#ifndef Q_OS_LINUX |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
240 |
addExpectedFailure("to-precision", "1.235e+27", "1.234e+27", "QTBUG-8053: toPrecision(4) gives wrong result on Mac"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
241 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
242 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
243 |
#ifdef Q_OS_SOLARIS |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
244 |
addExpectedFailure("math-min-max", "Infinity", "-Infinity", willFixInNextReleaseMessage); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
245 |
addExpectedFailure("negate-zero", "false", "true", willFixInNextReleaseMessage); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
246 |
addExpectedFailure("str-to-num", "Infinity", "-Infinity", willFixInNextReleaseMessage); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
247 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
248 |
|
0 | 249 |
addTestExclusion("debug-*", "not applicable"); |
250 |
addTestExclusion("mirror-*", "not applicable"); |
|
251 |
||
252 |
addTestExclusion("array-concat", "Hangs on JSC backend"); |
|
253 |
addTestExclusion("array-splice", "Hangs on JSC backend"); |
|
254 |
addTestExclusion("sparse-array-reverse", "Hangs on JSC backend"); |
|
255 |
||
256 |
addTestExclusion("string-case", "V8-specific behavior? (Doesn't pass on SpiderMonkey either)"); |
|
257 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
258 |
#ifdef Q_CC_MINGW |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
259 |
addTestExclusion("date$", "QTBUG-7698: Date.prototype.setMonth() crashes on win32-g++"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
260 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
261 |
|
0 | 262 |
#ifdef Q_OS_WINCE |
263 |
addTestExclusion("deep-recursion", "Demands too much memory on WinCE"); |
|
264 |
addTestExclusion("nested-repetition-count-overflow", "Demands too much memory on WinCE"); |
|
265 |
addTestExclusion("unicode-test", "Demands too much memory on WinCE"); |
|
266 |
addTestExclusion("mul-exhaustive", "Demands too much memory on WinCE"); |
|
267 |
#endif |
|
268 |
||
269 |
#ifdef Q_OS_SYMBIAN |
|
270 |
addTestExclusion("nested-repetition-count-overflow", "Demands too much memory on Symbian"); |
|
271 |
addTestExclusion("unicode-test", "Demands too much memory on Symbian"); |
|
272 |
#endif |
|
273 |
// Failures due to switch to JSC as back-end |
|
274 |
addExpectedFailure("date-parse", "NaN", "946713600000", willFixInNextReleaseMessage); |
|
275 |
addExpectedFailure("delete-global-properties", "true", "false", willFixInNextReleaseMessage); |
|
276 |
addExpectedFailure("delete", "false", "true", willFixInNextReleaseMessage); |
|
277 |
addExpectedFailure("function-arguments-null", "false", "true", willFixInNextReleaseMessage); |
|
278 |
addExpectedFailure("function-caller", "null", "function eval() {\n [native code]\n}", willFixInNextReleaseMessage); |
|
279 |
addExpectedFailure("function-prototype", "prototype", "disconnectconnect", willFixInNextReleaseMessage); |
|
280 |
addExpectedFailure("number-tostring", "0", "0.0000a7c5ac471b4788", willFixInNextReleaseMessage); |
|
281 |
addExpectedFailure("parse-int-float", "1e+21", "1", willFixInNextReleaseMessage); |
|
282 |
addExpectedFailure("regexp", "false", "true", willFixInNextReleaseMessage); |
|
283 |
addExpectedFailure("smi-negative-zero", "-Infinity", "Infinity", willFixInNextReleaseMessage); |
|
284 |
addExpectedFailure("string-split", "4", "3", willFixInNextReleaseMessage); |
|
285 |
addExpectedFailure("substr", "abcdefghijklmn", "", willFixInNextReleaseMessage); |
|
286 |
||
287 |
static const char klass[] = "tst_QScriptV8TestSuite"; |
|
288 |
||
289 |
QVector<uint> *data = qt_meta_data_tst_Suite(); |
|
290 |
// content: |
|
291 |
*data << 1 // revision |
|
292 |
<< 0 // classname |
|
293 |
<< 0 << 0 // classinfo |
|
294 |
<< 0 << 10 // methods (backpatched later) |
|
295 |
<< 0 << 0 // properties |
|
296 |
<< 0 << 0 // enums/sets |
|
297 |
; |
|
298 |
||
299 |
QVector<char> *stringdata = qt_meta_stringdata_tst_Suite(); |
|
300 |
appendCString(stringdata, klass); |
|
301 |
appendCString(stringdata, ""); |
|
302 |
||
303 |
QFileInfoList testFileInfos; |
|
304 |
if (testsFound) |
|
305 |
testFileInfos = testsDir.entryInfoList(QStringList() << "*.js", QDir::Files); |
|
306 |
foreach (QFileInfo tfi, testFileInfos) { |
|
307 |
QString name = tfi.baseName(); |
|
308 |
// slot: signature, parameters, type, tag, flags |
|
309 |
QString slot = QString::fromLatin1("%0()").arg(name); |
|
310 |
static const int nullbyte = sizeof(klass); |
|
311 |
*data << stringdata->size() << nullbyte << nullbyte << nullbyte << 0x08; |
|
312 |
appendCString(stringdata, slot.toLatin1()); |
|
313 |
testNames.append(name); |
|
314 |
} |
|
315 |
||
316 |
(*data)[4] = testFileInfos.size(); |
|
317 |
||
318 |
*data << 0; // eod |
|
319 |
||
320 |
// initialize staticMetaObject |
|
321 |
staticMetaObject.d.superdata = &QObject::staticMetaObject; |
|
322 |
staticMetaObject.d.stringdata = stringdata->constData(); |
|
323 |
staticMetaObject.d.data = data->constData(); |
|
324 |
staticMetaObject.d.extradata = 0; |
|
325 |
} |
|
326 |
||
327 |
tst_Suite::~tst_Suite() |
|
328 |
{ |
|
329 |
#ifdef GENERATE_ADDEXPECTEDFAILURE_CODE |
|
330 |
if (!generatedAddExpectedFailureCode.isEmpty()) { |
|
331 |
QFile file("addexpectedfailures.cpp"); |
|
332 |
file.open(QFile::WriteOnly); |
|
333 |
QTextStream ts(&file); |
|
334 |
ts << generatedAddExpectedFailureCode; |
|
335 |
} |
|
336 |
#endif |
|
337 |
} |
|
338 |
||
339 |
void tst_Suite::addExpectedFailure(const QString &testName, const QString &actual, |
|
340 |
const QString &expected, const QString &message) |
|
341 |
{ |
|
342 |
expectedFailures.append(ExpectedFailure(testName, actual, expected, message)); |
|
343 |
} |
|
344 |
||
345 |
bool tst_Suite::isExpectedFailure(const QString &testName, const QString &actual, |
|
346 |
const QString &expected, QString *message) const |
|
347 |
{ |
|
348 |
for (int i = 0; i < expectedFailures.size(); ++i) { |
|
349 |
const ExpectedFailure &ef = expectedFailures.at(i); |
|
350 |
if ((testName == ef.testName) && (actual == ef.actual) && (expected == ef.expected)) { |
|
351 |
if (message) |
|
352 |
*message = ef.message; |
|
353 |
return true; |
|
354 |
} |
|
355 |
} |
|
356 |
return false; |
|
357 |
} |
|
358 |
||
359 |
void tst_Suite::addTestExclusion(const QString &testName, const QString &message) |
|
360 |
{ |
|
361 |
testExclusions.append(qMakePair(QRegExp(testName), message)); |
|
362 |
} |
|
363 |
||
364 |
void tst_Suite::addTestExclusion(const QRegExp &rx, const QString &message) |
|
365 |
{ |
|
366 |
testExclusions.append(qMakePair(rx, message)); |
|
367 |
} |
|
368 |
||
369 |
bool tst_Suite::isExcludedTest(const QString &testName, QString *message) const |
|
370 |
{ |
|
371 |
for (int i = 0; i < testExclusions.size(); ++i) { |
|
372 |
if (testExclusions.at(i).first.indexIn(testName) != -1) { |
|
373 |
if (message) |
|
374 |
*message = testExclusions.at(i).second; |
|
375 |
return true; |
|
376 |
} |
|
377 |
} |
|
378 |
return false; |
|
379 |
} |
|
380 |
||
381 |
QTEST_MAIN(tst_Suite) |