diff options
Diffstat (limited to 'tests/auto/qscriptable/tst_qscriptable.cpp')
-rw-r--r-- | tests/auto/qscriptable/tst_qscriptable.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/tests/auto/qscriptable/tst_qscriptable.cpp b/tests/auto/qscriptable/tst_qscriptable.cpp index 96b54bf..54ffbe9 100644 --- a/tests/auto/qscriptable/tst_qscriptable.cpp +++ b/tests/auto/qscriptable/tst_qscriptable.cpp @@ -137,8 +137,8 @@ int MyScriptable::getArgumentCount() void MyScriptable::foo() { m_lastEngine = engine(); - QVERIFY(engine() != 0); - context()->throwError("MyScriptable.foo"); + if (engine()) + context()->throwError("MyScriptable.foo"); } void MyScriptable::evalIsBar() @@ -164,15 +164,15 @@ void MyScriptable::setOtherEngine() void MyScriptable::setX(int x) { m_lastEngine = engine(); - Q_ASSERT(engine()); - thisObject().setProperty("x", QScriptValue(engine(), x)); + if (engine()) + thisObject().setProperty("x", QScriptValue(engine(), x)); } void MyScriptable::setX(const QString &x) { m_lastEngine = engine(); - Q_ASSERT(engine()); - thisObject().setProperty("x", QScriptValue(engine(), x)); + if (engine()) + thisObject().setProperty("x", QScriptValue(engine(), x)); } void MyScriptable::setX2(int) @@ -291,6 +291,7 @@ void tst_QScriptable::thisObject() "o.setX(123);" "o.__proto__ = Object.prototype;" "o.x"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.strictlyEquals(QScriptValue(&m_engine, 123)), true); } { @@ -298,46 +299,55 @@ void tst_QScriptable::thisObject() "o.setX2(456);" "o.__proto__ = Object.prototype;" "o.x"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.strictlyEquals(QScriptValue(&m_engine, 456)), true); } m_engine.evaluate("o.__proto__ = scriptable"); { QScriptValue ret = m_engine.evaluate("o.isBar()"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.strictlyEquals(QScriptValue(&m_engine, false)), true); } { QScriptValue ret = m_engine.evaluate("o.toString = function() { return 'foo@bar'; }; o.isBar()"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.strictlyEquals(QScriptValue(&m_engine, true)), true); } // property getter { QScriptValue ret = m_engine.evaluate("scriptable.zab"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.isQObject(), true); QCOMPARE(ret.toQObject(), (QObject *)&m_scriptable); } { QScriptValue ret = m_engine.evaluate("scriptable[1]"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.isQObject(), true); QCOMPARE(ret.toQObject(), (QObject *)&m_scriptable); } { QScriptValue ret = m_engine.evaluate("o.zab"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.toQObject(), (QObject *)0); } // property setter { QScriptValue ret = m_engine.evaluate("scriptable.setZab(null)"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.isQObject(), true); QCOMPARE(ret.toQObject(), (QObject *)&m_scriptable); } { QVERIFY(!m_scriptable.oofThisObject().isValid()); m_engine.evaluate("o.oof = 123"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QVERIFY(m_scriptable.oofThisObject().strictlyEquals(m_engine.evaluate("o"))); } { m_engine.evaluate("scriptable.oof = 123"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QVERIFY(m_scriptable.oofThisObject().strictlyEquals(m_engine.evaluate("scriptable"))); } @@ -345,13 +355,17 @@ void tst_QScriptable::thisObject() { { QScriptValue ret = m_engine.evaluate("scriptable.sig.connect(o, scriptable.setX)"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QVERIFY(ret.isUndefined()); } QVERIFY(m_engine.evaluate("o.x").strictlyEquals(QScriptValue(&m_engine, 456))); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); m_scriptable.emitSig(654321); QVERIFY(m_engine.evaluate("o.x").strictlyEquals(QScriptValue(&m_engine, 654321))); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); { QScriptValue ret = m_engine.evaluate("scriptable.sig.disconnect(o, scriptable.setX)"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QVERIFY(ret.isUndefined()); } } @@ -383,6 +397,7 @@ void tst_QScriptable::arguments() void tst_QScriptable::throwError() { QScriptValue ret = m_engine.evaluate("scriptable.foo()"); + QCOMPARE(m_scriptable.lastEngine(), &m_engine); QCOMPARE(ret.isError(), true); QCOMPARE(ret.toString(), QString("Error: MyScriptable.foo")); } |