summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorabcd <qt-info@nokia.com>2011-07-05 10:43:53 +1000
committerabcd <qt-info@nokia.com>2011-07-05 10:43:53 +1000
commit70f1975bb478034f88a8250011aea49ee397dca9 (patch)
tree92edd322274d3b926573c3c188638341b772ffe3
parent31ad98bbc7a1c5020f01bb789f75f18de1fa7f96 (diff)
downloadqtlocation-70f1975bb478034f88a8250011aea49ee397dca9.tar.gz
Add QGeoSearchReply unit test form mobility
This unit test comes from Qt Mobility as at a7f0eaff2295ced345fb05dafb31a2e6c5f98d6e
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qgeosearchreply/qgeosearchreply.pro10
-rw-r--r--tests/auto/qgeosearchreply/tst_qgeosearchreply.cpp291
-rw-r--r--tests/auto/qgeosearchreply/tst_qgeosearchreply.h118
4 files changed, 420 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index e748cfaa..d93549e1 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -10,6 +10,7 @@ SUBDIRS += qgeoaddress \
qgeocoordinate \
qgeolocation \
qgeoplace \
+ qgeosearchreply \
qplacealternativevalue \
qplacebusinessfeature \
qplacecategory \
diff --git a/tests/auto/qgeosearchreply/qgeosearchreply.pro b/tests/auto/qgeosearchreply/qgeosearchreply.pro
new file mode 100644
index 00000000..c51de38a
--- /dev/null
+++ b/tests/auto/qgeosearchreply/qgeosearchreply.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+CONFIG += testcase
+TARGET = tst_qgeosearchreply
+
+HEADERS += ../qgeocoordinate/qlocationtestutils_p.h \
+ tst_qgeosearchreply.h
+SOURCES += tst_qgeosearchreply.cpp \
+ ../qgeocoordinate/qlocationtestutils.cpp
+
+QT += location testlib
diff --git a/tests/auto/qgeosearchreply/tst_qgeosearchreply.cpp b/tests/auto/qgeosearchreply/tst_qgeosearchreply.cpp
new file mode 100644
index 00000000..9224e497
--- /dev/null
+++ b/tests/auto/qgeosearchreply/tst_qgeosearchreply.cpp
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $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_qgeosearchreply.h"
+
+QTM_USE_NAMESPACE
+
+void tst_QGeoSearchReply::initTestCase()
+{
+
+ reply = new SubSearchReply();
+}
+
+void tst_QGeoSearchReply::cleanupTestCase()
+{
+
+ delete reply;
+ delete qgeoplace;
+}
+
+void tst_QGeoSearchReply::init()
+{
+ qRegisterMetaType<QGeoSearchReply::Error>("Error");
+ signalerror = new QSignalSpy(reply, SIGNAL(error(QGeoSearchReply::Error,const QString)));
+ signalfinished = new QSignalSpy(reply, SIGNAL(finished()));
+}
+
+void tst_QGeoSearchReply::cleanup()
+{
+ delete signalerror;
+ delete signalfinished;
+}
+
+void tst_QGeoSearchReply::constructor()
+{
+ QVERIFY(!reply->isFinished());
+
+ QCOMPARE(reply->limit(),-1);
+ QCOMPARE(reply->offset(),0);
+ QCOMPARE(reply->error(),QGeoSearchReply::NoError);
+
+ QVERIFY( signalerror->isValid() );
+ QVERIFY( signalfinished->isValid() );
+
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE(signalfinished->count(),0);
+}
+
+void tst_QGeoSearchReply::constructor_error()
+{
+ QFETCH(QGeoSearchReply::Error,error);
+ QFETCH(QString,msg);
+
+ QVERIFY( signalerror->isValid() );
+ QVERIFY( signalfinished->isValid() );
+
+ QGeoSearchReply *qgeosearchreplycopy = new QGeoSearchReply (error,msg,0);
+
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE(signalfinished->count(),0);
+
+ QCOMPARE (qgeosearchreplycopy->error(),error);
+ QCOMPARE (qgeosearchreplycopy->errorString(),msg);
+
+ delete qgeosearchreplycopy;
+}
+
+void tst_QGeoSearchReply::constructor_error_data()
+{
+ QTest::addColumn<QGeoSearchReply::Error>("error");
+ QTest::addColumn<QString>("msg");
+
+ QTest::newRow("error1") << QGeoSearchReply::NoError << "No error.";
+ QTest::newRow("error2") << QGeoSearchReply::EngineNotSetError << "Engine Not Set Error.";
+ QTest::newRow("error3") << QGeoSearchReply::CommunicationError << "Communication Error.";
+ QTest::newRow("error4") << QGeoSearchReply::ParseError << "Parse Error.";
+ QTest::newRow("error5") << QGeoSearchReply::UnsupportedOptionError << "Unsupported Option Error.";
+ QTest::newRow("error6") << QGeoSearchReply::UnknownError << "Unknown Error.";
+
+}
+
+void tst_QGeoSearchReply::destructor()
+{
+ QGeoSearchReply *qgeosearchreplycopy;
+ QFETCH(QGeoSearchReply::Error,error);
+ QFETCH(QString,msg);
+
+ QLocationTestUtils::uheap_mark();
+ qgeosearchreplycopy = new QGeoSearchReply (error,msg,0);
+ delete qgeosearchreplycopy;
+ QLocationTestUtils::uheap_mark_end();
+
+}
+
+void tst_QGeoSearchReply::destructor_data()
+{
+ tst_QGeoSearchReply::constructor_error_data();
+}
+
+void tst_QGeoSearchReply::abort()
+{
+ QVERIFY( signalerror->isValid() );
+ QVERIFY( signalfinished->isValid() );
+
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),0);
+
+ reply->callSetFinished(true);
+ reply->abort();
+
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),1);
+
+ reply->abort();
+ reply->callSetFinished(false);
+ reply->abort();
+
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),2);
+}
+
+void tst_QGeoSearchReply::error()
+{
+ QFETCH(QGeoSearchReply::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_QGeoSearchReply::error_data()
+{
+ QTest::addColumn<QGeoSearchReply::Error>("error");
+ QTest::addColumn<QString>("msg");
+
+ QTest::newRow("error1") << QGeoSearchReply::NoError << "No error.";
+ QTest::newRow("error2") << QGeoSearchReply::EngineNotSetError << "Engine Not Set Error.";
+ QTest::newRow("error3") << QGeoSearchReply::CommunicationError << "Communication Error.";
+ QTest::newRow("error4") << QGeoSearchReply::ParseError << "Parse Error.";
+ QTest::newRow("error5") << QGeoSearchReply::UnsupportedOptionError << "Unsupported Option Error.";
+ QTest::newRow("error6") << QGeoSearchReply::UnknownError << "Unknown Error.";
+}
+
+void tst_QGeoSearchReply::finished()
+{
+ QVERIFY( signalerror->isValid() );
+ QVERIFY( signalfinished->isValid() );
+
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),0);
+
+ reply->callSetFinished(true);
+ QVERIFY(reply->isFinished());
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),1);
+
+ reply->callSetFinished(false);
+
+ QVERIFY(!reply->isFinished());
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),1);
+
+ reply->callSetFinished(true);
+
+ QVERIFY(reply->isFinished());
+ QCOMPARE(signalerror->count(),0);
+ QCOMPARE (signalfinished->count(),2);
+}
+
+
+
+void tst_QGeoSearchReply::limit()
+{
+ int limit =30;
+ reply->callSetLimit(limit);
+ QCOMPARE(reply->limit(),limit);
+}
+
+void tst_QGeoSearchReply::offset()
+{
+ int offset = 2;
+ reply->callSetOffset(offset);
+ QCOMPARE(reply->offset(),offset);
+}
+
+void tst_QGeoSearchReply::places()
+{
+ QList <QGeoPlace> geoplaces;
+ geoplaces = reply->places();
+
+ QCOMPARE(geoplaces.size(),0);
+
+ QGeoAddress *qgeoaddress = new QGeoAddress ();
+ qgeoaddress->setCity("Berlin");
+
+ QGeoCoordinate *qgeocoordinate = new QGeoCoordinate (12.12 , 54.43);
+
+ qgeoplace = new QGeoPlace ();
+ qgeoplace->setAddress(*qgeoaddress);
+ qgeoplace->setCoordinate(*qgeocoordinate);
+
+ reply->callAddPlace(*qgeoplace);
+
+ geoplaces = reply->places();
+ QCOMPARE(geoplaces.size(),1);
+ QCOMPARE(geoplaces.at(0),*qgeoplace);
+
+ QGeoPlace *qgeoplacecopy = new QGeoPlace (*qgeoplace);
+
+ QList <QGeoPlace> qgeoplaces;
+ qgeoplaces.append(*qgeoplace);
+ qgeoplaces.append(*qgeoplacecopy);
+
+ reply->callSetPlaces(qgeoplaces);
+
+ geoplaces = reply->places();
+
+ QCOMPARE(geoplaces.size(),qgeoplaces.size());
+ for (int i = 0 ; i < geoplaces.size(); i++)
+ {
+ QCOMPARE(geoplaces.at(i),qgeoplaces.at(i));
+ }
+
+ delete qgeoaddress;
+ delete qgeocoordinate;
+ delete qgeoplacecopy;
+}
+
+void tst_QGeoSearchReply::viewport()
+{
+ QGeoCoordinate *qgeocoordinate = new QGeoCoordinate (12.12 , 54.43);
+
+ qgeoboundingbox = new QGeoBoundingBox (*qgeocoordinate, 0.5 , 0.5);
+
+ reply->callSetViewport(qgeoboundingbox);
+
+ QCOMPARE (reply->viewport(), static_cast<QGeoBoundingArea*>(qgeoboundingbox));
+
+ delete qgeocoordinate;
+ delete qgeoboundingbox;
+}
+
+QTEST_MAIN(tst_QGeoSearchReply);
diff --git a/tests/auto/qgeosearchreply/tst_qgeosearchreply.h b/tests/auto/qgeosearchreply/tst_qgeosearchreply.h
new file mode 100644
index 00000000..dfc8cb84
--- /dev/null
+++ b/tests/auto/qgeosearchreply/tst_qgeosearchreply.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $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_QGEOSEARCHREPLY_H
+#define TST_QGEOSEARCHREPLY_H
+
+#include <QtCore/QString>
+#include <QtTest/QtTest>
+#include <QtCore/QCoreApplication>
+#include <QMetaType>
+#include <QSignalSpy>
+
+#include "../qgeocoordinate/qlocationtestutils_p.h"
+
+#include <qgeosearchreply.h>
+#include <qgeoplace.h>
+#include <qgeoaddress.h>
+#include <qgeocoordinate.h>
+#include <qgeoboundingbox.h>
+
+QTM_USE_NAMESPACE
+class SubSearchReply : public QGeoSearchReply
+{
+ Q_OBJECT
+public:
+ SubSearchReply():QGeoSearchReply() {}
+
+ void callAddPlace ( const QGeoPlace & place ) {addPlace(place);}
+ void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);}
+ void callSetFinished ( bool finished ) {setFinished(finished);}
+ void callSetLimit ( int limit ) {setLimit(limit);}
+ void callSetOffset ( int offset ) {setOffset(offset);}
+ void callSetPlaces ( const QList<QGeoPlace> & places ) {setPlaces(places);}
+ void callSetViewport ( QGeoBoundingArea * viewport ) {setViewport(viewport);}
+
+};
+
+class tst_QGeoSearchReply :public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+ //Start Unit Test for QGeoSearchReply
+private slots:
+ void constructor();
+ void constructor_error();
+ void constructor_error_data();
+ void destructor();
+ void destructor_data();
+ void abort();
+ void error();
+ void error_data();
+ void finished();
+ void limit();
+ void offset();
+ void places();
+ void viewport();
+
+ //End Unit Test for QGeoSearchReply
+
+
+
+private:
+ QSignalSpy *signalerror;
+ QSignalSpy *signalfinished;
+ SubSearchReply* reply;
+ QGeoPlace *qgeoplace;
+ QGeoBoundingBox *qgeoboundingbox;
+};
+
+Q_DECLARE_METATYPE( QList<double>);
+Q_DECLARE_METATYPE( QGeoSearchReply::Error);
+
+#endif // TST_QGEOSEARCHREPLY_H
+