diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-10-29 13:15:45 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-10-29 14:06:20 (GMT) |
commit | bd3c35cf1cbdbde16df9357a08b8b45a96fa3a5e (patch) | |
tree | a9173bfdcad12dd1d8dee1a9c7f4940ee1a1f74c /tests | |
parent | bf8a9dc1248083dfb0ce5599b11af1727d349631 (diff) | |
download | Qt-bd3c35cf1cbdbde16df9357a08b8b45a96fa3a5e.zip Qt-bd3c35cf1cbdbde16df9357a08b8b45a96fa3a5e.tar.gz Qt-bd3c35cf1cbdbde16df9357a08b8b45a96fa3a5e.tar.bz2 |
Improve QtScript test coverage
Based on BullsEye coverage reports.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qscriptable/tst_qscriptable.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qscriptclass/tst_qscriptclass.cpp | 40 | ||||
-rw-r--r-- | tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 38 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 141 | ||||
-rw-r--r-- | tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp | 100 | ||||
-rw-r--r-- | tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp | 21 |
6 files changed, 332 insertions, 12 deletions
diff --git a/tests/auto/qscriptable/tst_qscriptable.cpp b/tests/auto/qscriptable/tst_qscriptable.cpp index 3c781b1..86dd80e 100644 --- a/tests/auto/qscriptable/tst_qscriptable.cpp +++ b/tests/auto/qscriptable/tst_qscriptable.cpp @@ -131,7 +131,7 @@ QScriptValue MyScriptable::getArguments() int MyScriptable::getArgumentCount() { - return context()->argumentCount(); + return argumentCount(); } void MyScriptable::foo() @@ -283,6 +283,8 @@ void tst_QScriptable::engine() void tst_QScriptable::thisObject() { + QVERIFY(!m_scriptable.thisObject().isValid()); + m_engine.evaluate("o = { }"); { QScriptValue ret = m_engine.evaluate("o.__proto__ = scriptable;" diff --git a/tests/auto/qscriptclass/tst_qscriptclass.cpp b/tests/auto/qscriptclass/tst_qscriptclass.cpp index b4dbe73..2c669f3 100644 --- a/tests/auto/qscriptclass/tst_qscriptclass.cpp +++ b/tests/auto/qscriptclass/tst_qscriptclass.cpp @@ -68,6 +68,7 @@ private slots: void getAndSetProperty(); void enumerate(); void extension(); + void defaultImplementations(); }; tst_QScriptClass::tst_QScriptClass() @@ -603,6 +604,8 @@ void tst_QScriptClass::newInstance() QVERIFY(obj2.data().strictlyEquals(num)); QVERIFY(obj2.prototype().strictlyEquals(cls.prototype())); QCOMPARE(obj2.scriptClass(), (QScriptClass*)&cls); + QVERIFY(!obj2.equals(obj1)); + QVERIFY(!obj2.strictlyEquals(obj1)); QScriptValue obj3 = eng.newObject(); QCOMPARE(obj3.scriptClass(), (QScriptClass*)0); @@ -730,6 +733,14 @@ void tst_QScriptClass::getAndSetProperty() QCOMPARE(cls.lastPropertyId(), foo2Id); } + // attempt to delete custom property + obj1.setProperty(foo2, QScriptValue()); + // delete real property + obj1.setProperty(foo, QScriptValue()); + QVERIFY(!obj1.property(foo).isValid()); + obj1.setProperty(foo, num); + QVERIFY(obj1.property(foo).equals(num)); + // remove script class; normal properties should remain obj1.setScriptClass(0); QCOMPARE(obj1.scriptClass(), (QScriptClass*)0); @@ -805,6 +816,7 @@ void tst_QScriptClass::extension() QCOMPARE((int)cls.lastExtensionType(), -1); QVERIFY(!obj.instanceOf(obj)); QCOMPARE((int)cls.lastExtensionType(), -1); + QVERIFY(!obj.construct().isValid()); } // Callable { @@ -1017,5 +1029,33 @@ void tst_QScriptClass::extension() } } +void tst_QScriptClass::defaultImplementations() +{ + QScriptEngine eng; + + QScriptClass defaultClass(&eng); + QCOMPARE(defaultClass.engine(), &eng); + QVERIFY(!defaultClass.prototype().isValid()); + QCOMPARE(defaultClass.name(), QString()); + + QScriptValue obj = eng.newObject(&defaultClass); + QCOMPARE(obj.scriptClass(), &defaultClass); + + QScriptString name = eng.toStringHandle("foo"); + uint id = -1; + QCOMPARE(defaultClass.queryProperty(obj, name, QScriptClass::HandlesReadAccess, &id), QScriptClass::QueryFlags(0)); + QVERIFY(!defaultClass.property(obj, name, id).isValid()); + QCOMPARE(defaultClass.propertyFlags(obj, name, id), QScriptValue::PropertyFlags(0)); + defaultClass.setProperty(obj, name, id, 123); + QVERIFY(!obj.property(name).isValid()); + + QCOMPARE(defaultClass.newIterator(obj), (QScriptClassPropertyIterator*)0); + + QVERIFY(!defaultClass.supportsExtension(QScriptClass::Callable)); + QVERIFY(!defaultClass.supportsExtension(QScriptClass::HasInstance)); + QVERIFY(!defaultClass.extension(QScriptClass::Callable).isValid()); + QVERIFY(!defaultClass.extension(QScriptClass::HasInstance).isValid()); +} + QTEST_MAIN(tst_QScriptClass) #include "tst_qscriptclass.moc" diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index 617c183..99558eb 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -44,6 +44,7 @@ #include <QtScript/qscriptcontext.h> #include <QtScript/qscriptengine.h> +#include <QtScript/qscriptvalueiterator.h> //TESTED_CLASS= //TESTED_FILES= @@ -77,6 +78,7 @@ private slots: void scopeChain(); void pushAndPopScope(); void getSetActivationObject(); + void getSetActivationObject_customContext(); void inheritActivationAndThisObject(); void toString(); void calledAsConstructor(); @@ -513,8 +515,30 @@ void tst_QScriptContext::pushAndPopContext() QScriptContext *ctx3 = eng.pushContext(); ctx3->activationObject().setProperty("foo", QScriptValue(&eng, 123)); QVERIFY(eng.evaluate("foo").strictlyEquals(QScriptValue(&eng, 123))); + QCOMPARE(ctx3->activationObject().propertyFlags("foo"), QScriptValue::PropertyFlags(0)); + + ctx3->activationObject().setProperty(4, 456); + QVERIFY(ctx3->activationObject().property(4, QScriptValue::ResolveLocal).equals(456)); + eng.evaluate("var bar = 'ciao'"); QVERIFY(ctx3->activationObject().property("bar", QScriptValue::ResolveLocal).strictlyEquals(QScriptValue(&eng, "ciao"))); + + ctx3->activationObject().setProperty("baz", 789, QScriptValue::ReadOnly); + QVERIFY(eng.evaluate("baz").equals(789)); + QCOMPARE(ctx3->activationObject().propertyFlags("baz"), QScriptValue::ReadOnly); + + QSet<QString> activationPropertyNames; + QScriptValueIterator it(ctx3->activationObject()); + while (it.hasNext()) { + it.next(); + activationPropertyNames.insert(it.name()); + } + QCOMPARE(activationPropertyNames.size(), 4); + QVERIFY(activationPropertyNames.contains("foo")); + QVERIFY(activationPropertyNames.contains("4")); + QVERIFY(activationPropertyNames.contains("bar")); + QVERIFY(activationPropertyNames.contains("baz")); + eng.popContext(); } @@ -1054,6 +1078,20 @@ void tst_QScriptContext::getSetActivationObject() } } +void tst_QScriptContext::getSetActivationObject_customContext() +{ + QScriptEngine eng; + QScriptContext *ctx = eng.pushContext(); + QVERIFY(ctx->activationObject().isObject()); + QScriptValue act = eng.newObject(); + ctx->setActivationObject(act); + QVERIFY(ctx->activationObject().equals(act)); + eng.evaluate("var foo = 123"); + QCOMPARE(act.property("foo").toInt32(), 123); + eng.popContext(); + QCOMPARE(act.property("foo").toInt32(), 123); +} + static QScriptValue myEval(QScriptContext *ctx, QScriptEngine *eng) { QString code = ctx->argument(0).toString(); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 3a376ec..034512f 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -130,6 +130,7 @@ private slots: void gcWithNestedDataStructure(); void processEventsWhileRunning(); void throwErrorFromProcessEvents(); + void disableProcessEventsInterval(); void stacktrace(); void numberParsing_data(); void numberParsing(); @@ -170,6 +171,7 @@ private slots: void evaluateProgram(); void collectGarbageAfterConnect(); void promoteThisObjectToQObjectInConstructor(); + void scriptValueFromQMetaObject(); void qRegExpInport_data(); void qRegExpInport(); @@ -457,11 +459,13 @@ void tst_QScriptEngine::newVariant() // replace value of existing object { QScriptValue object = eng.newVariant(QVariant(123)); - QScriptValue ret = eng.newVariant(object, QVariant(456)); - QVERIFY(ret.isValid()); - QVERIFY(ret.strictlyEquals(object)); - QVERIFY(ret.isVariant()); - QCOMPARE(ret.toVariant(), QVariant(456)); + for (int x = 0; x < 2; ++x) { + QScriptValue ret = eng.newVariant(object, QVariant(456)); + QVERIFY(ret.isValid()); + QVERIFY(ret.strictlyEquals(object)); + QVERIFY(ret.isVariant()); + QCOMPARE(ret.toVariant(), QVariant(456)); + } } // valueOf() and toString() @@ -496,6 +500,19 @@ void tst_QScriptEngine::newVariant() QVERIFY(value.strictlyEquals(object)); QCOMPARE(object.toString(), QString::fromLatin1("QVariant(QPoint)")); } + + { + QVariant var(456); + QScriptValue ret = eng.newVariant(123, var); + QVERIFY(ret.isVariant()); + QCOMPARE(ret.toVariant(), var); + } + + { + QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::newVariant(): changing class of non-QScriptObject not supported"); + QScriptValue ret = eng.newVariant(eng.newArray(), 123); + QVERIFY(!ret.isValid()); + } } void tst_QScriptEngine::newRegExp() @@ -734,12 +751,14 @@ void tst_QScriptEngine::newQObject() QScriptValue object = eng.newVariant(123); QScriptValue originalProto = object.prototype(); QObject otherQObject; - QScriptValue ret = eng.newQObject(object, &otherQObject); - QVERIFY(ret.isValid()); - QVERIFY(ret.isQObject()); - QVERIFY(ret.strictlyEquals(object)); - QCOMPARE(ret.toQObject(), (QObject *)&otherQObject); - QVERIFY(ret.prototype().strictlyEquals(originalProto)); + for (int x = 0; x < 2; ++x) { + QScriptValue ret = eng.newQObject(object, &otherQObject); + QVERIFY(ret.isValid()); + QVERIFY(ret.isQObject()); + QVERIFY(ret.strictlyEquals(object)); + QCOMPARE(ret.toQObject(), (QObject *)&otherQObject); + QVERIFY(ret.prototype().strictlyEquals(originalProto)); + } } // calling newQObject() several times with same object @@ -794,6 +813,18 @@ void tst_QScriptEngine::newQObject() eng.setDefaultPrototype(qMetaTypeId<QObject*>(), oldQObjectProto); eng.setDefaultPrototype(typeId, QScriptValue()); } + + { + QScriptValue ret = eng.newQObject(123, this); + QVERIFY(ret.isQObject()); + QCOMPARE(ret.toQObject(), this); + } + + { + QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::newQObject(): changing class of non-QScriptObject not supported"); + QScriptValue ret = eng.newQObject(eng.newArray(), this); + QVERIFY(!ret.isValid()); + } } QT_BEGIN_NAMESPACE @@ -982,6 +1013,11 @@ void tst_QScriptEngine::getSetGlobalObject() QCOMPARE(glob.prototype().isObject(), true); QCOMPARE(glob.prototype().strictlyEquals(eng.evaluate("Object.prototype")), true); + eng.setGlobalObject(glob); + QVERIFY(eng.globalObject().equals(glob)); + eng.setGlobalObject(123); + QVERIFY(eng.globalObject().equals(glob)); + QScriptValue obj = eng.newObject(); eng.setGlobalObject(obj); QVERIFY(eng.globalObject().strictlyEquals(obj)); @@ -1031,6 +1067,28 @@ void tst_QScriptEngine::getSetGlobalObject() QScriptValue ret = eng.evaluate("(function() { return this; })()"); QVERIFY(ret.strictlyEquals(obj)); } + + // Delete property. + { + QScriptValue ret = eng.evaluate("delete foo"); + QVERIFY(ret.isBool()); + QVERIFY(ret.toBool()); + QVERIFY(!obj.property("foo").isValid()); + } + + // Getter/setter property. + QVERIFY(eng.evaluate("this.__defineGetter__('oof', function() { return this.bar; })").isUndefined()); + QVERIFY(eng.evaluate("this.__defineSetter__('oof', function(v) { this.bar = v; })").isUndefined()); + QVERIFY(eng.evaluate("this.__lookupGetter__('oof')").isFunction()); + QVERIFY(eng.evaluate("this.__lookupSetter__('oof')").isFunction()); + eng.evaluate("oof = 123"); + QVERIFY(eng.evaluate("oof").equals(obj.property("bar"))); + + // Enumeration. + { + QScriptValue ret = eng.evaluate("a = []; for (var p in this) a.push(p); a"); + QCOMPARE(ret.toString(), QString::fromLatin1("bar,baz,oof,p,a")); + } } static QScriptValue getSetFoo(QScriptContext *ctx, QScriptEngine *) @@ -2257,6 +2315,8 @@ void tst_QScriptEngine::valueConversion() QEXPECT_FAIL("", "QTBUG-6136: JSC-based back-end doesn't preserve QRegExp::minimal (always false)", Continue); QCOMPARE(val.toRegExp().isMinimal(), in.isMinimal()); } + + QCOMPARE(qscriptvalue_cast<QVariant>(QScriptValue(123)), QVariant(123)); } void tst_QScriptEngine::qScriptValueFromValue_noEngine() @@ -2701,6 +2761,19 @@ void tst_QScriptEngine::throwErrorFromProcessEvents() QCOMPARE(ret.toString(), QString::fromLatin1("Error: Killed")); } +void tst_QScriptEngine::disableProcessEventsInterval() +{ + QScriptEngine eng; + eng.setProcessEventsInterval(100); + QCOMPARE(eng.processEventsInterval(), 100); + eng.setProcessEventsInterval(0); + QCOMPARE(eng.processEventsInterval(), 0); + eng.setProcessEventsInterval(-1); + QCOMPARE(eng.processEventsInterval(), -1); + eng.setProcessEventsInterval(-100); + QCOMPARE(eng.processEventsInterval(), -100); +} + void tst_QScriptEngine::stacktrace() { QString script = QString::fromLatin1( @@ -4529,6 +4602,17 @@ void tst_QScriptEngine::installTranslatorFunctions() QVERIFY(ret.isString()); QCOMPARE(ret.toString(), QString::fromLatin1("foobar")); } + { + QScriptValue ret = eng.evaluate("'foo%0'.arg(123)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("foo123")); + } + { + // Maybe this should throw an error? + QScriptValue ret = eng.evaluate("'foo%0'.arg()"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString()); + } { QScriptValue ret = eng.evaluate("qsTrId('foo')"); @@ -4540,6 +4624,7 @@ void tst_QScriptEngine::installTranslatorFunctions() QVERIFY(ret.isString()); QCOMPARE(ret.toString(), QString::fromLatin1("foo")); } + QVERIFY(eng.evaluate("QT_TRID_NOOP()").isUndefined()); } static QScriptValue callQsTr(QScriptContext *ctx, QScriptEngine *eng) @@ -4574,9 +4659,14 @@ void tst_QScriptEngine::translateScript() QCOMPARE(engine.evaluate("eval('qsTranslate(\\'FooContext\\', \\'Goodbye\\')')", fileName).toString(), QString::fromLatin1("Farvel")); QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'UnicodeUTF8')", fileName).toString(), QString::fromLatin1("Farvel")); + QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'CodecForTr')", fileName).toString(), QString::fromLatin1("Farvel")); + + QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'UnicodeUTF8', 42)", fileName).toString(), QString::fromLatin1("Goodbye")); QCOMPARE(engine.evaluate("qsTr('One', 'not the same one')", fileName).toString(), QString::fromLatin1("Enda en")); + QCOMPARE(engine.evaluate("qsTr('One', 'not the same one', 42)", fileName).toString(), QString::fromLatin1("One")); + QVERIFY(engine.evaluate("QT_TR_NOOP()").isUndefined()); QCOMPARE(engine.evaluate("QT_TR_NOOP('One')").toString(), QString::fromLatin1("One")); @@ -4645,6 +4735,7 @@ void tst_QScriptEngine::translateWithInvalidArgs_data() QTest::newRow("qsTranslate()") << "qsTranslate()" << "Error: qsTranslate() requires at least two arguments"; QTest::newRow("qsTranslate('foo')") << "qsTranslate('foo')" << "Error: qsTranslate() requires at least two arguments"; + QTest::newRow("qsTranslate(123, 'foo')") << "qsTranslate(123, 'foo')" << "Error: qsTranslate(): first argument (context) must be a string"; QTest::newRow("qsTranslate('foo', 123)") << "qsTranslate('foo', 123)" << "Error: qsTranslate(): second argument (text) must be a string"; QTest::newRow("qsTranslate('foo', 'bar', 123)") << "qsTranslate('foo', 'bar', 123)" << "Error: qsTranslate(): third argument (comment) must be a string"; QTest::newRow("qsTranslate('foo', 'bar', 'baz', 123)") << "qsTranslate('foo', 'bar', 'baz', 123)" << "Error: qsTranslate(): fourth argument (encoding) must be a string"; @@ -5108,6 +5199,10 @@ void tst_QScriptEngine::qRegExpInport_data() QTest::newRow("aaa") << QRegExp("a{2,5}") << "aAaAaaaaaAa"; QTest::newRow("aaa minimal") << minimal(QRegExp("a{2,5}")) << "aAaAaaaaaAa"; QTest::newRow("minimal") << minimal(QRegExp(".*\\} [*8]")) << "}?} ?} *"; + QTest::newRow(".? minimal") << minimal(QRegExp(".?")) << ".?"; + QTest::newRow(".+ minimal") << minimal(QRegExp(".+")) << ".+"; + QTest::newRow("[.?] minimal") << minimal(QRegExp("[.?]")) << ".?"; + QTest::newRow("[.+] minimal") << minimal(QRegExp("[.+]")) << ".+"; } void tst_QScriptEngine::qRegExpInport() @@ -5452,5 +5547,29 @@ void tst_QScriptEngine::newGrowingStaticScopeObject() eng.popContext(); } +Q_SCRIPT_DECLARE_QMETAOBJECT(QStandardItemModel, QObject*) + +void tst_QScriptEngine::scriptValueFromQMetaObject() +{ + QScriptEngine eng; + { + QScriptValue meta = eng.scriptValueFromQMetaObject<QScriptEngine>(); + QVERIFY(meta.isQMetaObject()); + QCOMPARE(meta.toQMetaObject(), &QScriptEngine::staticMetaObject); + // Because of missing Q_SCRIPT_DECLARE_QMETAOBJECT() for QScriptEngine. + QVERIFY(!meta.construct().isValid()); + } + { + QScriptValue meta = eng.scriptValueFromQMetaObject<QStandardItemModel>(); + QVERIFY(meta.isQMetaObject()); + QCOMPARE(meta.toQMetaObject(), &QStandardItemModel::staticMetaObject); + QScriptValue obj = meta.construct(QScriptValueList() << eng.newQObject(&eng)); + QVERIFY(obj.isQObject()); + QStandardItemModel *model = qobject_cast<QStandardItemModel*>(obj.toQObject()); + QVERIFY(model != 0); + QCOMPARE(model->parent(), (QObject*)&eng); + } +} + QTEST_MAIN(tst_QScriptEngine) #include "tst_qscriptengine.moc" diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp index 0d57f0c..1562118 100644 --- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp +++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp @@ -329,6 +329,18 @@ public: { m_qtFunctionInvoked = 58; m_actuals << int(arg); return arg; } Q_INVOKABLE MyQObject::Ability myInvokableWithQualifiedFlagsArg(MyQObject::Ability arg) { m_qtFunctionInvoked = 59; m_actuals << int(arg); return arg; } + Q_INVOKABLE QWidget *myInvokableWithQWidgetStarArg(QWidget *arg) + { m_qtFunctionInvoked = 63; m_actuals << qVariantFromValue((QWidget*)arg); return arg; } + Q_INVOKABLE short myInvokableWithShortArg(short arg) + { m_qtFunctionInvoked = 64; m_actuals << qVariantFromValue(arg); return arg; } + Q_INVOKABLE unsigned short myInvokableWithUShortArg(unsigned short arg) + { m_qtFunctionInvoked = 65; m_actuals << qVariantFromValue(arg); return arg; } + Q_INVOKABLE char myInvokableWithCharArg(char arg) + { m_qtFunctionInvoked = 66; m_actuals << qVariantFromValue(arg); return arg; } + Q_INVOKABLE unsigned char myInvokableWithUCharArg(unsigned char arg) + { m_qtFunctionInvoked = 67; m_actuals << qVariantFromValue(arg); return arg; } + Q_INVOKABLE qulonglong myInvokableWithULonglongArg(qulonglong arg) + { m_qtFunctionInvoked = 68; m_actuals << qVariantFromValue(arg); return arg; } Q_INVOKABLE QObjectList findObjects() const { return findChildren<QObject *>(); } @@ -394,6 +406,8 @@ public Q_SLOTS: { m_qtFunctionInvoked = 32; m_actuals << arg; } void myOverloadedSlot(const QDate &arg) { m_qtFunctionInvoked = 33; m_actuals << arg; } + void myOverloadedSlot(const QTime &arg) + { m_qtFunctionInvoked = 69; m_actuals << arg; } void myOverloadedSlot(const QRegExp &arg) { m_qtFunctionInvoked = 34; m_actuals << arg; } void myOverloadedSlot(const QVariant &arg) @@ -519,6 +533,7 @@ private slots: void callQtInvokable(); void connectAndDisconnect(); void connectAndDisconnectWithBadArgs(); + void connectAndDisconnect_senderDeleted(); void cppConnectAndDisconnect(); void classEnums(); void classConstructor(); @@ -1361,6 +1376,17 @@ void tst_QScriptExtQObject::callQtInvokable() m_myObject->resetQtFunctionInvoked(); { + QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQWidgetStarArg(null)"); + QVERIFY(ret.isNull()); + QCOMPARE(m_myObject->qtFunctionInvoked(), 63); + QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); + QVariant v = m_myObject->qtFunctionActuals().at(0); + QCOMPARE(v.userType(), int(QMetaType::QWidgetStar)); + QCOMPARE(qvariant_cast<QWidget*>(v), (QObject *)0); + } + + m_myObject->resetQtFunctionInvoked(); + { // no implicit conversion from integer to QObject* QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQObjectStarArg(123)"); QCOMPARE(ret.isError(), true); @@ -1368,6 +1394,61 @@ void tst_QScriptExtQObject::callQtInvokable() m_myObject->resetQtFunctionInvoked(); { + QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithShortArg(123)"); + QVERIFY(ret.isNumber()); + QCOMPARE(m_myObject->qtFunctionInvoked(), 64); + QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); + QVariant v = m_myObject->qtFunctionActuals().at(0); + QCOMPARE(v.userType(), int(QMetaType::Short)); + QCOMPARE(qvariant_cast<short>(v), short(123)); + } + + m_myObject->resetQtFunctionInvoked(); + { + QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithUShortArg(123)"); + QVERIFY(ret.isNumber()); + QCOMPARE(m_myObject->qtFunctionInvoked(), 65); + QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); + QVariant v = m_myObject->qtFunctionActuals().at(0); + QCOMPARE(v.userType(), int(QMetaType::UShort)); + QCOMPARE(qvariant_cast<ushort>(v), ushort(123)); + } + + m_myObject->resetQtFunctionInvoked(); + { + QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithCharArg(123)"); + QVERIFY(ret.isNumber()); + QCOMPARE(m_myObject->qtFunctionInvoked(), 66); + QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); + QVariant v = m_myObject->qtFunctionActuals().at(0); + QCOMPARE(v.userType(), int(QMetaType::Char)); + QCOMPARE(qvariant_cast<char>(v), char(123)); + } + + m_myObject->resetQtFunctionInvoked(); + { + QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithUCharArg(123)"); + QVERIFY(ret.isNumber()); + QCOMPARE(m_myObject->qtFunctionInvoked(), 67); + QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); + QVariant v = m_myObject->qtFunctionActuals().at(0); + QCOMPARE(v.userType(), int(QMetaType::UChar)); + QCOMPARE(qvariant_cast<uchar>(v), uchar(123)); + } + + m_myObject->resetQtFunctionInvoked(); + { + QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithULonglongArg(123)"); + QVERIFY(ret.isNumber()); + QCOMPARE(m_myObject->qtFunctionInvoked(), 68); + QCOMPARE(m_myObject->qtFunctionActuals().size(), 1); + QVariant v = m_myObject->qtFunctionActuals().at(0); + QCOMPARE(v.userType(), int(QMetaType::ULongLong)); + QCOMPARE(qvariant_cast<qulonglong>(v), qulonglong(123)); + } + + m_myObject->resetQtFunctionInvoked(); + { QScriptValue fun = m_engine->evaluate("myObject.myInvokableWithQBrushArg"); QVERIFY(fun.isFunction()); QColor color(10, 20, 30, 40); @@ -1916,6 +1997,25 @@ void tst_QScriptExtQObject::connectAndDisconnectWithBadArgs() } } +void tst_QScriptExtQObject::connectAndDisconnect_senderDeleted() +{ + QScriptEngine eng; + QObject *obj = new QObject; + eng.globalObject().setProperty("obj", eng.newQObject(obj)); + eng.evaluate("signal = obj.destroyed"); + delete obj; + { + QScriptValue ret = eng.evaluate("signal.connect(function(){})"); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Function.prototype.connect: cannot connect to deleted QObject")); + } + { + QScriptValue ret = eng.evaluate("signal.disconnect(function(){})"); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Function.prototype.discconnect: cannot disconnect from deleted QObject")); + } +} + void tst_QScriptExtQObject::cppConnectAndDisconnect() { QScriptEngine eng; diff --git a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp index 55773f0..df11537 100644 --- a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp +++ b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp @@ -71,6 +71,7 @@ private slots: void iterateString(); void iterateGetterSetter(); void assignObjectToIterator(); + void iterateNonObject(); }; tst_QScriptValueIterator::tst_QScriptValueIterator() @@ -583,5 +584,25 @@ void tst_QScriptValueIterator::assignObjectToIterator() QCOMPARE(it.name(), QString::fromLatin1("bar")); } +void tst_QScriptValueIterator::iterateNonObject() +{ + QScriptValueIterator it(123); + QVERIFY(!it.hasNext()); + it.next(); + QVERIFY(!it.hasPrevious()); + it.previous(); + it.toFront(); + it.toBack(); + it.name(); + it.scriptName(); + it.flags(); + it.value(); + it.setValue(1); + it.remove(); + QScriptValue num(5); + it = num; + QVERIFY(!it.hasNext()); +} + QTEST_MAIN(tst_QScriptValueIterator) #include "tst_qscriptvalueiterator.moc" |