1
/****************************************************************************
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** GNU Lesser General Public License Usage
10
** This file may be used under the terms of the GNU Lesser General Public
11
** License version 2.1 as published by the Free Software Foundation and
12
** appearing in the file LICENSE.LGPL included in the packaging of this
13
** file. Please review the following information to ensure the GNU Lesser
14
** General Public License version 2.1 requirements will be met:
15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
** In addition, as a special exception, Nokia gives you certain additional
18
** rights. These rights are described in the Nokia Qt LGPL Exception
19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
** GNU General Public License Usage
22
** Alternatively, this file may be used under the terms of the GNU General
23
** Public License version 3.0 as published by the Free Software Foundation
24
** and appearing in the file LICENSE.GPL included in the packaging of this
25
** file. Please review the following information to ensure the GNU General
26
** Public License version 3.0 requirements will be met:
27
** http://www.gnu.org/copyleft/gpl.html.
30
** Alternatively, this file may be used in accordance with the terms and
31
** conditions contained in a signed written agreement between you and Nokia.
40
****************************************************************************/
44
#include <QQmlComponent>
49
class tst_parserstress : public QObject
56
void ecmascript_data();
60
static QStringList findJSFiles(const QDir &);
64
QStringList tst_parserstress::findJSFiles(const QDir &d)
68
QStringList files = d.entryList(QStringList() << QLatin1String("*.js"),
70
foreach (const QString &file, files) {
71
if (file == "browser.js")
73
rv << d.absoluteFilePath(file);
76
QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
78
foreach (const QString &dir, dirs) {
81
rv << findJSFiles(sub);
87
void tst_parserstress::ecmascript_data()
89
QString testDataDir = QFileInfo(QFINDTESTDATA("tests/shell.js")).absolutePath();
90
QVERIFY2(!testDataDir.isEmpty(), qPrintable("Cannot find testDataDir!"));
92
QDir dir(testDataDir);
93
QStringList files = findJSFiles(dir);
95
QTest::addColumn<QString>("file");
96
foreach (const QString &file, files) {
97
QTest::newRow(qPrintable(file)) << file;
101
void tst_parserstress::ecmascript()
103
QFETCH(QString, file);
106
QVERIFY(f.open(QIODevice::ReadOnly));
108
QByteArray data = f.readAll();
110
QVERIFY(!data.isEmpty());
112
QString dataStr = QString::fromUtf8(data);
114
QString qml = "import QtQuick 2.0\n";
116
qml+= "QtObject {\n";
117
qml+= " property int test\n";
119
qml+= dataStr + "\n";
120
qml+= " return 1;\n";
122
qml+= " function stress() {\n";
127
QByteArray qmlData = qml.toUtf8();
129
QQmlComponent component(&engine);
131
component.setData(qmlData, QUrl());
133
QFileInfo info(file);
135
if (info.fileName() == QLatin1String("regress-352044-02-n.js")) {
136
QVERIFY(component.isError());
138
QCOMPARE(component.errors().length(), 2);
140
QCOMPARE(component.errors().at(0).description(), QString("Expected token `;'"));
141
QCOMPARE(component.errors().at(0).line(), 66);
143
QCOMPARE(component.errors().at(1).description(), QString("Expected token `;'"));
144
QCOMPARE(component.errors().at(1).line(), 142);
148
QVERIFY(!component.isError());
153
QTEST_MAIN(tst_parserstress)
155
#include "tst_parserstress.moc"