diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-07-25 16:24:01 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-25 09:43:14 +0200 |
commit | afaf155cf41682378d23ef8da12752f415e70273 (patch) | |
tree | c4c98c7d8d54d864bd259e4574f9fa3dd999b72c /tests | |
parent | 3bb8c0d3f2115765b519f795a2898456bf31924b (diff) |
Reverse lookup ids by object pointer
Task-number: QTBUG-18554
Change-Id: Ia4effb629d19aa36b835f6c09a63d9495e5c26e7
Reviewed-on: http://codereview.qt.nokia.com/2079
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index fdb8ff7dc2..89d08e01df 100644 --- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp +++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp @@ -67,6 +67,7 @@ private slots: void destruction(); void idAsContextProperty(); void readOnlyContexts(); + void nameForObject(); private: QDeclarativeEngine engine; @@ -463,6 +464,37 @@ void tst_qdeclarativecontext::readOnlyContexts() delete obj; } +void tst_qdeclarativecontext::nameForObject() +{ + QObject o1; + QObject o2; + QObject o3; + + QDeclarativeEngine engine; + + // As a context property + engine.rootContext()->setContextProperty("o1", &o1); + engine.rootContext()->setContextProperty("o2", &o2); + engine.rootContext()->setContextProperty("o1_2", &o1); + + QCOMPARE(engine.rootContext()->nameForObject(&o1), QString("o1")); + QCOMPARE(engine.rootContext()->nameForObject(&o2), QString("o2")); + QCOMPARE(engine.rootContext()->nameForObject(&o3), QString()); + + // As an id + QDeclarativeComponent component(&engine); + component.setData("import QtQuick 1.0; QtObject { id: root; property QtObject o: QtObject { id: nested } }", QUrl()); + + QObject *o = component.create(); + QVERIFY(o != 0); + + QCOMPARE(qmlContext(o)->nameForObject(o), QString("root")); + QCOMPARE(qmlContext(o)->nameForObject(qvariant_cast<QObject*>(o->property("o"))), QString("nested")); + QCOMPARE(qmlContext(o)->nameForObject(&o1), QString()); + + delete o; +} + QTEST_MAIN(tst_qdeclarativecontext) #include "tst_qdeclarativecontext.moc" |