diff options
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/positionplugin/plugin.cpp | 213 | ||||
-rw-r--r-- | tests/auto/positionplugin/positionplugin.pro | 11 | ||||
-rw-r--r-- | tests/auto/positionplugintest/positionplugintest.pro | 7 | ||||
-rw-r--r-- | tests/auto/positionplugintest/tst_positionplugin.cpp | 105 |
5 files changed, 338 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 7165ae12..f94c6ae4 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,6 +1,8 @@ TEMPLATE = subdirs SUBDIRS += geotestplugin \ + positionplugin \ + positionplugintest \ qgeocodingmanagerplugins \ qgeoaddress \ qgeoboundingbox \ diff --git a/tests/auto/positionplugin/plugin.cpp b/tests/auto/positionplugin/plugin.cpp new file mode 100644 index 00000000..abd51e02 --- /dev/null +++ b/tests/auto/positionplugin/plugin.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** 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 <qgeopositioninfosource.h> +#include <qgeopositioninfosourcefactory.h> +#include <QObject> +#include <QtPlugin> +#include <QTimer> + +QT_USE_NAMESPACE + +class DummySource : public QGeoPositionInfoSource +{ + Q_OBJECT + +public: + DummySource(QObject *parent=0); + ~DummySource(); + + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout=5000); + + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const; + PositioningMethods supportedPositioningMethods() const; + + void setUpdateInterval(int msec); + int minimumUpdateInterval() const; + +private: + QTimer *timer; + QTimer *timeoutTimer; + QTimer *singleTimer; + QGeoPositionInfo lastPosition; + +private slots: + void updatePosition(); + void doTimeout(); +}; + +DummySource::DummySource(QObject *parent) : + QGeoPositionInfoSource(parent), + timer(new QTimer(this)), + timeoutTimer(new QTimer(this)), + singleTimer(new QTimer(this)), + lastPosition(QGeoCoordinate(0,0), QDateTime::currentDateTime()) +{ + timer->setInterval(1000); + connect(timer, SIGNAL(timeout()), + this, SLOT(updatePosition())); + connect(singleTimer, SIGNAL(timeout()), + this, SLOT(updatePosition())); + connect(timeoutTimer, SIGNAL(timeout()), + this, SLOT(doTimeout())); +} + +void DummySource::setUpdateInterval(int msec) +{ + if (msec == 0) { + timer->setInterval(1000); + } else if (msec < 1000) { + msec = 1000; + timer->setInterval(msec); + } else { + timer->setInterval(msec); + } + + QGeoPositionInfoSource::setUpdateInterval(msec); +} + +int DummySource::minimumUpdateInterval() const +{ + return 1000; +} + +QGeoPositionInfo DummySource::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const +{ + Q_UNUSED(fromSatellitePositioningMethodsOnly); + return lastPosition; +} + +QGeoPositionInfoSource::PositioningMethods DummySource::supportedPositioningMethods() const +{ + return QGeoPositionInfoSource::AllPositioningMethods; +} + +void DummySource::startUpdates() +{ + timer->start(); +} + +void DummySource::stopUpdates() +{ + timer->stop(); +} + +void DummySource::requestUpdate(int timeout) +{ + if (timeout == 0) + timeout = 5000; + if (timeout < 0) + timeout = 0; + + timeoutTimer->setInterval(timeout); + timeoutTimer->start(); + + if (timer->isActive()) { + timer->stop(); + timer->start(); + } + + singleTimer->setInterval(1000); + singleTimer->start(); +} + +DummySource::~DummySource() +{} + +void DummySource::updatePosition() +{ + timeoutTimer->stop(); + singleTimer->stop(); + QGeoCoordinate coord(lastPosition.coordinate().latitude() + 0.1, + lastPosition.coordinate().longitude() + 0.1); + QGeoPositionInfo info(coord, QDateTime::currentDateTime()); + lastPosition = info; + emit positionUpdated(info); +} + +void DummySource::doTimeout() +{ + timeoutTimer->stop(); + singleTimer->stop(); + emit updateTimeout(); +} + + +class QGeoPositionInfoSourceFactoryTest : public QObject, public QGeoPositionInfoSourceFactory +{ + Q_OBJECT + Q_INTERFACES(QGeoPositionInfoSourceFactory) + +public: + QString sourceName() const; + int sourceVersion() const; + + QGeoPositionInfoSource *positionInfoSource(QObject *parent); + QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent); +}; + +QString QGeoPositionInfoSourceFactoryTest::sourceName() const +{ + return QLatin1String("test.source"); +} + +int QGeoPositionInfoSourceFactoryTest::sourceVersion() const +{ + return 1; +} + +QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryTest::positionInfoSource(QObject *parent) +{ + return new DummySource(parent); +} + +QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactoryTest::satelliteInfoSource(QObject *parent) +{ + Q_UNUSED(parent) + // not implemented + return 0; +} + +Q_EXPORT_PLUGIN2(qtposition_testplugin, QGeoPositionInfoSourceFactoryTest) + +#include "plugin.moc" diff --git a/tests/auto/positionplugin/positionplugin.pro b/tests/auto/positionplugin/positionplugin.pro new file mode 100644 index 00000000..4e34d953 --- /dev/null +++ b/tests/auto/positionplugin/positionplugin.pro @@ -0,0 +1,11 @@ +load(qt_plugin) + +TARGET = qtposition_testplugin +QT += location + +DESTDIR = $$QT.location.plugins/position + +SOURCES += plugin.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/position +INSTALLS += target diff --git a/tests/auto/positionplugintest/positionplugintest.pro b/tests/auto/positionplugintest/positionplugintest.pro new file mode 100644 index 00000000..a52ef06a --- /dev/null +++ b/tests/auto/positionplugintest/positionplugintest.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +CONFIG+=testcase +TARGET=tst_positionplugin + +SOURCES += tst_positionplugin.cpp + +QT += location testlib diff --git a/tests/auto/positionplugintest/tst_positionplugin.cpp b/tests/auto/positionplugintest/tst_positionplugin.cpp new file mode 100644 index 00000000..1be8f65b --- /dev/null +++ b/tests/auto/positionplugintest/tst_positionplugin.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/location + +#include <QtTest/QtTest> +#include <QSignalSpy> +#include <qgeopositioninfosource.h> +#include <qgeosatelliteinfosource.h> +#include <qgeocoordinate.h> + +QT_USE_NAMESPACE + +Q_DECLARE_METATYPE(QGeoPositionInfo) + +class tst_PositionPlugin : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + + void availableSources(); + void create(); + void getUpdates(); +}; + +void tst_PositionPlugin::initTestCase() +{ + qRegisterMetaType<QGeoPositionInfo>(); +} + +void tst_PositionPlugin::availableSources() +{ + QVERIFY(QGeoPositionInfoSource::availableSources().contains("test.source")); + QVERIFY(QGeoSatelliteInfoSource::availableSources().contains("test.source")); +} + +void tst_PositionPlugin::create() +{ + QGeoPositionInfoSource *src = 0; + src = QGeoPositionInfoSource::createSource("test.source", 0); + QVERIFY(src != 0); + + QVERIFY(src->minimumUpdateInterval() == 1000); +} + +void tst_PositionPlugin::getUpdates() +{ + QGeoPositionInfoSource *src = QGeoPositionInfoSource::createSource("test.source", 0); + src->setUpdateInterval(1000); + + QSignalSpy spy(src, SIGNAL(positionUpdated(QGeoPositionInfo))); + src->startUpdates(); + QTest::qWait(1500); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy[0].size(), 1); + + QGeoPositionInfo info = qvariant_cast<QGeoPositionInfo>(spy[0][0]); + QCOMPARE(info.coordinate().latitude(), 0.1); + QCOMPARE(info.coordinate().longitude(), 0.1); +} + + + +QTEST_GUILESS_MAIN(tst_PositionPlugin) +#include "tst_positionplugin.moc" |