summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJedrzej Nowacki <jedrzej.nowacki@nokia.com>2011-01-17 08:47:52 (GMT)
committerJedrzej Nowacki <jedrzej.nowacki@nokia.com>2011-01-17 10:57:29 (GMT)
commite7907b32c323400562607253ec293e814c015f7a (patch)
treef83a38714d05ae7aa2968a49f5ebc7a410f05e87 /tests
parent6c52715202ad8fd3c3f4bb94207cb7627c12f995 (diff)
downloadQt-e7907b32c323400562607253ec293e814c015f7a.zip
Qt-e7907b32c323400562607253ec293e814c015f7a.tar.gz
Qt-e7907b32c323400562607253ec293e814c015f7a.tar.bz2
Fix QScriptValueIterator::hasNext and QScriptValueIterator::hasPrevious
When a script engine is about to be deleted all bound iterators should be invalidated. Previously behavior of the class was not tested for the case, so new test for QScriptValueIterator was added. Reviewed-by: Olivier Goffart
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
index df11537..07b1cc7 100644
--- a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
+++ b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
@@ -72,6 +72,7 @@ private slots:
void iterateGetterSetter();
void assignObjectToIterator();
void iterateNonObject();
+ void iterateOverObjectFromDeletedEngine();
};
tst_QScriptValueIterator::tst_QScriptValueIterator()
@@ -604,5 +605,50 @@ void tst_QScriptValueIterator::iterateNonObject()
QVERIFY(!it.hasNext());
}
+void tst_QScriptValueIterator::iterateOverObjectFromDeletedEngine()
+{
+ QScriptEngine *engine = new QScriptEngine;
+ QScriptValue objet = engine->newObject();
+
+ // populate object with properties
+ QHash<QString, int> properties;
+ properties.insert("foo",1235);
+ properties.insert("oof",5321);
+ properties.insert("ofo",3521);
+ QHash<QString, int>::const_iterator i = properties.constBegin();
+ for(; i != properties.constEnd(); ++i) {
+ objet.setProperty(i.key(), i.value());
+ }
+
+ // start iterating
+ QScriptValueIterator it(objet);
+ it.next();
+ QVERIFY(properties.contains(it.name()));
+
+ delete engine;
+
+ QVERIFY(!objet.isValid());
+ QVERIFY(it.name().isEmpty());
+ QVERIFY(!it.value().isValid());
+
+ QVERIFY(!it.hasNext());
+ it.next();
+
+ QVERIFY(it.name().isEmpty());
+ QVERIFY(!it.scriptName().isValid());
+ QVERIFY(!it.value().isValid());
+ it.setValue("1234567");
+ it.remove();
+
+ QVERIFY(!it.hasPrevious());
+ it.previous();
+
+ QVERIFY(it.name().isEmpty());
+ QVERIFY(!it.scriptName().isValid());
+ QVERIFY(!it.value().isValid());
+ it.setValue("1234567");
+ it.remove();
+}
+
QTEST_MAIN(tst_QScriptValueIterator)
#include "tst_qscriptvalueiterator.moc"