diff options
author | axis <qt-info@nokia.com> | 2010-03-22 09:24:51 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2010-03-22 09:24:51 (GMT) |
commit | e48850c6ec90cd5eaa95d07573c2afa1a1c4f67f (patch) | |
tree | c53fa338b532c986b4baa1b481e5406f2fa16b5a /tests/auto/qscriptclass | |
parent | 390d7f64d9afa288fb2c01fc70eddc8b1f5ff585 (diff) | |
parent | 7491a2ecfdd0fe883c72d2ee60ca72393c2990d9 (diff) | |
download | Qt-e48850c6ec90cd5eaa95d07573c2afa1a1c4f67f.zip Qt-e48850c6ec90cd5eaa95d07573c2afa1a1c4f67f.tar.gz Qt-e48850c6ec90cd5eaa95d07573c2afa1a1c4f67f.tar.bz2 |
Merge branch '4.6-s60' into 4.7-s60
Conflicts:
configure.exe
mkspecs/common/symbian/symbian.conf
src/gui/graphicsview/qgraphicswidget.h
src/gui/kernel/qapplication.cpp
src/gui/text/qtextlayout.cpp
src/openvg/qpixmapdata_vg.cpp
src/s60installs/s60installs.pro
tools/runonphone/main.cpp
tools/runonphone/serenum_unix.cpp
qtextlayout.cpp fixed up together with Eskil.
Kept the configure.exe from 4.7 without recompile.
Diffstat (limited to 'tests/auto/qscriptclass')
-rw-r--r-- | tests/auto/qscriptclass/tst_qscriptclass.cpp | 118 |
1 files changed, 116 insertions, 2 deletions
diff --git a/tests/auto/qscriptclass/tst_qscriptclass.cpp b/tests/auto/qscriptclass/tst_qscriptclass.cpp index aca33ce..b4dbe73 100644 --- a/tests/auto/qscriptclass/tst_qscriptclass.cpp +++ b/tests/auto/qscriptclass/tst_qscriptclass.cpp @@ -98,7 +98,12 @@ public: NotCallable, CallableReturnsSum, CallableReturnsArgument, - CallableReturnsInvalidVariant + CallableReturnsInvalidVariant, + CallableReturnsGlobalObject, + CallableReturnsThisObject, + CallableReturnsCallee, + CallableReturnsArgumentsObject, + CallableInitializesThisObject }; TestClass(QScriptEngine *engine); @@ -348,7 +353,7 @@ QVariant TestClass::extension(Extension extension, qsreal sum = 0; for (int i = 0; i < ctx->argumentCount(); ++i) sum += ctx->argument(i).toNumber(); - QScriptValueIterator it(ctx->thisObject()); + QScriptValueIterator it(ctx->callee()); while (it.hasNext()) { it.next(); sum += it.value().toNumber(); @@ -358,6 +363,17 @@ QVariant TestClass::extension(Extension extension, return qVariantFromValue(ctx->argument(0)); } else if (m_callableMode == CallableReturnsInvalidVariant) { return QVariant(); + } else if (m_callableMode == CallableReturnsGlobalObject) { + return qVariantFromValue(engine()->globalObject()); + } else if (m_callableMode == CallableReturnsThisObject) { + return qVariantFromValue(ctx->thisObject()); + } else if (m_callableMode == CallableReturnsCallee) { + return qVariantFromValue(ctx->callee()); + } else if (m_callableMode == CallableReturnsArgumentsObject) { + return qVariantFromValue(ctx->argumentsObject()); + } else if (m_callableMode == CallableInitializesThisObject) { + engine()->newQObject(ctx->thisObject(), engine()); + return QVariant(); } } else if (extension == HasInstance) { Q_ASSERT(m_hasInstance); @@ -797,9 +813,11 @@ void tst_QScriptClass::extension() QVERIFY(cls.supportsExtension(QScriptClass::Callable)); QScriptValue obj = eng.newObject(&cls); + eng.globalObject().setProperty("obj", obj); obj.setProperty("one", QScriptValue(&eng, 1)); obj.setProperty("two", QScriptValue(&eng, 2)); obj.setProperty("three", QScriptValue(&eng, 3)); + // From C++ cls.clearReceivedArgs(); { QScriptValueList args; @@ -810,8 +828,18 @@ void tst_QScriptClass::extension() QVERIFY(ret.isNumber()); QCOMPARE(ret.toNumber(), qsreal(15)); } + // From JS + cls.clearReceivedArgs(); + { + QScriptValue ret = eng.evaluate("obj(4, 5)"); + QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable); + QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>()); + QVERIFY(ret.isNumber()); + QCOMPARE(ret.toNumber(), qsreal(15)); + } cls.setCallableMode(TestClass::CallableReturnsArgument); + // From C++ cls.clearReceivedArgs(); { QScriptValue ret = obj.call(obj, QScriptValueList() << 123); @@ -843,6 +871,13 @@ void tst_QScriptClass::extension() QScriptValue ret = obj.call(obj, QScriptValueList() << QScriptValue()); QVERIFY(ret.isUndefined()); } + // From JS + cls.clearReceivedArgs(); + { + QScriptValue ret = eng.evaluate("obj(123)"); + QVERIFY(ret.isNumber()); + QCOMPARE(ret.toInt32(), 123); + } cls.setCallableMode(TestClass::CallableReturnsInvalidVariant); { @@ -850,13 +885,92 @@ void tst_QScriptClass::extension() QVERIFY(ret.isUndefined()); } + cls.setCallableMode(TestClass::CallableReturnsThisObject); + // From C++ + { + QScriptValue ret = obj.call(obj); + QVERIFY(ret.isObject()); + QVERIFY(ret.strictlyEquals(obj)); + } + // From JS + { + QScriptValue ret = eng.evaluate("obj()"); + QVERIFY(ret.isObject()); + QVERIFY(ret.strictlyEquals(eng.globalObject())); + } + + cls.setCallableMode(TestClass::CallableReturnsCallee); + // From C++ + { + QScriptValue ret = obj.call(); + QVERIFY(ret.isObject()); + QVERIFY(ret.strictlyEquals(obj)); + } + // From JS + { + QScriptValue ret = eng.evaluate("obj()"); + QVERIFY(ret.isObject()); + QVERIFY(ret.strictlyEquals(obj)); + } + + cls.setCallableMode(TestClass::CallableReturnsArgumentsObject); + // From C++ + { + QScriptValue ret = obj.call(obj, QScriptValueList() << 123); + QVERIFY(ret.isObject()); + QVERIFY(ret.property("length").isNumber()); + QCOMPARE(ret.property("length").toInt32(), 1); + QVERIFY(ret.property(0).isNumber()); + QCOMPARE(ret.property(0).toInt32(), 123); + } + // From JS + { + QScriptValue ret = eng.evaluate("obj(123)"); + QVERIFY(ret.isObject()); + QVERIFY(ret.property("length").isNumber()); + QCOMPARE(ret.property("length").toInt32(), 1); + QVERIFY(ret.property(0).isNumber()); + QCOMPARE(ret.property(0).toInt32(), 123); + } + // construct() + // From C++ cls.clearReceivedArgs(); + cls.setCallableMode(TestClass::CallableReturnsGlobalObject); { QScriptValue ret = obj.construct(); QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable); QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>()); QVERIFY(ret.isObject()); + QVERIFY(ret.strictlyEquals(eng.globalObject())); + } + // From JS + cls.clearReceivedArgs(); + { + QScriptValue ret = eng.evaluate("new obj()"); + QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable); + QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>()); + QVERIFY(ret.isObject()); + QVERIFY(ret.strictlyEquals(eng.globalObject())); + } + // From C++ + cls.clearReceivedArgs(); + cls.setCallableMode(TestClass::CallableInitializesThisObject); + { + QScriptValue ret = obj.construct(); + QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable); + QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>()); + QVERIFY(ret.isQObject()); + QCOMPARE(ret.toQObject(), (QObject*)&eng); + } + // From JS + cls.clearReceivedArgs(); + { + QScriptValue ret = eng.evaluate("new obj()"); + QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable); + QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>()); + QVERIFY(ret.isQObject()); + QCOMPARE(ret.toQObject(), (QObject*)&eng); } } // HasInstance |