summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptextqobject
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-03-24 13:05:38 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-03-24 13:09:32 (GMT)
commit9540e2b5d67af9a26f431c3e8636bff9946e88c4 (patch)
treeb040515bf5b541a82f8a3a8cdd809777ac2b71dd /tests/auto/qscriptextqobject
parent739f15838f73e84cb5e5ae58bb8adc267bc1b79c (diff)
downloadQt-9540e2b5d67af9a26f431c3e8636bff9946e88c4.zip
Qt-9540e2b5d67af9a26f431c3e8636bff9946e88c4.tar.gz
Qt-9540e2b5d67af9a26f431c3e8636bff9946e88c4.tar.bz2
QtScript: Add QObjectWrapOption for not exposing slots
This makes it possible to have a prototype object in place that handles all slot calls, rather than having the slots be recreated in each wrapper object. Task-number: QTBUG-3637 Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests/auto/qscriptextqobject')
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index b4ce561..c1496f7 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -533,6 +533,7 @@ private slots:
void objectDeleted();
void connectToDestroyedSignal();
void emitAfterReceiverDeleted();
+ void inheritedSlots();
private:
QScriptEngine *m_engine;
@@ -2658,6 +2659,21 @@ void tst_QScriptExtQObject::enumerate_data()
<< "mySignal()"
// slots
<< "mySlot()" << "myOtherSlot()");
+
+ QTest::newRow( "don't enumerate slots" )
+ << int(QScriptEngine::ExcludeSlots)
+ << (QStringList()
+ // meta-object-defined properties:
+ // inherited
+ << "objectName"
+ // non-inherited
+ << "p1" << "p2" << "p4" << "p6"
+ // dynamic properties
+ << "dp1" << "dp2" << "dp3"
+ // inherited signals
+ << "destroyed(QObject*)" << "destroyed()"
+ // signals
+ << "mySignal()");
}
void tst_QScriptExtQObject::enumerate()
@@ -2850,6 +2866,28 @@ void tst_QScriptExtQObject::wrapOptions()
QVERIFY(obj.property("intProperty").isValid());
QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember);
}
+ // exclude slots
+ {
+ QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSlots);
+ QVERIFY(!obj.property("deleteLater").isValid());
+ QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember));
+ QVERIFY(!obj.property("mySlot").isValid());
+ QVERIFY(!(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember));
+
+ QVERIFY(obj.property("myInvokable").isFunction());
+ QVERIFY(obj.propertyFlags("myInvokable") & QScriptValue::QObjectMember);
+
+ QVERIFY(obj.property("mySignal").isFunction());
+ QVERIFY(obj.propertyFlags("mySignal") & QScriptValue::QObjectMember);
+ QVERIFY(obj.property("destroyed").isFunction());
+ QVERIFY(obj.propertyFlags("destroyed") & QScriptValue::QObjectMember);
+
+ QVERIFY(obj.property("objectName").isValid());
+ QVERIFY(obj.propertyFlags("objectName") & QScriptValue::QObjectMember);
+ QVERIFY(obj.property("intProperty").isValid());
+ QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember);
+ }
// exclude all that we can
{
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership,
@@ -2871,6 +2909,33 @@ void tst_QScriptExtQObject::wrapOptions()
QCOMPARE(obj.property("child")
.strictlyEquals(QScriptValue(m_engine, 123)), true);
}
+ // exclude absolutely all that we can
+ {
+ QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSuperClassMethods
+ | QScriptEngine::ExcludeSuperClassProperties
+ | QScriptEngine::ExcludeChildObjects
+ | QScriptEngine::ExcludeSlots);
+ QVERIFY(!obj.property("deleteLater").isValid());
+ QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember));
+
+ QVERIFY(!obj.property("mySlot").isValid());
+ QVERIFY(!(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember));
+
+ QVERIFY(obj.property("mySignal").isFunction());
+ QVERIFY(obj.propertyFlags("mySignal") & QScriptValue::QObjectMember);
+
+ QVERIFY(obj.property("myInvokable").isFunction());
+ QVERIFY(obj.propertyFlags("myInvokable") & QScriptValue::QObjectMember);
+
+ QVERIFY(!obj.property("objectName").isValid());
+ QVERIFY(!(obj.propertyFlags("objectName") & QScriptValue::QObjectMember));
+
+ QVERIFY(obj.property("intProperty").isValid());
+ QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember);
+
+ QVERIFY(!obj.property("child").isValid());
+ }
delete child;
}
@@ -3043,5 +3108,27 @@ void tst_QScriptExtQObject::emitAfterReceiverDeleted()
}
}
+void tst_QScriptExtQObject::inheritedSlots()
+{
+ QScriptEngine eng;
+
+ QPushButton prototypeButton;
+ QScriptValue scriptPrototypeButton = eng.newQObject(&prototypeButton);
+
+ QPushButton button;
+ QScriptValue scriptButton = eng.newQObject(&button, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSlots);
+ scriptButton.setPrototype(scriptPrototypeButton);
+
+ QVERIFY(scriptButton.property("click").isFunction());
+ QVERIFY(scriptButton.property("click").strictlyEquals(scriptPrototypeButton.property("click")));
+
+ QSignalSpy prototypeButtonClickedSpy(&prototypeButton, SIGNAL(clicked()));
+ QSignalSpy buttonClickedSpy(&button, SIGNAL(clicked()));
+ scriptButton.property("click").call(scriptButton);
+ QCOMPARE(buttonClickedSpy.count(), 1);
+ QCOMPARE(prototypeButtonClickedSpy.count(), 0);
+}
+
QTEST_MAIN(tst_QScriptExtQObject)
#include "tst_qscriptextqobject.moc"