From a034dc196ebaf82731a8bbe2bf602c5c527c9f76 Mon Sep 17 00:00:00 2001 From: Damian Jansen Date: Thu, 14 Jun 2012 16:19:02 +1000 Subject: [PATCH] Remove superfluous statusChanged signal If the file name is empty, or is a local file, statusChanged would be emitted twice. Task-number: QTBUG-26155 Change-Id: Id341d1c76d45e3fca19260293f632b0b51a34e90 Reviewed-by: Andrew den Exter --- src/quick/items/qquickborderimage.cpp | 2 + .../qquickborderimage/tst_qquickborderimage.cpp | 51 ++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp index 5d4ce7f..87d423f 100644 --- a/src/quick/items/qquickborderimage.cpp +++ b/src/quick/items/qquickborderimage.cpp @@ -305,6 +305,7 @@ void QQuickBorderImage::load() setImplicitSize(0, 0); emit statusChanged(d->status); update(); + return; } else { d->status = Loading; if (d->url.path().endsWith(QLatin1String("sci"))) { @@ -347,6 +348,7 @@ void QQuickBorderImage::load() emit statusChanged(d->status); emit progressChanged(d->progress); update(); + return; } } } diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index c6c3f6c..9bffdbc 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,8 @@ #define SERVER_PORT 14446 #define SERVER_ADDR "http://127.0.0.1:14446" +Q_DECLARE_METATYPE(QQuickImageBase::Status) + class tst_qquickborderimage : public QQmlDataTest { @@ -84,6 +87,9 @@ private slots: void pendingRemoteRequest(); void pendingRemoteRequest_data(); + void statusChanges(); + void statusChanges_data(); + private: QQmlEngine engine; }; @@ -396,6 +402,51 @@ void tst_qquickborderimage::pendingRemoteRequest_data() QTest::newRow("sci file") << "http://localhost/none.sci"; } +//QTBUG-26155 +void tst_qquickborderimage::statusChanges_data() +{ + QTest::addColumn("source"); + QTest::addColumn("emissions"); + QTest::addColumn("remote"); + QTest::addColumn("finalStatus"); + + QTest::newRow("localfile") << testFileUrl("colors.png").toString() << 1 << false << QQuickImageBase::Ready; + QTest::newRow("nofile") << "" << 0 << false << QQuickImageBase::Null; + QTest::newRow("nonexistent") << testFileUrl("thisfiledoesnotexist.png").toString() << 1 << false << QQuickImageBase::Error; + QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 2 << false << QQuickImageBase::Error; + QTest::newRow("remote") << "http://localhost:14446/colors.png" << 2 << true << QQuickImageBase::Ready; +} + +void tst_qquickborderimage::statusChanges() +{ + QFETCH(QString, source); + QFETCH(int, emissions); + QFETCH(bool, remote); + QFETCH(QQuickImageBase::Status, finalStatus); + + TestHTTPServer *server = 0; + if (remote) { + server = new TestHTTPServer(SERVER_PORT); + QVERIFY(server->isValid()); + server->serveDirectory(dataDirectory(), TestHTTPServer::Delay); + } + + QString componentStr = "import QtQuick 2.0\nBorderImage { width: 300; height: 300 }"; + QQmlComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl("")); + + QQuickBorderImage *obj = qobject_cast(component.create()); + qRegisterMetaType(); + QSignalSpy spy(obj, SIGNAL(statusChanged(QQuickImageBase::Status))); + QVERIFY(obj != 0); + obj->setSource(source); + QTRY_VERIFY(obj->status() == finalStatus); + QCOMPARE(spy.count(), emissions); + + delete obj; + delete server; +} + QTEST_MAIN(tst_qquickborderimage) #include "tst_qquickborderimage.moc" -- 2.7.4