summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-03-18 01:29:44 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-03-18 01:29:44 (GMT)
commit04776ee4cac6edfba910d5e0082f32b01948db51 (patch)
tree9dffaa88d4add31e632c0dc55057bd12a911d7bc /tests/auto/declarative
parent4b4e9be3ea5a267c8fc05d6ff5aca972d64eb705 (diff)
downloadQt-04776ee4cac6edfba910d5e0082f32b01948db51.zip
Qt-04776ee4cac6edfba910d5e0082f32b01948db51.tar.gz
Qt-04776ee4cac6edfba910d5e0082f32b01948db51.tar.bz2
Block modifications to internal QDeclarativeContexts
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp31
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"