summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-04-15 15:13:50 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-04-15 15:28:15 (GMT)
commit45ec585b46dc71de8a72e3bbc2401f50a2a42a8b (patch)
tree5f90801f73a1fe199e78a32fbb72c08771d9f0e7
parent43e9b68620e9de2cd6ec15cfd69b2327e8232fe2 (diff)
downloadQt-45ec585b46dc71de8a72e3bbc2401f50a2a42a8b.zip
Qt-45ec585b46dc71de8a72e3bbc2401f50a2a42a8b.tar.gz
Qt-45ec585b46dc71de8a72e3bbc2401f50a2a42a8b.tar.bz2
QtScript: Add autotest for enumeration of QMetaObject properties
The issue reported in QTBUG-3665 had been fixed since 4.6.0, but it went unnoticed that there had been a bug in the first place since there was no test for this behavior.
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index b4ce561..fddab3f 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 enumerateMetaObject();
private:
QScriptEngine *m_engine;
@@ -3043,5 +3044,38 @@ void tst_QScriptExtQObject::emitAfterReceiverDeleted()
}
}
+void tst_QScriptExtQObject::enumerateMetaObject()
+{
+ QScriptValue myClass = m_engine->newQMetaObject(m_myObject->metaObject(), m_engine->undefinedValue());
+
+ QStringList expectedNames;
+ expectedNames << "FooPolicy" << "BarPolicy" << "BazPolicy"
+ << "FooStrategy" << "BarStrategy" << "BazStrategy"
+ << "NoAbility" << "FooAbility" << "BarAbility" << "BazAbility" << "AllAbility";
+
+ for (int x = 0; x < 2; ++x) {
+ QSet<QString> actualNames;
+ if (x == 0) {
+ // From C++
+ QScriptValueIterator it(myClass);
+ while (it.hasNext()) {
+ it.next();
+ actualNames.insert(it.name());
+ }
+ } else {
+ // From JS
+ m_engine->globalObject().setProperty("MyClass", myClass);
+ QScriptValue ret = m_engine->evaluate("a=[]; for (var p in MyClass) if (MyClass.hasOwnProperty(p)) a.push(p); a");
+ QVERIFY(ret.isArray());
+ QStringList strings = qscriptvalue_cast<QStringList>(ret);
+ for (int i = 0; i < strings.size(); ++i)
+ actualNames.insert(strings.at(i));
+ }
+ QCOMPARE(actualNames.size(), expectedNames.size());
+ for (int i = 0; i < expectedNames.size(); ++i)
+ QVERIFY(actualNames.contains(expectedNames.at(i)));
+ }
+}
+
QTEST_MAIN(tst_QScriptExtQObject)
#include "tst_qscriptextqobject.moc"