diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index b212820..be20ba1 100644 --- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp +++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp @@ -61,6 +61,7 @@ private slots: void setContextObject(); void destruction(); void idAsContextProperty(); + void readOnlyContexts(); private: QDeclarativeEngine engine; @@ -427,6 +428,36 @@ void tst_qdeclarativecontext::idAsContextProperty() delete obj; } +// Internal contexts should be read-only +void tst_qdeclarativecontext::readOnlyContexts() +{ + QDeclarativeComponent component(&engine); + component.setData("import Qt 4.6; QtObject { id: me }", QUrl()); + + QObject *obj = component.create(); + QVERIFY(obj); + + QDeclarativeContext *context = qmlContext(obj); + QVERIFY(context); + + QVERIFY(qvariant_cast<QObject*>(context->contextProperty("me")) == obj); + QVERIFY(context->contextObject() == obj); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeContext: Cannot set property on internal context."); + context->setContextProperty("hello", 12); + QVERIFY(context->contextProperty("hello") == QVariant()); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeContext: Cannot set property on internal context."); + context->setContextProperty("hello", obj); + QVERIFY(context->contextProperty("hello") == QVariant()); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeContext: Cannot set context object for internal context."); + context->setContextObject(0); + QVERIFY(context->contextObject() == obj); + + delete obj; +} + QTEST_MAIN(tst_qdeclarativecontext) #include "tst_qdeclarativecontext.moc" |