From 310618d504aed92ac532c69471ef196829b3f07c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 1 Dec 2011 14:34:10 +0000 Subject: [PATCH] Fix test warnings If the enums aren't correctly registered, the use of signal spy always causes a warning. Change-Id: If7fd0c1765ac33e0c1548701e199e710e2fe3b30 Reviewed-by: Martin Jones --- .../qdeclarativexmllistmodel.pro | 2 +- .../tst_qdeclarativexmllistmodel.cpp | 60 +++++++++++++--------- .../tst_qquickanimatedimage.cpp | 3 ++ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro b/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro index 6ece73e..10944bc 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro +++ b/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro @@ -9,4 +9,4 @@ DEPLOYMENT += testDataFiles CONFIG += parallel_test -QT += core-private gui-private v8-private declarative-private network testlib xmlpatterns \ No newline at end of file +QT += core-private gui-private v8-private declarative-private network testlib xmlpatterns diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 7a119dd..c2cf4a6 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -57,12 +57,14 @@ #include #include #include +#include "../../../../src/imports/xmllistmodel/qdeclarativexmllistmodel_p.h" typedef QPair QDeclarativeXmlListRange; typedef QList QDeclarativeXmlModelData; Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QDeclarativeXmlModelData) +Q_DECLARE_METATYPE(QDeclarativeXmlListModel::Status) class tst_qdeclarativexmllistmodel : public QObject @@ -70,11 +72,10 @@ class tst_qdeclarativexmllistmodel : public QObject Q_OBJECT public: tst_qdeclarativexmllistmodel() {} - enum Status { Null, Ready, Loading, Error }; private slots: void initTestCase() { - qRegisterMetaType("tst_qdeclarativexmllistmodel::Status"); + qRegisterMetaType(); } void buildModel(); @@ -152,7 +153,7 @@ private: QDeclarativeEngine engine; }; -Q_DECLARE_METATYPE(tst_qdeclarativexmllistmodel::Status) + class CustomNetworkAccessManagerFactory : public QObject, public QDeclarativeNetworkAccessManagerFactory { Q_OBJECT @@ -359,10 +360,12 @@ void tst_qdeclarativexmllistmodel::xml() QSignalSpy spy(model, SIGNAL(statusChanged(QDeclarativeXmlListModel::Status))); QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->property("progress").toDouble(), qreal(0.0)); - QCOMPARE(model->property("status").toInt(), static_cast(Loading)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Loading); QTRY_COMPARE(spy.count(), 1); spy.clear(); QTest::qWait(50); - QCOMPARE(model->property("status").toInt(), static_cast(Ready)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Ready); QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); QCOMPARE(model->count(), 9); @@ -373,12 +376,15 @@ void tst_qdeclarativexmllistmodel::xml() model->setProperty("xml",xml); QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); // immediately goes to 1.0 if using setXml() QTRY_COMPARE(spy.count(), 1); spy.clear(); - QCOMPARE(model->property("status").toInt(), static_cast(Loading)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Loading); QTRY_COMPARE(spy.count(), 1); spy.clear(); if (xml.isEmpty()) - QCOMPARE(model->property("status").toInt(), static_cast(Null)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Null); else - QCOMPARE(model->property("status").toInt(), static_cast(Ready)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Ready); QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->count(), count); @@ -406,7 +412,8 @@ void tst_qdeclarativexmllistmodel::headers() QDeclarativeComponent component(&qmlEng, QUrl::fromLocalFile(TESTDATA("model.qml"))); QListModelInterface *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->property("status").toInt(), static_cast(Ready)); + QTRY_COMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Ready); QVariantMap expectedHeaders; expectedHeaders["Accept"] = "application/xml,*/*"; @@ -424,7 +431,7 @@ void tst_qdeclarativexmllistmodel::source() { QFETCH(QUrl, source); QFETCH(int, count); - QFETCH(Status, status); + QFETCH(QDeclarativeXmlListModel::Status, status); QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("model.qml"))); QListModelInterface *model = qobject_cast(component.create()); @@ -432,19 +439,23 @@ void tst_qdeclarativexmllistmodel::source() QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->property("progress").toDouble(), qreal(0.0)); - QCOMPARE(model->property("status").toInt(), static_cast(Loading)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Loading); QTRY_COMPARE(spy.count(), 1); spy.clear(); - QCOMPARE(model->property("status").toInt(), static_cast(Ready)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Ready); QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); QCOMPARE(model->count(), 9); model->setProperty("source",source); if (model->property("source").toString().isEmpty()) - QCOMPARE(model->property("status").toInt(), static_cast(Null)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Null); QCOMPARE(model->property("progress").toDouble(), qreal(0.0)); QTRY_COMPARE(spy.count(), 1); spy.clear(); - QCOMPARE(model->property("status").toInt(), static_cast(Loading)); + QCOMPARE(qvariant_cast(model->property("status")), + QDeclarativeXmlListModel::Loading); QVERIFY(errorString(model).isEmpty()); QEventLoop loop; @@ -455,19 +466,19 @@ void tst_qdeclarativexmllistmodel::source() timer.start(20000); loop.exec(); - if (spy.count() == 0 && status != Ready) { + if (spy.count() == 0 && status != QDeclarativeXmlListModel::Ready) { qWarning("QDeclarativeXmlListModel invalid source test timed out"); } else { QCOMPARE(spy.count(), 1); spy.clear(); } - QCOMPARE(model->property("status").toInt(), static_cast(status)); + QCOMPARE(qvariant_cast(model->property("status")), status); QCOMPARE(model->count(), count); - if (status == Ready) + if (status == QDeclarativeXmlListModel::Ready) QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); - QCOMPARE(errorString(model).isEmpty(), status == Ready); + QCOMPARE(errorString(model).isEmpty(), status == QDeclarativeXmlListModel::Ready); delete model; } @@ -476,15 +487,18 @@ void tst_qdeclarativexmllistmodel::source_data() { QTest::addColumn("source"); QTest::addColumn("count"); - QTest::addColumn("status"); + QTest::addColumn("status"); - QTest::newRow("valid") << QUrl::fromLocalFile(TESTDATA("model2.xml")) << 2 << Ready; - QTest::newRow("invalid") << QUrl("http://blah.blah/blah.xml") << 0 << Error; + QTest::newRow("valid") << QUrl::fromLocalFile(TESTDATA("model2.xml")) << 2 + << QDeclarativeXmlListModel::Ready; + QTest::newRow("invalid") << QUrl("http://blah.blah/blah.xml") << 0 + << QDeclarativeXmlListModel::Error; // empty file QTemporaryFile *temp = new QTemporaryFile(this); if (temp->open()) - QTest::newRow("empty file") << QUrl::fromLocalFile(temp->fileName()) << 0 << Ready; + QTest::newRow("empty file") << QUrl::fromLocalFile(temp->fileName()) << 0 + << QDeclarativeXmlListModel::Ready; temp->close(); } @@ -944,4 +958,4 @@ void tst_qdeclarativexmllistmodel::roleCrash() QTEST_MAIN(tst_qdeclarativexmllistmodel) -#include "tst_qdeclarativexmllistmodel.moc" \ No newline at end of file +#include "tst_qdeclarativexmllistmodel.moc" diff --git a/tests/auto/declarative/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/declarative/qquickanimatedimage/tst_qquickanimatedimage.cpp index c9394ef..542811e 100644 --- a/tests/auto/declarative/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/declarative/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -51,6 +51,8 @@ #include "../shared/testhttpserver.h" #include "../shared/util.h" +Q_DECLARE_METATYPE(QQuickImageBase::Status) + class tst_qquickanimatedimage : public QObject { Q_OBJECT @@ -340,6 +342,7 @@ void tst_qquickanimatedimage::progressAndStatusChanges() QVERIFY(obj->status() == QQuickImage::Ready); QTRY_VERIFY(obj->progress() == 1.0); + qRegisterMetaType(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(const QUrl &))); QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal))); QSignalSpy statusSpy(obj, SIGNAL(statusChanged(QQuickImageBase::Status))); -- 2.7.4