diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-11 05:15:16 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-11 05:15:16 (GMT) |
commit | c0f26c449d0d20915b65af6172ede1dc5659ba01 (patch) | |
tree | a2000f0cccedc78411ae0ec5b4ec3e12637f9710 | |
parent | 010dae33653c76359e857aadfbdfeb4841c01d2f (diff) | |
download | Qt-c0f26c449d0d20915b65af6172ede1dc5659ba01.zip Qt-c0f26c449d0d20915b65af6172ede1dc5659ba01.tar.gz Qt-c0f26c449d0d20915b65af6172ede1dc5659ba01.tar.bz2 |
Add context property test
-rw-r--r-- | tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp index ca840f4..c63caf4 100644 --- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp +++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp @@ -1,6 +1,8 @@ #include <qtest.h> #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlexpression.h> +#include <QtDeclarative/qmlcontext.h> class MyQmlObject : public QObject { @@ -75,6 +77,7 @@ private slots: void methods(); void signalAssignment(); void bindingLoop(); + void contextPropertiesTriggerReeval(); private: QmlEngine engine; @@ -141,7 +144,7 @@ void tst_qmlbindengine::methods() QCOMPARE(object->methodIntCalled(), true); } } -#include <QDebug> + void tst_qmlbindengine::bindingLoop() { QmlComponent component(&engine, "MyQmlContainer { children : [ "\ @@ -153,6 +156,31 @@ void tst_qmlbindengine::bindingLoop() QVERIFY(object != 0); } +class MyExpression : public QmlExpression +{ +public: + MyExpression(QmlContext *ctxt, const QString &expr) + : QmlExpression(ctxt, expr, 0), changed(false) + { + } + + bool changed; +}; + +void tst_qmlbindengine::contextPropertiesTriggerReeval() +{ + QmlContext context(engine.rootContext()); + context.setContextProperty("testProp", QVariant(1)); + + MyExpression expr(&context, "testProp + 1"); + QCOMPARE(expr.changed, false); + QCOMPARE(expr.value(), QVariant(2)); + + context.setContextProperty("testProp", QVariant(2)); + QCOMPARE(expr.changed, true); + QCOMPARE(expr.value(), QVariant(3)); +} + QTEST_MAIN(tst_qmlbindengine) #include "tst_qmlbindengine.moc" |