531 void wrapOptions(); |
531 void wrapOptions(); |
532 void prototypes(); |
532 void prototypes(); |
533 void objectDeleted(); |
533 void objectDeleted(); |
534 void connectToDestroyedSignal(); |
534 void connectToDestroyedSignal(); |
535 void emitAfterReceiverDeleted(); |
535 void emitAfterReceiverDeleted(); |
|
536 void enumerateMetaObject(); |
536 |
537 |
537 private: |
538 private: |
538 QScriptEngine *m_engine; |
539 QScriptEngine *m_engine; |
539 MyQObject *m_myObject; |
540 MyQObject *m_myObject; |
540 QScriptValue m_signalHandlerException; |
541 QScriptValue m_signalHandlerException; |
3041 QCOMPARE(signalHandlerExceptionSpy.count(), 0); |
3042 QCOMPARE(signalHandlerExceptionSpy.count(), 0); |
3042 QVERIFY(!m_engine->hasUncaughtException()); |
3043 QVERIFY(!m_engine->hasUncaughtException()); |
3043 } |
3044 } |
3044 } |
3045 } |
3045 |
3046 |
|
3047 void tst_QScriptExtQObject::enumerateMetaObject() |
|
3048 { |
|
3049 QScriptValue myClass = m_engine->newQMetaObject(m_myObject->metaObject(), m_engine->undefinedValue()); |
|
3050 |
|
3051 QStringList expectedNames; |
|
3052 expectedNames << "FooPolicy" << "BarPolicy" << "BazPolicy" |
|
3053 << "FooStrategy" << "BarStrategy" << "BazStrategy" |
|
3054 << "NoAbility" << "FooAbility" << "BarAbility" << "BazAbility" << "AllAbility"; |
|
3055 |
|
3056 for (int x = 0; x < 2; ++x) { |
|
3057 QSet<QString> actualNames; |
|
3058 if (x == 0) { |
|
3059 // From C++ |
|
3060 QScriptValueIterator it(myClass); |
|
3061 while (it.hasNext()) { |
|
3062 it.next(); |
|
3063 actualNames.insert(it.name()); |
|
3064 } |
|
3065 } else { |
|
3066 // From JS |
|
3067 m_engine->globalObject().setProperty("MyClass", myClass); |
|
3068 QScriptValue ret = m_engine->evaluate("a=[]; for (var p in MyClass) if (MyClass.hasOwnProperty(p)) a.push(p); a"); |
|
3069 QVERIFY(ret.isArray()); |
|
3070 QStringList strings = qscriptvalue_cast<QStringList>(ret); |
|
3071 for (int i = 0; i < strings.size(); ++i) |
|
3072 actualNames.insert(strings.at(i)); |
|
3073 } |
|
3074 QCOMPARE(actualNames.size(), expectedNames.size()); |
|
3075 for (int i = 0; i < expectedNames.size(); ++i) |
|
3076 QVERIFY(actualNames.contains(expectedNames.at(i))); |
|
3077 } |
|
3078 } |
|
3079 |
3046 QTEST_MAIN(tst_QScriptExtQObject) |
3080 QTEST_MAIN(tst_QScriptExtQObject) |
3047 #include "tst_qscriptextqobject.moc" |
3081 #include "tst_qscriptextqobject.moc" |