summaryrefslogtreecommitdiff
path: root/tests/auto/positionplugin
diff options
context:
space:
mode:
authoralex <alex.blasche@nokia.com>2011-10-05 16:45:23 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-05 08:55:32 +0200
commitfafb32c0b7ce213948da82f76d586a0aaa59c98a (patch)
tree55dad3bfdca891d8aba7052801052026413cf604 /tests/auto/positionplugin
parente7c2c1281a238e4c9e7cf37c4e770b38d8a238a5 (diff)
downloadqtlocation-fafb32c0b7ce213948da82f76d586a0aaa59c98a.tar.gz
Add a dummy position plugin for test case execution.
The additional test case verifies that dynamic position plugins are properly loaded. More advanced QgeoPositionInfoSource tests will follow. Change-Id: Idb8c84a4555606814868dfb0e5b019f96878f145 Reviewed-on: http://codereview.qt-project.org/6018 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'tests/auto/positionplugin')
-rw-r--r--tests/auto/positionplugin/plugin.cpp213
-rw-r--r--tests/auto/positionplugin/positionplugin.pro11
2 files changed, 224 insertions, 0 deletions
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