]>
git.saurik.com Git - apple/javascriptcore.git/blob - qt/benchmarks/qscriptvalue/tst_qscriptvalue.cpp
7c39b8e7c4d549427cc36fe48a1159e3723ee742
2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
20 #include "qscriptengine.h"
21 #include "qscriptstring.h"
22 #include "qscriptvalue.h"
25 Q_DECLARE_METATYPE(QScriptValue
);
27 class tst_QScriptValue
: public QObject
{
50 void ctorQScriptValue();
58 void isFunction_data();
64 void isUndefined_data();
77 void toInteger_data();
90 void strictlyEquals_data();
91 void strictlyEquals();
92 void instanceOf_data();
96 QScriptEngine
* m_engine
;
99 void tst_QScriptValue::values_data()
103 m_engine
= new QScriptEngine
;
105 QTest::addColumn
<QScriptValue
>("value");
107 QTest::newRow("invalid") << QScriptValue();
109 QTest::newRow("cbool") << QScriptValue(true);
110 QTest::newRow("cnumber") << QScriptValue(1234);
111 QTest::newRow("cstring") << QScriptValue("abc");
112 QTest::newRow("cnull") << QScriptValue(QScriptValue::NullValue
);
113 QTest::newRow("cundefined") << QScriptValue(QScriptValue::UndefinedValue
);
115 QTest::newRow("jsbool") << m_engine
->evaluate("true");
116 QTest::newRow("jsnumber") << m_engine
->evaluate("12345");
117 QTest::newRow("jsstring") << m_engine
->evaluate("'go'");
118 QTest::newRow("jsfunction") << m_engine
->evaluate("(function {})");
119 QTest::newRow("jsnull") << m_engine
->nullValue();
120 QTest::newRow("jsundefined") << m_engine
->undefinedValue();
121 QTest::newRow("jsobject") << m_engine
->newObject();
122 QTest::newRow("jserror") << m_engine
->evaluate("new Error()");
125 void tst_QScriptValue::ctorBool()
132 void tst_QScriptValue::ctorReal()
139 void tst_QScriptValue::ctorNumber()
146 void tst_QScriptValue::ctorQString()
148 QString str
= QString::fromLatin1("ciao");
154 void tst_QScriptValue::ctorCString()
157 QScriptValue("Pong!");
161 void tst_QScriptValue::ctorSpecial()
164 (void)QScriptValue(QScriptValue::NullValue
);
168 void tst_QScriptValue::ctorQScriptValue()
170 QScriptValue
tmp(1234);
176 void tst_QScriptValue::isValid_data()
181 void tst_QScriptValue::isValid()
183 QFETCH(QScriptValue
, value
);
189 void tst_QScriptValue::isBool_data()
194 void tst_QScriptValue::isBool()
196 QFETCH(QScriptValue
, value
);
202 void tst_QScriptValue::isNumber_data()
207 void tst_QScriptValue::isNumber()
209 QFETCH(QScriptValue
, value
);
215 void tst_QScriptValue::isFunction_data()
220 void tst_QScriptValue::isFunction()
222 QFETCH(QScriptValue
, value
);
228 void tst_QScriptValue::isNull_data()
233 void tst_QScriptValue::isNull()
235 QFETCH(QScriptValue
, value
);
241 void tst_QScriptValue::isString_data()
246 void tst_QScriptValue::isString()
248 QFETCH(QScriptValue
, value
);
254 void tst_QScriptValue::isUndefined_data()
259 void tst_QScriptValue::isUndefined()
261 QFETCH(QScriptValue
, value
);
267 void tst_QScriptValue::isObject_data()
272 void tst_QScriptValue::isObject()
274 QFETCH(QScriptValue
, value
);
280 void tst_QScriptValue::isError_data()
285 void tst_QScriptValue::isError()
287 QFETCH(QScriptValue
, value
);
293 void tst_QScriptValue::toString_data()
298 void tst_QScriptValue::toString()
300 QFETCH(QScriptValue
, value
);
306 void tst_QScriptValue::toNumber_data()
311 void tst_QScriptValue::toNumber()
313 QFETCH(QScriptValue
, value
);
319 void tst_QScriptValue::toBool_data()
324 void tst_QScriptValue::toBool()
326 QFETCH(QScriptValue
, value
);
332 void tst_QScriptValue::toInteger_data()
337 void tst_QScriptValue::toInteger()
339 QFETCH(QScriptValue
, value
);
345 void tst_QScriptValue::toInt32_data()
350 void tst_QScriptValue::toInt32()
352 QFETCH(QScriptValue
, value
);
358 void tst_QScriptValue::toUInt32_data()
363 void tst_QScriptValue::toUInt32()
365 QFETCH(QScriptValue
, value
);
371 void tst_QScriptValue::toUInt16_data()
376 void tst_QScriptValue::toUInt16()
378 QFETCH(QScriptValue
, value
);
384 void tst_QScriptValue::toObject_data()
389 void tst_QScriptValue::toObject()
391 QFETCH(QScriptValue
, value
);
397 void tst_QScriptValue::equals_data()
402 void tst_QScriptValue::equals()
404 QFETCH(QScriptValue
, value
);
405 static QScriptValue previous
;
407 value
.equals(previous
);
412 void tst_QScriptValue::strictlyEquals_data()
417 void tst_QScriptValue::strictlyEquals()
419 QFETCH(QScriptValue
, value
);
420 static QScriptValue previous
;
422 value
.strictlyEquals(previous
);
427 void tst_QScriptValue::instanceOf_data()
432 void tst_QScriptValue::instanceOf()
434 QFETCH(QScriptValue
, value
);
435 static QScriptValue object
= m_engine
->newObject();
437 value
.instanceOf(object
);
441 QTEST_MAIN(tst_QScriptValue
)
442 #include "tst_qscriptvalue.moc"