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#include "qscriptengine.h"
21#include "qscriptvalue.h"
22#include <qtest.h>
23
24class tst_QScriptEngine : public QObject {
25    Q_OBJECT
26
27private slots:
28    void checkSyntax_data();
29    void checkSyntax();
30    void constructor();
31    void evaluateString_data();
32    void evaluateString();
33    void evaluateProgram_data();
34    void evaluateProgram();
35    void newObject();
36    void nullValue();
37    void undefinedValue();
38    void globalObject();
39    void toStringHandle();
40};
41
42void tst_QScriptEngine::checkSyntax_data()
43{
44    evaluateString_data();
45}
46
47void tst_QScriptEngine::checkSyntax()
48{
49    QFETCH(QString, code);
50    QScriptEngine engine;
51    QBENCHMARK {
52        engine.checkSyntax(code);
53    }
54}
55
56void tst_QScriptEngine::constructor()
57{
58    QBENCHMARK {
59        QScriptEngine engine;
60    }
61}
62
63void tst_QScriptEngine::evaluateString_data()
64{
65    QTest::addColumn<QString>("code");
66    QTest::newRow("empty script") << QString::fromLatin1("");
67    QTest::newRow("number literal") << QString::fromLatin1("123");
68    QTest::newRow("string literal") << QString::fromLatin1("'ciao'");
69    QTest::newRow("regexp literal") << QString::fromLatin1("/foo/gim");
70    QTest::newRow("null literal") << QString::fromLatin1("null");
71    QTest::newRow("undefined literal") << QString::fromLatin1("undefined");
72    QTest::newRow("empty object literal") << QString::fromLatin1("{}");
73    QTest::newRow("this") << QString::fromLatin1("this");
74}
75
76void tst_QScriptEngine::evaluateString()
77{
78    QFETCH(QString, code);
79    QScriptEngine engine;
80    QBENCHMARK {
81        engine.evaluate(code);
82    }
83}
84
85void tst_QScriptEngine::evaluateProgram_data()
86{
87    evaluateString_data();
88}
89
90void tst_QScriptEngine::evaluateProgram()
91{
92    QFETCH(QString, code);
93    QScriptEngine engine;
94    QScriptProgram program(code);
95    QBENCHMARK {
96        engine.evaluate(program);
97    }
98}
99
100void tst_QScriptEngine::newObject()
101{
102    QScriptEngine engine;
103    QBENCHMARK {
104        engine.newObject();
105    }
106}
107
108void tst_QScriptEngine::nullValue()
109{
110    QScriptEngine engine;
111    QBENCHMARK {
112        engine.nullValue();
113    }
114}
115
116void tst_QScriptEngine::undefinedValue()
117{
118    QScriptEngine engine;
119    QBENCHMARK {
120        engine.undefinedValue();
121    }
122}
123
124void tst_QScriptEngine::globalObject()
125{
126    QScriptEngine engine;
127    QBENCHMARK {
128        engine.globalObject();
129    }
130}
131
132void tst_QScriptEngine::toStringHandle()
133{
134    QScriptEngine engine;
135    QString str = QString::fromLatin1("foobarbaz");
136    QBENCHMARK {
137        engine.toStringHandle(str);
138    }
139}
140
141QTEST_MAIN(tst_QScriptEngine)
142#include "tst_qscriptengine.moc"
143