~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to tests/auto/qml/parserstress/tst_parserstress.cpp

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
20
**
 
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.
 
28
**
 
29
** Other Usage
 
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.
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <qtest.h>
 
43
#include <QQmlEngine>
 
44
#include <QQmlComponent>
 
45
#include <QDebug>
 
46
#include <QDir>
 
47
#include <QFile>
 
48
 
 
49
class tst_parserstress : public QObject
 
50
{
 
51
    Q_OBJECT
 
52
public:
 
53
    tst_parserstress() {}
 
54
 
 
55
private slots:
 
56
    void ecmascript_data();
 
57
    void ecmascript();
 
58
 
 
59
private:
 
60
    static QStringList findJSFiles(const QDir &);
 
61
    QQmlEngine engine;
 
62
};
 
63
 
 
64
QStringList tst_parserstress::findJSFiles(const QDir &d)
 
65
{
 
66
    QStringList rv;
 
67
 
 
68
    QStringList files = d.entryList(QStringList() << QLatin1String("*.js"),
 
69
                                    QDir::Files);
 
70
    foreach (const QString &file, files) {
 
71
        if (file == "browser.js")
 
72
            continue;
 
73
        rv << d.absoluteFilePath(file);
 
74
    }
 
75
 
 
76
    QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
 
77
                                   QDir::NoSymLinks);
 
78
    foreach (const QString &dir, dirs) {
 
79
        QDir sub = d;
 
80
        sub.cd(dir);
 
81
        rv << findJSFiles(sub);
 
82
    }
 
83
 
 
84
    return rv;
 
85
}
 
86
 
 
87
void tst_parserstress::ecmascript_data()
 
88
{
 
89
    QString testDataDir = QFileInfo(QFINDTESTDATA("tests/shell.js")).absolutePath();
 
90
    QVERIFY2(!testDataDir.isEmpty(), qPrintable("Cannot find testDataDir!"));
 
91
 
 
92
    QDir dir(testDataDir);
 
93
    QStringList files = findJSFiles(dir);
 
94
 
 
95
    QTest::addColumn<QString>("file");
 
96
    foreach (const QString &file, files) {
 
97
        QTest::newRow(qPrintable(file)) << file;
 
98
    }
 
99
}
 
100
 
 
101
void tst_parserstress::ecmascript()
 
102
{
 
103
    QFETCH(QString, file);
 
104
 
 
105
    QFile f(file);
 
106
    QVERIFY(f.open(QIODevice::ReadOnly));
 
107
 
 
108
    QByteArray data = f.readAll();
 
109
 
 
110
    QVERIFY(!data.isEmpty());
 
111
 
 
112
    QString dataStr = QString::fromUtf8(data);
 
113
 
 
114
    QString qml = "import QtQuick 2.0\n";
 
115
            qml+= "\n";
 
116
            qml+= "QtObject {\n";
 
117
            qml+= "    property int test\n";
 
118
            qml+= "    test: {\n";
 
119
            qml+= dataStr + "\n";
 
120
            qml+= "        return 1;\n";
 
121
            qml+= "    }\n";
 
122
            qml+= "    function stress() {\n";
 
123
            qml+= dataStr;
 
124
            qml+= "    }\n";
 
125
            qml+= "}\n";
 
126
 
 
127
    QByteArray qmlData = qml.toUtf8();
 
128
 
 
129
    QQmlComponent component(&engine);
 
130
 
 
131
    component.setData(qmlData, QUrl());
 
132
 
 
133
    QFileInfo info(file);
 
134
 
 
135
    if (info.fileName() == QLatin1String("regress-352044-02-n.js")) {
 
136
        QVERIFY(component.isError());
 
137
 
 
138
        QCOMPARE(component.errors().length(), 2);
 
139
 
 
140
        QCOMPARE(component.errors().at(0).description(), QString("Expected token `;'"));
 
141
        QCOMPARE(component.errors().at(0).line(), 66);
 
142
 
 
143
        QCOMPARE(component.errors().at(1).description(), QString("Expected token `;'"));
 
144
        QCOMPARE(component.errors().at(1).line(), 142);
 
145
 
 
146
    } else {
 
147
 
 
148
        QVERIFY(!component.isError());
 
149
    }
 
150
}
 
151
 
 
152
 
 
153
QTEST_MAIN(tst_parserstress)
 
154
 
 
155
#include "tst_parserstress.moc"