diff options
Diffstat (limited to 'tests')
170 files changed, 8268 insertions, 2109 deletions
diff --git a/tests/auto/bic/data/QtQuick.5.0.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuick.5.0.0.linux-gcc-amd64.txt index 6c8ed16153..01f76a894f 100644 --- a/tests/auto/bic/data/QtQuick.5.0.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuick.5.0.0.linux-gcc-amd64.txt @@ -7542,10 +7542,6 @@ Class QJSValueIterator base size=8 base align=8 QJSValueIterator (0x0x7f49b0d69420) 0 -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7f49b0d69540) 0 Class QQuickTransform::QPrivateSignal size=1 align=1 diff --git a/tests/auto/bic/data/QtQuick.5.1.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuick.5.1.0.linux-gcc-amd64.txt index 4f970788e3..18ee25dccb 100644 --- a/tests/auto/bic/data/QtQuick.5.1.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuick.5.1.0.linux-gcc-amd64.txt @@ -7864,10 +7864,6 @@ Class QJSValueIterator base size=8 base align=8 QJSValueIterator (0x0x7fd8c4ff79c0) 0 -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7fd8c4ff7ae0) 0 Class QQuickTransform::QPrivateSignal size=1 align=1 diff --git a/tests/auto/bic/data/QtQuick.5.2.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuick.5.2.0.linux-gcc-amd64.txt index c652ca32d6..aa46b9ca87 100644 --- a/tests/auto/bic/data/QtQuick.5.2.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuick.5.2.0.linux-gcc-amd64.txt @@ -8216,10 +8216,6 @@ QQmlPropertyMap (0x0x7f6f5eb9a4e0) 0 QObject (0x0x7f6f5e8cb060) 0 primary-for QQmlPropertyMap (0x0x7f6f5eb9a4e0) -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7f6f5e8cb120) 0 Class QQuickTransform::QPrivateSignal size=1 align=1 diff --git a/tests/auto/bic/data/QtQuick.5.3.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuick.5.3.0.linux-gcc-amd64.txt index c268efa08c..080e8b9041 100644 --- a/tests/auto/bic/data/QtQuick.5.3.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuick.5.3.0.linux-gcc-amd64.txt @@ -8247,11 +8247,6 @@ QQmlPropertyMap (0x0x7fc57b23ed68) 0 QObject (0x0x7fc57b1146c0) 0 primary-for QQmlPropertyMap (0x0x7fc57b23ed68) -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7fc57b114780) 0 - Class QQuickTransform::QPrivateSignal size=1 align=1 base size=0 base align=1 diff --git a/tests/auto/bic/data/QtQuick.5.4.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuick.5.4.0.linux-gcc-amd64.txt index e689193076..de684fa2f8 100644 --- a/tests/auto/bic/data/QtQuick.5.4.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuick.5.4.0.linux-gcc-amd64.txt @@ -8549,11 +8549,6 @@ QQmlPropertyMap (0x0x7faeca8d9e38) 0 QObject (0x0x7faeca7bb780) 0 primary-for QQmlPropertyMap (0x0x7faeca8d9e38) -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7faeca7bb840) 0 - Class QQuickTransform::QPrivateSignal size=1 align=1 base size=0 base align=1 diff --git a/tests/auto/bic/data/QtQuickWidgets.5.3.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuickWidgets.5.3.0.linux-gcc-amd64.txt index 1b55d5e268..48409f49b7 100644 --- a/tests/auto/bic/data/QtQuickWidgets.5.3.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuickWidgets.5.3.0.linux-gcc-amd64.txt @@ -8247,10 +8247,6 @@ QQmlPropertyMap (0x0x7f249928bd68) 0 QObject (0x0x7f2498d5f720) 0 primary-for QQmlPropertyMap (0x0x7f249928bd68) -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7f2498d5f7e0) 0 Class QQuickTransform::QPrivateSignal size=1 align=1 diff --git a/tests/auto/bic/data/QtQuickWidgets.5.4.0.linux-gcc-amd64.txt b/tests/auto/bic/data/QtQuickWidgets.5.4.0.linux-gcc-amd64.txt index 93e620995e..57b4485857 100644 --- a/tests/auto/bic/data/QtQuickWidgets.5.4.0.linux-gcc-amd64.txt +++ b/tests/auto/bic/data/QtQuickWidgets.5.4.0.linux-gcc-amd64.txt @@ -8549,11 +8549,6 @@ QQmlPropertyMap (0x0x7f4037b54e38) 0 QObject (0x0x7f40376357e0) 0 primary-for QQmlPropertyMap (0x0x7f4037b54e38) -Class DesignerSupport - size=8 align=8 - base size=8 base align=8 -DesignerSupport (0x0x7f40376358a0) 0 - Class QQuickTransform::QPrivateSignal size=1 align=1 base size=0 base align=1 diff --git a/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp b/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp index 325702f9c4..8132f3e24b 100644 --- a/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp +++ b/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp @@ -68,7 +68,7 @@ void tst_qquickpointattractor::test_basic() QVERIFY(d->x != 0.f); QVERIFY(d->y != 0.f); - QVERIFY(d->x == d->y); + QCOMPARE(d->x, d->y); QCOMPARE(d->vx, 0.f); QCOMPARE(d->vy, 0.f); QCOMPARE(d->ax, 0.f); diff --git a/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp b/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp index 21384ef3d8..92065d35e3 100644 --- a/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp +++ b/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp @@ -120,10 +120,10 @@ void tst_QPauseAnimationJob::changeDirectionWhileRunning() animation.setDuration(400); animation.start(); QTest::qWait(100); - QVERIFY(animation.state() == QAbstractAnimationJob::Running); + QCOMPARE(animation.state(), QAbstractAnimationJob::Running); animation.setDirection(QAbstractAnimationJob::Backward); QTest::qWait(animation.totalDuration() + 50); - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(animation.state(), QAbstractAnimationJob::Stopped); } void tst_QPauseAnimationJob::noTimerUpdates_data() @@ -155,7 +155,7 @@ void tst_QPauseAnimationJob::noTimerUpdates() QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(animation.state(), QAbstractAnimationJob::Stopped); const int expectedLoopCount = 1 + loopCount; #ifdef Q_OS_WIN @@ -183,13 +183,13 @@ void tst_QPauseAnimationJob::multiplePauseAnimations() if (animation.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(animation.state(), QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (animation2.state() != QAbstractAnimationJob::Running) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(animation2.state() == QAbstractAnimationJob::Running); + QCOMPARE(animation2.state(), QAbstractAnimationJob::Running); #ifdef Q_OS_WIN if (animation.m_updateCurrentTimeCount != 2) @@ -224,7 +224,7 @@ void tst_QPauseAnimationJob::pauseAndPropertyAnimations() QCOMPARE(animation.state(), QAbstractAnimationJob::Running); QTRY_COMPARE(animation.state(), QAbstractAnimationJob::Running); - QVERIFY(pause.state() == QAbstractAnimationJob::Running); + QCOMPARE(pause.state(), QAbstractAnimationJob::Running); QVERIFY2(pause.m_updateCurrentTimeCount >= 2, QByteArrayLiteral("pause.m_updateCurrentTimeCount=") + QByteArray::number(pause.m_updateCurrentTimeCount)); @@ -245,7 +245,7 @@ void tst_QPauseAnimationJob::pauseResume() QCOMPARE(animation.state(), QAbstractAnimationJob::Paused); animation.start(); QTest::qWait(300); - QTRY_VERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QTRY_COMPARE(animation.state(), QAbstractAnimationJob::Stopped); QVERIFY2(animation.m_updateCurrentTimeCount >= 3, QByteArrayLiteral("animation.m_updateCurrentTimeCount=") + QByteArray::number(animation.m_updateCurrentTimeCount)); } @@ -266,39 +266,39 @@ void tst_QPauseAnimationJob::sequentialPauseGroup() QCOMPARE(animation2.m_updateCurrentTimeCount, 0); QCOMPARE(animation3.m_updateCurrentTimeCount, 0); - QVERIFY(group.state() == QAbstractAnimationJob::Running); - QVERIFY(animation1.state() == QAbstractAnimationJob::Running); - QVERIFY(animation2.state() == QAbstractAnimationJob::Stopped); - QVERIFY(animation3.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation1.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation2.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(animation3.state(), QAbstractAnimationJob::Stopped); group.setCurrentTime(250); QCOMPARE(animation1.m_updateCurrentTimeCount, 2); QCOMPARE(animation2.m_updateCurrentTimeCount, 1); QCOMPARE(animation3.m_updateCurrentTimeCount, 0); - QVERIFY(group.state() == QAbstractAnimationJob::Running); - QVERIFY(animation1.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation1.state(), QAbstractAnimationJob::Stopped); QCOMPARE((QAbstractAnimationJob*)&animation2, group.currentAnimation()); - QVERIFY(animation2.state() == QAbstractAnimationJob::Running); - QVERIFY(animation3.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(animation2.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation3.state(), QAbstractAnimationJob::Stopped); group.setCurrentTime(500); QCOMPARE(animation1.m_updateCurrentTimeCount, 2); QCOMPARE(animation2.m_updateCurrentTimeCount, 2); QCOMPARE(animation3.m_updateCurrentTimeCount, 1); - QVERIFY(group.state() == QAbstractAnimationJob::Running); - QVERIFY(animation1.state() == QAbstractAnimationJob::Stopped); - QVERIFY(animation2.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation1.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(animation2.state(), QAbstractAnimationJob::Stopped); QCOMPARE((QAbstractAnimationJob*)&animation3, group.currentAnimation()); - QVERIFY(animation3.state() == QAbstractAnimationJob::Running); + QCOMPARE(animation3.state(), QAbstractAnimationJob::Running); group.setCurrentTime(750); - QVERIFY(group.state() == QAbstractAnimationJob::Stopped); - QVERIFY(animation1.state() == QAbstractAnimationJob::Stopped); - QVERIFY(animation2.state() == QAbstractAnimationJob::Stopped); - QVERIFY(animation3.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(animation1.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(animation2.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(animation3.state(), QAbstractAnimationJob::Stopped); QCOMPARE(animation1.m_updateCurrentTimeCount, 2); QCOMPARE(animation2.m_updateCurrentTimeCount, 2); @@ -318,22 +318,22 @@ void tst_QPauseAnimationJob::sequentialGroupWithPause() group.start(); - QVERIFY(group.state() == QAbstractAnimationJob::Running); - QVERIFY(animation.state() == QAbstractAnimationJob::Running); - QVERIFY(pause.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation.state(), QAbstractAnimationJob::Running); + QCOMPARE(pause.state(), QAbstractAnimationJob::Stopped); group.setCurrentTime(300); - QVERIFY(group.state() == QAbstractAnimationJob::Running); - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Running); + QCOMPARE(animation.state(), QAbstractAnimationJob::Stopped); QCOMPARE((QAbstractAnimationJob*)&pause, group.currentAnimation()); - QVERIFY(pause.state() == QAbstractAnimationJob::Running); + QCOMPARE(pause.state(), QAbstractAnimationJob::Running); group.setCurrentTime(600); - QVERIFY(group.state() == QAbstractAnimationJob::Stopped); - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); - QVERIFY(pause.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(group.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(animation.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(pause.state(), QAbstractAnimationJob::Stopped); QCOMPARE(pause.m_updateCurrentTimeCount, 2); } @@ -383,11 +383,11 @@ void tst_QPauseAnimationJob::multipleSequentialGroups() group.start(); - QVERIFY(group.state() == QAbstractAnimationJob::Running); - QVERIFY(subgroup1.state() == QAbstractAnimationJob::Running); - QVERIFY(subgroup2.state() == QAbstractAnimationJob::Running); - QVERIFY(subgroup3.state() == QAbstractAnimationJob::Running); - QVERIFY(subgroup4.state() == QAbstractAnimationJob::Running); + QCOMPARE(group.state(), QAbstractAnimationJob::Running); + QCOMPARE(subgroup1.state(), QAbstractAnimationJob::Running); + QCOMPARE(subgroup2.state(), QAbstractAnimationJob::Running); + QCOMPARE(subgroup3.state(), QAbstractAnimationJob::Running); + QCOMPARE(subgroup4.state(), QAbstractAnimationJob::Running); // This is a pretty long animation so it tends to get rather out of sync // when using the consistent timer, so run for an extra half second for good @@ -398,31 +398,31 @@ void tst_QPauseAnimationJob::multipleSequentialGroups() if (group.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QTRY_VERIFY(group.state() == QAbstractAnimationJob::Stopped); + QTRY_COMPARE(group.state(), QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (subgroup1.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(subgroup1.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(subgroup1.state(), QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (subgroup2.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(subgroup2.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(subgroup2.state(), QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (subgroup3.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(subgroup3.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(subgroup3.state(), QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (subgroup4.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(subgroup4.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(subgroup4.state(), QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (pause5.m_updateCurrentTimeCount != 4) @@ -437,7 +437,7 @@ void tst_QPauseAnimationJob::zeroDuration() animation.setDuration(0); animation.start(); QTest::qWait(animation.totalDuration() + 100); - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QCOMPARE(animation.state(), QAbstractAnimationJob::Stopped); QCOMPARE(animation.m_updateCurrentTimeCount, 1); } diff --git a/tests/auto/qml/animation/qsequentialanimationgroupjob/BLACKLIST b/tests/auto/qml/animation/qsequentialanimationgroupjob/BLACKLIST new file mode 100644 index 0000000000..2afe6074d7 --- /dev/null +++ b/tests/auto/qml/animation/qsequentialanimationgroupjob/BLACKLIST @@ -0,0 +1,2 @@ +[finishWithUncontrolledAnimation] +* diff --git a/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp b/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp index 848bec0b0b..f004593d94 100644 --- a/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp +++ b/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp @@ -911,7 +911,7 @@ void tst_QSequentialAnimationGroupJob::startDelay() QTest::qWait(500); QTRY_COMPARE(group.state(), QAnimationGroupJob::Stopped); - QVERIFY(group.currentLoopTime() == 375); + QCOMPARE(group.currentLoopTime(), 375); } void tst_QSequentialAnimationGroupJob::clearGroup() @@ -1456,7 +1456,7 @@ void tst_QSequentialAnimationGroupJob::addRemoveAnimation() void tst_QSequentialAnimationGroupJob::currentAnimation() { QSequentialAnimationGroupJob group; - QVERIFY(group.currentAnimation() == 0); + QVERIFY(!group.currentAnimation()); TestAnimation anim(0); group.appendAnimation(&anim); @@ -1466,7 +1466,7 @@ void tst_QSequentialAnimationGroupJob::currentAnimation() void tst_QSequentialAnimationGroupJob::currentAnimationWithZeroDuration() { QSequentialAnimationGroupJob group; - QVERIFY(group.currentAnimation() == 0); + QVERIFY(!group.currentAnimation()); TestAnimation zero1(0); TestAnimation zero2(0); diff --git a/tests/auto/qml/debugger/debugger.pro b/tests/auto/qml/debugger/debugger.pro index fc1c0b537b..5a08418be1 100644 --- a/tests/auto/qml/debugger/debugger.pro +++ b/tests/auto/qml/debugger/debugger.pro @@ -12,6 +12,7 @@ PUBLICTESTS += \ PRIVATETESTS += \ qqmldebugclient \ + qqmldebuglocal \ qqmldebugservice SUBDIRS += $$PUBLICTESTS diff --git a/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp b/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp index 6f559d7833..d0801dd4ee 100644 --- a/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp +++ b/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp @@ -185,7 +185,7 @@ void tst_QDebugMessageService::init() if (m_client->state() != QQmlDebugClient::Enabled) QQmlDebugTest::waitForSignal(m_client, SIGNAL(enabled())); - QVERIFY(m_client->state() == QQmlDebugClient::Enabled); + QCOMPARE(m_client->state(), QQmlDebugClient::Enabled); } void tst_QDebugMessageService::cleanup() diff --git a/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp index 155f11bdaf..db9e621d54 100644 --- a/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp +++ b/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp @@ -222,7 +222,7 @@ void tst_QPacketProtocol::read() void tst_QPacketProtocol::device() { QPacketProtocol p(m_client); - QVERIFY(p.device() == m_client); + QCOMPARE(p.device(), m_client); } void tst_QPacketProtocol::tst_QPacket_clear() diff --git a/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp b/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp index 7ca69b6d44..6fc6c6a914 100644 --- a/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp +++ b/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp @@ -42,6 +42,8 @@ #include "debugutil_p.h" #include "qqmldebugtestservice.h" +#include <private/qqmldebugconnector_p.h> + #define PORT 13770 #define STR_PORT "13770" @@ -51,6 +53,7 @@ class tst_QQmlDebugClient : public QObject private: QQmlDebugConnection *m_conn; + QQmlDebugTestService *m_service; private slots: void initTestCase(); @@ -64,26 +67,31 @@ private slots: void tst_QQmlDebugClient::initTestCase() { + QQmlDebugConnector::setPluginKey(QLatin1String("QQmlDebugServer")); + QTest::ignoreMessage(QtWarningMsg, + "QML debugger: Cannot set plugin key after loading the plugin."); + + m_service = new QQmlDebugTestService("tst_QQmlDebugClient::handshake()"); const QString waitingMsg = QString("QML Debugger: Waiting for connection on port %1...").arg(PORT); QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData()); + QQmlDebuggingEnabler::startTcpDebugServer(PORT); + new QQmlEngine(this); m_conn = new QQmlDebugConnection(this); QQmlDebugTestClient client("tst_QQmlDebugClient::handshake()", m_conn); - QQmlDebugTestService service("tst_QQmlDebugClient::handshake()"); + for (int i = 0; i < 50; ++i) { // try for 5 seconds ... m_conn->connectToHost("127.0.0.1", PORT); - if (m_conn->waitForConnected()) + if (m_conn->waitForConnected(100)) break; - QTest::qSleep(100); } QVERIFY(m_conn->isConnected()); - QTRY_VERIFY(QQmlDebugService::hasDebuggingClient()); QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); } @@ -107,14 +115,6 @@ void tst_QQmlDebugClient::state() QQmlDebugTestClient client("tst_QQmlDebugClient::state()", m_conn); QCOMPARE(client.state(), QQmlDebugClient::Unavailable); - { - QQmlDebugTestService service("tst_QQmlDebugClient::state()", 2); - QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); - QCOMPARE(client.serviceVersion(), 2.0f); - } - - QTRY_COMPARE(client.state(), QQmlDebugClient::Unavailable); - // duplicate plugin name QTest::ignoreMessage(QtWarningMsg, "QQmlDebugClient: Conflicting plugin name \"tst_QQmlDebugClient::state()\""); QQmlDebugClient client2("tst_QQmlDebugClient::state()", m_conn); @@ -126,8 +126,7 @@ void tst_QQmlDebugClient::state() void tst_QQmlDebugClient::sendMessage() { - QQmlDebugTestService service("tst_QQmlDebugClient::sendMessage()"); - QQmlDebugTestClient client("tst_QQmlDebugClient::sendMessage()", m_conn); + QQmlDebugTestClient client("tst_QQmlDebugClient::handshake()", m_conn); QByteArray msg = "hello!"; @@ -153,7 +152,6 @@ void tst_QQmlDebugClient::sequentialConnect() { QQmlDebugConnection connection2; QQmlDebugTestClient client2("tst_QQmlDebugClient::handshake()", &connection2); - QQmlDebugTestService service("tst_QQmlDebugClient::handshake()"); m_conn->close(); QVERIFY(!m_conn->isConnected()); @@ -165,23 +163,10 @@ void tst_QQmlDebugClient::sequentialConnect() connection2.connectToHost("127.0.0.1", PORT); QVERIFY(connection2.waitForConnected()); QVERIFY(connection2.isConnected()); - QTRY_VERIFY(client2.state() == QQmlDebugClient::Enabled); + QTRY_COMPARE(client2.state(), QQmlDebugClient::Enabled); } -int main(int argc, char *argv[]) -{ - int _argc = argc + 1; - char **_argv = new char*[_argc]; - for (int i = 0; i < argc; ++i) - _argv[i] = argv[i]; - char arg[] = "-qmljsdebugger=port:" STR_PORT; - _argv[_argc - 1] = arg; - - QGuiApplication app(_argc, _argv); - tst_QQmlDebugClient tc; - return QTest::qExec(&tc, _argc, _argv); - delete _argv; -} +QTEST_MAIN(tst_QQmlDebugClient) #include "tst_qqmldebugclient.moc" diff --git a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp index ed424b5a67..7dbe35807d 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp @@ -120,6 +120,8 @@ const char *UNCAUGHT = "uncaught"; const char *BLOCKMODE = "-qmljsdebugger=port:3771,3800,block"; const char *NORMALMODE = "-qmljsdebugger=port:3771,3800"; +const char *BLOCKRESTRICTEDMODE = "-qmljsdebugger=port:3771,3800,block,services:V8Debugger"; +const char *NORMALRESTRICTEDMODE = "-qmljsdebugger=port:3771,3800,services:V8Debugger"; const char *TEST_QMLFILE = "test.qml"; const char *TEST_JSFILE = "test.js"; const char *TIMER_QMLFILE = "timer.qml"; @@ -157,7 +159,8 @@ class tst_QQmlDebugJS : public QQmlDataTest { Q_OBJECT - bool init(const QString &qmlFile = QString(TEST_QMLFILE), bool blockMode = true); + void init(const QString &qmlFile = QString(TEST_QMLFILE), bool blockMode = true, + bool restrictServices = false); private slots: void initTestCase(); @@ -165,6 +168,7 @@ private slots: void cleanup(); + void connect_data(); void connect(); void interrupt(); void getVersion(); @@ -822,33 +826,29 @@ void tst_QQmlDebugJS::cleanupTestCase() // qDebug() << "Time Elapsed:" << t.elapsed(); } -bool tst_QQmlDebugJS::init(const QString &qmlFile, bool blockMode) +void tst_QQmlDebugJS::init(const QString &qmlFile, bool blockMode, bool restrictServices) { connection = new QQmlDebugConnection(); process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", this); client = new QJSDebugClient(connection); + const char *args = 0; if (blockMode) - process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(qmlFile)); + args = restrictServices ? BLOCKRESTRICTEDMODE : BLOCKMODE; else - process->start(QStringList() << QLatin1String(NORMALMODE) << testFile(qmlFile)); + args = restrictServices ? NORMALRESTRICTEDMODE : NORMALMODE; - if (!process->waitForSessionStart()) { - qDebug() << "could not launch application, or did not get 'Waiting for connection'."; - return false; - } + process->start(QStringList() << QLatin1String(args) << testFile(qmlFile)); + + QVERIFY(process->waitForSessionStart()); const int port = process->debugPort(); connection->connectToHost("127.0.0.1", port); - if (!connection->waitForConnected()) { - qDebug() << "could not connect to host!"; - return false; - } + QVERIFY(connection->waitForConnected()); - if (client->state() == QQmlDebugClient::Enabled) - return true; - return QQmlDebugTest::waitForSignal(client, SIGNAL(enabled())); + if (client->state() != QQmlDebugClient::Enabled) + QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(enabled()))); } void tst_QQmlDebugJS::cleanup() @@ -874,11 +874,21 @@ void tst_QQmlDebugJS::cleanup() connection = 0; } -void tst_QQmlDebugJS::connect() +void tst_QQmlDebugJS::connect_data() { - //void connect() + QTest::addColumn<bool>("blockMode"); + QTest::addColumn<bool>("restrictMode"); + QTest::newRow("normal/unrestricted") << false << false; + QTest::newRow("block/unrestricted") << true << false; + QTest::newRow("normal/restricted") << false << true; + QTest::newRow("block/restricted") << true << true; +} - QVERIFY(init()); +void tst_QQmlDebugJS::connect() +{ + QFETCH(bool, blockMode); + QFETCH(bool, restrictMode); + init(QString(TEST_QMLFILE), blockMode, restrictMode); client->connect(); QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(connected()))); } @@ -887,7 +897,7 @@ void tst_QQmlDebugJS::interrupt() { //void connect() - QVERIFY(init()); + init(); client->connect(); client->interrupt(); @@ -898,7 +908,7 @@ void tst_QQmlDebugJS::getVersion() { //void version() - QVERIFY(init()); + init(); client->connect(); QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(connected()))); @@ -923,7 +933,7 @@ void tst_QQmlDebugJS::disconnect() { //void disconnect() - QVERIFY(init()); + init(); client->connect(); client->disconnect(); @@ -935,7 +945,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnCompleted() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) int sourceLine = 39; - QVERIFY(init(ONCOMPLETED_QMLFILE)); + init(ONCOMPLETED_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); client->connect(); @@ -955,7 +965,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnComponentCreated() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) int sourceLine = 39; - QVERIFY(init(CREATECOMPONENT_QMLFILE)); + init(CREATECOMPONENT_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); client->connect(); @@ -973,7 +983,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnComponentCreated() void tst_QQmlDebugJS::setBreakpointInScriptOnTimerCallback() { int sourceLine = 40; - QVERIFY(init(TIMER_QMLFILE)); + init(TIMER_QMLFILE); client->connect(); //We can set the breakpoint after connect() here because the timer is repeating and if we miss @@ -995,7 +1005,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptInDifferentFile() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) int sourceLine = 35; - QVERIFY(init(LOADJSFILE_QMLFILE)); + init(LOADJSFILE_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_JSFILE), sourceLine, -1, true); client->connect(); @@ -1016,7 +1026,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnComment() int sourceLine = 39; int actualLine = 41; - QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE)); + init(BREAKPOINTRELOCATION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1038,7 +1048,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnEmptyLine() int sourceLine = 40; int actualLine = 41; - QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE)); + init(BREAKPOINTRELOCATION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1059,7 +1069,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnOptimizedBinding() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) int sourceLine = 44; - QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE)); + init(BREAKPOINTRELOCATION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1078,7 +1088,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptWithCondition() { int out = 10; int sourceLine = 42; - QVERIFY(init(CONDITION_QMLFILE)); + init(CONDITION_QMLFILE); client->connect(); //The breakpoint is in a timer loop so we can set it after connect(). @@ -1112,7 +1122,7 @@ void tst_QQmlDebugJS::setBreakpointInScriptWithCondition() void tst_QQmlDebugJS::setBreakpointInScriptThatQuits() { - QVERIFY(init(QUIT_QMLFILE)); + init(QUIT_QMLFILE); int sourceLine = 41; @@ -1153,7 +1163,7 @@ void tst_QQmlDebugJS::setBreakpointOnEvent() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - QVERIFY(init(TIMER_QMLFILE)); + init(TIMER_QMLFILE); client->setBreakpoint(QLatin1String(EVENT), QLatin1String("triggered"), -1, -1, true); client->connect(); @@ -1174,7 +1184,7 @@ void tst_QQmlDebugJS::clearBreakpoint() int sourceLine1 = 42; int sourceLine2 = 43; - QVERIFY(init(CHANGEBREAKPOINT_QMLFILE)); + init(CHANGEBREAKPOINT_QMLFILE); client->connect(); //The breakpoints are in a timer loop so we can set them after connect(). @@ -1219,7 +1229,7 @@ void tst_QQmlDebugJS::setExceptionBreak() { //void setExceptionBreak(QString type, bool enabled = false); - QVERIFY(init(EXCEPTION_QMLFILE)); + init(EXCEPTION_QMLFILE); client->setExceptionBreak(QJSDebugClient::All,true); client->connect(); QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); @@ -1230,7 +1240,7 @@ void tst_QQmlDebugJS::stepNext() //void continueDebugging(StepAction stepAction, int stepCount = 1); int sourceLine = 42; - QVERIFY(init(STEPACTION_QMLFILE)); + init(STEPACTION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1254,7 +1264,7 @@ void tst_QQmlDebugJS::stepIn() int sourceLine = 46; int actualLine = 42; - QVERIFY(init(STEPACTION_QMLFILE)); + init(STEPACTION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, 1, true); client->connect(); @@ -1278,7 +1288,7 @@ void tst_QQmlDebugJS::stepOut() int sourceLine = 42; int actualLine = 46; - QVERIFY(init(STEPACTION_QMLFILE)); + init(STEPACTION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1302,7 +1312,7 @@ void tst_QQmlDebugJS::continueDebugging() int sourceLine1 = 46; int sourceLine2 = 43; - QVERIFY(init(STEPACTION_QMLFILE)); + init(STEPACTION_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine1, -1, true); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine2, -1, true); @@ -1326,7 +1336,7 @@ void tst_QQmlDebugJS::backtrace() //void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); int sourceLine = 39; - QVERIFY(init(ONCOMPLETED_QMLFILE)); + init(ONCOMPLETED_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1341,7 +1351,7 @@ void tst_QQmlDebugJS::getFrameDetails() //void frame(int number = -1); int sourceLine = 39; - QVERIFY(init(ONCOMPLETED_QMLFILE)); + init(ONCOMPLETED_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1356,7 +1366,7 @@ void tst_QQmlDebugJS::getScopeDetails() //void scope(int number = -1, int frameNumber = -1); int sourceLine = 39; - QVERIFY(init(ONCOMPLETED_QMLFILE)); + init(ONCOMPLETED_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1371,7 +1381,7 @@ void tst_QQmlDebugJS::evaluateInGlobalScope() { //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); - QVERIFY(init()); + init(); client->connect(); client->evaluate(QLatin1String("console.log('Hello World')"), true); @@ -1393,7 +1403,7 @@ void tst_QQmlDebugJS::evaluateInLocalScope() //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); int sourceLine = 47; - QVERIFY(init(ONCOMPLETED_QMLFILE)); + init(ONCOMPLETED_QMLFILE); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); client->connect(); @@ -1427,7 +1437,7 @@ void tst_QQmlDebugJS::getScripts() { //void scripts(int types = -1, QList<int> ids = QList<int>(), bool includeSource = false, QVariant filter = QVariant()); - QVERIFY(init()); + init(); client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QString(TEST_QMLFILE), 40, -1, true); client->connect(); diff --git a/tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro b/tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro new file mode 100644 index 0000000000..b612da11de --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro @@ -0,0 +1,16 @@ +CONFIG += testcase +TARGET = tst_qqmldebuglocal +osx:CONFIG -= app_bundle + +HEADERS += ../shared/qqmldebugtestservice.h + +SOURCES += tst_qqmldebuglocal.cpp \ + ../shared/qqmldebugtestservice.cpp + +INCLUDEPATH += ../shared +include(../shared/debugutil.pri) + +CONFIG += parallel_test +QT += qml-private testlib gui-private core-private + +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 QT_QML_DEBUG_NO_WARNING diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp new file mode 100644 index 0000000000..0343ea77ee --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QSignalSpy> +#include <QTimer> +#include <QHostAddress> +#include <QDebug> +#include <QThread> +#include <ctime> + +#include "debugutil_p.h" +#include "qqmldebugtestservice.h" + +#include <private/qqmldebugconnector_p.h> + +QString fileName; + +class tst_QQmlDebugLocal : public QObject +{ + Q_OBJECT + +private: + QQmlDebugConnection *m_conn; + QQmlDebugTestService *m_service; + + bool connect(); + +signals: + void waiting(); + void parallel(); + +private slots: + void initTestCase(); + + void name(); + void state(); + void sendMessage(); +}; + +void tst_QQmlDebugLocal::initTestCase() +{ + fileName = QString::fromLatin1("tst_QQmlDebugLocal%1").arg(std::time(0)); + QQmlDebugConnector::setPluginKey("QQmlDebugServer"); + QTest::ignoreMessage(QtWarningMsg, + "QML debugger: Cannot set plugin key after loading the plugin."); + m_service = new QQmlDebugTestService("tst_QQmlDebugLocal::handshake()"); + + const QString waitingMsg = QString("QML Debugger: Connecting to socket %1...").arg(fileName); + QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData()); + + m_conn = new QQmlDebugConnection(this); + m_conn->startLocalServer(fileName); + + QQmlDebuggingEnabler::connectToLocalDebugger(fileName); + + new QQmlEngine(this); + + QQmlDebugTestClient client("tst_QQmlDebugLocal::handshake()", m_conn); + + for (int i = 0; i < 50; ++i) { + // try for 5 seconds ... + if (m_conn->waitForConnected(100)) + break; + } + + QVERIFY(m_conn->isConnected()); + + QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); +} + +void tst_QQmlDebugLocal::name() +{ + QString name = "tst_QQmlDebugLocal::name()"; + + QQmlDebugClient client(name, m_conn); + QCOMPARE(client.name(), name); +} + +void tst_QQmlDebugLocal::state() +{ + { + QQmlDebugConnection dummyConn; + QQmlDebugClient client("tst_QQmlDebugLocal::state()", &dummyConn); + QCOMPARE(client.state(), QQmlDebugClient::NotConnected); + QCOMPARE(client.serviceVersion(), -1.0f); + } + + QQmlDebugTestClient client("tst_QQmlDebugLocal::state()", m_conn); + QCOMPARE(client.state(), QQmlDebugClient::Unavailable); + + // duplicate plugin name + QTest::ignoreMessage(QtWarningMsg, "QQmlDebugClient: Conflicting plugin name \"tst_QQmlDebugLocal::state()\""); + QQmlDebugClient client2("tst_QQmlDebugLocal::state()", m_conn); + QCOMPARE(client2.state(), QQmlDebugClient::NotConnected); + + QQmlDebugClient client3("tst_QQmlDebugLocal::state3()", 0); + QCOMPARE(client3.state(), QQmlDebugClient::NotConnected); +} + +void tst_QQmlDebugLocal::sendMessage() +{ + QQmlDebugTestClient client("tst_QQmlDebugLocal::handshake()", m_conn); + + QByteArray msg = "hello!"; + + QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); +} + +QTEST_MAIN(tst_QQmlDebugLocal) + +#include "tst_qqmldebuglocal.moc" diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro diff --git a/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp b/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp index de05594161..b63c5c0a6d 100644 --- a/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp +++ b/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp @@ -44,6 +44,7 @@ #include "debugutil_p.h" #include "qqmldebugclient.h" #include "qqmldebugtestservice.h" +#include <private/qqmldebugconnector_p.h> #define PORT 3769 #define STR_PORT "3769" @@ -53,7 +54,7 @@ class tst_QQmlDebugService : public QQmlDataTest Q_OBJECT private: QQmlDebugConnection *m_conn; - + QQmlDebugTestService *m_service; private slots: @@ -65,7 +66,6 @@ private slots: void sendMessage(); void idForObject(); void objectForId(); - void objectToString(); void checkSupportForDataStreamVersion(); void checkSupportForOldDataStreamVersion(); }; @@ -73,8 +73,15 @@ private slots: void tst_QQmlDebugService::initTestCase() { QQmlDataTest::initTestCase(); + QQmlDebugConnector::setPluginKey(QLatin1String("QQmlDebugServer")); + QTest::ignoreMessage(QtWarningMsg, + "QML debugger: Cannot set plugin key after loading the plugin."); + m_service = new QQmlDebugTestService("tst_QQmlDebugService", 2); + const QString waitingMsg = QString("QML Debugger: Waiting for connection on port %1...").arg(PORT); QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData()); + QQmlDebuggingEnabler::startTcpDebugServer(PORT); + new QQmlEngine(this); m_conn = new QQmlDebugConnection(this); @@ -87,8 +94,6 @@ void tst_QQmlDebugService::initTestCase() QTest::qSleep(100); } QVERIFY(m_conn->isConnected()); - - QTRY_VERIFY(QQmlDebugService::hasDebuggingClient()); } void tst_QQmlDebugService::checkPortRange() @@ -128,67 +133,64 @@ void tst_QQmlDebugService::checkPortRange() void tst_QQmlDebugService::name() { - QString name = "tst_QQmlDebugService::name()"; - - QQmlDebugService service(name, 1); - QCOMPARE(service.name(), name); + QCOMPARE(m_service->name(), QLatin1String("tst_QQmlDebugService")); } void tst_QQmlDebugService::version() { - QString name = "tst_QQmlDebugService::name()"; - - QQmlDebugService service(name, 2); - QCOMPARE(service.version(), 2.0f); + QCOMPARE(m_service->version(), 2.0f); } void tst_QQmlDebugService::state() { - QQmlDebugTestService service("tst_QQmlDebugService::state()"); - QCOMPARE(service.state(), QQmlDebugService::Unavailable); + QCOMPARE(m_service->state(), QQmlDebugService::Unavailable); { - QQmlDebugTestClient client("tst_QQmlDebugService::state()", m_conn); + QQmlDebugTestClient client("tst_QQmlDebugService", m_conn); QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); - QTRY_COMPARE(service.state(), QQmlDebugService::Enabled); + QTRY_COMPARE(m_service->state(), QQmlDebugService::Enabled); } + QTRY_COMPARE(m_service->state(), QQmlDebugService::Unavailable); - QTRY_COMPARE(service.state(), QQmlDebugService::Unavailable); - - QTest::ignoreMessage(QtWarningMsg, "QQmlDebugService: Conflicting plugin name \"tst_QQmlDebugService::state()\""); - QQmlDebugTestService duplicate("tst_QQmlDebugService::state()"); + // We can do this because it will never addService() + QTest::ignoreMessage(QtWarningMsg, + "QQmlDebugService: Conflicting plugin name \"tst_QQmlDebugService\""); + QQmlDebugTestService duplicate("tst_QQmlDebugService"); QCOMPARE(duplicate.state(), QQmlDebugService::NotConnected); + QTest::ignoreMessage(QtWarningMsg, + "QQmlDebugService: Plugin \"tst_QQmlDebugService\" is not registered."); } void tst_QQmlDebugService::sendMessage() { - QQmlDebugTestService service("tst_QQmlDebugService::sendMessage()"); - QQmlDebugTestClient client("tst_QQmlDebugService::sendMessage()", m_conn); + QQmlDebugTestClient client("tst_QQmlDebugService", m_conn); QByteArray msg = "hello!"; QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); - QTRY_COMPARE(service.state(), QQmlDebugService::Enabled); + QTRY_COMPARE(m_service->state(), QQmlDebugService::Enabled); client.sendMessage(msg); QByteArray resp = client.waitForResponse(); QCOMPARE(resp, msg); - QTest::ignoreMessage(QtWarningMsg, "QQmlDebugService: Conflicting plugin name \"tst_QQmlDebugService::sendMessage()\""); - QQmlDebugTestService duplicate("tst_QQmlDebugService::sendMessage()"); - duplicate.sendMessage("msg"); + QTest::ignoreMessage(QtWarningMsg, + "QQmlDebugService: Conflicting plugin name \"tst_QQmlDebugService\""); + QQmlDebugTestService duplicate("tst_QQmlDebugService"); + emit duplicate.messageToClient(duplicate.name(), "msg"); + QTest::ignoreMessage(QtWarningMsg, + "QQmlDebugService: Plugin \"tst_QQmlDebugService\" is not registered."); } void tst_QQmlDebugService::checkSupportForDataStreamVersion() { - QQmlDebugTestService service("tst_QQmlDebugService::sendMessage2()"); - QQmlDebugTestClient client("tst_QQmlDebugService::sendMessage2()", m_conn); + QQmlDebugTestClient client("tst_QQmlDebugService", m_conn); QByteArray msg = "hello!"; QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); - QTRY_COMPARE(service.state(), QQmlDebugService::Enabled); + QTRY_COMPARE(m_service->state(), QQmlDebugService::Enabled); client.sendMessage(msg); QByteArray resp = client.waitForResponse(); @@ -231,18 +233,6 @@ void tst_QQmlDebugService::objectForId() QCOMPARE(QQmlDebugService::objectForId(id), static_cast<QObject*>(0)); } -void tst_QQmlDebugService::objectToString() -{ - QCOMPARE(QQmlDebugService::objectToString(0), QString("NULL")); - - QObject *obj = new QObject; - QCOMPARE(QQmlDebugService::objectToString(obj), QString("QObject: <unnamed>")); - - obj->setObjectName("Hello"); - QCOMPARE(QQmlDebugService::objectToString(obj), QString("QObject: Hello")); - delete obj; -} - void tst_QQmlDebugService::checkSupportForOldDataStreamVersion() { //create a new connection; @@ -258,14 +248,12 @@ void tst_QQmlDebugService::checkSupportForOldDataStreamVersion() } QVERIFY(m_conn->isConnected()); - QTRY_VERIFY(QQmlDebugService::hasDebuggingClient()); - QQmlDebugTestService service("tst_QQmlDebugService::sendMessage2()"); - QQmlDebugTestClient client("tst_QQmlDebugService::sendMessage2()", m_conn); + QQmlDebugTestClient client("tst_QQmlDebugService", m_conn); QByteArray msg = "hello!"; QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled); - QTRY_COMPARE(service.state(), QQmlDebugService::Enabled); + QTRY_COMPARE(m_service->state(), QQmlDebugService::Enabled); client.sendMessage(msg); QByteArray resp = client.waitForResponse(); @@ -273,20 +261,6 @@ void tst_QQmlDebugService::checkSupportForOldDataStreamVersion() QCOMPARE(m_conn->dataStreamVersion(), int(QDataStream::Qt_4_7)); } - -int main(int argc, char *argv[]) -{ - int _argc = argc + 1; - char **_argv = new char*[_argc]; - for (int i = 0; i < argc; ++i) - _argv[i] = argv[i]; - char arg[] = "-qmljsdebugger=port:" STR_PORT ",host:127.0.0.1"; - _argv[_argc - 1] = arg; - - QGuiApplication app(_argc, _argv); - tst_QQmlDebugService tc; - return QTest::qExec(&tc, _argc, _argv); - delete _argv; -} +QTEST_MAIN(tst_QQmlDebugService) #include "tst_qqmldebugservice.moc" diff --git a/tests/auto/qml/debugger/qqmlenginecontrol/tst_qqmlenginecontrol.cpp b/tests/auto/qml/debugger/qqmlenginecontrol/tst_qqmlenginecontrol.cpp index f6cf9dae60..11fa56d710 100644 --- a/tests/auto/qml/debugger/qqmlenginecontrol/tst_qqmlenginecontrol.cpp +++ b/tests/auto/qml/debugger/qqmlenginecontrol/tst_qqmlenginecontrol.cpp @@ -103,12 +103,15 @@ private: QQmlDebugConnection *m_connection; QQmlEngineControlClient *m_client; - void connect(const QString &testFile); + void connect(const QString &testFile, bool restrictServices); + void engine_data(); private slots: void cleanup(); + void startEngine_data(); void startEngine(); + void stopEngine_data(); void stopEngine(); }; @@ -148,11 +151,13 @@ void QQmlEngineControlClient::messageReceived(const QByteArray &message) QVERIFY(stream.atEnd()); } -void tst_QQmlEngineControl::connect(const QString &testFile) +void tst_QQmlEngineControl::connect(const QString &testFile, bool restrictServices) { const QString executable = QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene"; QStringList arguments; - arguments << QString("-qmljsdebugger=port:" STR_PORT_FROM "," STR_PORT_TO ",block"); + arguments << QString::fromLatin1("-qmljsdebugger=port:%1,%2,block%3") + .arg(STR_PORT_FROM).arg(STR_PORT_TO) + .arg(restrictServices ? QStringLiteral(",services:EngineControl") : QString()); arguments << QQmlDataTest::instance()->testFile(testFile); @@ -165,6 +170,8 @@ void tst_QQmlEngineControl::connect(const QString &testFile) const int port = m_process->debugPort(); m_connection->connectToHost(QLatin1String("127.0.0.1"), port); + + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); } void tst_QQmlEngineControl::cleanup() @@ -183,11 +190,23 @@ void tst_QQmlEngineControl::cleanup() m_connection = 0; } +void tst_QQmlEngineControl::engine_data() +{ + QTest::addColumn<bool>("restrictMode"); + QTest::newRow("unrestricted") << false; + QTest::newRow("restricted") << true; +} + +void tst_QQmlEngineControl::startEngine_data() +{ + engine_data(); +} + void tst_QQmlEngineControl::startEngine() { - connect("test.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + QFETCH(bool, restrictMode); + + connect("test.qml", restrictMode); QTRY_VERIFY(!m_client->startingEngines.empty()); m_client->command(QQmlEngineControlClient::StartWaitingEngine, m_client->startingEngines.last()); @@ -196,11 +215,16 @@ void tst_QQmlEngineControl::startEngine() "No engine start message received in time."); } +void tst_QQmlEngineControl::stopEngine_data() +{ + engine_data(); +} + void tst_QQmlEngineControl::stopEngine() { - connect("exit.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + QFETCH(bool, restrictMode); + + connect("exit.qml", restrictMode); QTRY_VERIFY(!m_client->startingEngines.empty()); m_client->command(QQmlEngineControlClient::StartWaitingEngine, m_client->startingEngines.last()); diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp index 8d119a30d7..0285bae189 100644 --- a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp @@ -61,6 +61,7 @@ public: private: + void init(bool restrictServices); QmlDebugObjectReference findRootObject(); QQmlDebugProcess *m_process; @@ -68,9 +69,9 @@ private: QQmlEngineDebugClient *m_engineDebugClient; private slots: - void init(); void cleanup(); + void connect_data(); void connect(); void clearObjectReferenceHashonReloadQml(); }; @@ -93,9 +94,12 @@ QmlDebugObjectReference tst_QQmlEngineDebugInspectorIntegration::findRootObject( } -void tst_QQmlEngineDebugInspectorIntegration::init() +void tst_QQmlEngineDebugInspectorIntegration::init(bool restrictServices) { - const QString argument = "-qmljsdebugger=port:" STR_PORT_FROM "," STR_PORT_TO ",block"; + const QString argument = QString::fromLatin1("-qmljsdebugger=port:%1,%2,block%3") + .arg(STR_PORT_FROM).arg(STR_PORT_TO) + .arg(restrictServices ? QStringLiteral(",services:QmlDebugger,QmlInspector") : + QString()); // ### Still using qmlscene because of QTBUG-33376 m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) @@ -108,10 +112,8 @@ void tst_QQmlEngineDebugInspectorIntegration::init() m_inspectorClient = new QQmlInspectorClient(m_connection); m_engineDebugClient = new QQmlEngineDebugClient(m_connection); - const int port = m_process->debugPort(); - m_connection->connectToHost(QLatin1String("127.0.0.1"), port); - bool ok = m_connection->waitForConnected(); - QVERIFY(ok); + m_connection->connectToHost(QLatin1String("127.0.0.1"), m_process->debugPort()); + QVERIFY(m_connection->waitForConnected()); } void tst_QQmlEngineDebugInspectorIntegration::cleanup() @@ -125,14 +127,24 @@ void tst_QQmlEngineDebugInspectorIntegration::cleanup() delete m_inspectorClient; } +void tst_QQmlEngineDebugInspectorIntegration::connect_data() +{ + QTest::addColumn<bool>("restrictMode"); + QTest::newRow("unrestricted") << false; + QTest::newRow("restricted") << true; +} + void tst_QQmlEngineDebugInspectorIntegration::connect() { + QFETCH(bool, restrictMode); + init(restrictMode); QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled); QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled); } void tst_QQmlEngineDebugInspectorIntegration::clearObjectReferenceHashonReloadQml() { + init(true); QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled); bool success = false; QmlDebugObjectReference rootObject = findRootObject(); diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index d3bb5c38ca..bc3220ad8c 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -87,6 +87,8 @@ public: class tst_QQmlEngineDebugService : public QObject { Q_OBJECT +public: + tst_QQmlEngineDebugService() : m_conn(0), m_dbg(0), m_engine(0), m_rootItem(0) {} private: QmlDebugObjectReference findRootObject(int context = 0, @@ -349,9 +351,8 @@ void tst_QQmlEngineDebugService::initTestCase() bool ok = m_conn->waitForConnected(); QVERIFY(ok); - QTRY_VERIFY(QQmlDebugService::hasDebuggingClient()); m_dbg = new QQmlEngineDebugClient(m_conn); - QTRY_VERIFY(m_dbg->state() == QQmlEngineDebugClient::Enabled); + QTRY_COMPARE(m_dbg->state(), QQmlEngineDebugClient::Enabled); } void tst_QQmlEngineDebugService::cleanupTestCase() @@ -372,7 +373,7 @@ void tst_QQmlEngineDebugService::setMethodBody() QVariant rv; QVERIFY(QMetaObject::invokeMethod(root, "myMethodNoArgs", Qt::DirectConnection, Q_RETURN_ARG(QVariant, rv))); - QVERIFY(rv == QVariant(qreal(3))); + QCOMPARE(rv, QVariant(qreal(3))); QVERIFY(m_dbg->setMethodBody(obj.debugId, "myMethodNoArgs", "return 7", @@ -382,7 +383,7 @@ void tst_QQmlEngineDebugService::setMethodBody() QVERIFY(QMetaObject::invokeMethod(root, "myMethodNoArgs", Qt::DirectConnection, Q_RETURN_ARG(QVariant, rv))); - QVERIFY(rv == QVariant(qreal(7))); + QCOMPARE(rv, QVariant(qreal(7))); } // With args @@ -390,7 +391,7 @@ void tst_QQmlEngineDebugService::setMethodBody() QVariant rv; QVERIFY(QMetaObject::invokeMethod(root, "myMethod", Qt::DirectConnection, Q_RETURN_ARG(QVariant, rv), Q_ARG(QVariant, QVariant(19)))); - QVERIFY(rv == QVariant(qreal(28))); + QCOMPARE(rv, QVariant(qreal(28))); QVERIFY(m_dbg->setMethodBody(obj.debugId, "myMethod", "return a + 7", &success)); @@ -399,7 +400,7 @@ void tst_QQmlEngineDebugService::setMethodBody() QVERIFY(QMetaObject::invokeMethod(root, "myMethod", Qt::DirectConnection, Q_RETURN_ARG(QVariant, rv), Q_ARG(QVariant, QVariant(19)))); - QVERIFY(rv == QVariant(qreal(26))); + QCOMPARE(rv, QVariant(qreal(26))); } } @@ -731,7 +732,7 @@ void tst_QQmlEngineDebugService::queryObjectsForLocation() QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - QVERIFY(m_dbg->objects().count() == 1); + QCOMPARE(m_dbg->objects().count(), 1); QmlDebugObjectReference obj = m_dbg->objects().first(); // check source as defined in main() @@ -1018,7 +1019,7 @@ void tst_QQmlEngineDebugService::setBindingForObject() mouseAreaObject = m_dbg->object(); onEnteredRef = findProperty(mouseAreaObject.properties, "onEntered"); QCOMPARE(onEnteredRef.name, QString("onEntered")); - QCOMPARE(onEnteredRef.value, QVariant("{console.log('hello, world') }")); + QCOMPARE(onEnteredRef.value, QVariant("function() { [code] }")); } void tst_QQmlEngineDebugService::resetBindingForObject() @@ -1224,7 +1225,7 @@ int main(int argc, char *argv[]) char **_argv = new char*[_argc]; for (int i = 0; i < argc; ++i) _argv[i] = argv[i]; - char arg[] = "-qmljsdebugger=port:3768"; + char arg[] = "-qmljsdebugger=port:3768,services:QmlDebugger"; _argv[_argc - 1] = arg; QGuiApplication app(_argc, _argv); diff --git a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp index 5ed866c04d..70833f5e2c 100644 --- a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp +++ b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp @@ -60,7 +60,7 @@ public: } private: - void startQmlsceneProcess(const char *qmlFile); + void startQmlsceneProcess(const char *qmlFile, bool restrictMode = true); private: QQmlDebugProcess *m_process; @@ -68,18 +68,20 @@ private: QQmlInspectorClient *m_client; private slots: - void init(); void cleanup(); + void connect_data(); void connect(); void showAppOnTop(); void reloadQml(); void reloadQmlWindow(); }; -void tst_QQmlInspector::startQmlsceneProcess(const char * /* qmlFile */) +void tst_QQmlInspector::startQmlsceneProcess(const char * /* qmlFile */, bool restrictServices) { - const QString argument = "-qmljsdebugger=port:" STR_PORT_FROM "," STR_PORT_TO ",block"; + const QString argument = QString::fromLatin1("-qmljsdebugger=port:%1,%2,block%3") + .arg(STR_PORT_FROM).arg(STR_PORT_TO) + .arg(restrictServices ? QStringLiteral(",services:QmlInspector") : QString()); // ### This should be using qml instead of qmlscene, but can't because of QTBUG-33376 (same as the XFAIL testcase) m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", this); @@ -87,15 +89,13 @@ void tst_QQmlInspector::startQmlsceneProcess(const char * /* qmlFile */) QVERIFY2(m_process->waitForSessionStart(), "Could not launch application, or did not get 'Waiting for connection'."); - QQmlDebugConnection *m_connection = new QQmlDebugConnection(); + m_connection = new QQmlDebugConnection(); m_client = new QQmlInspectorClient(m_connection); - const int port = m_process->debugPort(); - m_connection->connectToHost(QLatin1String("127.0.0.1"), port); -} + m_connection->connectToHost(QLatin1String("127.0.0.1"), m_process->debugPort()); + QVERIFY(m_client); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); -void tst_QQmlInspector::init() -{ } void tst_QQmlInspector::cleanup() @@ -104,20 +104,31 @@ void tst_QQmlInspector::cleanup() qDebug() << "Process State:" << m_process->state(); qDebug() << "Application Output:" << m_process->output(); } - delete m_process; - delete m_connection; delete m_client; + m_client = 0; + delete m_connection; + m_connection = 0; + delete m_process; + m_process = 0; +} + +void tst_QQmlInspector::connect_data() +{ + QTest::addColumn<bool>("restrictMode"); + QTest::newRow("unrestricted") << false; + QTest::newRow("restricted") << true; } void tst_QQmlInspector::connect() { - startQmlsceneProcess("qtquick2.qml"); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + QFETCH(bool, restrictMode); + startQmlsceneProcess("qtquick2.qml", restrictMode); } void tst_QQmlInspector::showAppOnTop() { startQmlsceneProcess("qtquick2.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setShowAppOnTop(true); @@ -132,6 +143,7 @@ void tst_QQmlInspector::showAppOnTop() void tst_QQmlInspector::reloadQml() { startQmlsceneProcess("qtquick2.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); QByteArray fileContents; @@ -157,6 +169,7 @@ void tst_QQmlInspector::reloadQml() void tst_QQmlInspector::reloadQmlWindow() { startQmlsceneProcess("window.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); QByteArray fileContents; @@ -173,8 +186,8 @@ void tst_QQmlInspector::reloadQmlWindow() QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(responseReceived()))); QEXPECT_FAIL("", "cannot debug with a QML file containing a top-level Window", Abort); // QTBUG-33376 - QTRY_COMPARE(m_process->output().contains( - QString("version 2.0")), true); + // TODO: remove the timeout once we don't expect it to fail anymore. + QTRY_VERIFY_WITH_TIMEOUT(m_process->output().contains(QString("version 2.0")), 1); QCOMPARE(m_client->m_requestResult, true); QCOMPARE(m_client->m_reloadRequestId, m_client->m_responseId); diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/data/timer.qml b/tests/auto/qml/debugger/qqmlprofilerservice/data/timer.qml new file mode 100644 index 0000000000..18b8947172 --- /dev/null +++ b/tests/auto/qml/debugger/qqmlprofilerservice/data/timer.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Rectangle { + width: 100 + height: 62 + + Timer { + running: true + repeat: true + interval: 50 + onTriggered: height = (2 * height) % 99; + } +} + diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro b/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro index ec84139797..e422d3ef99 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro +++ b/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro @@ -21,4 +21,5 @@ OTHER_FILES += \ data/scenegraphTest.qml \ data/TestImage_2x2.png \ data/signalSourceLocation.qml \ - data/javascript.qml + data/javascript.qml \ + data/timer.qml diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index 094bf43549..0e63e18952 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -139,16 +139,18 @@ public: { } - QList<QQmlProfilerData> qmlMessages; - QList<QQmlProfilerData> javascriptMessages; - QList<QQmlProfilerData> jsHeapMessages; - QList<QQmlProfilerData> asynchronousMessages; - QList<QQmlProfilerData> pixmapMessages; + QVector<QQmlProfilerData> qmlMessages; + QVector<QQmlProfilerData> javascriptMessages; + QVector<QQmlProfilerData> jsHeapMessages; + QVector<QQmlProfilerData> asynchronousMessages; + QVector<QQmlProfilerData> pixmapMessages; - void setTraceState(bool enabled) { + void setTraceState(bool enabled, quint32 flushInterval = 0) { QByteArray message; QDataStream stream(&message, QIODevice::WriteOnly); stream << enabled; + if (enabled && flushInterval) + stream << -1 << std::numeric_limits<quint64>::max() << flushInterval; sendMessage(message); } @@ -195,7 +197,7 @@ private: CheckAll = CheckMessageType | CheckDetailType | CheckLine | CheckColumn | CheckDataEndsWith }; - void connect(bool block, const QString &testFile); + void connect(bool block, const QString &testFile, bool restrictServices = true); void checkTraceReceived(); void checkJsHeap(); bool verify(MessageListType type, int expectedPosition, const QQmlProfilerData &expected, @@ -204,15 +206,15 @@ private: private slots: void cleanup(); - void blockingConnectWithTraceEnabled(); - void blockingConnectWithTraceDisabled(); - void nonBlockingConnect(); + void connect_data(); + void connect(); void pixmapCacheData(); void scenegraphData(); void profileOnExit(); void controlFromJS(); void signalSourceLocation(); void javascript(); + void flushInterval(); }; #define VERIFY(type, position, expected, checks) QVERIFY(verify(type, position, expected, checks)) @@ -354,17 +356,16 @@ void QQmlProfilerClient::messageReceived(const QByteArray &message) qmlMessages.append(data); } -void tst_QQmlProfilerService::connect(bool block, const QString &testFile) +void tst_QQmlProfilerService::connect(bool block, const QString &testFile, bool restrictServices) { // ### Still using qmlscene due to QTBUG-33377 const QString executable = QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene"; QStringList arguments; - if (block) - arguments << QString("-qmljsdebugger=port:" STR_PORT_FROM "," STR_PORT_TO ",block"); - else - arguments << QString("-qmljsdebugger=port:" STR_PORT_FROM "," STR_PORT_TO ); - - arguments << QQmlDataTest::instance()->testFile(testFile); + arguments << QString::fromLatin1("-qmljsdebugger=port:%1,%2%3%4") + .arg(STR_PORT_FROM).arg(STR_PORT_TO) + .arg(block ? QStringLiteral(",block") : QString()) + .arg(restrictServices ? QStringLiteral(",services:CanvasFrameRate") : QString()) + << QQmlDataTest::instance()->testFile(testFile); m_process = new QQmlDebugProcess(executable, this); m_process->start(QStringList() << arguments); @@ -375,6 +376,8 @@ void tst_QQmlProfilerService::connect(bool block, const QString &testFile) const int port = m_process->debugPort(); m_connection->connectToHost(QLatin1String("127.0.0.1"), port); + QVERIFY(m_client); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); } void tst_QQmlProfilerService::checkTraceReceived() @@ -449,7 +452,7 @@ bool tst_QQmlProfilerService::verify(tst_QQmlProfilerService::MessageListType ty int expectedPosition, const QQmlProfilerData &expected, quint32 checks) { - QList<QQmlProfilerData> *target = 0; + QVector<QQmlProfilerData> *target = 0; switch (type) { case MessageListQML: target = &(m_client->qmlMessages); break; case MessageListJavaScript: target = &(m_client->javascriptMessages); break; @@ -509,7 +512,7 @@ bool tst_QQmlProfilerService::verify(tst_QQmlProfilerService::MessageListType ty void tst_QQmlProfilerService::cleanup() { - if (QTest::currentTestFailed()) { + if (m_client && QTest::currentTestFailed()) { qDebug() << "QML Messages:" << m_client->qmlMessages.count(); int i = 0; foreach (const QQmlProfilerData &data, m_client->qmlMessages) { @@ -547,7 +550,7 @@ void tst_QQmlProfilerService::cleanup() qDebug() << "Process State:" << (m_process ? m_process->state() : QLatin1String("null")); qDebug() << "Application Output:" << (m_process ? m_process->output() : QLatin1String("null")); qDebug() << "Connection State:" << (m_connection ? m_connection->stateString() : QLatin1String("null")); - qDebug() << "Client State:" << (m_client ? m_client->stateString() : QLatin1String("null")); + qDebug() << "Client State:" << m_client->stateString(); } delete m_process; m_process = 0; @@ -557,37 +560,32 @@ void tst_QQmlProfilerService::cleanup() m_connection = 0; } -void tst_QQmlProfilerService::blockingConnectWithTraceEnabled() +void tst_QQmlProfilerService::connect_data() { - connect(true, "test.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); - - m_client->setTraceState(true); - m_client->setTraceState(false); - checkTraceReceived(); - checkJsHeap(); + QTest::addColumn<bool>("blockMode"); + QTest::addColumn<bool>("restrictMode"); + QTest::addColumn<bool>("traceEnabled"); + QTest::newRow("normal/unrestricted/disabled") << false << false << false; + QTest::newRow("block/unrestricted/disabled") << true << false << false; + QTest::newRow("normal/restricted/disabled") << false << true << false; + QTest::newRow("block/restricted/disabled") << true << true << false; + QTest::newRow("normal/unrestricted/enabled") << false << false << true; + QTest::newRow("block/unrestricted/enabled") << true << false << true; + QTest::newRow("normal/restricted/enabled") << false << true << true; + QTest::newRow("block/restricted/enabled") << true << true << true; } -void tst_QQmlProfilerService::blockingConnectWithTraceDisabled() +void tst_QQmlProfilerService::connect() { - connect(true, "test.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + QFETCH(bool, blockMode); + QFETCH(bool, restrictMode); + QFETCH(bool, traceEnabled); - m_client->setTraceState(false); - m_client->setTraceState(true); - m_client->setTraceState(false); - checkTraceReceived(); - checkJsHeap(); -} - -void tst_QQmlProfilerService::nonBlockingConnect() -{ - connect(false, "test.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + connect(blockMode, "test.qml", restrictMode); + // if the engine is waiting, then the first message determines if it starts with trace enabled + if (!traceEnabled) + m_client->setTraceState(false); m_client->setTraceState(true); m_client->setTraceState(false); checkTraceReceived(); @@ -597,8 +595,6 @@ void tst_QQmlProfilerService::nonBlockingConnect() void tst_QQmlProfilerService::pixmapCacheData() { connect(true, "pixmapCacheTest.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); @@ -636,8 +632,6 @@ void tst_QQmlProfilerService::pixmapCacheData() void tst_QQmlProfilerService::scenegraphData() { connect(true, "scenegraphTest.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); @@ -690,8 +684,6 @@ void tst_QQmlProfilerService::scenegraphData() void tst_QQmlProfilerService::profileOnExit() { connect(true, "exit.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); @@ -702,8 +694,6 @@ void tst_QQmlProfilerService::profileOnExit() void tst_QQmlProfilerService::controlFromJS() { connect(true, "controlFromJS.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(false); checkTraceReceived(); @@ -713,8 +703,6 @@ void tst_QQmlProfilerService::controlFromJS() void tst_QQmlProfilerService::signalSourceLocation() { connect(true, "signalSourceLocation.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); while (!(m_process->output().contains(QLatin1String("500")))) @@ -738,8 +726,6 @@ void tst_QQmlProfilerService::signalSourceLocation() void tst_QQmlProfilerService::javascript() { connect(true, "javascript.qml"); - QVERIFY(m_client); - QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); while (!(m_process->output().contains(QLatin1String("done")))) @@ -766,6 +752,22 @@ void tst_QQmlProfilerService::javascript() VERIFY(MessageListJavaScript, 21, expected, CheckMessageType | CheckDetailType); } +void tst_QQmlProfilerService::flushInterval() +{ + connect(true, "timer.qml"); + + m_client->setTraceState(true, 1); + + // Make sure we get multiple messages + QTRY_VERIFY(m_client->qmlMessages.length() > 0); + QVERIFY(m_client->qmlMessages.length() < 100); + QTRY_VERIFY(m_client->qmlMessages.length() > 100); + + m_client->setTraceState(false); + checkTraceReceived(); + checkJsHeap(); +} + QTEST_MAIN(tst_QQmlProfilerService) #include "tst_qqmlprofilerservice.moc" diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index 74f22e6997..51d706b818 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -91,7 +91,7 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) m_timer.setSingleShot(true); m_timer.setInterval(5000); connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput())); - connect(&m_process, SIGNAL(error(QProcess::ProcessError)), + connect(&m_process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); } diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp index c7281dec69..0f7e572e02 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp @@ -39,6 +39,8 @@ #include <QtCore/qstringlist.h> #include <QtCore/qtimer.h> #include <QtNetwork/qnetworkproxy.h> +#include <QtNetwork/qlocalserver.h> +#include <QtNetwork/qlocalsocket.h> const int protocolVersion = 1; const QString serverId = QLatin1String("QDeclarativeDebugServer"); @@ -61,6 +63,7 @@ public: QQmlDebugConnection *q; QPacketProtocol *protocol; QIODevice *device; + QLocalServer *server; QEventLoop handshakeEventLoop; QTimer handshakeTimer; @@ -72,6 +75,10 @@ public: void connectDeviceSignals(); public Q_SLOTS: + void forwardStateChange(QLocalSocket::LocalSocketState state); + void forwardError(QLocalSocket::LocalSocketError error); + + void newConnection(); void connected(); void readyRead(); void deviceAboutToClose(); @@ -79,7 +86,7 @@ public Q_SLOTS: }; QQmlDebugConnectionPrivate::QQmlDebugConnectionPrivate(QQmlDebugConnection *c) - : QObject(c), q(c), protocol(0), device(0), gotHello(false) + : QObject(c), q(c), protocol(0), device(0), server(0), gotHello(false) { protocol = new QPacketProtocol(q, this); QObject::connect(c, SIGNAL(connected()), this, SLOT(connected())); @@ -307,10 +314,13 @@ void QQmlDebugConnection::close() bool QQmlDebugConnection::waitForConnected(int msecs) { QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device); - if (!socket) - return false; - if (!socket->waitForConnected(msecs)) + if (!socket) { + if (!d->server || (!d->server->hasPendingConnections() && + !d->server->waitForNewConnection(msecs))) + return false; + } else if (!socket->waitForConnected(msecs)) { return false; + } // wait for handshake d->handshakeTimer.start(); d->handshakeEventLoop.exec(); @@ -336,9 +346,13 @@ QString QQmlDebugConnection::stateString() const QAbstractSocket::SocketState QQmlDebugConnection::state() const { - QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device); - if (socket) - return socket->state(); + QAbstractSocket *abstractSocket = qobject_cast<QAbstractSocket*>(d->device); + if (abstractSocket) + return abstractSocket->state(); + + QLocalSocket *localSocket = qobject_cast<QLocalSocket*>(d->device); + if (localSocket) + return static_cast<QAbstractSocket::SocketState>(localSocket->state()); return QAbstractSocket::UnconnectedState; } @@ -366,6 +380,29 @@ void QQmlDebugConnection::connectToHost(const QString &hostName, quint16 port) QIODevice::open(ReadWrite | Unbuffered); } +void QQmlDebugConnection::startLocalServer(const QString &fileName) +{ + d->gotHello = false; + d->server = new QLocalServer(d); + // QueuedConnection so that waitForNewConnection() returns true. + connect(d->server, SIGNAL(newConnection()), d, SLOT(newConnection()), Qt::QueuedConnection); + d->server->listen(fileName); + QIODevice::open(ReadWrite | Unbuffered); +} + +void QQmlDebugConnectionPrivate::newConnection() +{ + QLocalSocket *socket = server->nextPendingConnection(); + server->close(); + device = socket; + connectDeviceSignals(); + connect(socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)), + this, SLOT(forwardStateChange(QLocalSocket::LocalSocketState))); + connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)), + this, SLOT(forwardError(QLocalSocket::LocalSocketError))); + emit q->connected(); +} + void QQmlDebugConnectionPrivate::connectDeviceSignals() { connect(device, SIGNAL(bytesWritten(qint64)), q, SIGNAL(bytesWritten(qint64))); @@ -373,7 +410,15 @@ void QQmlDebugConnectionPrivate::connectDeviceSignals() connect(device, SIGNAL(aboutToClose()), this, SLOT(deviceAboutToClose())); } -// +void QQmlDebugConnectionPrivate::forwardStateChange(QLocalSocket::LocalSocketState state) +{ + emit q->stateChanged(static_cast<QAbstractSocket::SocketState>(state)); +} + +void QQmlDebugConnectionPrivate::forwardError(QLocalSocket::LocalSocketError error) +{ + emit q->error(static_cast<QAbstractSocket::SocketError>(error)); +} QQmlDebugClientPrivate::QQmlDebugClientPrivate() : connection(0) diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.h b/tests/auto/qml/debugger/shared/qqmldebugclient.h index 52f428cca7..fe9da693c8 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugclient.h +++ b/tests/auto/qml/debugger/shared/qqmldebugclient.h @@ -46,6 +46,7 @@ public: ~QQmlDebugConnection(); void connectToHost(const QString &hostName, quint16 port); + void startLocalServer(const QString &fileName); void setDataStreamVersion(int dataStreamVersion); int dataStreamVersion(); diff --git a/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp b/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp index 990cb1caa1..e62aa2ce61 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp @@ -37,13 +37,12 @@ QQmlDebugTestService::QQmlDebugTestService(const QString &s, float version, QObject *parent) : QQmlDebugService(s, version, parent) { - registerService(); } void QQmlDebugTestService::messageReceived(const QByteArray &ba) { Q_ASSERT(QThread::currentThread() != thread()); - QMetaObject::invokeMethod(this, "_sendMessage", Qt::QueuedConnection, Q_ARG(QByteArray, ba)); + emit messageToClient(name(), ba); } void QQmlDebugTestService::stateAboutToBeChanged(QQmlDebugService::State) @@ -56,8 +55,3 @@ void QQmlDebugTestService::stateChanged(State) Q_ASSERT(QThread::currentThread() != thread()); emit stateHasChanged(); } - -void QQmlDebugTestService::_sendMessage(const QByteArray &msg) -{ - QQmlDebugService::sendMessage(msg); -} diff --git a/tests/auto/qml/debugger/shared/qqmldebugtestservice.h b/tests/auto/qml/debugger/shared/qqmldebugtestservice.h index 7cb09798de..cc24f3c119 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugtestservice.h +++ b/tests/auto/qml/debugger/shared/qqmldebugtestservice.h @@ -46,9 +46,6 @@ public: signals: void stateHasChanged(); -private slots: - void _sendMessage(const QByteArray &msg); - protected: virtual void messageReceived(const QByteArray &ba); virtual void stateAboutToBeChanged(State state); diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 5a9d6d20eb..4c7dba9f90 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -336,7 +336,7 @@ void tst_QJSEngine::constructWithParent() QJSEngine *engine = new QJSEngine(&obj); ptr = engine; } - QVERIFY(ptr == 0); + QVERIFY(ptr.isNull()); } void tst_QJSEngine::newObject() @@ -631,7 +631,7 @@ void tst_QJSEngine::newQObject_ownership() eng.collectGarbage(); if (ptr) QGuiApplication::sendPostedEvents(ptr, QEvent::DeferredDelete); - QVERIFY(ptr == 0); + QVERIFY(ptr.isNull()); } { QPointer<QObject> ptr = new QObject(this); @@ -641,7 +641,7 @@ void tst_QJSEngine::newQObject_ownership() } QObject *before = ptr; eng.collectGarbage(); - QVERIFY(ptr == before); + QCOMPARE(ptr.data(), before); delete ptr; } { @@ -662,7 +662,7 @@ void tst_QJSEngine::newQObject_ownership() // no parent, so it should be like ScriptOwnership if (ptr) QGuiApplication::sendPostedEvents(ptr, QEvent::DeferredDelete); - QVERIFY(ptr == 0); + QVERIFY(ptr.isNull()); } { QObject *parent = new QObject(); @@ -1258,7 +1258,7 @@ void tst_QJSEngine::valueConversion_QVariant() { QVariant tmp1; QVariant tmp2(QMetaType::QVariant, &tmp1); - QVERIFY(QMetaType::Type(tmp2.type()) == QMetaType::QVariant); + QCOMPARE(QMetaType::Type(tmp2.type()), QMetaType::QVariant); QJSValue val1 = eng.toScriptValue(tmp1); QJSValue val2 = eng.toScriptValue(tmp2); @@ -1273,9 +1273,9 @@ void tst_QJSEngine::valueConversion_QVariant() QVariant tmp1(123); QVariant tmp2(QMetaType::QVariant, &tmp1); QVariant tmp3(QMetaType::QVariant, &tmp2); - QVERIFY(QMetaType::Type(tmp1.type()) == QMetaType::Int); - QVERIFY(QMetaType::Type(tmp2.type()) == QMetaType::QVariant); - QVERIFY(QMetaType::Type(tmp3.type()) == QMetaType::QVariant); + QCOMPARE(QMetaType::Type(tmp1.type()), QMetaType::Int); + QCOMPARE(QMetaType::Type(tmp2.type()), QMetaType::QVariant); + QCOMPARE(QMetaType::Type(tmp3.type()), QMetaType::QVariant); QJSValue val1 = eng.toScriptValue(tmp2); QJSValue val2 = eng.toScriptValue(tmp3); @@ -1285,8 +1285,8 @@ void tst_QJSEngine::valueConversion_QVariant() QVERIFY(val1.isVariant()); QEXPECT_FAIL("", "Variant are unrwapped, maybe we should not...", Continue); QVERIFY(val2.isVariant()); - QVERIFY(val1.toVariant().toInt() == 123); - QVERIFY(eng.toScriptValue(val2.toVariant()).toVariant().toInt() == 123); + QCOMPARE(val1.toVariant().toInt(), 123); + QCOMPARE(eng.toScriptValue(val2.toVariant()).toVariant().toInt(), 123); } { QJSValue val = eng.toScriptValue(QVariant(true)); @@ -1472,7 +1472,7 @@ void tst_QJSEngine::collectGarbage() eng.collectGarbage(); if (ptr) QGuiApplication::sendPostedEvents(ptr, QEvent::DeferredDelete); - QVERIFY(ptr == 0); + QVERIFY(ptr.isNull()); } void tst_QJSEngine::gcWithNestedDataStructure() diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp index d608379d52..bea44cb6e3 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp @@ -1076,7 +1076,7 @@ void tst_QJSValue::toVariant() QVariantList listOut = ret.toList(); QCOMPARE(listOut.size(), listIn.size()); for (int i = 0; i < listIn.size(); ++i) - QVERIFY(listOut.at(i) == listIn.at(i)); + QCOMPARE(listOut.at(i), listIn.at(i)); // round-trip conversion QJSValue array2 = eng.toScriptValue(ret); QVERIFY(array2.isArray()); @@ -2261,7 +2261,7 @@ void tst_QJSValue::castToPointer() QCOMPARE(*cp, c); QBrush *bp = qjsvalue_cast<QBrush*>(v); - QVERIFY(bp == 0); + QVERIFY(!bp); QJSValue v2 = eng.toScriptValue(qVariantFromValue(cp)); QCOMPARE(qjsvalue_cast<QColor*>(v2), cp); @@ -2465,15 +2465,15 @@ void tst_QJSValue::engineDeleted() delete eng; QVERIFY(v1.isUndefined()); - QVERIFY(v1.engine() == 0); + QVERIFY(!v1.engine()); QVERIFY(v2.isUndefined()); - QVERIFY(v2.engine() == 0); + QVERIFY(!v2.engine()); QVERIFY(v3.isUndefined()); - QVERIFY(v3.engine() == 0); + QVERIFY(!v3.engine()); QVERIFY(v4.isUndefined()); - QVERIFY(v4.engine() == 0); + QVERIFY(!v4.engine()); QVERIFY(v5.isString()); // was not bound to engine - QVERIFY(v5.engine() == 0); + QVERIFY(!v5.engine()); QVERIFY(v3.property("foo").isUndefined()); } diff --git a/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp b/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp index 6049e423e8..81a79331c3 100644 --- a/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp +++ b/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp @@ -92,7 +92,7 @@ void tst_QJSValueIterator::iterateForward() QFETCH(QStringList, propertyNames); QFETCH(QStringList, propertyValues); QMap<QString, QString> pmap; - QVERIFY(propertyNames.size() == propertyValues.size()); + QCOMPARE(propertyNames.size(), propertyValues.size()); QJSEngine engine; QJSValue object = engine.newObject(); diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index 430a90b800..b61eca730f 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -37,6 +37,7 @@ PRIVATETESTS += \ qqmldirparser \ qqmlglobal \ qqmllanguage \ + qqmlopenmetaobject \ qqmlproperty \ qqmlpropertycache \ qqmlpropertymap \ @@ -60,7 +61,8 @@ PRIVATETESTS += \ qqmlenginecleanup \ v4misc \ qqmltranslation \ - qqmlimport + qqmlimport \ + qqmlobjectmodel qtHaveModule(widgets) { PUBLICTESTS += \ @@ -70,7 +72,7 @@ qtHaveModule(widgets) { SUBDIRS += $$PUBLICTESTS SUBDIRS += $$METATYPETESTS -!winrt: SUBDIRS += debugger # no QProcess on winrt +!winrt:!contains(QT_CONFIG, no-qml-debug): SUBDIRS += debugger # no QProcess on winrt contains(QT_CONFIG, private_tests) { SUBDIRS += $$PRIVATETESTS diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index bb159d5931..85579a6019 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -110,6 +110,7 @@ private slots: void qmlCreateParentReference(); void async(); void asyncHierarchy(); + void asyncForceSync(); void componentUrlCanonicalization(); void onDestructionLookup(); void onDestructionCount(); @@ -157,7 +158,7 @@ void tst_qqmlcomponent::qmlIncubateObject() QCOMPARE(object->property("test1").toBool(), true); QCOMPARE(object->property("test2").toBool(), false); - QTRY_VERIFY(object->property("test2").toBool() == true); + QTRY_VERIFY(object->property("test2").toBool()); delete object; } @@ -250,7 +251,7 @@ void tst_qqmlcomponent::qmlCreateObjectWithProperties() QObject *testObject1 = object->property("declarativerectangle").value<QObject*>(); QVERIFY(testObject1); - QVERIFY(testObject1->parent() == object); + QCOMPARE(testObject1->parent(), object); QCOMPARE(testObject1->property("x").value<int>(), 17); QCOMPARE(testObject1->property("y").value<int>(), 17); QCOMPARE(testObject1->property("color").value<QColor>(), QColor(255,255,255)); @@ -260,7 +261,7 @@ void tst_qqmlcomponent::qmlCreateObjectWithProperties() QObject *testObject2 = object->property("declarativeitem").value<QObject*>(); QVERIFY(testObject2); - QVERIFY(testObject2->parent() == object); + QCOMPARE(testObject2->parent(), object); //QCOMPARE(testObject2->metaObject()->className(), "QDeclarativeItem_QML_2"); QCOMPARE(testObject2->property("x").value<int>(), 17); QCOMPARE(testObject2->property("y").value<int>(), 17); @@ -371,6 +372,35 @@ void tst_qqmlcomponent::asyncHierarchy() delete root; } +void tst_qqmlcomponent::asyncForceSync() +{ + { + // 1) make sure that HTTP URLs cannot be completed synchronously + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + server.serveDirectory(dataDirectory()); + + // ensure that the item hierarchy is compiled correctly. + QQmlComponent component(&engine); + component.loadUrl(server.url("/TestComponent.2.qml"), QQmlComponent::Asynchronous); + QCOMPARE(component.status(), QQmlComponent::Loading); + QQmlComponent component2(&engine, server.url("/TestComponent.2.qml"), QQmlComponent::PreferSynchronous); + QCOMPARE(component2.status(), QQmlComponent::Loading); + } + { + // 2) make sure that file:// URL can be completed synchronously + + // ensure that the item hierarchy is compiled correctly. + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("/TestComponent.2.qml"), QQmlComponent::Asynchronous); + QCOMPARE(component.status(), QQmlComponent::Loading); + QQmlComponent component2(&engine, testFileUrl("/TestComponent.2.qml"), QQmlComponent::PreferSynchronous); + QCOMPARE(component2.status(), QQmlComponent::Ready); + QCOMPARE(component.status(), QQmlComponent::Loading); + QTRY_COMPARE_WITH_TIMEOUT(component.status(), QQmlComponent::Ready, 0); + } +} + void tst_qqmlcomponent::componentUrlCanonicalization() { // ensure that url canonicalization succeeds so that type information @@ -418,7 +448,7 @@ void tst_qqmlcomponent::componentUrlCanonicalization() QQmlComponent component(&engine, testFileUrl("componentUrlCanonicalization.5.qml")); QTest::ignoreMessage(QtWarningMsg, QLatin1String("QQmlComponent: Component is not ready").data()); QScopedPointer<QObject> object(component.create()); - QVERIFY(object == 0); + QVERIFY(object.isNull()); } } diff --git a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp index 45393bf2f0..e529c74acc 100644 --- a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp +++ b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp @@ -72,7 +72,7 @@ void tst_qqmlconnections::defaultValues() QQmlConnections *item = qobject_cast<QQmlConnections*>(c.create()); QVERIFY(item != 0); - QVERIFY(item->target() == 0); + QVERIFY(!item->target()); delete item; } @@ -86,7 +86,7 @@ void tst_qqmlconnections::properties() QVERIFY(item != 0); QVERIFY(item != 0); - QVERIFY(item->target() == item); + QCOMPARE(item->target(), item); delete item; } @@ -146,7 +146,7 @@ void tst_qqmlconnections::targetChanged() QQuickItem *item2 = item->findChild<QQuickItem*>("item2"); QVERIFY(item2); - QVERIFY(connections->target() == item2); + QCOMPARE(connections->target(), item2); // If we don't crash then we're OK @@ -211,9 +211,9 @@ void tst_qqmlconnections::errors() QQmlEngine engine; QQmlComponent c(&engine, url); - QVERIFY(c.isError() == true); + QVERIFY(c.isError()); QList<QQmlError> errors = c.errors(); - QVERIFY(errors.count() == 1); + QCOMPARE(errors.count(), 1); QCOMPARE(errors.at(0).description(), error); } diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp index 1ee675a91d..98e3a53b81 100644 --- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp +++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp @@ -47,7 +47,7 @@ private slots: void logging(); void tracing(); void profiling(); - void assert(); + void testAssert(); void exception(); private: @@ -122,7 +122,7 @@ void tst_qqmlconsole::profiling() delete object; } -void tst_qqmlconsole::assert() +void tst_qqmlconsole::testAssert() { QUrl testUrl = testFileUrl("assert.qml"); diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index 1bd070c2d0..18ef7ac31d 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -433,12 +433,12 @@ void tst_qqmlcontext::idAsContextProperty() QVERIFY(obj); QVariant a = obj->property("a"); - QVERIFY(a.userType() == QMetaType::QObjectStar); + QCOMPARE(a.userType(), int(QMetaType::QObjectStar)); QVariant ctxt = qmlContext(obj)->contextProperty("myObject"); - QVERIFY(ctxt.userType() == QMetaType::QObjectStar); + QCOMPARE(ctxt.userType(), int(QMetaType::QObjectStar)); - QVERIFY(a == ctxt); + QCOMPARE(a, ctxt); delete obj; } @@ -455,20 +455,20 @@ void tst_qqmlcontext::readOnlyContexts() QQmlContext *context = qmlContext(obj); QVERIFY(context); - QVERIFY(qvariant_cast<QObject*>(context->contextProperty("me")) == obj); - QVERIFY(context->contextObject() == obj); + QCOMPARE(qvariant_cast<QObject*>(context->contextProperty("me")), obj); + QCOMPARE(context->contextObject(), obj); QTest::ignoreMessage(QtWarningMsg, "QQmlContext: Cannot set property on internal context."); context->setContextProperty("hello", 12); - QVERIFY(context->contextProperty("hello") == QVariant()); + QCOMPARE(context->contextProperty("hello"), QVariant()); QTest::ignoreMessage(QtWarningMsg, "QQmlContext: Cannot set property on internal context."); context->setContextProperty("hello", obj); - QVERIFY(context->contextProperty("hello") == QVariant()); + QCOMPARE(context->contextProperty("hello"), QVariant()); QTest::ignoreMessage(QtWarningMsg, "QQmlContext: Cannot set context object for internal context."); context->setContextObject(0); - QVERIFY(context->contextObject() == obj); + QCOMPARE(context->contextObject(), obj); delete obj; } diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index bbccf7b94b..eb4a3147d3 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -1253,7 +1253,7 @@ public: Q_INVOKABLE void addReference(QObject *other) { QQmlData *ddata = QQmlData::get(this); - assert(ddata); + Q_ASSERT(ddata); QV4::ExecutionEngine *v4 = ddata->jsWrapper.engine(); Q_ASSERT(v4); QV4::Scope scope(v4); diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index eb25eb70f4..8bb9ddc07e 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -521,7 +521,7 @@ void tst_qqmlecmascript::idShortcutInvalidates() QVERIFY(object != 0); QVERIFY(object->objectProperty() != 0); delete object->objectProperty(); - QVERIFY(object->objectProperty() == 0); + QVERIFY(!object->objectProperty()); delete object; } @@ -531,7 +531,7 @@ void tst_qqmlecmascript::idShortcutInvalidates() QVERIFY(object != 0); QVERIFY(object->objectProperty() != 0); delete object->objectProperty(); - QVERIFY(object->objectProperty() == 0); + QVERIFY(!object->objectProperty()); delete object; } } @@ -885,7 +885,7 @@ void tst_qqmlecmascript::deferredProperties() qobject_cast<MyDeferredObject *>(component.create()); QVERIFY(object != 0); QCOMPARE(object->value(), 0); - QVERIFY(object->objectProperty() == 0); + QVERIFY(!object->objectProperty()); QVERIFY(object->objectProperty2() != 0); qmlExecuteDeferred(object); QCOMPARE(object->value(), 10); @@ -908,8 +908,8 @@ void tst_qqmlecmascript::deferredPropertiesErrors() qobject_cast<MyDeferredObject *>(component.create()); QVERIFY(object != 0); QCOMPARE(object->value(), 0); - QVERIFY(object->objectProperty() == 0); - QVERIFY(object->objectProperty2() == 0); + QVERIFY(!object->objectProperty()); + QVERIFY(!object->objectProperty2()); QString warning = component.url().toString() + ":6:21: Unable to assign [undefined] to QObject*"; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); @@ -932,7 +932,7 @@ void tst_qqmlecmascript::deferredPropertiesInComponents() MyDeferredObject *defObjectA = qobject_cast<MyDeferredObject *>(object->property("deferredInside").value<QObject*>()); QVERIFY(defObjectA != 0); - QVERIFY(defObjectA->objectProperty() == 0); + QVERIFY(!defObjectA->objectProperty()); qmlExecuteDeferred(defObjectA); QVERIFY(defObjectA->objectProperty() != 0); @@ -941,7 +941,7 @@ void tst_qqmlecmascript::deferredPropertiesInComponents() MyDeferredObject *defObjectB = qobject_cast<MyDeferredObject *>(object->property("deferredOutside").value<QObject*>()); QVERIFY(defObjectB != 0); - QVERIFY(defObjectB->objectProperty() == 0); + QVERIFY(!defObjectB->objectProperty()); qmlExecuteDeferred(defObjectB); QVERIFY(defObjectB->objectProperty() != 0); @@ -995,7 +995,7 @@ void tst_qqmlecmascript::overrideExtensionProperties() qobject_cast<OverrideDefaultPropertyObject *>(component.create()); QVERIFY(object != 0); QVERIFY(object->secondProperty() != 0); - QVERIFY(object->firstProperty() == 0); + QVERIFY(!object->firstProperty()); delete object; } @@ -1459,7 +1459,7 @@ void tst_qqmlecmascript::aliasPropertyReset() QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() != 0); QCOMPARE(object->property("aliasIsUndefined"), QVariant(false)); QMetaObject::invokeMethod(object, "resetAliased"); - QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); + QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>()); QCOMPARE(object->property("aliasIsUndefined"), QVariant(true)); delete object; @@ -1470,7 +1470,7 @@ void tst_qqmlecmascript::aliasPropertyReset() QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() != 0); QCOMPARE(object->property("loaderSourceComponentIsUndefined"), QVariant(false)); QMetaObject::invokeMethod(object, "resetAlias"); - QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); + QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>()); QCOMPARE(object->property("loaderSourceComponentIsUndefined"), QVariant(true)); delete object; @@ -1482,7 +1482,7 @@ void tst_qqmlecmascript::aliasPropertyReset() QCOMPARE(object->property("loaderOneSourceComponentIsUndefined"), QVariant(false)); QCOMPARE(object->property("loaderTwoSourceComponentIsUndefined"), QVariant(false)); QMetaObject::invokeMethod(object, "resetAlias"); - QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); + QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>()); QCOMPARE(object->property("loaderOneSourceComponentIsUndefined"), QVariant(true)); QCOMPARE(object->property("loaderTwoSourceComponentIsUndefined"), QVariant(false)); delete object; @@ -1498,9 +1498,9 @@ void tst_qqmlecmascript::aliasPropertyReset() delete loader; QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); // deletion should have caused value unset. QMetaObject::invokeMethod(object, "resetAlias"); // shouldn't crash. - QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); + QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>()); QMetaObject::invokeMethod(object, "setAlias"); // shouldn't crash, and shouldn't change value (since it's no longer referencing anything). - QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); + QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>()); delete object; // test that binding an alias property to an undefined value works correctly @@ -1680,7 +1680,7 @@ void tst_qqmlecmascript::dynamicDestruction() QObject *o = component.create(); QVERIFY(o != 0); - QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty"))); QMetaObject::invokeMethod(o, "create"); @@ -1691,7 +1691,7 @@ void tst_qqmlecmascript::dynamicDestruction() QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty"))); delete o; } @@ -1702,19 +1702,19 @@ void tst_qqmlecmascript::dynamicDestruction() QQmlComponent component(&engine, testFileUrl("dynamicDeletion.3.qml")); QObject *o = component.create(); QVERIFY(o != 0); - QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty"))); QMetaObject::invokeMethod(o, "create"); createdQmlObject = qvariant_cast<QObject*>(o->property("objectProperty")); QVERIFY(createdQmlObject); QMetaObject::invokeMethod(o, "destroy"); - QVERIFY(qvariant_cast<bool>(o->property("test")) == false); + QCOMPARE(qvariant_cast<bool>(o->property("test")), false); for (int ii = 0; createdQmlObject && ii < 50; ++ii) { // After 5 seconds we should give up QTest::qWait(100); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); } - QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); - QVERIFY(qvariant_cast<bool>(o->property("test")) == true); + QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty"))); + QCOMPARE(qvariant_cast<bool>(o->property("test")), true); delete o; } } @@ -1750,9 +1750,9 @@ void tst_qqmlecmascript::objectHasOwnProperty() // test QObjects in QML QMetaObject::invokeMethod(object, "testHasOwnPropertySuccess"); - QVERIFY(object->property("result").value<bool>() == true); + QVERIFY(object->property("result").value<bool>()); QMetaObject::invokeMethod(object, "testHasOwnPropertyFailure"); - QVERIFY(object->property("result").value<bool>() == false); + QVERIFY(!object->property("result").value<bool>()); // now test other types in QML QObject *child = object->findChild<QObject*>("typeObj"); @@ -1846,7 +1846,7 @@ void tst_qqmlecmascript::uncreatableExtendedObjectFailureCheck() QQmlComponent component(&engine, testFileUrl("uncreatableExtendedObjectFailureCheck.qml")); QObject *object = component.create(); - QVERIFY(object == 0); + QVERIFY(!object); } /* @@ -2235,7 +2235,7 @@ void tst_qqmlecmascript::dynamicCreationCrash() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); QMetaObject::invokeMethod(object, "dontCrash"); QObject *created = object->objectProperty(); - QVERIFY(created == 0); + QVERIFY(!created); delete object; } @@ -2993,7 +2993,7 @@ void tst_qqmlecmascript::listToVariant() QVariant v = object->property("test"); QCOMPARE(v.userType(), qMetaTypeId<QQmlListReference>()); - QVERIFY(qvariant_cast<QQmlListReference>(v).object() == &container); + QCOMPARE(qvariant_cast<QQmlListReference>(v).object(), &container); delete object; } @@ -3260,7 +3260,7 @@ void tst_qqmlecmascript::ownership() QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QVERIFY(own.object == 0); + QVERIFY(own.object.isNull()); delete object; } @@ -3319,7 +3319,7 @@ void tst_qqmlecmascript::cppOwnershipReturnValue() QQmlEngine engine; engine.rootContext()->setContextProperty("source", &source); - QVERIFY(source.value == 0); + QVERIFY(source.value.isNull()); QQmlComponent component(&engine); component.setData("import QtQuick 2.0\nQtObject {\nComponent.onCompleted: { var a = source.create(); }\n}\n", QUrl()); @@ -3347,7 +3347,7 @@ void tst_qqmlecmascript::ownershipCustomReturnValue() QQmlEngine engine; engine.rootContext()->setContextProperty("source", &source); - QVERIFY(source.value == 0); + QVERIFY(source.value.isNull()); QQmlComponent component(&engine); component.setData("import QtQuick 2.0\nQtObject {\nComponent.onCompleted: { var a = source.createQmlObject(); }\n}\n", QUrl()); @@ -3364,7 +3364,7 @@ void tst_qqmlecmascript::ownershipCustomReturnValue() QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QVERIFY(source.value == 0); + QVERIFY(source.value.isNull()); } //the return value from getObject will be JS ownership, @@ -3446,7 +3446,7 @@ void tst_qqmlecmascript::ownershipQmlIncubated() QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QVERIFY(object->property("incubatedItem").value<QObject*>() == 0); + QVERIFY(!object->property("incubatedItem").value<QObject*>()); delete object; } @@ -3863,7 +3863,7 @@ void tst_qqmlecmascript::singletonType() QObject *object = component.create(); if (!errorMessage.isEmpty()) { - QVERIFY(object == 0); + QVERIFY(!object); } else { QVERIFY(object != 0); for (int i = 0; i < readProperties.size(); ++i) @@ -3920,7 +3920,7 @@ void tst_qqmlecmascript::singletonTypeImportOrder() QQmlComponent component(&engine, testFileUrl("singletontype/singletonTypeImportOrder.qml")); QObject *object = component.create(); QVERIFY(object); - QVERIFY(object->property("v") == 1); + QCOMPARE(object->property("v").toInt(), 1); delete object; } @@ -3929,7 +3929,7 @@ void tst_qqmlecmascript::singletonTypeResolution() QQmlComponent component(&engine, testFileUrl("singletontype/singletonTypeResolution.qml")); QObject *object = component.create(); QVERIFY(object); - QVERIFY(object->property("success") == true); + QVERIFY(object->property("success").toBool()); delete object; } @@ -3958,7 +3958,7 @@ void tst_qqmlecmascript::verifyContextLifetime(QQmlContextData *ctxt) { ctxt->engine->collectGarbage(); qml = scripts->getIndexed(i); newContext = QV4::QmlContextWrapper::getContext(qml); - QVERIFY(scriptContext == newContext); + QCOMPARE(scriptContext, newContext); } } @@ -4232,7 +4232,7 @@ void tst_qqmlecmascript::importScripts() QObject *object = component.create(); if (!errorMessage.isEmpty()) { - QVERIFY(object == 0); + QVERIFY(!object); } else { QVERIFY(object != 0); @@ -4685,7 +4685,7 @@ void tst_qqmlecmascript::propertyChangeSlots() QString expectedErrorString = e1.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_nameWithUnderscoreChanged\""); QCOMPARE(e1.errors().at(0).toString(), expectedErrorString); object = e1.create(); - QVERIFY(object == 0); + QVERIFY(!object); delete object; QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); @@ -4693,7 +4693,7 @@ void tst_qqmlecmascript::propertyChangeSlots() expectedErrorString = e2.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on____nameWithUnderscoresChanged\""); QCOMPARE(e2.errors().at(0).toString(), expectedErrorString); object = e2.create(); - QVERIFY(object == 0); + QVERIFY(!object); delete object; QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); @@ -4701,7 +4701,7 @@ void tst_qqmlecmascript::propertyChangeSlots() expectedErrorString = e3.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on$NameWithDollarsignChanged\""); QCOMPARE(e3.errors().at(0).toString(), expectedErrorString); object = e3.create(); - QVERIFY(object == 0); + QVERIFY(!object); delete object; QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); @@ -4709,7 +4709,7 @@ void tst_qqmlecmascript::propertyChangeSlots() expectedErrorString = e4.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_6NameWithUnderscoreNumberChanged\""); QCOMPARE(e4.errors().at(0).toString(), expectedErrorString); object = e4.create(); - QVERIFY(object == 0); + QVERIFY(!object); delete object; } @@ -5747,10 +5747,10 @@ void tst_qqmlecmascript::variants() QObject *object = component.create(); QVERIFY(object != 0); - QVERIFY(object->property("undefinedVariant").type() == QVariant::Invalid); - QVERIFY(object->property("nullVariant").type() == (int)QMetaType::VoidStar); - QVERIFY(object->property("intVariant").type() == QVariant::Int); - QVERIFY(object->property("doubleVariant").type() == QVariant::Double); + QCOMPARE(object->property("undefinedVariant").type(), QVariant::Invalid); + QCOMPARE(int(object->property("nullVariant").type()), int(QMetaType::VoidStar)); + QCOMPARE(object->property("intVariant").type(), QVariant::Int); + QCOMPARE(object->property("doubleVariant").type(), QVariant::Double); QVariant result; QMetaObject::invokeMethod(object, "checkNull", Q_RETURN_ARG(QVariant, result)); @@ -5801,7 +5801,7 @@ void tst_qqmlecmascript::qtcreatorbug_1289() delete nested; nested = qvariant_cast<QObject *>(o->property("object")); - QVERIFY(nested == 0); + QVERIFY(!nested); // If the bug is present, the next line will crash delete o; @@ -5848,7 +5848,7 @@ void tst_qqmlecmascript::canAssignNullToQObject() o->setProperty("runTest", true); - QVERIFY(o->objectProperty() == 0); + QVERIFY(!o->objectProperty()); delete o; } @@ -5859,7 +5859,7 @@ void tst_qqmlecmascript::canAssignNullToQObject() MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create()); QVERIFY(o != 0); - QVERIFY(o->objectProperty() == 0); + QVERIFY(!o->objectProperty()); delete o; } @@ -6064,7 +6064,7 @@ void tst_qqmlecmascript::include() o->setProperty("serverBaseUrl", server.baseUrl().toString()); component.completeCreate(); - QTRY_VERIFY(o->property("done").toBool() == true); + QTRY_VERIFY(o->property("done").toBool()); QCOMPARE(o->property("test1").toBool(), true); QCOMPARE(o->property("test2").toBool(), true); @@ -6108,8 +6108,8 @@ void tst_qqmlecmascript::includeRemoteSuccess() o->setProperty("serverBaseUrl", server.baseUrl().toString()); component.completeCreate(); - QTRY_VERIFY(o->property("done").toBool() == true); - QTRY_VERIFY(o->property("done2").toBool() == true); + QTRY_VERIFY(o->property("done").toBool()); + QTRY_VERIFY(o->property("done2").toBool()); QCOMPARE(o->property("test1").toBool(), true); QCOMPARE(o->property("test2").toBool(), true); @@ -6132,7 +6132,7 @@ void tst_qqmlecmascript::signalHandlers() QObject *o = component.create(); QVERIFY(o != 0); - QVERIFY(o->property("count").toInt() == 0); + QCOMPARE(o->property("count").toInt(), 0); QMetaObject::invokeMethod(o, "testSignalCall"); QCOMPARE(o->property("count").toInt(), 1); @@ -6140,7 +6140,7 @@ void tst_qqmlecmascript::signalHandlers() QCOMPARE(o->property("count").toInt(), 1); QCOMPARE(o->property("errorString").toString(), QLatin1String("TypeError: Property 'onTestSignal' of object [object Object] is not a function")); - QVERIFY(o->property("funcCount").toInt() == 0); + QCOMPARE(o->property("funcCount").toInt(), 0); QMetaObject::invokeMethod(o, "testSignalConnection"); QCOMPARE(o->property("funcCount").toInt(), 1); @@ -6684,7 +6684,7 @@ void tst_qqmlecmascript::incrDecrSemicolon_error1() { QQmlComponent component(&engine, testFileUrl("incrDecrSemicolon_error1.qml")); QObject *object = component.create(); - QVERIFY(object == 0); + QVERIFY(!object); } void tst_qqmlecmascript::unaryExpression() @@ -7032,7 +7032,7 @@ void tst_qqmlecmascript::invokableWithQObjectDerived() QObject *object = component.create(); QVERIFY(object != 0); - QVERIFY(object->property("result").value<bool>() == true); + QVERIFY(object->property("result").value<bool>()); delete object; } @@ -7344,7 +7344,7 @@ void tst_qqmlecmascript::sequenceSort() QVariant q; QMetaObject::invokeMethod(object, function.toAscii().constData(), Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, useComparer)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); delete object; } @@ -7360,10 +7360,10 @@ void tst_qqmlecmascript::dateParse() QVariant q; QMetaObject::invokeMethod(object, "test_is_invalid_jsDateTime", Q_RETURN_ARG(QVariant, q)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); QMetaObject::invokeMethod(object, "test_is_invalid_qtDateTime", Q_RETURN_ARG(QVariant, q)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); QMetaObject::invokeMethod(object, "test_rfc2822_date", Q_RETURN_ARG(QVariant, q)); QCOMPARE(q.toLongLong(), 1379512851000LL); @@ -7381,7 +7381,7 @@ void tst_qqmlecmascript::utcDate() QVariant q; QVariant val = QString::fromLatin1("2014-07-16T23:30:31"); QMetaObject::invokeMethod(object, "check_utc", Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, val)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); } void tst_qqmlecmascript::negativeYear() @@ -7478,7 +7478,7 @@ void tst_qqmlecmascript::stringParsing() file = file.arg(i); QQmlComponent component(&engine, testFileUrl(file)); QObject *object = component.create(); - QVERIFY(object == 0); + QVERIFY(!object); } } @@ -7491,7 +7491,7 @@ void tst_qqmlecmascript::push_and_shift() " array.push(5); array.unshift(5); array.push(5);" "}" "array.length;"; - QVERIFY(e.evaluate(program).toNumber() == 30000); + QCOMPARE(e.evaluate(program).toNumber(), double(30000)); } void tst_qqmlecmascript::qtbug_32801() @@ -7611,13 +7611,13 @@ void tst_qqmlecmascript::miscTypeTest() QVariant q; QMetaObject::invokeMethod(object, "test_invalid_url_equal", Q_RETURN_ARG(QVariant, q)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); QMetaObject::invokeMethod(object, "test_invalid_url_strictequal", Q_RETURN_ARG(QVariant, q)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); QMetaObject::invokeMethod(object, "test_valid_url_equal", Q_RETURN_ARG(QVariant, q)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); QMetaObject::invokeMethod(object, "test_valid_url_strictequal", Q_RETURN_ARG(QVariant, q)); - QVERIFY(q.toBool() == true); + QVERIFY(q.toBool()); delete object; } @@ -7665,7 +7665,7 @@ void tst_qqmlecmascript::singletonWithEnum() qDebug() << component.errors().first().toString(); QVERIFY(!obj.isNull()); QVariant prop = obj->property("testValue"); - QVERIFY(prop.type() == QVariant::Int); + QCOMPARE(prop.type(), QVariant::Int); QCOMPARE(prop.toInt(), int(SingletonWithEnum::TestValue)); } @@ -7677,7 +7677,7 @@ void tst_qqmlecmascript::lazyBindingEvaluation() qDebug() << component.errors().first().toString(); QVERIFY(!obj.isNull()); QVariant prop = obj->property("arrayLength"); - QVERIFY(prop.type() == QVariant::Int); + QCOMPARE(prop.type(), QVariant::Int); QCOMPARE(prop.toInt(), 2); } @@ -7688,7 +7688,7 @@ void tst_qqmlecmascript::varPropertyAccessOnObjectWithInvalidContext() if (obj.isNull()) qDebug() << component.errors().first().toString(); QVERIFY(!obj.isNull()); - QVERIFY(obj->property("success") == true); + QVERIFY(obj->property("success").toBool()); } void tst_qqmlecmascript::importedScriptsAccessOnObjectWithInvalidContext() @@ -7698,7 +7698,7 @@ void tst_qqmlecmascript::importedScriptsAccessOnObjectWithInvalidContext() if (obj.isNull()) qDebug() << component.errors().first().toString(); QVERIFY(!obj.isNull()); - QTRY_VERIFY(obj->property("success") == true); + QTRY_VERIFY(obj->property("success").toBool()); } void tst_qqmlecmascript::importedScriptsWithoutQmlMode() @@ -7708,7 +7708,7 @@ void tst_qqmlecmascript::importedScriptsWithoutQmlMode() if (obj.isNull()) qDebug() << component.errors().first().toString(); QVERIFY(!obj.isNull()); - QTRY_VERIFY(obj->property("success") == true); + QTRY_VERIFY(obj->property("success").toBool()); } void tst_qqmlecmascript::contextObjectOnLazyBindings() diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index eac648ef15..cb911d0115 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -90,7 +90,7 @@ void tst_qqmlengine::rootContext() QVERIFY(engine.rootContext()); QCOMPARE(engine.rootContext()->engine(), &engine); - QVERIFY(engine.rootContext()->parentContext() == 0); + QVERIFY(!engine.rootContext()->parentContext()); } class NetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory @@ -119,8 +119,9 @@ void tst_qqmlengine::networkAccessManager() engine = new QQmlEngine; NetworkAccessManagerFactory factory; engine->setNetworkAccessManagerFactory(&factory); - QVERIFY(engine->networkAccessManagerFactory() == &factory); - QVERIFY(engine->networkAccessManager() == factory.manager); + QCOMPARE(engine->networkAccessManagerFactory(), &factory); + QNetworkAccessManager *engineNam = engine->networkAccessManager(); // calls NetworkAccessManagerFactory::create() + QCOMPARE(engineNam, factory.manager); delete engine; } @@ -184,7 +185,7 @@ void tst_qqmlengine::baseUrl() dir.cdUp(); QVERIFY(dir != QDir::current()); QDir::setCurrent(dir.path()); - QVERIFY(QDir::current() == dir); + QCOMPARE(QDir::current(), dir); QUrl cwd2 = QUrl::fromLocalFile(QDir::currentPath() + QDir::separator()); QCOMPARE(engine.baseUrl(), cwd2); @@ -200,11 +201,11 @@ void tst_qqmlengine::contextForObject() QQmlEngine *engine = new QQmlEngine; // Test null-object - QVERIFY(QQmlEngine::contextForObject(0) == 0); + QVERIFY(!QQmlEngine::contextForObject(0)); // Test an object with no context QObject object; - QVERIFY(QQmlEngine::contextForObject(&object) == 0); + QVERIFY(!QQmlEngine::contextForObject(&object)); // Test setting null-object QQmlEngine::setContextForObject(0, engine->rootContext()); @@ -214,18 +215,18 @@ void tst_qqmlengine::contextForObject() // Test setting context QQmlEngine::setContextForObject(&object, engine->rootContext()); - QVERIFY(QQmlEngine::contextForObject(&object) == engine->rootContext()); + QCOMPARE(QQmlEngine::contextForObject(&object), engine->rootContext()); QQmlContext context(engine->rootContext()); // Try changing context QTest::ignoreMessage(QtWarningMsg, "QQmlEngine::setContextForObject(): Object already has a QQmlContext"); QQmlEngine::setContextForObject(&object, &context); - QVERIFY(QQmlEngine::contextForObject(&object) == engine->rootContext()); + QCOMPARE(QQmlEngine::contextForObject(&object), engine->rootContext()); // Delete context delete engine; engine = 0; - QVERIFY(QQmlEngine::contextForObject(&object) == 0); + QVERIFY(!QQmlEngine::contextForObject(&object)); } void tst_qqmlengine::offlineStoragePath() @@ -446,7 +447,7 @@ void tst_qqmlengine::failedCompilation() QQmlComponent component(&engine, testFileUrl(file)); QVERIFY(!component.isReady()); QScopedPointer<QObject> object(component.create()); - QVERIFY(object == 0); + QVERIFY(object.isNull()); engine.collectGarbage(); engine.trimComponentCache(); @@ -470,7 +471,7 @@ void tst_qqmlengine::outputWarningsToStandardError() QQmlComponent c(&engine); c.setData("import QtQuick 2.0; QtObject { property int a: undefined }", QUrl()); - QVERIFY(c.isReady() == true); + QVERIFY(c.isReady()); QQmlTestMessageHandler messageHandler; diff --git a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp index e381976448..d9838a4941 100644 --- a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp +++ b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp @@ -140,7 +140,7 @@ void tst_qqmlexpression::expressionFromDataComponent() QQmlExpression expression(object->scriptString()); QVariant result = expression.evaluate(); - QVERIFY(result.type() == QVariant::String); + QCOMPARE(result.type(), QVariant::String); QCOMPARE(result.toString(), QStringLiteral("success")); } diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp index 26092595d9..4f559b0d33 100644 --- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp +++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp @@ -148,7 +148,7 @@ void tst_qqmlincubator::objectDeleted() component.create(incubator); QCOMPARE(incubator.status(), QQmlIncubator::Loading); - QVERIFY(SelfRegisteringType::me() == 0); + QVERIFY(!SelfRegisteringType::me()); while (SelfRegisteringOuterType::me() == 0 && incubator.isLoading()) { bool b = false; @@ -172,7 +172,7 @@ void tst_qqmlincubator::objectDeleted() QVERIFY(incubator.isError()); VERIFY_ERRORS(incubator, "objectDeleted.errors.txt"); - QVERIFY(incubator.object() == 0); + QVERIFY(!incubator.object()); } QVERIFY(SelfRegisteringOuterType::beenDeleted); } @@ -236,7 +236,7 @@ void tst_qqmlincubator::clear() incubator.clear(); QVERIFY(incubator.isNull()); - QVERIFY(incubator.object() == 0); + QVERIFY(!incubator.object()); QVERIFY(!obj.isNull()); delete obj; @@ -413,7 +413,7 @@ void tst_qqmlincubator::clearDuringCompletion() component.create(incubator); QCOMPARE(incubator.status(), QQmlIncubator::Loading); - QVERIFY(CompletionRegisteringType::me() == 0); + QVERIFY(!CompletionRegisteringType::me()); while (CompletionRegisteringType::me() == 0 && incubator.isLoading()) { bool b = false; @@ -622,7 +622,7 @@ void tst_qqmlincubator::asynchronousIfNested() component.create(incubator); QVERIFY(incubator.isLoading()); - QVERIFY(SelfRegisteringType::me() == 0); + QVERIFY(!SelfRegisteringType::me()); while (SelfRegisteringType::me() == 0 && incubator.isLoading()) { bool b = false; controller.incubateWhile(&b); @@ -741,7 +741,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNested() component.create(incubator); QVERIFY(incubator.isLoading()); - QVERIFY(SelfRegisteringType::me() == 0); + QVERIFY(!SelfRegisteringType::me()); while (SelfRegisteringType::me() == 0 && incubator.isLoading()) { bool b = false; @@ -855,7 +855,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted() component.create(incubator); QVERIFY(incubator.isLoading()); - QVERIFY(SelfRegisteringType::me() == 0); + QVERIFY(!SelfRegisteringType::me()); while (SelfRegisteringType::me() == 0 && incubator.isLoading()) { bool b = false; @@ -983,7 +983,7 @@ void tst_qqmlincubator::chainedAsynchronousClear() component.create(incubator); QVERIFY(incubator.isLoading()); - QVERIFY(SelfRegisteringType::me() == 0); + QVERIFY(!SelfRegisteringType::me()); while (SelfRegisteringType::me() == 0 && incubator.isLoading()) { bool b = false; @@ -1106,7 +1106,7 @@ void tst_qqmlincubator::selfDelete() component.create(*incubator); QCOMPARE(incubator->QQmlIncubator::status(), QQmlIncubator::Loading); - QVERIFY(SelfRegisteringType::me() == 0); + QVERIFY(!SelfRegisteringType::me()); while (SelfRegisteringType::me() == 0 && incubator->isLoading()) { bool b = false; diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 08da779d90..152b7510d2 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -55,6 +55,10 @@ #include "../../shared/util.h" +#if defined(Q_OS_MAC) +#include <unistd.h> +#endif + DEFINE_BOOL_CONFIG_OPTION(qmlCheckTypes, QML_CHECK_TYPES) static inline bool isCaseSensitiveFileSystem(const QString &path) { @@ -328,7 +332,7 @@ void tst_qqmllanguage::insertedSemicolon() if(create) { QObject *object = component.create(); - QVERIFY(object == 0); + QVERIFY(!object); } VERIFY_ERRORS(errorFile.toLatin1().constData()); @@ -550,7 +554,7 @@ void tst_qqmllanguage::errors() if (create) { QObject *object = component.create(); - QVERIFY(object == 0); + QVERIFY(!object); } VERIFY_ERRORS(errorFile.toLatin1().constData()); @@ -580,7 +584,7 @@ void tst_qqmllanguage::interfaceProperty() MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); QVERIFY(object != 0); QVERIFY(object->interface()); - QVERIFY(object->interface()->id == 913); + QCOMPARE(object->interface()->id, 913); } void tst_qqmllanguage::interfaceQList() @@ -589,9 +593,9 @@ void tst_qqmllanguage::interfaceQList() VERIFY_ERRORS(0); MyContainer *container= qobject_cast<MyContainer*>(component.create()); QVERIFY(container != 0); - QVERIFY(container->getQListInterfaces()->count() == 2); + QCOMPARE(container->getQListInterfaces()->count(), 2); for(int ii = 0; ii < 2; ++ii) - QVERIFY(container->getQListInterfaces()->at(ii)->id == 913); + QCOMPARE(container->getQListInterfaces()->at(ii)->id, 913); } void tst_qqmllanguage::assignObjectToSignal() @@ -630,7 +634,7 @@ void tst_qqmllanguage::assignQmlComponent() VERIFY_ERRORS(0); MyContainer *object = qobject_cast<MyContainer *>(component.create()); QVERIFY(object != 0); - QVERIFY(object->getChildren()->count() == 1); + QCOMPARE(object->getChildren()->count(), 1); QObject *child = object->getChildren()->at(0); QCOMPARE(child->property("x"), QVariant(10)); QCOMPARE(child->property("y"), QVariant(11)); @@ -722,17 +726,17 @@ void tst_qqmllanguage::assignLiteralToVariant() QCOMPARE(object->property("test11").userType(), (int)QVariant::Bool); QCOMPARE(object->property("test12").userType(), (int)QVariant::Vector4D); - QVERIFY(object->property("test1") == QVariant(1)); - QVERIFY(object->property("test2") == QVariant((double)1.7)); + QCOMPARE(object->property("test1"), QVariant(1)); + QCOMPARE(object->property("test2"), QVariant((double)1.7)); QVERIFY(object->property("test3") == QVariant(QString(QLatin1String("Hello world!")))); - QVERIFY(object->property("test4") == QVariant(QColor::fromRgb(0xFF008800))); + QCOMPARE(object->property("test4"), QVariant(QColor::fromRgb(0xFF008800))); QVERIFY(object->property("test5") == QVariant(QRectF(10, 10, 10, 10))); QVERIFY(object->property("test6") == QVariant(QPointF(10, 10))); QVERIFY(object->property("test7") == QVariant(QSizeF(10, 10))); QVERIFY(object->property("test8") == QVariant(QVector3D(100, 100, 100))); - QVERIFY(object->property("test9") == QVariant(QString(QLatin1String("#FF008800")))); - QVERIFY(object->property("test10") == QVariant(bool(true))); - QVERIFY(object->property("test11") == QVariant(bool(false))); + QCOMPARE(object->property("test9"), QVariant(QString(QLatin1String("#FF008800")))); + QCOMPARE(object->property("test10"), QVariant(bool(true))); + QCOMPARE(object->property("test11"), QVariant(bool(false))); QVERIFY(object->property("test12") == QVariant(QVector4D(100, 100, 100, 100))); delete object; @@ -1170,7 +1174,7 @@ void tst_qqmllanguage::customParserTypes() VERIFY_ERRORS(0); QObject *object = component.create(); QVERIFY(object != 0); - QVERIFY(object->property("count") == QVariant(2)); + QCOMPARE(object->property("count"), QVariant(2)); } // Tests that the root item can be a custom component @@ -1352,7 +1356,7 @@ void tst_qqmllanguage::dynamicObjectProperties() QObject *object = component.create(); QVERIFY(object != 0); - QVERIFY(object->property("objectProperty") == qVariantFromValue((QObject*)0)); + QCOMPARE(object->property("objectProperty"), qVariantFromValue((QObject*)0)); QVERIFY(object->property("objectProperty2") != qVariantFromValue((QObject*)0)); } { @@ -1661,7 +1665,7 @@ void tst_qqmllanguage::aliasProperties() v = object->property("otherAlias"); QCOMPARE(v.userType(), qMetaTypeId<MyQmlObject*>()); o = qvariant_cast<MyQmlObject*>(v); - QVERIFY(o == 0); + QVERIFY(!o); delete object; } @@ -1691,7 +1695,7 @@ void tst_qqmllanguage::aliasProperties() QVERIFY(object2 != 0); QObject *alias = qvariant_cast<QObject *>(object->property("aliasedObject")); - QVERIFY(alias == object2); + QCOMPARE(alias, object2); delete object1; @@ -1700,7 +1704,7 @@ void tst_qqmllanguage::aliasProperties() void *a[] = { &alias2, 0, &status }; QMetaObject::metacall(object, QMetaObject::ReadProperty, object->metaObject()->indexOfProperty("aliasedObject"), a); - QVERIFY(alias2 == 0); + QVERIFY(!alias2); } // Simple composite type @@ -2106,50 +2110,50 @@ void tst_qqmllanguage::scriptStringComparison() const qreal n = 12.345; bool ok; - QVERIFY(object2->scriptProperty().stringLiteral() == s); + QCOMPARE(object2->scriptProperty().stringLiteral(), s); QVERIFY(object3->scriptProperty().numberLiteral(&ok) == n && ok); - QVERIFY(object1->scriptProperty() == object1->scriptProperty()); - QVERIFY(object2->scriptProperty() == object2->scriptProperty()); - QVERIFY(object3->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object1->scriptProperty(), object1->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object2->scriptProperty()); + QCOMPARE(object3->scriptProperty(), object3->scriptProperty()); QVERIFY(object2->scriptProperty() != object3->scriptProperty()); QVERIFY(object1->scriptProperty() != object2->scriptProperty()); QVERIFY(object1->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst2, QJSValueList() << n); - QVERIFY(object2->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object3->scriptProperty()); func.callWithInstance(inst2, QJSValueList() << s); QVERIFY(object2->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst3, QJSValueList() << s); - QVERIFY(object2->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object3->scriptProperty()); func.callWithInstance(inst2, QJSValueList() << QJSValue::UndefinedValue); QVERIFY(object2->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst3, QJSValueList() << QJSValue::UndefinedValue); - QVERIFY(object2->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object3->scriptProperty()); func.callWithInstance(inst2, QJSValueList() << QJSValue::NullValue); QVERIFY(object2->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst3, QJSValueList() << QJSValue::NullValue); - QVERIFY(object2->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object3->scriptProperty()); func.callWithInstance(inst2, QJSValueList() << false); QVERIFY(object2->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst3, QJSValueList() << false); - QVERIFY(object2->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object3->scriptProperty()); func.callWithInstance(inst2, QJSValueList() << true); QVERIFY(object2->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst3, QJSValueList() << true); - QVERIFY(object2->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object2->scriptProperty(), object3->scriptProperty()); QVERIFY(object1->scriptProperty() != object2->scriptProperty()); object2->setScriptProperty(object1->scriptProperty()); - QVERIFY(object1->scriptProperty() == object2->scriptProperty()); + QCOMPARE(object1->scriptProperty(), object2->scriptProperty()); QVERIFY(object1->scriptProperty() != object3->scriptProperty()); func.callWithInstance(inst3, QJSValueList() << engine.toScriptValue(object1->scriptProperty())); - QVERIFY(object1->scriptProperty() == object3->scriptProperty()); + QCOMPARE(object1->scriptProperty(), object3->scriptProperty()); // While this are two instances of the same object they are still considered different // because the (none literal) script string may access variables which have different @@ -3250,7 +3254,7 @@ void tst_qqmllanguage::registrationOrder() QObject *o = component.create(); QVERIFY(o != 0); - QVERIFY(o->metaObject() == &MyVersion2Class::staticMetaObject); + QCOMPARE(o->metaObject(), &MyVersion2Class::staticMetaObject); delete o; } @@ -3644,7 +3648,7 @@ void tst_qqmllanguage::compositeSingletonSameEngine() QVERIFY(s2 != 0); QCOMPARE(s2->property("testProp2"), QVariant(13)); - QVERIFY(s1 == s2); + QCOMPARE(s1, s2); } // Checks that the addresses of the composite singletons used in different @@ -3693,7 +3697,7 @@ void tst_qqmllanguage::compositeSingletonQualifiedNamespace() getSingletonInstance(engine, "singletonTest5a.qml", "singletonInstance", &s2); QVERIFY(s2 != 0); - QVERIFY(s1 == s2); + QCOMPARE(s1, s2); } // Loads a singleton from a module @@ -3719,7 +3723,7 @@ void tst_qqmllanguage::compositeSingletonModule() getSingletonInstance(engine, "singletonTest6a.qml", "singletonInstance", &s2); QVERIFY(s2 != 0); - QVERIFY(s1 == s2); + QCOMPARE(s1, s2); } // Loads a singleton from a module with a higher version @@ -3745,7 +3749,7 @@ void tst_qqmllanguage::compositeSingletonModuleVersioned() getSingletonInstance(engine, "singletonTest7a.qml", "singletonInstance", &s2); QVERIFY(s2 != 0); - QVERIFY(s1 == s2); + QCOMPARE(s1, s2); } // Loads a singleton from a module with a qualified namespace @@ -3771,7 +3775,7 @@ void tst_qqmllanguage::compositeSingletonModuleQualified() getSingletonInstance(engine, "singletonTest8a.qml", "singletonInstance", &s2); QVERIFY(s2 != 0); - QVERIFY(s1 == s2); + QCOMPARE(s1, s2); } // Tries to instantiate a type with a pragma Singleton and fails @@ -3995,7 +3999,7 @@ void tst_qqmllanguage::propertyCacheInSync() QVERIFY(ddata); QVERIFY(ddata->propertyCache); // Those always have to be in sync and correct. - QVERIFY(ddata->propertyCache == vmemoCache); + QCOMPARE(ddata->propertyCache, vmemoCache); QCOMPARE(anchors->property("margins").toInt(), 50); } diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index 4d76fc4fba..5c252013ea 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -642,7 +642,7 @@ void tst_qqmllistmodel::enumerate() } } - QVERIFY(matchCount == expectedStringCount); + QCOMPARE(matchCount, expectedStringCount); delete item; } @@ -1296,7 +1296,7 @@ void tst_qqmllistmodel::datetime() QQmlExpression e(engine.rootContext(), &model, qml); QVariant result = e.evaluate(); QDateTime dtResult = result.toDateTime(); - QVERIFY(expected == dtResult); + QCOMPARE(expected, dtResult); } class RowTester : public QObject diff --git a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp index 5bf75d41d4..0ad2963265 100644 --- a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp +++ b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp @@ -647,15 +647,15 @@ void tst_qqmllistmodelworkerscript::worker_sync() QQuickItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != 0); - QVERIFY(model.count() == 0); + QCOMPARE(model.count(), 0); QVERIFY(QMetaObject::invokeMethod(item, "addItem0")); - QVERIFY(model.count() == 2); + QCOMPARE(model.count(), 2); QVariant childData = model.data(0, 0); QQmlListModel *childModel = qobject_cast<QQmlListModel *>(childData.value<QObject *>()); QVERIFY(childModel); - QVERIFY(childModel->count() == 1); + QCOMPARE(childModel->count(), 1); QSignalSpy spyModelInserted(&model, SIGNAL(rowsInserted(QModelIndex,int,int))); QSignalSpy spyChildInserted(childModel, SIGNAL(rowsInserted(QModelIndex,int,int))); @@ -663,34 +663,34 @@ void tst_qqmllistmodelworkerscript::worker_sync() QVERIFY(QMetaObject::invokeMethod(item, "addItemViaWorker")); waitForWorker(item); - QVERIFY(model.count() == 2); - QVERIFY(childModel->count() == 1); - QVERIFY(spyModelInserted.count() == 0); - QVERIFY(spyChildInserted.count() == 0); + QCOMPARE(model.count(), 2); + QCOMPARE(childModel->count(), 1); + QCOMPARE(spyModelInserted.count(), 0); + QCOMPARE(spyChildInserted.count(), 0); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); - QVERIFY(model.count() == 2); - QVERIFY(childModel->count() == 2); - QVERIFY(spyModelInserted.count() == 0); - QVERIFY(spyChildInserted.count() == 1); + QCOMPARE(model.count(), 2); + QCOMPARE(childModel->count(), 2); + QCOMPARE(spyModelInserted.count(), 0); + QCOMPARE(spyChildInserted.count(), 1); QVERIFY(QMetaObject::invokeMethod(item, "addItemViaWorker")); waitForWorker(item); - QVERIFY(model.count() == 2); - QVERIFY(childModel->count() == 2); - QVERIFY(spyModelInserted.count() == 0); - QVERIFY(spyChildInserted.count() == 1); + QCOMPARE(model.count(), 2); + QCOMPARE(childModel->count(), 2); + QCOMPARE(spyModelInserted.count(), 0); + QCOMPARE(spyChildInserted.count(), 1); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); - QVERIFY(model.count() == 2); - QVERIFY(childModel->count() == 3); - QVERIFY(spyModelInserted.count() == 0); - QVERIFY(spyChildInserted.count() == 2); + QCOMPARE(model.count(), 2); + QCOMPARE(childModel->count(), 3); + QCOMPARE(spyModelInserted.count(), 0); + QCOMPARE(spyChildInserted.count(), 2); delete item; qApp->processEvents(); @@ -714,24 +714,24 @@ void tst_qqmllistmodelworkerscript::worker_remove_element() QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); - QVERIFY(model.count() == 0); - QVERIFY(spyModelRemoved.count() == 0); + QCOMPARE(model.count(), 0); + QCOMPARE(spyModelRemoved.count(), 0); QVERIFY(QMetaObject::invokeMethod(item, "addItem")); - QVERIFY(model.count() == 1); + QCOMPARE(model.count(), 1); QVERIFY(QMetaObject::invokeMethod(item, "removeItemViaWorker")); waitForWorker(item); - QVERIFY(model.count() == 1); - QVERIFY(spyModelRemoved.count() == 0); + QCOMPARE(model.count(), 1); + QCOMPARE(spyModelRemoved.count(), 0); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); - QVERIFY(model.count() == 0); - QVERIFY(spyModelRemoved.count() == 1); + QCOMPARE(model.count(), 0); + QCOMPARE(spyModelRemoved.count(), 1); delete item; qApp->processEvents(); @@ -747,7 +747,7 @@ void tst_qqmllistmodelworkerscript::worker_remove_element() QVERIFY(QMetaObject::invokeMethod(item, "addItem")); - QVERIFY(model->count() == 1); + QCOMPARE(model->count(), 1); QVERIFY(QMetaObject::invokeMethod(item, "removeItemViaWorker")); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); @@ -777,24 +777,24 @@ void tst_qqmllistmodelworkerscript::worker_remove_list() QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); - QVERIFY(model.count() == 0); - QVERIFY(spyModelRemoved.count() == 0); + QCOMPARE(model.count(), 0); + QCOMPARE(spyModelRemoved.count(), 0); QVERIFY(QMetaObject::invokeMethod(item, "addList")); - QVERIFY(model.count() == 1); + QCOMPARE(model.count(), 1); QVERIFY(QMetaObject::invokeMethod(item, "removeListViaWorker")); waitForWorker(item); - QVERIFY(model.count() == 1); - QVERIFY(spyModelRemoved.count() == 0); + QCOMPARE(model.count(), 1); + QCOMPARE(spyModelRemoved.count(), 0); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); - QVERIFY(model.count() == 0); - QVERIFY(spyModelRemoved.count() == 1); + QCOMPARE(model.count(), 0); + QCOMPARE(spyModelRemoved.count(), 1); delete item; qApp->processEvents(); diff --git a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp index b5963e2f71..274f292c38 100644 --- a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp +++ b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp @@ -98,7 +98,7 @@ void tst_qqmllistreference::qmllistreference() TestType tt; QQmlListReference r(&tt, "data"); - QVERIFY(r.isValid() == true); + QVERIFY(r.isValid()); QCOMPARE(r.count(), 0); tt.data.append(&tt); @@ -112,52 +112,52 @@ void tst_qqmllistreference::qmllistreference_invalid() // Invalid { QQmlListReference r; - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - QVERIFY(r.isReadable() == false); - QVERIFY(r.isManipulable() == false); + QVERIFY(!r.isValid()); + QVERIFY(!r.object()); + QVERIFY(!r.listElementType()); + QVERIFY(!r.canAt()); + QVERIFY(!r.canClear()); + QVERIFY(!r.canCount()); + QVERIFY(!r.append(0)); + QVERIFY(!r.at(10)); + QVERIFY(!r.clear()); + QCOMPARE(r.count(), 0); + QVERIFY(!r.isReadable()); + QVERIFY(!r.isManipulable()); } // Non-property { QQmlListReference r(&tt, "blah"); - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - QVERIFY(r.isReadable() == false); - QVERIFY(r.isManipulable() == false); + QVERIFY(!r.isValid()); + QVERIFY(!r.object()); + QVERIFY(!r.listElementType()); + QVERIFY(!r.canAt()); + QVERIFY(!r.canClear()); + QVERIFY(!r.canCount()); + QVERIFY(!r.append(0)); + QVERIFY(!r.at(10)); + QVERIFY(!r.clear()); + QCOMPARE(r.count(), 0); + QVERIFY(!r.isReadable()); + QVERIFY(!r.isManipulable()); } // Non-list property { QQmlListReference r(&tt, "intProperty"); - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - QVERIFY(r.isReadable() == false); - QVERIFY(r.isManipulable() == false); + QVERIFY(!r.isValid()); + QVERIFY(!r.object()); + QVERIFY(!r.listElementType()); + QVERIFY(!r.canAt()); + QVERIFY(!r.canClear()); + QVERIFY(!r.canCount()); + QVERIFY(!r.append(0)); + QVERIFY(!r.at(10)); + QVERIFY(!r.clear()); + QCOMPARE(r.count(), 0); + QVERIFY(!r.isReadable()); + QVERIFY(!r.isManipulable()); } } @@ -167,19 +167,19 @@ void tst_qqmllistreference::isValid() { QQmlListReference ref; - QVERIFY(ref.isValid() == false); + QVERIFY(!ref.isValid()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.isValid() == false); + QVERIFY(!ref.isValid()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.isValid() == true); + QVERIFY(ref.isValid()); delete tt; - QVERIFY(ref.isValid() == false); + QVERIFY(!ref.isValid()); } } @@ -189,19 +189,19 @@ void tst_qqmllistreference::object() { QQmlListReference ref; - QVERIFY(ref.object() == 0); + QVERIFY(!ref.object()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.object() == 0); + QVERIFY(!ref.object()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.object() == tt); + QCOMPARE(ref.object(), tt); delete tt; - QVERIFY(ref.object() == 0); + QVERIFY(!ref.object()); } } @@ -211,19 +211,19 @@ void tst_qqmllistreference::listElementType() { QQmlListReference ref; - QVERIFY(ref.listElementType() == 0); + QVERIFY(!ref.listElementType()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.listElementType() == 0); + QVERIFY(!ref.listElementType()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.listElementType() == &TestType::staticMetaObject); + QCOMPARE(ref.listElementType(), &TestType::staticMetaObject); delete tt; - QVERIFY(ref.listElementType() == 0); + QVERIFY(!ref.listElementType()); } } @@ -233,26 +233,26 @@ void tst_qqmllistreference::canAppend() { QQmlListReference ref; - QVERIFY(ref.canAppend() == false); + QVERIFY(!ref.canAppend()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.canAppend() == false); + QVERIFY(!ref.canAppend()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.canAppend() == true); + QVERIFY(ref.canAppend()); delete tt; - QVERIFY(ref.canAppend() == false); + QVERIFY(!ref.canAppend()); } { TestType tt; tt.property.append = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.canAppend() == false); + QVERIFY(!ref.canAppend()); } } @@ -262,26 +262,26 @@ void tst_qqmllistreference::canAt() { QQmlListReference ref; - QVERIFY(ref.canAt() == false); + QVERIFY(!ref.canAt()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.canAt() == false); + QVERIFY(!ref.canAt()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.canAt() == true); + QVERIFY(ref.canAt()); delete tt; - QVERIFY(ref.canAt() == false); + QVERIFY(!ref.canAt()); } { TestType tt; tt.property.at = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.canAt() == false); + QVERIFY(!ref.canAt()); } } @@ -291,26 +291,26 @@ void tst_qqmllistreference::canClear() { QQmlListReference ref; - QVERIFY(ref.canClear() == false); + QVERIFY(!ref.canClear()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.canClear() == false); + QVERIFY(!ref.canClear()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.canClear() == true); + QVERIFY(ref.canClear()); delete tt; - QVERIFY(ref.canClear() == false); + QVERIFY(!ref.canClear()); } { TestType tt; tt.property.clear = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.canClear() == false); + QVERIFY(!ref.canClear()); } } @@ -320,26 +320,26 @@ void tst_qqmllistreference::canCount() { QQmlListReference ref; - QVERIFY(ref.canCount() == false); + QVERIFY(!ref.canCount()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.canCount() == false); + QVERIFY(!ref.canCount()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.canCount() == true); + QVERIFY(ref.canCount()); delete tt; - QVERIFY(ref.canCount() == false); + QVERIFY(!ref.canCount()); } { TestType tt; tt.property.count = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.canCount() == false); + QVERIFY(!ref.canCount()); } } @@ -349,26 +349,26 @@ void tst_qqmllistreference::isReadable() { QQmlListReference ref; - QVERIFY(ref.isReadable() == false); + QVERIFY(!ref.isReadable()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.isReadable() == false); + QVERIFY(!ref.isReadable()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.isReadable() == true); + QVERIFY(ref.isReadable()); delete tt; - QVERIFY(ref.isReadable() == false); + QVERIFY(!ref.isReadable()); } { TestType tt; tt.property.count = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.isReadable() == false); + QVERIFY(!ref.isReadable()); } } @@ -378,26 +378,26 @@ void tst_qqmllistreference::isManipulable() { QQmlListReference ref; - QVERIFY(ref.isManipulable() == false); + QVERIFY(!ref.isManipulable()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.isManipulable() == false); + QVERIFY(!ref.isManipulable()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.isManipulable() == true); + QVERIFY(ref.isManipulable()); delete tt; - QVERIFY(ref.isManipulable() == false); + QVERIFY(!ref.isManipulable()); } { TestType tt; tt.property.count = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.isManipulable() == false); + QVERIFY(!ref.isManipulable()); } } @@ -408,35 +408,35 @@ void tst_qqmllistreference::append() { QQmlListReference ref; - QVERIFY(ref.append(tt) == false); + QVERIFY(!ref.append(tt)); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.append(tt) == false); + QVERIFY(!ref.append(tt)); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.append(tt) == true); - QVERIFY(tt->data.count() == 1); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(ref.append(&object) == false); - QVERIFY(tt->data.count() == 1); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(ref.append(0) == true); - QVERIFY(tt->data.count() == 2); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(tt->data.at(1) == 0); + QVERIFY(ref.append(tt)); + QCOMPARE(tt->data.count(), 1); + QCOMPARE(tt->data.at(0), tt); + QVERIFY(!ref.append(&object)); + QCOMPARE(tt->data.count(), 1); + QCOMPARE(tt->data.at(0), tt); + QVERIFY(ref.append(0)); + QCOMPARE(tt->data.count(), 2); + QCOMPARE(tt->data.at(0), tt); + QVERIFY(!tt->data.at(1)); delete tt; - QVERIFY(ref.append(0) == false); + QVERIFY(!ref.append(0)); } { TestType tt; tt.property.append = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.append(&tt) == false); + QVERIFY(!ref.append(&tt)); } } @@ -449,21 +449,21 @@ void tst_qqmllistreference::at() { QQmlListReference ref; - QVERIFY(ref.at(0) == 0); + QVERIFY(!ref.at(0)); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.at(0) == 0); + QVERIFY(!ref.at(0)); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.at(0) == tt); - QVERIFY(ref.at(1) == 0); - QVERIFY(ref.at(2) == tt); + QCOMPARE(ref.at(0), tt); + QVERIFY(!ref.at(1)); + QCOMPARE(ref.at(2), tt); delete tt; - QVERIFY(ref.at(0) == 0); + QVERIFY(!ref.at(0)); } { @@ -471,7 +471,7 @@ void tst_qqmllistreference::at() tt.data.append(&tt); tt.property.at = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.at(0) == 0); + QVERIFY(!ref.at(0)); } } @@ -484,27 +484,27 @@ void tst_qqmllistreference::clear() { QQmlListReference ref; - QVERIFY(ref.clear() == false); + QVERIFY(!ref.clear()); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.clear() == false); + QVERIFY(!ref.clear()); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.clear() == true); - QVERIFY(tt->data.count() == 0); + QVERIFY(ref.clear()); + QCOMPARE(tt->data.count(), 0); delete tt; - QVERIFY(ref.clear() == false); + QVERIFY(!ref.clear()); } { TestType tt; tt.property.clear = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.clear() == false); + QVERIFY(!ref.clear()); } } @@ -517,21 +517,21 @@ void tst_qqmllistreference::count() { QQmlListReference ref; - QVERIFY(ref.count() == 0); + QCOMPARE(ref.count(), 0); } { QQmlListReference ref(tt, "blah"); - QVERIFY(ref.count() == 0); + QCOMPARE(ref.count(), 0); } { QQmlListReference ref(tt, "data"); - QVERIFY(ref.count() == 3); + QCOMPARE(ref.count(), 3); tt->data.removeAt(1); - QVERIFY(ref.count() == 2); + QCOMPARE(ref.count(), 2); delete tt; - QVERIFY(ref.count() == 0); + QCOMPARE(ref.count(), 0); } { @@ -539,7 +539,7 @@ void tst_qqmllistreference::count() tt.data.append(&tt); tt.property.count = 0; QQmlListReference ref(&tt, "data"); - QVERIFY(ref.count() == 0); + QCOMPARE(ref.count(), 0); } } @@ -551,24 +551,24 @@ void tst_qqmllistreference::copy() tt.data.append(&tt); QQmlListReference *r1 = new QQmlListReference(&tt, "data"); - QVERIFY(r1->count() == 3); + QCOMPARE(r1->count(), 3); QQmlListReference r2(*r1); QQmlListReference r3; r3 = *r1; - QVERIFY(r2.count() == 3); - QVERIFY(r3.count() == 3); + QCOMPARE(r2.count(), 3); + QCOMPARE(r3.count(), 3); delete r1; - QVERIFY(r2.count() == 3); - QVERIFY(r3.count() == 3); + QCOMPARE(r2.count(), 3); + QCOMPARE(r3.count(), 3); tt.data.removeAt(2); - QVERIFY(r2.count() == 2); - QVERIFY(r3.count() == 2); + QCOMPARE(r2.count(), 2); + QCOMPARE(r3.count(), 2); } void tst_qqmllistreference::qmlmetaproperty() @@ -580,10 +580,10 @@ void tst_qqmllistreference::qmlmetaproperty() QQmlProperty prop(&tt, QLatin1String("data")); QVariant v = prop.read(); - QVERIFY(v.userType() == qMetaTypeId<QQmlListReference>()); + QCOMPARE(v.userType(), qMetaTypeId<QQmlListReference>()); QQmlListReference ref = qvariant_cast<QQmlListReference>(v); - QVERIFY(ref.count() == 3); - QVERIFY(ref.listElementType() == &TestType::staticMetaObject); + QCOMPARE(ref.count(), 3); + QCOMPARE(ref.listElementType(), &TestType::staticMetaObject); } void tst_qqmllistreference::engineTypes() @@ -595,14 +595,14 @@ void tst_qqmllistreference::engineTypes() QVERIFY(o); QQmlProperty p1(o, QLatin1String("myList")); - QVERIFY(p1.propertyTypeCategory() == QQmlProperty::List); + QCOMPARE(p1.propertyTypeCategory(), QQmlProperty::List); QQmlProperty p2(o, QLatin1String("myList"), engine.rootContext()); - QVERIFY(p2.propertyTypeCategory() == QQmlProperty::List); + QCOMPARE(p2.propertyTypeCategory(), QQmlProperty::List); QVariant v = p2.read(); - QVERIFY(v.userType() == qMetaTypeId<QQmlListReference>()); + QCOMPARE(v.userType(), qMetaTypeId<QQmlListReference>()); QQmlListReference ref = qvariant_cast<QQmlListReference>(v); - QVERIFY(ref.count() == 2); + QCOMPARE(ref.count(), 2); QVERIFY(ref.listElementType()); QVERIFY(ref.listElementType() != &QObject::staticMetaObject); @@ -617,7 +617,7 @@ void tst_qqmllistreference::variantToList() QObject *o = component.create(); QVERIFY(o); - QVERIFY(o->property("value").userType() == qMetaTypeId<QQmlListReference>()); + QCOMPARE(o->property("value").userType(), qMetaTypeId<QQmlListReference>()); QCOMPARE(o->property("test").toInt(), 1); delete o; diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index 011db7b363..ba3f72f2c1 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -451,7 +451,7 @@ void tst_qqmllocale::firstDayOfWeek() Q_ARG(QVariant, QVariant(locale))); QVariant val = obj->property("firstDayOfWeek"); - QVERIFY(val.type() == QVariant::Int); + QCOMPARE(val.type(), QVariant::Int); int day = int(QLocale(locale).firstDayOfWeek()); if (day == 7) // JS Date days in range 0(Sunday) to 6(Saturday) @@ -486,12 +486,12 @@ void tst_qqmllocale::weekDays() Q_ARG(QVariant, QVariant(locale))); QVariant val = obj->property("weekDays"); - QVERIFY(val.userType() == qMetaTypeId<QJSValue>()); + QCOMPARE(val.userType(), qMetaTypeId<QJSValue>()); QList<QVariant> qmlDays = val.toList(); QList<Qt::DayOfWeek> days = QLocale(locale).weekdays(); - QVERIFY(days.count() == qmlDays.count()); + QCOMPARE(days.count(), qmlDays.count()); for (int i = 0; i < days.count(); ++i) { int day = int(days.at(i)); @@ -528,12 +528,12 @@ void tst_qqmllocale::uiLanguages() Q_ARG(QVariant, QVariant(locale))); QVariant val = obj->property("uiLanguages"); - QVERIFY(val.userType() == qMetaTypeId<QJSValue>()); + QCOMPARE(val.userType(), qMetaTypeId<QJSValue>()); QList<QVariant> qmlLangs = val.toList(); QStringList langs = QLocale(locale).uiLanguages(); - QVERIFY(langs.count() == qmlLangs.count()); + QCOMPARE(langs.count(), qmlLangs.count()); for (int i = 0; i < langs.count(); ++i) { QCOMPARE(langs.at(i), qmlLangs.at(i).toString()); diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index f5423582b2..27e92f67a3 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -126,7 +126,7 @@ void tst_qqmlmetatype::initTestCase() void tst_qqmlmetatype::qmlParserStatusCast() { - QVERIFY(QQmlMetaType::qmlType(QVariant::Int) == 0); + QVERIFY(!QQmlMetaType::qmlType(QVariant::Int)); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()) != 0); QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId<TestType *>())->parserStatusCast(), -1); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<ValueSourceTestType *>()) != 0); @@ -146,7 +146,7 @@ void tst_qqmlmetatype::qmlParserStatusCast() void tst_qqmlmetatype::qmlPropertyValueSourceCast() { - QVERIFY(QQmlMetaType::qmlType(QVariant::Int) == 0); + QVERIFY(!QQmlMetaType::qmlType(QVariant::Int)); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()) != 0); QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId<TestType *>())->propertyValueSourceCast(), -1); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<ParserStatusTestType *>()) != 0); @@ -166,7 +166,7 @@ void tst_qqmlmetatype::qmlPropertyValueSourceCast() void tst_qqmlmetatype::qmlPropertyValueInterceptorCast() { - QVERIFY(QQmlMetaType::qmlType(QVariant::Int) == 0); + QVERIFY(!QQmlMetaType::qmlType(QVariant::Int)); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()) != 0); QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId<TestType *>())->propertyValueInterceptorCast(), -1); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<ParserStatusTestType *>()) != 0); @@ -224,8 +224,8 @@ void tst_qqmlmetatype::isList() void tst_qqmlmetatype::defaultObject() { - QVERIFY(QQmlMetaType::defaultProperty(&QObject::staticMetaObject).name() == 0); - QVERIFY(QQmlMetaType::defaultProperty(&ParserStatusTestType::staticMetaObject).name() == 0); + QVERIFY(!QQmlMetaType::defaultProperty(&QObject::staticMetaObject).name()); + QVERIFY(!QQmlMetaType::defaultProperty(&ParserStatusTestType::staticMetaObject).name()); QCOMPARE(QString(QQmlMetaType::defaultProperty(&TestType::staticMetaObject).name()), QString("foo")); QObject o; @@ -233,8 +233,8 @@ void tst_qqmlmetatype::defaultObject() ParserStatusTestType p; QVERIFY(QQmlMetaType::defaultProperty((QObject *)0).name() == 0); - QVERIFY(QQmlMetaType::defaultProperty(&o).name() == 0); - QVERIFY(QQmlMetaType::defaultProperty(&p).name() == 0); + QVERIFY(!QQmlMetaType::defaultProperty(&o).name()); + QVERIFY(!QQmlMetaType::defaultProperty(&p).name()); QCOMPARE(QString(QQmlMetaType::defaultProperty(&t).name()), QString("foo")); } @@ -270,8 +270,8 @@ void tst_qqmlmetatype::compositeType() QQmlType *type = QQmlMetaType::qmlType(QString("ImplicitType"), QString(""), 1, 0); QVERIFY(type); - QVERIFY(type->module() == QLatin1String("")); - QVERIFY(type->elementName() == QLatin1String("ImplicitType")); + QVERIFY(type->module().isEmpty()); + QCOMPARE(type->elementName(), QLatin1String("ImplicitType")); QCOMPARE(type->qmlTypeName(), QLatin1String("ImplicitType")); QCOMPARE(type->sourceUrl(), testFileUrl("ImplicitType.qml")); } diff --git a/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro b/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro new file mode 100644 index 0000000000..f8232f8854 --- /dev/null +++ b/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qqmlobjectmodel +osx:CONFIG -= app_bundle + +SOURCES += tst_qqmlobjectmodel.cpp + +CONFIG += parallel_test + +QT += qml testlib +QT += core-private qml-private diff --git a/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp b/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp new file mode 100644 index 0000000000..001739e38d --- /dev/null +++ b/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/private/qqmlobjectmodel_p.h> +#include <QtTest/qsignalspy.h> +#include <QtTest/qtest.h> + +class tst_QQmlObjectModel : public QObject +{ + Q_OBJECT + +private slots: + void changes(); +}; + +static bool compareItems(QQmlObjectModel *model, const QObjectList &items) +{ + for (int i = 0; i < items.count(); ++i) { + if (model->get(i) != items.at(i)) + return false; + } + return true; +} + +void tst_QQmlObjectModel::changes() +{ + QQmlObjectModel model; + + QSignalSpy countSpy(&model, SIGNAL(countChanged())); + QSignalSpy childrenSpy(&model, SIGNAL(childrenChanged())); + + int count = 0; + int countSignals = 0; + int childrenSignals = 0; + + QObjectList items; + QObject item0, item1, item2, item3; + + // append(item0) -> [item0] + model.append(&item0); items.append(&item0); + QCOMPARE(model.count(), ++count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // insert(0, item1) -> [item1, item0] + model.insert(0, &item1); items.insert(0, &item1); + QCOMPARE(model.count(), ++count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // append(item2) -> [item1, item0, item2] + model.append(&item2); items.append(&item2); + QCOMPARE(model.count(), ++count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // insert(2, item3) -> [item1, item0, item3, item2] + model.insert(2, &item3); items.insert(2, &item3); + QCOMPARE(model.count(), ++count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // move(0, 1) -> [item0, item1, item3, item2] + model.move(0, 1); items.move(0, 1); + QCOMPARE(model.count(), count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // move(3, 2) -> [item0, item1, item2, item3] + model.move(3, 2); items.move(3, 2); + QCOMPARE(model.count(), count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // remove(0) -> [item1, item2, item3] + model.remove(0); items.removeAt(0); + QCOMPARE(model.count(), --count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // remove(2) -> [item1, item2] + model.remove(2); items.removeAt(2); + QCOMPARE(model.count(), --count); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); + + // clear() -> [] + model.clear(); items.clear(); + QCOMPARE(model.count(), 0); + QVERIFY(compareItems(&model, items)); + QCOMPARE(countSpy.count(), ++countSignals); + QCOMPARE(childrenSpy.count(), ++childrenSignals); +} + +QTEST_MAIN(tst_QQmlObjectModel) + +#include "tst_qqmlobjectmodel.moc" diff --git a/tests/auto/qml/qqmlopenmetaobject/qqmlopenmetaobject.pro b/tests/auto/qml/qqmlopenmetaobject/qqmlopenmetaobject.pro new file mode 100644 index 0000000000..c81394e77e --- /dev/null +++ b/tests/auto/qml/qqmlopenmetaobject/qqmlopenmetaobject.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +TARGET = tst_qqmlopenmetaobject +osx:CONFIG -= app_bundle + +SOURCES += tst_qqmlopenmetaobject.cpp + +CONFIG += parallel_test +QT += core-private gui-private qml-private testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qml/qqmlopenmetaobject/tst_qqmlopenmetaobject.cpp b/tests/auto/qml/qqmlopenmetaobject/tst_qqmlopenmetaobject.cpp new file mode 100644 index 0000000000..429f45b875 --- /dev/null +++ b/tests/auto/qml/qqmlopenmetaobject/tst_qqmlopenmetaobject.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <private/qqmlopenmetaobject_p.h> +#include <QtQml/qqmlengine.h> + +class tst_qqmlopenmetaobject : public QObject +{ + Q_OBJECT +public: + tst_qqmlopenmetaobject() {} + +private slots: + void createProperties(); +}; + +class CustomObject: public QObject +{ + Q_OBJECT +public: + CustomObject(QObject *parent = 0) + : QObject(parent) {} +}; + +void tst_qqmlopenmetaobject::createProperties() +{ + QQmlEngine engine; + CustomObject object; + const QQmlRefPointer<QQmlOpenMetaObjectType> mot = new QQmlOpenMetaObjectType(object.metaObject(), &engine); + QQmlOpenMetaObject *const mo = new QQmlOpenMetaObject(&object, mot); + mo->setCached(true); + mot->createProperty("customProperty"); + QVERIFY(true); +} + +QTEST_MAIN(tst_qqmlopenmetaobject) + +#include "tst_qqmlopenmetaobject.moc" diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index a8b06ffa71..d6b1c86b88 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -159,10 +159,10 @@ void tst_qqmlproperty::qmlmetaproperty() QObject *obj = new QObject; - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); - QVERIFY(binding != 0); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(obj, QObjectPrivate::get(obj)->signalIndex("destroyed()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QCOMPARE(prop.name(), QString()); @@ -188,12 +188,12 @@ void tst_qqmlproperty::qmlmetaproperty() QCOMPARE(prop.propertyTypeCategory(), QQmlProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!prop.property().name()); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -255,7 +255,7 @@ void tst_qqmlproperty::registeredCompositeTypeProperty() QQmlProperty p1e(obj, "first", &engine); QQmlProperty p2e(obj, "second", &engine); QQmlProperty p3e(obj, "third", &engine); - QVERIFY(p1.propertyType() == p2.propertyType()); + QCOMPARE(p1.propertyType(), p2.propertyType()); QVERIFY(p1.propertyType() != p3.propertyType()); // check that the values are retrievable from CPP @@ -293,7 +293,7 @@ void tst_qqmlproperty::registeredCompositeTypeProperty() QQmlProperty lp2e(obj, "sclistOne", &engine); QQmlProperty lp3e(obj, "sclistTwo", &engine); QVERIFY(lp1e.propertyType() != lp2e.propertyType()); - QVERIFY(lp2e.propertyType() == lp3e.propertyType()); + QCOMPARE(lp2e.propertyType(), lp3e.propertyType()); // check that the list values are retrievable from CPP QVariant firstList = obj->property("fclist"); @@ -408,10 +408,10 @@ void tst_qqmlproperty::qmlmetaproperty_object() { QQmlProperty prop(&object); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); - QVERIFY(binding != 0); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&object, QObjectPrivate::get(&object)->signalIndex("destroyed()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -439,12 +439,12 @@ void tst_qqmlproperty::qmlmetaproperty_object() QCOMPARE(prop.propertyTypeCategory(), QQmlProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!prop.property().name()); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -455,11 +455,11 @@ void tst_qqmlproperty::qmlmetaproperty_object() { QQmlProperty prop(&dobject); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QObjectPrivate::get(&dobject)->signalIndex("clicked()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -488,13 +488,13 @@ void tst_qqmlproperty::qmlmetaproperty_object() QCOMPARE(prop.propertyType(), (int)QVariant::Int); QCOMPARE(prop.propertyTypeName(), "int"); QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int"); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding != 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding); + QCOMPARE(QQmlPropertyPrivate::binding(prop), binding.data()); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -511,10 +511,10 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() { QQmlProperty prop(&object, QString("defaultProperty")); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); - QVERIFY(binding != 0); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&object, QObjectPrivate::get(&object)->signalIndex("destroyed()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -542,12 +542,12 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QCOMPARE(prop.propertyTypeCategory(), QQmlProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!prop.property().name()); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -558,11 +558,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() { QQmlProperty prop(&dobject, QString("defaultProperty")); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QObjectPrivate::get(&dobject)->signalIndex("clicked()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -591,13 +591,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QCOMPARE(prop.propertyType(), (int)QVariant::Int); QCOMPARE(prop.propertyTypeName(), "int"); QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int"); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding != 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding); + QCOMPARE(QQmlPropertyPrivate::binding(prop), binding.data()); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -608,11 +608,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() { QQmlProperty prop(&dobject, QString("onClicked")); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QQmlPropertyPrivate::get(prop)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -641,13 +641,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(!sigExprWatcher.wasDeleted()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); + QCOMPARE(QQmlPropertyPrivate::signalExpression(prop), sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("clicked()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -657,11 +657,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() { QQmlProperty prop(&dobject, QString("onPropertyWithNotifyChanged")); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QQmlPropertyPrivate::get(prop)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -690,13 +690,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(!sigExprWatcher.wasDeleted()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); + QCOMPARE(QQmlPropertyPrivate::signalExpression(prop), sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -712,10 +712,10 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() { QQmlProperty prop(&object, engine.rootContext()); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); - QVERIFY(binding != 0); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&object, QObjectPrivate::get(&object)->signalIndex("destroyed()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -743,12 +743,12 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() QCOMPARE(prop.propertyTypeCategory(), QQmlProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!prop.property().name()); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -759,11 +759,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() { QQmlProperty prop(&dobject, engine.rootContext()); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QObjectPrivate::get(&dobject)->signalIndex("clicked()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -792,13 +792,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() QCOMPARE(prop.propertyType(), (int)QVariant::Int); QCOMPARE(prop.propertyTypeName(), "int"); QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int"); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding != 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding); + QCOMPARE(QQmlPropertyPrivate::binding(prop), binding.data()); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -815,10 +815,10 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() { QQmlProperty prop(&object, QString("defaultProperty"), engine.rootContext()); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); - QVERIFY(binding != 0); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&object, QObjectPrivate::get(&object)->signalIndex("destroyed()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -846,12 +846,12 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.propertyTypeCategory(), QQmlProperty::InvalidCategory); QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!prop.property().name()); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -862,11 +862,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() { QQmlProperty prop(&dobject, QString("defaultProperty"), engine.rootContext()); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QObjectPrivate::get(&dobject)->signalIndex("clicked()"), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -895,13 +895,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.propertyType(), (int)QVariant::Int); QCOMPARE(prop.propertyTypeName(), "int"); QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int"); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding != 0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding); + QCOMPARE(QQmlPropertyPrivate::binding(prop), binding.data()); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -912,11 +912,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() { QQmlProperty prop(&dobject, QString("onClicked"), engine.rootContext()); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QQmlPropertyPrivate::get(prop)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -945,13 +945,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(!sigExprWatcher.wasDeleted()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); + QCOMPARE(QQmlPropertyPrivate::signalExpression(prop), sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("clicked()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -961,11 +961,11 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() { QQmlProperty prop(&dobject, QString("onPropertyWithNotifyChanged"), engine.rootContext()); - QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); + QQmlAbstractBinding::Ptr binding(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext())); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); - QVERIFY(binding != 0); + QVERIFY(binding); QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(&dobject, QQmlPropertyPrivate::get(prop)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1); - QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QQmlJavaScriptExpression::DeleteWatcher sigExprWatcher(sigExpr); QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -994,13 +994,13 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.propertyType(), 0); QCOMPARE(prop.propertyTypeName(), (const char *)0); QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(QQmlPropertyPrivate::binding(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); - QVERIFY(binding == 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr) == 0); + QVERIFY(!QQmlPropertyPrivate::binding(prop)); + QQmlPropertyPrivate::setBinding(prop, binding.data()); + QVERIFY(binding->ref == 1); + QVERIFY(!QQmlPropertyPrivate::signalExpression(prop)); + QQmlPropertyPrivate::takeSignalExpression(prop, sigExpr); QVERIFY(!sigExprWatcher.wasDeleted()); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); + QCOMPARE(QQmlPropertyPrivate::signalExpression(prop), sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -1146,7 +1146,7 @@ void tst_qqmlproperty::read() QQmlProperty p(&o, "onClicked"); QCOMPARE(p.read(), QVariant()); - QVERIFY(0 == QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1))); + QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1)); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.read(), QVariant()); @@ -1158,7 +1158,7 @@ void tst_qqmlproperty::read() QQmlProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.read(), QVariant()); - QVERIFY(0 == QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1))); + QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1)); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.read(), QVariant()); @@ -1203,7 +1203,7 @@ void tst_qqmlproperty::read() QCOMPARE(p.propertyTypeCategory(), QQmlProperty::Object); QCOMPARE(p.propertyType(), qMetaTypeId<MyQmlObject*>()); QVariant v = p.read(); - QVERIFY(v.userType() == QMetaType::QObjectStar); + QCOMPARE(v.userType(), int(QMetaType::QObjectStar)); QVERIFY(qvariant_cast<QObject *>(v) == o.qmlObject()); } { @@ -1217,7 +1217,7 @@ void tst_qqmlproperty::read() QVERIFY(p.propertyType() != QMetaType::QObjectStar); QVariant v = p.read(); - QVERIFY(v.userType() == QMetaType::QObjectStar); + QCOMPARE(v.userType(), int(QMetaType::QObjectStar)); QCOMPARE(qvariant_cast<QObject *>(v)->property("a").toInt(), 10); QCOMPARE(qvariant_cast<QObject *>(v)->property("b").toInt(), 19); } @@ -1227,7 +1227,7 @@ void tst_qqmlproperty::read() QVERIFY(object != 0); QVariant v = QQmlProperty::read(object, "test", &engine); - QVERIFY(v.userType() == QMetaType::QObjectStar); + QCOMPARE(v.userType(), int(QMetaType::QObjectStar)); QCOMPARE(qvariant_cast<QObject *>(v)->property("a").toInt(), 10); QCOMPARE(qvariant_cast<QObject *>(v)->property("b").toInt(), 19); } @@ -1337,7 +1337,7 @@ void tst_qqmlproperty::write() QQmlProperty p(&o, "onClicked"); QCOMPARE(p.write(QVariant("console.log(1921)")), false); - QVERIFY(0 == QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1))); + QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1)); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.write(QVariant("console.log(1921)")), false); @@ -1351,7 +1351,7 @@ void tst_qqmlproperty::write() QQmlProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.write(QVariant("console.log(1921)")), false); - QVERIFY(0 == QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1))); + QQmlPropertyPrivate::takeSignalExpression(p, new QQmlBoundSignalExpression(&o, QQmlPropertyPrivate::get(p)->signalIndex(), QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), QString(), -1, -1)); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.write(QVariant("console.log(1921)")), false); @@ -1643,7 +1643,7 @@ void tst_qqmlproperty::writeObjectToList() MyContainer *container = qobject_cast<MyContainer*>(containerComponent.create()); QVERIFY(container != 0); QQmlListReference list(container, "children"); - QVERIFY(list.count() == 1); + QCOMPARE(list.count(), 1); MyQmlObject *object = new MyQmlObject; QQmlProperty prop(container, "children"); @@ -1659,7 +1659,7 @@ void tst_qqmlproperty::writeListToList() MyContainer *container = qobject_cast<MyContainer*>(containerComponent.create()); QVERIFY(container != 0); QQmlListReference list(container, "children"); - QVERIFY(list.count() == 1); + QCOMPARE(list.count(), 1); QList<QObject*> objList; objList << new MyQmlObject() << new MyQmlObject() << new MyQmlObject() << new MyQmlObject(); diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 4860602a45..2f3754e42d 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -104,7 +104,7 @@ void tst_QQmlPropertyMap::insert() QQmlPropertyMap map; map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); - QVERIFY(map.keys().count() == 2); + QCOMPARE(map.keys().count(), 2); QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); @@ -117,33 +117,33 @@ void tst_QQmlPropertyMap::insert() //QQmlPropertyMap has an invokable keys() method QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols."); map.insert(QLatin1String("keys"), 1); - QVERIFY(map.keys().count() == 2); + QCOMPARE(map.keys().count(), 2); QVERIFY(!map.contains(QLatin1String("keys"))); QVERIFY(map.value(QLatin1String("keys")).isNull()); //QQmlPropertyMap has a deleteLater() slot QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols."); map.insert(QLatin1String("deleteLater"), 1); - QVERIFY(map.keys().count() == 2); + QCOMPARE(map.keys().count(), 2); QVERIFY(!map.contains(QLatin1String("deleteLater"))); QVERIFY(map.value(QLatin1String("deleteLater")).isNull()); //QQmlPropertyMap has an valueChanged() signal QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols."); map.insert(QLatin1String("valueChanged"), 1); - QVERIFY(map.keys().count() == 2); + QCOMPARE(map.keys().count(), 2); QVERIFY(!map.contains(QLatin1String("valueChanged"))); QVERIFY(map.value(QLatin1String("valueChanged")).isNull()); //but 'valueChange' should be ok map.insert(QLatin1String("valueChange"), 1); - QVERIFY(map.keys().count() == 3); + QCOMPARE(map.keys().count(), 3); QVERIFY(map.contains(QLatin1String("valueChange"))); QCOMPARE(map.value(QLatin1String("valueChange")), QVariant(1)); //'valueCHANGED' should be ok, too map.insert(QLatin1String("valueCHANGED"), 1); - QVERIFY(map.keys().count() == 4); + QCOMPARE(map.keys().count(), 4); QVERIFY(map.contains(QLatin1String("valueCHANGED"))); QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1)); } @@ -153,7 +153,7 @@ void tst_QQmlPropertyMap::operatorInsert() QQmlPropertyMap map; map[QLatin1String("key1")] = 100; map[QLatin1String("key2")] = 200; - QVERIFY(map.keys().count() == 2); + QCOMPARE(map.keys().count(), 2); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); @@ -167,7 +167,7 @@ void tst_QQmlPropertyMap::operatorValue() QQmlPropertyMap map; map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); - QVERIFY(map.count() == 2); + QCOMPARE(map.count(), 2); QVERIFY(map.contains(QLatin1String("key1"))); const QQmlPropertyMap &constMap = map; @@ -182,12 +182,12 @@ void tst_QQmlPropertyMap::clear() { QQmlPropertyMap map; map.insert(QLatin1String("key1"),100); - QVERIFY(map.keys().count() == 1); + QCOMPARE(map.keys().count(), 1); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); map.clear(QLatin1String("key1")); - QVERIFY(map.keys().count() == 1); + QCOMPARE(map.keys().count(), 1); QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant()); } @@ -463,7 +463,7 @@ void tst_QQmlPropertyMap::QTBUG_35906() QScopedPointer<QObject> obj(component.create()); QVERIFY(!obj.isNull()); QVariant value = obj->property("testValue"); - QVERIFY(value.type() == QVariant::Int); + QCOMPARE(value.type(), QVariant::Int); QCOMPARE(value.toInt(), 42); } diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index 671f7b5e73..b5bdc3a3b9 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -651,7 +651,7 @@ void tst_qqmlqt::createQmlObject() QQuickItem *item = qobject_cast<QQuickItem *>(object); QVERIFY(item != 0); - QVERIFY(item->childItems().count() == 1); + QCOMPARE(item->childItems().count(), 1); delete object; } diff --git a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp index 17083a4c6a..5a98a6bed8 100644 --- a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp +++ b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp @@ -134,7 +134,7 @@ void tst_qqmltimer::notRepeating() QCOMPARE(helper.count, 1); consistentWait(200); QCOMPARE(helper.count, 1); - QVERIFY(timer->isRunning() == false); + QVERIFY(!timer->isRunning()); } void tst_qqmltimer::notRepeatingStart() @@ -157,7 +157,7 @@ void tst_qqmltimer::notRepeatingStart() QCOMPARE(helper.count, 1); consistentWait(200); QCOMPARE(helper.count, 1); - QVERIFY(timer->isRunning() == false); + QVERIFY(!timer->isRunning()); delete timer; } @@ -186,8 +186,8 @@ void tst_qqmltimer::repeat() timer->stop(); consistentWait(200); - QVERIFY(helper.count == oldCount); - QVERIFY(timer->isRunning() == false); + QCOMPARE(helper.count, oldCount); + QVERIFY(!timer->isRunning()); QSignalSpy spy(timer, SIGNAL(repeatChanged())); @@ -221,7 +221,7 @@ void tst_qqmltimer::triggeredOnStart() QCOMPARE(helper.count, 2); consistentWait(200); QCOMPARE(helper.count, 2); - QVERIFY(timer->isRunning() == false); + QVERIFY(!timer->isRunning()); QSignalSpy spy(timer, SIGNAL(triggeredOnStartChanged())); diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 578004b0a1..52f744578a 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -1183,7 +1183,7 @@ void tst_qqmlvaluetypes::enums() QQmlComponent component(&engine, testFileUrl("enums.1.qml")); MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::AllUppercase); + QCOMPARE(object->font().capitalization(), QFont::AllUppercase); delete object; } @@ -1191,7 +1191,7 @@ void tst_qqmlvaluetypes::enums() QQmlComponent component(&engine, testFileUrl("enums.2.qml")); MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::AllUppercase); + QCOMPARE(object->font().capitalization(), QFont::AllUppercase); delete object; } @@ -1199,7 +1199,7 @@ void tst_qqmlvaluetypes::enums() QQmlComponent component(&engine, testFileUrl("enums.3.qml")); MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::AllUppercase); + QCOMPARE(object->font().capitalization(), QFont::AllUppercase); delete object; } @@ -1207,7 +1207,7 @@ void tst_qqmlvaluetypes::enums() QQmlComponent component(&engine, testFileUrl("enums.4.qml")); MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::AllUppercase); + QCOMPARE(object->font().capitalization(), QFont::AllUppercase); delete object; } @@ -1215,7 +1215,7 @@ void tst_qqmlvaluetypes::enums() QQmlComponent component(&engine, testFileUrl("enums.5.qml")); MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); QVERIFY(object != 0); - QVERIFY(object->font().capitalization() == QFont::AllUppercase); + QCOMPARE(object->font().capitalization(), QFont::AllUppercase); delete object; } } diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.collection.allprop.expect b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.collection.allprop.expect new file mode 100644 index 0000000000..f0dc8ed3fd --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.collection.allprop.expect @@ -0,0 +1,14 @@ +PROPFIND /container/ HTTP/1.1 +Depth: 1 +Content-Length: 95 +Connection: Keep-Alive +Accept-Encoding: gzip, deflate +Accept-Language: en-US,* +Content-type:i application/xml; charset="utf-8" +User-Agent: Mozilla/5.0 +Host: {{ServerHostUrl}} + +<?xml version="1.0" encoding="utf-8" ?> +<D:propfind xmlns:D="DAV:"> +<D:allprop/> +</D:propfind> diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.collection.allprop.reply.body b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.collection.allprop.reply.body new file mode 100644 index 0000000000..ef0c38956c --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.collection.allprop.reply.body @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +<D:multistatus xmlns:D="DAV:"> + <D:response> + <D:href>/container/</D:href> + <D:propstat> + <D:prop xmlns:R="http://ns.example.com/boxschema/"> + <R:bigbox><R:BoxType>Box type A</R:BoxType></R:bigbox> + <R:author><R:Name>Hadrian</R:Name></R:author> + <D:creationdate>1997-12-01T17:42:21-08:00</D:creationdate> + <D:displayname>Example collection</D:displayname> + <D:resourcetype><D:collection/></D:resourcetype> + <D:supportedlock> + <D:lockentry> + <D:lockscope><D:exclusive/></D:lockscope> + <D:locktype><D:write/></D:locktype> + </D:lockentry> + <D:lockentry> + <D:lockscope><D:shared/></D:lockscope> + <D:locktype><D:write/></D:locktype> + </D:lockentry> + </D:supportedlock> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + </D:response> +/D:multistatus> +--> +<D:multistatus xmlns:D="DAV:"><D:response><D:href>/container/</D:href><D:propstat><D:prop xmlns:R="http://ns.example.com/boxschema/"><R:bigbox><R:BoxType>Box type A</R:BoxType></R:bigbox><R:author><R:Name>Hadrian</R:Name></R:author><D:creationdate>1997-12-01T17:42:21-08:00</D:creationdate><D:displayname>Example collection</D:displayname><D:resourcetype><D:collection/></D:resourcetype><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus> diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.expect b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.expect new file mode 100644 index 0000000000..2d14de634d --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.expect @@ -0,0 +1,18 @@ +PROPFIND /file HTTP/1.1 +Content-Length: 192 +Connection: Keep-Alive +Accept-Encoding: gzip, deflate +Accept-Language: en-US,* +Content-type: text/xml; charset="utf-8" +User-Agent: Mozilla/5.0 +Host: {{ServerHostUrl}} + +<?xml version="1.0" encoding="utf-8" ?> +<D:propfind xmlns:D="DAV:"> +<D:prop xmlns:R="http://www.foo.bar/boxschema/"> +<R:bigbox/> +<R:author/> +<R:DingALing/> +<R:Random/> +</D:prop> +</D:propfind> diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.reply.body b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.reply.body new file mode 100644 index 0000000000..9e5028fe01 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.reply.body @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +<D:multistatus xmlns:D="DAV:"> + <D:response xmlns:R="http://ns.example.com/boxschema/"> + <D:href>http://www.example.com/file</D:href> + <D:propstat> + <D:prop> + <R:bigbox> + <R:BoxType>Box type A</R:BoxType> + </R:bigbox> + <R:author> + <R:Name>J.J. Johnson</R:Name> + </R:author> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <R:DingALing/> + <R:Random/> + </D:prop> + <D:status>HTTP/1.1 403 Forbidden</D:status> + <D:responsedescription>The user does not have access to the DingALing property.</D:responsedescription> + </D:propstat> + </D:response> + <D:responsedescription>There has been an access violation error.</D:responsedescription> +</D:multistatus> +--> +<D:multistatus xmlns:D="DAV:"><D:response xmlns:R="http://ns.example.com/boxschema/"><D:href>http://www.example.com/file</D:href><D:propstat><D:prop><R:bigbox><R:BoxType>Box type A</R:BoxType></R:bigbox><R:author><R:Name>J.J. Johnson</R:Name></R:author></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat><D:propstat><D:prop><R:DingALing/><R:Random/></D:prop><D:status>HTTP/1.1 403 Forbidden</D:status><D:responsedescription>The user does not have access to the DingALing property.</D:responsedescription></D:propstat></D:response><D:responsedescription>There has been an access violation error.</D:responsedescription></D:multistatus> diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.reply.header b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.reply.header new file mode 100644 index 0000000000..50fa080ad2 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/propfind.file.reply.header @@ -0,0 +1,2 @@ +HTTP/1.1 207 Multi-Status +Content-Type: text/xml; charset="utf-8" diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.collection.allprop.qml b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.collection.allprop.qml new file mode 100644 index 0000000000..2f47a5e62c --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.collection.allprop.qml @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +QtObject { + property string url + property bool xmlTest: false + property bool typeTest: false + + function checkXML(document) + { + if (document.xmlVersion != "1.0") + return; + + if (document.xmlEncoding != "utf-8") + return; + + if (document.documentElement == null) + return; + + var multistatus = document.documentElement; + if (multistatus.nodeName != "multistatus") + return; + + if (multistatus.namespaceUri != "DAV:") + return; + + var multistatusChildTags = [ "response" ]; + for (var node = 0; node < multistatus.childNodes.length; ++node) { + if (multistatus.childNodes[node].nodeName != multistatusChildTags[node]) + return; + } + + var response = multistatus.childNodes[0]; + var responseChildTags = [ "href", "propstat" ]; + for (var node = 0; node < response.childNodes.length; ++node) { + var nodeName = response.childNodes[node].nodeName; + if (nodeName != responseChildTags[node]) + return; + + var nodeValue = response.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "href") && (nodeValue != "/container/")) + return; + } + + var propstat = response.childNodes[1]; + var propstatChildTags = ["prop", "status"]; + for (var node = 0; node < propstat.childNodes.length; ++node) { + var nodeName = propstat.childNodes[node].nodeName; + if (nodeName != propstatChildTags[node]) + return; + + var nodeValue = propstat.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "status") && (nodeValue != "HTTP/1.1 200 OK")) + return; + } + + var prop = propstat.childNodes[0]; + var propChildTags = [ "bigbox", "author", "creationdate", "displayname", "resourcetype", "supportedlock" ]; + for (var node = 0; node < prop.childNodes.length; ++node) { + var nodeName = prop.childNodes[node].nodeName; + if (nodeName != propChildTags[node]) + return; + + if (nodeName == "bigbox") { + if (prop.childNodes[node].childNodes.length != 1) + return; + + var boxType = prop.childNodes[node].childNodes[0]; + if (boxType.nodeName != "BoxType") + return; + if (boxType.childNodes[0].nodeValue != "Box type A") + return; + } + + if (nodeName == "author") { + if (prop.childNodes[node].childNodes.length != 1) + return; + + var boxType = prop.childNodes[node].childNodes[0]; + if (boxType.nodeName != "Name") + return; + if (boxType.childNodes[0].nodeValue != "Hadrian") + return; + } + + if (nodeName == "creationdate") { + if (prop.childNodes[node].childNodes.length != 1) + return; + + if (prop.childNodes[node].childNodes[0].nodeValue != "1997-12-01T17:42:21-08:00") + return; + } + + if (nodeName == "displayname") { + if (prop.childNodes[node].childNodes.length != 1) + return; + + if (prop.childNodes[node].childNodes[0].nodeValue != "Example collection") + return; + } + + if (nodeName == "resourcetpye") { + if (prop.childNodes[node].childNodes.length != 1) + return; + + if (prop.childNodes[node].childNodes[0].nodeValue != "collection") + return; + } + + if (nodeName == "supportedlock") { + if (prop.childNodes[node].childNodes.length != 2) + return; + + var lockEntry1 = prop.childNodes[node].childNodes[0]; + if (lockEntry1.nodeName != "lockentry") + return; + if (lockEntry1.childNodes.length != 2) + return; + if (lockEntry1.childNodes[0].nodeName != "lockscope") + return; + if (lockEntry1.childNodes[0].childNodes[0].nodeName != "exclusive") + return; + if (lockEntry1.childNodes[1].nodeName != "locktype") + return; + if (lockEntry1.childNodes[1].childNodes[0].nodeName != "write") + return; + + var lockEntry2 = prop.childNodes[node].childNodes[1]; + if (lockEntry2.nodeName != "lockentry") + return; + if (lockEntry2.childNodes.length != 2) + return; + if (lockEntry2.childNodes[0].nodeName != "lockscope") + return; + if (lockEntry2.childNodes[0].childNodes[0].nodeName != "shared") + return; + if (lockEntry2.childNodes[1].nodeName != "locktype") + return; + if (lockEntry2.childNodes[1].childNodes[0].nodeName != "write") + return; + } + } + + xmlTest = true; + } + + Component.onCompleted: { + + var request = new XMLHttpRequest(); + request.open("PROPFIND", url); + request.responseType = "document"; + request.setRequestHeader("Depth", "1"); + + request.onreadystatechange = function() { + if (request.readyState == XMLHttpRequest.DONE) { + checkXML(request.response); + typeTest = (request.responseType == "document"); + } + } + + var requestBody = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + + "<D:propfind xmlns:D=\"DAV:\">\n" + + "<D:allprop/>\n" + + "</D:propfind>\n" + request.send(requestBody); + } +} + diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.response.qml b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.response.qml new file mode 100644 index 0000000000..01353e5e95 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.response.qml @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +QtObject { + property string url + property bool xmlTest: false + property bool typeTest: false + + function checkXML(document) + { + if (document.xmlVersion != "1.0") + return; + + if (document.xmlEncoding != "utf-8") + return; + + if (document.documentElement == null) + return; + + var multistatus = document.documentElement; + if (multistatus.nodeName != "multistatus") + return; + + if (multistatus.namespaceUri != "DAV:") + return; + + var multistatusChildTags = [ "response", "responsedescription" ]; + for (var node = 0; node < multistatus.childNodes.length; ++node) { + if (multistatus.childNodes[node].nodeName != multistatusChildTags[node]) + return; + } + + var response = multistatus.childNodes[0]; + var responseChildTags = [ "href", "propstat", "propstat" ]; + for (var node = 0; node < response.childNodes.length; ++node) { + var nodeName = response.childNodes[node].nodeName; + if (nodeName != responseChildTags[node]) + return; + + var nodeValue = response.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "href") && (nodeValue != "http://www.example.com/file")) + return; + } + + if (multistatus.childNodes[1].childNodes[0].nodeValue != "There has been an access violation error.") + return; + + var propstat1 = response.childNodes[1]; + var propstat1ChildTags = ["prop", "status"]; + for (var node = 0; node < propstat1.childNodes.length; ++node) { + var nodeName = propstat1.childNodes[node].nodeName; + if (nodeName != propstat1ChildTags[node]) + return; + + var nodeValue = propstat1.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "status") && (nodeValue != "HTTP/1.1 200 OK")) + return; + } + + var prop1 = propstat1.childNodes[0]; + var prop1ChildTags = [ "bigbox", "author" ]; + for (var node = 0; node < prop1.childNodes.length; ++node) { + var nodeName = prop1.childNodes[node].nodeName; + if (nodeName != prop1ChildTags[node]) + return; + + if (nodeName == "bigbox") { + if (prop1.childNodes[node].childNodes.length != 1) + return; + + var boxType = prop1.childNodes[node].childNodes[0]; + if (boxType.nodeName != "BoxType") + return; + if (boxType.childNodes[0].nodeValue != "Box type A") + return; + } + } + + var propstat2 = response.childNodes[2]; + var propstat2ChildTags = ["prop", "status", "responsedescription" ]; + for (var node = 0; node < propstat2.childNodes.length; ++node) { + var nodeName = propstat2.childNodes[node].nodeName; + if (nodeName != propstat2ChildTags[node]) + return; + + var nodeValue = propstat2.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "status") && (nodeValue != "HTTP/1.1 403 Forbidden")) + return; + if ((nodeName == "responsedescription") && (nodeValue != "The user does not have access to the DingALing property.")) + return; + } + + var prop2 = propstat2.childNodes[0]; + var prop2ChildTags = [ "DingALing", "Random" ]; + for (var node = 0; node < prop2.childNodes.length; ++node) { + var nodeName = prop2.childNodes[node].nodeName; + if (nodeName != prop2ChildTags[node]) + return; + } + + xmlTest = true; + } + + Component.onCompleted: { + + var request = new XMLHttpRequest(); + request.open("PROPFIND", url); + request.responseType = "document"; + + request.onreadystatechange = function() { + if (request.readyState == XMLHttpRequest.DONE) { + checkXML(request.response); + typeTest = (request.responseType == "document"); + } + } + + var requestBody = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + + "<D:propfind xmlns:D=\"DAV:\">\n" + + "<D:prop xmlns:R=\"http://www.foo.bar/boxschema/\">\n" + + "<R:bigbox/>\n" + + "<R:author/>\n" + + "<R:DingALing/>\n" + + "<R:Random/>\n" + + "</D:prop>\n" + + "</D:propfind>\n" + request.send(requestBody); + } +} + diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.responseXML.qml b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.responseXML.qml new file mode 100644 index 0000000000..3b4d1e2c1e --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/WebDAV/sendPropfind.responseXML.qml @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +QtObject { + property string url + property bool xmlTest: false + property bool typeTest: false + + function checkXML(document) + { + if (document.xmlVersion != "1.0") + return; + + if (document.xmlEncoding != "utf-8") + return; + + if (document.documentElement == null) + return; + + var multistatus = document.documentElement; + if (multistatus.nodeName != "multistatus") + return; + + if (multistatus.namespaceUri != "DAV:") + return; + + var multistatusChildTags = [ "response", "responsedescription" ]; + for (var node = 0; node < multistatus.childNodes.length; ++node) { + if (multistatus.childNodes[node].nodeName != multistatusChildTags[node]) + return; + } + + var response = multistatus.childNodes[0]; + var responseChildTags = [ "href", "propstat", "propstat" ]; + for (var node = 0; node < response.childNodes.length; ++node) { + var nodeName = response.childNodes[node].nodeName; + if (nodeName != responseChildTags[node]) + return; + + var nodeValue = response.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "href") && (nodeValue != "http://www.example.com/file")) + return; + } + + if (multistatus.childNodes[1].childNodes[0].nodeValue != "There has been an access violation error.") + return; + + var propstat1 = response.childNodes[1]; + var propstat1ChildTags = ["prop", "status"]; + for (var node = 0; node < propstat1.childNodes.length; ++node) { + var nodeName = propstat1.childNodes[node].nodeName; + if (nodeName != propstat1ChildTags[node]) + return; + + var nodeValue = propstat1.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "status") && (nodeValue != "HTTP/1.1 200 OK")) + return; + } + + var prop1 = propstat1.childNodes[0]; + var prop1ChildTags = [ "bigbox", "author" ]; + for (var node = 0; node < prop1.childNodes.length; ++node) { + var nodeName = prop1.childNodes[node].nodeName; + if (nodeName != prop1ChildTags[node]) + return; + + if (nodeName == "bigbox") { + if (prop1.childNodes[node].childNodes.length != 1) + return; + + var boxType = prop1.childNodes[node].childNodes[0]; + if (boxType.nodeName != "BoxType") + return; + if (boxType.childNodes[0].nodeValue != "Box type A") + return; + } + } + + var propstat2 = response.childNodes[2]; + var propstat2ChildTags = ["prop", "status", "responsedescription" ]; + for (var node = 0; node < propstat2.childNodes.length; ++node) { + var nodeName = propstat2.childNodes[node].nodeName; + if (nodeName != propstat2ChildTags[node]) + return; + + var nodeValue = propstat2.childNodes[node].childNodes[0].nodeValue; + if ((nodeName == "status") && (nodeValue != "HTTP/1.1 403 Forbidden")) + return; + if ((nodeName == "responsedescription") && (nodeValue != "The user does not have access to the DingALing property.")) + return; + } + + var prop2 = propstat2.childNodes[0]; + var prop2ChildTags = [ "DingALing", "Random" ]; + for (var node = 0; node < prop2.childNodes.length; ++node) { + var nodeName = prop2.childNodes[node].nodeName; + if (nodeName != prop2ChildTags[node]) + return; + } + + xmlTest = true; + } + + Component.onCompleted: { + + var request = new XMLHttpRequest(); + request.open("PROPFIND", url); + + request.onreadystatechange = function() { + if (request.readyState == XMLHttpRequest.DONE) { + checkXML(request.responseXML); + typeTest = (request.responseType == "document"); + } + } + + var requestBody = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + + "<D:propfind xmlns:D=\"DAV:\">\n" + + "<D:prop xmlns:R=\"http://www.foo.bar/boxschema/\">\n" + + "<R:bigbox/>\n" + + "<R:author/>\n" + + "<R:DingALing/>\n" + + "<R:Random/>\n" + + "</D:prop>\n" + + "</D:propfind>\n" + request.send(requestBody); + } +} + diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/cdata.qml b/tests/auto/qml/qqmlxmlhttprequest/data/cdata.qml index f558fdadc6..e1b690dbf3 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/cdata.qml +++ b/tests/auto/qml/qqmlxmlhttprequest/data/cdata.qml @@ -3,6 +3,7 @@ import QtQuick 2.0 QtObject { property bool xmlTest: false property bool dataOK: false + property int status: 0 function checkCData(text, whitespacetext) { @@ -114,12 +115,11 @@ QtObject { // Test to the end x.onreadystatechange = function() { if (x.readyState == XMLHttpRequest.DONE) { - dataOK = true; + status = x.status; if (x.responseXML != null) checkXML(x.responseXML); - } } diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/json.data b/tests/auto/qml/qqmlxmlhttprequest/data/json.data new file mode 100644 index 0000000000..7925375293 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/json.data @@ -0,0 +1,6 @@ +{"widget": { + "debug": "on", + "window": { + "name": "main_window", + "width": 500 +}}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml b/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml index 234d759284..b9f0ab6e66 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml +++ b/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml @@ -3,6 +3,7 @@ import QtQuick 2.0 QtObject { property string url property int readSize: 0 + property int status: 0 Component.onCompleted: { @@ -12,6 +13,7 @@ QtObject { request.onreadystatechange = function() { if (request.readyState == XMLHttpRequest.DONE) { + status = request.status; var arrayBuffer = request.response; if (arrayBuffer) { var byteArray = new Uint8Array(arrayBuffer); diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml b/tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml new file mode 100644 index 0000000000..3fc116e675 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 + +QtObject { + property string url; + property bool result: false + property string correctjsondata : "{\"widget\":{\"debug\":\"on\",\"window\":{\"name\":\"main_window\",\"width\":500}}}" + + Component.onCompleted: { + var request = new XMLHttpRequest(); + request.open("GET", url, true); + request.responseType = "json"; + + request.onreadystatechange = function() { + if (request.readyState == XMLHttpRequest.DONE) { + var jsonData = JSON.stringify(request.response); + result = (correctjsondata == jsonData); + } + } + + request.send(null); + } +} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect new file mode 100644 index 0000000000..97b016f50a --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect @@ -0,0 +1,7 @@ +GET /json.data HTTP/1.1 +Accept-Language: en-US,* +Content-Type: application/jsonrequest +Connection: Keep-Alive +Accept-Encoding: gzip, deflate +User-Agent: Mozilla/5.0 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply new file mode 100644 index 0000000000..f1ee73d623 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply @@ -0,0 +1,3 @@ +HTTP/1.1 200 OK +Connection: close +Content-Type: application/jsonrequest diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/text.qml b/tests/auto/qml/qqmlxmlhttprequest/data/text.qml index b79e0bc7b1..972557358b 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/text.qml +++ b/tests/auto/qml/qqmlxmlhttprequest/data/text.qml @@ -3,6 +3,7 @@ import QtQuick 2.0 QtObject { property bool xmlTest: false property bool dataOK: false + property int status: 0 function checkText(text, whitespacetext) { @@ -111,12 +112,11 @@ QtObject { // Test to the end x.onreadystatechange = function() { if (x.readyState == XMLHttpRequest.DONE) { - dataOK = true; + status = x.status; if (x.responseXML != null) checkXML(x.responseXML); - } } diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp index c159dc8420..ae0350278a 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -88,6 +88,7 @@ private slots: void getAllResponseHeaders_sent(); void getAllResponseHeaders_args(); void getBinaryData(); + void getJsonData(); void status(); void status_data(); void statusText(); @@ -100,6 +101,10 @@ private slots: void nonUtf8(); void nonUtf8_data(); + // WebDAV + void sendPropfind(); + void sendPropfind_data(); + // Attributes void document(); void element(); @@ -172,7 +177,7 @@ void tst_qqmlxmlhttprequest::callbackException() object->setProperty("which", which); component.completeCreate(); - QTRY_VERIFY(object->property("threw").toBool() == true); + QTRY_VERIFY(object->property("threw").toBool()); } // Test that the state value properties on the XMLHttpRequest constructor have the correct values. @@ -258,7 +263,7 @@ void tst_qqmlxmlhttprequest::open() QCOMPARE(object->property("responseText").toBool(), true); QCOMPARE(object->property("responseXML").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } void tst_qqmlxmlhttprequest::open_data() @@ -371,7 +376,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader() object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Test valid setRequestHeader() calls with different header cases @@ -389,7 +394,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_caseInsensitive() object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Test setting headers before open() throws exception void tst_qqmlxmlhttprequest::setRequestHeader_unsent() @@ -454,7 +459,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_illegalName() QCOMPARE(object->property("responseText").toBool(), true); QCOMPARE(object->property("responseXML").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Test that attempting to set a header after a request is sent throws an exception @@ -474,7 +479,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_sent() QCOMPARE(object->property("test").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Invalid arg count throws exception @@ -505,7 +510,7 @@ void tst_qqmlxmlhttprequest::send_alreadySent() QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Test that sends for GET, HEAD and DELETE ignore data @@ -525,7 +530,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } { @@ -542,7 +547,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } { @@ -559,7 +564,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } } @@ -581,7 +586,7 @@ void tst_qqmlxmlhttprequest::send_withdata() object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } void tst_qqmlxmlhttprequest::send_withdata_data() @@ -655,7 +660,7 @@ void tst_qqmlxmlhttprequest::abort_unsent() QCOMPARE(object->property("responseText").toBool(), true); QCOMPARE(object->property("responseXML").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Test abort() cancels an open (but unsent) request @@ -674,7 +679,7 @@ void tst_qqmlxmlhttprequest::abort_opened() QCOMPARE(object->property("responseText").toBool(), true); QCOMPARE(object->property("responseXML").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } // Test abort() aborts in progress send @@ -700,7 +705,7 @@ void tst_qqmlxmlhttprequest::abort() QCOMPARE(object->property("didNotSeeUnsent").toBool(), true); QCOMPARE(object->property("endStateUnsent").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); } void tst_qqmlxmlhttprequest::getResponseHeader() @@ -725,7 +730,7 @@ void tst_qqmlxmlhttprequest::getResponseHeader() QCOMPARE(object->property("readyState").toBool(), true); QCOMPARE(object->property("openedState").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("headersReceivedState").toBool(), true); QCOMPARE(object->property("headersReceivedNullHeader").toBool(), true); @@ -767,7 +772,7 @@ void tst_qqmlxmlhttprequest::getResponseHeader_args() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("exceptionThrown").toBool() == true); + QTRY_VERIFY(object->property("exceptionThrown").toBool()); } void tst_qqmlxmlhttprequest::getAllResponseHeaders() @@ -791,7 +796,7 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders() QCOMPARE(object->property("readyState").toBool(), true); QCOMPARE(object->property("openedState").toBool(), true); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("headersReceivedState").toBool(), true); QCOMPARE(object->property("headersReceivedHeader").toBool(), true); @@ -827,7 +832,7 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders_args() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("exceptionThrown").toBool() == true); + QTRY_VERIFY(object->property("exceptionThrown").toBool()); } void tst_qqmlxmlhttprequest::getBinaryData() @@ -845,7 +850,25 @@ void tst_qqmlxmlhttprequest::getBinaryData() component.completeCreate(); QFileInfo fileInfo("data/qml_logo.png"); - QTRY_VERIFY(object->property("readSize").toInt() == fileInfo.size()); + QTRY_COMPARE(object->property("readSize").toInt(), fileInfo.size()); + QCOMPARE(object->property("status").toInt(), 200); +} + +void tst_qqmlxmlhttprequest::getJsonData() +{ + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QVERIFY(server.wait(testFileUrl("receive_json_data.expect"), + testFileUrl("receive_binary_data.reply"), + testFileUrl("json.data"))); + + QQmlComponent component(&engine, testFileUrl("receiveJsonData.qml")); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); + object->setProperty("url", server.urlString("/json.data")); + component.completeCreate(); + + QTRY_VERIFY(object->property("result").toBool()); } void tst_qqmlxmlhttprequest::status() @@ -866,7 +889,7 @@ void tst_qqmlxmlhttprequest::status() object->setProperty("expectedStatus", status); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("unsentException").toBool(), true); QCOMPARE(object->property("openedException").toBool(), true); @@ -905,7 +928,7 @@ void tst_qqmlxmlhttprequest::statusText() object->setProperty("expectedStatus", statusText); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("unsentException").toBool(), true); QCOMPARE(object->property("openedException").toBool(), true); @@ -945,7 +968,7 @@ void tst_qqmlxmlhttprequest::responseText() object->setProperty("expectedText", responseText); component.completeCreate(); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("unsent").toBool(), true); QCOMPARE(object->property("opened").toBool(), true); @@ -981,7 +1004,7 @@ void tst_qqmlxmlhttprequest::nonUtf8() object->setProperty("fileName", fileName); QMetaObject::invokeMethod(object.data(), "startRequest"); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("responseText").toString(), responseText); @@ -1007,6 +1030,46 @@ void tst_qqmlxmlhttprequest::nonUtf8_data() QTest::newRow("responseXML") << "utf16.xml" << "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\n" << QString('\n' + uc + '\n'); } +void tst_qqmlxmlhttprequest::sendPropfind() +{ + const QString prefix = "WebDAV//"; + + QFETCH(QString, qml); + QFETCH(QString, resource); + QFETCH(QString, expectedFile); + QFETCH(QString, replyHeader); + QFETCH(QString, replyBody); + + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + + QVERIFY(server.wait(testFileUrl(prefix + expectedFile), + testFileUrl(prefix + replyHeader), + testFileUrl(prefix + replyBody))); + + QQmlComponent component(&engine, testFileUrl(prefix + qml)); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); + object->setProperty("url", server.urlString(resource)); + component.completeCreate(); + + QTRY_VERIFY(object->property("xmlTest").toBool()); + QCOMPARE(object->property("typeTest").toBool(), true); +} + +void tst_qqmlxmlhttprequest::sendPropfind_data() +{ + QTest::addColumn<QString>("qml"); + QTest::addColumn<QString>("resource"); + QTest::addColumn<QString>("expectedFile"); + QTest::addColumn<QString>("replyHeader"); + QTest::addColumn<QString>("replyBody"); + + QTest::newRow("Send PROPFIND for file (bigbox, author, DingALing, Random properties). Get response with responseXML.") << "sendPropfind.responseXML.qml" << "/file" << "propfind.file.expect" << "propfind.file.reply.header" << "propfind.file.reply.body"; + QTest::newRow("Send PROPFIND for file (bigbox, author, DingALing, Random properties). Get response with response.") << "sendPropfind.response.qml" << "/file" << "propfind.file.expect" << "propfind.file.reply.header" << "propfind.file.reply.body"; + QTest::newRow("Send PROPFIND \"allprop\" request for collection.") << "sendPropfind.collection.allprop.qml" << "/container/" << "propfind.collection.allprop.expect" << "propfind.file.reply.header" << "propfind.collection.allprop.reply.body"; +} + // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object // throws an exception void tst_qqmlxmlhttprequest::invalidMethodUsage() @@ -1045,7 +1108,7 @@ void tst_qqmlxmlhttprequest::redirects() object->setProperty("expectedText", ""); component.completeCreate(); - QTRY_VERIFY(object->property("done").toBool() == true); + QTRY_VERIFY(object->property("done").toBool()); QCOMPARE(object->property("dataOK").toBool(), true); } @@ -1062,7 +1125,7 @@ void tst_qqmlxmlhttprequest::redirects() object->setProperty("expectedText", ""); component.completeCreate(); - QTRY_VERIFY(object->property("done").toBool() == true); + QTRY_VERIFY(object->property("done").toBool()); QCOMPARE(object->property("dataOK").toBool(), true); } @@ -1083,7 +1146,7 @@ void tst_qqmlxmlhttprequest::redirects() if (object->property("done").toBool()) break; QTest::qWait(50); } - QVERIFY(object->property("done").toBool() == true); + QVERIFY(object->property("done").toBool()); QCOMPARE(object->property("dataOK").toBool(), true); } @@ -1095,7 +1158,7 @@ void tst_qqmlxmlhttprequest::responseXML_invalid() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("xmlNull").toBool(), true); } @@ -1107,7 +1170,7 @@ void tst_qqmlxmlhttprequest::document() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("xmlTest").toBool(), true); } @@ -1119,7 +1182,7 @@ void tst_qqmlxmlhttprequest::element() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("xmlTest").toBool(), true); } @@ -1131,7 +1194,7 @@ void tst_qqmlxmlhttprequest::attr() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("xmlTest").toBool(), true); } @@ -1143,9 +1206,10 @@ void tst_qqmlxmlhttprequest::text() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("xmlTest").toBool(), true); + QCOMPARE(object->property("status").toInt(), 200); } // Test the CDataSection DOM element @@ -1155,9 +1219,10 @@ void tst_qqmlxmlhttprequest::cdata() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); - QTRY_VERIFY(object->property("dataOK").toBool() == true); + QTRY_VERIFY(object->property("dataOK").toBool()); QCOMPARE(object->property("xmlTest").toBool(), true); + QCOMPARE(object->property("status").toInt(), 200); } void tst_qqmlxmlhttprequest::stateChangeCallingContext() @@ -1179,7 +1244,7 @@ void tst_qqmlxmlhttprequest::stateChangeCallingContext() object->setProperty("serverBaseUrl", server.baseUrl().toString()); component.completeCreate(); server.sendDelayedItem(); - QTRY_VERIFY(object->property("success").toBool() == true); + QTRY_VERIFY(object->property("success").toBool()); } QTEST_MAIN(tst_qqmlxmlhttprequest) diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index 59be469d5b..dc6e2fa561 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -295,11 +295,11 @@ void tst_qquickfolderlistmodel::changeDrive() flm->setProperty("folder",QUrl::fromLocalFile(dataDir)); QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(dataDir)); - QTRY_VERIFY(folderChangeSpy.count() == 1); + QTRY_COMPARE(folderChangeSpy.count(), 1); flm->setProperty("folder",QUrl::fromLocalFile("X:/resetfiltering/")); QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile("X:/resetfiltering/")); - QTRY_VERIFY(folderChangeSpy.count() == 2); + QTRY_COMPARE(folderChangeSpy.count(), 2); } #endif diff --git a/tests/auto/qml/qv4debugger/qv4debugger.pro b/tests/auto/qml/qv4debugger/qv4debugger.pro index 2a318955f3..540cab70e6 100644 --- a/tests/auto/qml/qv4debugger/qv4debugger.pro +++ b/tests/auto/qml/qv4debugger/qv4debugger.pro @@ -2,6 +2,14 @@ CONFIG += testcase TARGET = tst_qv4debugger macx:CONFIG -= app_bundle -SOURCES += tst_qv4debugger.cpp +SOURCES += \ + $$PWD/tst_qv4debugger.cpp \ + $$PWD/../../../../src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp + +HEADERS += \ + $$PWD/../../../../src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h + +INCLUDEPATH += \ + $$PWD/../../../../src/plugins/qmltooling/qmldbg_debugger QT += core-private gui-private qml-private network testlib diff --git a/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp index 056b24d167..ca308a4f49 100644 --- a/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp @@ -32,12 +32,15 @@ ****************************************************************************/ #include <QtTest/QtTest> +#include "qv4datacollector.h" + #include <QJSEngine> #include <QQmlEngine> #include <QQmlComponent> #include <private/qv4engine_p.h> #include <private/qv4debugging_p.h> #include <private/qv8engine_p.h> +#include <private/qv4objectiterator_p.h> using namespace QV4; using namespace QV4::Debugging; @@ -85,99 +88,93 @@ public: QV4::ScopedString name(scope, v4->newString(functionName)); QV4::ScopedContext ctx(scope, v4->rootContext()); QV4::ScopedValue function(scope, BuiltinFunction::create(ctx, name, injectedFunction)); - v4->globalObject()->put(name, function); + v4->globalObject->put(name, function); } signals: void evaluateFinished(); }; - -namespace { -class TestCollector: public QV4::Debugging::Debugger::Collector +class TestAgent : public QObject { + Q_OBJECT public: - TestCollector(QV4::ExecutionEngine *engine) - : Collector(engine) - , destination(0) - {} - - virtual ~TestCollector() {} - - void setDestination(QVariantMap *dest) - { destination = dest; } - -protected: - virtual void addUndefined(const QString &name) - { - destination->insert(name, QStringLiteral("undefined")); // TODO: add a user-defined type for this - } - - virtual void addNull(const QString &name) - { - destination->insert(name, QStringLiteral("null")); // TODO: add a user-defined type for this - } - - virtual void addBoolean(const QString &name, bool value) - { - destination->insert(name, value); - } + typedef QV4DataCollector::Refs Refs; + typedef QV4DataCollector::Ref Ref; + struct NamedRefs { + NamedRefs(QV4DataCollector *collector = 0): collector(collector) {} + + QStringList names; + Refs refs; + QV4DataCollector *collector; + + int size() const { + Q_ASSERT(names.size() == refs.size()); + return names.size(); + } - virtual void addString(const QString &name, const QString &value) - { - destination->insert(name, value); - } + bool contains(const QString &name) const { + return names.contains(name); + } - virtual void addObject(const QString &name, const QV4::Value &value) - { - QV4::Scope scope(engine()); - QV4::ScopedObject obj(scope, value.asObject()); +#define DUMP_JSON(x) {\ + QJsonDocument doc(x);\ + qDebug() << #x << "=" << doc.toJson(QJsonDocument::Indented);\ +} - QVariantMap props, *prev = &props; - qSwap(destination, prev); - collect(obj); - qSwap(destination, prev); + QJsonObject rawValue(const QString &name) const { + Q_ASSERT(contains(name)); + return collector->lookupRef(refs.at(names.indexOf(name))); + } - destination->insert(name, props); - } + QJsonValue value(const QString &name) const { + return rawValue(name).value(QStringLiteral("value")); + } - virtual void addInteger(const QString &name, int value) - { - destination->insert(name, QVariant::fromValue<double>(static_cast<double>(value))); - } + QString type(const QString &name) const { + return rawValue(name).value(QStringLiteral("type")).toString(); + } - virtual void addDouble(const QString &name, double value) - { - destination->insert(name, QVariant::fromValue<double>(value)); - } + void dump(const QString &name) const { + if (!contains(name)) { + qDebug() << "no" << name; + return; + } -private: - QVariantMap *destination; -}; -} + QJsonObject o = collector->lookupRef(refs.at(names.indexOf(name))); + QJsonDocument d; + d.setObject(o); + qDebug() << name << "=" << d.toJson(QJsonDocument::Indented); + } + }; -class TestAgent : public QV4::Debugging::DebuggerAgent -{ - Q_OBJECT -public: - TestAgent() + TestAgent(QV4::ExecutionEngine *engine) : m_wasPaused(false) , m_captureContextInfo(false) + , m_thrownValue(-1) + , collector(engine) + , m_debugger(0) { } - virtual void debuggerPaused(Debugger *debugger, PauseReason reason) +public slots: + void debuggerPaused(QV4::Debugging::Debugger *debugger, QV4::Debugging::PauseReason reason) { - Q_ASSERT(m_debuggers.count() == 1 && m_debuggers.first() == debugger); + Q_ASSERT(debugger == m_debugger); + Q_ASSERT(debugger->engine() == collector.engine()); m_wasPaused = true; m_pauseReason = reason; m_statesWhenPaused << debugger->currentExecutionState(); - TestCollector collector(debugger->engine()); - QVariantMap tmp; - collector.setDestination(&tmp); - debugger->collectThrownValue(&collector); - m_thrownValue = tmp["exception"]; + if (debugger->state() == QV4::Debugging::Debugger::Paused && + debugger->engine()->hasException) { + Refs refs; + RefHolder holder(&collector, &refs); + ExceptionCollectJob job(debugger->engine(), &collector); + debugger->runInEngine(&job); + Q_ASSERT(refs.size() > 0); + m_thrownValue = refs.first(); + } foreach (const TestBreakPoint &bp, m_breakPointsToAddWhenPaused) debugger->addBreakPoint(bp.fileName, bp.lineNumber); @@ -186,11 +183,13 @@ public: m_stackTrace = debugger->stackTrace(); while (!m_expressionRequests.isEmpty()) { + Q_ASSERT(debugger->state() == QV4::Debugging::Debugger::Paused); ExpressionRequest request = m_expressionRequests.takeFirst(); - QVariantMap result; - collector.setDestination(&result); - debugger->evaluateExpression(request.frameNr, request.expression, &collector); - m_expressionResults << result[QString::fromLatin1("body")]; + m_expressionResults << Refs(); + RefHolder holder(&collector, &m_expressionResults.last()); + ExpressionEvalJob job(debugger->engine(), request.frameNr, request.expression, + &collector); + debugger->runInEngine(&job); } if (m_captureContextInfo) @@ -199,15 +198,7 @@ public: debugger->resume(Debugger::FullThrottle); } - virtual void sourcesCollected(Debugger *debugger, QStringList sources, int requestSequenceNr) - { - Q_UNUSED(debugger); - Q_UNUSED(sources); - Q_UNUSED(requestSequenceNr); - } - - int debuggerCount() const { return m_debuggers.count(); } - +public: struct TestBreakPoint { TestBreakPoint() : lineNumber(-1) {} @@ -219,37 +210,49 @@ public: void captureContextInfo(Debugger *debugger) { - TestCollector collector(debugger->engine()); - for (int i = 0, ei = m_stackTrace.size(); i != ei; ++i) { - QVariantMap args; - collector.setDestination(&args); - debugger->collectArgumentsInContext(&collector, i); - m_capturedArguments.append(args); - - QVariantMap locals; - collector.setDestination(&locals); - debugger->collectLocalsInContext(&collector, i); - m_capturedLocals.append(locals); + m_capturedArguments.append(NamedRefs(&collector)); + RefHolder argHolder(&collector, &m_capturedArguments.last().refs); + ArgumentCollectJob argumentsJob(debugger->engine(), &collector, + &m_capturedArguments.last().names, i, 0); + debugger->runInEngine(&argumentsJob); + + m_capturedLocals.append(NamedRefs(&collector)); + RefHolder localHolder(&collector, &m_capturedLocals.last().refs); + LocalCollectJob localsJob(debugger->engine(), &collector, + &m_capturedLocals.last().names, i, 0); + debugger->runInEngine(&localsJob); } } + void addDebugger(QV4::Debugging::Debugger *debugger) + { + Q_ASSERT(!m_debugger); + m_debugger = debugger; + connect(m_debugger, + SIGNAL(debuggerPaused(QV4::Debugging::Debugger*,QV4::Debugging::PauseReason)), + this, + SLOT(debuggerPaused(QV4::Debugging::Debugger*,QV4::Debugging::PauseReason))); + } + bool m_wasPaused; PauseReason m_pauseReason; bool m_captureContextInfo; QList<Debugger::ExecutionState> m_statesWhenPaused; QList<TestBreakPoint> m_breakPointsToAddWhenPaused; QVector<QV4::StackFrame> m_stackTrace; - QList<QVariantMap> m_capturedArguments; - QList<QVariantMap> m_capturedLocals; - QVariant m_thrownValue; + QVector<NamedRefs> m_capturedArguments; + QVector<NamedRefs> m_capturedLocals; + qint64 m_thrownValue; + QV4DataCollector collector; struct ExpressionRequest { QString expression; int frameNr; }; QVector<ExpressionRequest> m_expressionRequests; - QVector<QVariant> m_expressionResults; + QVector<Refs> m_expressionResults; + QV4::Debugging::Debugger *m_debugger; // Utility methods: void dumpStackTrace() const @@ -315,7 +318,7 @@ void tst_qv4debugger::init() m_v4->enableDebugger(); m_engine->moveToThread(m_javaScriptThread); m_javaScriptThread->start(); - m_debuggerAgent = new TestAgent; + m_debuggerAgent = new TestAgent(m_v4); m_debuggerAgent->addDebugger(m_v4->debugger); } @@ -327,7 +330,6 @@ void tst_qv4debugger::cleanup() delete m_javaScriptThread; m_engine = 0; m_v4 = 0; - QCOMPARE(m_debuggerAgent->debuggerCount(), 0); delete m_debuggerAgent; m_debuggerAgent = 0; } @@ -338,7 +340,7 @@ void tst_qv4debugger::breakAnywhere() "var i = 42;\n" "var j = i + 1\n" "var k = i\n"; - m_debuggerAgent->pauseAll(); + m_v4->debugger->pause(); evaluateJavaScript(script, "testFile"); QVERIFY(m_debuggerAgent->m_wasPaused); } @@ -349,7 +351,7 @@ void tst_qv4debugger::pendingBreakpoint() "var i = 42;\n" "var j = i + 1\n" "var k = i\n"; - m_debuggerAgent->addBreakPoint("testfile", 2); + m_v4->debugger->addBreakPoint("testfile", 2); evaluateJavaScript(script, "testfile"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 1); @@ -365,7 +367,7 @@ void tst_qv4debugger::liveBreakPoint() "var j = i + 1\n" "var k = i\n"; m_debuggerAgent->m_breakPointsToAddWhenPaused << TestAgent::TestBreakPoint("liveBreakPoint", 3); - m_debuggerAgent->pauseAll(); + m_v4->debugger->pause(); evaluateJavaScript(script, "liveBreakPoint"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 2); @@ -380,8 +382,8 @@ void tst_qv4debugger::removePendingBreakPoint() "var i = 42;\n" "var j = i + 1\n" "var k = i\n"; - int id = m_debuggerAgent->addBreakPoint("removePendingBreakPoint", 2); - m_debuggerAgent->removeBreakPoint(id); + m_v4->debugger->addBreakPoint("removePendingBreakPoint", 2); + m_v4->debugger->removeBreakPoint("removePendingBreakPoint", 2); evaluateJavaScript(script, "removePendingBreakPoint"); QVERIFY(!m_debuggerAgent->m_wasPaused); } @@ -392,7 +394,7 @@ void tst_qv4debugger::addBreakPointWhilePaused() "var i = 42;\n" "var j = i + 1\n" "var k = i\n"; - m_debuggerAgent->addBreakPoint("addBreakPointWhilePaused", 1); + m_v4->debugger->addBreakPoint("addBreakPointWhilePaused", 1); m_debuggerAgent->m_breakPointsToAddWhenPaused << TestAgent::TestBreakPoint("addBreakPointWhilePaused", 2); evaluateJavaScript(script, "addBreakPointWhilePaused"); QVERIFY(m_debuggerAgent->m_wasPaused); @@ -422,7 +424,7 @@ void tst_qv4debugger::removeBreakPointForNextInstruction() QMetaObject::invokeMethod(m_engine, "injectFunction", Qt::BlockingQueuedConnection, Q_ARG(QString, "someCall"), Q_ARG(InjectedFunction, someCall)); - m_debuggerAgent->addBreakPoint("removeBreakPointForNextInstruction", 2); + m_v4->debugger->addBreakPoint("removeBreakPointForNextInstruction", 2); evaluateJavaScript(script, "removeBreakPointForNextInstruction"); QVERIFY(!m_debuggerAgent->m_wasPaused); @@ -439,16 +441,19 @@ void tst_qv4debugger::conditionalBreakPoint() "}\n" "test()\n"; - m_debuggerAgent->addBreakPoint("conditionalBreakPoint", 3, /*enabled*/true, QStringLiteral("i > 10")); + m_v4->debugger->addBreakPoint("conditionalBreakPoint", 3, QStringLiteral("i > 10")); evaluateJavaScript(script, "conditionalBreakPoint"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 4); QV4::Debugging::Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.first(); QCOMPARE(state.fileName, QString("conditionalBreakPoint")); QCOMPARE(state.lineNumber, 3); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0].size(), 2); - QVERIFY(m_debuggerAgent->m_capturedLocals[0].contains(QStringLiteral("i"))); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0]["i"].toInt(), 11); + + QVERIFY(m_debuggerAgent->m_capturedLocals.size() > 1); + const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedLocals.at(0); + QCOMPARE(frame0.size(), 2); + QVERIFY(frame0.contains("i")); + QCOMPARE(frame0.value("i").toInt(), 11); } void tst_qv4debugger::conditionalBreakPointInQml() @@ -459,7 +464,7 @@ void tst_qv4debugger::conditionalBreakPointInQml() QScopedPointer<QThread> debugThread(new QThread); debugThread->start(); - QScopedPointer<TestAgent> debuggerAgent(new TestAgent); + QScopedPointer<TestAgent> debuggerAgent(new TestAgent(v4)); debuggerAgent->addDebugger(v4->debugger); debuggerAgent->moveToThread(debugThread.data()); @@ -474,7 +479,7 @@ void tst_qv4debugger::conditionalBreakPointInQml() " }\n" "}\n", QUrl("test.qml")); - debuggerAgent->addBreakPoint("test.qml", 7, /*enabled*/true, "root.foo == 42"); + v4->debugger->addBreakPoint("test.qml", 7, "root.foo == 42"); QScopedPointer<QObject> obj(component.create()); QCOMPARE(obj->property("success").toBool(), true); @@ -496,16 +501,18 @@ void tst_qv4debugger::readArguments() "}\n" "var four;\n" "f(1, 'two', null, four);\n"; - m_debuggerAgent->addBreakPoint("readArguments", 2); + m_v4->debugger->addBreakPoint("readArguments", 2); evaluateJavaScript(script, "readArguments"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_capturedArguments[0].size(), 4); - QVERIFY(m_debuggerAgent->m_capturedArguments[0].contains(QStringLiteral("a"))); - QCOMPARE(m_debuggerAgent->m_capturedArguments[0]["a"].type(), QVariant::Double); - QCOMPARE(m_debuggerAgent->m_capturedArguments[0]["a"].toDouble(), 1.0); - QVERIFY(m_debuggerAgent->m_capturedArguments[0].contains("b")); - QCOMPARE(m_debuggerAgent->m_capturedArguments[0]["b"].type(), QVariant::String); - QCOMPARE(m_debuggerAgent->m_capturedArguments[0]["b"].toString(), QLatin1String("two")); + QVERIFY(m_debuggerAgent->m_capturedArguments.size() > 1); + const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedArguments.at(0); + QCOMPARE(frame0.size(), 4); + QVERIFY(frame0.contains(QStringLiteral("a"))); + QCOMPARE(frame0.type(QStringLiteral("a")), QStringLiteral("number")); + QCOMPARE(frame0.value(QStringLiteral("a")).toDouble(), 1.0); + QVERIFY(frame0.names.contains("b")); + QCOMPARE(frame0.type(QStringLiteral("b")), QStringLiteral("string")); + QCOMPARE(frame0.value(QStringLiteral("b")).toString(), QStringLiteral("two")); } void tst_qv4debugger::readLocals() @@ -518,15 +525,17 @@ void tst_qv4debugger::readLocals() " return c === d\n" "}\n" "f(1, 2, 3);\n"; - m_debuggerAgent->addBreakPoint("readLocals", 3); + m_v4->debugger->addBreakPoint("readLocals", 3); evaluateJavaScript(script, "readLocals"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0].size(), 2); - QVERIFY(m_debuggerAgent->m_capturedLocals[0].contains("c")); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0]["c"].type(), QVariant::Double); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0]["c"].toDouble(), 3.0); - QVERIFY(m_debuggerAgent->m_capturedLocals[0].contains("d")); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0]["d"].toString(), QString("undefined")); + QVERIFY(m_debuggerAgent->m_capturedLocals.size() > 1); + const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedLocals.at(0); + QCOMPARE(frame0.size(), 2); + QVERIFY(frame0.contains("c")); + QCOMPARE(frame0.type("c"), QStringLiteral("number")); + QCOMPARE(frame0.value("c").toDouble(), 3.0); + QVERIFY(frame0.contains("d")); + QCOMPARE(frame0.type("d"), QStringLiteral("undefined")); } void tst_qv4debugger::readObject() @@ -538,26 +547,49 @@ void tst_qv4debugger::readObject() " return b\n" "}\n" "f({head: 1, tail: { head: 'asdf', tail: null }});\n"; - m_debuggerAgent->addBreakPoint("readObject", 3); + m_v4->debugger->addBreakPoint("readObject", 3); evaluateJavaScript(script, "readObject"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0].size(), 1); - QVERIFY(m_debuggerAgent->m_capturedLocals[0].contains("b")); - QCOMPARE(m_debuggerAgent->m_capturedLocals[0]["b"].type(), QVariant::Map); - - QVariantMap b = m_debuggerAgent->m_capturedLocals[0]["b"].toMap(); - QCOMPARE(b.size(), 2); - QVERIFY(b.contains("head")); - QCOMPARE(b["head"].type(), QVariant::Double); - QCOMPARE(b["head"].toDouble(), 1.0); - QVERIFY(b.contains("tail")); - QCOMPARE(b["tail"].type(), QVariant::Map); - - QVariantMap b_tail = b["tail"].toMap(); - QCOMPARE(b_tail.size(), 2); - QVERIFY(b_tail.contains("head")); - QCOMPARE(b_tail["head"].type(), QVariant::String); - QCOMPARE(b_tail["head"].toString(), QString("asdf")); + QVERIFY(m_debuggerAgent->m_capturedLocals.size() > 1); + const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedLocals.at(0); + QCOMPARE(frame0.size(), 1); + QVERIFY(frame0.contains("b")); + QCOMPARE(frame0.type("b"), QStringLiteral("object")); + QJsonObject b = frame0.rawValue("b"); + QVERIFY(b.contains(QStringLiteral("properties"))); + QVERIFY(b.value("properties").isArray()); + QJsonArray b_props = b.value("properties").toArray(); + QCOMPARE(b_props.size(), 2); + + QVERIFY(b_props.at(0).isObject()); + QJsonObject b_head = b_props.at(0).toObject(); + QCOMPARE(b_head.value("name").toString(), QStringLiteral("head")); + QVERIFY(b_head.contains("ref")); + QJsonObject b_head_value = frame0.collector->lookupRef(b_head.value("ref").toInt()); + QCOMPARE(b_head_value.value("type").toString(), QStringLiteral("number")); + QCOMPARE(b_head_value.value("value").toDouble(), 1.0); + QVERIFY(b_props.at(1).isObject()); + QJsonObject b_tail = b_props.at(1).toObject(); + QCOMPARE(b_tail.value("name").toString(), QStringLiteral("tail")); + QVERIFY(b_tail.contains("ref")); + + QJsonObject b_tail_value = frame0.collector->lookupRef(b_tail.value("ref").toInt()); + QCOMPARE(b_tail_value.value("type").toString(), QStringLiteral("object")); + QVERIFY(b_tail_value.contains("properties")); + QJsonArray b_tail_props = b_tail_value.value("properties").toArray(); + QCOMPARE(b_tail_props.size(), 2); + QJsonObject b_tail_head = b_tail_props.at(0).toObject(); + QCOMPARE(b_tail_head.value("name").toString(), QStringLiteral("head")); + QVERIFY(b_tail_head.contains("ref")); + QJsonObject b_tail_head_value = frame0.collector->lookupRef(b_tail_head.value("ref").toInt()); + QCOMPARE(b_tail_head_value.value("type").toString(), QStringLiteral("string")); + QCOMPARE(b_tail_head_value.value("value").toString(), QStringLiteral("asdf")); + QJsonObject b_tail_tail = b_tail_props.at(1).toObject(); + QCOMPARE(b_tail_tail.value("name").toString(), QStringLiteral("tail")); + QVERIFY(b_tail_tail.contains("ref")); + + QJsonObject b_tail_tail_value = frame0.collector->lookupRef(b_tail_tail.value("ref").toInt()); + QCOMPARE(b_tail_tail_value.value("type").toString(), QStringLiteral("null")); } void tst_qv4debugger::readContextInAllFrames() @@ -573,7 +605,7 @@ void tst_qv4debugger::readContextInAllFrames() " return 1;\n" // breakpoint "}\n" "fact(12);\n"; - m_debuggerAgent->addBreakPoint("readFormalsInAllFrames", 7); + m_v4->debugger->addBreakPoint("readFormalsInAllFrames", 7); evaluateJavaScript(script, "readFormalsInAllFrames"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_stackTrace.size(), 13); @@ -581,18 +613,20 @@ void tst_qv4debugger::readContextInAllFrames() QCOMPARE(m_debuggerAgent->m_capturedLocals.size(), 13); for (int i = 0; i < 12; ++i) { - QCOMPARE(m_debuggerAgent->m_capturedArguments[i].size(), 1); - QVERIFY(m_debuggerAgent->m_capturedArguments[i].contains("n")); - QCOMPARE(m_debuggerAgent->m_capturedArguments[i]["n"].type(), QVariant::Double); - QCOMPARE(m_debuggerAgent->m_capturedArguments[i]["n"].toDouble(), i + 1.0); - - QCOMPARE(m_debuggerAgent->m_capturedLocals[i].size(), 1); - QVERIFY(m_debuggerAgent->m_capturedLocals[i].contains("n_1")); + const TestAgent::NamedRefs &args = m_debuggerAgent->m_capturedArguments.at(i); + QCOMPARE(args.size(), 1); + QVERIFY(args.contains("n")); + QCOMPARE(args.type("n"), QStringLiteral("number")); + QCOMPARE(args.value("n").toDouble(), i + 1.0); + + const TestAgent::NamedRefs &locals = m_debuggerAgent->m_capturedLocals.at(i); + QCOMPARE(locals.size(), 1); + QVERIFY(locals.contains("n_1")); if (i == 0) { - QCOMPARE(m_debuggerAgent->m_capturedLocals[i]["n_1"].toString(), QString("undefined")); + QCOMPARE(locals.type("n_1"), QStringLiteral("undefined")); } else { - QCOMPARE(m_debuggerAgent->m_capturedLocals[i]["n_1"].type(), QVariant::Double); - QCOMPARE(m_debuggerAgent->m_capturedLocals[i]["n_1"].toInt(), i); + QCOMPARE(locals.type("n_1"), QStringLiteral("number")); + QCOMPARE(locals.value("n_1").toInt(), i); } } QCOMPARE(m_debuggerAgent->m_capturedArguments[12].size(), 0); @@ -606,13 +640,16 @@ void tst_qv4debugger::pauseOnThrow() " throw n\n" "}\n" "die('hard');\n"; - m_debuggerAgent->setBreakOnThrow(true); + m_v4->debugger->setBreakOnThrow(true); evaluateJavaScript(script, "pauseOnThrow"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, Throwing); QCOMPARE(m_debuggerAgent->m_stackTrace.size(), 2); - QCOMPARE(m_debuggerAgent->m_thrownValue.type(), QVariant::String); - QCOMPARE(m_debuggerAgent->m_thrownValue.toString(), QString("hard")); + QVERIFY(m_debuggerAgent->m_thrownValue >= qint64(0)); + QJsonObject exception = m_debuggerAgent->collector.lookupRef(m_debuggerAgent->m_thrownValue); +// DUMP_JSON(exception); + QCOMPARE(exception.value("type").toString(), QStringLiteral("string")); + QCOMPARE(exception.value("value").toString(), QStringLiteral("hard")); } void tst_qv4debugger::breakInCatch() @@ -624,7 +661,7 @@ void tst_qv4debugger::breakInCatch() " console.log(e, 'me');\n" "}\n"; - m_debuggerAgent->addBreakPoint("breakInCatch", 4); + m_v4->debugger->addBreakPoint("breakInCatch", 4); evaluateJavaScript(script, "breakInCatch"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, BreakPoint); @@ -641,7 +678,7 @@ void tst_qv4debugger::breakInWith() " console.log('give the answer');\n" "}\n"; - m_debuggerAgent->addBreakPoint("breakInWith", 2); + m_v4->debugger->addBreakPoint("breakInWith", 2); evaluateJavaScript(script, "breakInWith"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, BreakPoint); @@ -669,13 +706,21 @@ void tst_qv4debugger::evaluateExpression() request.frameNr = 1; m_debuggerAgent->m_expressionRequests << request; - m_debuggerAgent->addBreakPoint("evaluateExpression", 3); + m_v4->debugger->addBreakPoint("evaluateExpression", 3); evaluateJavaScript(script, "evaluateExpression"); QCOMPARE(m_debuggerAgent->m_expressionResults.count(), 2); - QCOMPARE(m_debuggerAgent->m_expressionResults[0].toInt(), 10); - QCOMPARE(m_debuggerAgent->m_expressionResults[1].toInt(), 20); + QCOMPARE(m_debuggerAgent->m_expressionResults[0].size(), 1); + QJsonObject result0 = + m_debuggerAgent->collector.lookupRef(m_debuggerAgent->m_expressionResults[0].first()); + QCOMPARE(result0.value("type").toString(), QStringLiteral("number")); + QCOMPARE(result0.value("value").toInt(), 10); + QCOMPARE(m_debuggerAgent->m_expressionResults[1].size(), 1); + QJsonObject result1 = + m_debuggerAgent->collector.lookupRef(m_debuggerAgent->m_expressionResults[1].first()); + QCOMPARE(result1.value("type").toString(), QStringLiteral("number")); + QCOMPARE(result1.value("value").toInt(), 20); } QTEST_MAIN(tst_qv4debugger) diff --git a/tests/auto/qmldevtools/compile/tst_compile.cpp b/tests/auto/qmldevtools/compile/tst_compile.cpp index b19260779c..4637f14739 100644 --- a/tests/auto/qmldevtools/compile/tst_compile.cpp +++ b/tests/auto/qmldevtools/compile/tst_compile.cpp @@ -37,7 +37,6 @@ #include <private/qqmljsastvisitor_p.h> #include <private/qqmljsast_p.h> #include <private/qqmlirbuilder_p.h> -#include <private/qv4value_inl_p.h> #include <private/qv4codegen_p.h> int main() diff --git a/tests/auto/qmltest/BLACKLIST b/tests/auto/qmltest/BLACKLIST new file mode 100644 index 0000000000..cd8b1181e0 --- /dev/null +++ b/tests/auto/qmltest/BLACKLIST @@ -0,0 +1,5 @@ +# Blacklist for testing +[SelfTests::test_blacklisted_fail] +* +[SelfTests::test_blacklistWithData:test2] +* diff --git a/tests/auto/qmltest/objectmodel/tst_objectmodel.qml b/tests/auto/qmltest/objectmodel/tst_objectmodel.qml new file mode 100644 index 0000000000..e8205a1486 --- /dev/null +++ b/tests/auto/qmltest/objectmodel/tst_objectmodel.qml @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQml 2.1 +import QtQml.Models 2.3 +import QtTest 1.1 + +TestCase { + name: "ObjectModel" + + ObjectModel { + id: model + QtObject { id: static0 } + QtObject { id: static1 } + QtObject { id: static2 } + } + + Component { id: object; QtObject { } } + + function test_attached_index() { + compare(model.count, 3) + compare(static0.ObjectModel.index, 0) + compare(static1.ObjectModel.index, 1) + compare(static2.ObjectModel.index, 2) + + var dynamic0 = object.createObject(model, {objectName: "dynamic0"}) + compare(dynamic0.ObjectModel.index, -1) + model.append(dynamic0) // -> [static0, static1, static2, dynamic0] + compare(model.count, 4) + for (var i = 0; i < model.count; ++i) + compare(model.get(i).ObjectModel.index, i) + + var dynamic1 = object.createObject(model, {objectName: "dynamic1"}) + compare(dynamic1.ObjectModel.index, -1) + model.insert(0, dynamic1) // -> [dynamic1, static0, static1, static2, dynamic0] + compare(model.count, 5) + for (i = 0; i < model.count; ++i) + compare(model.get(i).ObjectModel.index, i) + + model.move(1, 3) // -> [dynamic1, static1, static2, static0, dynamic0] + compare(model.count, 5) + for (i = 0; i < model.count; ++i) + compare(model.get(i).ObjectModel.index, i) + + model.move(4, 0) // -> [dynamic0, dynamic1, static1, static2, static0] + compare(model.count, 5) + for (i = 0; i < model.count; ++i) + compare(model.get(i).ObjectModel.index, i) + + model.remove(1) // -> [dynamic0, static1, static2, static0] + compare(model.count, 4) + compare(dynamic1.ObjectModel.index, -1) + for (i = 0; i < model.count; ++i) + compare(model.get(i).ObjectModel.index, i) + + model.clear() + compare(static0.ObjectModel.index, -1) + compare(static1.ObjectModel.index, -1) + compare(static2.ObjectModel.index, -1) + compare(dynamic0.ObjectModel.index, -1) + compare(dynamic1.ObjectModel.index, -1) + } +} diff --git a/tests/auto/qmltest/qtbug46798/tst_qtbug46798.qml b/tests/auto/qmltest/qtbug46798/tst_qtbug46798.qml new file mode 100644 index 0000000000..9de9a621f6 --- /dev/null +++ b/tests/auto/qmltest/qtbug46798/tst_qtbug46798.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQml.Models 2.3 +import QtTest 1.1 + +Item { + id: top + + ListView { + id: listViewWithObjectModel // QTBUG-46798 + anchors.fill: parent + model: ObjectModel { + id: objectModel + Rectangle { width: 160; height: 160; color: "red" } + Rectangle { width: 160; height: 160; color: "green" } + Rectangle { width: 160; height: 160; color: "blue" } + } + } + + TestCase { + name: "QTBUG-46798" + when: windowShown + + function test_bug46798() { + var item = objectModel.get(0) + if (item) { + objectModel.remove(0) + item.destroy() + } + } + } +} diff --git a/tests/auto/qmltest/selftests/tst_grabImage.qml b/tests/auto/qmltest/selftests/tst_grabImage.qml new file mode 100644 index 0000000000..7a758ae8fc --- /dev/null +++ b/tests/auto/qmltest/selftests/tst_grabImage.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.1 + +TestCase { + id: testCase + name: "tst_grabImage" + when: windowShown + + function test_equals() { + var rect = Qt.createQmlObject("import QtQuick 2.0; Rectangle { color: 'red'; width: 10; height: 10; }", testCase); + verify(rect); + var oldImage = grabImage(rect); + rect.width += 10; + var newImage = grabImage(rect); + verify(!newImage.equals(oldImage)); + + oldImage = grabImage(rect); + // Don't change anything... + newImage = grabImage(rect); + verify(newImage.equals(oldImage)); + + verify(!newImage.equals(null)); + verify(!newImage.equals(undefined)); + } +} diff --git a/tests/auto/qmltest/selftests/tst_selftests.qml b/tests/auto/qmltest/selftests/tst_selftests.qml index 0d09f9536a..a372107e26 100644 --- a/tests/auto/qmltest/selftests/tst_selftests.qml +++ b/tests/auto/qmltest/selftests/tst_selftests.qml @@ -278,4 +278,30 @@ TestCase { } verify(caught) } + + function test_blacklisted_fail() + { + verify(false) + } + + function test_blacklistWithData_data() { + return [ + { + tag: "test1", + success: true + }, + { + tag: "test2", + success: false + }, + { + tag: "test3", + success: true + } + ] + } + + function test_blacklistWithData(row) { + verify(row.success) + } } diff --git a/tests/auto/qmltest/textedit/tst_textedit_editingfinished.qml b/tests/auto/qmltest/textedit/tst_textedit_editingfinished.qml new file mode 100644 index 0000000000..c9eadde373 --- /dev/null +++ b/tests/auto/qmltest/textedit/tst_textedit_editingfinished.qml @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtTest 1.1 + +Row { + width: 100 + height: 50 + spacing: 10 + + property alias control1: _control1 + property alias control2: _control2 + TextEdit { + id: _control1 + text: 'A' + property bool myeditingfinished: false + onEditingFinished: myeditingfinished = true + activeFocusOnTab: true + } + TextEdit { + id: _control2 + text: 'B' + property bool myeditingfinished: false + onEditingFinished: myeditingfinished = true + activeFocusOnTab: true + } + + TestCase { + name: "TextEdit_editingFinished" + when: windowShown + + function test_editingFinished() { + control1.forceActiveFocus() + verify(control1.activeFocus) + verify(!control2.activeFocus) + + verify(control1.myeditingfinished === false) + verify(control2.myeditingfinished === false) + + keyClick(Qt.Key_Backtab) + verify(!control1.activeFocus) + verify(control2.activeFocus) + verify(control1.myeditingfinished === true) + + keyClick(Qt.Key_Backtab) + verify(control1.activeFocus) + verify(!control2.activeFocus) + verify(control2.myeditingfinished === true) + } + } +} diff --git a/tests/auto/qmltest/window/tst_clickwindow.qml b/tests/auto/qmltest/window/tst_clickwindow.qml new file mode 100644 index 0000000000..bbe091990c --- /dev/null +++ b/tests/auto/qmltest/window/tst_clickwindow.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Window 2.0 +import QtTest 1.1 + +Item { + width: height + height: 40 + MouseArea { + id: ma + anchors.fill: parent + + property bool everClicked: false + + onClicked: everClicked = true; + } + + Window { + id: ma2Window + width: height + height: 40 + MouseArea { + id: ma2 + anchors.fill: parent + + property bool everClicked: false + + onClicked: everClicked = true; + } + + Component.onCompleted: ma2Window.show(); + } + + TestCase { + name: "ClickWindow" + when: windowShown + + function test_clickBothWindows() { + mouseClick(ma, 20, 20); + verify(ma.everClicked); + mouseClick(ma2, 20, 20); + verify(ma2.everClicked); + } + } +} diff --git a/tests/auto/quick/geometry/tst_geometry.cpp b/tests/auto/quick/geometry/tst_geometry.cpp index 1cc9b112cc..bdd6f1a394 100644 --- a/tests/auto/quick/geometry/tst_geometry.cpp +++ b/tests/auto/quick/geometry/tst_geometry.cpp @@ -58,7 +58,7 @@ void GeometryTest::testPoint2D() QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 2); QCOMPARE(geometry.vertexCount(), 4); QCOMPARE(geometry.indexCount(), 0); - QVERIFY(geometry.indexData() == 0); + QVERIFY(!geometry.indexData()); QSGGeometry::updateRectGeometry(&geometry, QRectF(1, 2, 3, 4)); @@ -91,7 +91,7 @@ void GeometryTest::testTexturedPoint2D() QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 4); QCOMPARE(geometry.vertexCount(), 4); QCOMPARE(geometry.indexCount(), 0); - QVERIFY(geometry.indexData() == 0); + QVERIFY(!geometry.indexData()); QSGGeometry::updateTexturedRectGeometry(&geometry, QRectF(1, 2, 3, 4), QRectF(5, 6, 7, 8)); @@ -163,7 +163,7 @@ void GeometryTest::testCustomGeometry() for (int i=0; i<4000; ++i) QCOMPARE(ii[i], (quint16) i); for (int i=0; i<1000; ++i) - QVERIFY(v[i].v1 == 6); + QCOMPARE(v[i].v1, float(6)); } diff --git a/tests/auto/quick/nokeywords/tst_nokeywords.cpp b/tests/auto/quick/nokeywords/tst_nokeywords.cpp index 378af7ea90..58746447f0 100644 --- a/tests/auto/quick/nokeywords/tst_nokeywords.cpp +++ b/tests/auto/quick/nokeywords/tst_nokeywords.cpp @@ -67,7 +67,6 @@ #include <QtQuick/private/qsgrenderer_p.h> #include <QtQuick/private/qsgrenderloop_p.h> #include <QtQuick/private/qsgrendernode_p.h> -#include <QtQuick/private/qsgshareddistancefieldglyphcache_p.h> #include <QtQuick/private/qsgtexturematerial_p.h> #include <QtQuick/private/qsgtexture_p.h> #include <QtQuick/private/qsgthreadedrenderloop_p.h> diff --git a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp index 6591d84504..597ea87feb 100644 --- a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp @@ -405,15 +405,15 @@ void tst_qquickanchors::resetConvenience() //fill itemPrivate->anchors()->setFill(baseItem); - QVERIFY(itemPrivate->anchors()->fill() == baseItem); + QCOMPARE(itemPrivate->anchors()->fill(), baseItem); itemPrivate->anchors()->resetFill(); - QVERIFY(itemPrivate->anchors()->fill() == 0); + QVERIFY(!itemPrivate->anchors()->fill()); //centerIn itemPrivate->anchors()->setCenterIn(baseItem); - QVERIFY(itemPrivate->anchors()->centerIn() == baseItem); + QCOMPARE(itemPrivate->anchors()->centerIn(), baseItem); itemPrivate->anchors()->resetCenterIn(); - QVERIFY(itemPrivate->anchors()->centerIn() == 0); + QVERIFY(!itemPrivate->anchors()->centerIn()); delete item; delete baseItem; diff --git a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp index a0accfcd58..45694f38dd 100644 --- a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -335,48 +335,48 @@ void tst_qquickanimatedimage::sourceSizeChanges() // Local ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_VERIFY(sourceSizeSpy.count() == 0); + QTRY_COMPARE(sourceSizeSpy.count(), 0); ctxt->setContextProperty("srcImage", testFileUrl("hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 1); + QTRY_COMPARE(sourceSizeSpy.count(), 1); ctxt->setContextProperty("srcImage", testFileUrl("hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 1); + QTRY_COMPARE(sourceSizeSpy.count(), 1); ctxt->setContextProperty("srcImage", testFileUrl("hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 1); + QTRY_COMPARE(sourceSizeSpy.count(), 1); ctxt->setContextProperty("srcImage", testFileUrl("colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 2); + QTRY_COMPARE(sourceSizeSpy.count(), 2); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_VERIFY(sourceSizeSpy.count() == 3); + QTRY_COMPARE(sourceSizeSpy.count(), 3); // Remote ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 4); + QTRY_COMPARE(sourceSizeSpy.count(), 4); ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 4); + QTRY_COMPARE(sourceSizeSpy.count(), 4); ctxt->setContextProperty("srcImage", server.url("/hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 4); + QTRY_COMPARE(sourceSizeSpy.count(), 4); ctxt->setContextProperty("srcImage", server.url("/colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 5); + QTRY_COMPARE(sourceSizeSpy.count(), 5); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_VERIFY(sourceSizeSpy.count() == 6); + QTRY_COMPARE(sourceSizeSpy.count(), 6); delete anim; } @@ -397,8 +397,8 @@ void tst_qquickanimatedimage::qtbug_16520() QVERIFY(anim != 0); anim->setProperty("source", server.urlString("/stickman.gif")); - QTRY_VERIFY(anim->opacity() == 0); - QTRY_VERIFY(anim->opacity() == 1); + QTRY_COMPARE(anim->opacity(), qreal(0)); + QTRY_COMPARE(anim->opacity(), qreal(1)); delete anim; delete root; @@ -418,8 +418,8 @@ void tst_qquickanimatedimage::progressAndStatusChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QCOMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); qRegisterMetaType<QQuickImageBase::Status>(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); @@ -428,33 +428,33 @@ void tst_qquickanimatedimage::progressAndStatusChanges() // Same image ctxt->setContextProperty("srcImage", testFileUrl("stickman.gif")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 0); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.gif")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/stickman.gif")); - QTRY_VERIFY(obj->status() == QQuickImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); QTRY_VERIFY(progressSpy.count() > 1); QTRY_COMPARE(statusSpy.count(), 3); ctxt->setContextProperty("srcImage", ""); - QTRY_VERIFY(obj->status() == QQuickImage::Null); - QTRY_VERIFY(obj->progress() == 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Null); + QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(sourceSpy.count(), 3); QTRY_VERIFY(progressSpy.count() > 2); QTRY_COMPARE(statusSpy.count(), 4); @@ -472,7 +472,7 @@ void tst_qquickanimatedimage::playingAndPausedChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickAnimatedImage *obj = qobject_cast<QQuickAnimatedImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickAnimatedImage::Null); + QCOMPARE(obj->status(), QQuickAnimatedImage::Null); QTRY_VERIFY(obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); QSignalSpy playingSpy(obj, SIGNAL(playingChanged())); diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 45cfe4f334..2b805e9eeb 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -122,9 +122,9 @@ void tst_qquickanimations::simpleProperty() animation.setTargetObject(&rect); animation.setProperty("x"); animation.setTo(200); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to().toReal() == 200.0); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("x")); + QCOMPARE(animation.to().toReal(), 200.0); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -136,7 +136,7 @@ void tst_qquickanimations::simpleProperty() animation.pause(); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(),100.0); } @@ -147,9 +147,9 @@ void tst_qquickanimations::simpleNumber() animation.setTargetObject(&rect); animation.setProperty("x"); animation.setTo(200); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to() == 200); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("x")); + QCOMPARE(animation.to(), qreal(200)); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -161,7 +161,7 @@ void tst_qquickanimations::simpleNumber() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(), qreal(100)); } @@ -172,9 +172,9 @@ void tst_qquickanimations::simpleColor() animation.setTargetObject(&rect); animation.setProperty("color"); animation.setTo(QColor("red")); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "color"); - QVERIFY(animation.to() == QColor("red")); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("color")); + QCOMPARE(animation.to(), QColor("red")); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -186,12 +186,12 @@ void tst_qquickanimations::simpleColor() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1)); rect.setColor(QColor("green")); animation.setFrom(QColor("blue")); - QVERIFY(animation.from() == QColor("blue")); + QCOMPARE(animation.from(), QColor("blue")); animation.restart(); QCOMPARE(rect.color(), QColor("blue")); QVERIFY(animation.isRunning()); @@ -206,10 +206,10 @@ void tst_qquickanimations::simpleRotation() animation.setTargetObject(&rect); animation.setProperty("rotation"); animation.setTo(270); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "rotation"); - QVERIFY(animation.to() == 270); - QVERIFY(animation.direction() == QQuickRotationAnimation::Numerical); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("rotation")); + QCOMPARE(animation.to(), qreal(270)); + QCOMPARE(animation.direction(), QQuickRotationAnimation::Numerical); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -221,7 +221,7 @@ void tst_qquickanimations::simpleRotation() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.rotation(), qreal(135)); } @@ -567,8 +567,8 @@ void tst_qquickanimations::alwaysRunToEnd() animation.setDuration(1000); animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.loops() == -1); - QVERIFY(animation.alwaysRunToEnd() == true); + QCOMPARE(animation.loops(), -1); + QVERIFY(animation.alwaysRunToEnd()); QElapsedTimer timer; timer.start(); @@ -600,7 +600,7 @@ void tst_qquickanimations::complete() animation.setFrom(1); animation.setTo(200); animation.setDuration(500); - QVERIFY(animation.from() == 1); + QCOMPARE(animation.from().toInt(), 1); animation.start(); QTest::qWait(50); animation.stop(); @@ -620,7 +620,7 @@ void tst_qquickanimations::resume() animation.setFrom(10); animation.setTo(200); animation.setDuration(1000); - QVERIFY(animation.from() == 10); + QCOMPARE(animation.from().toInt(), 10); animation.start(); QTest::qWait(400); @@ -685,7 +685,7 @@ void tst_qquickanimations::dotProperty() animation.start(); animation.pause(); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.border()->width(), 5.0); } @@ -708,7 +708,7 @@ void tst_qquickanimations::badTypes() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); c.create(); - QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().count(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected")); } @@ -719,7 +719,7 @@ void tst_qquickanimations::badTypes() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); c.create(); - QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().count(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected")); } @@ -1065,7 +1065,7 @@ void tst_qquickanimations::propertyValueSourceDefaultStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim); - QVERIFY(myAnim->isRunning() == false); + QVERIFY(!myAnim->isRunning()); } { @@ -1078,7 +1078,7 @@ void tst_qquickanimations::propertyValueSourceDefaultStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } } @@ -1097,7 +1097,7 @@ void tst_qquickanimations::dontStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } { @@ -1112,7 +1112,7 @@ void tst_qquickanimations::dontStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } } @@ -1350,8 +1350,8 @@ void tst_qquickanimations::alwaysRunToEndRestartBug() animation.setDuration(1000); animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.loops() == -1); - QVERIFY(animation.alwaysRunToEnd() == true); + QCOMPARE(animation.loops(), -1); + QVERIFY(animation.alwaysRunToEnd()); animation.start(); animation.stop(); animation.start(); @@ -1387,7 +1387,7 @@ void tst_qquickanimations::pauseBindingBug() QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); QVERIFY(rect != 0); QQuickAbstractAnimation *anim = rect->findChild<QQuickAbstractAnimation*>("animation"); - QVERIFY(anim->qtAnimation()->state() == QAbstractAnimationJob::Paused); + QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Paused); delete rect; } diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp index 7df020405f..1d8fc430b8 100644 --- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp +++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp @@ -97,7 +97,7 @@ void tst_qquickapplication::active() window.show(); window.requestActivate(); QTest::qWaitForWindowActive(&window); - QVERIFY(QGuiApplication::focusWindow() == &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); QVERIFY(item->property("active").toBool()); QVERIFY(item->property("active2").toBool()); @@ -167,7 +167,7 @@ void tst_qquickapplication::state() window.show(); window.requestActivate(); QTest::qWaitForWindowActive(&window); - QVERIFY(QGuiApplication::focusWindow() == &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationActive); QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationActive); diff --git a/tests/auto/quick/qquickbehaviors/BLACKLIST b/tests/auto/quick/qquickbehaviors/BLACKLIST new file mode 100644 index 0000000000..9be4da176d --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/BLACKLIST @@ -0,0 +1,2 @@ +[currentValue] +windows diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index b96f1de930..643bed4376 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -82,39 +82,35 @@ void tst_qquickbehaviors::simpleBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("simple.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QTRY_VERIFY(qobject_cast<QQuickBehavior*>(rect->findChild<QQuickBehavior*>("MyBehavior"))->animation()); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::scriptTriggered() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("scripttrigger.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); rect->setColor(QColor("red")); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::cppTriggered() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("cpptrigger.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *innerRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect")); QTRY_VERIFY(innerRect); @@ -122,60 +118,52 @@ void tst_qquickbehaviors::cppTriggered() innerRect->setProperty("x", 200); QTRY_VERIFY(innerRect->x() > 0); QTRY_VERIFY(innerRect->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::loop() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("loop.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); //don't crash - QQuickItemPrivate::get(rect)->setState("moved"); - - delete rect; + QQuickItemPrivate::get(rect.data())->setState("moved"); } void tst_qquickbehaviors::colorBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("color.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("red"); + QQuickItemPrivate::get(rect.data())->setState("red"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->color() != QColor("red")); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->color() != QColor("green")); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::parentBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("parent.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("reparented"); + QQuickItemPrivate::get(rect.data())->setState("reparented"); QTRY_VERIFY(rect->findChild<QQuickRectangle*>("MyRect")->parentItem() != rect->findChild<QQuickItem*>("NewParent")); QTRY_VERIFY(rect->findChild<QQuickRectangle*>("MyRect")->parentItem() == rect->findChild<QQuickItem*>("NewParent")); - - delete rect; } void tst_qquickbehaviors::replaceBinding() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("binding.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QQuickRectangle *innerRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect")); QTRY_VERIFY(innerRect); QTRY_VERIFY(innerRect->x() > 0); @@ -187,7 +175,7 @@ void tst_qquickbehaviors::replaceBinding() rect->setProperty("movedx", 210); QTRY_COMPARE(innerRect->x(), (qreal)210); - QQuickItemPrivate::get(rect)->setState(""); + QQuickItemPrivate::get(rect.data())->setState(""); QTRY_VERIFY(innerRect->x() > 10); QTRY_VERIFY(innerRect->x() < 210); //i.e. the behavior has been triggered QTRY_COMPARE(innerRect->x(), (qreal)10); @@ -195,8 +183,6 @@ void tst_qquickbehaviors::replaceBinding() QTRY_COMPARE(innerRect->x(), (qreal)10); rect->setProperty("basex", 20); QTRY_COMPARE(innerRect->x(), (qreal)20); - - delete rect; } void tst_qquickbehaviors::group() @@ -205,32 +191,27 @@ void tst_qquickbehaviors::group() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("groupProperty.qml"))); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - qDebug() << c.errorString(); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); //QTest::qWait(200); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } */ { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("groupProperty2.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->border()->width() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->border()->width() < 4); //i.e. the behavior has been triggered - - delete rect; } } @@ -238,56 +219,48 @@ void tst_qquickbehaviors::valueType() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("valueType.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); //QTBUG-20827 QCOMPARE(rect->color(), QColor::fromRgb(255,0,255)); - - delete rect; } void tst_qquickbehaviors::emptyBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("empty.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately - - delete rect; } void tst_qquickbehaviors::explicitSelection() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("explicit.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::nonSelectingBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("nonSelecting2.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately - - delete rect; } void tst_qquickbehaviors::reassignedAnimation() @@ -296,27 +269,23 @@ void tst_qquickbehaviors::reassignedAnimation() QQmlComponent c(&engine, testFileUrl("reassignedAnimation.qml")); QString warning = testFileUrl("reassignedAnimation.qml").toString() + ":9:9: QML Behavior: Cannot change the animation assigned to a Behavior."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QCOMPARE(qobject_cast<QQuickNumberAnimation*>( rect->findChild<QQuickBehavior*>("MyBehavior")->animation())->duration(), 200); - - delete rect; } void tst_qquickbehaviors::disabled() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("disabled.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QCOMPARE(rect->findChild<QQuickBehavior*>("MyBehavior")->enabled(), false); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately - - delete rect; } void tst_qquickbehaviors::dontStart() @@ -327,13 +296,12 @@ void tst_qquickbehaviors::dontStart() QString warning = c.url().toString() + ":13:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && !myAnim->qtAnimation()); - - delete rect; + QVERIFY(myAnim); + QVERIFY(!myAnim->qtAnimation()); } void tst_qquickbehaviors::startup() @@ -341,22 +309,20 @@ void tst_qquickbehaviors::startup() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("startup.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *innerRect = rect->findChild<QQuickRectangle*>("innerRect"); QVERIFY(innerRect); QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately - - delete rect; } { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("startup2.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *innerRect = rect->findChild<QQuickRectangle*>("innerRect"); QVERIFY(innerRect); @@ -365,8 +331,6 @@ void tst_qquickbehaviors::startup() QVERIFY(text); QCOMPARE(innerRect->x(), text->width()); //should be set immediately - - delete rect; } } @@ -375,10 +339,8 @@ void tst_qquickbehaviors::groupedPropertyCrash() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("groupedPropertyCrash.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); //don't crash - - delete rect; + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); //don't crash } //QTBUG-5491 @@ -386,8 +348,8 @@ void tst_qquickbehaviors::runningTrue() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("runningTrue.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickAbstractAnimation *animation = rect->findChild<QQuickAbstractAnimation*>("rotAnim"); QVERIFY(animation); @@ -395,8 +357,6 @@ void tst_qquickbehaviors::runningTrue() QSignalSpy runningSpy(animation, SIGNAL(runningChanged(bool))); rect->setProperty("myValue", 180); QTRY_VERIFY(runningSpy.count() > 0); - - delete rect; } //QTBUG-12295 @@ -404,8 +364,8 @@ void tst_qquickbehaviors::sameValue() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("qtbug12295.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *target = rect->findChild<QQuickRectangle*>("myRect"); QVERIFY(target); @@ -424,8 +384,6 @@ void tst_qquickbehaviors::sameValue() //even though we set 0 twice in a row. target->setProperty("x", 0); QTRY_VERIFY(target->x() != qreal(0) && target->x() != qreal(100)); - - delete rect; } //QTBUG-18362 @@ -434,8 +392,8 @@ void tst_qquickbehaviors::delayedRegistration() QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("delayedRegistration.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect != 0); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickItem *innerRect = rect->property("myItem").value<QQuickItem*>(); QVERIFY(innerRect != 0); @@ -451,8 +409,8 @@ void tst_qquickbehaviors::startOnCompleted() QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("startOnCompleted.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect != 0); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickItem *innerRect = rect->findChild<QQuickRectangle*>(); QVERIFY(innerRect != 0); @@ -460,8 +418,6 @@ void tst_qquickbehaviors::startOnCompleted() QCOMPARE(innerRect->property("x").toInt(), int(0)); QTRY_COMPARE(innerRect->property("x").toInt(), int(100)); - - delete rect; } //QTBUG-25139 @@ -471,7 +427,7 @@ void tst_qquickbehaviors::multipleChangesToValueType() QQmlComponent c(&engine, testFileUrl("multipleChangesToValueType.qml")); QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle *>(c.create())); - QVERIFY(rect != 0); + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickText *text = rect->findChild<QQuickText *>(); QVERIFY(text != 0); @@ -496,8 +452,8 @@ void tst_qquickbehaviors::currentValue() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("qtbug21549.qml")); - QQuickItem *item = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(item); + QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!item.isNull(), qPrintable(c.errorString())); QQuickRectangle *target = item->findChild<QQuickRectangle*>("myRect"); QVERIFY(target); @@ -516,15 +472,13 @@ void tst_qquickbehaviors::currentValue() target->setProperty("x", 100); QCOMPARE(item->property("behaviorCount").toInt(), 1); QCOMPARE(target->x(), qreal(100)); - - delete item; } { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("qtbug21549-2.qml")); - QQuickItem *item = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(item); + QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!item.isNull(), qPrintable(c.errorString())); QQuickRectangle *target = item->findChild<QQuickRectangle*>("myRect"); QVERIFY(target); @@ -537,9 +491,7 @@ void tst_qquickbehaviors::currentValue() // in the QML (which should be between 50 and 80); QTRY_COMPARE(item->property("animRunning").toBool(), true); QTRY_COMPARE(item->property("animRunning").toBool(), false); - QVERIFY(target->x() > qreal(50) && target->x() < qreal(80)); - - delete item; + QVERIFY2(target->x() > qreal(50) && target->x() < qreal(80), QByteArray::number(target->x())); } } @@ -548,8 +500,8 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("disabledWriteWhileRunning.qml")); - QQuickItem *root = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(root); + QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!root.isNull(), qPrintable(c.errorString())); QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(root->findChild<QQuickRectangle*>("MyRect")); QQuickBehavior *myBehavior = qobject_cast<QQuickBehavior*>(root->findChild<QQuickBehavior*>("MyBehavior")); @@ -579,16 +531,14 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() QCOMPARE(myRect->x(), qreal(100)); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); - - delete root; } //test additional complications with SmoothedAnimation { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("disabledWriteWhileRunning2.qml")); - QQuickItem *root = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(root); + QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!root.isNull(), qPrintable(c.errorString())); QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(root->findChild<QQuickRectangle*>("MyRect")); QQuickBehavior *myBehavior = qobject_cast<QQuickBehavior*>(root->findChild<QQuickBehavior*>("MyBehavior")); @@ -623,8 +573,6 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() QCOMPARE(myRect->x(), qreal(100)); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); - - delete root; } } diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index efe2ca8b18..071ea0b494 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -132,6 +132,13 @@ void tst_qquickborderimage::imageSource() QFETCH(bool, remote); QFETCH(QString, error); +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + if (qstrcmp(QTest::currentDataTag(), "remote") == 0 + || qstrcmp(QTest::currentDataTag(), "remote not found") == 0) { + QSKIP("Remote tests cause occasional hangs in the CI system -- QTBUG-45655"); + } +#endif + TestHTTPServer server; if (remote) { QVERIFY2(server.listen(), qPrintable(server.errorString())); @@ -150,12 +157,12 @@ void tst_qquickborderimage::imageSource() QVERIFY(obj != 0); if (remote) - QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Loading); QCOMPARE(obj->source(), remote ? source : QUrl(source)); if (error.isEmpty()) { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QCOMPARE(obj->width(), 120.); QCOMPARE(obj->height(), 120.); QCOMPARE(obj->sourceSize().width(), 120); @@ -163,7 +170,7 @@ void tst_qquickborderimage::imageSource() QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch); QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch); } else { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Error); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Error); } delete obj; @@ -178,13 +185,13 @@ void tst_qquickborderimage::clearSource() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickBorderImage::Ready); + QCOMPARE(obj->status(), QQuickBorderImage::Ready); QCOMPARE(obj->width(), 120.); QCOMPARE(obj->height(), 120.); ctxt->setContextProperty("srcImage", ""); QVERIFY(obj->source().isEmpty()); - QVERIFY(obj->status() == QQuickBorderImage::Null); + QCOMPARE(obj->status(), QQuickBorderImage::Null); QCOMPARE(obj->width(), 0.); QCOMPARE(obj->height(), 0.); @@ -296,14 +303,14 @@ void tst_qquickborderimage::sciSource() QVERIFY(obj != 0); if (remote) - QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Loading); QCOMPARE(obj->source(), remote ? source : QUrl(source)); QCOMPARE(obj->width(), 300.); QCOMPARE(obj->height(), 300.); if (valid) { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QCOMPARE(obj->border()->left(), 10); QCOMPARE(obj->border()->top(), 20); QCOMPARE(obj->border()->right(), 30); @@ -311,7 +318,7 @@ void tst_qquickborderimage::sciSource() QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Round); QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Repeat); } else { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Error); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Error); } delete obj; @@ -443,7 +450,7 @@ void tst_qquickborderimage::statusChanges() obj->setSource(source); if (remote) server.sendDelayedItem(); - QTRY_VERIFY(obj->status() == finalStatus); + QTRY_COMPARE(obj->status(), finalStatus); QCOMPARE(spy.count(), emissions); delete obj; @@ -529,8 +536,8 @@ void tst_qquickborderimage::progressAndStatusChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QCOMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); qRegisterMetaType<QQuickBorderImage::Status>(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); @@ -539,33 +546,33 @@ void tst_qquickborderimage::progressAndStatusChanges() // Same file ctxt->setContextProperty("srcImage", testFileUrl("heart200.png")); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 0); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/heart200.png")); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); QTRY_VERIFY(progressSpy.count() > 1); QTRY_COMPARE(statusSpy.count(), 3); ctxt->setContextProperty("srcImage", ""); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Null); - QTRY_VERIFY(obj->progress() == 0.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Null); + QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(sourceSpy.count(), 3); QTRY_VERIFY(progressSpy.count() > 2); QTRY_COMPARE(statusSpy.count(), 4); diff --git a/tests/auto/quick/qquickdesignersupport/data/TestComponent.qml b/tests/auto/quick/qquickdesignersupport/data/TestComponent.qml new file mode 100644 index 0000000000..68f456af99 --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/TestComponent.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + width: 100 + height: 62 + + x: Math.max(0, 200) +} + diff --git a/tests/auto/quick/qquickdesignersupport/data/test.qml b/tests/auto/quick/qquickdesignersupport/data/test.qml new file mode 100644 index 0000000000..1d43cb3b7e --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/test.qml @@ -0,0 +1,39 @@ +import QtQuick 2.0 + +Rectangle { + objectName: "rootItem" + color: "white" + width: 800 + height: 600 + + TestComponent { + objectName: "testComponent" + + } + + Rectangle { + objectName: "rectangleItem" + gradient: Gradient { + + } + } + + Item { + id: item + objectName: "simpleItem" + property string testProperty: dynamicProperty + } + + states: [ + State { + name: "state01" + PropertyChanges { + target: item + width: 10 + } + }, + State { + name: "state02" + } + ] +} diff --git a/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro b/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro new file mode 100644 index 0000000000..af932d834b --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro @@ -0,0 +1,16 @@ +CONFIG += testcase +TARGET = tst_qquickdesignersupport +SOURCES += tst_qquickdesignersupport.cpp + +include (../../shared/util.pri) +include (../shared/util.pri) + +osx:CONFIG -= app_bundle + +TESTDATA = data/* + +QT += core-private gui-private qml-private quick-private testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +DISTFILES += \ + data/TestComponent.qml diff --git a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp new file mode 100644 index 0000000000..49535783c1 --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp @@ -0,0 +1,500 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlcomponent.h> +#include <QtQuick/qquickview.h> +#include <private/qquickdesignersupportitems_p.h> +#include <private/qquickdesignersupportmetainfo_p.h> +#include <private/qquickdesignersupportproperties_p.h> +#include <private/qquickdesignersupportstates_p.h> +#include <private/qquickdesignersupportpropertychanges_p.h> +#include <private/qquickitem_p.h> +#include <private/qquickstate_p.h> +#include <private/qquickstate_p_p.h> +#include <private/qquickstategroup_p.h> +#include <private/qquickpropertychanges_p.h> +#include <private/qquickrectangle_p.h> +#include "../../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; + +class tst_qquickdesignersupport : public QQmlDataTest +{ + Q_OBJECT +public: + tst_qquickdesignersupport() {} + +private slots: + void customData(); + void customDataBindings(); + void objectProperties(); + void dynamicProperty(); + void createComponent(); + void basicStates(); + void statesPropertyChanges(); + void testNotifyPropertyChangeCallBack(); + void testFixResourcePathsForObjectCallBack(); +}; + +void tst_qquickdesignersupport::customData() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QScopedPointer<QObject> newItemScopedPointer(QQuickDesignerSupportItems::createPrimitive(QLatin1String("QtQuick/Item"), 2, 6, view->rootContext())); + QObject *newItem = newItemScopedPointer.data(); + + QVERIFY(newItem); + QVERIFY(qobject_cast<QQuickItem*>(newItem)); + + QQuickDesignerSupportProperties::registerCustomData(newItem); + QVERIFY(QQuickDesignerSupportProperties::getResetValue(newItem, "width").isValid()); + int defaultWidth = QQuickDesignerSupportProperties::getResetValue(newItem, "width").toInt(); + QCOMPARE(defaultWidth, 0); + + newItem->setProperty("width", 200); + QCOMPARE(newItem->property("width").toInt(), 200); + + //Check if reseting property does work + QQuickDesignerSupportProperties::doResetProperty(newItem, view->rootContext(), "width"); + QCOMPARE(newItem->property("width").toInt(), 0); + + //Setting a binding on width + QQuickDesignerSupportProperties::setPropertyBinding(newItem, + view->engine()->contextForObject(newItem), + "width", + QLatin1String("Math.max(0, 200)")); + QCOMPARE(newItem->property("width").toInt(), 200); + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(newItem, + view->engine()->contextForObject(newItem), + "width", + 0)); + + //Check if reseting property does work after setting binding + QQuickDesignerSupportProperties::doResetProperty(newItem, view->rootContext(), "width"); + QCOMPARE(newItem->property("width").toInt(), 0); + + //No custom data available for the rootItem, because not registered by QQuickDesignerSupportProperties::registerCustomData + QVERIFY(!QQuickDesignerSupportProperties::getResetValue(rootItem, "width").isValid()); + + newItemScopedPointer.reset(); //Delete the item and check if item gets removed from the hash and an invalid QVariant is returned. + + QVERIFY(!QQuickDesignerSupportProperties::getResetValue(newItem, "width").isValid()); +} + +void tst_qquickdesignersupport::customDataBindings() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *testComponent = findItem<QQuickItem>(view->rootObject(), QLatin1String("testComponent")); + + QVERIFY(testComponent); + QQuickDesignerSupportProperties::registerCustomData(testComponent); + QQuickDesignerSupportProperties::hasValidResetBinding(testComponent, "x"); + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + + QCOMPARE(testComponent->property("x").toInt(), 200); + + + //Set property to 100 and ovveride the default binding + QQmlProperty property(testComponent, "x", view->engine()->contextForObject(testComponent)); + QVERIFY(property.write(100)); + QCOMPARE(testComponent->property("x").toInt(), 100); + + QVERIFY(!QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + + //Reset the binding to the default + QQuickDesignerSupportProperties::doResetProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x"); + + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + QCOMPARE(testComponent->property("x").toInt(), 200); + + + + //Set a different binding/expression + QQuickDesignerSupportProperties::setPropertyBinding(testComponent, + view->engine()->contextForObject(testComponent), + "x", + QLatin1String("Math.max(0, 300)")); + + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + + QCOMPARE(testComponent->property("x").toInt(), 300); + + + + //Reset the binding to the default + QQuickDesignerSupportProperties::doResetProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x"); + + + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + QCOMPARE(testComponent->property("x").toInt(), 200); +} + +void tst_qquickdesignersupport::objectProperties() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *rectangleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("rectangleItem")); + QVERIFY(rectangleItem); + + + //Read gradient property as QObject + int propertyIndex = rectangleItem->metaObject()->indexOfProperty("gradient"); + QVERIFY(propertyIndex > 0); + QMetaProperty metaProperty = rectangleItem->metaObject()->property(propertyIndex); + QVERIFY(metaProperty.isValid()); + + QVERIFY(QQuickDesignerSupportProperties::isPropertyQObject(metaProperty)); + + QObject*gradient = QQuickDesignerSupportProperties::readQObjectProperty(metaProperty, rectangleItem); + QVERIFY(gradient); + + + //The width property is not a QObject + propertyIndex = rectangleItem->metaObject()->indexOfProperty("width"); + QVERIFY(propertyIndex > 0); + metaProperty = rectangleItem->metaObject()->property(propertyIndex); + QVERIFY(metaProperty.isValid()); + QVERIFY(!QQuickDesignerSupportProperties::isPropertyQObject(metaProperty)); +} + +void tst_qquickdesignersupport::dynamicProperty() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *simpleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("simpleItem")); + + QVERIFY(simpleItem); + + QQuickDesignerSupportProperties::registerNodeInstanceMetaObject(simpleItem, view->engine()); + QQuickDesignerSupportProperties::getPropertyCache(simpleItem, view->engine()); + + QQuickDesignerSupportProperties::createNewDynamicProperty(simpleItem, view->engine(), QLatin1String("dynamicProperty")); + + QQmlProperty property(simpleItem, "dynamicProperty", view->engine()->contextForObject(simpleItem)); + QVERIFY(property.isValid()); + QVERIFY(property.write(QLatin1String("test"))); + + + QCOMPARE(property.read().toString(), QLatin1String("test")); + + //Force evalutation of all bindings + QQuickDesignerSupport::refreshExpressions(view->rootContext()); + + //Check if expression to dynamic property gets properly resolved + property = QQmlProperty(simpleItem, "testProperty", view->engine()->contextForObject(simpleItem)); + QVERIFY(property.isValid()); + QCOMPARE(property.read().toString(), QLatin1String("test")); +} + +void tst_qquickdesignersupport::createComponent() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QObject *testComponentObject = QQuickDesignerSupportItems::createComponent(testFileUrl("TestComponent.qml"), view->rootContext()); + QVERIFY(testComponentObject); + + QVERIFY(QQuickDesignerSupportMetaInfo::isSubclassOf(testComponentObject, "QtQuick/Item")); +} + +void tst_qquickdesignersupport::basicStates() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickStateGroup *stateGroup = QQuickItemPrivate::get(rootItem)->_states(); + + QVERIFY(stateGroup); + + QCOMPARE(stateGroup->states().count(), 2 ); + + QQuickState *state01 = stateGroup->states().first(); + QQuickState *state02 = stateGroup->states().last(); + + QVERIFY(state01); + QVERIFY(state02); + + QCOMPARE(state01->property("name").toString(), QLatin1String("state01")); + QCOMPARE(state02->property("name").toString(), QLatin1String("state02")); + + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QVERIFY(QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + + QQuickDesignerSupportStates::activateState(state02, view->rootContext()); + QVERIFY(QQuickDesignerSupportStates::isStateActive(state02, view->rootContext())); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + + QQuickDesignerSupportStates::deactivateState(state02); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); +} + +void tst_qquickdesignersupport::statesPropertyChanges() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *simpleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("simpleItem")); + + QVERIFY(simpleItem); + + QQuickStateGroup *stateGroup = QQuickItemPrivate::get(rootItem)->_states(); + + QVERIFY(stateGroup); + + QCOMPARE(stateGroup->states().count(), 2 ); + + QQuickState *state01 = stateGroup->states().first(); + QQuickState *state02 = stateGroup->states().last(); + + QVERIFY(state01); + QVERIFY(state02); + + QCOMPARE(state01->property("name").toString(), QLatin1String("state01")); + QCOMPARE(state02->property("name").toString(), QLatin1String("state02")); + + //PropertyChanges are parsed lazily + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QQuickDesignerSupportStates::deactivateState(state01); + + QQuickStatePrivate *statePrivate01 = static_cast<QQuickStatePrivate *>(QQuickStatePrivate::get(state01)); + + QCOMPARE(state01->operationCount(), 1); + + QCOMPARE(statePrivate01->operations.count(), 1); + + QQuickStateOperation *propertyChange = statePrivate01->operations.at(0).data(); + + QCOMPARE(QQuickDesignerSupportPropertyChanges::stateObject(propertyChange), state01); + + QQuickDesignerSupportPropertyChanges::changeValue(propertyChange, "width", 300); + + QCOMPARE(simpleItem->property("width").toInt(), 0); + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QCOMPARE(simpleItem->property("width").toInt(), 300); + QQuickDesignerSupportStates::deactivateState(state01); + QCOMPARE(simpleItem->property("width").toInt(), 0); + + //Set "base state value" in state1 using the revert list + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QQuickDesignerSupportStates::changeValueInRevertList(state01, simpleItem, "width", 200); + QCOMPARE(simpleItem->property("width").toInt(), 300); + QQuickDesignerSupportStates::deactivateState(state01); + QCOMPARE(simpleItem->property("width").toInt(), 200); + + + //Create new PropertyChanges + QQuickPropertyChanges *newPropertyChange = new QQuickPropertyChanges(); + newPropertyChange->setParent(state01); + QQuickStatePrivate::operations_append(&state01->changes(), newPropertyChange); + + newPropertyChange->setObject(rootItem); + + QQuickDesignerSupportPropertyChanges::attachToState(newPropertyChange); + + QCOMPARE(rootItem, QQuickDesignerSupportPropertyChanges::targetObject(newPropertyChange)); + + QCOMPARE(state01->operationCount(), 2); + QCOMPARE(statePrivate01->operations.count(), 2); + + QCOMPARE(QQuickDesignerSupportPropertyChanges::stateObject(newPropertyChange), state01); + + //Set color for rootItem in state1 + QQuickDesignerSupportPropertyChanges::changeValue(newPropertyChange, "color", QColor(Qt::red)); + + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QCOMPARE(rootItem->property("color").value<QColor>(), QColor(Qt::red)); + QQuickDesignerSupportStates::deactivateState(state01); + QCOMPARE(rootItem->property("color").value<QColor>(), QColor(Qt::white)); + + QQuickDesignerSupportPropertyChanges::removeProperty(newPropertyChange, "color"); + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QCOMPARE(rootItem->property("color").value<QColor>(), QColor(Qt::white)); + +} + +static QObject * s_object = 0; +static QQuickDesignerSupport::PropertyName s_propertyName; + +static void notifyPropertyChangeCallBackFunction(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName) +{ + s_object = object; + s_propertyName = propertyName; +} + +static void (*notifyPropertyChangeCallBackPointer)(QObject *, const QQuickDesignerSupport::PropertyName &) = ¬ifyPropertyChangeCallBackFunction; + + +void tst_qquickdesignersupport::testNotifyPropertyChangeCallBack() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickRectangle *rectangle = static_cast<QQuickRectangle *>(rootItem); + QVERIFY(rectangle); + + QQuickDesignerSupportProperties::registerNodeInstanceMetaObject(rectangle, view->engine()); + + QQuickGradient *gradient = new QQuickGradient(rectangle); + + QQuickDesignerSupportMetaInfo::registerNotifyPropertyChangeCallBack(notifyPropertyChangeCallBackPointer); + + rectangle->setProperty("gradient", QVariant::fromValue<QQuickGradient *>(gradient)); + + QVERIFY(s_object); + QCOMPARE(s_object, rootItem); + QCOMPARE(s_propertyName, QQuickDesignerSupport::PropertyName("gradient")); +} + +static void fixResourcePathsForObjectCallBackFunction(QObject *object) +{ + s_object = object; +} + +static void (*fixResourcePathsForObjectCallBackPointer)(QObject *) = &fixResourcePathsForObjectCallBackFunction; + +void tst_qquickdesignersupport::testFixResourcePathsForObjectCallBack() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + s_object = 0; + + QQuickDesignerSupportItems::registerFixResourcePathsForObjectCallBack(fixResourcePathsForObjectCallBackPointer); + + QQuickItem *simpleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("simpleItem")); + + QVERIFY(simpleItem); + + QQuickDesignerSupportItems::tweakObjects(simpleItem); + + //Check that the fixResourcePathsForObjectCallBack was called on simpleItem + QCOMPARE(simpleItem , s_object); +} + + +QTEST_MAIN(tst_qquickdesignersupport) + +#include "tst_qquickdesignersupport.moc" diff --git a/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp b/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp index 40bd6624f0..3656bb8aab 100644 --- a/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp +++ b/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp @@ -59,11 +59,11 @@ private: QQmlProperty testProp(item, propertyName); QPropertyAnimation animation(item, propertyName, this); animation.setEndValue(toValue); - QVERIFY(animation.targetObject() == item); - QVERIFY(animation.propertyName() == propertyName); - QVERIFY(animation.endValue().value<T>() == toValue); + QCOMPARE(animation.targetObject(), item); + QCOMPARE(animation.propertyName(), propertyName); + QCOMPARE(animation.endValue().value<T>(), toValue); animation.start(); - QVERIFY(animation.state() == QAbstractAnimation::Running); + QCOMPARE(animation.state(), QAbstractAnimation::Running); QTest::qWait(animation.duration()); QTRY_COMPARE(testProp.read().value<T>(), toValue); } diff --git a/tests/auto/quick/qquickflickable/BLACKLIST b/tests/auto/quick/qquickflickable/BLACKLIST index 92ed8708de..647bf819a5 100644 --- a/tests/auto/quick/qquickflickable/BLACKLIST +++ b/tests/auto/quick/qquickflickable/BLACKLIST @@ -10,7 +10,7 @@ osx-10.10 osx-10.10 [stopAtBounds] osx-10.10 -windows 32bit developer-build +windows developer-build [returnToBounds] osx [pressWhileFlicking] diff --git a/tests/auto/quick/qquickflickable/data/movementSignals.qml b/tests/auto/quick/qquickflickable/data/movementSignals.qml new file mode 100644 index 0000000000..581e882139 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/movementSignals.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 + +Flickable { + width: 400; height: 400 + contentWidth: 400; contentHeight: 1200 + + property string signalString + + Rectangle { + width: 400; height: 400 + color: "red" + } + Rectangle { + y: 400; width: 400; height: 400 + color: "yellow" + } + Rectangle { + y: 800; width: 400; height: 400 + color: "green" + } + + onMovementStarted: signalString += "ms" + onMovementEnded: signalString += "me" + onFlickStarted: signalString += "fs" + onFlickEnded: signalString += "fe" +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 7d08c3c81e..eee7ffe560 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -91,6 +91,7 @@ private slots: void stopAtBounds_data(); void nestedMouseAreaUsingTouch(); void pressDelayWithLoader(); + void movementFromProgrammaticFlick(); void cleanup(); private: @@ -195,9 +196,9 @@ void tst_qquickflickable::properties() QCOMPARE(obj->pressDelay(), 200); QCOMPARE(obj->maximumFlickVelocity(), 2000.); - QVERIFY(obj->property("ok").toBool() == false); + QVERIFY(!obj->property("ok").toBool()); QMetaObject::invokeMethod(obj, "check"); - QVERIFY(obj->property("ok").toBool() == true); + QVERIFY(obj->property("ok").toBool()); delete obj; } @@ -211,28 +212,28 @@ void tst_qquickflickable::boundsBehavior() QSignalSpy spy(flickable, SIGNAL(boundsBehaviorChanged())); QVERIFY(flickable); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::StopAtBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::StopAtBounds); flickable->setBoundsBehavior(QQuickFlickable::DragAndOvershootBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::DragAndOvershootBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::DragAndOvershootBounds); QCOMPARE(spy.count(),1); flickable->setBoundsBehavior(QQuickFlickable::DragAndOvershootBounds); QCOMPARE(spy.count(),1); flickable->setBoundsBehavior(QQuickFlickable::DragOverBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::DragOverBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::DragOverBounds); QCOMPARE(spy.count(),2); flickable->setBoundsBehavior(QQuickFlickable::DragOverBounds); QCOMPARE(spy.count(),2); flickable->setBoundsBehavior(QQuickFlickable::StopAtBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::StopAtBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::StopAtBounds); QCOMPARE(spy.count(),3); flickable->setBoundsBehavior(QQuickFlickable::StopAtBounds); QCOMPARE(spy.count(),3); flickable->setBoundsBehavior(QQuickFlickable::OvershootBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::OvershootBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::OvershootBounds); QCOMPARE(spy.count(),4); flickable->setBoundsBehavior(QQuickFlickable::OvershootBounds); QCOMPARE(spy.count(),4); @@ -249,7 +250,7 @@ void tst_qquickflickable::rebound() QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -295,11 +296,11 @@ void tst_qquickflickable::rebound() // flick and trigger the transition multiple times // (moving signals are emitted as soon as the first transition starts) - flick(window.data(), QPoint(20,20), QPoint(120,120), 200); // both x and y will bounce back - flick(window.data(), QPoint(20,120), QPoint(120,20), 200); // only x will bounce back + flick(window.data(), QPoint(20,20), QPoint(120,120), 50); // both x and y will bounce back + flick(window.data(), QPoint(20,120), QPoint(120,20), 50); // only x will bounce back QVERIFY(flickable->isMoving()); - QVERIFY(window->rootObject()->property("transitionsStarted").toInt() >= 1); + QTRY_VERIFY(window->rootObject()->property("transitionsStarted").toInt() >= 1); QCOMPARE(hMoveSpy.count(), 1); QCOMPARE(vMoveSpy.count(), 1); QCOMPARE(movementStartedSpy.count(), 1); @@ -388,7 +389,7 @@ void tst_qquickflickable::pressDelay() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -406,13 +407,13 @@ void tst_qquickflickable::pressDelay() QQuickItem *mouseArea = window->rootObject()->findChild<QQuickItem*>("mouseArea"); QSignalSpy clickedSpy(mouseArea, SIGNAL(clicked(QQuickMouseEvent*))); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // The press should not occur immediately - QVERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); // But, it should occur eventually - QTRY_VERIFY(mouseArea->property("pressed").toBool() == true); + QTRY_VERIFY(mouseArea->property("pressed").toBool()); QCOMPARE(clickedSpy.count(),0); @@ -427,10 +428,10 @@ void tst_qquickflickable::pressDelay() // Test a quick tap within the pressDelay timeout clickedSpy.clear(); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(180, 180)); + moveAndPress(window.data(), QPoint(180, 180)); // The press should not occur immediately - QVERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); QCOMPARE(clickedSpy.count(),0); @@ -444,16 +445,16 @@ void tst_qquickflickable::pressDelay() // QTBUG-31168 - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 110)); + moveAndPress(window.data(), QPoint(150, 110)); // The press should not occur immediately - QVERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(150, 190)); // As we moved pass the drag threshold, we should never receive the press - QVERIFY(mouseArea->property("pressed").toBool() == false); - QTRY_VERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); + QTRY_VERIFY(!mouseArea->property("pressed").toBool()); // On release the clicked signal should *not* be emitted QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 190)); @@ -469,7 +470,7 @@ void tst_qquickflickable::nestedPressDelay() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -478,44 +479,44 @@ void tst_qquickflickable::nestedPressDelay() QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable"); QVERIFY(inner != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); - QVERIFY(inner->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); + QVERIFY(!inner->property("pressed").toBool()); // The inner pressDelay will prevail (50ms, vs. 10sec) // QTRY_VERIFY() has 5sec timeout, so will timeout well within 10sec. - QTRY_VERIFY(outer->property("pressed").toBool() == true); + QTRY_VERIFY(outer->property("pressed").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); // Dragging inner Flickable should work - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(80, 150)); + moveAndPress(window.data(), QPoint(80, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); - QVERIFY(inner->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); + QVERIFY(!inner->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(60, 150)); QTest::mouseMove(window.data(), QPoint(40, 150)); QTest::mouseMove(window.data(), QPoint(20, 150)); - QVERIFY(inner->property("moving").toBool() == true); - QVERIFY(outer->property("moving").toBool() == false); + QVERIFY(inner->property("moving").toBool()); + QVERIFY(!outer->property("moving").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(20, 150)); // Dragging the MouseArea in the inner Flickable should move the inner Flickable - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(130, 150)); QTest::mouseMove(window.data(), QPoint(110, 150)); QTest::mouseMove(window.data(), QPoint(90, 150)); - QVERIFY(outer->property("moving").toBool() == false); - QVERIFY(inner->property("moving").toBool() == true); + QVERIFY(!outer->property("moving").toBool()); + QVERIFY(inner->property("moving").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(90, 150)); } @@ -529,7 +530,7 @@ void tst_qquickflickable::nestedClickThenFlick() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -538,29 +539,29 @@ void tst_qquickflickable::nestedClickThenFlick() QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable"); QVERIFY(inner != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); - QTRY_VERIFY(outer->property("pressed").toBool() == true); + QVERIFY(!outer->property("pressed").toBool()); + QTRY_VERIFY(outer->property("pressed").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); - QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); // Dragging inner Flickable should work - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(80, 150)); + moveAndPress(window.data(), QPoint(80, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(80, 148)); QTest::mouseMove(window.data(), QPoint(80, 140)); QTest::mouseMove(window.data(), QPoint(80, 120)); QTest::mouseMove(window.data(), QPoint(80, 100)); - QVERIFY(outer->property("moving").toBool() == false); - QVERIFY(inner->property("moving").toBool() == true); + QVERIFY(!outer->property("moving").toBool()); + QVERIFY(inner->property("moving").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(80, 100)); } @@ -628,6 +629,8 @@ void tst_qquickflickable::returnToBounds() window->rootContext()->setContextProperty("setRebound", setRebound); window->setSource(testFileUrl("resize.qml")); + window->show(); + QTest::qWaitForWindowActive(window.data()); QVERIFY(window->rootObject() != 0); QQuickFlickable *obj = findItem<QQuickFlickable>(window->rootObject(), "flick"); @@ -671,7 +674,7 @@ void tst_qquickflickable::wheel() QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("wheel.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flick"); @@ -685,10 +688,10 @@ void tst_qquickflickable::wheel() } QTRY_VERIFY(flick->contentY() > 0); - QVERIFY(flick->contentX() == 0); + QCOMPARE(flick->contentX(), qreal(0)); flick->setContentY(0); - QVERIFY(flick->contentY() == 0); + QCOMPARE(flick->contentY(), qreal(0)); { QPoint pos(200, 200); @@ -699,7 +702,7 @@ void tst_qquickflickable::wheel() } QTRY_VERIFY(flick->contentX() > 0); - QVERIFY(flick->contentY() == 0); + QCOMPARE(flick->contentY(), qreal(0)); } void tst_qquickflickable::movingAndFlicking_data() @@ -740,7 +743,7 @@ void tst_qquickflickable::movingAndFlicking() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -903,7 +906,7 @@ void tst_qquickflickable::movingAndDragging() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -922,7 +925,7 @@ void tst_qquickflickable::movingAndDragging() QSignalSpy moveEndSpy(flickable, SIGNAL(movementEnded())); // start the drag - QTest::mousePress(window.data(), Qt::LeftButton, 0, moveFrom); + moveAndPress(window.data(), moveFrom); QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack); QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack*2); QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack*3); @@ -962,7 +965,7 @@ void tst_qquickflickable::movingAndDragging() // Don't test whether moving finished because a flick could occur // wait for any motion to end - QTRY_VERIFY(flickable->isMoving() == false); + QTRY_VERIFY(!flickable->isMoving()); QVERIFY(!flickable->isMovingHorizontally()); QVERIFY(!flickable->isMovingVertically()); @@ -998,7 +1001,7 @@ void tst_qquickflickable::movingAndDragging() flickable->setContentX(0); flickable->setContentY(0); QTRY_VERIFY(!flickable->isMoving()); - QTest::mousePress(window.data(), Qt::LeftButton, 0, moveFrom); + moveAndPress(window.data(), moveFrom); QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack); QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack*2); QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack*3); @@ -1072,7 +1075,7 @@ void tst_qquickflickable::flickOnRelease() QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("flickable03.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -1085,14 +1088,14 @@ void tst_qquickflickable::flickOnRelease() // underlying drivers will hopefully provide a pre-calculated velocity // (based on more data than what the UI gets), thus making this use case // working even with small movements. - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 300)); + moveAndPress(window.data(), QPoint(50, 300)); QTest::mouseMove(window.data(), QPoint(50, 10), 10); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 10), 10); QCOMPARE(vFlickSpy.count(), 1); // wait for any motion to end - QTRY_VERIFY(flickable->isMoving() == false); + QTRY_VERIFY(!flickable->isMoving()); #ifdef Q_OS_MAC QEXPECT_FAIL("", "QTBUG-26094 stopping on a full pixel doesn't work on OS X", Continue); @@ -1109,7 +1112,7 @@ void tst_qquickflickable::pressWhileFlicking() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -1159,27 +1162,27 @@ void tst_qquickflickable::disabled() QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("disabled.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flickable"); QVERIFY(flick != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 90)); + moveAndPress(window.data(), QPoint(50, 90)); QTest::mouseMove(window.data(), QPoint(50, 80)); QTest::mouseMove(window.data(), QPoint(50, 70)); QTest::mouseMove(window.data(), QPoint(50, 60)); - QVERIFY(flick->isMoving() == false); + QVERIFY(!flick->isMoving()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 60)); // verify that mouse clicks on other elements still work (QTBUG-20584) - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 10)); + moveAndPress(window.data(), QPoint(50, 10)); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 10)); - QTRY_VERIFY(window->rootObject()->property("clicked").toBool() == true); + QTRY_VERIFY(window->rootObject()->property("clicked").toBool()); } void tst_qquickflickable::flickVelocity() @@ -1190,7 +1193,7 @@ void tst_qquickflickable::flickVelocity() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -1199,12 +1202,12 @@ void tst_qquickflickable::flickVelocity() // flick up flick(window.data(), QPoint(20,190), QPoint(20, 50), 200); QVERIFY(flickable->verticalVelocity() > 0.0); - QTRY_VERIFY(flickable->verticalVelocity() == 0.0); + QTRY_COMPARE(flickable->verticalVelocity(), 0.0); // flick down flick(window.data(), QPoint(20,10), QPoint(20, 140), 200); QTRY_VERIFY(flickable->verticalVelocity() < 0.0); - QTRY_VERIFY(flickable->verticalVelocity() == 0.0); + QTRY_COMPARE(flickable->verticalVelocity(), 0.0); #ifdef Q_OS_MAC QSKIP("boost doesn't work on OS X"); @@ -1223,7 +1226,7 @@ void tst_qquickflickable::flickVelocity() // Flick in opposite direction -> boost cancelled. flick(window.data(), QPoint(20,10), QPoint(20, 340), 200); QTRY_VERIFY(flickable->verticalVelocity() < 0.0); - QVERIFY(fp->flickBoost == 1.0); + QCOMPARE(fp->flickBoost, 1.0); } void tst_qquickflickable::margins() @@ -1235,7 +1238,7 @@ void tst_qquickflickable::margins() QQuickViewTestUtil::moveMouseAway(window.data()); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QQuickItem *root = window->rootObject(); QVERIFY(root); QQuickFlickable *obj = qobject_cast<QQuickFlickable*>(root); @@ -1298,13 +1301,13 @@ void tst_qquickflickable::cancelOnMouseGrab() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); QVERIFY(flickable != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(10, 10)); + moveAndPress(window.data(), QPoint(10, 10)); // drag out of bounds QTest::mouseMove(window.data(), QPoint(50, 50)); QTest::mouseMove(window.data(), QPoint(100, 100)); @@ -1324,7 +1327,7 @@ void tst_qquickflickable::cancelOnMouseGrab() QTRY_VERIFY(!flickable->isMoving()); QTRY_VERIFY(!flickable->isDragging()); - QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 10)); + moveAndRelease(window.data(), QPoint(50, 10)); } @@ -1336,41 +1339,41 @@ void tst_qquickflickable::clickAndDragWhenTransformed() QQuickViewTestUtil::centerOnScreen(view.data()); QQuickViewTestUtil::moveMouseAway(view.data()); view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view.data())); + QVERIFY(QTest::qWaitForWindowActive(view.data())); QVERIFY(view->rootObject() != 0); QQuickFlickable *flickable = view->rootObject()->findChild<QQuickFlickable*>("flickable"); QVERIFY(flickable != 0); // click outside child rect - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(190, 190)); + moveAndPress(view.data(), QPoint(190, 190)); QTRY_COMPARE(flickable->property("itemPressed").toBool(), false); QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(190, 190)); // click inside child rect - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(200, 200)); + moveAndPress(view.data(), QPoint(200, 200)); QTRY_COMPARE(flickable->property("itemPressed").toBool(), true); QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(200, 200)); const int threshold = qApp->styleHints()->startDragDistance(); // drag outside bounds - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(160, 160)); + moveAndPress(view.data(), QPoint(160, 160)); QTest::qWait(10); QTest::mouseMove(view.data(), QPoint(160 + threshold * 2, 160)); QTest::mouseMove(view.data(), QPoint(160 + threshold * 3, 160)); QCOMPARE(flickable->isDragging(), false); QCOMPARE(flickable->property("itemPressed").toBool(), false); - QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(180, 160)); + moveAndRelease(view.data(), QPoint(180, 160)); // drag inside bounds - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(200, 140)); + moveAndPress(view.data(), QPoint(200, 140)); QTest::qWait(10); QTest::mouseMove(view.data(), QPoint(200 + threshold * 2, 140)); QTest::mouseMove(view.data(), QPoint(200 + threshold * 3, 140)); QCOMPARE(flickable->isDragging(), true); QCOMPARE(flickable->property("itemPressed").toBool(), false); - QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(220, 140)); + moveAndRelease(view.data(), QPoint(220, 140)); } void tst_qquickflickable::flickTwiceUsingTouches() @@ -1459,7 +1462,7 @@ void tst_qquickflickable::nestedStopAtBounds() QQuickViewTestUtil::moveMouseAway(&view); view.show(); view.requestActivate(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()); QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(view.rootObject()); @@ -1489,7 +1492,7 @@ void tst_qquickflickable::nestedStopAtBounds() int &axis = transpose ? position.ry() : position.rx(); // drag toward the aligned boundary. Outer flickable dragged. - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? threshold * 2 : -threshold * 2; QTest::mouseMove(&view, position); @@ -1507,7 +1510,7 @@ void tst_qquickflickable::nestedStopAtBounds() outer->setContentY(50); // drag away from the aligned boundary. Inner flickable dragged. - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? -threshold * 2 : threshold * 2; QTest::mouseMove(&view, position); @@ -1526,7 +1529,7 @@ void tst_qquickflickable::nestedStopAtBounds() inner->setContentHeight(inner->height() - margin); // Drag inner with equal size and contentSize - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? -threshold * 2 : threshold * 2; QTest::mouseMove(&view, position); @@ -1543,7 +1546,7 @@ void tst_qquickflickable::nestedStopAtBounds() inner->setContentHeight(inner->height() - 100); // Drag inner with size greater than contentSize - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? -threshold * 2 : threshold * 2; QTest::mouseMove(&view, position); @@ -1583,7 +1586,7 @@ void tst_qquickflickable::stopAtBounds() QQuickViewTestUtil::moveMouseAway(&view); view.show(); view.requestActivate(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(view.rootObject()); @@ -1601,7 +1604,7 @@ void tst_qquickflickable::stopAtBounds() int &axis = transpose ? position.ry() : position.rx(); // drag away from the aligned boundary. View should not move - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); for (int i = 0; i < 3; ++i) { axis += invert ? -threshold : threshold; @@ -1649,12 +1652,14 @@ void tst_qquickflickable::stopAtBounds() } else { flickable->setContentX(invert ? 100 : 0); } + + QSignalSpy flickSignal(flickable, SIGNAL(flickingChanged())); if (invert) flick(&view, QPoint(20,20), QPoint(120,120), 100); else flick(&view, QPoint(120,120), QPoint(20,20), 100); - QVERIFY(flickable->isFlicking()); + QVERIFY(flickSignal.count() > 0); if (transpose) { if (invert) QTRY_COMPARE(flickable->isAtYBeginning(), true); @@ -1707,14 +1712,33 @@ void tst_qquickflickable::pressDelayWithLoader() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); // do not crash - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); } +// QTBUG-34507 +void tst_qquickflickable::movementFromProgrammaticFlick() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("movementSignals.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickViewTestUtil::centerOnScreen(window.data()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable != 0); + + // verify that the signals for movement and flicking are called in the right order + flickable->flick(0, -1000); + QTRY_COMPARE(flickable->property("signalString").toString(), QString("msfsfeme")); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" diff --git a/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp b/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp index 76bf509cf0..2eb8942eee 100644 --- a/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp +++ b/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp @@ -108,11 +108,11 @@ void tst_qquickflipable::flipFlipable() QQmlComponent c(&engine, testFileUrl("flip-flipable.qml")); QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create()); QVERIFY(obj != 0); - QVERIFY(obj->side() == QQuickFlipable::Front); + QCOMPARE(obj->side(), QQuickFlipable::Front); obj->setProperty("flipped", QVariant(true)); - QTRY_VERIFY(obj->side() == QQuickFlipable::Back); - QTRY_VERIFY(obj->side() == QQuickFlipable::Front); - QTRY_VERIFY(obj->side() == QQuickFlipable::Back); + QTRY_COMPARE(obj->side(), QQuickFlipable::Back); + QTRY_COMPARE(obj->side(), QQuickFlipable::Front); + QTRY_COMPARE(obj->side(), QQuickFlipable::Back); delete obj; } diff --git a/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp b/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp index 98f85af92e..4b377f92d6 100644 --- a/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp +++ b/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp @@ -81,27 +81,27 @@ void tst_qquickfocusscope::basic() view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QVERIFY(view->isTopLevel()); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); QTest::qWait(50); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == true); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Down); QTest::qWait(50); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == true); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); delete view; } @@ -126,13 +126,13 @@ void tst_qquickfocusscope::nested() view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == true); - QVERIFY(item3->hasActiveFocus() == true); - QVERIFY(item4->hasActiveFocus() == true); - QVERIFY(item5->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); + QVERIFY(item4->hasActiveFocus()); + QVERIFY(item5->hasActiveFocus()); delete view; } @@ -153,24 +153,24 @@ void tst_qquickfocusscope::noFocus() view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); - QVERIFY(view == qGuiApp->focusWindow()); + QCOMPARE(view, qGuiApp->focusWindow()); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); delete view; } @@ -194,33 +194,33 @@ void tst_qquickfocusscope::textEdit() QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QTRY_COMPARE(view, qGuiApp->focusWindow()); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == true); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == true); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); delete view; } @@ -246,30 +246,30 @@ void tst_qquickfocusscope::forceFocus() view->show(); view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); - QVERIFY(item4->hasActiveFocus() == false); - QVERIFY(item5->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); + QVERIFY(!item4->hasActiveFocus()); + QVERIFY(!item5->hasActiveFocus()); QTest::keyClick(view, Qt::Key_4); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); - QVERIFY(item4->hasActiveFocus() == false); - QVERIFY(item5->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); + QVERIFY(!item4->hasActiveFocus()); + QVERIFY(!item5->hasActiveFocus()); QTest::keyClick(view, Qt::Key_5); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == true); - QVERIFY(item4->hasActiveFocus() == false); - QVERIFY(item5->hasActiveFocus() == true); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); + QVERIFY(!item4->hasActiveFocus()); + QVERIFY(item5->hasActiveFocus()); delete view; } @@ -283,13 +283,13 @@ void tst_qquickfocusscope::noParentFocus() view->show(); view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); - QVERIFY(view->rootObject()->property("focus1") == false); - QVERIFY(view->rootObject()->property("focus2") == false); - QVERIFY(view->rootObject()->property("focus3") == true); - QVERIFY(view->rootObject()->property("focus4") == true); - QVERIFY(view->rootObject()->property("focus5") == true); + QVERIFY(!view->rootObject()->property("focus1").toBool()); + QVERIFY(!view->rootObject()->property("focus2").toBool()); + QVERIFY(view->rootObject()->property("focus3").toBool()); + QVERIFY(view->rootObject()->property("focus4").toBool()); + QVERIFY(view->rootObject()->property("focus5").toBool()); delete view; } @@ -312,7 +312,7 @@ void tst_qquickfocusscope::signalEmission() view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QVariant blue(QColor("blue")); QVariant red(QColor("red")); @@ -362,7 +362,7 @@ void tst_qquickfocusscope::qtBug13380() QVERIFY(QTest::qWaitForWindowExposed(view)); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QVERIFY(view->rootObject()->property("noFocus").toBool()); view->rootObject()->setProperty("showRect", true); @@ -379,7 +379,7 @@ void tst_qquickfocusscope::forceActiveFocus() view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowExposed(view)); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QQuickItem *rootObject = view->rootObject(); QVERIFY(rootObject); @@ -532,7 +532,7 @@ void tst_qquickfocusscope::canvasFocus() view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); - QVERIFY(view == qGuiApp->focusWindow()); + QCOMPARE(view, qGuiApp->focusWindow()); // Now the window has focus, active focus given to item1 QCOMPARE(rootItem->hasFocus(), true); @@ -558,7 +558,7 @@ void tst_qquickfocusscope::canvasFocus() alternateView.show(); alternateView.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&alternateView)); - QVERIFY(QGuiApplication::focusWindow() == &alternateView); + QCOMPARE(QGuiApplication::focusWindow(), &alternateView); QCOMPARE(rootItem->hasFocus(), false); QCOMPARE(rootItem->hasActiveFocus(), false); @@ -604,7 +604,7 @@ void tst_qquickfocusscope::canvasFocus() view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); - QVERIFY(QGuiApplication::focusWindow() == view); + QCOMPARE(QGuiApplication::focusWindow(), view); QCOMPARE(rootItem->hasFocus(), true); QCOMPARE(rootItem->hasActiveFocus(), true); diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp index a084c86a95..f4f1e290c1 100644 --- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp +++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp @@ -85,7 +85,7 @@ void tst_qquickfontloader::noFont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); QCOMPARE(fontObject->source(), QUrl("")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Null); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Null); delete fontObject; } @@ -100,7 +100,7 @@ void tst_qquickfontloader::namedFont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->source(), QUrl("")); QCOMPARE(fontObject->name(), QString("Helvetica")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::localFont() @@ -113,7 +113,7 @@ void tst_qquickfontloader::localFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::failLocalFont() @@ -127,7 +127,7 @@ void tst_qquickfontloader::failLocalFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Error); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Error); } void tst_qquickfontloader::webFont() @@ -141,7 +141,7 @@ void tst_qquickfontloader::webFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::redirWebFont() @@ -157,7 +157,7 @@ void tst_qquickfontloader::redirWebFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::failWebFont() @@ -172,7 +172,7 @@ void tst_qquickfontloader::failWebFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Error); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Error); } void tst_qquickfontloader::changeFont() @@ -189,26 +189,26 @@ void tst_qquickfontloader::changeFont() QSignalSpy nameSpy(fontObject, SIGNAL(nameChanged())); QSignalSpy statusSpy(fontObject, SIGNAL(statusChanged())); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 0); QCOMPARE(statusSpy.count(), 0); QTRY_COMPARE(fontObject->name(), QString("OCRA")); ctxt->setContextProperty("font", server.urlString("/daniel.ttf")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Loading); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Loading); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 1); QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("Daniel")); ctxt->setContextProperty("font", testFileUrl("tarzeau_ocr_a.ttf")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 2); QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("OCRA")); ctxt->setContextProperty("font", server.urlString("/daniel.ttf")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 3); QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("Daniel")); @@ -224,7 +224,7 @@ void tst_qquickfontloader::changeFontSourceViaState() QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(qvariant_cast<QObject *>(window.rootObject()->property("fontloader"))); QVERIFY(fontObject != 0); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); @@ -236,7 +236,7 @@ void tst_qquickfontloader::changeFontSourceViaState() QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); QEXPECT_FAIL("", "QTBUG-20268", Abort); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(window.rootObject()->property("name").toString(), QString("Tahoma")); } diff --git a/tests/auto/quick/qquickgridview/BLACKLIST b/tests/auto/quick/qquickgridview/BLACKLIST new file mode 100644 index 0000000000..9eb9940aa5 --- /dev/null +++ b/tests/auto/quick/qquickgridview/BLACKLIST @@ -0,0 +1,2 @@ +[snapOneRow:horizontal, right to left] +windows diff --git a/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml b/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml new file mode 100644 index 0000000000..3f8246bafc --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml @@ -0,0 +1,47 @@ +import QtQuick 2.1 + +Item { + width: 400 + height: 600 + function takeOne() + { + gridView.model.remove(2) + } + function takeThree() + { + gridView.model.remove(4) + gridView.model.remove(2) + gridView.model.remove(0) + } + function takeAll() + { + gridView.model.clear() + } + + GridView { + id: gridView + + property bool useDelayRemove + + height: parent.height + width: 400 + cellWidth: width/2 + model: ListModel { + ListElement { name: "A" } + ListElement { name: "B" } + ListElement { name: "C" } + ListElement { name: "D" } + ListElement { name: "E" } + } + delegate: Text { + id: wrapper + height: 100 + text: index + gridView.count + GridView.delayRemove: gridView.useDelayRemove + GridView.onRemove: SequentialAnimation { + PauseAnimation { duration: wrapper.GridView.delayRemove ? 100 : 0 } + PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: false } + } + } + } +} diff --git a/tests/auto/quick/qquickgridview/data/qtbug45640.qml b/tests/auto/quick/qquickgridview/data/qtbug45640.qml new file mode 100644 index 0000000000..6973773432 --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/qtbug45640.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +GridView { + id: gridView + width: 400; height: 400 + cellHeight: 100 + cellWidth: 100 + model: 32 + + topMargin: 50 + snapMode: GridView.SnapToRow + preferredHighlightBegin: 50 + preferredHighlightEnd: 50 + highlightRangeMode: GridView.ApplyRange + + delegate: Rectangle { + width: 100 + height: 100 + color: index % 2 == 0 ? "#FFFF00" : "#0000FF" + } + + highlight: Rectangle { color: "red"; z: 2 } + highlightMoveDuration: 1000 +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 9472407e01..87042ca7ba 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -206,6 +206,11 @@ private slots: void jsArrayChange(); + void contentHeightWithDelayRemove_data(); + void contentHeightWithDelayRemove(); + + void QTBUG_45640(); + private: QList<int> toIntList(const QVariantList &list); void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes); @@ -373,7 +378,7 @@ void tst_QQuickGridView::items() ctxt->setContextProperty("testModel", &model2); int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); - QTRY_VERIFY(itemCount == 0); + QTRY_COMPARE(itemCount, 0); delete window; } @@ -473,8 +478,8 @@ void tst_QQuickGridView::inserted_basic() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } for (int i = model.count(); i < 30; ++i) @@ -485,7 +490,7 @@ void tst_QQuickGridView::inserted_basic() // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTRY_VERIFY(gridview->contentY() == 120); + QTRY_COMPARE(gridview->contentY(), qreal(120)); delete window; } @@ -815,8 +820,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove first item (which is the current item); @@ -836,8 +841,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove items not visible @@ -849,8 +854,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove items before visible @@ -867,8 +872,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 6; i < 18; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove currentIndex @@ -886,8 +891,8 @@ void tst_QQuickGridView::removed_basic() itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // remove item outside current view. @@ -895,7 +900,7 @@ void tst_QQuickGridView::removed_basic() gridview->setContentY(240); model.removeItem(30); - QTRY_VERIFY(gridview->currentIndex() == 31); + QTRY_COMPARE(gridview->currentIndex(), 31); // remove current item beyond visible items. gridview->setCurrentIndex(20); @@ -912,7 +917,7 @@ void tst_QQuickGridView::removed_basic() model.removeItem(6); QTRY_COMPARE(gridview->currentIndex(), 7); - QTRY_VERIFY(gridview->currentItem() == oldCurrent); + QTRY_COMPARE(gridview->currentItem(), oldCurrent); delete window; } @@ -1211,7 +1216,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() for (int i = 0; i < model.count() && i < itemCount; ++i) { QTRY_VERIFY(findItem<QQuickItem>(contentItem, "wrapper", i)); QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); - QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); QTRY_VERIFY(item->y() == (i/3)*60 + newTopContentY); } @@ -1249,10 +1254,10 @@ void tst_QQuickGridView::clear() model.clear(); gridview->forceLayout(); - QVERIFY(gridview->count() == 0); - QVERIFY(gridview->currentItem() == 0); - QVERIFY(gridview->contentY() == 0); - QVERIFY(gridview->currentIndex() == -1); + QCOMPARE(gridview->count(), 0); + QVERIFY(!gridview->currentItem()); + QCOMPARE(gridview->contentY(), qreal(0)); + QCOMPARE(gridview->currentIndex(), -1); QCOMPARE(gridview->contentHeight(), 0.0); // confirm sanity when adding an item to cleared list @@ -1260,7 +1265,7 @@ void tst_QQuickGridView::clear() gridview->forceLayout(); QTRY_COMPARE(gridview->count(), 1); QVERIFY(gridview->currentItem() != 0); - QVERIFY(gridview->currentIndex() == 0); + QCOMPARE(gridview->currentIndex(), 0); delete window; } @@ -1799,7 +1804,7 @@ void tst_QQuickGridView::swapWithFirstItem() // ensure content position is stable gridview->setContentY(0); model.moveItem(10, 0); - QTRY_VERIFY(gridview->contentY() == 0); + QTRY_COMPARE(gridview->contentY(), qreal(0)); delete window; } @@ -1849,7 +1854,7 @@ void tst_QQuickGridView::currentIndex() gridview->setCurrentIndex(35); QTRY_VERIFY(gridview->verticalVelocity() != 0.0); gridview->setCurrentIndex(0); - QTRY_VERIFY(gridview->verticalVelocity() == 0.0); + QTRY_COMPARE(gridview->verticalVelocity(), 0.0); // footer should become visible if it is out of view, and then current index moves to the first row window->rootObject()->setProperty("showFooter", true); @@ -1871,7 +1876,7 @@ void tst_QQuickGridView::currentIndex() // turn off auto highlight gridview->setHighlightFollowsCurrentItem(false); - QVERIFY(gridview->highlightFollowsCurrentItem() == false); + QVERIFY(!gridview->highlightFollowsCurrentItem()); QVERIFY(gridview->highlightItem()); qreal hlPosX = gridview->highlightItem()->x(); qreal hlPosY = gridview->highlightItem()->y(); @@ -1971,7 +1976,7 @@ void tst_QQuickGridView::keyNavigation() window->requestActivate(); QTest::qWaitForWindowActive(window); - QTRY_VERIFY(qGuiApp->focusWindow() == window); + QTRY_COMPARE(qGuiApp->focusWindow(), window); QCOMPARE(gridview->currentIndex(), 0); QTest::keyClick(window, forwardsKey); @@ -2256,15 +2261,15 @@ void tst_QQuickGridView::defaultValues() QQuickGridView *obj = qobject_cast<QQuickGridView*>(c.create()); QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->model() == QVariant()); - QTRY_VERIFY(obj->delegate() == 0); + QTRY_COMPARE(obj->model(), QVariant()); + QTRY_VERIFY(!obj->delegate()); QTRY_COMPARE(obj->currentIndex(), -1); - QTRY_VERIFY(obj->currentItem() == 0); + QTRY_VERIFY(!obj->currentItem()); QTRY_COMPARE(obj->count(), 0); - QTRY_VERIFY(obj->highlight() == 0); - QTRY_VERIFY(obj->highlightItem() == 0); + QTRY_VERIFY(!obj->highlight()); + QTRY_VERIFY(!obj->highlightItem()); QTRY_COMPARE(obj->highlightFollowsCurrentItem(), true); - QTRY_VERIFY(obj->flow() == 0); + QTRY_COMPARE(obj->flow(), QQuickGridView::FlowLeftToRight); QTRY_COMPARE(obj->isWrapEnabled(), false); #ifdef QML_VIEW_DEFAULTCACHEBUFFER QTRY_COMPARE(obj->cacheBuffer(), QML_VIEW_DEFAULTCACHEBUFFER); @@ -2291,7 +2296,7 @@ void tst_QQuickGridView::properties() QTRY_VERIFY(obj->highlight() != 0); QTRY_VERIFY(obj->highlightItem() != 0); QTRY_COMPARE(obj->highlightFollowsCurrentItem(), false); - QTRY_VERIFY(obj->flow() == 0); + QTRY_COMPARE(obj->flow(), QQuickGridView::FlowLeftToRight); QTRY_COMPARE(obj->isWrapEnabled(), true); QTRY_COMPARE(obj->cacheBuffer(), 200); QTRY_COMPARE(obj->cellWidth(), qreal(100)); @@ -2728,7 +2733,7 @@ void tst_QQuickGridView::mirroring() foreach (const QString objectName, objectNames) QCOMPARE(findItem<QQuickItem>(gridviewA, objectName)->x(), findItem<QQuickItem>(gridviewB, objectName)->x()); - QVERIFY(gridviewB->layoutDirection() == gridviewB->effectiveLayoutDirection()); + QCOMPARE(gridviewB->layoutDirection(), gridviewB->effectiveLayoutDirection()); QQuickItemPrivate::get(gridviewB)->setLayoutMirror(true); QVERIFY(gridviewB->layoutDirection() != gridviewB->effectiveLayoutDirection()); @@ -3016,7 +3021,7 @@ void tst_QQuickGridView::footer() QQuickText *footer = findItem<QQuickText>(contentItem, "footer"); QVERIFY(footer); - QVERIFY(footer == gridview->footerItem()); + QCOMPARE(footer, gridview->footerItem()); QCOMPARE(footer->position(), initialFooterPos); QCOMPARE(footer->width(), 100.); @@ -3082,7 +3087,7 @@ void tst_QQuickGridView::footer() QVERIFY(!footer); footer = findItem<QQuickText>(contentItem, "footer2"); QVERIFY(footer); - QVERIFY(footer == gridview->footerItem()); + QCOMPARE(footer, gridview->footerItem()); QCOMPARE(footer->position(), changedFooterPos); QCOMPARE(footer->width(), 50.); @@ -3265,7 +3270,7 @@ void tst_QQuickGridView::header() QQuickText *header = findItem<QQuickText>(contentItem, "header"); QVERIFY(header); - QVERIFY(header == gridview->headerItem()); + QCOMPARE(header, gridview->headerItem()); QCOMPARE(header->position(), initialHeaderPos); QCOMPARE(header->width(), 100.); @@ -3302,7 +3307,7 @@ void tst_QQuickGridView::header() header = findItem<QQuickText>(contentItem, "header2"); QVERIFY(header); - QVERIFY(header == gridview->headerItem()); + QCOMPARE(header, gridview->headerItem()); QCOMPARE(header->position(), changedHeaderPos); QCOMPARE(header->width(), 50.); @@ -3609,11 +3614,11 @@ void tst_QQuickGridView::resetModel_headerFooter() // A reset should not force a new header or footer to be created. QQuickItem *newHeader = findItem<QQuickItem>(contentItem, "header"); - QVERIFY(newHeader == header); + QCOMPARE(newHeader, header); QCOMPARE(header->y(), -header->height()); QQuickItem *newFooter = findItem<QQuickItem>(contentItem, "footer"); - QVERIFY(newFooter == footer); + QCOMPARE(newFooter, footer); QCOMPARE(footer->y(), 60.*2); delete window; @@ -4315,8 +4320,19 @@ void tst_QQuickGridView::snapToRow() QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != 0); + qreal origContentY = gridview->contentY(); + qreal origContentX = gridview->contentX(); // confirm that a flick hits an item boundary flick(window, flickStart, flickEnd, 180); + + // wait until it's at least one cell further + QTRY_VERIFY(qAbs(gridview->contentX() - origContentX) > 80 || + qAbs(gridview->contentY() - origContentY) > 80); + + // click to stop it. Otherwise we wouldn't know how much further it will go. We don't want to it + // to hit the endExtent, yet. + QTest::mouseClick(window, Qt::LeftButton, 0, flickEnd); + QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops if (flow == QQuickGridView::FlowLeftToRight) QCOMPARE(qreal(fmod(gridview->contentY(),80.0)), snapAlignment); @@ -5810,7 +5826,7 @@ void tst_QQuickGridView::cacheBuffer() window->engine()->setIncubationController(&controller); window->rootObject()->setProperty("cacheBuffer", 200); - QTRY_VERIFY(gridview->cacheBuffer() == 200); + QTRY_COMPARE(gridview->cacheBuffer(), 200); // items will be created one at a time for (int i = itemCount; i < qMin(itemCount+9,model.count()); ++i) { @@ -5910,8 +5926,8 @@ void tst_QQuickGridView::asynchronous() for (int i = 0; i < 12; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item->x() == (i%3)*100); - QVERIFY(item->y() == (i/3)*100); + QCOMPARE(item->x(), qreal((i%3)*100)); + QCOMPARE(item->y(), qreal((i/3)*100)); } delete window; @@ -6329,7 +6345,7 @@ void tst_QQuickGridView::matchIndexLists(const QVariantList &indexLists, const Q void tst_QQuickGridView::matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes) { for (QVariantMap::const_iterator it = items.begin(); it != items.end(); ++it) { - QVERIFY(it.value().type() == QVariant::Int); + QCOMPARE(it.value().type(), QVariant::Int); QString name = it.key(); int itemIndex = it.value().toInt(); QVERIFY2(expectedIndexes.contains(itemIndex), QTest::toString(QString("Index %1 not found in expectedIndexes").arg(itemIndex))); @@ -6460,6 +6476,93 @@ void tst_QQuickGridView::jsArrayChange() QCOMPARE(spy.count(), 1); } +void tst_QQuickGridView::contentHeightWithDelayRemove_data() +{ + QTest::addColumn<bool>("useDelayRemove"); + QTest::addColumn<QByteArray>("removeFunc"); + QTest::addColumn<int>("countDelta"); + QTest::addColumn<qreal>("contentHeightDelta"); + + QTest::newRow("remove without delayRemove") + << false + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with delayRemove") + << true + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with multiple delayRemove") + << true + << QByteArray("takeThree") + << -3 + << qreal(-2 * 100.0); + + QTest::newRow("clear with delayRemove") + << true + << QByteArray("takeAll") + << -5 + << qreal(-3 * 100.0); +} + +void tst_QQuickGridView::contentHeightWithDelayRemove() +{ + QFETCH(bool, useDelayRemove); + QFETCH(QByteArray, removeFunc); + QFETCH(int, countDelta); + QFETCH(qreal, contentHeightDelta); + + QQuickView *window = createView(); + window->setSource(testFileUrl("contentHeightWithDelayRemove.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickGridView *gridview = window->rootObject()->findChild<QQuickGridView*>(); + QTRY_VERIFY(gridview != 0); + + const int initialCount(gridview->count()); + const int eventualCount(initialCount + countDelta); + + const qreal initialContentHeight(gridview->contentHeight()); + const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta)); + + gridview->setProperty("useDelayRemove", useDelayRemove); + QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData()); + QTest::qWait(50); + QCOMPARE(gridview->count(), eventualCount); + + if (useDelayRemove) { + QCOMPARE(qRound(gridview->contentHeight()), qRound(initialContentHeight)); + QTRY_COMPARE(qRound(gridview->contentHeight()), eventualContentHeight); + } else { + QCOMPARE(qRound(gridview->contentHeight()), eventualContentHeight); + } + + delete window; +} + +void tst_QQuickGridView::QTBUG_45640() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("qtbug45640.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject()); + QVERIFY(gridview != 0); + + QCOMPARE(gridview->contentY(), qreal(-50.0)); + + gridview->moveCurrentIndexDown(); + + QTRY_VERIFY(gridview->contentY() > qreal(-50.0) && gridview->contentY() < qreal(0.0)); + + delete window; +} + QTEST_MAIN(tst_QQuickGridView) #include "tst_qquickgridview.moc" diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index ce8b52222d..71e9d747f4 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -121,7 +121,7 @@ void tst_qquickimage::noSource() QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); QCOMPARE(obj->source(), QUrl()); - QVERIFY(obj->status() == QQuickImage::Null); + QCOMPARE(obj->status(), QQuickImage::Null); QCOMPARE(obj->width(), 0.); QCOMPARE(obj->height(), 0.); QCOMPARE(obj->fillMode(), QQuickImage::Stretch); @@ -168,6 +168,18 @@ void tst_qquickimage::imageSource() QFETCH(bool, cache); QFETCH(QString, error); + +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + if (qstrcmp(QTest::currentDataTag(), "remote") == 0 + || qstrcmp(QTest::currentDataTag(), "remote redirected") == 0 + || qstrcmp(QTest::currentDataTag(), "remote svg") == 0 + || qstrcmp(QTest::currentDataTag(), "remote svgz") == 0 + || qstrcmp(QTest::currentDataTag(), "remote not found") == 0 + ) { + QSKIP("Remote tests cause occasional hangs in the CI system -- QTBUG-45655"); + } +#endif + TestHTTPServer server; if (remote) { QVERIFY2(server.listen(), qPrintable(server.errorString())); @@ -189,28 +201,28 @@ void tst_qquickimage::imageSource() QVERIFY(obj != 0); if (async) - QVERIFY(obj->asynchronous() == true); + QVERIFY(obj->asynchronous()); else - QVERIFY(obj->asynchronous() == false); + QVERIFY(!obj->asynchronous()); if (cache) - QVERIFY(obj->cache() == true); + QVERIFY(obj->cache()); else - QVERIFY(obj->cache() == false); + QVERIFY(!obj->cache()); if (remote || async) - QTRY_VERIFY(obj->status() == QQuickImage::Loading); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); QCOMPARE(obj->source(), remote ? source : QUrl(source)); if (error.isEmpty()) { - QTRY_VERIFY(obj->status() == QQuickImage::Ready); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); QCOMPARE(obj->width(), qreal(width)); QCOMPARE(obj->height(), qreal(height)); QCOMPARE(obj->fillMode(), QQuickImage::Stretch); QCOMPARE(obj->progress(), 1.0); } else { - QTRY_VERIFY(obj->status() == QQuickImage::Error); + QTRY_COMPARE(obj->status(), QQuickImage::Error); } delete obj; @@ -225,14 +237,14 @@ void tst_qquickimage::clearSource() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); + QCOMPARE(obj->status(), QQuickImage::Ready); QCOMPARE(obj->width(), 120.); QCOMPARE(obj->height(), 120.); QCOMPARE(obj->progress(), 1.0); ctxt->setContextProperty("srcImage", ""); QVERIFY(obj->source().isEmpty()); - QVERIFY(obj->status() == QQuickImage::Null); + QCOMPARE(obj->status(), QQuickImage::Null); QCOMPARE(obj->width(), 0.); QCOMPARE(obj->height(), 0.); QCOMPARE(obj->progress(), 0.0); @@ -533,7 +545,7 @@ void tst_qquickimage::noLoading() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); + QCOMPARE(obj->status(), QQuickImage::Ready); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal))); @@ -541,29 +553,30 @@ void tst_qquickimage::noLoading() // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("green.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/rect.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_COMPARE(progressSpy.count(), 2); + QTRY_VERIFY(progressSpy.count() >= 2); QTRY_COMPARE(statusSpy.count(), 3); // Loading remote file again - should not go through 'Loading' state. + progressSpy.clear(); ctxt->setContextProperty("srcImage", testFileUrl("green.png")); ctxt->setContextProperty("srcImage", server.url("/rect.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 4); - QTRY_COMPARE(progressSpy.count(), 2); + QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 5); delete obj; @@ -615,7 +628,7 @@ void tst_qquickimage::sourceSize_QTBUG_14303() QSignalSpy sourceSizeSpy(obj, SIGNAL(sourceSizeChanged())); QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->sourceSize().width(), 200); QTRY_COMPARE(obj->sourceSize().height(), 200); @@ -831,8 +844,8 @@ void tst_qquickimage::progressAndStatusChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QCOMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); qRegisterMetaType<QQuickImageBase::Status>(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); @@ -841,33 +854,33 @@ void tst_qquickimage::progressAndStatusChanges() // Same image ctxt->setContextProperty("srcImage", testFileUrl("heart.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 0); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/heart.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); QTRY_VERIFY(progressSpy.count() > 1); QTRY_COMPARE(statusSpy.count(), 3); ctxt->setContextProperty("srcImage", ""); - QTRY_VERIFY(obj->status() == QQuickImage::Null); - QTRY_VERIFY(obj->progress() == 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Null); + QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(sourceSpy.count(), 3); QTRY_VERIFY(progressSpy.count() > 2); QTRY_COMPARE(statusSpy.count(), 4); diff --git a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp index dae46b5c3d..644f2be129 100644 --- a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp +++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp @@ -37,6 +37,7 @@ #include <private/qquickimage_p.h> #include <QImageReader> #include <QWaitCondition> +#include <QThreadPool> Q_DECLARE_METATYPE(QQuickImageProvider*); @@ -68,6 +69,8 @@ private slots: void threadTest(); + void asyncTextureTest(); + private: QString newImageFileName() const; void fillRequestTestsData(const QString &id); @@ -234,15 +237,15 @@ void tst_qquickimageprovider::runTest(bool async, QQuickImageProvider *provider) async |= (provider->flags() & QQuickImageProvider::ForceAsynchronousImageLoading) != 0; if (async) - QTRY_VERIFY(obj->status() == QQuickImage::Loading); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); QCOMPARE(obj->source(), QUrl(source)); if (error.isEmpty()) { if (async) - QTRY_VERIFY(obj->status() == QQuickImage::Ready); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); else - QVERIFY(obj->status() == QQuickImage::Ready); + QCOMPARE(obj->status(), QQuickImage::Ready); if (QByteArray(QTest::currentDataTag()).startsWith("qimage")) QCOMPARE(static_cast<TestQImageProvider*>(provider)->lastImageId, imageId); else @@ -254,9 +257,9 @@ void tst_qquickimageprovider::runTest(bool async, QQuickImageProvider *provider) QCOMPARE(obj->progress(), 1.0); } else { if (async) - QTRY_VERIFY(obj->status() == QQuickImage::Error); + QTRY_COMPARE(obj->status(), QQuickImage::Error); else - QVERIFY(obj->status() == QQuickImage::Error); + QCOMPARE(obj->status(), QQuickImage::Error); } delete obj; @@ -453,7 +456,102 @@ void tst_qquickimageprovider::threadTest() provider->cond.wakeAll(); QTest::qWait(250); foreach (QQuickImage *img, images) { - QTRY_VERIFY(img->status() == QQuickImage::Ready); + QTRY_COMPARE(img->status(), QQuickImage::Ready); + } +} + +class TestImageResponse : public QQuickImageResponse, public QRunnable +{ + public: + TestImageResponse(QMutex *lock, QWaitCondition *condition, bool *ok, const QString &id, const QSize &requestedSize) + : m_lock(lock), m_condition(condition), m_ok(ok), m_id(id), m_requestedSize(requestedSize), m_texture(0) + { + setAutoDelete(false); + } + + QQuickTextureFactory *textureFactory() const + { + return m_texture; + } + + void run() + { + m_lock->lock(); + if (!(*m_ok)) { + m_condition->wait(m_lock); + } + m_lock->unlock(); + QImage image(50, 50, QImage::Format_RGB32); + image.fill(QColor(m_id).rgb()); + if (m_requestedSize.isValid()) + image = image.scaled(m_requestedSize); + m_texture = QQuickTextureFactory::textureFactoryForImage(image); + emit finished(); + } + + QMutex *m_lock; + QWaitCondition *m_condition; + bool *m_ok; + QString m_id; + QSize m_requestedSize; + QQuickTextureFactory *m_texture; +}; + +class TestAsyncProvider : public QQuickAsyncImageProvider +{ + public: + TestAsyncProvider() : ok(false) + { + pool.setMaxThreadCount(4); + } + + ~TestAsyncProvider() {} + + QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) + { + TestImageResponse *response = new TestImageResponse(&lock, &condition, &ok, id, requestedSize); + pool.start(response); + return response; + } + + QThreadPool pool; + QMutex lock; + QWaitCondition condition; + bool ok; +}; + + +void tst_qquickimageprovider::asyncTextureTest() +{ + QQmlEngine engine; + + TestAsyncProvider *provider = new TestAsyncProvider; + + engine.addImageProvider("test_async", provider); + QVERIFY(engine.imageProvider("test_async") != 0); + + QString componentStr = "import QtQuick 2.0\nItem { \n" + "Image { source: \"image://test_async/blue\"; }\n" + "Image { source: \"image://test_async/red\"; }\n" + "Image { source: \"image://test_async/green\"; }\n" + "Image { source: \"image://test_async/yellow\"; }\n" + " }"; + QQmlComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QObject *obj = component.create(); + //MUST not deadlock + QVERIFY(obj != 0); + QList<QQuickImage *> images = obj->findChildren<QQuickImage *>(); + QCOMPARE(images.count(), 4); + + QTRY_COMPARE(provider->pool.activeThreadCount(), 4); + foreach (QQuickImage *img, images) { + QTRY_COMPARE(img->status(), QQuickImage::Loading); + } + provider->ok = true; + provider->condition.wakeAll(); + foreach (QQuickImage *img, images) { + QTRY_COMPARE(img->status(), QQuickImage::Ready); } } diff --git a/tests/auto/quick/qquickitem/BLACKLIST b/tests/auto/quick/qquickitem/BLACKLIST new file mode 100644 index 0000000000..d94a3ef102 --- /dev/null +++ b/tests/auto/quick/qquickitem/BLACKLIST @@ -0,0 +1,2 @@ +[contains:hollow square: testing points inside] +xcb diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index c79af91747..73e691b08c 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -276,7 +276,7 @@ void tst_qquickitem::simpleFocus() QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *l1c1 = new TestItem(window.contentItem()); QQuickItem *l1c2 = new TestItem(window.contentItem()); @@ -327,7 +327,7 @@ void tst_qquickitem::scopedFocus() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *l1c1 = new TestItem(window.contentItem()); QQuickItem *l1c2 = new TestItem(window.contentItem()); @@ -407,7 +407,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *item = new TestItem; @@ -427,7 +427,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *item = new TestItem(window.contentItem()); @@ -456,7 +456,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *tree = new TestItem; QQuickItem *c1 = new TestItem(tree); @@ -480,7 +480,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *tree = new TestFocusScope; QQuickItem *c1 = new TestItem(tree); QQuickItem *c2 = new TestItem(tree); @@ -508,7 +508,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *tree = new TestFocusScope; QQuickItem *c1 = new TestItem(tree); QQuickItem *c2 = new TestItem(tree); @@ -534,7 +534,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *tree = new TestFocusScope; QQuickItem *c1 = new TestItem(tree); @@ -574,7 +574,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); FocusState focusState; @@ -596,7 +596,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestItem(window.contentItem()); @@ -617,7 +617,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestFocusScope(window.contentItem()); QQuickItem *item = new TestItem(child); @@ -639,7 +639,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestFocusScope(window.contentItem()); QQuickItem *item = new TestItem(child2); @@ -661,7 +661,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestFocusScope(window.contentItem()); QQuickItem *item = new TestItem(child2); @@ -687,7 +687,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *item = new TestFocusScope(window.contentItem()); QQuickItem *child = new TestItem(item); QQuickItem *child2 = new TestItem; @@ -726,7 +726,7 @@ void tst_qquickitem::multipleFocusClears() view.setSource(testFileUrl("multipleFocusClears.qml")); view.show(); ensureFocus(&view); - QTRY_VERIFY(QGuiApplication::focusWindow() == &view); + QTRY_COMPARE(QGuiApplication::focusWindow(), &view); } void tst_qquickitem::focusSubItemInNonFocusScope() @@ -757,7 +757,7 @@ void tst_qquickitem::parentItemWithFocus() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); { QQuickItem parent; QQuickItem child; @@ -856,7 +856,7 @@ void tst_qquickitem::reparentFocusedItem() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem parent(window.contentItem()); QQuickItem child(&parent); @@ -883,18 +883,18 @@ void tst_qquickitem::reparentFocusedItem() void tst_qquickitem::constructor() { QScopedPointer<QQuickItem> root(new QQuickItem); - QVERIFY(root->parent() == 0); - QVERIFY(root->parentItem() == 0); + QVERIFY(!root->parent()); + QVERIFY(!root->parentItem()); QQuickItem *child1 = new QQuickItem(root.data()); - QVERIFY(child1->parent() == root.data()); - QVERIFY(child1->parentItem() == root.data()); + QCOMPARE(child1->parent(), root.data()); + QCOMPARE(child1->parentItem(), root.data()); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child1); QQuickItem *child2 = new QQuickItem(root.data()); - QVERIFY(child2->parent() == root.data()); - QVERIFY(child2->parentItem() == root.data()); + QCOMPARE(child2->parent(), root.data()); + QCOMPARE(child2->parentItem(), root.data()); QCOMPARE(root->childItems().count(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); @@ -903,41 +903,41 @@ void tst_qquickitem::constructor() void tst_qquickitem::setParentItem() { QQuickItem *root = new QQuickItem; - QVERIFY(root->parent() == 0); - QVERIFY(root->parentItem() == 0); + QVERIFY(!root->parent()); + QVERIFY(!root->parentItem()); QQuickItem *child1 = new QQuickItem; - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == 0); + QVERIFY(!child1->parent()); + QVERIFY(!child1->parentItem()); child1->setParentItem(root); - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == root); + QVERIFY(!child1->parent()); + QCOMPARE(child1->parentItem(), root); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child1); QQuickItem *child2 = new QQuickItem; - QVERIFY(child2->parent() == 0); - QVERIFY(child2->parentItem() == 0); + QVERIFY(!child2->parent()); + QVERIFY(!child2->parentItem()); child2->setParentItem(root); - QVERIFY(child2->parent() == 0); - QVERIFY(child2->parentItem() == root); + QVERIFY(!child2->parent()); + QCOMPARE(child2->parentItem(), root); QCOMPARE(root->childItems().count(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); child1->setParentItem(0); - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == 0); + QVERIFY(!child1->parent()); + QVERIFY(!child1->parentItem()); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child2); delete root; - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == 0); - QVERIFY(child2->parent() == 0); - QVERIFY(child2->parentItem() == 0); + QVERIFY(!child1->parent()); + QVERIFY(!child1->parentItem()); + QVERIFY(!child2->parent()); + QVERIFY(!child2->parentItem()); delete child1; delete child2; diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 69c7250134..396f183860 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -319,7 +319,7 @@ void tst_QQuickItem::activeFocusOnTab() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button12 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button12"); @@ -431,7 +431,7 @@ void tst_QQuickItem::activeFocusOnTab2() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button12 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button12"); @@ -471,7 +471,7 @@ void tst_QQuickItem::activeFocusOnTab3() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button1 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button1"); @@ -653,7 +653,7 @@ void tst_QQuickItem::activeFocusOnTab4() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button11 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button11"); @@ -685,7 +685,7 @@ void tst_QQuickItem::activeFocusOnTab5() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button11 in sub1 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button11"); @@ -719,7 +719,7 @@ void tst_QQuickItem::activeFocusOnTab6() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button12 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button12"); @@ -777,7 +777,7 @@ void tst_QQuickItem::activeFocusOnTab7() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button1"); QVERIFY(item); @@ -810,7 +810,7 @@ void tst_QQuickItem::activeFocusOnTab8() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *content = window->contentItem(); QVERIFY(content); @@ -862,7 +862,7 @@ void tst_QQuickItem::activeFocusOnTab9() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *content = window->contentItem(); QVERIFY(content); @@ -913,7 +913,7 @@ void tst_QQuickItem::activeFocusOnTab10() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *content = window->contentItem(); QVERIFY(content); @@ -996,7 +996,7 @@ void tst_QQuickItem::nextItemInFocusChain() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *button11 = findItem<QQuickItem>(window->rootObject(), "button11"); QVERIFY(button11); @@ -1072,7 +1072,7 @@ void tst_QQuickItem::nextItemInFocusChain2() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *button11 = findItem<QQuickItem>(window->rootObject(), "button11"); QVERIFY(button11); @@ -1117,7 +1117,7 @@ void tst_QQuickItem::nextItemInFocusChain3() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); } void tst_QQuickItem::keys() @@ -1135,7 +1135,7 @@ void tst_QQuickItem::keys() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QVERIFY(window->rootObject()); QCOMPARE(window->rootObject()->property("isEnabled").toBool(), true); @@ -1145,7 +1145,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_A)); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1155,7 +1155,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_A)); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::ShiftModifier); + QCOMPARE(testObject->mModifiers, int(Qt::ShiftModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1165,7 +1165,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_Return)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Return)); QCOMPARE(testObject->mText, QLatin1String("Return")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1175,7 +1175,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_0)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_0)); QCOMPARE(testObject->mText, QLatin1String("0")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1185,7 +1185,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_9)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_9)); QCOMPARE(testObject->mText, QLatin1String("9")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1195,7 +1195,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_Tab)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Tab)); QCOMPARE(testObject->mText, QLatin1String("Tab")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1205,7 +1205,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_Backtab)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Backtab)); QCOMPARE(testObject->mText, QLatin1String("Backtab")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1214,8 +1214,8 @@ void tst_QQuickItem::keys() QGuiApplication::sendEvent(window, &key); QCOMPARE(testObject->mKey, int(Qt::Key_VolumeUp)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_VolumeUp)); - QVERIFY(testObject->mModifiers == Qt::NoModifier); - QVERIFY(testObject->mNativeScanCode == 1234); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); + QCOMPARE(testObject->mNativeScanCode, quint32(1234)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1226,7 +1226,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mForwardedKey, 0); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1321,7 +1321,7 @@ void tst_QQuickItem::keysProcessingOrder() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); KeyTestItem *testItem = qobject_cast<KeyTestItem*>(window->rootObject()); QVERIFY(testItem); @@ -1332,7 +1332,7 @@ void tst_QQuickItem::keysProcessingOrder() QGuiApplication::sendEvent(window, &key); QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1352,7 +1352,7 @@ void tst_QQuickItem::keysProcessingOrder() QGuiApplication::sendEvent(window, &key); QCOMPARE(testObject->mKey, int(Qt::Key_B)); QCOMPARE(testObject->mText, QLatin1String("B")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1379,7 +1379,7 @@ void tst_QQuickItem::keysim() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QVERIFY(window->rootObject()); QVERIFY(window->rootObject()->hasFocus() && window->rootObject()->hasActiveFocus()); @@ -1405,7 +1405,7 @@ void tst_QQuickItem::keysForward() window.show(); window.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&window)); - QVERIFY(QGuiApplication::focusWindow() == &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *rootItem = qobject_cast<QQuickItem *>(window.rootObject()); QVERIFY(rootItem); @@ -1645,7 +1645,7 @@ void tst_QQuickItem::keyNavigation() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item1"); QVERIFY(item); @@ -1722,7 +1722,7 @@ void tst_QQuickItem::keyNavigation_RightToLeft() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window->rootObject()); QVERIFY(rootItem); @@ -1777,7 +1777,7 @@ void tst_QQuickItem::keyNavigation_skipNotVisible() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item1"); QVERIFY(item); @@ -1852,7 +1852,7 @@ void tst_QQuickItem::keyNavigation_implicitSetting() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QEvent wa(QEvent::WindowActivate); QGuiApplication::sendEvent(window, &wa); @@ -1982,7 +1982,7 @@ void tst_QQuickItem::keyNavigation_focusReason() window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // install event filter on first item QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item1"); @@ -2040,8 +2040,8 @@ void tst_QQuickItem::smooth() QVERIFY(item->smooth()); QCOMPARE(spy.count(),1); QList<QVariant> arguments = spy.first(); - QVERIFY(arguments.count() == 1); - QVERIFY(arguments.at(0).toBool() == true); + QCOMPARE(arguments.count(), 1); + QVERIFY(arguments.at(0).toBool()); item->setSmooth(true); QCOMPARE(spy.count(),1); @@ -2069,8 +2069,8 @@ void tst_QQuickItem::antialiasing() QVERIFY(item->antialiasing()); QCOMPARE(spy.count(),1); QList<QVariant> arguments = spy.first(); - QVERIFY(arguments.count() == 1); - QVERIFY(arguments.at(0).toBool() == true); + QCOMPARE(arguments.count(), 1); + QVERIFY(arguments.at(0).toBool()); item->setAntialiasing(true); QCOMPARE(spy.count(),1); @@ -2098,8 +2098,8 @@ void tst_QQuickItem::clip() QVERIFY(item->clip()); QList<QVariant> arguments = spy.first(); - QVERIFY(arguments.count() == 1); - QVERIFY(arguments.at(0).toBool() == true); + QCOMPARE(arguments.count(), 1); + QVERIFY(arguments.at(0).toBool()); QCOMPARE(spy.count(),1); item->setClip(true); @@ -2325,7 +2325,7 @@ void tst_QQuickItem::propertyChanges() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item"); QQuickItem *parentItem = findItem<QQuickItem>(window->rootObject(), "parentItem"); @@ -2353,7 +2353,7 @@ void tst_QQuickItem::propertyChanges() QCOMPARE(item->parentItem(), parentItem); QCOMPARE(parentSpy.count(),1); QList<QVariant> parentArguments = parentSpy.first(); - QVERIFY(parentArguments.count() == 1); + QCOMPARE(parentArguments.count(), 1); QCOMPARE(item->parentItem(), qvariant_cast<QQuickItem *>(parentArguments.at(0))); QCOMPARE(childrenChangedSpy.count(),1); @@ -2369,19 +2369,19 @@ void tst_QQuickItem::propertyChanges() QCOMPARE(item->baselineOffset(), 10.0); QCOMPARE(baselineOffsetSpy.count(),1); QList<QVariant> baselineOffsetArguments = baselineOffsetSpy.first(); - QVERIFY(baselineOffsetArguments.count() == 1); + QCOMPARE(baselineOffsetArguments.count(), 1); QCOMPARE(item->baselineOffset(), baselineOffsetArguments.at(0).toReal()); QCOMPARE(parentItem->childrenRect(), QRectF(0.0,0.0,100.0,200.0)); QCOMPARE(childrenRectSpy.count(),1); QList<QVariant> childrenRectArguments = childrenRectSpy.at(0); - QVERIFY(childrenRectArguments.count() == 1); + QCOMPARE(childrenRectArguments.count(), 1); QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF()); QCOMPARE(item->hasActiveFocus(), true); QCOMPARE(focusSpy.count(),1); QList<QVariant> focusArguments = focusSpy.first(); - QVERIFY(focusArguments.count() == 1); + QCOMPARE(focusArguments.count(), 1); QCOMPARE(focusArguments.at(0).toBool(), true); QCOMPARE(parentItem->hasActiveFocus(), false); @@ -2737,7 +2737,7 @@ void tst_QQuickItem::contains() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *root = qobject_cast<QQuickItem *>(window->rootObject()); QVERIFY(root); diff --git a/tests/auto/quick/qquicklistview/BLACKLIST b/tests/auto/quick/qquicklistview/BLACKLIST new file mode 100644 index 0000000000..269696ce8c --- /dev/null +++ b/tests/auto/quick/qquicklistview/BLACKLIST @@ -0,0 +1,4 @@ +[QTBUG_38209] +* +[enforceRange_withoutHighlight] +osx diff --git a/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml b/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml new file mode 100644 index 0000000000..06011519b2 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml @@ -0,0 +1,46 @@ +import QtQuick 2.1 + +Item { + width: 400 + height: 600 + function takeOne() + { + listView.model.remove(2) + } + function takeThree() + { + listView.model.remove(4) + listView.model.remove(2) + listView.model.remove(0) + } + function takeAll() + { + listView.model.clear() + } + + ListView { + id: listView + + property bool useDelayRemove + + height: parent.height + width: 400 + model: ListModel { + ListElement { name: "A" } + ListElement { name: "B" } + ListElement { name: "C" } + ListElement { name: "D" } + ListElement { name: "E" } + } + delegate: Text { + id: wrapper + height: 100 + text: index + listView.count + ListView.delayRemove: listView.useDelayRemove + ListView.onRemove: SequentialAnimation { + PauseAnimation { duration: wrapper.ListView.delayRemove ? 100 : 0 } + PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } + } + } + } +} diff --git a/tests/auto/quick/qquicklistview/data/objectmodel.qml b/tests/auto/quick/qquicklistview/data/objectmodel.qml new file mode 100644 index 0000000000..5c23d64cd3 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/objectmodel.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 +import QtQml.Models 2.1 + +ListView { + width: 360 + height: 360 + model: ObjectModel { + Rectangle { + width: 20 + height: 20 + color: "red" + } + Rectangle { + width: 20 + height: 20 + color: "green" + } + Rectangle { + width: 20 + height: 20 + color: "blue" + } + } +} diff --git a/tests/auto/quick/qquicklistview/data/snapOneItemResize.qml b/tests/auto/quick/qquicklistview/data/snapOneItemResize.qml new file mode 100644 index 0000000000..7ecc833a64 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/snapOneItemResize.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +ListView { + id: list + currentIndex: 5 + snapMode: ListView.SnapOneItem + orientation: ListView.Horizontal + highlightRangeMode: ListView.StrictlyEnforceRange + highlightFollowsCurrentItem: true + model: 10 + spacing: 10 + delegate: Item { + width: ListView.view.width + height: ListView.view.height + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index c93aac456d..472ffdc4b6 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -179,6 +179,7 @@ private slots: void creationContext(); void snapToItem_data(); void snapToItem(); + void snapOneItemResize_QTBUG_43555(); void snapOneItem_data(); void snapOneItem(); @@ -241,6 +242,10 @@ private slots: void QTBUG_39492(); void jsArrayChange(); + void objectModel(); + + void contentHeightWithDelayRemove(); + void contentHeightWithDelayRemove_data(); private: template <class T> void items(const QUrl &source); @@ -391,7 +396,7 @@ void tst_QQuickListView::items(const QUrl &source) QTRY_VERIFY(contentItem != 0); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->highlightItem() != 0); QTRY_COMPARE(listview->count(), model.count()); @@ -414,20 +419,20 @@ void tst_QQuickListView::items(const QUrl &source) // switch to other delegate testObject->setAnimate(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->currentItem()); // set invalid highlight testObject->setInvalidHighlight(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->currentItem()); - QTRY_VERIFY(listview->highlightItem() == 0); + QTRY_VERIFY(!listview->highlightItem()); // back to normal highlight testObject->setInvalidHighlight(false); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->currentItem()); QTRY_VERIFY(listview->highlightItem() != 0); @@ -439,7 +444,7 @@ void tst_QQuickListView::items(const QUrl &source) listview->forceLayout(); int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); - QTRY_VERIFY(itemCount == 0); + QTRY_COMPARE(itemCount, 0); QTRY_COMPARE(listview->highlightResizeVelocity(), 1000.0); QTRY_COMPARE(listview->highlightMoveVelocity(), 100000.0); @@ -563,7 +568,7 @@ void tst_QQuickListView::inserted(const QUrl &source) // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTRY_VERIFY(listview->contentY() == 80); + QTRY_COMPARE(listview->contentY(), qreal(80)); // Confirm items positioned correctly for (int i = 5; i < 5+15; ++i) { @@ -583,7 +588,7 @@ void tst_QQuickListView::inserted(const QUrl &source) QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", 0); QVERIFY(item); QCOMPARE(item->y(), 0.); - QTRY_VERIFY(listview->contentY() == 0); + QTRY_COMPARE(listview->contentY(), qreal(0)); delete window; delete testObject; @@ -916,7 +921,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } // Remove first item (which is the current item); @@ -968,7 +973,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) } // Remove current index - QTRY_VERIFY(listview->currentIndex() == 9); + QTRY_COMPARE(listview->currentIndex(), 9); QQuickItem *oldCurrent = listview->currentItem(); model.removeItem(9); @@ -1004,7 +1009,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) model.removeItem(6); QTRY_COMPARE(listview->currentIndex(), 7); - QTRY_VERIFY(listview->currentItem() == oldCurrent); + QTRY_COMPARE(listview->currentItem(), oldCurrent); listview->setContentY(80); QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); @@ -1272,22 +1277,22 @@ void tst_QQuickListView::clear(const QUrl &source, QQuickItemView::VerticalLayou model.clear(); QTRY_COMPARE(findItems<QQuickListView>(contentItem, "wrapper").count(), 0); - QTRY_VERIFY(listview->count() == 0); - QTRY_VERIFY(listview->currentItem() == 0); + QTRY_COMPARE(listview->count(), 0); + QTRY_VERIFY(!listview->currentItem()); if (verticalLayoutDirection == QQuickItemView::TopToBottom) QTRY_COMPARE(listview->contentY(), 0.0); else QTRY_COMPARE(listview->contentY(), -listview->height()); - QVERIFY(listview->currentIndex() == -1); + QCOMPARE(listview->currentIndex(), -1); QCOMPARE(listview->contentHeight(), 0.0); // confirm sanity when adding an item to cleared list model.addItem("New", "1"); listview->forceLayout(); - QTRY_VERIFY(listview->count() == 1); + QTRY_COMPARE(listview->count(), 1); QVERIFY(listview->currentItem() != 0); - QVERIFY(listview->currentIndex() == 0); + QCOMPARE(listview->currentIndex(), 0); delete window; delete testObject; @@ -1805,7 +1810,7 @@ void tst_QQuickListView::swapWithFirstItem() // ensure content position is stable listview->setContentY(0); model.moveItem(1, 0); - QTRY_VERIFY(listview->contentY() == 0); + QTRY_COMPARE(listview->contentY(), qreal(0)); delete testObject; delete window; @@ -1943,11 +1948,11 @@ void tst_QQuickListView::spacing() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } listview->setSpacing(10); - QTRY_VERIFY(listview->spacing() == 10); + QTRY_COMPARE(listview->spacing(), qreal(10)); // Confirm items positioned correctly QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").count() == 11); @@ -1955,7 +1960,7 @@ void tst_QQuickListView::spacing() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*30); + QTRY_COMPARE(item->y(), qreal(i*30)); } listview->setSpacing(0); @@ -2261,7 +2266,7 @@ void tst_QQuickListView::sectionsDelegate_headerVisibility() listview->setCurrentIndex(20); QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); QTRY_VERIFY(qFuzzyCompare(listview->contentY(), 200.0)); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); listview->setCurrentIndex(0); QTRY_VERIFY(qFuzzyIsNull(listview->contentY())); @@ -2682,7 +2687,7 @@ void tst_QQuickListView::currentIndex() listview->setCurrentIndex(20); QTRY_VERIFY(listview->verticalVelocity() != 0.0); listview->setCurrentIndex(0); - QTRY_VERIFY(listview->verticalVelocity() == 0.0); + QTRY_COMPARE(listview->verticalVelocity(), 0.0); // footer should become visible if it is out of view, and then current index is set to count-1 window->rootObject()->setProperty("showFooter", true); @@ -2704,7 +2709,7 @@ void tst_QQuickListView::currentIndex() // turn off auto highlight listview->setHighlightFollowsCurrentItem(false); - QVERIFY(listview->highlightFollowsCurrentItem() == false); + QVERIFY(!listview->highlightFollowsCurrentItem()); QVERIFY(listview->highlightItem()); qreal hlPos = listview->highlightItem()->y(); @@ -2808,7 +2813,7 @@ void tst_QQuickListView::keyNavigation() window->requestActivate(); QTest::qWaitForWindowActive(window); - QTRY_VERIFY(qGuiApp->focusWindow() == window); + QTRY_COMPARE(qGuiApp->focusWindow(), window); QTest::keyClick(window, forwardsKey); QCOMPARE(listview->currentIndex(), 1); @@ -2917,7 +2922,7 @@ void tst_QQuickListView::itemList() QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != 0); - QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(model->count(), 3); QTRY_COMPARE(listview->currentIndex(), 0); QQuickItem *item = findItem<QQuickItem>(contentItem, "item1"); @@ -2958,7 +2963,7 @@ void tst_QQuickListView::itemListFlicker() QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != 0); - QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(model->count(), 3); QTRY_COMPARE(listview->currentIndex(), 0); QQuickItem *item; @@ -3024,14 +3029,14 @@ void tst_QQuickListView::cacheBuffer() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } QQmlIncubationController controller; window->engine()->setIncubationController(&controller); testObject->setCacheBuffer(200); - QTRY_VERIFY(listview->cacheBuffer() == 200); + QTRY_COMPARE(listview->cacheBuffer(), 200); // items will be created one at a time for (int i = itemCount; i < qMin(itemCount+10,model.count()); ++i) { @@ -3057,7 +3062,7 @@ void tst_QQuickListView::cacheBuffer() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } // move view and confirm items in view are visible immediately and outside are created async @@ -3067,7 +3072,7 @@ void tst_QQuickListView::cacheBuffer() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); - QVERIFY(item->y() == i*20); + QCOMPARE(item->y(), qreal(i*20)); } QVERIFY(findItem<QQuickItem>(listview, "wrapper", 32) == 0); @@ -3528,7 +3533,7 @@ void tst_QQuickListView::QTBUG_11105() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } listview->positionViewAtIndex(20, QQuickListView::Beginning); @@ -3622,7 +3627,7 @@ void tst_QQuickListView::header() QQuickText *header = 0; QTRY_VERIFY(header = findItem<QQuickText>(contentItem, "header")); - QVERIFY(header == listview->headerItem()); + QCOMPARE(header, listview->headerItem()); QCOMPARE(header->width(), 100.); QCOMPARE(header->height(), 30.); @@ -3660,7 +3665,7 @@ void tst_QQuickListView::header() header = findItem<QQuickText>(contentItem, "header2"); QVERIFY(header); - QVERIFY(header == listview->headerItem()); + QCOMPARE(header, listview->headerItem()); QCOMPARE(header->position(), changedHeaderPos); QCOMPARE(header->width(), 50.); @@ -3811,7 +3816,7 @@ void tst_QQuickListView::headerChangesViewport() QQuickText *header = 0; QTRY_VERIFY(header = findItem<QQuickText>(contentItem, "header")); - QVERIFY(header == listview->headerItem()); + QCOMPARE(header, listview->headerItem()); QCOMPARE(header->height(), 20.); QCOMPARE(listview->contentHeight(), 20.); @@ -3862,7 +3867,7 @@ void tst_QQuickListView::footer() QQuickText *footer = findItem<QQuickText>(contentItem, "footer"); QVERIFY(footer); - QVERIFY(footer == listview->footerItem()); + QCOMPARE(footer, listview->footerItem()); QCOMPARE(footer->position(), initialFooterPos); QCOMPARE(footer->width(), 100.); @@ -3922,7 +3927,7 @@ void tst_QQuickListView::footer() footer = findItem<QQuickText>(contentItem, "footer2"); QVERIFY(footer); - QVERIFY(footer == listview->footerItem()); + QCOMPARE(footer, listview->footerItem()); QCOMPARE(footer->position(), changedFooterPos); QCOMPARE(footer->width(), 50.); @@ -4155,11 +4160,11 @@ void tst_QQuickListView::resetModel_headerFooter() // A reset should not force a new header or footer to be created. QQuickItem *newHeader = findItem<QQuickItem>(contentItem, "header"); - QVERIFY(newHeader == header); + QCOMPARE(newHeader, header); QCOMPARE(header->y(), -header->height()); QQuickItem *newFooter = findItem<QQuickItem>(contentItem, "footer"); - QVERIFY(newFooter == footer); + QCOMPARE(newFooter, footer); QCOMPARE(footer->y(), 30.*4); delete window; @@ -4664,7 +4669,7 @@ void tst_QQuickListView::indexAt_itemAt() QVERIFY(item); } QCOMPARE(listview->indexAt(x,y), index); - QVERIFY(listview->itemAt(x,y) == item); + QCOMPARE(listview->itemAt(x,y), item); releaseView(window); delete testObject; @@ -4828,7 +4833,7 @@ void tst_QQuickListView::rightToLeft() QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != 0); - QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(model->count(), 3); QTRY_COMPARE(listview->currentIndex(), 0); // initial position at first item, right edge aligned @@ -4893,7 +4898,7 @@ void tst_QQuickListView::test_mirroring() foreach (const QString objectName, objectNames) QCOMPARE(findItem<QQuickItem>(listviewA, objectName)->x(), findItem<QQuickItem>(listviewB, objectName)->x()); - QVERIFY(listviewB->layoutDirection() == listviewB->effectiveLayoutDirection()); + QCOMPARE(listviewB->layoutDirection(), listviewB->effectiveLayoutDirection()); QQuickItemPrivate::get(listviewB)->setLayoutMirror(true); QVERIFY(listviewB->layoutDirection() != listviewB->effectiveLayoutDirection()); @@ -5034,7 +5039,7 @@ void tst_QQuickListView::marginsResize() // flick past the end and check content pos still settles on correct extents flick(window, flickStart, flickEnd, 180); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); if (orientation == QQuickListView::Vertical) QTRY_COMPARE(listview->contentY(), end); else @@ -5049,7 +5054,7 @@ void tst_QQuickListView::marginsResize() // flick past the beginning and check content pos still settles on correct extents flick(window, flickEnd, flickStart, 180); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); if (orientation == QQuickListView::Vertical) QTRY_COMPARE(listview->contentY(), start); else @@ -5199,6 +5204,37 @@ void tst_QQuickListView::snapToItem() releaseView(window); } +void tst_QQuickListView::snapOneItemResize_QTBUG_43555() +{ + QQuickView *window = createView(); + window->resize(QSize(100, 320)); + window->setResizeMode(QQuickView::SizeRootObjectToView); + QQuickViewTestUtil::moveMouseAway(window); + + window->setSource(testFileUrl("snapOneItemResize.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); + QTRY_VERIFY(listview != 0); + + QSignalSpy currentIndexSpy(listview, SIGNAL(currentIndexChanged())); + + QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QTRY_COMPARE(listview->currentIndex(), 5); + currentIndexSpy.clear(); + + window->resize(QSize(400, 320)); + + QTRY_COMPARE(int(listview->width()), 400); + QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + + QTRY_COMPARE(listview->currentIndex(), 5); + QCOMPARE(currentIndexSpy.count(), 0); + + delete window; +} + void tst_QQuickListView::qAbstractItemModel_package_items() { items<QaimModel>(testFileUrl("listviewtest-package.qml")); @@ -7006,7 +7042,7 @@ void tst_QQuickListView::matchIndexLists(const QVariantList &indexLists, const Q void tst_QQuickListView::matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes) { for (QVariantMap::const_iterator it = items.begin(); it != items.end(); ++it) { - QVERIFY(it.value().type() == QVariant::Int); + QCOMPARE(it.value().type(), QVariant::Int); QString name = it.key(); int itemIndex = it.value().toInt(); QVERIFY2(expectedIndexes.contains(itemIndex), QTest::toString(QString("Index %1 not found in expectedIndexes").arg(itemIndex))); @@ -7020,7 +7056,7 @@ void tst_QQuickListView::matchItemsAndIndexes(const QVariantMap &items, const Qa void tst_QQuickListView::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { for (int i=0; i<itemLists.count(); i++) { - QVERIFY(itemLists[i].type() == QVariant::List); + QCOMPARE(itemLists[i].type(), QVariant::List); QVariantList current = itemLists[i].toList(); for (int j=0; j<current.count(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); @@ -7062,7 +7098,7 @@ void tst_QQuickListView::flickBeyondBounds() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*45); + QTRY_COMPARE(item->y(), qreal(i*45)); } delete window; @@ -7856,7 +7892,7 @@ void tst_QQuickListView::QTBUG_38209() // simulate mouse flick flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); qreal contentY = listview->contentY(); // flick down @@ -8063,6 +8099,135 @@ void tst_QQuickListView::jsArrayChange() QCOMPARE(spy.count(), 1); } +static bool compareObjectModel(QQuickListView *listview, QQmlObjectModel *model) +{ + if (listview->count() != model->count()) + return false; + for (int i = 0; i < listview->count(); ++i) { + listview->setCurrentIndex(i); + if (listview->currentItem() != model->get(i)) + return false; + } + return true; +} + +void tst_QQuickListView::objectModel() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("objectmodel.qml")); + + QQuickListView *listview = qobject_cast<QQuickListView *>(component.create()); + QVERIFY(listview); + + QQmlObjectModel *model = listview->model().value<QQmlObjectModel *>(); + QVERIFY(model); + + listview->setCurrentIndex(0); + QVERIFY(listview->currentItem()); + QCOMPARE(listview->currentItem()->property("color").toString(), QColor("red").name()); + + listview->setCurrentIndex(1); + QVERIFY(listview->currentItem()); + QCOMPARE(listview->currentItem()->property("color").toString(), QColor("green").name()); + + listview->setCurrentIndex(2); + QVERIFY(listview->currentItem()); + QCOMPARE(listview->currentItem()->property("color").toString(), QColor("blue").name()); + + QQuickItem *item0 = new QQuickItem(listview); + item0->setSize(QSizeF(20, 20)); + model->append(item0); + QCOMPARE(model->count(), 4); + QVERIFY(compareObjectModel(listview, model)); + + QQuickItem *item1 = new QQuickItem(listview); + item1->setSize(QSizeF(20, 20)); + model->insert(0, item1); + QCOMPARE(model->count(), 5); + QVERIFY(compareObjectModel(listview, model)); + + model->move(1, 2, 3); + QVERIFY(compareObjectModel(listview, model)); + + model->remove(2, 2); + QCOMPARE(model->count(), 3); + QVERIFY(compareObjectModel(listview, model)); + + model->clear(); + QCOMPARE(model->count(), 0); + QCOMPARE(listview->count(), 0); + + delete listview; +} + +void tst_QQuickListView::contentHeightWithDelayRemove_data() +{ + QTest::addColumn<bool>("useDelayRemove"); + QTest::addColumn<QByteArray>("removeFunc"); + QTest::addColumn<int>("countDelta"); + QTest::addColumn<qreal>("contentHeightDelta"); + + QTest::newRow("remove without delayRemove") + << false + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with delayRemove") + << true + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with multiple delayRemove") + << true + << QByteArray("takeThree") + << -3 + << qreal(-3 * 100.0); + + QTest::newRow("clear with delayRemove") + << true + << QByteArray("takeAll") + << -5 + << qreal(-5 * 100.0); +} + +void tst_QQuickListView::contentHeightWithDelayRemove() +{ + QFETCH(bool, useDelayRemove); + QFETCH(QByteArray, removeFunc); + QFETCH(int, countDelta); + QFETCH(qreal, contentHeightDelta); + + QQuickView *window = createView(); + window->setSource(testFileUrl("contentHeightWithDelayRemove.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = window->rootObject()->findChild<QQuickListView*>(); + QTRY_VERIFY(listview != 0); + + const int initialCount(listview->count()); + const int eventualCount(initialCount + countDelta); + + const qreal initialContentHeight(listview->contentHeight()); + const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta)); + + listview->setProperty("useDelayRemove", useDelayRemove); + QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData()); + QTest::qWait(50); + QCOMPARE(listview->count(), eventualCount); + + if (useDelayRemove) { + QCOMPARE(qRound(listview->contentHeight()), qRound(initialContentHeight)); + QTRY_COMPARE(qRound(listview->contentHeight()), eventualContentHeight); + } else { + QCOMPARE(qRound(listview->contentHeight()), eventualContentHeight); + } + + delete window; +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 3dd2551d9d..e72b38e06c 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -236,7 +236,7 @@ void tst_QQuickLoader::clear() QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); - QTRY_VERIFY(loader->item() == 0); + QTRY_VERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -256,7 +256,7 @@ void tst_QQuickLoader::clear() loader->setSourceComponent(0); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -276,7 +276,7 @@ void tst_QQuickLoader::clear() QMetaObject::invokeMethod(item, "clear"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -447,7 +447,7 @@ void tst_QQuickLoader::networkRequestUrl() QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); QVERIFY(loader != 0); - QTRY_VERIFY(loader->status() == QQuickLoader::Ready); + QTRY_COMPARE(loader->status(), QQuickLoader::Ready); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); @@ -480,7 +480,7 @@ void tst_QQuickLoader::networkComponent() QQuickLoader *loader = qobject_cast<QQuickLoader*>(item->children().at(1)); QVERIFY(loader); - QTRY_VERIFY(loader->status() == QQuickLoader::Ready); + QTRY_COMPARE(loader->status(), QQuickLoader::Ready); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); @@ -505,9 +505,9 @@ void tst_QQuickLoader::failNetworkRequest() QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); QVERIFY(loader != 0); - QTRY_VERIFY(loader->status() == QQuickLoader::Error); + QTRY_COMPARE(loader->status(), QQuickLoader::Error); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->property("did_load").toInt(), 123); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -525,11 +525,11 @@ void tst_QQuickLoader::active() QQuickLoader *loader = object->findChild<QQuickLoader*>("loader"); QVERIFY(loader->active() == false); // set manually to false - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QMetaObject::invokeMethod(object, "doSetSourceComponent"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QMetaObject::invokeMethod(object, "doSetSource"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QMetaObject::invokeMethod(object, "doSetActive"); QVERIFY(loader->item() != 0); @@ -598,7 +598,7 @@ void tst_QQuickLoader::active() QVERIFY(loader->item() != 0); int currItemChangedCount = loader->property("itemChangedCount").toInt(); QMetaObject::invokeMethod(object, "doSetInactive"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->property("itemChangedCount").toInt(), (currItemChangedCount+1)); delete object; @@ -781,7 +781,7 @@ void tst_QQuickLoader::initialPropertyValuesError() QVERIFY(object != 0); QQuickLoader *loader = object->findChild<QQuickLoader*>("loader"); QVERIFY(loader != 0); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); delete object; } @@ -803,7 +803,7 @@ void tst_QQuickLoader::deleteComponentCrash() QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); QTRY_COMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); - QVERIFY(loader->source() == testFileUrl("BlueRect.qml")); + QCOMPARE(loader->source(), testFileUrl("BlueRect.qml")); delete item; } @@ -833,7 +833,7 @@ void tst_QQuickLoader::vmeErrors() QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); QVERIFY(loader); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); delete loader; } @@ -1098,7 +1098,7 @@ void tst_QQuickLoader::parented() QQuickItem *item = root->findChild<QQuickItem*>("comp"); QVERIFY(item); - QVERIFY(item->parentItem() == root); + QCOMPARE(item->parentItem(), root); QCOMPARE(item->width(), 300.); QCOMPARE(item->height(), 300.); diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index da8bb9e94d..6e6c9da829 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -169,7 +169,7 @@ void tst_QQuickMouseArea::dragProperties() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window.rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); @@ -267,14 +267,14 @@ void tst_QQuickMouseArea::resetDrag() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window.rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); QVERIFY(drag->target() != 0); window.rootContext()->setContextProperty("haveTarget", QVariant(false)); QCOMPARE(targetSpy.count(),1); - QVERIFY(drag->target() == 0); + QVERIFY(!drag->target()); } void tst_QQuickMouseArea::dragging() @@ -300,7 +300,7 @@ void tst_QQuickMouseArea::dragging() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -347,7 +347,7 @@ void tst_QQuickMouseArea::dragSmoothed() mouseRegion->setAcceptedButtons(Qt::LeftButton); QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QVERIFY(!drag->active()); @@ -393,7 +393,7 @@ void tst_QQuickMouseArea::dragThreshold() mouseRegion->setAcceptedButtons(Qt::LeftButton); QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QVERIFY(!drag->active()); @@ -451,7 +451,7 @@ void tst_QQuickMouseArea::invalidDrag() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -501,7 +501,7 @@ void tst_QQuickMouseArea::cancelDragging() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -655,7 +655,7 @@ void tst_QQuickMouseArea::noOnClickedWithPressAndHold() QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); QGuiApplication::sendEvent(&window, &pressEvent); - QVERIFY(mouseArea->pressedButtons() == Qt::LeftButton); + QCOMPARE(mouseArea->pressedButtons(), Qt::LeftButton); QVERIFY(!window.rootObject()->property("clicked").toBool()); QVERIFY(!window.rootObject()->property("held").toBool()); @@ -1268,7 +1268,7 @@ void tst_QQuickMouseArea::disableAfterPress() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -1561,7 +1561,7 @@ void tst_QQuickMouseArea::changeAxis() // target QQuickItem *blackRect = view.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); diff --git a/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST new file mode 100644 index 0000000000..1777af9e0c --- /dev/null +++ b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST @@ -0,0 +1,2 @@ +[inFlickable] +* diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index e69ebfa8fe..4da4767d7b 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -719,7 +719,7 @@ void tst_QQuickMultiPointTouchArea::inFlickable() QTest::mouseMove(window.data(), p1); QQuickTouchUtils::flush(window.data()); - QVERIFY(flickable->contentY() == 0); + QCOMPARE(flickable->contentY(), qreal(0)); QCOMPARE(point11->pressed(), true); QCOMPARE(point12->pressed(), true); @@ -1186,14 +1186,14 @@ void tst_QQuickMultiPointTouchArea::mouseInteraction() QPoint p1 = QPoint(100, 100); QTest::mousePress(view.data(), (Qt::MouseButton) buttons, 0, p1); QCOMPARE(area->property("touchCount").toInt(), accept); - QCOMPARE(point1->pressed(), accept); + QCOMPARE(point1->pressed(), accept != 0); p1 += QPoint(10, 10); QTest::mouseMove(view.data(), p1); - QCOMPARE(point1->pressed(), accept); + QCOMPARE(point1->pressed(), accept != 0); QCOMPARE(area->property("touchCount").toInt(), accept); p1 += QPoint(10, 10); QTest::mouseMove(view.data(), p1); - QCOMPARE(point1->pressed(), accept); + QCOMPARE(point1->pressed(), accept != 0); QCOMPARE(area->property("touchCount").toInt(), accept); QTest::mouseRelease(view.data(), (Qt::MouseButton) buttons); QCOMPARE(point1->pressed(), false); diff --git a/tests/auto/quick/qquickpathview/data/customAttribute.qml b/tests/auto/quick/qquickpathview/data/customAttribute.qml new file mode 100644 index 0000000000..bd4c9fd1de --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/customAttribute.qml @@ -0,0 +1,58 @@ +import QtQuick 2.4 + +PathView { + width: 200 + height: 600 + + pathItemCount: 7 + + model: ListModel { + ListElement { color: "salmon" } + ListElement { color: "seagreen" } + ListElement { color: "navy" } + ListElement { color: "goldenrod" } + } + path: Path { + startX: width / 2; startY: -100 + PathAttribute { name: "BEGIN" } + + PathLine { relativeX: 0; y: height / 2 } + PathAttribute { name: "BEGIN" } + + PathLine { relativeX: 0; y: height + 100 } + PathAttribute { name: "BEGIN" } + } + delegate: Rectangle { + width: 200 + height: 200 + color: model.color + opacity: PathView.transparency + } + + Component { + id: attributeComponent + PathAttribute {} + } + + function addAttribute(name, values) { + var valueIndex = 0 + var elements = [] + for (var i = 0; i < path.pathElements.length; ++i) { + elements.push(path.pathElements[i]) + + if (path.pathElements[i].name === "BEGIN") { + if (values[valueIndex] !== undefined) { + var attribute = attributeComponent.createObject(this, { "name": name, "value": values[valueIndex] }) + elements.push(attribute) + } + ++valueIndex + } + } + + console.log("??") + path.pathElements = elements + console.log("!!") + } + + Component.onCompleted: addAttribute("transparency", [0, 1, 0]) +} diff --git a/tests/auto/quick/qquickpathview/data/qtbug42716.qml b/tests/auto/quick/qquickpathview/data/qtbug42716.qml new file mode 100644 index 0000000000..81d52d5ea3 --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/qtbug42716.qml @@ -0,0 +1,111 @@ +import QtQuick 2.0 + +Rectangle { + //Note that this file was originally the manual reproduction, MouseAreas were left in. + id: qmlBrowser + + width: 500 + height: 350 + + ListModel { + id: myModel + ListElement { + name: "Bill Jones 0" + } + ListElement { + name: "Jane Doe 1" + } + ListElement { + name: "John Smith 2" + } + ListElement { + name: "Bill Jones 3" + } + ListElement { + name: "Jane Doe 4" + } + ListElement { + name: "John Smith 5" + } + ListElement { + name: "John Smith 6" + } + ListElement { + name: "John Smith 7" + } + } + + Component { + id: delegate + + Text { + id: nameText + height: 33 + width: parent.width + objectName: "delegate"+index + + text: "index: " + index + " text: " + name + font.pointSize: 16 + color: PathView.isCurrentItem ? "red" : "black" + } + } + + PathView { + id: contentList + objectName: "pathView" + anchors.fill: parent + + property int maxPathItemCount: 7 + property real itemHeight: 34 + + delegate: delegate + model: myModel + currentIndex: 5 + pathItemCount: maxPathItemCount + highlightMoveDuration: 0 + + path: Path { + startX: 30 + contentList.width / 2 + startY: 30 + PathLine { + relativeX: 0 + relativeY: contentList.itemHeight * contentList.maxPathItemCount + } + } + + focus: true + Keys.onLeftPressed: decrementCurrentIndex() + Keys.onRightPressed: incrementCurrentIndex() + } + + Column { + anchors.right: parent.right + Text { + text: "Go 1" + font.weight: Font.Bold + font.pixelSize: 24 + MouseArea { + anchors.fill: parent + onClicked: contentList.offset = 2.55882 + } + } + Text { + text: "Go 2" + font.weight: Font.Bold + font.pixelSize: 24 + MouseArea { + anchors.fill: parent + onClicked: contentList.offset = 0.0882353 + } + } + Text { + text: "Go 3" + font.weight: Font.Bold + font.pixelSize: 24 + MouseArea { + anchors.fill: parent + onClicked: contentList.offset = 0.99987 + } + } + } +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 7db15522b5..eed947bfcd 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -140,6 +140,8 @@ private slots: void nestedinFlickable(); void flickableDelegate(); void jsArrayChange(); + void qtbug42716(); + void addCustomAttribute(); }; class TestObject : public QObject @@ -183,8 +185,8 @@ void tst_QQuickPathView::initValues() QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create()); QVERIFY(obj != 0); - QVERIFY(obj->path() == 0); - QVERIFY(obj->delegate() == 0); + QVERIFY(!obj->path()); + QVERIFY(!obj->delegate()); QCOMPARE(obj->model(), QVariant()); QCOMPARE(obj->currentIndex(), 0); QCOMPARE(obj->offset(), 0.); @@ -799,7 +801,7 @@ void tst_QQuickPathView::dataModel() QVERIFY(pathview != 0); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); QQuickItem *item = findItem<QQuickItem>(pathview, "wrapper", 0); QVERIFY(item); @@ -828,14 +830,14 @@ void tst_QQuickPathView::dataModel() testObject->setPathItemCount(5); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); QQuickRectangle *testItem = findItem<QQuickRectangle>(pathview, "wrapper", 4); QVERIFY(testItem != 0); testItem = findItem<QQuickRectangle>(pathview, "wrapper", 5); - QVERIFY(testItem == 0); + QVERIFY(!testItem); pathview->setCurrentIndex(1); QCOMPARE(pathview->currentIndex(), 1); @@ -1814,7 +1816,7 @@ void tst_QQuickPathView::cancelDrag() item->grabMouse(); // returns to a snap point. - QTRY_VERIFY(pathview->offset() == qFloor(pathview->offset())); + QTRY_COMPARE(pathview->offset(), qreal(qFloor(pathview->offset()))); QTRY_VERIFY(!pathview->isMoving()); QVERIFY(!pathview->isDragging()); QCOMPARE(draggingSpy.count(), 2); @@ -1897,7 +1899,7 @@ void tst_QQuickPathView::snapToItem() QVERIFY(pathview->isMoving()); QTRY_VERIFY_WITH_TIMEOUT(!pathview->isMoving(), 50000); - QVERIFY(pathview->offset() == qFloor(pathview->offset())); + QCOMPARE(pathview->offset(), qreal(qFloor(pathview->offset()))); if (enforceRange) QVERIFY(pathview->currentIndex() != currentIndex); @@ -2051,7 +2053,7 @@ void tst_QQuickPathView::indexAt_itemAt() QVERIFY(item); } QCOMPARE(pathview->indexAt(x,y), index); - QVERIFY(pathview->itemAt(x,y) == item); + QCOMPARE(pathview->itemAt(x,y), item); } @@ -2322,6 +2324,61 @@ void tst_QQuickPathView::jsArrayChange() QCOMPARE(spy.count(), 1); } +/* This bug was one where if you jump the list such that the sole missing item needed to be + * added in the middle of the list, it would instead move an item somewhere else in the list + * to the middle (messing it up very badly). + * + * The test checks correct visual order both before and after the jump. + */ +void tst_QQuickPathView::qtbug42716() +{ + QScopedPointer<QQuickView> window(createView()); + + window->setSource(testFileUrl("qtbug42716.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathView = findItem<QQuickPathView>(window->rootObject(), "pathView"); + QVERIFY(pathView != 0); + + int order1[] = {5,6,7,0,1,2,3}; + int missing1 = 4; + int order2[] = {0,1,2,3,4,5,6}; + int missing2 = 7; + + qreal lastY = 0.0; + for (int i = 0; i<7; i++) { + QQuickItem *item = findItem<QQuickItem>(pathView, QString("delegate%1").arg(order1[i])); + QVERIFY(item); + QVERIFY(item->y() > lastY); + lastY = item->y(); + } + QQuickItem *itemMiss = findItem<QQuickItem>(pathView, QString("delegate%1").arg(missing1)); + QVERIFY(!itemMiss); + + pathView->setOffset(0.0882353); + //Note refill is delayed, needs time to take effect + QTest::qWait(100); + + lastY = 0.0; + for (int i = 0; i<7; i++) { + QQuickItem *item = findItem<QQuickItem>(pathView, QString("delegate%1").arg(order2[i])); + QVERIFY(item); + QVERIFY(item->y() > lastY); + lastY = item->y(); + } + itemMiss = findItem<QQuickItem>(pathView, QString("delegate%1").arg(missing2)); + QVERIFY(!itemMiss); +} + +void tst_QQuickPathView::addCustomAttribute() +{ + const QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("customAttribute.qml")); + window->show(); +} + QTEST_MAIN(tst_QQuickPathView) #include "tst_qquickpathview.moc" diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index 8063453993..3988a90aed 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -91,7 +91,7 @@ void tst_QQuickPinchArea::pinchProperties() // target QQuickItem *blackRect = window->rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == pinch->target()); + QCOMPARE(blackRect, pinch->target()); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window->rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(pinch, SIGNAL(targetChanged())); diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index b9f93a4dcf..0064212a78 100644 --- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp +++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp @@ -110,12 +110,14 @@ void tst_qquickpixmapcache::initTestCase() QVERIFY2(server.listen(), qPrintable(server.errorString())); +#ifndef QT_NO_BEARERMANAGEMENT // This avoids a race condition/deadlock bug in network config // manager when it is accessed by the HTTP server thread before // anything else. Bug report can be found at: // QTBUG-26355 QNetworkConfigurationManager cm; cm.updateConfigurations(); +#endif server.serveDirectory(testFile("http")); } @@ -159,10 +161,10 @@ void tst_qquickpixmapcache::single() if (incache) { QCOMPARE(pixmap.error(), expectedError); if (exists) { - QVERIFY(pixmap.status() == QQuickPixmap::Ready); + QCOMPARE(pixmap.status(), QQuickPixmap::Ready); QVERIFY(pixmap.width() > 0); } else { - QVERIFY(pixmap.status() == QQuickPixmap::Error); + QCOMPARE(pixmap.status(), QQuickPixmap::Error); QVERIFY(pixmap.width() <= 0); } } else { @@ -174,10 +176,10 @@ void tst_qquickpixmapcache::single() QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(getter.gotslot); if (exists) { - QVERIFY(pixmap.status() == QQuickPixmap::Ready); + QCOMPARE(pixmap.status(), QQuickPixmap::Ready); QVERIFY(pixmap.width() > 0); } else { - QVERIFY(pixmap.status() == QQuickPixmap::Error); + QCOMPARE(pixmap.status(), QQuickPixmap::Error); QVERIFY(pixmap.width() <= 0); } QCOMPARE(pixmap.error(), expectedError); @@ -259,7 +261,9 @@ void tst_qquickpixmapcache::parallel() } } - QCOMPARE(incache+slotters, targets.count()); + if (incache + slotters != targets.count()) + QFAIL(QString::fromLatin1("pixmap counts don't add up: %1 incache, %2 slotters, %3 total") + .arg(incache).arg(slotters).arg(targets.count()).toLatin1().constData()); if (cancel >= 0) { pixmaps.at(cancel)->clear(getters[cancel]); @@ -280,7 +284,12 @@ void tst_qquickpixmapcache::parallel() if (pending[i]) QVERIFY(getters[i]->gotslot); - QVERIFY(pixmap->isReady()); + if (!pixmap->isReady()) { + QFAIL(QString::fromLatin1("pixmap %1 not ready, status %2: %3") + .arg(pixmap->url().toString()).arg(pixmap->status()) + .arg(pixmap->error()).toLatin1().constData()); + + } QVERIFY(pixmap->width() > 0); delete getters[i]; } @@ -307,7 +316,7 @@ void tst_qquickpixmapcache::massive() QVERIFY(p2.isReady()); QVERIFY(p2.image().size() == QSize(10000, 1000)); - QVERIFY(p2.image().cacheKey() == cachekey); + QCOMPARE(p2.image().cacheKey(), cachekey); } // Confirm that massive images are removed from the cache when diff --git a/tests/auto/quick/qquickpositioners/data/allInvisible.qml b/tests/auto/quick/qquickpositioners/data/allInvisible.qml index 5894171434..3b95a5e1da 100644 --- a/tests/auto/quick/qquickpositioners/data/allInvisible.qml +++ b/tests/auto/quick/qquickpositioners/data/allInvisible.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.6 Item{ width: 400 @@ -41,4 +41,42 @@ Item{ visible: false } } + Grid{ + spacing: 20 + objectName: "grid" + Item{ + width: 0 + height: 20 + visible: false + } + Item{ + width: 20 + height: 0 + visible: false + } + Item{ + width: 20 + height: 20 + visible: false + } + } + Flow{ + spacing: 20 + objectName: "flow" + Item{ + width: 0 + height: 20 + visible: false + } + Item{ + width: 20 + height: 0 + visible: false + } + Item{ + width: 20 + height: 20 + visible: false + } + } } diff --git a/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml b/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml new file mode 100644 index 0000000000..a85e7a5c52 --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml @@ -0,0 +1,44 @@ +import QtQuick 2.6 + +Item { + width: 90 + height: 480 + property bool testRightToLeft: false + + Flow { + objectName: "flow" + width: parent.width + layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "green" + width: 20 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 50 + height: 20 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml b/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml new file mode 100644 index 0000000000..46244ecef5 --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml @@ -0,0 +1,47 @@ +import QtQuick 2.6 + +Item { + width: 640 + height: 480 + property bool testRightToLeft: false + property int testHAlignment: Grid.AlignLeft; + property int testVAlignment: Grid.AlignTop; + Grid { + layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight + horizontalItemAlignment: testHAlignment + verticalItemAlignment: testVAlignment + objectName: "grid" + columns: 3 + padding: 1; topPadding: 1; leftPadding: 1; rightPadding: 1; bottomPadding: 1 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "green" + width: 20 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 30 + height: 20 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml b/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml new file mode 100644 index 0000000000..d320c4789f --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml @@ -0,0 +1,30 @@ +import QtQuick 2.6 + +Item { + width: 640 + height: 480 + property bool testRightToLeft: false + Row { + objectName: "row" + layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight + padding: 1; topPadding: 1; leftPadding: 1; rightPadding: 1; bottomPadding: 1 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "red" + width: 20 + height: 10 + } + Rectangle { + objectName: "three" + color: "red" + width: 40 + height: 20 + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml b/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml new file mode 100644 index 0000000000..577d4ef0b7 --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml @@ -0,0 +1,53 @@ +import QtQuick 2.6 + +Item { + width: 640 + height: 480 + Row { + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater{ model: 3; + delegate: Component { + Rectangle { + color: "red" + width: 50 + height: 50 + z: { + if (index == 0) + return 2; + else if (index == 1) + return 1; + else + return 3; + } + objectName: { + if (index == 0) + return "one"; + else if (index == 1) + return "two"; + else + return "three"; + } + } + } + } + } + + //This crashed once (QTBUG-16959) because the repeater ended up on the end of the list + //If this grid just instantiates without crashing, then it has not regressed. + Grid { + id: grid + rows: 2 + flow: Grid.TopToBottom + + Repeater { + model: 13 + Rectangle { + color: "goldenrod" + width: 100 + height: 100 + radius: 10 + border.width: 1 + } + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/repeatertest.qml b/tests/auto/quick/qquickpositioners/data/repeatertest.qml index d90e1cf160..ae3d961c75 100644 --- a/tests/auto/quick/qquickpositioners/data/repeatertest.qml +++ b/tests/auto/quick/qquickpositioners/data/repeatertest.qml @@ -10,8 +10,22 @@ Item { color: "red" width: 50 height: 50 - z: {if(index == 0){2;}else if(index == 1){1;} else{3;}} - objectName: {if(index == 0){"one";}else if(index == 1){"two";} else{"three";}} + z: { + if (index == 0) + return 2; + else if (index == 1) + return 1; + else + return 3; + } + objectName: { + if (index == 0) + return "one"; + else if (index == 1) + return "two"; + else + return "three"; + } } } } diff --git a/tests/auto/quick/qquickpositioners/data/transitions-padding.qml b/tests/auto/quick/qquickpositioners/data/transitions-padding.qml new file mode 100644 index 0000000000..e3175c480c --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/transitions-padding.qml @@ -0,0 +1,239 @@ +import QtQuick 2.6 + +Rectangle { + id: root + width: 500 + height: 500 + + property int duration: 50 + + property real incrementalSize: 5 + + property int populateTransitionsDone + property int addTransitionsDone + property int displaceTransitionsDone + + property var targetTrans_items: new Object() + property var targetTrans_targetIndexes: new Array() + property var targetTrans_targetItems: new Array() + + property var displacedTrans_items: new Object() + property var displacedTrans_targetIndexes: new Array() + property var displacedTrans_targetItems: new Array() + + // for QQmlListProperty types + function copyList(propList) { + var temp = new Array() + for (var i=0; i<propList.length; i++) + temp.push(propList[i]) + return temp + } + + function checkPos(x, y, name) { + if (Qt.point(x, y) == targetItems_transitionFrom) + model_targetItems_transitionFrom.addItem(name, "") + if (Qt.point(x, y) == displacedItems_transitionVia) + model_displacedItems_transitionVia.addItem(name, "") + } + + Component.onCompleted: { + if (dynamicallyPopulate) { + for (var i=0; i<30; i++) + testModel.addItem("item " + i, "") + } + } + + Transition { + id: populateTransition + enabled: usePopulateTransition + + SequentialAnimation { + ScriptAction { + script: { + root.targetTrans_items[populateTransition.ViewTransition.item.nameData] = populateTransition.ViewTransition.index + root.targetTrans_targetIndexes.push(populateTransition.ViewTransition.targetIndexes) + root.targetTrans_targetItems.push(root.copyList(populateTransition.ViewTransition.targetItems)) + } + } + ParallelAnimation { + NumberAnimation { properties: "x"; from: targetItems_transitionFrom.x; duration: root.duration } + NumberAnimation { properties: "y"; from: targetItems_transitionFrom.y; duration: root.duration } + } + + ScriptAction { script: root.populateTransitionsDone += 1 } + } + } + + Transition { + id: addTransition + enabled: enableAddTransition + + SequentialAnimation { + ScriptAction { + script: { + root.targetTrans_items[addTransition.ViewTransition.item.nameData] = addTransition.ViewTransition.index + root.targetTrans_targetIndexes.push(addTransition.ViewTransition.targetIndexes) + root.targetTrans_targetItems.push(root.copyList(addTransition.ViewTransition.targetItems)) + } + } + ParallelAnimation { + NumberAnimation { properties: "x"; from: targetItems_transitionFrom.x; duration: root.duration } + NumberAnimation { properties: "y"; from: targetItems_transitionFrom.y; duration: root.duration } + } + + ScriptAction { script: root.addTransitionsDone += 1 } + } + } + + Transition { + id: displaced + + SequentialAnimation { + ScriptAction { + script: { + root.displacedTrans_items[displaced.ViewTransition.item.nameData] = displaced.ViewTransition.index + root.displacedTrans_targetIndexes.push(displaced.ViewTransition.targetIndexes) + root.displacedTrans_targetItems.push(root.copyList(displaced.ViewTransition.targetItems)) + } + } + ParallelAnimation { + NumberAnimation { properties: "x"; duration: root.duration; to: displacedItems_transitionVia.x } + NumberAnimation { properties: "y"; duration: root.duration; to: displacedItems_transitionVia.y } + } + NumberAnimation { properties: "x,y"; duration: root.duration } + + ScriptAction { script: root.displaceTransitionsDone += 1 } + } + + } + + Row { + objectName: "row" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "row" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.y } + } + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } + + Column { + objectName: "column" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "column" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.y } + } + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } + + Grid { + objectName: "grid" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "grid" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.y } + } + + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } + + Flow { + objectName: "flow" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "flow" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.x + " " + parent.parent.y } + } + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } +} + diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index 3c44041ca5..69359503fe 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -53,33 +53,50 @@ public: private slots: void test_horizontal(); + void test_horizontal_padding(); void test_horizontal_rtl(); void test_horizontal_spacing(); void test_horizontal_spacing_rightToLeft(); void test_horizontal_animated(); + void test_horizontal_animated_padding(); void test_horizontal_animated_rightToLeft(); + void test_horizontal_animated_rightToLeft_padding(); void test_horizontal_animated_disabled(); + void test_horizontal_animated_disabled_padding(); void test_vertical(); + void test_vertical_padding(); void test_vertical_spacing(); void test_vertical_animated(); + void test_vertical_animated_padding(); void test_grid(); + void test_grid_padding(); void test_grid_topToBottom(); void test_grid_rightToLeft(); void test_grid_spacing(); void test_grid_row_column_spacing(); void test_grid_animated(); + void test_grid_animated_padding(); void test_grid_animated_rightToLeft(); + void test_grid_animated_rightToLeft_padding(); void test_grid_zero_columns(); void test_grid_H_alignment(); + void test_grid_H_alignment_padding(); void test_grid_V_alignment(); + void test_grid_V_alignment_padding(); void test_propertychanges(); void test_repeater(); + void test_repeater_padding(); void test_flow(); + void test_flow_padding(); void test_flow_rightToLeft(); void test_flow_topToBottom(); + void test_flow_topToBottom_padding(); void test_flow_resize(); + void test_flow_resize_padding(); void test_flow_resize_rightToLeft(); + void test_flow_resize_rightToLeft_padding(); void test_flow_implicit_resize(); + void test_flow_implicit_resize_padding(); void test_conflictinganchors(); void test_mirroring(); void test_allInvisible(); @@ -198,18 +215,25 @@ void tst_qquickpositioners::addTransitions_grid_data() // (adding items further down the grid can cause displace transitions at // previous indexes, since grid is auto-resized to tightly fit all of its items) + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<int>("insertionIndex"); QTest::addColumn<int>("insertionCount"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("add one @ start") << 10 << 0 << 1 << ListRange(0, 9); - QTest::newRow("add one @ middle") << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9); - QTest::newRow("add one @ end") << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7); + QTest::newRow("add one @ start") << "transitions.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("add one @ middle") << "transitions.qml" << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9); + QTest::newRow("add one @ end") << "transitions.qml" << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7); + QTest::newRow("padding, add one @ start") << "transitions-padding.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("padding, add one @ middle") << "transitions-padding.qml" << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9); + QTest::newRow("padding, add one @ end") << "transitions-padding.qml" << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7); - QTest::newRow("add multiple @ start") << 10 << 0 << 3 << ListRange(0, 9); - QTest::newRow("add multiple @ middle") << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9); - QTest::newRow("add multiple @ end") << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9); + QTest::newRow("add multiple @ start") << "transitions.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("add multiple @ middle") << "transitions.qml" << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9); + QTest::newRow("add multiple @ end") << "transitions.qml" << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9); + QTest::newRow("padding, add multiple @ start") << "transitions-padding.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("padding, add multiple @ middle") << "transitions-padding.qml" << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9); + QTest::newRow("padding, add multiple @ end") << "transitions-padding.qml" << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9); } void tst_qquickpositioners::addTransitions_flow() @@ -253,17 +277,24 @@ void tst_qquickpositioners::moveTransitions_grid_data() // (removing items further down the grid can cause displace transitions at // previous indexes, since grid is auto-resized to tightly fit all of its items) + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<ListChange>("change"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("remove one @ start") << 10 << ListChange::remove(0, 1) << ListRange(1, 9); - QTest::newRow("remove one @ middle") << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9); - QTest::newRow("remove one @ end") << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7); + QTest::newRow("remove one @ start") << "transitions.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("remove one @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9); + QTest::newRow("remove one @ end") << "transitions.qml" << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7); + QTest::newRow("padding, remove one @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("padding, remove one @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9); + QTest::newRow("padding, remove one @ end") << "transitions-padding.qml" << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7); - QTest::newRow("remove multiple @ start") << 10 << ListChange::remove(0, 3) << ListRange(3, 9); - QTest::newRow("remove multiple @ middle") << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9); - QTest::newRow("remove multiple @ end") << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6); + QTest::newRow("remove multiple @ start") << "transitions.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("remove multiple @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9); + QTest::newRow("remove multiple @ end") << "transitions.qml" << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6); + QTest::newRow("padding, remove multiple @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("padding, remove multiple @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9); + QTest::newRow("padding, remove multiple @ end") << "transitions-padding.qml" << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6); } void tst_qquickpositioners::moveTransitions_flow() @@ -305,6 +336,185 @@ void tst_qquickpositioners::test_horizontal() QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); QCOMPARE(row->width(), 110.0); QCOMPARE(row->height(), 50.0); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 117.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); +} + +void tst_qquickpositioners::test_horizontal_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal.qml"))); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QCOMPARE(row->width(), 110.0); + QCOMPARE(row->height(), 50.0); + + QQuickRow *obj = qobject_cast<QQuickRow*>(row); + QVERIFY(obj != 0); + + QCOMPARE(row->property("padding").toDouble(), 0.0); + QCOMPARE(row->property("topPadding").toDouble(), 0.0); + QCOMPARE(row->property("leftPadding").toDouble(), 0.0); + QCOMPARE(row->property("rightPadding").toDouble(), 0.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 0.0); + + obj->setPadding(1.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 1.0); + QCOMPARE(row->property("leftPadding").toDouble(), 1.0); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->width(), 112.0); + QCOMPARE(row->height(), 52.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 1.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 1.0); + + obj->setTopPadding(2.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 1.0); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->height(), 53.0); + QCOMPARE(row->width(), 112.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 2.0); + + obj->setLeftPadding(3.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 3.0); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->width(), 114.0); + QCOMPARE(row->height(), 53.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + + obj->setRightPadding(4.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 3.0); + QCOMPARE(row->property("rightPadding").toDouble(), 4.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->width(), 117.0); + QCOMPARE(row->height(), 53.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + + obj->setBottomPadding(5.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 3.0); + QCOMPARE(row->property("rightPadding").toDouble(), 4.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(row->height(), 57.0); + QCOMPARE(row->width(), 117.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + + obj->resetBottomPadding(); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(row->height(), 53.0); + QCOMPARE(row->width(), 117.0); + + obj->resetRightPadding(); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(row->width(), 114.0); + QCOMPARE(row->height(), 53.0); + + obj->resetLeftPadding(); + QCOMPARE(row->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(row->width(), 112.0); + QCOMPARE(row->height(), 53.0); + + obj->resetTopPadding(); + QCOMPARE(row->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(row->height(), 52.0); + QCOMPARE(row->width(), 112.0); + + obj->resetPadding(); + QCOMPARE(row->property("padding").toDouble(), 0.0); + QCOMPARE(row->property("topPadding").toDouble(), 0.0); + QCOMPARE(row->property("leftPadding").toDouble(), 0.0); + QCOMPARE(row->property("rightPadding").toDouble(), 0.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(row->height(), 50.0); + QCOMPARE(row->width(), 110.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); } void tst_qquickpositioners::test_horizontal_rtl() @@ -333,6 +543,36 @@ void tst_qquickpositioners::test_horizontal_rtl() QCOMPARE(row->width(), 110.0); QCOMPARE(row->height(), 50.0); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 117.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 63.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 43.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + + row->setProperty("topPadding", 0); + row->setProperty("leftPadding", 0); + row->setProperty("rightPadding", 0); + row->setProperty("bottomPadding", 0); + row->setProperty("padding", 0); + + QTRY_COMPARE(one->x(), 60.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 40.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 0.0); + // Change the width of the row and check that items stay to the right row->setWidth(200); QTRY_COMPARE(one->x(), 150.0); @@ -342,6 +582,18 @@ void tst_qquickpositioners::test_horizontal_rtl() QCOMPARE(three->x(), 90.0); QCOMPARE(three->y(), 0.0); + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(one->x(), 146.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 126.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 86.0); + QCOMPARE(three->y(), 2.0); } void tst_qquickpositioners::test_horizontal_spacing() @@ -370,6 +622,22 @@ void tst_qquickpositioners::test_horizontal_spacing() QCOMPARE(row->width(), 130.0); QCOMPARE(row->height(), 50.0); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 137.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 63.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 93.0); + QCOMPARE(three->y(), 2.0); } void tst_qquickpositioners::test_horizontal_spacing_rightToLeft() @@ -391,13 +659,29 @@ void tst_qquickpositioners::test_horizontal_spacing_rightToLeft() QCOMPARE(one->y(), 0.0); QCOMPARE(two->x(), 50.0); QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 00.0); + QCOMPARE(three->x(), 0.0); QCOMPARE(three->y(), 0.0); QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); QCOMPARE(row->width(), 130.0); QCOMPARE(row->height(), 50.0); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 137.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 83.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); } void tst_qquickpositioners::test_horizontal_animated() @@ -453,6 +737,70 @@ void tst_qquickpositioners::test_horizontal_animated() } +void tst_qquickpositioners::test_horizontal_animated_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + //Note that they animate in + QCOMPARE(one->x(), -100.0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(three->x(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QVERIFY(row); + QCOMPARE(row->width(), 100.0); + QCOMPARE(row->height(), 50.0); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 107.0); + QCOMPARE(row->height(), 57.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet + QTRY_COMPARE(two->y(), 0.0); + QTRY_COMPARE(three->x(), 53.0); + QTRY_COMPARE(three->y(), 2.0); + + //Add 'two' + two->setVisible(true); + QTRY_COMPARE(two->isVisible(), true); + QTRY_COMPARE(row->width(), 157.0); + QTRY_COMPARE(row->height(), 57.0); + + QTest::qWait(0);//Let the animation start + QVERIFY(two->x() >= -100.0 && two->x() < 53.0); + QVERIFY(three->x() >= 53.0 && three->x() < 103.0); + + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(three->x(), 103.0); + +} + void tst_qquickpositioners::test_horizontal_animated_rightToLeft() { QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false)); @@ -508,6 +856,72 @@ void tst_qquickpositioners::test_horizontal_animated_rightToLeft() } +void tst_qquickpositioners::test_horizontal_animated_rightToLeft_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", true); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + //Note that they animate in + QCOMPARE(one->x(), -100.0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(three->x(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QVERIFY(row); + QCOMPARE(row->width(), 100.0); + QCOMPARE(row->height(), 50.0); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 107.0); + QCOMPARE(row->height(), 57.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->x(), 53.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet + QTRY_COMPARE(two->y(), 0.0); + QTRY_COMPARE(three->x(), 3.0); + QTRY_COMPARE(three->y(), 2.0); + + //Add 'two' + two->setVisible(true); + QTRY_COMPARE(two->isVisible(), true); + + // New size should propagate after visible change + QTRY_COMPARE(row->width(), 157.0); + QTRY_COMPARE(row->height(), 57.0); + + QTest::qWait(0);//Let the animation start + QVERIFY(one->x() >= 53.0 && one->x() < 100); + QVERIFY(two->x() >= -100.0 && two->x() < 53.0); + + QTRY_COMPARE(one->x(), 103.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + +} + void tst_qquickpositioners::test_horizontal_animated_disabled() { QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated-disabled.qml"))); @@ -526,6 +940,54 @@ void tst_qquickpositioners::test_horizontal_animated_disabled() qApp->processEvents(); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 107.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->isVisible(), false); + QCOMPARE(two->x(), -100.0);//Not 'in' yet + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 2.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + QTRY_COMPARE(row->width(), 157.0); + QTRY_COMPARE(row->height(), 57.0); + + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(three->x(), 103.0); + +} + +void tst_qquickpositioners::test_horizontal_animated_disabled_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated-disabled.qml"))); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QVERIFY(row); + + qApp->processEvents(); + QCOMPARE(one->x(), 0.0); QCOMPARE(one->y(), 0.0); QCOMPARE(two->isVisible(), false); @@ -547,6 +1009,7 @@ void tst_qquickpositioners::test_horizontal_animated_disabled() void tst_qquickpositioners::populateTransitions(const QString &positionerObjectName) { + QFETCH(QString, qmlFile); QFETCH(bool, dynamicallyPopulate); QFETCH(bool, usePopulateTransition); @@ -574,7 +1037,7 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); ctxt->setContextProperty("testedPositioner", positionerObjectName); - window->setSource(testFileUrl("transitions.qml")); + window->setSource(testFileUrl(qmlFile)); QQuickItem *positioner = window->rootObject()->findChild<QQuickItem*>(positionerObjectName); QVERIFY(positioner); @@ -619,18 +1082,24 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN void tst_qquickpositioners::populateTransitions_data() { + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<bool>("dynamicallyPopulate"); QTest::addColumn<bool>("usePopulateTransition"); - QTest::newRow("statically populate") << false << true; - QTest::newRow("statically populate, no populate transition") << false << false; + QTest::newRow("statically populate") << "transitions.qml" << false << true; + QTest::newRow("statically populate, no populate transition") << "transitions.qml" << false << false; + QTest::newRow("padding, statically populate") << "transitions-padding.qml" << false << true; + QTest::newRow("padding, statically populate, no populate transition") << "transitions-padding.qml" << false << false; - QTest::newRow("dynamically populate") << true << true; - QTest::newRow("dynamically populate, no populate transition") << true << false; + QTest::newRow("dynamically populate") << "transitions.qml" << true << true; + QTest::newRow("dynamically populate, no populate transition") << "transitions.qml" << true << false; + QTest::newRow("padding, dynamically populate") << "transitions-padding.qml" << true << true; + QTest::newRow("padding, dynamically populate, no populate transition") << "transitions-padding.qml" << true << false; } void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) { + QFETCH(QString, qmlFile); QFETCH(int, initialItemCount); QFETCH(int, insertionIndex); QFETCH(int, insertionCount); @@ -654,7 +1123,7 @@ void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); ctxt->setContextProperty("testedPositioner", QString()); - window->setSource(testFileUrl("transitions.qml")); + window->setSource(testFileUrl(qmlFile)); window->show(); QTest::qWaitForWindowExposed(window.data()); qApp->processEvents(); @@ -729,22 +1198,30 @@ void tst_qquickpositioners::addTransitions_data() { // If this data changes, update addTransitions_grid_data() also + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<int>("insertionIndex"); QTest::addColumn<int>("insertionCount"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("add one @ start") << 10 << 0 << 1 << ListRange(0, 9); - QTest::newRow("add one @ middle") << 10 << 5 << 1 << ListRange(5, 9); - QTest::newRow("add one @ end") << 10 << 10 << 1 << ListRange(); + QTest::newRow("add one @ start") << "transitions.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("add one @ middle") << "transitions.qml" << 10 << 5 << 1 << ListRange(5, 9); + QTest::newRow("add one @ end") << "transitions.qml" << 10 << 10 << 1 << ListRange(); + QTest::newRow("padding, add one @ start") << "transitions-padding.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("padding, add one @ middle") << "transitions-padding.qml" << 10 << 5 << 1 << ListRange(5, 9); + QTest::newRow("padding, add one @ end") << "transitions-padding.qml" << 10 << 10 << 1 << ListRange(); - QTest::newRow("add multiple @ start") << 10 << 0 << 3 << ListRange(0, 9); - QTest::newRow("add multiple @ middle") << 10 << 5 << 3 << ListRange(5, 9); - QTest::newRow("add multiple @ end") << 10 << 10 << 3 << ListRange(); + QTest::newRow("add multiple @ start") << "transitions.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("add multiple @ middle") << "transitions.qml" << 10 << 5 << 3 << ListRange(5, 9); + QTest::newRow("add multiple @ end") << "transitions.qml" << 10 << 10 << 3 << ListRange(); + QTest::newRow("padding, add multiple @ start") << "transitions-padding.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("padding, add multiple @ middle") << "transitions-padding.qml" << 10 << 5 << 3 << ListRange(5, 9); + QTest::newRow("padding, add multiple @ end") << "transitions-padding.qml" << 10 << 10 << 3 << ListRange(); } void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) { + QFETCH(QString, qmlFile); QFETCH(int, initialItemCount); QFETCH(ListChange, change); QFETCH(ListRange, expectedDisplacedIndexes); @@ -769,7 +1246,7 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); ctxt->setContextProperty("testedPositioner", QString()); - window->setSource(testFileUrl("transitions.qml")); + window->setSource(testFileUrl(qmlFile)); window->show(); QTest::qWaitForWindowExposed(window.data()); qApp->processEvents(); @@ -840,27 +1317,36 @@ void tst_qquickpositioners::moveTransitions_data() { // If this data changes, update moveTransitions_grid_data() also + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<ListChange>("change"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("remove one @ start") << 10 << ListChange::remove(0, 1) << ListRange(1, 9); - QTest::newRow("remove one @ middle") << 10 << ListChange::remove(4, 1) << ListRange(5, 9); - QTest::newRow("remove one @ end") << 10 << ListChange::remove(9, 1) << ListRange(); + QTest::newRow("remove one @ start") << "transitions.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("remove one @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 1) << ListRange(5, 9); + QTest::newRow("remove one @ end") << "transitions.qml" << 10 << ListChange::remove(9, 1) << ListRange(); + QTest::newRow("padding, remove one @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("padding, remove one @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 1) << ListRange(5, 9); + QTest::newRow("padding, remove one @ end") << "transitions-padding.qml" << 10 << ListChange::remove(9, 1) << ListRange(); - QTest::newRow("remove multiple @ start") << 10 << ListChange::remove(0, 3) << ListRange(3, 9); - QTest::newRow("remove multiple @ middle") << 10 << ListChange::remove(4, 3) << ListRange(7, 9); - QTest::newRow("remove multiple @ end") << 10 << ListChange::remove(7, 3) << ListRange(); + QTest::newRow("remove multiple @ start") << "transitions.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("remove multiple @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 3) << ListRange(7, 9); + QTest::newRow("remove multiple @ end") << "transitions.qml" << 10 << ListChange::remove(7, 3) << ListRange(); + QTest::newRow("padding, remove multiple @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("padding, remove multiple @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 3) << ListRange(7, 9); + QTest::newRow("padding, remove multiple @ end") << "transitions-padding.qml" << 10 << ListChange::remove(7, 3) << ListRange(); } - void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel *model, qreal incrementalSize) { QVERIFY(model->count() > 0); + + QQuickBasePositioner *p = qobject_cast<QQuickBasePositioner*>(positioner); + qreal padding = 0; qreal currentSize = 30; - qreal rowX = 0; - qreal rowY = 0; + qreal rowX = p->leftPadding(); + qreal rowY = p->topPadding(); for (int i=0; i<model->count(); ++i) { QQuickItem *item = findItem<QQuickItem>(positioner, "wrapper", i); @@ -870,11 +1356,11 @@ void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel QCOMPARE(item->height(), currentSize); if (qobject_cast<QQuickRow*>(positioner)) { - QCOMPARE(item->x(), (i * 30.0) + padding); - QCOMPARE(item->y(), 0.0); + QCOMPARE(item->x(), (i * 30.0) + padding + p->leftPadding()); + QCOMPARE(item->y(), p->topPadding()); } else if (qobject_cast<QQuickColumn*>(positioner)) { - QCOMPARE(item->x(), 0.0); - QCOMPARE(item->y(), (i * 30.0) + padding); + QCOMPARE(item->x(), p->leftPadding()); + QCOMPARE(item->y(), (i * 30.0) + padding + p->topPadding()); } else if (qobject_cast<QQuickGrid*>(positioner)) { int columns = 4; int rows = qCeil(model->count() / qreal(columns)); @@ -886,20 +1372,20 @@ void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel QVERIFY(finalAlignedRowItem); QCOMPARE(item->x(), finalAlignedRowItem->x()); } else { - QCOMPARE(item->x(), 0.0); + QCOMPARE(item->x(), p->leftPadding()); } if (i / columns > 0) { QQuickItem *prevRowLastItem = findItem<QQuickItem>(positioner, "wrapper", (i/columns * columns) - 1); QVERIFY(prevRowLastItem); QCOMPARE(item->y(), prevRowLastItem->y() + prevRowLastItem->height()); } else { - QCOMPARE(item->y(), 0.0); + QCOMPARE(item->y(), p->topPadding()); } } else if (qobject_cast<QQuickFlow*>(positioner)) { if (rowX + item->width() > positioner->width()) { QQuickItem *prevItem = findItem<QQuickItem>(positioner, "wrapper", i-1); QVERIFY(prevItem); - rowX = 0; + rowX = p->leftPadding(); rowY = prevItem->y() + prevItem->height(); } QCOMPARE(item->x(), rowX); @@ -942,6 +1428,183 @@ void tst_qquickpositioners::test_vertical() QCOMPARE(column->height(), 80.0); QCOMPARE(column->width(), 50.0); + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 87.0); + QCOMPARE(column->width(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); +} + +void tst_qquickpositioners::test_vertical_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("vertical.qml"))); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); + + QQuickItem *column = window->rootObject()->findChild<QQuickItem*>("column"); + QVERIFY(column); + QCOMPARE(column->height(), 80.0); + QCOMPARE(column->width(), 50.0); + + QQuickColumn *obj = qobject_cast<QQuickColumn*>(column); + QVERIFY(obj != 0); + + QCOMPARE(column->property("padding").toDouble(), 0.0); + QCOMPARE(column->property("topPadding").toDouble(), 0.0); + QCOMPARE(column->property("leftPadding").toDouble(), 0.0); + QCOMPARE(column->property("rightPadding").toDouble(), 0.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 0.0); + + obj->setPadding(1.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 1.0); + QCOMPARE(column->property("leftPadding").toDouble(), 1.0); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->height(), 82.0); + QCOMPARE(column->width(), 52.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 1.0); + QCOMPARE(two->y(), 51.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 61.0); + + obj->setTopPadding(2.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 1.0); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->height(), 83.0); + QCOMPARE(column->width(), 52.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 1.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 62.0); + + obj->setLeftPadding(3.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 3.0); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->width(), 54.0); + QCOMPARE(column->height(), 83.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); + + obj->setRightPadding(4.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 3.0); + QCOMPARE(column->property("rightPadding").toDouble(), 4.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->width(), 57.0); + QCOMPARE(column->height(), 83.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); + + obj->setBottomPadding(5.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 3.0); + QCOMPARE(column->property("rightPadding").toDouble(), 4.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(column->height(), 87.0); + QCOMPARE(column->width(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); + + obj->resetBottomPadding(); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(column->height(), 83.0); + QCOMPARE(column->width(), 57.0); + + obj->resetRightPadding(); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(column->width(), 54.0); + QCOMPARE(column->height(), 83.0); + + obj->resetLeftPadding(); + QCOMPARE(column->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(column->width(), 52.0); + QCOMPARE(column->height(), 83.0); + + obj->resetTopPadding(); + QCOMPARE(column->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(column->height(), 82.0); + QCOMPARE(column->width(), 52.0); + + obj->resetPadding(); + QCOMPARE(column->property("padding").toDouble(), 0.0); + QCOMPARE(column->property("topPadding").toDouble(), 0.0); + QCOMPARE(column->property("leftPadding").toDouble(), 0.0); + QCOMPARE(column->property("rightPadding").toDouble(), 0.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(column->height(), 80.0); + QCOMPARE(column->width(), 50.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); } void tst_qquickpositioners::test_vertical_spacing() @@ -968,6 +1631,22 @@ void tst_qquickpositioners::test_vertical_spacing() QCOMPARE(column->height(), 100.0); QCOMPARE(column->width(), 50.0); + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 107.0); + QCOMPARE(column->width(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 62.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 82.0); } void tst_qquickpositioners::test_vertical_animated() @@ -1019,6 +1698,66 @@ void tst_qquickpositioners::test_vertical_animated() } +void tst_qquickpositioners::test_vertical_animated_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("vertical-animated.qml"), false)); + + //Note that they animate in + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->y(), -100.0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->y(), -100.0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->y(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *column = window->rootObject()->findChild<QQuickItem*>("column"); + QVERIFY(column); + QCOMPARE(column->height(), 100.0); + QCOMPARE(column->width(), 50.0); + + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 107.0); + QCOMPARE(column->width(), 57.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet + QTRY_COMPARE(two->x(), 0.0); + QTRY_COMPARE(three->y(), 52.0); + QTRY_COMPARE(three->x(), 3.0); + + //Add 'two' + two->setVisible(true); + QTRY_COMPARE(two->isVisible(), true); + QTRY_COMPARE(column->height(), 157.0); + QTRY_COMPARE(column->width(), 57.0); + QTest::qWait(0);//Let the animation start + QVERIFY(two->y() >= -100.0 && two->y() < 52.0); + QVERIFY(three->y() >= 52.0 && three->y() < 102.0); + + QTRY_COMPARE(two->x(), 3.0); + QTRY_COMPARE(two->y(), 52.0); + QTRY_COMPARE(three->y(), 102.0); + +} + void tst_qquickpositioners::test_grid() { QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); @@ -1050,6 +1789,214 @@ void tst_qquickpositioners::test_grid() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 100.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); +} + +void tst_qquickpositioners::test_grid_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); + + QQuickGrid *grid = window->rootObject()->findChild<QQuickGrid*>("grid"); + QCOMPARE(grid->flow(), QQuickGrid::LeftToRight); + QCOMPARE(grid->width(), 100.0); + QCOMPARE(grid->height(), 100.0); + + QCOMPARE(grid->property("padding").toDouble(), 0.0); + QCOMPARE(grid->property("topPadding").toDouble(), 0.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 0.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 0.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 0.0); + + grid->setPadding(1.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 1.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 1.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->width(), 102.0); + QCOMPARE(grid->height(), 102.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 1.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 1.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 51.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 51.0); + + grid->setTopPadding(2.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 1.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->height(), 103.0); + QCOMPARE(grid->width(), 102.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 52.0); + + grid->setLeftPadding(3.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 3.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->width(), 104.0); + QCOMPARE(grid->height(), 103.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); + + grid->setRightPadding(4.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 3.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 4.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 103.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); + + grid->setBottomPadding(5.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 3.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 4.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(grid->height(), 107.0); + QCOMPARE(grid->width(), 107.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); + + grid->resetBottomPadding(); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->height(), 103.0); + QCOMPARE(grid->width(), 107.0); + + grid->resetRightPadding(); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->width(), 104.0); + QCOMPARE(grid->height(), 103.0); + + grid->resetLeftPadding(); + QCOMPARE(grid->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->width(), 102.0); + QCOMPARE(grid->height(), 103.0); + + grid->resetTopPadding(); + QCOMPARE(grid->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->height(), 102.0); + QCOMPARE(grid->width(), 102.0); + + grid->resetPadding(); + QCOMPARE(grid->property("padding").toDouble(), 0.0); + QCOMPARE(grid->property("topPadding").toDouble(), 0.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 0.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 0.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(grid->height(), 100.0); + QCOMPARE(grid->width(), 100.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); } void tst_qquickpositioners::test_grid_topToBottom() @@ -1083,6 +2030,26 @@ void tst_qquickpositioners::test_grid_topToBottom() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 120.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 127.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 102.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); } void tst_qquickpositioners::test_grid_rightToLeft() @@ -1118,6 +2085,44 @@ void tst_qquickpositioners::test_grid_rightToLeft() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 100.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + QCOMPARE(one->x(), 53.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 33.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 43.0); + QCOMPARE(five->y(), 52.0); + + grid->setProperty("topPadding", 0); + grid->setProperty("leftPadding", 0); + grid->setProperty("rightPadding", 0); + grid->setProperty("bottomPadding", 0); + grid->setProperty("padding", 0); + + QTRY_COMPARE(one->x(), 50.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 30.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 50.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 40.0); + QCOMPARE(five->y(), 50.0); + // Change the width of the grid and check that items stay to the right grid->setWidth(200); QTRY_COMPARE(one->x(), 150.0); @@ -1131,6 +2136,22 @@ void tst_qquickpositioners::test_grid_rightToLeft() QCOMPARE(five->x(), 140.0); QCOMPARE(five->y(), 50.0); + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(one->x(), 146.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 126.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 96.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 146.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 136.0); + QCOMPARE(five->y(), 52.0); } void tst_qquickpositioners::test_grid_spacing() @@ -1163,6 +2184,26 @@ void tst_qquickpositioners::test_grid_spacing() QCOMPARE(grid->width(), 128.0); QCOMPARE(grid->height(), 104.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 135.0); + QCOMPARE(grid->height(), 111.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 57.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 81.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 56.0); + QCOMPARE(five->x(), 57.0); + QCOMPARE(five->y(), 56.0); } void tst_qquickpositioners::test_grid_row_column_spacing() @@ -1195,6 +2236,26 @@ void tst_qquickpositioners::test_grid_row_column_spacing() QCOMPARE(grid->width(), 142.0); QCOMPARE(grid->height(), 107.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 149.0); + QCOMPARE(grid->height(), 114.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 64.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 95.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 59.0); + QCOMPARE(five->x(), 64.0); + QCOMPARE(five->y(), 59.0); } void tst_qquickpositioners::test_grid_animated() @@ -1281,6 +2342,100 @@ void tst_qquickpositioners::test_grid_animated() } +void tst_qquickpositioners::test_grid_animated_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", false); + + //Note that all animate in + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + QCOMPARE(one->y(), -100.0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + QCOMPARE(three->y(), -100.0); + + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QCOMPARE(four->x(), -100.0); + QCOMPARE(four->y(), -100.0); + + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + QCOMPARE(five->x(), -100.0); + QCOMPARE(five->y(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QVERIFY(grid); + QCOMPARE(grid->width(), 150.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->y(), -100.0); + QTRY_COMPARE(two->x(), -100.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(three->x(), 53.0); + QTRY_COMPARE(four->y(), 2.0); + QTRY_COMPARE(four->x(), 103.0); + QTRY_COMPARE(five->y(), 52.0); + QTRY_COMPARE(five->x(), 3.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + QCOMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 103.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 3.0); + QCOMPARE(five->y(), 52.0); + //Let the animation complete + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(three->x(), 103.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(four->x(), 3.0); + QTRY_COMPARE(four->y(), 52.0); + QTRY_COMPARE(five->x(), 53.0); + QTRY_COMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_grid_animated_rightToLeft() { QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false)); @@ -1365,6 +2520,100 @@ void tst_qquickpositioners::test_grid_animated_rightToLeft() } +void tst_qquickpositioners::test_grid_animated_rightToLeft_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", true); + + //Note that all animate in + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + QCOMPARE(one->y(), -100.0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + QCOMPARE(three->y(), -100.0); + + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QCOMPARE(four->x(), -100.0); + QCOMPARE(four->y(), -100.0); + + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + QCOMPARE(five->x(), -100.0); + QCOMPARE(five->y(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QVERIFY(grid); + QCOMPARE(grid->width(), 150.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(one->x(), 103.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->y(), -100.0); + QTRY_COMPARE(two->x(), -100.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(three->x(), 53.0); + QTRY_COMPARE(four->y(), 2.0); + QTRY_COMPARE(four->x(), 3.0); + QTRY_COMPARE(five->y(), 52.0); + QTRY_COMPARE(five->x(), 103.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + QCOMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(one->x(), 103.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 103.0); + QCOMPARE(five->y(), 52.0); + //Let the animation complete + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(one->x(), 103.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(three->x(), 3.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(four->x(), 103.0); + QTRY_COMPARE(four->y(), 52.0); + QTRY_COMPARE(five->x(), 53.0); + QTRY_COMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_grid_zero_columns() { QScopedPointer<QQuickView> window(createView(testFile("gridzerocolumns.qml"))); @@ -1395,6 +2644,26 @@ void tst_qquickpositioners::test_grid_zero_columns() QCOMPARE(grid->width(), 170.0); QCOMPARE(grid->height(), 60.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 177.0); + QCOMPARE(grid->height(), 67.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 123.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 3.0); + QCOMPARE(five->y(), 52.0); } void tst_qquickpositioners::test_grid_H_alignment() @@ -1476,6 +2745,95 @@ void tst_qquickpositioners::test_grid_H_alignment() } +void tst_qquickpositioners::test_grid_H_alignment_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); + + window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignHCenter); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 55.0); + QCOMPARE(five->y(), 50.0); + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QCOMPARE(grid->width(), 100.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignRight); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 63.0); + QCOMPARE(five->y(), 52.0); + QCOMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + window->rootObject()->setProperty("testRightToLeft", true); + + QCOMPARE(one->x(), 53.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 33.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 33.0); + QCOMPARE(five->y(), 52.0); + QCOMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignHCenter); + + QCOMPARE(one->x(), 53.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 33.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 38.0); + QCOMPARE(five->y(), 52.0); + QCOMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + +} + void tst_qquickpositioners::test_grid_V_alignment() { QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); @@ -1519,6 +2877,63 @@ void tst_qquickpositioners::test_grid_V_alignment() } +void tst_qquickpositioners::test_grid_V_alignment_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); + + window->rootObject()->setProperty("testVAlignment", QQuickGrid::AlignVCenter); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QCOMPARE(grid->width(), 100.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 17.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + window->rootObject()->setProperty("testVAlignment", QQuickGrid::AlignBottom); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 32.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 92.0); + +} + void tst_qquickpositioners::test_propertychanges() { QScopedPointer<QQuickView> window(createView(testFile("propertychangestest.qml"))); @@ -1599,6 +3014,28 @@ void tst_qquickpositioners::test_repeater() } +void tst_qquickpositioners::test_repeater_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("repeatertest-padding.qml"))); + + QQuickRectangle *one = findItem<QQuickRectangle>(window->contentItem(), "one"); + QVERIFY(one != 0); + + QQuickRectangle *two = findItem<QQuickRectangle>(window->contentItem(), "two"); + QVERIFY(two != 0); + + QQuickRectangle *three = findItem<QQuickRectangle>(window->contentItem(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 103.0); + QCOMPARE(three->y(), 2.0); + +} + void tst_qquickpositioners::test_flow() { QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); @@ -1632,6 +3069,219 @@ void tst_qquickpositioners::test_flow() QCOMPARE(flow->width(), 90.0); QCOMPARE(flow->height(), 120.0); + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->height(), 127.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); +} + +void tst_qquickpositioners::test_flow_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 70.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 70.0); + + QQuickItem *flow = window->rootObject()->findChild<QQuickItem*>("flow"); + QVERIFY(flow); + QCOMPARE(flow->width(), 90.0); + QCOMPARE(flow->height(), 120.0); + + QQuickFlow *obj = qobject_cast<QQuickFlow*>(flow); + QVERIFY(obj != 0); + + QCOMPARE(flow->property("padding").toDouble(), 0.0); + QCOMPARE(flow->property("topPadding").toDouble(), 0.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 0.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 0.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 0.0); + + obj->setPadding(1.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 1.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 1.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(flow->height(), 122.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 1.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 51.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 71.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 71.0); + + obj->setTopPadding(2.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 1.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 72.0); + + obj->setLeftPadding(3.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 3.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QCOMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + QTRY_COMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + obj->setRightPadding(4.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 3.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 4.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QCOMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + QTRY_COMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + obj->setBottomPadding(5.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 3.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 4.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(flow->height(), 127.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + obj->resetBottomPadding(); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetRightPadding(); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetLeftPadding(); + QCOMPARE(flow->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetTopPadding(); + QCOMPARE(flow->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 122.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetPadding(); + QCOMPARE(flow->property("padding").toDouble(), 0.0); + QCOMPARE(flow->property("topPadding").toDouble(), 0.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 0.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 0.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(flow->height(), 120.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 70.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 70.0); } void tst_qquickpositioners::test_flow_rightToLeft() @@ -1667,6 +3317,26 @@ void tst_qquickpositioners::test_flow_rightToLeft() QCOMPARE(flow->width(), 90.0); QCOMPARE(flow->height(), 120.0); + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->height(), 127.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 36.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 16.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 36.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 36.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 26.0); + QCOMPARE(five->y(), 72.0); } void tst_qquickpositioners::test_flow_topToBottom() @@ -1693,7 +3363,7 @@ void tst_qquickpositioners::test_flow_topToBottom() QCOMPARE(three->x(), 50.0); QCOMPARE(three->y(), 50.0); QCOMPARE(four->x(), 100.0); - QCOMPARE(four->y(), 00.0); + QCOMPARE(four->y(), 0.0); QCOMPARE(five->x(), 100.0); QCOMPARE(five->y(), 50.0); @@ -1721,6 +3391,79 @@ void tst_qquickpositioners::test_flow_topToBottom() } +void tst_qquickpositioners::test_flow_topToBottom_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest-toptobottom.qml"))); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 100.0); + QCOMPARE(five->y(), 50.0); + + QQuickItem *flow = window->rootObject()->findChild<QQuickItem*>("flow"); + QVERIFY(flow); + QCOMPARE(flow->height(), 90.0); + QCOMPARE(flow->width(), 150.0); + + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->width(), 157.0); + QCOMPARE(flow->height(), 90.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 103.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 103.0); + QCOMPARE(five->y(), 52.0); + + window->rootObject()->setProperty("testRightToLeft", true); + + QVERIFY(flow); + QTRY_COMPARE(flow->width(), 157.0); + QCOMPARE(flow->height(), 90.0); + + QCOMPARE(one->x(), 103.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 83.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 43.0); + QCOMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_flow_resize() { QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); @@ -1754,6 +3497,39 @@ void tst_qquickpositioners::test_flow_resize() } +void tst_qquickpositioners::test_flow_resize_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest-padding.qml"))); + + QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject()); + QVERIFY(root); + root->setWidth(125); + root->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(three->x(), 3.0); + QTRY_COMPARE(three->y(), 52.0); + QTRY_COMPARE(four->x(), 53.0); + QTRY_COMPARE(four->y(), 52.0); + QTRY_COMPARE(five->x(), 103.0); + QTRY_COMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_flow_resize_rightToLeft() { QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); @@ -1787,6 +3563,39 @@ void tst_qquickpositioners::test_flow_resize_rightToLeft() } +void tst_qquickpositioners::test_flow_resize_rightToLeft_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest-padding.qml"))); + + QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject()); + QVERIFY(root); + root->setWidth(125); + root->setProperty("testRightToLeft", true); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QTRY_VERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 71.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 21.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 11.0); + QCOMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_flow_implicit_resize() { QScopedPointer<QQuickView> window(createView(testFile("flow-testimplicitsize.qml"))); @@ -1815,6 +3624,44 @@ void tst_qquickpositioners::test_flow_implicit_resize() } +void tst_qquickpositioners::test_flow_implicit_resize_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flow-testimplicitsize.qml"))); + QVERIFY(window->rootObject() != 0); + + QQuickFlow *flow = window->rootObject()->findChild<QQuickFlow*>("flow"); + QVERIFY(flow != 0); + + QCOMPARE(flow->width(), 100.0); + QCOMPARE(flow->height(), 120.0); + + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->width(), 107.0); + QCOMPARE(flow->height(), 127.0); + + window->rootObject()->setProperty("flowLayout", 0); + QCOMPARE(flow->flow(), QQuickFlow::LeftToRight); + QCOMPARE(flow->width(), 227.0); + QCOMPARE(flow->height(), 57.0); + + window->rootObject()->setProperty("flowLayout", 1); + QCOMPARE(flow->flow(), QQuickFlow::TopToBottom); + QCOMPARE(flow->width(), 107.0); + QCOMPARE(flow->height(), 127.0); + + window->rootObject()->setProperty("flowLayout", 2); + QCOMPARE(flow->layoutDirection(), Qt::RightToLeft); + QCOMPARE(flow->width(), 227.0); + QCOMPARE(flow->height(), 57.0); + +} + void tst_qquickpositioners::test_conflictinganchors() { QQmlTestMessageHandler messageHandler; @@ -1924,7 +3771,9 @@ void tst_qquickpositioners::test_conflictinganchors() void tst_qquickpositioners::test_mirroring() { QList<QString> qmlFiles; - qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml"; + qmlFiles << "horizontal.qml" << "horizontal-padding.qml" + << "gridtest.qml" << "gridtest-padding.qml" + << "flowtest.qml" << "flowtest-padding.qml"; QList<QString> objectNames; objectNames << "one" << "two" << "three" << "four" << "five"; @@ -1942,8 +3791,8 @@ void tst_qquickpositioners::test_mirroring() // LTR != RTL foreach (const QString objectName, objectNames) { - // horizontal.qml only has three items - if (qmlFile == QString("horizontal.qml") && objectName == QString("four")) + // horizontal.qml and horizontal-padding.qml only have three items + if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four")) break; QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName); QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName); @@ -1957,8 +3806,8 @@ void tst_qquickpositioners::test_mirroring() // RTL == mirror foreach (const QString objectName, objectNames) { - // horizontal.qml only has three items - if (qmlFile == QString("horizontal.qml") && objectName == QString("four")) + // horizontal.qml and horizontal-padding.qml only have three items + if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four")) break; QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName); QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName); @@ -1978,8 +3827,8 @@ void tst_qquickpositioners::test_mirroring() // LTR == RTL + mirror foreach (const QString objectName, objectNames) { - // horizontal.qml only has three items - if (qmlFile == QString("horizontal.qml") && objectName == QString("four")) + // horizontal.qml and horizontal-padding.qml only have three items + if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four")) break; QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName); QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName); @@ -1998,12 +3847,63 @@ void tst_qquickpositioners::test_allInvisible() QQuickRow *row = window->rootObject()->findChild<QQuickRow*>("row"); QVERIFY(row != 0); - QVERIFY(row->width() == 0); - QVERIFY(row->height() == 0); + QCOMPARE(row->width(), qreal(0)); + QCOMPARE(row->height(), qreal(0)); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->height(), 7.0); + QCOMPARE(row->width(), 7.0); + QQuickColumn *column = window->rootObject()->findChild<QQuickColumn*>("column"); QVERIFY(column != 0); - QVERIFY(column->width() == 0); - QVERIFY(column->height() == 0); + QCOMPARE(column->width(), qreal(0)); + QCOMPARE(column->height(), qreal(0)); + + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 7.0); + QCOMPARE(column->width(), 7.0); + + QQuickGrid *grid = window->rootObject()->findChild<QQuickGrid*>("grid"); + QVERIFY(grid != 0); + QCOMPARE(grid->width(), qreal(0)); + QCOMPARE(grid->height(), qreal(0)); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->height(), 7.0); + QCOMPARE(grid->width(), 7.0); + + QQuickFlow *flow = window->rootObject()->findChild<QQuickFlow*>("flow"); + QVERIFY(flow != 0); + QCOMPARE(flow->width(), qreal(0)); + QCOMPARE(flow->height(), qreal(0)); + + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->height(), 7.0); + QCOMPARE(flow->width(), 7.0); } void tst_qquickpositioners::test_attachedproperties() @@ -2017,30 +3917,30 @@ void tst_qquickpositioners::test_attachedproperties() QVERIFY(greenRect != 0); int posIndex = greenRect->property("posIndex").toInt(); - QVERIFY(posIndex == 0); + QCOMPARE(posIndex, 0); bool isFirst = greenRect->property("isFirstItem").toBool(); - QVERIFY(isFirst == true); + QVERIFY(isFirst); bool isLast = greenRect->property("isLastItem").toBool(); - QVERIFY(isLast == false); + QVERIFY(!isLast); QQuickRectangle *yellowRect = window->rootObject()->findChild<QQuickRectangle *>("yellowRect"); QVERIFY(yellowRect != 0); posIndex = yellowRect->property("posIndex").toInt(); - QVERIFY(posIndex == -1); + QCOMPARE(posIndex, -1); isFirst = yellowRect->property("isFirstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = yellowRect->property("isLastItem").toBool(); - QVERIFY(isLast == false); + QVERIFY(!isLast); yellowRect->metaObject()->invokeMethod(yellowRect, "onDemandPositioner"); posIndex = yellowRect->property("posIndex").toInt(); - QVERIFY(posIndex == 1); + QCOMPARE(posIndex, 1); isFirst = yellowRect->property("isFirstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = yellowRect->property("isLastItem").toBool(); - QVERIFY(isLast == true); + QVERIFY(isLast); } @@ -2066,46 +3966,46 @@ void tst_qquickpositioners::test_attachedproperties_dynamic() QVERIFY(rect0 != 0); int posIndex = rect0->property("index").toInt(); - QVERIFY(posIndex == 0); + QCOMPARE(posIndex, 0); bool isFirst = rect0->property("firstItem").toBool(); - QVERIFY(isFirst == true); + QVERIFY(isFirst); bool isLast = rect0->property("lastItem").toBool(); - QVERIFY(isLast == false); + QVERIFY(!isLast); QQuickRectangle *rect1 = window->rootObject()->findChild<QQuickRectangle *>("rect1"); QVERIFY(rect1 != 0); posIndex = rect1->property("index").toInt(); - QVERIFY(posIndex == 1); + QCOMPARE(posIndex, 1); isFirst = rect1->property("firstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = rect1->property("lastItem").toBool(); - QVERIFY(isLast == true); + QVERIFY(isLast); row->metaObject()->invokeMethod(row, "createSubRect"); - QTRY_VERIFY(rect1->property("index").toInt() == 1); - QTRY_VERIFY(rect1->property("firstItem").toBool() == false); - QTRY_VERIFY(rect1->property("lastItem").toBool() == false); + QTRY_COMPARE(rect1->property("index").toInt(), 1); + QTRY_VERIFY(!rect1->property("firstItem").toBool()); + QTRY_VERIFY(!rect1->property("lastItem").toBool()); QQuickRectangle *rect2 = window->rootObject()->findChild<QQuickRectangle *>("rect2"); QVERIFY(rect2 != 0); posIndex = rect2->property("index").toInt(); - QVERIFY(posIndex == 2); + QCOMPARE(posIndex, 2); isFirst = rect2->property("firstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = rect2->property("lastItem").toBool(); - QVERIFY(isLast == true); + QVERIFY(isLast); row->metaObject()->invokeMethod(row, "destroySubRect"); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QTRY_VERIFY(rect1->property("index").toInt() == 1); - QTRY_VERIFY(rect1->property("firstItem").toBool() == false); - QTRY_VERIFY(rect1->property("lastItem").toBool() == true); + QTRY_COMPARE(rect1->property("index").toInt(), 1); + QTRY_VERIFY(!rect1->property("firstItem").toBool()); + QTRY_VERIFY(rect1->property("lastItem").toBool()); } @@ -2138,7 +4038,7 @@ void tst_qquickpositioners::matchIndexLists(const QVariantList &indexLists, cons void tst_qquickpositioners::matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes) { for (QVariantMap::const_iterator it = items.begin(); it != items.end(); ++it) { - QVERIFY(it.value().type() == QVariant::Int); + QCOMPARE(it.value().type(), QVariant::Int); QString name = it.key(); int itemIndex = it.value().toInt(); QVERIFY2(expectedIndexes.contains(itemIndex), QTest::toString(QString("Index %1 not found in expectedIndexes").arg(itemIndex))); @@ -2152,7 +4052,7 @@ void tst_qquickpositioners::matchItemsAndIndexes(const QVariantMap &items, const void tst_qquickpositioners::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { for (int i=0; i<itemLists.count(); i++) { - QVERIFY(itemLists[i].type() == QVariant::List); + QCOMPARE(itemLists[i].type(), QVariant::List); QVariantList current = itemLists[i].toList(); for (int j=0; j<current.count(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); diff --git a/tests/auto/quick/qquickrepeater/data/modelCleared.qml b/tests/auto/quick/qquickrepeater/data/modelCleared.qml new file mode 100644 index 0000000000..1269e9bdf2 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/modelCleared.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Row { + spacing: 2 + height: 100 + + Repeater { + id: repeater + objectName: "repeater" + model: 10 + Rectangle { + color: "green" + width: 10; height: 50 + anchors.bottom: parent.bottom + } + } +} diff --git a/tests/auto/quick/qquickrepeater/data/objectmodel.qml b/tests/auto/quick/qquickrepeater/data/objectmodel.qml new file mode 100644 index 0000000000..780f53e802 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/objectmodel.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 +import QtQml.Models 2.1 + +Row { + width: 360 + height: 360 + + Repeater { + objectName: "repeater" + model: ObjectModel { + Rectangle { + width: 20 + height: 20 + color: "red" + } + Rectangle { + width: 20 + height: 20 + color: "green" + } + Rectangle { + width: 20 + height: 20 + color: "blue" + } + } + } +} diff --git a/tests/auto/quick/qquickrepeater/data/stackingorder.qml b/tests/auto/quick/qquickrepeater/data/stackingorder.qml new file mode 100644 index 0000000000..41dadca0df --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/stackingorder.qml @@ -0,0 +1,38 @@ +import QtQuick 2.0 + +Item { + id: root + property bool stackingOrderOk: true + + function verifyStackingOrder() { + var len = children.length + for (var i = 0; i < len; ++i) { + var expectedName; + if (i === 0) { + expectedName = "first" + } else if (i === len - 2) { + expectedName = "repeater" + } else if (i === len - 1) { + expectedName = "last" + } else { + expectedName = "middle" + (i - 1) + } + if (children[i].objectName !== expectedName) + stackingOrderOk = false + } + } + Item { + objectName: "first" + } + Repeater { + objectName: "repeater" + model: 1 + Item { + objectName: "middle" + index + Component.onCompleted: { verifyStackingOrder();} + } + } + Item { + objectName: "last" + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index b2039bd323..a34001b23a 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -41,6 +41,7 @@ #include <private/qquickrepeater_p.h> #include <QtQuick/private/qquicktext_p.h> #include <QtQml/private/qqmllistmodel_p.h> +#include <QtQml/private/qqmlobjectmodel_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -67,6 +68,7 @@ private slots: void resetModel(); void modelChanged(); void modelReset(); + void modelCleared(); void properties(); void asynchronous(); void initParent(); @@ -76,6 +78,8 @@ private slots: void jsArrayChange(); void clearRemovalOrder(); void destroyCount(); + void stackingOrder(); + void objectModel(); }; class TestObject : public QObject @@ -128,7 +132,7 @@ void tst_QQuickRepeater::numberModel() QVERIFY(!repeater->itemAt(repeater->count())); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); delete testObject; delete window; @@ -440,19 +444,19 @@ void tst_QQuickRepeater::itemModel() testObject->setUseModel(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); QCOMPARE(container->childItems().count(), 4); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(0))->objectName() == "item1"); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(1))->objectName() == "item2"); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(2))->objectName() == "item3"); - QVERIFY(container->childItems().at(3) == repeater); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(0))->objectName(), QLatin1String("item1")); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(1))->objectName(), QLatin1String("item2")); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(2))->objectName(), QLatin1String("item3")); + QCOMPARE(container->childItems().at(3), repeater); QMetaObject::invokeMethod(window->rootObject(), "switchModel"); QCOMPARE(container->childItems().count(), 3); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(0))->objectName() == "item4"); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(1))->objectName() == "item5"); - QVERIFY(container->childItems().at(2) == repeater); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(0))->objectName(), QLatin1String("item4")); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(1))->objectName(), QLatin1String("item5")); + QCOMPARE(container->childItems().at(2), repeater); testObject->setUseModel(false); QCOMPARE(container->childItems().count(), 1); @@ -631,6 +635,26 @@ void tst_QQuickRepeater::modelReset() QCOMPARE(addedSpy.count(), 0); } +// QTBUG-46828 +void tst_QQuickRepeater::modelCleared() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("modelCleared.qml")); + + QQuickItem *rootObject = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(rootObject); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(rootObject, "repeater"); + QVERIFY(repeater); + + // verify no error messages when the model is cleared and the items are destroyed + QQmlTestMessageHandler messageHandler; + repeater->setModel(0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); + + delete rootObject; +} + void tst_QQuickRepeater::properties() { QQmlEngine engine; @@ -788,8 +812,8 @@ void tst_QQuickRepeater::invalidContextCrash() repeater->setParent(root.data()); QCOMPARE(root->children().count(), 2); - QVERIFY(root->children().at(0) == model); - QVERIFY(root->children().at(1) == repeater); + QCOMPARE(root->children().at(0), model); + QCOMPARE(root->children().at(1), repeater); // Delete the root object, which will invalidate/delete the QML context // and then delete the child QObjects, which may try to access the context. @@ -894,6 +918,82 @@ void tst_QQuickRepeater::destroyCount() QCOMPARE(repeater->property("componentCount").toInt(), 4); } +void tst_QQuickRepeater::stackingOrder() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("stackingorder.qml")); + + QQuickItem *rootObject = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(rootObject); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(rootObject, "repeater"); + QVERIFY(repeater); + int count = 1; + do { + bool stackingOrderOk = rootObject->property("stackingOrderOk").toBool(); + QVERIFY(stackingOrderOk); + repeater->setModel(QVariant(++count)); + } while (count < 3); +} + +static bool compareObjectModel(QQuickRepeater *repeater, QQmlObjectModel *model) +{ + if (repeater->count() != model->count()) + return false; + for (int i = 0; i < repeater->count(); ++i) { + if (repeater->itemAt(i) != model->get(i)) + return false; + } + return true; +} + +void tst_QQuickRepeater::objectModel() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("objectmodel.qml")); + + QQuickItem *positioner = qobject_cast<QQuickItem *>(component.create()); + QVERIFY(positioner); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(positioner, "repeater"); + QVERIFY(repeater); + + QQmlObjectModel *model = repeater->model().value<QQmlObjectModel *>(); + QVERIFY(model); + + QVERIFY(repeater->itemAt(0)); + QVERIFY(repeater->itemAt(1)); + QVERIFY(repeater->itemAt(2)); + QCOMPARE(repeater->itemAt(0)->property("color").toString(), QColor("red").name()); + QCOMPARE(repeater->itemAt(1)->property("color").toString(), QColor("green").name()); + QCOMPARE(repeater->itemAt(2)->property("color").toString(), QColor("blue").name()); + + QQuickItem *item0 = new QQuickItem(positioner); + item0->setSize(QSizeF(20, 20)); + model->append(item0); + QCOMPARE(model->count(), 4); + QVERIFY(compareObjectModel(repeater, model)); + + QQuickItem *item1 = new QQuickItem(positioner); + item1->setSize(QSizeF(20, 20)); + model->insert(0, item1); + QCOMPARE(model->count(), 5); + QVERIFY(compareObjectModel(repeater, model)); + + model->move(1, 2, 3); + QVERIFY(compareObjectModel(repeater, model)); + + model->remove(2, 2); + QCOMPARE(model->count(), 3); + QVERIFY(compareObjectModel(repeater, model)); + + model->clear(); + QCOMPARE(model->count(), 0); + QCOMPARE(repeater->count(), 0); + + delete positioner; +} + QTEST_MAIN(tst_QQuickRepeater) #include "tst_qquickrepeater.moc" diff --git a/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp b/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp index 04fdc4ecf7..10e91c455b 100644 --- a/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp +++ b/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp @@ -130,9 +130,9 @@ void tst_qquicksmoothedanimation::simpleAnimation() animation->setProperty("x"); animation->setTo(200); animation->setDuration(250); - QVERIFY(animation->target() == rect); - QVERIFY(animation->property() == "x"); - QVERIFY(animation->to() == 200); + QCOMPARE(animation->target(), rect); + QCOMPARE(animation->property(), QLatin1String("x")); + QCOMPARE(animation->to(), qreal(200)); animation->start(); QVERIFY(animation->isRunning()); QTest::qWait(animation->duration()); @@ -147,7 +147,7 @@ void tst_qquicksmoothedanimation::simpleAnimation() QVERIFY(animation->isRunning()); QVERIFY(animation->isPaused()); animation->setCurrentTime(125); - QVERIFY(animation->currentTime() == 125); + QCOMPARE(animation->currentTime(), 125); QCOMPARE(rect->x(), qreal(100)); } diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 6c42a7a0ee..a375a55877 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -1241,7 +1241,7 @@ void tst_qquickstates::deletingState() QVERIFY(state != 0); delete state; - QVERIFY(sg->findState("blue") == 0); + QVERIFY(!sg->findState("blue")); //### should we warn that state doesn't exist sg->setState("blue"); @@ -1317,7 +1317,7 @@ void tst_qquickstates::illegalObjectCreation() QQmlComponent component(&engine, testFileUrl("illegalObj.qml")); QList<QQmlError> errors = component.errors(); - QVERIFY(errors.count() == 1); + QCOMPARE(errors.count(), 1); const QQmlError &error = errors.at(0); QCOMPARE(error.line(), 9); QCOMPARE(error.column(), 23); @@ -1637,7 +1637,7 @@ void tst_qquickstates::QTBUG_38492() void tst_qquickstates::revertListMemoryLeak() { - QWeakPointer<QQmlAbstractBinding> weakPtr; + QQmlAbstractBinding::Ptr bindingPtr; { QQmlEngine engine; @@ -1651,12 +1651,12 @@ void tst_qquickstates::revertListMemoryLeak() QQmlAbstractBinding *binding = state->bindingInRevertList(item, "height"); QVERIFY(binding); - weakPtr = QQmlAbstractBinding::getPointer(binding); - QVERIFY(!weakPtr.toStrongRef().isNull()); + bindingPtr = binding; + QVERIFY(bindingPtr->ref > 1); delete item; } - QVERIFY(weakPtr.toStrongRef().isNull()); + QVERIFY(bindingPtr->ref == 1); } QTEST_MAIN(tst_qquickstates) diff --git a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp index 816440b191..4678f5fbb9 100644 --- a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp +++ b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp @@ -171,16 +171,16 @@ void tst_qquickstyledtext::textOutput() QCOMPARE(layout.text(), output); - QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats(); + const QVector<QTextLayout::FormatRange> layoutFormats = layout.formats(); QCOMPARE(layoutFormats.count(), formats.count()); for (int i = 0; i < formats.count(); ++i) { QCOMPARE(layoutFormats.at(i).start, formats.at(i).start); QCOMPARE(layoutFormats.at(i).length, formats.at(i).length); if (formats.at(i).type & Format::Bold) - QVERIFY(layoutFormats.at(i).format.fontWeight() == QFont::Bold); + QCOMPARE(layoutFormats.at(i).format.fontWeight(), int(QFont::Bold)); else - QVERIFY(layoutFormats.at(i).format.fontWeight() == QFont::Normal); + QCOMPARE(layoutFormats.at(i).format.fontWeight(), int(QFont::Normal)); QVERIFY(layoutFormats.at(i).format.fontItalic() == bool(formats.at(i).type & Format::Italic)); QVERIFY(layoutFormats.at(i).format.fontUnderline() == bool(formats.at(i).type & Format::Underline)); } @@ -200,7 +200,7 @@ void tst_qquickstyledtext::anchors() QCOMPARE(layout.text(), output); - QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats(); + const QVector<QTextLayout::FormatRange> layoutFormats = layout.formats(); QCOMPARE(layoutFormats.count(), formats.count()); for (int i = 0; i < formats.count(); ++i) { diff --git a/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp b/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp index 5c0c5fd8d3..a4c4987ad9 100644 --- a/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp +++ b/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp @@ -97,7 +97,7 @@ void tst_qquicksystempalette::inactivePalette() QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create()); QVERIFY(object != 0); - QVERIFY(object->colorGroup() == QQuickSystemPalette::Inactive); + QCOMPARE(object->colorGroup(), QQuickSystemPalette::Inactive); QPalette palette; palette.setCurrentColorGroup(QPalette::Inactive); @@ -127,7 +127,7 @@ void tst_qquicksystempalette::disabledPalette() QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create()); QVERIFY(object != 0); - QVERIFY(object->colorGroup() == QQuickSystemPalette::Disabled); + QCOMPARE(object->colorGroup(), QQuickSystemPalette::Disabled); QPalette palette; palette.setCurrentColorGroup(QPalette::Disabled); diff --git a/tests/auto/quick/qquicktext/BLACKLIST b/tests/auto/quick/qquicktext/BLACKLIST new file mode 100644 index 0000000000..0c65f1e245 --- /dev/null +++ b/tests/auto/quick/qquicktext/BLACKLIST @@ -0,0 +1,4 @@ +[dependentImplicitSizes] +* +[mouseSelection] +* diff --git a/tests/auto/quick/qquicktext/data/padding.qml b/tests/auto/quick/qquicktext/data/padding.qml new file mode 100644 index 0000000000..ab0a37d041 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/padding.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 + +Text { + width: 200; height: 200 + text: "Hello Qt" + + padding: 10 + topPadding: 20 + leftPadding: 30 + rightPadding: 40 + bottomPadding: 50 +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index eb9f7529fe..c1f10f9788 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -148,6 +148,8 @@ private slots: void growFromZeroWidth(); + void padding(); + private: QStringList standard; QStringList richText; @@ -240,7 +242,7 @@ void tst_qquicktext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), QString("")); - QVERIFY(textObject->width() == 0); + QCOMPARE(textObject->width(), qreal(0)); delete textObject; } @@ -357,7 +359,7 @@ void tst_qquicktext::width() QVERIFY(doc != 0); QCOMPARE(int(textObject->width()), int(doc->idealWidth())); - QVERIFY(textObject->textFormat() == QQuickText::RichText); + QCOMPARE(textObject->textFormat(), QQuickText::RichText); delete textObject; } @@ -374,7 +376,7 @@ void tst_qquicktext::wrap() textHeight = textObject->height(); QVERIFY(textObject != 0); - QVERIFY(textObject->wrapMode() == QQuickText::WordWrap); + QCOMPARE(textObject->wrapMode(), QQuickText::WordWrap); QCOMPARE(textObject->width(), 300.); delete textObject; @@ -657,11 +659,11 @@ void tst_qquicktext::textFormat() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickText::RichText); + QCOMPARE(textObject->textFormat(), QQuickText::RichText); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->richText == true); + QVERIFY(textPrivate->richText); delete textObject; } @@ -671,11 +673,11 @@ void tst_qquicktext::textFormat() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickText::AutoText); + QCOMPARE(textObject->textFormat(), QQuickText::AutoText); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->styledText == true); + QVERIFY(textPrivate->styledText); delete textObject; } @@ -685,7 +687,7 @@ void tst_qquicktext::textFormat() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickText::PlainText); + QCOMPARE(textObject->textFormat(), QQuickText::PlainText); delete textObject; } @@ -2048,7 +2050,7 @@ void tst_qquicktext::embeddedImages_data() QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found"; - QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; + QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } void tst_qquicktext::embeddedImages() @@ -2058,6 +2060,14 @@ void tst_qquicktext::embeddedImages() QFETCH(QUrl, qmlfile); QFETCH(QString, error); +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + if (qstrcmp(QTest::currentDataTag(), "remote") == 0 + || qstrcmp(QTest::currentDataTag(), "remote-error") == 0 + || qstrcmp(QTest::currentDataTag(), "remote-relative") == 0) { + QSKIP("Remote tests cause occasional hangs in the CI system -- QTBUG-45655"); + } +#endif + TestHTTPServer server; QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("http")); @@ -2126,8 +2136,8 @@ void tst_qquicktext::lineHeight() QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); - QVERIFY(myText->lineHeight() == 1); - QVERIFY(myText->lineHeightMode() == QQuickText::ProportionalHeight); + QCOMPARE(myText->lineHeight(), qreal(1)); + QCOMPARE(myText->lineHeightMode(), QQuickText::ProportionalHeight); qreal h = myText->height(); myText->setLineHeight(1.5); @@ -2197,12 +2207,12 @@ void tst_qquicktext::implicitSize() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject->width() < textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); QCOMPARE(textObject->property("iWidth").toReal(), textObject->implicitWidth()); textObject->resetWidth(); - QVERIFY(textObject->width() == textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->width(), textObject->implicitWidth()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); delete textObject; } @@ -2738,7 +2748,7 @@ void tst_qquicktext::lineLaidOut() QVERIFY(r.x() == r.width() + 30); if (i >= 60) { QVERIFY(r.x() == r.width() * 2 + 60); - QVERIFY(r.height() == 20); + QCOMPARE(r.height(), qreal(20)); } } @@ -2916,7 +2926,7 @@ void tst_qquicktext::imgTagsAlign() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->height() == imgHeight); + QCOMPARE(textObject->height(), qreal(imgHeight)); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); @@ -2927,7 +2937,7 @@ void tst_qquicktext::imgTagsAlign() else if (align == "middle") QVERIFY(br.y() == imgHeight / 2.0 - br.height() / 2.0); else if (align == "top") - QVERIFY(br.y() == 0); + QCOMPARE(br.y(), qreal(0)); delete textObject; } @@ -2941,11 +2951,11 @@ void tst_qquicktext::imgTagsMultipleImages() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->height() == 85); + QCOMPARE(textObject->height(), qreal(85)); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->extra->visibleImgTags.count() == 2); + QCOMPARE(textPrivate->extra->visibleImgTags.count(), 2); delete textObject; } @@ -2958,9 +2968,9 @@ void tst_qquicktext::imgTagsElide() QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(myText); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->extra->visibleImgTags.count() == 0); + QCOMPARE(textPrivate->extra->visibleImgTags.count(), 0); myText->setMaximumLineCount(20); - QTRY_VERIFY(textPrivate->extra->visibleImgTags.count() == 1); + QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); delete myText; delete window; @@ -2978,16 +2988,16 @@ void tst_qquicktext::imgTagsUpdates() QVERIFY(textPrivate != 0); myText->setText("This is a heart<img src=\"images/heart200.png\">."); - QVERIFY(textPrivate->extra->visibleImgTags.count() == 1); - QVERIFY(spy.count() == 1); + QCOMPARE(textPrivate->extra->visibleImgTags.count(), 1); + QCOMPARE(spy.count(), 1); myText->setMaximumLineCount(2); myText->setText("This is another heart<img src=\"images/heart200.png\">."); - QTRY_VERIFY(textPrivate->extra->visibleImgTags.count() == 1); + QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); // if maximumLineCount is set and the img tag doesn't have an explicit size // we relayout twice. - QVERIFY(spy.count() == 3); + QCOMPARE(spy.count(), 3); delete myText; delete window; @@ -3634,19 +3644,19 @@ Q_DECLARE_METATYPE(ExpectedBaseline) static qreal expectedBaselineTop(QQuickText *item) { QFontMetricsF fm(item->font()); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } static qreal expectedBaselineBottom(QQuickText *item) { QFontMetricsF fm(item->font()); - return item->height() - item->contentHeight() + fm.ascent(); + return item->height() - item->contentHeight() - item->bottomPadding() + fm.ascent(); } static qreal expectedBaselineCenter(QQuickText *item) { QFontMetricsF fm(item->font()); - return ((item->height() - item->contentHeight()) / 2) + fm.ascent(); + return ((item->height() - item->contentHeight() - item->topPadding() - item->bottomPadding()) / 2) + fm.ascent() + item->topPadding(); } static qreal expectedBaselineBold(QQuickText *item) @@ -3654,7 +3664,7 @@ static qreal expectedBaselineBold(QQuickText *item) QFont font = item->font(); font.setBold(true); QFontMetricsF fm(font); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } static qreal expectedBaselineImage(QQuickText *item) @@ -3664,13 +3674,13 @@ static qreal expectedBaselineImage(QQuickText *item) // or image height - line height and the baseline is line position + ascent. Because // QTextLine's height is rounded up this can give slightly different results to image height // - descent. - return 181 - qCeil(fm.height()) + fm.ascent(); + return 181 - qCeil(fm.height()) + fm.ascent() + item->topPadding(); } static qreal expectedBaselineCustom(QQuickText *item) { QFontMetricsF fm(item->font()); - return 16 + fm.ascent(); + return 16 + fm.ascent() + item->topPadding(); } static qreal expectedBaselineScaled(QQuickText *item) @@ -3689,11 +3699,11 @@ static qreal expectedBaselineScaled(QQuickText *item) if (width < item->width()) { QFontMetricsF fm(layout.font()); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } font.setPointSize(font.pointSize() - 1); } while (font.pointSize() > 0); - return 0; + return item->topPadding(); } static qreal expectedBaselineFixedBottom(QQuickText *item) @@ -3702,7 +3712,7 @@ static qreal expectedBaselineFixedBottom(QQuickText *item) qreal dy = item->text().contains(QLatin1Char('\n')) ? 160 : 180; - return dy + fm.ascent(); + return dy + fm.ascent() - item->bottomPadding(); } static qreal expectedBaselineProportionalBottom(QQuickText *item) @@ -3711,7 +3721,7 @@ static qreal expectedBaselineProportionalBottom(QQuickText *item) qreal dy = item->text().contains(QLatin1Char('\n')) ? 200 - (qCeil(fm.height()) * 3) : 200 - (qCeil(fm.height()) * 1.5); - return dy + fm.ascent(); + return dy + fm.ascent() - item->bottomPadding(); } void tst_qquicktext::baselineOffset_data() @@ -3818,6 +3828,102 @@ void tst_qquicktext::baselineOffset_data() << QByteArray("height: 200; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignBottom") << &expectedBaselineProportionalBottom << &expectedBaselineProportionalBottom; + + QTest::newRow("top align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; verticalAlignment: Text.AlignTop") + << &expectedBaselineTop + << &expectedBaselineTop; + QTest::newRow("bottom align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; verticalAlignment: Text.AlignBottom") + << &expectedBaselineBottom + << &expectedBaselineBottom; + QTest::newRow("center align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; verticalAlignment: Text.AlignVCenter") + << &expectedBaselineCenter + << &expectedBaselineCenter; + + QTest::newRow("bold width padding") + << "<b>hello world</b>" + << "<b>hello<br/>world</b>" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20") + << &expectedBaselineTop + << &expectedBaselineBold; + + QTest::newRow("richText with padding") + << "<b>hello world</b>" + << "<b>hello<br/>world</b>" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; textFormat: Text.RichText") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("elided with padding") + << "hello world" + << "hello\nworld" + << QByteArray("width: 20; height: 8; topPadding: 10; bottomPadding: 20; elide: Text.ElideRight") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("elided bottom align with padding") + << "hello world" + << "hello\nworld!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + << QByteArray("width: 200; height: 200; topPadding: 10; bottomPadding: 20; elide: Text.ElideRight; verticalAlignment: Text.AlignBottom") + << &expectedBaselineBottom + << &expectedBaselineBottom; + + QTest::newRow("image with padding") + << "hello <img src=\"images/heart200.png\" /> world" + << "hello <img src=\"images/heart200.png\" /><br/>world" + << QByteArray("height: 200\n; topPadding: 10; bottomPadding: 20; baseUrl: \"") + testFileUrl("reference").toEncoded() + QByteArray("\"") + << &expectedBaselineImage + << &expectedBaselineTop; + + QTest::newRow("customLine with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; onLineLaidOut: line.y += 16") + << &expectedBaselineCustom + << &expectedBaselineCustom; + + QTest::newRow("scaled font with padding") + << "hello world" + << "hello\nworld" + << QByteArray("width: 200; topPadding: 10; bottomPadding: 20; minimumPointSize: 1; font.pointSize: 64; fontSizeMode: Text.HorizontalFit") + << &expectedBaselineScaled + << &expectedBaselineTop; + + QTest::newRow("fixed line height top align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.FixedHeight; lineHeight: 20; verticalAlignment: Text.AlignTop") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("fixed line height bottom align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.FixedHeight; lineHeight: 20; verticalAlignment: Text.AlignBottom") + << &expectedBaselineFixedBottom + << &expectedBaselineFixedBottom; + + QTest::newRow("proportional line height top align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignTop") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("proportional line height bottom align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignBottom") + << &expectedBaselineProportionalBottom + << &expectedBaselineProportionalBottom; } void tst_qquicktext::baselineOffset() @@ -3830,7 +3936,7 @@ void tst_qquicktext::baselineOffset() QQmlComponent component(&engine); component.setData( - "import QtQuick 2.0\n" + "import QtQuick 2.6\n" "Text {\n" + bindings + "\n" "}", QUrl()); @@ -3972,6 +4078,84 @@ void tst_qquicktext::growFromZeroWidth() QVERIFY(text->lineCount() > 3); } +void tst_qquicktext::padding() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("padding.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickText *obj = qobject_cast<QQuickText*>(root); + QVERIFY(obj != 0); + + qreal cw = obj->contentWidth(); + qreal ch = obj->contentHeight(); + + QVERIFY(cw > 0); + QVERIFY(ch > 0); + + QCOMPARE(obj->topPadding(), 20.0); + QCOMPARE(obj->leftPadding(), 30.0); + QCOMPARE(obj->rightPadding(), 40.0); + QCOMPARE(obj->bottomPadding(), 50.0); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setTopPadding(2.25); + QCOMPARE(obj->topPadding(), 2.25); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setLeftPadding(3.75); + QCOMPARE(obj->leftPadding(), 3.75); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setRightPadding(4.4); + QCOMPARE(obj->rightPadding(), 4.4); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setBottomPadding(1.11); + QCOMPARE(obj->bottomPadding(), 1.11); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setText("Qt"); + QVERIFY(obj->contentWidth() < cw); + QCOMPARE(obj->contentHeight(), ch); + cw = obj->contentWidth(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setFont(QFont("Courier", 96)); + QVERIFY(obj->contentWidth() > cw); + QVERIFY(obj->contentHeight() > ch); + cw = obj->contentWidth(); + ch = obj->contentHeight(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->resetTopPadding(); + QCOMPARE(obj->topPadding(), 10.0); + obj->resetLeftPadding(); + QCOMPARE(obj->leftPadding(), 10.0); + obj->resetRightPadding(); + QCOMPARE(obj->rightPadding(), 10.0); + obj->resetBottomPadding(); + QCOMPARE(obj->bottomPadding(), 10.0); + + obj->resetPadding(); + QCOMPARE(obj->padding(), 0.0); + QCOMPARE(obj->topPadding(), 0.0); + QCOMPARE(obj->leftPadding(), 0.0); + QCOMPARE(obj->rightPadding(), 0.0); + QCOMPARE(obj->bottomPadding(), 0.0); + + delete root; +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" diff --git a/tests/auto/quick/qquicktextedit/BLACKLIST b/tests/auto/quick/qquicktextedit/BLACKLIST new file mode 100644 index 0000000000..492d81531a --- /dev/null +++ b/tests/auto/quick/qquicktextedit/BLACKLIST @@ -0,0 +1,2 @@ +[mouseSelection] +* diff --git a/tests/auto/quick/qquicktextedit/data/padding.qml b/tests/auto/quick/qquicktextedit/data/padding.qml new file mode 100644 index 0000000000..f4852bec8b --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/padding.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 + +TextEdit { + width: 200; height: 200 + text: "Hello Qt" + + padding: 10 + topPadding: 20 + leftPadding: 30 + rightPadding: 40 + bottomPadding: 50 +} diff --git a/tests/auto/quick/qquicktextedit/data/signal_editingfinished.qml b/tests/auto/quick/qquicktextedit/data/signal_editingfinished.qml new file mode 100644 index 0000000000..b5caab5e7c --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/signal_editingfinished.qml @@ -0,0 +1,13 @@ +import QtQuick 2.6 + +Item { + property QtObject input1: input1 + property QtObject input2: input2 + + width: 800; height: 600 + + Column{ + TextEdit { id: input1; activeFocusOnTab: true } + TextEdit { id: input2; activeFocusOnTab: true } + } +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 9d1d099c0e..5ec8fa2e83 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -166,6 +166,8 @@ private slots: void implicitSizeBinding_data(); void implicitSizeBinding(); + void signal_editingfinished(); + void preeditCursorRectangle(); void inputMethodComposing(); void cursorRectangleSize_data(); @@ -200,6 +202,8 @@ private slots: void cursorRectangle_QTBUG_38947(); void textCached_QTBUG_41583(); + void padding(); + private: void simulateKeys(QWindow *window, const QList<Key> &keys); void simulateKeys(QWindow *window, const QKeySequence &sequence); @@ -573,7 +577,7 @@ void tst_qquicktextedit::textFormat() QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickTextEdit::RichText); + QCOMPARE(textObject->textFormat(), QQuickTextEdit::RichText); } { QQmlComponent textComponent(&engine); @@ -581,7 +585,7 @@ void tst_qquicktextedit::textFormat() QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickTextEdit::PlainText); + QCOMPARE(textObject->textFormat(), QQuickTextEdit::PlainText); } { QQmlComponent component(&engine); @@ -798,7 +802,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() // keyboard input direction from qApp->inputMethod()->inputDirection textEdit->setText(""); platformInputContext.setInputDirection(Qt::LeftToRight); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::LeftToRight); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::LeftToRight); QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignLeft); QVERIFY(textEdit->positionToRectangle(0).x() < window.width()/2); @@ -806,7 +810,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() platformInputContext.setInputDirection(Qt::RightToLeft); QCOMPARE(cursorRectangleSpy.count(), 1); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::RightToLeft); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::RightToLeft); QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignRight); QVERIFY(textEdit->positionToRectangle(0).x() > window.width()/2); @@ -1397,22 +1401,22 @@ void tst_qquicktextedit::selection() } textEditObject->setCursorPosition(0); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); // Verify invalid positions are ignored. textEditObject->setCursorPosition(-1); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); textEditObject->setCursorPosition(textEditObject->text().count()+1); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); //Test selection @@ -1426,9 +1430,9 @@ void tst_qquicktextedit::selection() } textEditObject->setCursorPosition(0); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); //Test Error Ignoring behaviour @@ -1443,20 +1447,20 @@ void tst_qquicktextedit::selection() textEditObject->select(0,100); QVERIFY(textEditObject->selectedText().isNull()); textEditObject->select(0,10); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(-10,0); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(100,101); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(0,-10); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(0,100); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->deselect(); QVERIFY(textEditObject->selectedText().isNull()); textEditObject->select(0,10); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->deselect(); QVERIFY(textEditObject->selectedText().isNull()); } @@ -1535,31 +1539,31 @@ void tst_qquicktextedit::keySelection() QSignalSpy spy(input, SIGNAL(selectedTextChanged())); simulateKey(&window, Qt::Key_Right, Qt::ShiftModifier); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString("a")); QCOMPARE(spy.count(), 1); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 2); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 2); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(spy.count(), 2); simulateKey(&window, Qt::Key_Left, Qt::ShiftModifier); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString("a")); QCOMPARE(spy.count(), 3); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 4); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 4); } @@ -2786,17 +2790,17 @@ void tst_qquicktextedit::navigation() QQuickTextEdit *input = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // Test left and right navigation works if the TextEdit is empty (QTBUG-25447). input->setText(QString()); @@ -2976,8 +2980,8 @@ void tst_qquicktextedit::readOnly() QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(edit != 0); - QTRY_VERIFY(edit->hasActiveFocus() == true); - QVERIFY(edit->isReadOnly() == true); + QTRY_VERIFY(edit->hasActiveFocus()); + QVERIFY(edit->isReadOnly()); QString initial = edit->text(); for (int k=Qt::Key_0; k<=Qt::Key_Z; k++) simulateKey(&window, k); @@ -3009,7 +3013,7 @@ void tst_qquicktextedit::textInput() QTest::qWaitForWindowActive(&view); QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(view.rootObject()); QVERIFY(edit); - QVERIFY(edit->hasActiveFocus() == true); + QVERIFY(edit->hasActiveFocus()); // test that input method event is committed and change signal is emitted QSignalSpy spy(edit, SIGNAL(textChanged())); @@ -3045,7 +3049,7 @@ void tst_qquicktextedit::inputMethodUpdate() QTest::qWaitForWindowActive(&view); QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(view.rootObject()); QVERIFY(edit); - QVERIFY(edit->hasActiveFocus() == true); + QVERIFY(edit->hasActiveFocus()); // text change even without cursor position change needs to trigger update edit->setText("test"); @@ -3219,15 +3223,15 @@ void tst_qquicktextedit::pastingRichText_QTBUG_14003() QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(component.create()); QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->textFormat() == QQuickTextEdit::PlainText); + QTRY_COMPARE(obj->textFormat(), QQuickTextEdit::PlainText); QMimeData *mData = new QMimeData; mData->setHtml("<font color=\"red\">Hello</font>"); QGuiApplication::clipboard()->setMimeData(mData); obj->paste(); - QTRY_VERIFY(obj->text() == ""); - QTRY_VERIFY(obj->textFormat() == QQuickTextEdit::PlainText); + QTRY_COMPARE(obj->text(), QString()); + QTRY_COMPARE(obj->textFormat(), QQuickTextEdit::PlainText); } #endif @@ -3253,11 +3257,11 @@ void tst_qquicktextedit::implicitSize() QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create()); QVERIFY(textObject->width() < textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); textObject->resetWidth(); - QVERIFY(textObject->width() == textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->width(), textObject->implicitWidth()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); } void tst_qquicktextedit::contentSize() @@ -3316,6 +3320,53 @@ void tst_qquicktextedit::implicitSizeBinding() QCOMPARE(textObject->height(), textObject->implicitHeight()); } +void tst_qquicktextedit::signal_editingfinished() +{ + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(800,600)); + + window->setSource(testFileUrl("signal_editingfinished.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QCOMPARE(QGuiApplication::focusWindow(), window); + + QVERIFY(window->rootObject() != 0); + + QQuickTextEdit *input1 = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window->rootObject()->property("input1"))); + QVERIFY(input1); + QQuickTextEdit *input2 = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window->rootObject()->property("input2"))); + QVERIFY(input2); + + QSignalSpy editingFinished1Spy(input1, SIGNAL(editingFinished())); + + input1->setFocus(true); + QTRY_VERIFY(input1->hasActiveFocus()); + QTRY_VERIFY(!input2->hasActiveFocus()); + + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + QTRY_COMPARE(editingFinished1Spy.count(), 1); + + QTRY_VERIFY(!input1->hasActiveFocus()); + QTRY_VERIFY(input2->hasActiveFocus()); + + QSignalSpy editingFinished2Spy(input2, SIGNAL(editingFinished())); + + input2->setFocus(true); + QTRY_VERIFY(!input1->hasActiveFocus()); + QTRY_VERIFY(input2->hasActiveFocus()); + + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + QTRY_COMPARE(editingFinished2Spy.count(), 1); + + QTRY_VERIFY(input1->hasActiveFocus()); + QTRY_VERIFY(!input2->hasActiveFocus()); +} + void tst_qquicktextedit::clipRect() { QQmlComponent component(&engine); @@ -5323,6 +5374,84 @@ void tst_qquicktextedit::textCached_QTBUG_41583() QVERIFY(!textedit->property("empty").toBool()); } +void tst_qquicktextedit::padding() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("padding.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(root); + QVERIFY(obj != 0); + + qreal cw = obj->contentWidth(); + qreal ch = obj->contentHeight(); + + QVERIFY(cw > 0); + QVERIFY(ch > 0); + + QCOMPARE(obj->topPadding(), 20.0); + QCOMPARE(obj->leftPadding(), 30.0); + QCOMPARE(obj->rightPadding(), 40.0); + QCOMPARE(obj->bottomPadding(), 50.0); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setTopPadding(2.25); + QCOMPARE(obj->topPadding(), 2.25); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setLeftPadding(3.75); + QCOMPARE(obj->leftPadding(), 3.75); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setRightPadding(4.4); + QCOMPARE(obj->rightPadding(), 4.4); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setBottomPadding(1.11); + QCOMPARE(obj->bottomPadding(), 1.11); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setText("Qt"); + QVERIFY(obj->contentWidth() < cw); + QCOMPARE(obj->contentHeight(), ch); + cw = obj->contentWidth(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setFont(QFont("Courier", 96)); + QVERIFY(obj->contentWidth() > cw); + QVERIFY(obj->contentHeight() > ch); + cw = obj->contentWidth(); + ch = obj->contentHeight(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->resetTopPadding(); + QCOMPARE(obj->topPadding(), 10.0); + obj->resetLeftPadding(); + QCOMPARE(obj->leftPadding(), 10.0); + obj->resetRightPadding(); + QCOMPARE(obj->rightPadding(), 10.0); + obj->resetBottomPadding(); + QCOMPARE(obj->bottomPadding(), 10.0); + + obj->resetPadding(); + QCOMPARE(obj->padding(), 0.0); + QCOMPARE(obj->topPadding(), 0.0); + QCOMPARE(obj->leftPadding(), 0.0); + QCOMPARE(obj->rightPadding(), 0.0); + QCOMPARE(obj->bottomPadding(), 0.0); + + delete root; +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" diff --git a/tests/auto/quick/qquicktextinput/data/padding.qml b/tests/auto/quick/qquicktextinput/data/padding.qml new file mode 100644 index 0000000000..23bfe20f22 --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/padding.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 + +TextInput { + width: 200; height: 200 + text: "Hello Qt" + + padding: 10 + topPadding: 20 + leftPadding: 30 + rightPadding: 40 + bottomPadding: 50 +} diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index d87054ac9e..079f73ae34 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -45,6 +45,7 @@ #include <QInputMethod> #include <private/qquicktextinput_p.h> #include <private/qquicktextinput_p_p.h> +#include <private/qquickvalidator_p.h> #include <QDebug> #include <QDir> #include <math.h> @@ -222,6 +223,7 @@ private slots: void baselineOffset(); void ensureVisible(); + void padding(); private: void simulateKey(QWindow *, int key); @@ -591,7 +593,7 @@ void tst_qquicktextinput::wrap() textHeight = textObject->height(); QVERIFY(textObject != 0); - QVERIFY(textObject->wrapMode() == QQuickTextInput::WrapAnywhere); + QCOMPARE(textObject->wrapMode(), QQuickTextInput::WrapAnywhere); QCOMPARE(textObject->width(), 300.); delete textObject; @@ -658,22 +660,22 @@ void tst_qquicktextinput::selection() } textinputObject->setCursorPosition(0); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); // Verify invalid positions are ignored. textinputObject->setCursorPosition(-1); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); textinputObject->setCursorPosition(textinputObject->text().count()+1); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); //Test selection @@ -687,9 +689,9 @@ void tst_qquicktextinput::selection() } textinputObject->setCursorPosition(0); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); //Test Error Ignoring behaviour @@ -704,20 +706,20 @@ void tst_qquicktextinput::selection() textinputObject->select(0,100); QVERIFY(textinputObject->selectedText().isNull()); textinputObject->select(0,10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(-10,10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(100,101); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(0,-10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(0,100); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->deselect(); QVERIFY(textinputObject->selectedText().isNull()); textinputObject->select(0,10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->deselect(); QVERIFY(textinputObject->selectedText().isNull()); @@ -1513,13 +1515,13 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() // keyboard input direction from QInputMethod::inputDirection() textInput->setText(""); platformInputContext.setInputDirection(Qt::LeftToRight); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::LeftToRight); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::LeftToRight); QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft); QCOMPARE(textInput->boundingRect().left(), qreal(0)); QSignalSpy cursorRectangleSpy(textInput, SIGNAL(cursorRectangleChanged())); platformInputContext.setInputDirection(Qt::RightToLeft); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::RightToLeft); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::RightToLeft); QCOMPARE(cursorRectangleSpy.count(), 1); QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); QVERIFY(textInput->boundingRect().right() >= textInput->width() - 1); @@ -1853,7 +1855,7 @@ void tst_qquicktextinput::maxLength() QQuickTextInput *textinputObject = qobject_cast<QQuickTextInput *>(window.rootObject()); QVERIFY(textinputObject != 0); QVERIFY(textinputObject->text().isEmpty()); - QVERIFY(textinputObject->maxLength() == 10); + QCOMPARE(textinputObject->maxLength(), 10); foreach (const QString &str, standard) { QVERIFY(textinputObject->text().length() <= 10); textinputObject->setText(str); @@ -1861,7 +1863,7 @@ void tst_qquicktextinput::maxLength() } textinputObject->setText(""); - QTRY_VERIFY(textinputObject->hasActiveFocus() == true); + QTRY_VERIFY(textinputObject->hasActiveFocus()); for (int i=0; i<20; i++) { QTRY_COMPARE(textinputObject->text().length(), qMin(i,10)); //simulateKey(&window, Qt::Key_A); @@ -1880,8 +1882,8 @@ void tst_qquicktextinput::masks() QVERIFY(window.rootObject() != 0); QQuickTextInput *textinputObject = qobject_cast<QQuickTextInput *>(window.rootObject()); QVERIFY(textinputObject != 0); - QTRY_VERIFY(textinputObject->hasActiveFocus() == true); - QVERIFY(textinputObject->text().length() == 0); + QTRY_VERIFY(textinputObject->hasActiveFocus()); + QCOMPARE(textinputObject->text().length(), 0); QCOMPARE(textinputObject->inputMask(), QString("HHHHhhhh; ")); QCOMPARE(textinputObject->length(), 8); for (int i=0; i<10; i++) { @@ -1997,7 +1999,7 @@ void tst_qquicktextinput::validators() QCOMPARE(dblInput->validator()->locale(), defaultLocale); dblInput->setFocus(true); - QVERIFY(dblInput->hasActiveFocus() == true); + QVERIFY(dblInput->hasActiveFocus()); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); QTest::keyPress(&window, Qt::Key_1); @@ -2131,7 +2133,7 @@ void tst_qquicktextinput::validators() QVERIFY(strInput); QSignalSpy strSpy(strInput, SIGNAL(acceptableInputChanged())); strInput->setFocus(true); - QVERIFY(strInput->hasActiveFocus() == true); + QVERIFY(strInput->hasActiveFocus()); QCOMPARE(strInput->hasAcceptableInput(), false); QCOMPARE(strInput->property("acceptable").toBool(), false); QTest::keyPress(&window, Qt::Key_1); @@ -2175,7 +2177,7 @@ void tst_qquicktextinput::validators() QVERIFY(unvalidatedInput); QSignalSpy unvalidatedSpy(unvalidatedInput, SIGNAL(acceptableInputChanged())); unvalidatedInput->setFocus(true); - QVERIFY(unvalidatedInput->hasActiveFocus() == true); + QVERIFY(unvalidatedInput->hasActiveFocus()); QCOMPARE(unvalidatedInput->hasAcceptableInput(), true); QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true); QTest::keyPress(&window, Qt::Key_1); @@ -2216,7 +2218,7 @@ void tst_qquicktextinput::inputMethods() QCOMPARE(plainInput.inputMethodHints(), Qt::ImhNone); input->setFocus(true); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // test that input method event is committed QInputMethodEvent event; event.setCommitString( "My ", -12, 0); @@ -2399,23 +2401,23 @@ void tst_qquicktextinput::navigation() QVERIFY(input != 0); input->setCursorPosition(0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); //QT-2944: If text is selected, ensure we deselect upon cursor motion input->setCursorPosition(input->text().length()); input->select(0,input->text().length()); QVERIFY(input->selectionStart() != input->selectionEnd()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->selectionStart() == input->selectionEnd()); - QVERIFY(input->selectionStart() == input->text().length()); - QVERIFY(input->hasActiveFocus() == true); + QCOMPARE(input->selectionStart(), input->selectionEnd()); + QCOMPARE(input->selectionStart(), input->text().length()); + QVERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // Up and Down should NOT do Home/End, even on OS X (QTBUG-10438). input->setCursorPosition(2); @@ -2451,26 +2453,26 @@ void tst_qquicktextinput::navigation_RTL() input->setText(QString::fromUtf16(arabic_str, 11)); input->setCursorPosition(0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); // move off simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); // move back simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); input->setCursorPosition(input->text().length()); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // move off simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); // move back simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); } #ifndef QT_NO_CLIPBOARD @@ -2996,6 +2998,14 @@ void tst_qquicktextinput::cursorRectangle_data() << false; } +#ifndef QT_NO_IM +#define COMPARE_INPUT_METHOD_QUERY(type, input, property, method, result) \ + QCOMPARE((type) input->inputMethodQuery(property).method(), result); +#else +#define COMPARE_INPUT_METHOD_QUERY(type, input, property, method, result) \ + qt_noop() +#endif + void tst_qquicktextinput::cursorRectangle() { QFETCH(QString, text); @@ -3035,7 +3045,7 @@ void tst_qquicktextinput::cursorRectangle() r = input.cursorRectangle(); QCOMPARE(r.left(), line.cursorToX(i, QTextLine::Leading) - offset); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3045,7 +3055,7 @@ void tst_qquicktextinput::cursorRectangle() for (int i = positionAtWidth + 1; i < text.length(); ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3058,7 +3068,7 @@ void tst_qquicktextinput::cursorRectangle() } else { QVERIFY(r.left() <= input.width()); } - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3071,7 +3081,7 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), line.cursorToX(i, QTextLine::Leading) - offset); QCOMPARE(r.top(), 0.); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3083,14 +3093,14 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), input.width()); } QVERIFY(r.top() >= line.height() - 1); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(11), r); for (int i = wrapPosition + 1; i < text.length(); ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.top() >= line.height() - 1); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3102,7 +3112,7 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), line.cursorToX(i, QTextLine::Leading) - offset); QCOMPARE(r.top(), 0.); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3112,7 +3122,7 @@ void tst_qquicktextinput::cursorRectangle() for (int i = positionAtWidth + 1; i < wrapPosition && leftToRight; ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3124,14 +3134,14 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), input.width()); } QVERIFY(r.bottom() >= input.height()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(11), r); for (int i = wrapPosition + 1; i < text.length(); ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.bottom() >= input.height()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3139,7 +3149,7 @@ void tst_qquicktextinput::cursorRectangle() input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.bottom() >= input.height()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3147,13 +3157,13 @@ void tst_qquicktextinput::cursorRectangle() r = input.cursorRectangle(); QCOMPARE(r.top(), 0.); QCOMPARE(r.left(), leftToRight ? input.width() : 0); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(10), r); for (int i = wrapPosition - 2; i >= positionAtWidth + 1; --i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3161,7 +3171,7 @@ void tst_qquicktextinput::cursorRectangle() input.setCursorPosition(i); r = input.cursorRectangle(); QCOMPARE(r.top(), 0.); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3190,9 +3200,9 @@ void tst_qquicktextinput::readOnly() QQuickTextInput *input = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasActiveFocus() == true); - QVERIFY(input->isReadOnly() == true); - QVERIFY(input->isCursorVisible() == false); + QTRY_VERIFY(input->hasActiveFocus()); + QVERIFY(input->isReadOnly()); + QVERIFY(!input->isCursorVisible()); QString initial = input->text(); for (int k=Qt::Key_0; k<=Qt::Key_Z; k++) simulateKey(&window, k); @@ -3205,7 +3215,7 @@ void tst_qquicktextinput::readOnly() input->setReadOnly(false); QCOMPARE(input->isReadOnly(), false); QCOMPARE(input->cursorPosition(), input->text().length()); - QVERIFY(input->isCursorVisible() == true); + QVERIFY(input->isCursorVisible()); } void tst_qquicktextinput::echoMode() @@ -3220,7 +3230,7 @@ void tst_qquicktextinput::echoMode() QQuickTextInput *input = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); QString initial = input->text(); Qt::InputMethodHints ref; QCOMPARE(initial, QLatin1String("ABCDefgh")); @@ -3230,7 +3240,7 @@ void tst_qquicktextinput::echoMode() //Normal ref &= ~Qt::ImhHiddenText; ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); input->setEchoMode(QQuickTextInput::NoEcho); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("")); @@ -3238,17 +3248,17 @@ void tst_qquicktextinput::echoMode() //NoEcho ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); input->setEchoMode(QQuickTextInput::Password); //Password ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QString(8, passwordMaskCharacter.at(0))); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); // clearing input hints do not clear bits set by echo mode input->setInputMethodHints(Qt::ImhNone); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); input->setPasswordCharacter(QChar('Q')); QCOMPARE(input->passwordCharacter(), QLatin1String("Q")); QCOMPARE(input->text(), initial); @@ -3257,19 +3267,20 @@ void tst_qquicktextinput::echoMode() //PasswordEchoOnEdit ref &= ~Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ")); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("QQQQQQQQ")); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, + QLatin1String("QQQQQQQQ")); QTest::keyPress(&window, Qt::Key_A);//Clearing previous entry is part of PasswordEchoOnEdit QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10); QCOMPARE(input->text(), QLatin1String("a")); QCOMPARE(input->displayText(), QLatin1String("a")); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("a")); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, QLatin1String("a")); input->setFocus(false); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->displayText(), QLatin1String("Q")); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("Q")); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, QLatin1String("Q")); input->setFocus(true); QVERIFY(input->hasActiveFocus()); QInputMethodEvent inputEvent; @@ -3277,7 +3288,7 @@ void tst_qquicktextinput::echoMode() QGuiApplication::sendEvent(input, &inputEvent); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), initial); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), initial); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, initial); } void tst_qquicktextinput::passwordEchoDelay() @@ -5819,11 +5830,11 @@ void tst_qquicktextinput::implicitSize() QQuickTextInput *textObject = qobject_cast<QQuickTextInput*>(textComponent.create()); QVERIFY(textObject->width() < textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); textObject->resetWidth(); - QVERIFY(textObject->width() == textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->width(), textObject->implicitWidth()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); } void tst_qquicktextinput::implicitSizeBinding_data() @@ -6370,25 +6381,25 @@ Q_DECLARE_METATYPE(ExpectedBaseline) static qreal expectedBaselineTop(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } static qreal expectedBaselineBottom(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return item->height() - item->contentHeight() + fm.ascent(); + return item->height() - item->contentHeight() - item->bottomPadding() + fm.ascent(); } static qreal expectedBaselineCenter(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return ((item->height() - item->contentHeight()) / 2) + fm.ascent(); + return ((item->height() - item->contentHeight() - item->topPadding() - item->bottomPadding()) / 2) + fm.ascent() + item->topPadding(); } static qreal expectedBaselineMultilineBottom(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return item->height() - item->contentHeight() + fm.ascent(); + return item->height() - item->contentHeight() - item->bottomPadding() + fm.ascent(); } void tst_qquicktextinput::baselineOffset_data() @@ -6433,6 +6444,41 @@ void tst_qquicktextinput::baselineOffset_data() << -1. << &expectedBaselineMultilineBottom << &expectedBaselineBottom; + + QTest::newRow("padding") + << "Typography" + << QByteArray("topPadding: 10; bottomPadding: 20") + << -1. + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("top align with padding") + << "Typography" + << QByteArray("height: 200; verticalAlignment: Text.AlignTop; topPadding: 10; bottomPadding: 20") + << -1. + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("bottom align with padding") + << "Typography" + << QByteArray("height: 200; verticalAlignment: Text.AlignBottom; topPadding: 10; bottomPadding: 20") + << 100. + << &expectedBaselineBottom + << &expectedBaselineBottom; + + QTest::newRow("center align with padding") + << "Typography" + << QByteArray("height: 200; verticalAlignment: Text.AlignVCenter; topPadding: 10; bottomPadding: 20") + << 100. + << &expectedBaselineCenter + << &expectedBaselineCenter; + + QTest::newRow("multiline bottom aligned with padding") + << "The quick brown fox jumps over the lazy dog" + << QByteArray("height: 200; width: 30; verticalAlignment: Text.AlignBottom; wrapMode: TextInput.WordWrap; topPadding: 10; bottomPadding: 20") + << -1. + << &expectedBaselineMultilineBottom + << &expectedBaselineBottom; } void tst_qquicktextinput::baselineOffset() @@ -6445,7 +6491,7 @@ void tst_qquicktextinput::baselineOffset() QQmlComponent component(&engine); component.setData( - "import QtQuick 2.0\n" + "import QtQuick 2.6\n" "TextInput {\n" + bindings + "\n" "}", QUrl()); @@ -6510,6 +6556,85 @@ void tst_qquicktextinput::ensureVisible() QCOMPARE(input->boundingRect().height(), line.height()); } +void tst_qquicktextinput::padding() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("padding.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickTextInput *obj = qobject_cast<QQuickTextInput*>(root); + QVERIFY(obj != 0); + + qreal cw = obj->contentWidth(); + qreal ch = obj->contentHeight(); + + QVERIFY(cw > 0); + QVERIFY(ch > 0); + + QCOMPARE(obj->padding(), 10.0); + QCOMPARE(obj->topPadding(), 20.0); + QCOMPARE(obj->leftPadding(), 30.0); + QCOMPARE(obj->rightPadding(), 40.0); + QCOMPARE(obj->bottomPadding(), 50.0); + + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setTopPadding(2.25); + QCOMPARE(obj->topPadding(), 2.25); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setLeftPadding(3.75); + QCOMPARE(obj->leftPadding(), 3.75); + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + + obj->setRightPadding(4.4); + QCOMPARE(obj->rightPadding(), 4.4); + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + + obj->setBottomPadding(1.11); + QCOMPARE(obj->bottomPadding(), 1.11); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setText("Qt"); + QVERIFY(obj->contentWidth() < cw); + QCOMPARE(obj->contentHeight(), ch); + cw = obj->contentWidth(); + + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setFont(QFont("Courier", 96)); + QVERIFY(obj->contentWidth() > cw); + QVERIFY(obj->contentHeight() > ch); + cw = obj->contentWidth(); + ch = obj->contentHeight(); + + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->resetTopPadding(); + QCOMPARE(obj->topPadding(), 10.0); + obj->resetLeftPadding(); + QCOMPARE(obj->leftPadding(), 10.0); + obj->resetRightPadding(); + QCOMPARE(obj->rightPadding(), 10.0); + obj->resetBottomPadding(); + QCOMPARE(obj->bottomPadding(), 10.0); + + obj->resetPadding(); + QCOMPARE(obj->padding(), 0.0); + QCOMPARE(obj->topPadding(), 0.0); + QCOMPARE(obj->leftPadding(), 0.0); + QCOMPARE(obj->rightPadding(), 0.0); + QCOMPARE(obj->bottomPadding(), 0.0); + + delete root; +} + QTEST_MAIN(tst_qquicktextinput) #include "tst_qquicktextinput.moc" diff --git a/tests/auto/quick/qquickview/data/error2.qml b/tests/auto/quick/qquickview/data/error2.qml new file mode 100644 index 0000000000..1d754b64f0 --- /dev/null +++ b/tests/auto/quick/qquickview/data/error2.qml @@ -0,0 +1,4 @@ +import QtQuick.Window 2.0 + +Window { +} diff --git a/tests/auto/quick/qquickview/tst_qquickview.cpp b/tests/auto/quick/qquickview/tst_qquickview.cpp index a980c69140..2f054e278a 100644 --- a/tests/auto/quick/qquickview/tst_qquickview.cpp +++ b/tests/auto/quick/qquickview/tst_qquickview.cpp @@ -184,8 +184,17 @@ void tst_QQuickView::errors() QQuickView view; QQmlTestMessageHandler messageHandler; view.setSource(testFileUrl("error1.qml")); - QVERIFY(view.status() == QQuickView::Error); - QVERIFY(view.errors().count() == 1); + QCOMPARE(view.status(), QQuickView::Error); + QCOMPARE(view.errors().count(), 1); + } + + { + QQuickView view; + QQmlTestMessageHandler messageHandler; + view.setSource(testFileUrl("error2.qml")); + QCOMPARE(view.status(), QQuickView::Error); + QCOMPARE(view.errors().count(), 1); + view.show(); } } @@ -196,16 +205,16 @@ void tst_QQuickView::engine() QQuickView *view = new QQuickView(engine, 0); QVERIFY(view); - QVERIFY(engine->incubationController() == view->incubationController()); + QCOMPARE(engine->incubationController(), view->incubationController()); QQuickView *view2 = new QQuickView(engine, 0); QVERIFY(view); - QVERIFY(engine->incubationController() == view->incubationController()); + QCOMPARE(engine->incubationController(), view->incubationController()); delete view; QVERIFY(!engine->incubationController()); engine->setIncubationController(view2->incubationController()); - QVERIFY(engine->incubationController() == view2->incubationController()); + QCOMPARE(engine->incubationController(), view2->incubationController()); delete view2; QVERIFY(!engine->incubationController()); diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 2dd9e77370..d578a0900c 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -513,15 +513,15 @@ void tst_qquickvisualdatamodel::rootIndex() QVERIFY(obj != 0); QMetaObject::invokeMethod(obj, "setRoot"); - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == model.index(0,0)); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), model.index(0,0)); QMetaObject::invokeMethod(obj, "setRootToParent"); - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == QModelIndex()); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), QModelIndex()); QMetaObject::invokeMethod(obj, "setRoot"); - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == model.index(0,0)); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), model.index(0,0)); model.clear(); // will emit modelReset() - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == QModelIndex()); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), QModelIndex()); delete obj; } @@ -628,7 +628,7 @@ void tst_qquickvisualdatamodel::childChanged() model.item(1,0)->takeRow(1); name = findItem<QQuickText>(contentItem, "display", 1); - QVERIFY(name == 0); + QVERIFY(!name); vdm->setRootIndex(QVariant::fromValue(QModelIndex())); QCOMPARE(listview->count(), 3); diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index dfe5276e8e..e1ea068a62 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -504,7 +504,7 @@ void tst_qquickwindow::touchEvent_basic() window->resize(250, 250); window->setPosition(100, 100); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *bottomItem = new TestTouchItem(window->contentItem()); bottomItem->setObjectName("Bottom Item"); @@ -635,7 +635,7 @@ void tst_qquickwindow::touchEvent_propagation() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *bottomItem = new TestTouchItem(window->contentItem()); bottomItem->setObjectName("Bottom Item"); @@ -769,18 +769,18 @@ void tst_qquickwindow::touchEvent_cancel() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *item = new TestTouchItem(window->contentItem()); item->setPosition(QPointF(50, 50)); item->setSize(QSizeF(150, 150)); - QPointF pos(10, 10); - QTest::touchEvent(window, touchDevice).press(0, item->mapToScene(pos).toPoint(),window); + QPointF pos(50, 50); + QTest::touchEvent(window, touchDevice).press(0, item->mapToScene(pos).toPoint(), window); QCoreApplication::processEvents(); QTRY_COMPARE(item->lastEvent.touchPoints.count(), 1); - TouchEventData d = makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(item,pos)); + TouchEventData d = makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(item, pos)); COMPARE_TOUCH_DATA(item->lastEvent, d); item->reset(); @@ -803,7 +803,7 @@ void tst_qquickwindow::touchEvent_reentrant() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *item = new TestTouchItem(window->contentItem()); @@ -978,7 +978,7 @@ void tst_qquickwindow::clearWindow() delete window; - QVERIFY(item->window() == 0); + QVERIFY(!item->window()); delete item; } @@ -993,7 +993,7 @@ void tst_qquickwindow::mouseFiltering() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *bottomItem = new TestTouchItem(window->contentItem()); bottomItem->setObjectName("Bottom Item"); @@ -1232,7 +1232,7 @@ void tst_qquickwindow::headless() if (threaded) { QTRY_COMPARE(invalidated.size(), 1); - QVERIFY(window->openglContext() == 0); + QVERIFY(!window->openglContext()); } if (QGuiApplication::platformName() == QLatin1String("windows") @@ -1242,7 +1242,7 @@ void tst_qquickwindow::headless() // Destroy the native windowing system buffers window->destroy(); - QVERIFY(window->handle() == 0); + QVERIFY(!window->handle()); // Show and verify that we are back and running window->show(); @@ -1452,7 +1452,7 @@ void tst_qquickwindow::cursor() clippedItem.setParentItem(&clippingItem); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); // Position the cursor over the parent and child item and the clipped section of clippedItem. QTest::mouseMove(&window, QPoint(100, 100)); @@ -1609,7 +1609,7 @@ void tst_qquickwindow::hideThenDelete() if (!persistentGL) QVERIFY(openglDestroyed->size() > 0); else - QVERIFY(openglDestroyed->size() == 0); + QCOMPARE(openglDestroyed->size(), 0); } else { QCOMPARE(sgInvalidated->size(), 0); QCOMPARE(openglDestroyed->size(), 0); @@ -1693,7 +1693,7 @@ void tst_qquickwindow::requestActivate() window1->requestActivate(); // and then transfer the focus to window1 QTRY_COMPARE(QGuiApplication::focusWindow(), window1.data()); - QVERIFY(window1->isActive() == true); + QVERIFY(window1->isActive()); QQuickItem *item = QQuickVisualTestUtil::findItem<QQuickItem>(window1->contentItem(), "item1"); QVERIFY(item); @@ -1805,7 +1805,7 @@ void tst_qquickwindow::crashWhenHoverItemDeleted() QVERIFY(!window.isNull()); window->setTitle(QTest::currentTestFunction()); window->show(); - QTest::qWaitForWindowExposed(window.data()); + QTest::qWaitForWindowActive(window.data()); // Simulate a move from the first rectangle to the second. Crash will happen in here // Moving instantaneously from (0, 99) to (0, 102) does not cause the crash @@ -1844,7 +1844,7 @@ void tst_qquickwindow::qobjectEventFilter_touch() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); item->setSize(QSizeF(150, 150)); @@ -1870,7 +1870,7 @@ void tst_qquickwindow::qobjectEventFilter_key() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); item->setSize(QSizeF(150, 150)); @@ -1899,8 +1899,7 @@ void tst_qquickwindow::qobjectEventFilter_mouse() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); item->setSize(QSizeF(150, 150)); @@ -1909,6 +1908,7 @@ void tst_qquickwindow::qobjectEventFilter_mouse() item->installEventFilter(&eventFilter); QPoint point = item->mapToScene(QPointF(10, 10)).toPoint(); + QTest::mouseMove(&window, point); QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point); QVERIFY(eventFilter.events.contains((int)QEvent::MouseButtonPress)); @@ -2048,44 +2048,108 @@ public: static int deleted; }; +class GlRenderJob : public QRunnable +{ +public: + GlRenderJob(GLubyte *buf) : readPixel(buf), mutex(0), condition(0) {} + ~GlRenderJob() {} + void run() { + QOpenGLContext::currentContext()->functions()->glClearColor(1.0f, 0, 0, 1.0f); + QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT); + QOpenGLContext::currentContext()->functions()->glReadPixels(0, 0, 1, 1, GL_RGBA, + GL_UNSIGNED_BYTE, + (void *)readPixel); + if (mutex) { + mutex->lock(); + condition->wakeOne(); + mutex->unlock(); + } + } + GLubyte *readPixel; + QMutex *mutex; + QWaitCondition *condition; +}; + int RenderJob::deleted = 0; void tst_qquickwindow::testRenderJob() { QList<QQuickWindow::RenderStage> completedJobs; - QQuickWindow window; - window.setTitle(QTest::currentTestFunction()); - QQuickWindow::RenderStage stages[] = { QQuickWindow::BeforeSynchronizingStage, QQuickWindow::AfterSynchronizingStage, QQuickWindow::BeforeRenderingStage, QQuickWindow::AfterRenderingStage, - QQuickWindow::AfterSwapStage + QQuickWindow::AfterSwapStage, + QQuickWindow::NoStage }; - // Schedule the jobs - for (int i=0; i<5; ++i) - window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]); - window.show(); - QTRY_COMPARE(completedJobs.size(), 5); + const int numJobs = 6; - for (int i=0; i<5; ++i) { - QCOMPARE(completedJobs.at(i), stages[i]); + { + QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); + RenderJob::deleted = 0; + + // Schedule the jobs + for (int i = 0; i < numJobs; ++i) + window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // All jobs should be deleted + QTRY_COMPARE(RenderJob::deleted, numJobs); + + // The NoStage job is not completed, if it is issued when there is no context, + // but the rest will be queued and completed once relevant render stage is hit. + QCOMPARE(completedJobs.size(), numJobs - 1); + + // Verify jobs were completed in correct order + for (int i = 0; i < numJobs - 1; ++i) + QCOMPARE(completedJobs.at(i), stages[i]); + + + // Check that NoStage job gets executed if it is scheduled when window is exposed + completedJobs.clear(); + RenderJob::deleted = 0; + window.scheduleRenderJob(new RenderJob(QQuickWindow::NoStage, &completedJobs), + QQuickWindow::NoStage); + QTRY_COMPARE(RenderJob::deleted, 1); + QCOMPARE(completedJobs.size(), 1); + + // Do a synchronized GL job. + GLubyte readPixel[4] = {0, 0, 0, 0}; + GlRenderJob *glJob = new GlRenderJob(readPixel); + if (window.openglContext()->thread() != QThread::currentThread()) { + QMutex mutex; + QWaitCondition condition; + glJob->mutex = &mutex; + glJob->condition = &condition; + mutex.lock(); + window.scheduleRenderJob(glJob, QQuickWindow::NoStage); + condition.wait(&mutex); + mutex.unlock(); + } else { + window.scheduleRenderJob(glJob, QQuickWindow::NoStage); + } + QCOMPARE(int(readPixel[0]), 255); + QCOMPARE(int(readPixel[1]), 0); + QCOMPARE(int(readPixel[2]), 0); + QCOMPARE(int(readPixel[3]), 255); } - // Verify that jobs are deleted when window has not been rendered at all... + // Verify that jobs are deleted when window is not rendered at all completedJobs.clear(); RenderJob::deleted = 0; { QQuickWindow window2; - for (int i=0; i<5; ++i) { + for (int i = 0; i < numJobs; ++i) { window2.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]); } } + QTRY_COMPARE(RenderJob::deleted, numJobs); QCOMPARE(completedJobs.size(), 0); - QCOMPARE(RenderJob::deleted, 5); } class EventCounter : public QQuickRectangle @@ -2144,7 +2208,7 @@ void tst_qquickwindow::testHoverChildMouseEventFilter() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); EventCounter *bottomItem = new EventCounter(window.contentItem()); bottomItem->setObjectName("Bottom Item"); diff --git a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp index 5372a4d3b3..c0bf86a212 100644 --- a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp +++ b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp @@ -760,9 +760,9 @@ void tst_qquickxmllistmodel::noKeysValueChanges() QTRY_VERIFY(model->data(model->index(0, 0), roles.at(2)).toString() != QLatin1String("Football")); QCOMPARE(model->data(model->index(0, 0), roles.at(2)).toString(), QLatin1String("AussieRules")); - QVERIFY(spyInsert.count() == 0); - QVERIFY(spyRemove.count() == 0); - QVERIFY(spyCount.count() == 0); + QCOMPARE(spyInsert.count(), 0); + QCOMPARE(spyRemove.count(), 0); + QCOMPARE(spyCount.count(), 0); QCOMPARE(model->rowCount(), 2); @@ -940,7 +940,7 @@ void tst_qquickxmllistmodel::propertyChanges() QCOMPARE(model->property("query").toString(), QString("/Pets")); QCOMPARE(model->property("namespaceDeclarations").toString(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); - QTRY_VERIFY(model->rowCount() == 1); + QTRY_COMPARE(model->rowCount(), 1); QCOMPARE(sourceSpy.count(),1); QCOMPARE(xmlSpy.count(),1); @@ -957,7 +957,7 @@ void tst_qquickxmllistmodel::propertyChanges() QCOMPARE(modelQuerySpy.count(),1); QCOMPARE(namespaceDeclarationsSpy.count(),1); - QTRY_VERIFY(model->rowCount() == 1); + QTRY_COMPARE(model->rowCount(), 1); delete model; } diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index c2b7a4cc8d..5593fd94f6 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -74,8 +74,8 @@ QUICKTESTS = \ qquickview \ qquickcanvasitem \ qquickscreen \ - touchmouse - + touchmouse \ + scenegraph SUBDIRS += $$PUBLICTESTS diff --git a/tests/auto/quick/scenegraph/data/mipmap_large.png b/tests/auto/quick/scenegraph/data/mipmap_large.png Binary files differindex 9cb0fc7de1..1b6d99c45c 100644 --- a/tests/auto/quick/scenegraph/data/mipmap_large.png +++ b/tests/auto/quick/scenegraph/data/mipmap_large.png diff --git a/tests/auto/quick/scenegraph/data/mipmap_small.png b/tests/auto/quick/scenegraph/data/mipmap_small.png Binary files differindex dc5216fb6c..2e53012ef5 100644 --- a/tests/auto/quick/scenegraph/data/mipmap_small.png +++ b/tests/auto/quick/scenegraph/data/mipmap_small.png diff --git a/tests/auto/quick/scenegraph/data/render_Mipmap.qml b/tests/auto/quick/scenegraph/data/render_Mipmap.qml index 6d9191c5ac..9bd585373a 100644 --- a/tests/auto/quick/scenegraph/data/render_Mipmap.qml +++ b/tests/auto/quick/scenegraph/data/render_Mipmap.qml @@ -32,6 +32,7 @@ ****************************************************************************/ import QtQuick 2.3 +import QtQuick.Window 2.2 /* The test verifies that scaled down mipmapped images contains @@ -39,8 +40,8 @@ import QtQuick 2.3 #samples: 2 PixelPos R G B Error-tolerance - #final: 0 0 0.33 0.33 0.33 0.1 - #final: 1 0 0.33 0.33 0.33 0.1 + #final: 0 0 0.25 0.25 0.25 0.1 + #final: 1 0 0.25 0.25 0.25 0.1 */ RenderTestBase @@ -52,7 +53,7 @@ RenderTestBase source: "mipmap_small.png" mipmap: true smooth: false - scale: 1 / width; + scale: 1 / (width * Screen.devicePixelRatio); } Image { @@ -62,7 +63,7 @@ RenderTestBase source: "mipmap_large.png" mipmap: true smooth: false - scale: 1 / width; + scale: 1 / (width * Screen.devicePixelRatio); } onEnterFinalStage: finalStageComplete = true; diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index d2d3643ca8..80672e234e 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -33,11 +33,17 @@ #include <qtest.h> +#include <QOffscreenSurface> +#include <QOpenGLContext> +#include <QOpenGLFunctions> + #include <QtQuick> +#include <QtQml> #include <private/qopenglcontext_p.h> +#include <private/qsgcontext_p.h> +#include <private/qsgrenderloop_p.h> -#include <QtQml> class PerPixelRect : public QQuickItem { @@ -97,6 +103,12 @@ private slots: void render(); void hideWithOtherContext(); + + void createTextureFromImage_data(); + void createTextureFromImage(); + +private: + bool m_brokenMipmapSupport; }; template <typename T> class ScopedList : public QList<T> { @@ -107,6 +119,42 @@ public: void tst_SceneGraph::initTestCase() { qmlRegisterType<PerPixelRect>("SceneGraphTest", 1, 0, "PerPixelRect"); + + QSGRenderLoop *loop = QSGRenderLoop::instance(); + qDebug() << "RenderLoop: " << loop; + + QOpenGLContext context; + context.setFormat(loop->sceneGraphContext()->defaultSurfaceFormat()); + context.create(); + QSurfaceFormat format = context.format(); + + QOffscreenSurface surface; + surface.setFormat(format); + surface.create(); + if (!context.makeCurrent(&surface)) + qFatal("Failed to create a GL context..."); + + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + qDebug() << "R/G/B/A Buffers: " << format.redBufferSize() << format.greenBufferSize() << format.blueBufferSize() << format.alphaBufferSize(); + qDebug() << "Depth Buffer: " << format.depthBufferSize(); + qDebug() << "Stencil Buffer: " << format.stencilBufferSize(); + qDebug() << "Samples: " << format.samples(); + int textureSize; + funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &textureSize); + qDebug() << "Max Texture Size: " << textureSize; + qDebug() << "GL_VENDOR: " << (const char *) funcs->glGetString(GL_VENDOR); + qDebug() << "GL_RENDERER: " << (const char *) funcs->glGetString(GL_RENDERER); + QByteArray version = (const char *) funcs->glGetString(GL_VERSION); + qDebug() << "GL_VERSION: " << version.constData(); + QSet<QByteArray> exts = context.extensions(); + QByteArray all; + foreach (const QByteArray &e, exts) all += ' ' + e; + qDebug() << "GL_EXTENSIONS: " << all.constData(); + + m_brokenMipmapSupport = version.contains("Mesa 10.1") || version.contains("Mesa 9."); + qDebug() << "Broken Mipmap: " << m_brokenMipmapSupport; + + context.doneCurrent(); } QQuickView *createView(const QString &file, QWindow *parent = 0, int x = -1, int y = -1, int w = -1, int h = -1) @@ -210,7 +258,7 @@ void tst_SceneGraph::manyWindows_data() struct ShareContextResetter { public: - ~ShareContextResetter() { QOpenGLContextPrivate::setGlobalShareContext(0); } + ~ShareContextResetter() { qt_gl_set_global_share_context(0); } }; void tst_SceneGraph::manyWindows() @@ -223,7 +271,7 @@ void tst_SceneGraph::manyWindows() ShareContextResetter cleanup; // To avoid dangling pointer in case of test-failure. if (shared) { QVERIFY(sharedGLContext.create()); - QOpenGLContextPrivate::setGlobalShareContext(&sharedGLContext); + qt_gl_set_global_share_context(&sharedGLContext); } QScopedPointer<QWindow> parent; @@ -297,8 +345,8 @@ struct Sample { .arg(color.redF()).arg(color.greenF()).arg(color.blueF()); } - bool check(const QImage &image) { - QColor color(image.pixel(x, y)); + bool check(const QImage &image, qreal scale) { + QColor color(image.pixel(x * scale, y * scale)); return qAbs(color.redF() - r) <= tolerance && qAbs(color.greenF() - g) <= tolerance && qAbs(color.blueF() - b) <= tolerance; @@ -368,11 +416,11 @@ void tst_SceneGraph::render_data() << "data/render_BreakOpacityBatch.qml" << "data/render_OutOfFloatRange.qml" << "data/render_StackingOrder.qml" - << "data/render_Mipmap.qml" << "data/render_ImageFiltering.qml" << "data/render_bug37422.qml" - << "data/render_OpacityThroughBatchRoot.qml" - ; + << "data/render_OpacityThroughBatchRoot.qml"; + if (!m_brokenMipmapSupport) + files << "data/render_Mipmap.qml"; QRegExp sampleCount("#samples: *(\\d+)"); // X:int Y:int R:float G:float B:float Error:float @@ -428,11 +476,18 @@ void tst_SceneGraph::render() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + // We're checking actual pixels, so scale up the sample point to the top-left of the + // 2x2 pixel block and hope that this is good enough. Ideally, view and content + // would be in identical coordinate space, meaning pixels, but we're not in an + // ideal world. + // Just keep this in mind when writing tests. + qreal scale = view.devicePixelRatio(); + // Grab the window and check all our base stage samples QImage content = view.grabWindow(); for (int i=0; i<baseStage.size(); ++i) { Sample sample = baseStage.at(i); - QVERIFY2(sample.check(content), qPrintable(sample.toString(content))); + QVERIFY2(sample.check(content, scale), qPrintable(sample.toString(content))); } // Put the qml file into the final stage and wait for it to @@ -445,7 +500,7 @@ void tst_SceneGraph::render() content = view.grabWindow(); for (int i=0; i<finalStage.size(); ++i) { Sample sample = finalStage.at(i); - QVERIFY2(sample.check(content), qPrintable(sample.toString(content))); + QVERIFY2(sample.check(content, scale), qPrintable(sample.toString(content))); } } @@ -482,6 +537,34 @@ void tst_SceneGraph::hideWithOtherContext() QVERIFY(!renderingOnMainThread || QOpenGLContext::currentContext() != &context); } +void tst_SceneGraph::createTextureFromImage_data() +{ + QImage rgba(64, 64, QImage::Format_ARGB32_Premultiplied); + QImage rgb(64, 64, QImage::Format_RGB32); + + QTest::addColumn<QImage>("image"); + QTest::addColumn<uint>("flags"); + QTest::addColumn<bool>("expectedAlpha"); + + QTest::newRow("rgb") << rgb << uint(0) << false; + QTest::newRow("argb") << rgba << uint(0) << true; + QTest::newRow("rgb,alpha") << rgb << uint(QQuickWindow::TextureHasAlphaChannel) << false; + QTest::newRow("argb,alpha") << rgba << uint(QQuickWindow::TextureHasAlphaChannel) << true; + QTest::newRow("rgb,!alpha") << rgb << uint(QQuickWindow::TextureIsOpaque) << false; + QTest::newRow("argb,!alpha") << rgba << uint(QQuickWindow::TextureIsOpaque) << false; +} + +void tst_SceneGraph::createTextureFromImage() +{ + QFETCH(QImage, image); + QFETCH(uint, flags); + QFETCH(bool, expectedAlpha); + + QQuickView view; + QScopedPointer<QSGTexture> texture(view.createTextureFromImage(image, (QQuickWindow::CreateTextureOptions) flags)); + QCOMPARE(texture->hasAlphaChannel(), expectedAlpha); +} + #include "tst_scenegraph.moc" diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp index 5b9111d448..86d61a0c23 100644 --- a/tests/auto/quick/shared/viewtestutil.cpp +++ b/tests/auto/quick/shared/viewtestutil.cpp @@ -72,18 +72,30 @@ void QQuickViewTestUtil::moveMouseAway(QQuickView *window) #endif } +void QQuickViewTestUtil::moveAndRelease(QQuickView *window, const QPoint &position) +{ + QTest::mouseMove(window, position); + QTest::mouseRelease(window, Qt::LeftButton, 0, position); +} + +void QQuickViewTestUtil::moveAndPress(QQuickView *window, const QPoint &position) +{ + QTest::mouseMove(window, position); + QTest::mousePress(window, Qt::LeftButton, 0, position); +} + void QQuickViewTestUtil::flick(QQuickView *window, const QPoint &from, const QPoint &to, int duration) { const int pointCount = 5; QPoint diff = to - from; // send press, five equally spaced moves, and release. - QTest::mousePress(window, Qt::LeftButton, 0, from); + moveAndPress(window, from); for (int i = 0; i < pointCount; ++i) QTest::mouseMove(window, from + (i+1)*diff/pointCount, duration / pointCount); - QTest::mouseRelease(window, Qt::LeftButton, 0, to); + moveAndRelease(window, to); QTest::qWait(50); } diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index 8c5f5c54e6..1643eca979 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -48,6 +48,8 @@ namespace QQuickViewTestUtil void centerOnScreen(QQuickView *window, const QSize &size); void centerOnScreen(QQuickView *window); void moveMouseAway(QQuickView *window); + void moveAndPress(QQuickView *window, const QPoint &position); + void moveAndRelease(QQuickView *window, const QPoint &position); QList<int> adjustIndexesForAddDisplaced(const QList<int> &indexes, int index, int count); QList<int> adjustIndexesForMove(const QList<int> &indexes, int from, int to, int count); diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index 539bbb4703..90ee8215a1 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -863,7 +863,7 @@ void tst_TouchMouse::pinchOnFlickable() QVERIFY(rect); // flickable - single touch point - QVERIFY(flickable->contentX() == 0.0); + QCOMPARE(flickable->contentX(), 0.0); QPoint p = QPoint(100, 100); QTest::touchEvent(window, device).press(0, p, window); QQuickTouchUtils::flush(window); @@ -945,7 +945,7 @@ void tst_TouchMouse::flickableOnPinch() QVERIFY(rect); // flickable - single touch point - QVERIFY(flickable->contentX() == 0.0); + QCOMPARE(flickable->contentX(), 0.0); QPoint p = QPoint(100, 100); QTest::touchEvent(window, device).press(0, p, window); QQuickTouchUtils::flush(window); @@ -1025,7 +1025,7 @@ void tst_TouchMouse::mouseOnFlickableOnPinch() QVERIFY(rect); // flickable - single touch point - QVERIFY(flickable->contentX() == 0.0); + QCOMPARE(flickable->contentX(), 0.0); QPoint p = QPoint(100, 100); QTest::touchEvent(window, device).press(0, p, window); QQuickTouchUtils::flush(window); diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index 3da920ca27..11696e288f 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -226,8 +226,8 @@ void tst_qquickwidget::errors() QQmlTestMessageHandler messageHandler; view->setSource(testFileUrl("error1.qml")); - QVERIFY(view->status() == QQuickWidget::Error); - QVERIFY(view->errors().count() == 1); + QCOMPARE(view->status(), QQuickWidget::Error); + QCOMPARE(view->errors().count(), 1); } void tst_qquickwidget::engine() diff --git a/tests/benchmarks/script/qjsvalue/tst_qjsvalue.cpp b/tests/benchmarks/script/qjsvalue/tst_qjsvalue.cpp index a8e99b5cf9..b5147dbf01 100644 --- a/tests/benchmarks/script/qjsvalue/tst_qjsvalue.cpp +++ b/tests/benchmarks/script/qjsvalue/tst_qjsvalue.cpp @@ -34,12 +34,6 @@ #include <qtest.h> #include <QJSEngine> #include <QJSValue> -#include <private/v8.h> - -QT_BEGIN_NAMESPACE -extern Q_QML_EXPORT v8::Local<v8::Context> qt_QJSEngineV8Context(QJSEngine *); -extern Q_QML_EXPORT v8::Local<v8::Value> qt_QJSValueV8Value(const QJSValue &); -QT_END_NAMESPACE class tst_QJSValue : public QObject { @@ -49,16 +43,12 @@ public: private slots: void fillArray(); - void fillArray_V8(); void property(); - void property_V8(); void setProperty(); - void setProperty_V8(); void call(); - void call_V8(); }; void tst_QJSValue::fillArray() @@ -72,20 +62,6 @@ void tst_QJSValue::fillArray() } } -void tst_QJSValue::fillArray_V8() -{ - QJSEngine eng; - static const int ArrayLength = 10000; - QJSValue array = eng.newArray(ArrayLength); - - v8::HandleScope handleScope; - v8::Local<v8::Array> v8array = qt_QJSValueV8Value(array).As<v8::Array>(); - QBENCHMARK { - for (int i = 0; i < ArrayLength; ++i) - v8array->Set(i, v8::Number::New(i)); - } -} - void tst_QJSValue::property() { QJSEngine eng; @@ -98,23 +74,6 @@ void tst_QJSValue::property() } } -void tst_QJSValue::property_V8() -{ - QJSEngine eng; - QJSValue object = eng.newObject(); - QString propertyName = QString::fromLatin1("foo"); - object.setProperty(propertyName, 123); - QVERIFY(object.property(propertyName).isNumber()); - - v8::HandleScope handleScope; - v8::Local<v8::Object> v8object = qt_QJSValueV8Value(object).As<v8::Object>(); - v8::Local<v8::String> v8propertyName = v8::String::New("foo"); - QVERIFY(v8object->Get(v8propertyName)->IsNumber()); - QBENCHMARK { - v8object->Get(v8propertyName); - } -} - void tst_QJSValue::setProperty() { QJSEngine eng; @@ -126,24 +85,6 @@ void tst_QJSValue::setProperty() } } -void tst_QJSValue::setProperty_V8() -{ - QJSEngine eng; - QJSValue object = eng.newObject(); - - v8::HandleScope handleScope; - // A context scope is needed for v8::Object::Set(), otherwise we crash. - v8::Local<v8::Context> context = qt_QJSEngineV8Context(&eng); - v8::Context::Scope contextScope(context); - - v8::Local<v8::Object> v8object = qt_QJSValueV8Value(object).As<v8::Object>(); - v8::Local<v8::String> v8propertyName = v8::String::New("foo"); - v8::Local<v8::Value> v8value = v8::Number::New(123); - QBENCHMARK { - v8object->Set(v8propertyName, v8value); - } -} - #define TEST_FUNCTION_SOURCE "(function() { return 123; })" void tst_QJSValue::call() @@ -158,24 +99,6 @@ void tst_QJSValue::call() } } -void tst_QJSValue::call_V8() -{ - QJSEngine eng; - QJSValue fun = eng.evaluate(TEST_FUNCTION_SOURCE); - QVERIFY(fun.isCallable()); - - v8::HandleScope handleScope; - v8::Local<v8::Context> context = qt_QJSEngineV8Context(&eng); - v8::Context::Scope contextScope(context); - - v8::Local<v8::Function> v8fun = qt_QJSValueV8Value(fun).As<v8::Function>(); - v8::Local<v8::Object> v8thisObject = v8::Object::New(); - QVERIFY(v8fun->Call(v8thisObject, /*argc=*/0, /*argv=*/0)->IsNumber()); - QBENCHMARK { - v8fun->Call(v8thisObject, /*argc=*/0, /*argv=*/0); - } -} - QTEST_MAIN(tst_QJSValue) #include "tst_qjsvalue.moc" |