summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-08-26 14:46:10 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-08-26 17:03:38 (GMT)
commita3ceb3627c0270274caa5818d34689b7bd81e2e3 (patch)
treed78106c1e921e5dccbd688b0ff8f6115e2dc8671 /tests
parentf7709332d5ed16107e1bd8cbf07ab778e8f77217 (diff)
downloadQt-a3ceb3627c0270274caa5818d34689b7bd81e2e3.zip
Qt-a3ceb3627c0270274caa5818d34689b7bd81e2e3.tar.gz
Qt-a3ceb3627c0270274caa5818d34689b7bd81e2e3.tar.bz2
warn if QScriptValue::setScriptClass() is called on incompatible object
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index b125965..f9ce79f 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -2220,13 +2220,30 @@ void tst_QScriptValue::getSetScriptClass()
QCOMPARE(inv.scriptClass(), (QScriptClass*)0);
QScriptValue num(123);
QCOMPARE(num.scriptClass(), (QScriptClass*)0);
- QScriptValue obj = eng.newObject();
- QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
+
TestScriptClass testClass(&eng);
- obj.setScriptClass(&testClass);
- QCOMPARE(obj.scriptClass(), (QScriptClass*)&testClass);
- obj.setScriptClass(0);
- QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
+ // object created in C++ (newObject())
+ {
+ QScriptValue obj = eng.newObject();
+ QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
+ obj.setScriptClass(&testClass);
+ QCOMPARE(obj.scriptClass(), (QScriptClass*)&testClass);
+ obj.setScriptClass(0);
+ QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
+ }
+ // object created in JS
+ {
+ QScriptValue obj = eng.evaluate("new Object");
+ QVERIFY(!eng.hasUncaughtException());
+ QVERIFY(obj.isObject());
+ QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setScriptClass() failed: cannot change class of non-QScriptObject");
+ obj.setScriptClass(&testClass);
+ QEXPECT_FAIL("", "With JSC back-end, the class of a plain object created in JS can't be changed", Continue);
+ QCOMPARE(obj.scriptClass(), (QScriptClass*)&testClass);
+ obj.setScriptClass(0);
+ QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
+ }
}
static QScriptValue getArg(QScriptContext *ctx, QScriptEngine *)