diff options
author | alex <alex.blasche@nokia.com> | 2011-12-14 14:57:42 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-15 04:34:22 +0100 |
commit | 298bb31eba85ce4d152c0d9e3cbdefb147bbf984 (patch) | |
tree | 9f94b47b10dda9fb92df045aa2ecb8434ea48bb6 /tests/auto/qgeoroutereply | |
parent | d6e91077ee259e26b4574a2bde8f5990eddf272c (diff) | |
download | qtlocation-298bb31eba85ce4d152c0d9e3cbdefb147bbf984.tar.gz |
Add unit tests for QGeoRoute, QGeoRouteReply & QGeoRouteRequest.
Change-Id: I5844e57023786ea59b36383399b5cb3685dc7c92
Reviewed-by: David Laing <david.laing@nokia.com>
Diffstat (limited to 'tests/auto/qgeoroutereply')
-rw-r--r-- | tests/auto/qgeoroutereply/qgeoroutereply.pro | 9 | ||||
-rw-r--r-- | tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp | 255 | ||||
-rw-r--r-- | tests/auto/qgeoroutereply/tst_qgeoroutereply.h | 109 |
3 files changed, 373 insertions, 0 deletions
diff --git a/tests/auto/qgeoroutereply/qgeoroutereply.pro b/tests/auto/qgeoroutereply/qgeoroutereply.pro new file mode 100644 index 00000000..29f8480c --- /dev/null +++ b/tests/auto/qgeoroutereply/qgeoroutereply.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +CONFIG+=testcase +TARGET=tst_qgeoroutereply + +# Input +HEADERS += tst_qgeoroutereply.h +SOURCES += tst_qgeoroutereply.cpp + +QT += location testlib diff --git a/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp b/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp new file mode 100644 index 00000000..bf951f29 --- /dev/null +++ b/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "tst_qgeoroutereply.h" + +QT_USE_NAMESPACE + +void tst_QGeoRouteReply::initTestCase() +{ + qgeocoordinate1 = new QGeoCoordinate(43.5435 , 76.342); + qgeocoordinate2 = new QGeoCoordinate(-43.5435 , 176.342); + qgeocoordinate3 = new QGeoCoordinate(-13.5435 , +76.342); + + waypoints.append(*qgeocoordinate1); + waypoints.append(*qgeocoordinate2); + waypoints.append(*qgeocoordinate3); + + qgeorouterequest = new QGeoRouteRequest(waypoints); + reply = new SubRouteReply(*qgeorouterequest); +} + +void tst_QGeoRouteReply::cleanupTestCase() +{ + delete qgeocoordinate1; + delete qgeocoordinate2; + delete qgeocoordinate3; + delete qgeorouterequest; + delete reply; +} + +void tst_QGeoRouteReply::init() +{ + qRegisterMetaType<QGeoRouteReply::Error>("Error"); + signalerror = new QSignalSpy(reply, SIGNAL(error(QGeoRouteReply::Error, const QString))); + signalfinished = new QSignalSpy(reply, SIGNAL(finished())); +} + +void tst_QGeoRouteReply::cleanup() +{ + delete signalerror; + delete signalfinished; +} + +void tst_QGeoRouteReply::constructor() +{ + QVERIFY(!reply->isFinished()); + QCOMPARE(reply->error(), QGeoRouteReply::NoError); + QCOMPARE(reply->request(), *qgeorouterequest); + + QVERIFY(signalerror->isValid()); + QVERIFY(signalfinished->isValid()); + + QCOMPARE(signalerror->count(),0); + QCOMPARE(signalfinished->count(),0); +} + +void tst_QGeoRouteReply::constructor_error() +{ + QFETCH(QGeoRouteReply::Error,error); + QFETCH(QString,msg); + + QVERIFY(signalerror->isValid()); + QVERIFY(signalfinished->isValid()); + + QGeoRouteReply *qgeoroutereplycopy = new QGeoRouteReply(error, msg, 0); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 0); + + QVERIFY(qgeoroutereplycopy->isFinished()); + QCOMPARE(qgeoroutereplycopy->error(), error); + QCOMPARE(qgeoroutereplycopy->errorString(), msg); + + delete qgeoroutereplycopy; +} + +void tst_QGeoRouteReply::constructor_error_data() +{ + QTest::addColumn<QGeoRouteReply::Error>("error"); + QTest::addColumn<QString>("msg"); + + QTest::newRow("error1") << QGeoRouteReply::NoError << "No error."; + QTest::newRow("error2") << QGeoRouteReply::EngineNotSetError << "Engine Not Set Error."; + QTest::newRow("error3") << QGeoRouteReply::CommunicationError << "Communication Error."; + QTest::newRow("error4") << QGeoRouteReply::ParseError << "Parse Error."; + QTest::newRow("error5") << QGeoRouteReply::UnsupportedOptionError << "Unsupported Option Error."; + QTest::newRow("error6") << QGeoRouteReply::UnknownError << "Unknown Error."; + +} + +void tst_QGeoRouteReply::destructor() +{ + QGeoRouteReply *qgeoroutereplycopy; + + QFETCH(QGeoRouteReply::Error, error); + QFETCH(QString, msg); + + qgeoroutereplycopy = new QGeoRouteReply(error, msg, 0); + delete qgeoroutereplycopy; + +} + +void tst_QGeoRouteReply::destructor_data() +{ + tst_QGeoRouteReply::constructor_error_data(); +} + +void tst_QGeoRouteReply::routes() +{ + QList<QGeoRoute> routes; + QGeoRoute *route1 = new QGeoRoute(); + QGeoRoute *route2 = new QGeoRoute(); + + route1->setDistance(15.12); + route2->setDistance(20.12); + + routes.append(*route1); + routes.append(*route2); + + reply->callSetRoutes(routes); + + QList<QGeoRoute> routescopy; + routescopy = reply->routes(); + QCOMPARE(routescopy,routes); + + QCOMPARE(routescopy.at(0).distance(),route1->distance()); + QCOMPARE(routescopy.at(1).distance(),route2->distance()); + + delete route1; + delete route2; +} + +void tst_QGeoRouteReply::finished() +{ + QVERIFY(signalerror->isValid()); + QVERIFY(signalfinished->isValid()); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 0); + + reply->callSetFinished(true); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 1); + + reply->callSetFinished(false); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 1); + + reply->callSetFinished(true); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 2); +} + +void tst_QGeoRouteReply::abort() +{ + QVERIFY(signalerror->isValid()); + QVERIFY(signalfinished->isValid()); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 0); + + reply->abort(); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 0); + + reply->abort(); + reply->callSetFinished(false); + reply->abort(); + + QCOMPARE(signalerror->count(), 0); + QCOMPARE(signalfinished->count(), 1); +} + +void tst_QGeoRouteReply::error() +{ + QFETCH(QGeoRouteReply::Error, error); + QFETCH(QString, msg); + + QVERIFY(signalerror->isValid()); + QVERIFY(signalfinished->isValid()); + QCOMPARE(signalerror->count(), 0); + + reply->callSetError(error,msg); + + QCOMPARE(signalerror->count(), 1); + QCOMPARE(signalfinished->count(), 1); + QCOMPARE(reply->errorString(), msg); + QCOMPARE(reply->error(), error); +} + +void tst_QGeoRouteReply::error_data() +{ + QTest::addColumn<QGeoRouteReply::Error>("error"); + QTest::addColumn<QString>("msg"); + + QTest::newRow("error1") << QGeoRouteReply::NoError << "No error."; + QTest::newRow("error2") << QGeoRouteReply::EngineNotSetError << "Engine Not Set Error."; + QTest::newRow("error3") << QGeoRouteReply::CommunicationError << "Communication Error."; + QTest::newRow("error4") << QGeoRouteReply::ParseError << "Parse Error."; + QTest::newRow("error5") << QGeoRouteReply::UnsupportedOptionError << "Unsupported Option Error."; + QTest::newRow("error6") << QGeoRouteReply::UnknownError << "Unknown Error."; +} + +void tst_QGeoRouteReply::request() +{ + SubRouteReply *rr = new SubRouteReply(*qgeorouterequest); + + QCOMPARE(rr->request(), *qgeorouterequest); + + delete rr; +} + +QTEST_APPLESS_MAIN(tst_QGeoRouteReply); diff --git a/tests/auto/qgeoroutereply/tst_qgeoroutereply.h b/tests/auto/qgeoroutereply/tst_qgeoroutereply.h new file mode 100644 index 00000000..09944f84 --- /dev/null +++ b/tests/auto/qgeoroutereply/tst_qgeoroutereply.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TST_QGEOROUTEREPLY_H +#define TST_QGEOROUTEREPLY_H + +#include <QtCore/QString> +#include <QtTest/QtTest> +#include <QMetaType> +#include <QSignalSpy> + +#include <qgeocoordinate.h> +#include <qgeorouterequest.h> +#include <qgeoroutereply.h> +#include <qgeoroute.h> + +QT_USE_NAMESPACE +class SubRouteReply :public QGeoRouteReply +{ + Q_OBJECT +public: + SubRouteReply(QGeoRouteRequest request):QGeoRouteReply(request) {} + void callSetError(QGeoRouteReply::Error error, QString msg) {setError(error,msg);} + void callSetFinished(bool finished) {setFinished(finished);} + void callSetRoutes(const QList<QGeoRoute> & routes ) {setRoutes(routes);} +}; + +class tst_QGeoRouteReply :public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + + //Start Unit Test for QGeoRouteReply +private slots: + void constructor(); + void constructor_error(); + void constructor_error_data(); + void destructor(); + void destructor_data(); + void routes(); + void finished(); + void abort(); + void error(); + void error_data(); + void request(); + //End Unit Test for QGeoRouteReply + + +private: + QGeoCoordinate *qgeocoordinate1; + QGeoCoordinate *qgeocoordinate2; + QGeoCoordinate *qgeocoordinate3; + QGeoRouteRequest *qgeorouterequest; + QSignalSpy *signalerror; + QSignalSpy *signalfinished; + QList<QGeoCoordinate> waypoints; + SubRouteReply* reply; +}; + +Q_DECLARE_METATYPE( QList<QGeoRoute>); +Q_DECLARE_METATYPE( QList<QGeoCoordinate>); +Q_DECLARE_METATYPE( QList<double>); +Q_DECLARE_METATYPE( QGeoRouteReply::Error); + +#endif // TST_QGEOROUTEREPLY_H + |