diff -r 41300fa6a67c -r f7bc934e204c tests/auto/qscriptvalue/tst_qscriptvalue.cpp --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp Tue Feb 02 00:43:10 2010 +0200 +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp Wed Mar 31 11:06:36 2010 +0300 @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -39,14 +39,8 @@ ** ****************************************************************************/ - -#include +#include "tst_qscriptvalue.h" #include -#include - -#include -#include -#include //TESTED_CLASS= //TESTED_FILES= @@ -55,62 +49,70 @@ extern bool qt_script_isJITEnabled(); QT_END_NAMESPACE -class tst_QScriptValue : public QObject -{ - Q_OBJECT - -public: - tst_QScriptValue(); - virtual ~tst_QScriptValue(); - -private slots: - void ctor(); - void engine(); - void toString(); - void toNumber(); - void toBoolean(); - void toBool(); - void toInteger(); - void toInt32(); - void toUInt32(); - void toUInt16(); - void toVariant(); - void toQObject(); - void toObject(); - void toDateTime(); - void toRegExp(); - void instanceOf(); - void isArray(); - void isDate(); - void isError(); - void isRegExp(); - void getSetPrototype(); - void getSetScope(); - void getSetProperty(); - void arrayElementGetterSetter(); - void getSetData(); - void getSetScriptClass(); - void call(); - void construct(); - void lessThan(); - void equals(); - void strictlyEquals(); - void castToPointer(); - void prettyPrinter_data(); - void prettyPrinter(); - void engineDeleted(); - void valueOfWithClosure(); - void objectId(); -}; - tst_QScriptValue::tst_QScriptValue() + : engine(0) { } tst_QScriptValue::~tst_QScriptValue() { + delete engine; } +void tst_QScriptValue::dataHelper(InitDataFunction init, DefineDataFunction define) +{ + QTest::addColumn("__expression__"); + (this->*init)(); + QHash::const_iterator it; + for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) { + m_currentExpression = it.key(); + (this->*define)(it.key().toLatin1()); + } + m_currentExpression = QString(); +} + +QTestData &tst_QScriptValue::newRow(const char *tag) +{ + return QTest::newRow(tag) << m_currentExpression; +} + +void tst_QScriptValue::testHelper(TestFunction fun) +{ + QFETCH(QString, __expression__); + QScriptValue value = m_values.value(__expression__); + (this->*fun)(__expression__.toLatin1(), value); +} + +void tst_QScriptValue::assignAndCopyConstruct_initData() +{ + QTest::addColumn("dummy"); + initScriptValues(); +} + +void tst_QScriptValue::assignAndCopyConstruct_makeData(const char *expr) +{ + newRow(expr) << 0; +} + +void tst_QScriptValue::assignAndCopyConstruct_test(const char *, const QScriptValue &value) +{ + QScriptValue copy(value); + QCOMPARE(copy.strictlyEquals(value), !value.isNumber() || !qIsNaN(value.toNumber())); + QCOMPARE(copy.engine(), value.engine()); + + QScriptValue assigned = copy; + QCOMPARE(assigned.strictlyEquals(value), !copy.isNumber() || !qIsNaN(copy.toNumber())); + QCOMPARE(assigned.engine(), assigned.engine()); + + QScriptValue other(!value.toBool()); + assigned = other; + QVERIFY(!assigned.strictlyEquals(copy)); + QVERIFY(assigned.strictlyEquals(other)); + QCOMPARE(assigned.engine(), other.engine()); +} + +DEFINE_TEST_FUNCTION(assignAndCopyConstruct) + void tst_QScriptValue::ctor() { QScriptEngine eng; @@ -330,19 +332,12 @@ QVERIFY(QScriptValue(0, QString("ciao")).isString()); } -void tst_QScriptValue::engine() -{ - QScriptEngine eng; - QScriptValue object = eng.newObject(); - QCOMPARE(object.engine(), &eng); -} - static QScriptValue myFunction(QScriptContext *, QScriptEngine *eng) { return eng->undefinedValue(); } -void tst_QScriptValue::toString() +void tst_QScriptValue::toString_old() { QScriptEngine eng; @@ -456,7 +451,7 @@ QVERIFY(variant.toString().isEmpty()); } -void tst_QScriptValue::toNumber() +void tst_QScriptValue::toNumber_old() { QScriptEngine eng; @@ -529,7 +524,7 @@ } } -void tst_QScriptValue::toBoolean() // deprecated +void tst_QScriptValue::toBoolean_old() // deprecated { QScriptEngine eng; @@ -626,7 +621,7 @@ } } -void tst_QScriptValue::toBool() +void tst_QScriptValue::toBool_old() { QScriptEngine eng; @@ -723,7 +718,7 @@ } } -void tst_QScriptValue::toInteger() +void tst_QScriptValue::toInteger_old() { QScriptEngine eng; @@ -810,7 +805,7 @@ QCOMPARE(inv.toInteger(), 0.0); } -void tst_QScriptValue::toInt32() +void tst_QScriptValue::toInt32_old() { QScriptEngine eng; @@ -946,7 +941,7 @@ QCOMPARE(qscriptvalue_cast(inv), 0); } -void tst_QScriptValue::toUInt32() +void tst_QScriptValue::toUInt32_old() { QScriptEngine eng; @@ -1078,7 +1073,7 @@ QCOMPARE(qscriptvalue_cast(inv), quint32(0)); } -void tst_QScriptValue::toUInt16() +void tst_QScriptValue::toUInt16_old() { QScriptEngine eng; @@ -1239,7 +1234,7 @@ Q_DECLARE_METATYPE(QVariant) #endif -void tst_QScriptValue::toVariant() +void tst_QScriptValue::toVariant_old() { QScriptEngine eng; @@ -1346,7 +1341,7 @@ // unfortunately, this is necessary in order to do qscriptvalue_cast(...) Q_DECLARE_METATYPE(QPushButton*) -void tst_QScriptValue::toQObject() +void tst_QScriptValue::toQObject_old() { QScriptEngine eng; @@ -1541,7 +1536,7 @@ } } -void tst_QScriptValue::toDateTime() +void tst_QScriptValue::toDateTime_old() { QScriptEngine eng; QDateTime dt = eng.evaluate("new Date(0)").toDateTime(); @@ -1559,7 +1554,7 @@ QVERIFY(!eng.undefinedValue().toDateTime().isValid()); } -void tst_QScriptValue::toRegExp() +void tst_QScriptValue::toRegExp_old() { QScriptEngine eng; { @@ -1589,7 +1584,7 @@ QVERIFY(eng.undefinedValue().toRegExp().isEmpty()); } -void tst_QScriptValue::instanceOf() +void tst_QScriptValue::instanceOf_old() { QScriptEngine eng; QScriptValue obj = eng.newObject(); @@ -1625,7 +1620,7 @@ QCOMPARE(obj.instanceOf(otherEngine.globalObject().property("Object")), false); } -void tst_QScriptValue::isArray() +void tst_QScriptValue::isArray_old() { QScriptEngine eng; QVERIFY(eng.evaluate("[]").isArray()); @@ -1638,7 +1633,7 @@ QVERIFY(!eng.undefinedValue().isArray()); } -void tst_QScriptValue::isDate() +void tst_QScriptValue::isDate_old() { QScriptEngine eng; QVERIFY(eng.evaluate("new Date()").isDate()); @@ -1652,7 +1647,7 @@ QVERIFY(!eng.undefinedValue().isDate()); } -void tst_QScriptValue::isError() +void tst_QScriptValue::isError_old() { QStringList errors; errors << "Error" @@ -1677,7 +1672,7 @@ QVERIFY(!eng.evaluate("new Object()").isError()); } -void tst_QScriptValue::isRegExp() +void tst_QScriptValue::isRegExp_old() { QScriptEngine eng; QVERIFY(eng.evaluate("/foo/").isRegExp()); @@ -2576,6 +2571,10 @@ // call with something else as arguments QScriptValue ret5 = fun.call(QScriptValue(), QScriptValue(&eng, 123.0)); QCOMPARE(ret5.isError(), true); + // call with a non-array object as arguments + QScriptValue ret6 = fun.call(QScriptValue(), eng.globalObject()); + QVERIFY(ret6.isError()); + QCOMPARE(ret6.toString(), QString::fromLatin1("TypeError: Arguments must be an array")); } // calling things that are not functions @@ -2708,6 +2707,10 @@ // construct with something else as arguments QScriptValue ret5 = fun.construct(QScriptValue(&eng, 123.0)); QCOMPARE(ret5.isError(), true); + // construct with a non-array object as arguments + QScriptValue ret6 = fun.construct(eng.globalObject()); + QVERIFY(ret6.isError()); + QCOMPARE(ret6.toString(), QString::fromLatin1("TypeError: Arguments must be an array")); } // construct on things that are not functions @@ -2718,7 +2721,7 @@ QVERIFY(!QScriptValue(QScriptValue::NullValue).construct().isValid()); } -void tst_QScriptValue::lessThan() +void tst_QScriptValue::lessThan_old() { QScriptEngine eng; @@ -2812,7 +2815,7 @@ QCOMPARE(date1.lessThan(QScriptValue(&otherEngine, 123)), false); } -void tst_QScriptValue::equals() +void tst_QScriptValue::equals_old() { QScriptEngine eng; @@ -2907,7 +2910,7 @@ QScriptValue qobj1 = eng.newQObject(this); QScriptValue qobj2 = eng.newQObject(this); QScriptValue qobj3 = eng.newQObject(0); - QScriptValue qobj4 = eng.newQObject(new QObject()); + QScriptValue qobj4 = eng.newQObject(new QObject(), QScriptEngine::ScriptOwnership); QVERIFY(qobj1.equals(qobj2)); // compares the QObject pointers QVERIFY(!qobj2.equals(qobj4)); // compares the QObject pointers QVERIFY(!qobj2.equals(obj2)); // compares the QObject pointers @@ -3005,7 +3008,7 @@ QCOMPARE(date1.equals(QScriptValue(&otherEngine, 123)), false); } -void tst_QScriptValue::strictlyEquals() +void tst_QScriptValue::strictlyEquals_old() { QScriptEngine eng; @@ -3091,6 +3094,20 @@ QVERIFY(!falskt.strictlyEquals(null)); QVERIFY(!falskt.strictlyEquals(QScriptValue())); + QVERIFY(!QScriptValue(false).strictlyEquals(123)); + QVERIFY(!QScriptValue(QScriptValue::UndefinedValue).strictlyEquals(123)); + QVERIFY(!QScriptValue(QScriptValue::NullValue).strictlyEquals(123)); + QVERIFY(!QScriptValue(false).strictlyEquals("ciao")); + QVERIFY(!QScriptValue(QScriptValue::UndefinedValue).strictlyEquals("ciao")); + QVERIFY(!QScriptValue(QScriptValue::NullValue).strictlyEquals("ciao")); + QVERIFY(QScriptValue(&eng, "ciao").strictlyEquals("ciao")); + QVERIFY(QScriptValue("ciao").strictlyEquals(QScriptValue(&eng, "ciao"))); + QVERIFY(!QScriptValue("ciao").strictlyEquals(123)); + QVERIFY(!QScriptValue("ciao").strictlyEquals(QScriptValue(&eng, 123))); + QVERIFY(!QScriptValue(123).strictlyEquals("ciao")); + QVERIFY(!QScriptValue(123).strictlyEquals(QScriptValue(&eng, "ciao"))); + QVERIFY(!QScriptValue(&eng, 123).strictlyEquals("ciao")); + QScriptValue obj1 = eng.newObject(); QScriptValue obj2 = eng.newObject(); QCOMPARE(obj1.strictlyEquals(obj2), false); @@ -3442,4 +3459,3 @@ } QTEST_MAIN(tst_QScriptValue) -#include "tst_qscriptvalue.moc"