diff options
Diffstat (limited to 'tests')
10 files changed, 597 insertions, 42 deletions
diff --git a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp index 903b3739..995c375a 100644 --- a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -133,10 +133,6 @@ private: class tst_QDeclarativeDebugJS : public QDeclarativeDataTest { Q_OBJECT -private: - QDeclarativeDebugConnection *m_conn; - QDeclarativeEngine *m_engine; - QJSDebugClient *m_client; private slots: void initTestCase(); diff --git a/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp b/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp index 83c2f21a..d97ae70d 100644 --- a/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp +++ b/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp @@ -117,10 +117,6 @@ private: class tst_QDeclarativeDebugObserverMode : public QDeclarativeDataTest { Q_OBJECT -private: - QDeclarativeDebugConnection *m_conn; - QDeclarativeEngine *m_engine; - QDeclarativeObserverModeClient *m_client; private slots: void initTestCase(); diff --git a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp index 7795e026..f67cecdc 100644 --- a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp +++ b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp @@ -334,6 +334,8 @@ public: setFinished(true); } virtual qint64 readData(char* buffer, qint64 number) { + Q_UNUSED(buffer) + Q_UNUSED(number) return 0; } virtual void abort() { } @@ -348,6 +350,9 @@ public: } QNetworkReply *createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0) { + Q_UNUSED(op) + Q_UNUSED(req) + Q_UNUSED(outgoingData) return new MyReply; } }; @@ -356,7 +361,7 @@ class MyFactory : public QDeclarativeNetworkAccessManagerFactory { public: QNetworkAccessManager *create(QObject *parent) { - return new MyManager; + return new MyManager(parent); } }; diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml b/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml new file mode 100644 index 00000000..8345972a --- /dev/null +++ b/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml @@ -0,0 +1,81 @@ +import QtQuick 1.1 + +Item { + objectName: "rootItem" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item1" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + + Item { + objectName: "item2" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item3" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + } + + FocusScope { + objectName: "scope1" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item4" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + + FocusScope { + objectName: "scope2" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item5" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp index 64c8d210..f7099ba2 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp +++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp @@ -68,6 +68,10 @@ private slots: void signalEmission(); void qtBug13380(); void forceActiveFocus(); + void notifications(); + void notifications_data(); + void notificationsInScope(); + void notificationsInScope_data(); }; /* @@ -396,8 +400,11 @@ void tst_qdeclarativefocusscope::forceActiveFocus() { QDeclarativeView *view = new QDeclarativeView; view->setSource(QUrl::fromLocalFile(SRCDIR "/data/forceActiveFocus.qml")); + view->show(); + view->activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(view)); - QGraphicsObject *rootObject = view->rootObject(); + QDeclarativeItem *rootObject = qobject_cast<QDeclarativeItem *>(view->rootObject()); QVERIFY(rootObject); QDeclarativeItem *scope = findItem<QDeclarativeItem>(rootObject, QLatin1String("scope")); @@ -416,6 +423,11 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(scopeB); QVERIFY(itemB2); + QCOMPARE(rootObject->hasActiveFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(scopeA->hasActiveFocus(), false); + QCOMPARE(scopeB->hasActiveFocus(), false); + QSignalSpy rootSpy(rootObject, SIGNAL(activeFocusChanged(bool))); QSignalSpy scopeSpy(scope, SIGNAL(activeFocusChanged(bool))); QSignalSpy scopeASpy(scopeA, SIGNAL(activeFocusChanged(bool))); @@ -424,22 +436,34 @@ void tst_qdeclarativefocusscope::forceActiveFocus() // First, walk the focus from item-a1 down to item-a2 and back again itemA1->forceActiveFocus(); QVERIFY(itemA1->hasActiveFocus()); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); scopeA->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemA2->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(itemA2->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); + if (scopeASpy.count() == 3) { + qWarning() << "ignoring spurious changed signals"; + QCOMPARE(scopeASpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeASpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeASpy.first().first().toBool(), true); + } QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); + if (scopeSpy.count() == 3) { + qWarning() << "ignoring spurious changed signals"; + QCOMPARE(scopeSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeSpy.first().first().toBool(), true); + } QCOMPARE(scopeSpy.count(), 1); scopeA->forceActiveFocus(); @@ -447,7 +471,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(itemA2->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemA1->forceActiveFocus(); @@ -455,13 +479,13 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(!scopeA->hasActiveFocus()); QVERIFY(!itemA2->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 2); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); // Then jump back and forth between branch 'a' and 'b' itemB1->forceActiveFocus(); QVERIFY(itemB1->hasActiveFocus()); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); scopeA->forceActiveFocus(); @@ -469,7 +493,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(!itemB1->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 3); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); scopeB->forceActiveFocus(); @@ -478,7 +502,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(scopeB->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 4); QCOMPARE(scopeBSpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemA2->forceActiveFocus(); @@ -486,7 +510,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(itemA2->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 5); QCOMPARE(scopeBSpy.count(), 2); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemB2->forceActiveFocus(); @@ -494,12 +518,259 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(itemB2->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 6); QCOMPARE(scopeBSpy.count(), 3); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); delete view; } + +void tst_qdeclarativefocusscope::notifications_data() +{ + QTest::addColumn<QString>("objectName"); + + QTest::newRow("rootItem") << ""; + QTest::newRow("item1") << "item1"; + QTest::newRow("item3") << "item3"; + QTest::newRow("focusScope") << "scope1"; +} + +void tst_qdeclarativefocusscope::notifications() +{ + QFETCH(QString, objectName); + QDeclarativeView canvas; + canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/notifications.qml")); + canvas.show(); + canvas.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&canvas)); + + QGraphicsScene *scene = canvas.scene(); + + QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(canvas.rootObject()); + QVERIFY(item); + + item = objectName.isEmpty() ? item : item->findChild<QDeclarativeItem *>(objectName); + QVERIFY(item); + + QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool))); + QSignalSpy activeFocusSpy(item, SIGNAL(activeFocusChanged(bool))); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + + item->setFocus(true); + + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true); + + item->setFocus(false); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value<bool>(), false); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + + item->QGraphicsItem::setFocus(); + + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true); + + item->clearFocus(); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value<bool>(), false); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + + scene->setFocusItem(item); + + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true); + + scene->setFocusItem(0); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value<bool>(), false); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); +} + +void tst_qdeclarativefocusscope::notificationsInScope_data() +{ + QTest::addColumn<QString>("itemName"); + QTest::addColumn<QString>("scopeName"); + + QTest::newRow("item4") << "item4" << "scope1"; + QTest::newRow("item5") << "item5" << "scope2"; +} + +void tst_qdeclarativefocusscope::notificationsInScope() +{ + QFETCH(QString, itemName); + QFETCH(QString, scopeName); + QDeclarativeView canvas; + canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/notifications.qml")); + canvas.show(); + canvas.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&canvas)); + + QVERIFY(canvas.rootObject()); + + QDeclarativeItem *scope = canvas.rootObject()->findChild<QDeclarativeItem *>(scopeName); + QVERIFY(scope); + + QDeclarativeItem *item = scope->findChild<QDeclarativeItem *>(itemName); + QVERIFY(item); + + QSignalSpy itemFocusSpy(item, SIGNAL(focusChanged(bool))); + QSignalSpy itemActiveFocusSpy(item, SIGNAL(activeFocusChanged(bool))); + + QSignalSpy scopeFocusSpy(scope, SIGNAL(focusChanged(bool))); + QSignalSpy scopeActiveFocusSpy(scope, SIGNAL(activeFocusChanged(bool))); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(item->property("handlerFocus").value<bool>(), false); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false); + + item->setFocus(true); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(itemActiveFocusSpy.count(), 0); + QCOMPARE(scopeFocusSpy.count(), 0); + QCOMPARE(scopeActiveFocusSpy.count(), 0); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false); + + item->setFocus(false); + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(itemActiveFocusSpy.count(), 0); + QCOMPARE(scopeFocusSpy.count(), 0); + QCOMPARE(scopeActiveFocusSpy.count(), 0); + QCOMPARE(item->property("handlerFocus").value<bool>(), false); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false); + + item->forceActiveFocus(); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(scope->hasFocus(), true); + QCOMPARE(scope->hasActiveFocus(), true); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeFocusSpy.count(), 1); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeActiveFocusSpy.count(), 1); + QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true); + QCOMPARE(scope->property("handlerFocus").value<bool>(), true); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), true); + + scope->setFocus(false); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(itemFocusSpy.count(), 0); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeFocusSpy.count(), 1); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeActiveFocusSpy.count(), 1); + QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false); + + scope->setFocus(true); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(scope->hasFocus(), true); + QCOMPARE(scope->hasActiveFocus(), true); + QCOMPARE(itemFocusSpy.count(), 0); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeFocusSpy.count(), 1); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeActiveFocusSpy.count(), 1); + QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value<bool>(), true); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true); + QCOMPARE(scope->property("handlerFocus").value<bool>(), true); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), true); + + item->setFocus(false); + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), true); + QCOMPARE(scope->hasActiveFocus(), true); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), false); + if (scopeFocusSpy.count() == 2) { + qWarning() << "ignoring spurious changed signals"; + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true); + } + QCOMPARE(scopeFocusSpy.count(), 0); + QCOMPARE(scopeActiveFocusSpy.count(), 0); + QCOMPARE(item->property("handlerFocus").value<bool>(), false); + QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false); + QCOMPARE(scope->property("handlerFocus").value<bool>(), true); + QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), true); +} + QTEST_MAIN(tst_qdeclarativefocusscope) #include "tst_qdeclarativefocusscope.moc" diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 0f61bb7e..0251d74d 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -86,6 +86,11 @@ private slots: void qtbug_16871(); void qtbug_21045(); void hasActiveFocusAfterClear(); + void setAndClearFocusOfItem(); + void setAndClearFocusScopeFocus(); + void setFocusThenSetFocusItem0(); + void setFocusFocusItem0ThenHasActiveFocus(); + private: QDeclarativeEngine engine; }; @@ -1043,6 +1048,7 @@ void tst_QDeclarativeItem::propertyChanges() QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF()); QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(item->hasFocus(), true); QCOMPARE(focusSpy.count(),1); QList<QVariant> focusArguments = focusSpy.first(); QVERIFY(focusArguments.count() == 1); @@ -1249,8 +1255,9 @@ void tst_QDeclarativeItem::qtbug_21045() void tst_QDeclarativeItem::hasActiveFocusAfterClear() { QGraphicsScene scene; - QGraphicsView view(&scene); - view.show(); + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); QDeclarativeEngine engine; QDeclarativeComponent qmlComponent(&engine); @@ -1273,6 +1280,174 @@ void tst_QDeclarativeItem::hasActiveFocusAfterClear() QVERIFY(!createdItem->hasActiveFocus()); } +void tst_QDeclarativeItem::setAndClearFocusOfItem() +{ + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + qmlComponent.setData( + "import QtQuick 1.1;" + "Item { id: root; " + "signal focusChangedTo(bool value);" + "signal activeFocusChangedTo(bool value);" + "onFocusChanged: root.focusChangedTo(focus);" + "onActiveFocusChanged: root.activeFocusChangedTo(activeFocus);" + "}", QUrl("test")); + + QGraphicsItem *createdItem = qobject_cast<QGraphicsItem*>(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem); + scene.addItem(createdItem); + + QSignalSpy focusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(focusChangedTo(bool))); + QSignalSpy activeFocusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(activeFocusChangedTo(bool))); + + QVERIFY(!createdItem->hasFocus()); + createdItem->toGraphicsObject()->setFocus(); + QCOMPARE(focusChangedSpy.count(), 1); + QCOMPARE(activeFocusChangedSpy.count(), 1); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), true); + + createdItem->toGraphicsObject()->clearFocus(); + QCOMPARE(focusChangedSpy.count(), 1); + QCOMPARE(activeFocusChangedSpy.count(), 1); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), false); +} + +void tst_QDeclarativeItem::setAndClearFocusScopeFocus() +{ + //graphicsview init + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + //declarative init + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + + qmlComponent.setData( + "\nimport QtQuick 1.1" + "\nFocusScope {" + "\n id: root" + "\n signal listActiveFocusChangedTo(bool value)" + "\n signal topRectActiveFocusChangedTo(bool value)" + "\n Rectangle {" + "\n id: topRect" + "\n focus: true" + "\n onActiveFocusChanged: root.topRectActiveFocusChangedTo(topRect.activeFocus)" + "\n }" + "\n FocusScope {" + "\n objectName: \"focusScope\"" + "\n onActiveFocusChanged: root.listActiveFocusChangedTo(activeFocus)" + "\n }" + "\n Rectangle { objectName: \"bottom\" }" + "}", QUrl("")); + + QGraphicsItem *createdItem = qobject_cast<QGraphicsItem*>(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem); + scene.addItem(createdItem); + + QDeclarativeItem *focusScope = createdItem->toGraphicsObject()->findChild<QDeclarativeItem*>("focusScope"); + QDeclarativeItem *bottomRect = createdItem->toGraphicsObject()->findChild<QDeclarativeItem*>("bottom"); + + QSignalSpy focusScopeSpy(createdItem->toGraphicsObject(), SIGNAL(listActiveFocusChangedTo(bool))); + QSignalSpy topRectFocusSpy(createdItem->toGraphicsObject(), SIGNAL(topRectActiveFocusChangedTo(bool))); + + //#1: root gets activefocus, and in turn the top rectangle + createdItem->setFocus(); + + //#2 + focusScope->setFocus(true); + + //#3 + bottomRect->setFocus(true); + + QCOMPARE(topRectFocusSpy.count(), 2); + QCOMPARE(focusScopeSpy.count(), 2); + + QCOMPARE(topRectFocusSpy.takeFirst().first().toBool(), true); //from #1 + QCOMPARE(topRectFocusSpy.takeFirst().first().toBool(), false); //from #2 + + QCOMPARE(focusScopeSpy.takeFirst().first().toBool(), true); //from #2 + QCOMPARE(focusScopeSpy.takeFirst().first().toBool(), false); //from #3 +} + +void tst_QDeclarativeItem::setFocusThenSetFocusItem0() +{ + //graphicsview init + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + //declarative init + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + qmlComponent.setData( + "import QtQuick 1.1;" + "Item {" + "signal focusChangedTo(bool value);" + "signal activeFocusChangedTo(bool value);" + "onFocusChanged: focusChangedTo(focus);" + "onActiveFocusChanged: activeFocusChangedTo(activeFocus);" + "}", QUrl("")); + + QGraphicsItem *createdItem = qobject_cast<QGraphicsItem*>(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem); + + scene.addItem(createdItem); + + QSignalSpy focusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(focusChangedTo(bool))); + QSignalSpy activeFocusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(activeFocusChangedTo(bool))); + + createdItem->toGraphicsObject()->setFocus(); + QVERIFY(!focusChangedSpy.isEmpty()); + QVERIFY(!activeFocusChangedSpy.isEmpty()); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), true); + + scene.setFocusItem(0); + QVERIFY(!focusChangedSpy.isEmpty()); + QVERIFY(!activeFocusChangedSpy.isEmpty()); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), false); + QVERIFY(activeFocusChangedSpy.isEmpty()); +} + +void tst_QDeclarativeItem::setFocusFocusItem0ThenHasActiveFocus() +{ + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + qmlComponent.setData( + "import QtQuick 1.1;" + "TextInput {" + "width: 100; height: 100;" + "Rectangle { anchors.fill: parent; color: \"yellow\"; z: parent.z - 1 }" + "}", QUrl("")); + QDeclarativeItem *createdItem = qobject_cast<QDeclarativeItem*>(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem != 0); + + scene.addItem(createdItem); + + createdItem->QGraphicsItem::setFocus(); + QCoreApplication::processEvents(); + scene.setFocusItem(0); + QCoreApplication::processEvents(); + + QVERIFY(!createdItem->hasActiveFocus()); +} + QTEST_MAIN(tst_QDeclarativeItem) #include "tst_qdeclarativeitem.moc" diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index cd8c5aed..8815dbfb 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -615,45 +615,44 @@ void tst_QDeclarativePathView::moveModel_data() QTest::addColumn<int>("from"); QTest::addColumn<int>("to"); QTest::addColumn<int>("count"); - QTest::addColumn<qreal>("offset"); QTest::addColumn<int>("currentIndex"); // We have 8 items, with currentIndex == 4 QTest::newRow("move after current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4; QTest::newRow("move before current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4; QTest::newRow("move before current to after") - << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 6 << 1 << 5. << 3; + << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 6 << 1 << 3; QTest::newRow("move multiple after current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4; QTest::newRow("move multiple before current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4; QTest::newRow("move before current to end") - << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 7 << 1 << 5. << 3; + << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 7 << 1 << 3; QTest::newRow("move last to beginning") - << int(QDeclarativePathView::StrictlyEnforceRange) << 7 << 0 << 1 << 3. << 5; + << int(QDeclarativePathView::StrictlyEnforceRange) << 7 << 0 << 1 << 5; QTest::newRow("move current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 4 << 6 << 1 << 2. << 6; + << int(QDeclarativePathView::StrictlyEnforceRange) << 4 << 6 << 1 << 6; QTest::newRow("no range - move after current") - << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 1 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 1 << 4; QTest::newRow("no range - move before current") - << int(QDeclarativePathView::NoHighlightRange) << 2 << 3 << 1 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 2 << 3 << 1 << 4; QTest::newRow("no range - move before current to after") - << int(QDeclarativePathView::NoHighlightRange) << 2 << 6 << 1 << 5. << 3; + << int(QDeclarativePathView::NoHighlightRange) << 2 << 6 << 1 << 3; QTest::newRow("no range - move multiple after current") - << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 2 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 2 << 4; QTest::newRow("no range - move multiple before current") - << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 2 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 2 << 4; QTest::newRow("no range - move before current to end") - << int(QDeclarativePathView::NoHighlightRange) << 2 << 7 << 1 << 5. << 3; + << int(QDeclarativePathView::NoHighlightRange) << 2 << 7 << 1 << 3; QTest::newRow("no range - move last to beginning") - << int(QDeclarativePathView::NoHighlightRange) << 7 << 0 << 1 << 3. << 5; + << int(QDeclarativePathView::NoHighlightRange) << 7 << 0 << 1 << 5; QTest::newRow("no range - move current") - << int(QDeclarativePathView::NoHighlightRange) << 4 << 6 << 1 << 4. << 6; + << int(QDeclarativePathView::NoHighlightRange) << 4 << 6 << 1 << 6; QTest::newRow("no range - move multiple incl. current") - << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 5 << 4. << 5; + << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 5 << 5; } void tst_QDeclarativePathView::moveModel() @@ -662,7 +661,6 @@ void tst_QDeclarativePathView::moveModel() QFETCH(int, from); QFETCH(int, to); QFETCH(int, count); - QFETCH(qreal, offset); QFETCH(int, currentIndex); QDeclarativeView *window = createView(); diff --git a/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml b/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml new file mode 100644 index 00000000..cba1ffe5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 + +Rectangle { + width: 300; height: 300; + Rectangle { + objectName: "theRect" + color: "red" + width: 60; height: 60; + x: 100; y: 100; + SmoothedAnimation on x { objectName: "easeX"; to: 200; duration: 0 } + } +} diff --git a/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp b/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp index 452168a6..1d511779 100644 --- a/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp +++ b/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp @@ -58,6 +58,7 @@ private slots: void simpleAnimation(); void valueSource(); void behavior(); + void zeroDuration(); private: QDeclarativeEngine engine; @@ -201,6 +202,26 @@ void tst_qdeclarativesmoothedanimation::behavior() QTRY_COMPARE(theRect->y(), qreal(200)); } +void tst_qdeclarativesmoothedanimation::zeroDuration() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationZeroDuration.qml")); + + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *theRect = rect->findChild<QDeclarativeRectangle*>("theRect"); + QVERIFY(theRect); + + QDeclarativeSmoothedAnimation *easeX = rect->findChild<QDeclarativeSmoothedAnimation*>("easeX"); + QVERIFY(easeX); + QVERIFY(easeX->isRunning()); + + QTRY_VERIFY(!easeX->isRunning()); + QTRY_COMPARE(theRect->x(), qreal(200)); +} + QTEST_MAIN(tst_qdeclarativesmoothedanimation) #include "tst_qdeclarativesmoothedanimation.moc" diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index 1b2fdc4e..6e7c7f6b 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -520,7 +520,7 @@ void tst_qdeclarativevisualdatamodel::qaimRowsMoved() SingleRoleModel model; model.list.clear(); for (int i=0; i<30; i++) - model.list << ("item " + i); + model.list << (QStringLiteral("item ") + QString::number(i)); engine.rootContext()->setContextProperty("myModel", &model); QDeclarativeVisualDataModel *obj = qobject_cast<QDeclarativeVisualDataModel*>(c.create()); |