summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp198
1 files changed, 193 insertions, 5 deletions
diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
index 7ccedfd..917b8d8 100644
--- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
+++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
@@ -72,7 +72,7 @@ class tst_QDeclarativeDebug : public QObject
Q_OBJECT
private:
- QDeclarativeDebugObjectReference findRootObject(int context = 0);
+ QDeclarativeDebugObjectReference findRootObject(int context = 0, bool recursive = false);
QDeclarativeDebugPropertyReference findProperty(const QList<QDeclarativeDebugPropertyReference> &props, const QString &name) const;
void waitForQuery(QDeclarativeDebugQuery *query);
@@ -114,9 +114,11 @@ private slots:
void tst_QDeclarativeDebugPropertyReference();
void setMethodBody();
+ void queryObjectTree();
+ void setBindingInStates();
};
-QDeclarativeDebugObjectReference tst_QDeclarativeDebug::findRootObject(int context)
+QDeclarativeDebugObjectReference tst_QDeclarativeDebug::findRootObject(int context, bool recursive)
{
QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
waitForQuery(q_engines);
@@ -128,7 +130,9 @@ QDeclarativeDebugObjectReference tst_QDeclarativeDebug::findRootObject(int conte
if (q_context->rootContext().objects().count() == 0)
return QDeclarativeDebugObjectReference();
- QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[context], this);
+ QDeclarativeDebugObjectQuery *q_obj = recursive ?
+ m_dbg->queryObjectRecursive(q_context->rootContext().objects()[context], this) :
+ m_dbg->queryObject(q_context->rootContext().objects()[context], this);
waitForQuery(q_obj);
QDeclarativeDebugObjectReference result = q_obj->object();
@@ -308,6 +312,34 @@ void tst_QDeclarativeDebug::initTestCase()
"function myMethodIndirect() { myMethod(3); }\n"
"}";
+ // and a fourth to test states
+ qml << "import QtQuick 1.0\n"
+ "Rectangle {\n"
+ "id:rootRect\n"
+ "width:100\n"
+ "states: [\n"
+ "State {\n"
+ "name:\"state1\"\n"
+ "PropertyChanges {\n"
+ "target:rootRect\n"
+ "width:200\n"
+ "}\n"
+ "}\n"
+ "]\n"
+ "transitions: [\n"
+ "Transition {\n"
+ "from:\"*\"\n"
+ "to:\"state1\"\n"
+ "PropertyAnimation {\n"
+ "target:rootRect\n"
+ "property:\"width\"\n"
+ "duration:100\n"
+ "}\n"
+ "}\n"
+ "]\n"
+ "}\n"
+ ;
+
for (int i=0; i<qml.count(); i++) {
QDeclarativeComponent component(m_engine);
component.setData(qml[i], QUrl::fromLocalFile(""));
@@ -635,14 +667,14 @@ void tst_QDeclarativeDebug::queryRootContexts()
QCOMPARE(context.debugId(), QDeclarativeDebugService::idForObject(actualContext));
QCOMPARE(context.name(), actualContext->objectName());
- QCOMPARE(context.objects().count(), 3); // 3 qml component objects created for context in main()
+ QCOMPARE(context.objects().count(), 4); // 4 qml component objects created for context in main()
// root context query sends only root object data - it doesn't fill in
// the children or property info
QCOMPARE(context.objects()[0].properties().count(), 0);
QCOMPARE(context.objects()[0].children().count(), 0);
- QCOMPARE(context.contexts().count(), 4);
+ QCOMPARE(context.contexts().count(), 5);
QVERIFY(context.contexts()[0].debugId() >= 0);
QCOMPARE(context.contexts()[0].name(), QString("tst_QDeclarativeDebug_childContext"));
@@ -897,6 +929,162 @@ void tst_QDeclarativeDebug::tst_QDeclarativeDebugPropertyReference()
compareProperties(r, ref);
}
+void tst_QDeclarativeDebug::setBindingInStates()
+{
+ // Check if changing bindings of propertychanges works
+
+ const int sourceIndex = 3;
+
+ QDeclarativeDebugObjectReference obj = findRootObject(sourceIndex);
+
+ QVERIFY(obj.debugId() != -1);
+ QVERIFY(obj.children().count() >= 2);
+
+ // We are going to switch state a couple of times, we need to get rid of the transition before
+ QDeclarativeDebugExpressionQuery *q_deleteTransition = m_dbg->queryExpressionResult(obj.debugId(),QString("transitions = []"),this);
+ waitForQuery(q_deleteTransition);
+ delete q_deleteTransition;
+
+
+ // check initial value of the property that is changing
+ QDeclarativeDebugExpressionQuery *q_setState;
+ q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this);
+ waitForQuery(q_setState);
+ delete q_setState;
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),200);
+
+
+ q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"\""),this);
+ waitForQuery(q_setState);
+ delete q_setState;
+
+
+ obj = findRootObject(sourceIndex, true);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),100);
+
+
+ // change the binding
+ QDeclarativeDebugObjectReference state = obj.children()[0];
+ QCOMPARE(state.className(), QString("State"));
+ QVERIFY(state.children().count() > 0);
+
+ QDeclarativeDebugObjectReference propertyChange = state.children()[0];
+ QVERIFY(propertyChange.debugId() != -1);
+
+ QVERIFY( m_dbg->setBindingForObject(propertyChange.debugId(), "width",QVariant(300),true) );
+
+ // check properties changed in state
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),100);
+
+
+ q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this);
+ waitForQuery(q_setState);
+ delete q_setState;
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),300);
+
+ // check changing properties of base state from within a state
+ QVERIFY(m_dbg->setBindingForObject(obj.debugId(),"width","height*2",false));
+ QVERIFY(m_dbg->setBindingForObject(obj.debugId(),"height","200",true));
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),300);
+
+ q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"\""),this);
+ waitForQuery(q_setState);
+ delete q_setState;
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 400);
+
+ // reset binding while in a state
+ q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this);
+ waitForQuery(q_setState);
+ delete q_setState;
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 300);
+
+ m_dbg->resetBindingForObject(propertyChange.debugId(), "width");
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 400);
+
+ // re-add binding
+ m_dbg->setBindingForObject(propertyChange.debugId(), "width", "300", true);
+
+ obj = findRootObject(sourceIndex);
+ QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 300);
+}
+
+void tst_QDeclarativeDebug::queryObjectTree()
+{
+ const int sourceIndex = 3;
+
+ // Check if states/transitions are initialized when fetching root item
+ QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
+ waitForQuery(q_engines);
+
+ QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
+ waitForQuery(q_context);
+
+ QVERIFY(q_context->rootContext().objects().count() > sourceIndex);
+ QDeclarativeDebugObjectReference rootObject = q_context->rootContext().objects()[sourceIndex];
+
+ QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(rootObject, this);
+ waitForQuery(q_obj);
+
+ QDeclarativeDebugObjectReference obj = q_obj->object();
+
+ delete q_engines;
+ delete q_context;
+ delete q_obj;
+
+ QVERIFY(obj.debugId() != -1);
+ QVERIFY(obj.children().count() >= 2);
+
+
+
+ // check state
+ QDeclarativeDebugObjectReference state = obj.children()[0];
+ QCOMPARE(state.className(), QString("State"));
+ QVERIFY(state.children().count() > 0);
+
+ QDeclarativeDebugObjectReference propertyChange = state.children()[0];
+ QVERIFY(propertyChange.debugId() != -1);
+
+ QDeclarativeDebugPropertyReference propertyChangeTarget = findProperty(propertyChange.properties(),"target");
+ QCOMPARE(propertyChangeTarget.objectDebugId(), propertyChange.debugId());
+
+ QDeclarativeDebugObjectReference targetReference = qvariant_cast<QDeclarativeDebugObjectReference>(propertyChangeTarget.value());
+ QVERIFY(targetReference.debugId() != -1);
+
+
+
+ // check transition
+ QDeclarativeDebugObjectReference transition = obj.children()[1];
+ QCOMPARE(transition.className(), QString("Transition"));
+ QCOMPARE(findProperty(transition.properties(),"from").value().toString(), QString("*"));
+ QCOMPARE(findProperty(transition.properties(),"to").value(), findProperty(state.properties(),"name").value());
+ QVERIFY(transition.children().count() > 0);
+
+ QDeclarativeDebugObjectReference animation = transition.children()[0];
+ QVERIFY(animation.debugId() != -1);
+
+ QDeclarativeDebugPropertyReference animationTarget = findProperty(animation.properties(),"target");
+ QCOMPARE(animationTarget.objectDebugId(), animation.debugId());
+
+ targetReference = qvariant_cast<QDeclarativeDebugObjectReference>(animationTarget.value());
+ QVERIFY(targetReference.debugId() != -1);
+
+ QCOMPARE(findProperty(animation.properties(),"property").value().toString(), QString("width"));
+ QCOMPARE(findProperty(animation.properties(),"duration").value().toInt(), 100);
+}
+
int main(int argc, char *argv[])
{
int _argc = argc + 1;