diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-11-03 16:52:53 +0000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-04 16:22:04 +0100 |
commit | 3e84e81da776234bf62570b439f1e21848f83c4b (patch) | |
tree | f4d435300c7ee5f47b98bb1e85b40a34235eca51 /tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp | |
parent | 986367abdac654cea9c1fe37f9ff4226b7516fa5 (diff) |
Optimization: Minimize refreshing when root context changes
Modifying a context requires expressions to be refreshed incase they
depend on a name resolution that changes. As it is common to modify
the root context, and the root context can't hide any names, it is easy
to constrain the expressions that require refreshing. In a well
behaving app, this should mean that no expressions are reevaluated when
the root context is modified.
Change-Id: Id3b48cd595fdd6b5a3dc6f26319f652dccaef79c
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index dee2cd9805..68599a2e83 100644 --- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp +++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp @@ -78,6 +78,7 @@ private slots: void refreshExpressions(); void refreshExpressionsCrash(); + void refreshExpressionsRootContext(); private: QDeclarativeEngine engine; @@ -610,6 +611,39 @@ void tst_qdeclarativecontext::refreshExpressions() delete o1; } +// Test that updating the root context, only causes expressions in contexts with an +// unresolved name to reevaluate +void tst_qdeclarativecontext::refreshExpressionsRootContext() +{ + QDeclarativeEngine engine; + + CountCommand command; + engine.rootContext()->setContextProperty("countCommand", &command); + + QDeclarativeComponent component(&engine, TEST_FILE("refreshExpressions.qml")); + QDeclarativeComponent component2(&engine, TEST_FILE("refreshExpressionsRootContext.qml")); + + QDeclarativeContext context(engine.rootContext()); + QDeclarativeContext context2(engine.rootContext()); + + QString warning = component2.url().toString() + QLatin1String(":4: ReferenceError: Can't find variable: unresolvedName"); + + QObject *o1 = component.create(&context); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + QObject *o2 = component2.create(&context2); + + QCOMPARE(command.count, 3); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + QDeclarativeContextData::get(engine.rootContext())->refreshExpressions(); + + QCOMPARE(command.count, 4); + + delete o2; + delete o1; +} + QTEST_MAIN(tst_qdeclarativecontext) #include "tst_qdeclarativecontext.moc" |