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 <QtDeclarative/qdeclarativeengine.h>
45 #include <QtDeclarative/qdeclarativecomponent.h>
46 #include <QtDeclarative/private/qdeclarativejsengine_p.h>
47 #include <QtDeclarative/private/qdeclarativejsmemorypool_p.h>
48 #include <QtDeclarative/private/qdeclarativejsparser_p.h>
49 #include <QtDeclarative/private/qdeclarativejslexer_p.h>
50 #include <QtDeclarative/private/qdeclarativescript_p.h>
54 #include <QTextStream>
56 class tst_compilation : public QObject
68 void scriptparser_data();
72 QDeclarativeEngine engine;
75 tst_compilation::tst_compilation()
79 inline QUrl TEST_FILE(const QString &filename)
81 return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
84 void tst_compilation::boomblock()
86 QFile f(SRCDIR + QLatin1String("/data/BoomBlock.qml"));
87 QVERIFY(f.open(QIODevice::ReadOnly));
88 QByteArray data = f.readAll();
90 //get rid of initialization effects
92 QDeclarativeComponent c(&engine);
93 c.setData(data, QUrl());
97 QDeclarativeComponent c(&engine);
98 c.setData(data, QUrl());
99 // QVERIFY(c.isReady());
103 void tst_compilation::jsparser_data()
105 QTest::addColumn<QString>("file");
107 QTest::newRow("boomblock") << QString(SRCDIR + QLatin1String("/data/BoomBlock.qml"));
110 void tst_compilation::jsparser()
112 QFETCH(QString, file);
115 QVERIFY(f.open(QIODevice::ReadOnly));
116 QByteArray data = f.readAll();
118 QTextStream stream(data, QIODevice::ReadOnly);
119 const QString code = stream.readAll();
122 QDeclarativeJS::Engine engine;
123 QDeclarativeJS::NodePool nodePool(file, &engine);
125 QDeclarativeJS::Lexer lexer(&engine);
126 lexer.setCode(code, -1);
128 QDeclarativeJS::Parser parser(&engine);
134 void tst_compilation::scriptparser_data()
136 QTest::addColumn<QString>("file");
138 QTest::newRow("boomblock") << QString(SRCDIR + QLatin1String("/data/BoomBlock.qml"));
141 void tst_compilation::scriptparser()
143 QFETCH(QString, file);
146 QVERIFY(f.open(QIODevice::ReadOnly));
147 QByteArray data = f.readAll();
149 QUrl url = QUrl::fromLocalFile(file);
152 QDeclarativeScript::Parser parser;
153 parser.parse(data, url);
158 QTEST_MAIN(tst_compilation)
160 #include "tst_compilation.moc"