summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptcontext
diff options
context:
space:
mode:
authorJedrzej Nowacki <jedrzej.nowacki@nokia.com>2011-02-09 08:00:51 (GMT)
committerJedrzej Nowacki <jedrzej.nowacki@nokia.com>2011-02-09 08:09:26 (GMT)
commitebfbc5c03f689304fdd250fba46bbbfffb9af254 (patch)
treefaf01eaa0d08b0a2dd42f5e8276e32a1ff6f38c1 /tests/auto/qscriptcontext
parentb0c109ff2479dd8f4474b6c5ad537168224a5dc4 (diff)
downloadQt-ebfbc5c03f689304fdd250fba46bbbfffb9af254.zip
Qt-ebfbc5c03f689304fdd250fba46bbbfffb9af254.tar.gz
Qt-ebfbc5c03f689304fdd250fba46bbbfffb9af254.tar.bz2
Add new tests cases to context tests.
New tests mostly check thisObject and globalObject behavior in conjunction with popScope and pushScope functions. Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto/qscriptcontext')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index eee67df..1332a22 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -91,6 +91,11 @@ private slots:
void pushAndPopScope_globalContext();
void pushAndPopScope_globalContext2();
void getSetActivationObject_globalContext();
+ void pushScopeEvaluate();
+ void pushScopeCall();
+ void popScopeSimple();
+ void pushAndPopGlobalObjectSimple();
+ void pushAndPopIterative();
void getSetActivationObject_customContext();
void inheritActivationAndThisObject();
void toString();
@@ -1006,6 +1011,72 @@ void tst_QScriptContext::scopeChain_withStatement()
}
}
+void tst_QScriptContext::pushScopeEvaluate()
+{
+ QScriptEngine engine;
+ QScriptValue object = engine.newObject();
+ object.setProperty("foo", 1234);
+ object.setProperty(1, 1234);
+ engine.currentContext()->pushScope(object);
+ object.setProperty("bar", 4321);
+ object.setProperty(2, 4321);
+ QVERIFY(engine.evaluate("foo").equals(1234));
+ QVERIFY(engine.evaluate("bar").equals(4321));
+}
+
+void tst_QScriptContext::pushScopeCall()
+{
+ QScriptEngine engine;
+ QScriptValue object = engine.globalObject();
+ QScriptValue thisObject = engine.newObject();
+ QScriptValue function = engine.evaluate("(function(property){return this[property]; })");
+ QVERIFY(function.isFunction());
+ object.setProperty("foo", 1234);
+ thisObject.setProperty("foo", "foo");
+ engine.currentContext()->pushScope(object);
+ object.setProperty("bar", 4321);
+ thisObject.setProperty("bar", "bar");
+ QVERIFY(function.call(QScriptValue(), QScriptValueList() << "foo").equals(1234));
+ QVERIFY(function.call(QScriptValue(), QScriptValueList() << "bar").equals(4321));
+ QVERIFY(function.call(thisObject, QScriptValueList() << "foo").equals("foo"));
+ QVERIFY(function.call(thisObject, QScriptValueList() << "bar").equals("bar"));
+}
+
+void tst_QScriptContext::popScopeSimple()
+{
+ QScriptEngine engine;
+ QScriptValue object = engine.newObject();
+ QScriptValue globalObject = engine.globalObject();
+ engine.currentContext()->pushScope(object);
+ QVERIFY(engine.currentContext()->popScope().strictlyEquals(object));
+ QVERIFY(engine.globalObject().strictlyEquals(globalObject));
+}
+
+void tst_QScriptContext::pushAndPopGlobalObjectSimple()
+{
+ QScriptEngine engine;
+ QScriptValue globalObject = engine.globalObject();
+ engine.currentContext()->pushScope(globalObject);
+ QVERIFY(engine.currentContext()->popScope().strictlyEquals(globalObject));
+ QVERIFY(engine.globalObject().strictlyEquals(globalObject));
+}
+
+void tst_QScriptContext::pushAndPopIterative()
+{
+ QScriptEngine engine;
+ for (uint repeat = 0; repeat < 2; ++repeat) {
+ for (uint i = 1; i < 11; ++i) {
+ QScriptValue object = engine.newObject();
+ object.setProperty("x", i + 10 * repeat);
+ engine.currentContext()->pushScope(object);
+ }
+ for (uint i = 10; i > 0; --i) {
+ QScriptValue object = engine.currentContext()->popScope();
+ QVERIFY(object.property("x").equals(i + 10 * repeat));
+ }
+ }
+}
+
void tst_QScriptContext::pushAndPopScope_globalContext()
{
QScriptEngine eng;