diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-11 03:40:50 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-11 03:40:50 (GMT) |
commit | feae45e1a0b6079881e5e3493ed6f7bfaf83be45 (patch) | |
tree | 2c7eac400ac75f58477069b80cbbc20c562ef046 /tests | |
parent | 8768193ce3a3dc26508a911e189a084ed72d019a (diff) | |
parent | 22fe9474b01c577337e43416666a8f90d0ad6064 (diff) | |
download | Qt-feae45e1a0b6079881e5e3493ed6f7bfaf83be45.zip Qt-feae45e1a0b6079881e5e3493ed6f7bfaf83be45.tar.gz Qt-feae45e1a0b6079881e5e3493ed6f7bfaf83be45.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
7 files changed, 124 insertions, 85 deletions
diff --git a/tests/auto/declarative/debugger/debuggerutil.cpp b/tests/auto/declarative/debugger/debuggerutil.cpp index 8e93407..761105e 100644 --- a/tests/auto/declarative/debugger/debuggerutil.cpp +++ b/tests/auto/declarative/debugger/debuggerutil.cpp @@ -49,41 +49,42 @@ namespace QmlDebuggerTest { - void waitForSignal(QObject *receiver, const char *member) { + bool waitForSignal(QObject *receiver, const char *member, int timeout) { QEventLoop loop; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); QObject::connect(receiver, member, &loop, SLOT(quit())); - timer.start(5000); + timer.start(timeout); loop.exec(); + return timer.isActive(); } } -EchoService::EchoService(const QString &s, QObject *parent) +QmlDebuggerTestService::QmlDebuggerTestService(const QString &s, QObject *parent) : QmlDebugService(s, parent), enabled(false) { } -void EchoService::messageReceived(const QByteArray &ba) +void QmlDebuggerTestService::messageReceived(const QByteArray &ba) { sendMessage(ba); } -void EchoService::enabledChanged(bool e) +void QmlDebuggerTestService::enabledChanged(bool e) { emit enabledStateChanged(); enabled = e; } -MyQmlDebugClient::MyQmlDebugClient(const QString &s, QmlDebugConnection *c) +QmlDebuggerTestClient::QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c) : QmlDebugClient(s, c) { } -QByteArray MyQmlDebugClient::waitForResponse() +QByteArray QmlDebuggerTestClient::waitForResponse() { QSignalSpy spy(this, SIGNAL(serverMessage(QByteArray))); QmlDebuggerTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray))); @@ -94,7 +95,7 @@ QByteArray MyQmlDebugClient::waitForResponse() return spy.at(0).at(0).value<QByteArray>(); } -void MyQmlDebugClient::messageReceived(const QByteArray &ba) +void QmlDebuggerTestClient::messageReceived(const QByteArray &ba) { emit serverMessage(ba); } diff --git a/tests/auto/declarative/debugger/debuggerutil_p.h b/tests/auto/declarative/debugger/debuggerutil_p.h index 155d550..5e27a7a 100644 --- a/tests/auto/declarative/debugger/debuggerutil_p.h +++ b/tests/auto/declarative/debugger/debuggerutil_p.h @@ -47,14 +47,14 @@ namespace QmlDebuggerTest { - void waitForSignal(QObject *receiver, const char *member); + bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); } -class EchoService : public QmlDebugService +class QmlDebuggerTestService : public QmlDebugService { Q_OBJECT public: - EchoService(const QString &s, QObject *parent = 0); + QmlDebuggerTestService(const QString &s, QObject *parent = 0); bool enabled; signals: @@ -66,11 +66,11 @@ protected: virtual void enabledChanged(bool e); }; -class MyQmlDebugClient : public QmlDebugClient +class QmlDebuggerTestClient : public QmlDebugClient { Q_OBJECT public: - MyQmlDebugClient(const QString &s, QmlDebugConnection *c); + QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c); QByteArray waitForResponse(); diff --git a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro index 61f821e..c1ac125 100644 --- a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro +++ b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro @@ -2,4 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += network declarative macx:CONFIG -= app_bundle -SOURCES += tst_qmldebug.cpp +HEADERS += ../debuggerutil_p.h +SOURCES += tst_qmldebug.cpp \ + ../debuggerutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp index 7c52a19..bfb8aee 100644 --- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp @@ -59,6 +59,10 @@ #include <private/qmldebugservice_p.h> #include <private/qmlgraphicsrectangle_p.h> +#include "../debuggerutil_p.h" + +Q_DECLARE_METATYPE(QmlDebugWatch::State) + class tst_QmlDebug : public QObject { @@ -68,12 +72,6 @@ public: tst_QmlDebug(QmlDebugConnection *conn, QmlEngine *engine, QmlGraphicsItem *rootItem) : m_conn(conn), m_dbg(0), m_engine(engine), m_rootItem(rootItem) {} -protected slots: - void saveValueChange(const QByteArray &ba, const QVariant &v) - { - m_savedValueChanges[ba] = v; - } - private: QmlDebugObjectReference findRootObject(); QmlDebugPropertyReference findProperty(const QList<QmlDebugPropertyReference> &props, const QString &name) const; @@ -90,7 +88,6 @@ private: QmlEngineDebug *m_dbg; QmlEngine *m_engine; QmlGraphicsItem *m_rootItem; - QHash<QByteArray, QVariant> m_savedValueChanges; private slots: void initTestCase(); @@ -99,6 +96,8 @@ private slots: void watch_object(); void watch_expression(); void watch_expression_data(); + void watch_context(); + void watch_file(); void queryAvailableEngines(); void queryRootContexts(); @@ -160,14 +159,8 @@ void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) { QVERIFY(query); QCOMPARE(query->parent(), this); - QEventLoop loop; - QTimer timer; QVERIFY(query->state() == QmlDebugQuery::Waiting); - connect(query, SIGNAL(stateChanged(State)), &loop, SLOT(quit())); - connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - timer.start(5000); - loop.exec(); - if (!timer.isActive()) + if (!QmlDebuggerTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) QFAIL("query timed out"); } @@ -269,6 +262,8 @@ void tst_QmlDebug::compareProperties(const QmlDebugPropertyReference &a, const Q void tst_QmlDebug::initTestCase() { m_dbg = new QmlEngineDebug(m_conn, this); + + qRegisterMetaType<QmlDebugWatch::State>(); } void tst_QmlDebug::watch_property() @@ -276,29 +271,31 @@ void tst_QmlDebug::watch_property() QmlDebugObjectReference obj = findRootObject(); QmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); - QmlDebugPropertyWatch *watch = m_dbg->addWatch(prop, this); + QmlDebugPropertyWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(prop, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(prop, this); QCOMPARE(watch->state(), QmlDebugWatch::Waiting); QCOMPARE(watch->objectDebugId(), obj.debugId()); QCOMPARE(watch->name(), prop.name()); QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - QEventLoop loop; - QTimer timer; - connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), &loop, SLOT(quit())); - connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); int origWidth = m_rootItem->property("width").toInt(); - timer.start(5000); m_rootItem->setProperty("width", origWidth*2); - loop.exec(); - if (!timer.isActive()) - QFAIL("Did not receive valueChanged() for property"); + // stateChanged() is received before valueChanged() + QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(spy.count(), 1); m_dbg->removeWatch(watch); delete watch; - // restore original value and verify spy doesn't get a signal since watch has been removed + // restore original value and verify spy doesn't get additional signal since watch has been removed m_rootItem->setProperty("width", origWidth); QTest::qWait(100); QCOMPARE(spy.count(), 1); @@ -324,48 +321,51 @@ void tst_QmlDebug::watch_object() delete q_context; delete q_obj; - QmlDebugWatch *watch = m_dbg->addWatch(obj, this); + QmlDebugWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(obj, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(obj, this); QCOMPARE(watch->state(), QmlDebugWatch::Waiting); QCOMPARE(watch->objectDebugId(), obj.debugId()); - m_savedValueChanges.clear(); - connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), - SLOT(saveValueChange(QByteArray,QVariant))); + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); int origWidth = m_rootItem->property("width").toInt(); int origHeight = m_rootItem->property("height").toInt(); m_rootItem->setProperty("width", origWidth*2); m_rootItem->setProperty("height", origHeight*2); - QEventLoop loop; - QTimer timer; - timer.start(5000); - while (timer.isActive() && - (!m_savedValueChanges.contains("width") || !m_savedValueChanges.contains("height"))) { - loop.processEvents(QEventLoop::AllEvents, 50); - } + // stateChanged() is received before any valueChanged() signals + QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QVERIFY(spy.count() > 0); - QVariant newWidth = m_savedValueChanges["width"]; - QVariant newHeight = m_savedValueChanges["height"]; + int newWidth = -1; + int newHeight = -1; + for (int i=0; i<spy.count(); i++) { + const QVariantList &values = spy[i]; + if (values[0].value<QByteArray>() == "width") + newWidth = values[1].value<QVariant>().toInt(); + else if (values[0].value<QByteArray>() == "height") + newHeight = values[1].value<QVariant>().toInt(); + + } m_dbg->removeWatch(watch); delete watch; // since watch has been removed, restoring the original values should not trigger a valueChanged() - m_savedValueChanges.clear(); + spy.clear(); m_rootItem->setProperty("width", origWidth); m_rootItem->setProperty("height", origHeight); QTest::qWait(100); - QCOMPARE(m_savedValueChanges.count(), 0); + QCOMPARE(spy.count(), 0); - if (newWidth.isNull() || newHeight.isNull()) { - QString s = QString("Did not receive both width and height changes (width=%1, height=%2)") - .arg(newWidth.toString()).arg(newHeight.toString()); - QFAIL(qPrintable(s)); - } - - QCOMPARE(newWidth, qVariantFromValue(origWidth*2)); - QCOMPARE(newHeight, qVariantFromValue(origHeight*2)); + QCOMPARE(newWidth, origWidth * 2); + QCOMPARE(newHeight, origHeight * 2); } void tst_QmlDebug::watch_expression() @@ -378,30 +378,37 @@ void tst_QmlDebug::watch_expression() QmlDebugObjectReference obj = findRootObject(); - QmlDebugObjectExpressionWatch *watch = m_dbg->addWatch(obj, expr, this); + QmlDebugObjectExpressionWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(obj, expr, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(obj, expr, this); QCOMPARE(watch->state(), QmlDebugWatch::Waiting); QCOMPARE(watch->objectDebugId(), obj.debugId()); QCOMPARE(watch->expression(), expr); + QSignalSpy spyState(watch, SIGNAL(stateChanged(QmlDebugWatch::State))); + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value int width = origWidth; for (int i=0; i<incrementCount+1; i++) { - QTimer timer; - timer.start(5000); if (i > 0) { width += increment; m_rootItem->setProperty("width", width); } - QEventLoop loop; - connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), &loop, SLOT(quit())); - loop.exec(); - if (!timer.isActive()) - QFAIL("Did not receive valueChanged() signal for expression"); + if (!QmlDebuggerTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) + QFAIL("Did not receive valueChanged() for expression"); } + if (spyState.count() == 0) + QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(spyState.count(), 1); + m_dbg->removeWatch(watch); delete watch; @@ -427,6 +434,20 @@ void tst_QmlDebug::watch_expression_data() QTest::newRow("width+10") << "width + 10" << 10 << 5; } +void tst_QmlDebug::watch_context() +{ + QmlDebugContextReference c; + QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(c, QString(), this)); +} + +void tst_QmlDebug::watch_file() +{ + QmlDebugFileReference f; + QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(f, this)); +} + void tst_QmlDebug::queryAvailableEngines() { QmlDebugEnginesQuery *q_engines; @@ -722,6 +743,20 @@ void tst_QmlDebug::tst_QmlDebugPropertyReference() waitForQuery(query); QmlDebugObjectReference obj = query->object(); delete query; + + QmlDebugPropertyReference ref = findProperty(obj.properties(), "scale"); + QVERIFY(ref.objectDebugId() > 0); + QVERIFY(!ref.name().isEmpty()); + QVERIFY(!ref.value().isNull()); + QVERIFY(!ref.valueTypeName().isEmpty()); + QVERIFY(!ref.binding().isEmpty()); + QVERIFY(ref.hasNotifySignal()); + + QmlDebugPropertyReference copy(ref); + QmlDebugPropertyReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugPropertyReference &r, (QList<QmlDebugPropertyReference>() << copy << copyAssign)) + compareProperties(r, ref); } class TestRunnerThread : public QThread @@ -771,7 +806,7 @@ int main(int argc, char *argv[]) QmlComponent component(&engine, "import Qt 4.6\n" "Item {\n" - "width: 10; height: 20;\n" + "width: 10; height: 20; scale: blueRect.scale;\n" "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" "Text { color: blueRect.color; }" "}\n", diff --git a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp index db33061..0a768a5 100644 --- a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp +++ b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp @@ -89,8 +89,8 @@ void tst_QmlDebugClient::isEnabled() void tst_QmlDebugClient::setEnabled() { - EchoService service("tst_QmlDebugClient::setEnabled()"); - MyQmlDebugClient client("tst_QmlDebugClient::setEnabled()", m_conn); + QmlDebuggerTestService service("tst_QmlDebugClient::setEnabled()"); + QmlDebuggerTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); QCOMPARE(service.isEnabled(), false); @@ -125,8 +125,8 @@ void tst_QmlDebugClient::isConnected() void tst_QmlDebugClient::sendMessage() { - EchoService service("tst_QmlDebugClient::sendMessage()"); - MyQmlDebugClient client("tst_QmlDebugClient::sendMessage()", m_conn); + QmlDebuggerTestService service("tst_QmlDebugClient::sendMessage()"); + QmlDebuggerTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); QByteArray msg = "hello!"; diff --git a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp index 224e7e1..2cd8607 100644 --- a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp +++ b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp @@ -85,10 +85,10 @@ void tst_QmlDebugService::name() void tst_QmlDebugService::isEnabled() { - EchoService service("tst_QmlDebugService::isEnabled()", m_conn); + QmlDebuggerTestService service("tst_QmlDebugService::isEnabled()", m_conn); QCOMPARE(service.isEnabled(), false); - MyQmlDebugClient client("tst_QmlDebugService::isEnabled()", m_conn); + QmlDebuggerTestClient client("tst_QmlDebugService::isEnabled()", m_conn); client.setEnabled(true); QmlDebuggerTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); QCOMPARE(service.isEnabled(), true); @@ -100,8 +100,8 @@ void tst_QmlDebugService::isEnabled() void tst_QmlDebugService::enabledChanged() { - EchoService service("tst_QmlDebugService::enabledChanged()"); - MyQmlDebugClient client("tst_QmlDebugService::enabledChanged()", m_conn); + QmlDebuggerTestService service("tst_QmlDebugService::enabledChanged()"); + QmlDebuggerTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); QCOMPARE(service.enabled, false); @@ -112,8 +112,8 @@ void tst_QmlDebugService::enabledChanged() void tst_QmlDebugService::sendMessage() { - EchoService service("tst_QmlDebugService::sendMessage()"); - MyQmlDebugClient client("tst_QmlDebugService::sendMessage()", m_conn); + QmlDebuggerTestService service("tst_QmlDebugService::sendMessage()"); + QmlDebuggerTestClient client("tst_QmlDebugService::sendMessage()", m_conn); QByteArray msg = "hello!"; diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 6b2e39e..8a3a06c 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -8,12 +8,9 @@ SUBDIRS += \ debugger \ # Cover examples \ layouts \ # Cover - qmlgraphicslistview \ # Cover - qmlgraphicsgridview \ # Cover numberformatter \ # Cover parserstress \ # Cover pathview \ # Cover - qmlgraphicsloader \ # Cover qmetaobjectbuilder \ # Cover qmlbinding \ # Cover qmlconnection \ # Cover @@ -22,10 +19,13 @@ SUBDIRS += \ qmlecmascript \ # Cover qmlerror \ # Cover qmlfontloader \ # Cover - qmlgraphicsitem \ # Cover qmlgraphicsborderimage \ # Cover qmlgraphicsflickable \ # Cover qmlgraphicsflipable \ # Cover + qmlgraphicsgridview \ # Cover + qmlgraphicsitem \ # Cover + qmlgraphicslistview \ # Cover + qmlgraphicsloader \ # Cover qmlgraphicsparticles \ # Cover qmlgraphicspositioners \ # Cover qmlgraphicstext \ # Cover @@ -36,6 +36,7 @@ SUBDIRS += \ qmllanguage \ # Cover qmllist \ # Cover qmllistaccessor \ # Cover + qmllistmodel \ # Cover qmlmetaproperty \ # Cover qmlmetatype \ # Cover qmlpixmapcache \ # Cover |