summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-05-03 12:06:09 +1000
committerRohan McGovern <rohan.mcgovern@nokia.com>2011-05-18 11:02:59 +1000
commitf9d986da6c6f7d12a9819dde7de6445e336d10a1 (patch)
treec6484315dab106630cde1d0021f6f8b7b2e51253 /tests/auto
parent4fa2c1676a76b6f16e25ed8938475613401c9b44 (diff)
downloadqtscript-f9d986da6c6f7d12a9819dde7de6445e336d10a1.tar.gz
Remove Q_ASSERT's from QScriptable autotest
The helper class expects a valid script engine to be available and attempted to verify this with Q_ASSERT (which does nothing in release mode) and QVERIFY (which should only be used directly in test functions). This commit makes the helper class avoid using an invalid engine and catches the problem later by verifying that the last script engine used by the scriptable class was valid. Change-Id: I849df32b141b7801b9b5a92f44ff325397e32f2d Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern (cherry picked from commit a7acd7e0a09d89647abb9ff91b1bcb55d1a7a849)
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qscriptable/tst_qscriptable.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/tests/auto/qscriptable/tst_qscriptable.cpp b/tests/auto/qscriptable/tst_qscriptable.cpp
index f5d36ea..97af050 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"));
}