summaryrefslogtreecommitdiff
path: root/tests/auto/qgeomapcontroller
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2016-03-01 16:24:40 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-03-17 06:56:11 +0000
commitde165175549642c7fefa901d41ee96ef0702879c (patch)
treec89145289e0a7147870bef06bfb8755440837d10 /tests/auto/qgeomapcontroller
parent3d8da84e368f87386f14287b10fb6d08e3ce2b48 (diff)
downloadqtlocation-de165175549642c7fefa901d41ee96ef0702879c.tar.gz
Remove QGeoMapController from QGeoMap
Refactor code to use QGeoCameraData directly. All functionality related to zoom, center boundary checks are now handled in QDeclaratvieGeoMap class. This makes handling of center and zoomLevel properties much simpler and less error prone, since camera data can not be modified along the call stack. As result we avoid forwarding change signals back and forth: * qgeodeclarativegeomap::setCenter -> qgeomapcontroller::setCenter * qgeomapcontroller::setCenter -> qgeomap::setCameraData * qgeomap::setCameraData -> qgeomacontroller::cameraDataChanged * qgeomapcontroller::cameraDataChanged -> emit qdecalartivegeomap::centerChanged Call always setCenter and setZoomLevel on qdeclarativegeomap instance instead. Introduce initialize() method to handle cases where map plugin is loaded and scenegraph geometery is not yet set. This is required to correctly handle new boundary checks to limit grey areas. Change-Id: I6066cefd4a648dc76333dc241d1f261451a32e9c Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests/auto/qgeomapcontroller')
-rw-r--r--tests/auto/qgeomapcontroller/qgeomapcontroller.pro7
-rw-r--r--tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp369
2 files changed, 0 insertions, 376 deletions
diff --git a/tests/auto/qgeomapcontroller/qgeomapcontroller.pro b/tests/auto/qgeomapcontroller/qgeomapcontroller.pro
deleted file mode 100644
index 545d41f5..00000000
--- a/tests/auto/qgeomapcontroller/qgeomapcontroller.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = app
-CONFIG += testcase
-TARGET = tst_qgeomapcontroller
-
-SOURCES += tst_qgeomapcontroller.cpp
-
-QT += location-private positioning-private testlib
diff --git a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp b/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp
deleted file mode 100644
index a5650e42..00000000
--- a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp
+++ /dev/null
@@ -1,369 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/QString>
-#include <QtTest/QtTest>
-#include <QtTest/QSignalSpy>
-#include <QtLocation/QGeoServiceProvider>
-#include <QtLocation/private/qgeotiledmap_p.h>
-#include <QtLocation/private/qgeomappingmanager_p.h>
-#include <QtLocation/private/qgeomapcontroller_p.h>
-#include <QtLocation/private/qgeocameracapabilities_p.h>
-#include <cmath> /* for std::abs(double) */
-
-QT_USE_NAMESPACE
-
-class QGeoTiledMapTest: public QGeoTiledMap
-{
- Q_OBJECT
-public:
- QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0)
- : QGeoTiledMap(engine, parent) {}
-public:
- using QGeoTiledMap::setCameraData;
-};
-
-class tst_QGeoMapController : public QObject
-{
- Q_OBJECT
-
-public:
- tst_QGeoMapController();
- ~tst_QGeoMapController();
-
-private:
- void clearSignalSpies();
-
-private Q_SLOTS:
- void initTestCase();
- void signalsConstructedTest();
- void constructorTest_data();
- void constructorTest();
- void centerTest();
- void bearingTest();
- void tiltTest();
- void rollTest();
- void panTest();
- void zoomTest();
-
-private:
- QScopedPointer<QGeoTiledMapTest> m_map;
- QScopedPointer<QSignalSpy> m_signalCenterChanged;
- QScopedPointer<QSignalSpy> m_signalBearingChanged;
- QScopedPointer<QSignalSpy> m_signalTiltChanged;
- QScopedPointer<QSignalSpy> m_signalRollChanged;
- QScopedPointer<QSignalSpy> m_signalZoomChanged;
-};
-
-tst_QGeoMapController::tst_QGeoMapController()
-{
-}
-
-tst_QGeoMapController::~tst_QGeoMapController()
-{
-}
-
-void tst_QGeoMapController::initTestCase()
-{
- // Set custom path since CI doesn't install test plugins
-#ifdef Q_OS_WIN
- QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() +
- QStringLiteral("/../../../../plugins"));
-#else
- QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() +
- QStringLiteral("/../../../plugins"));
-#endif
- QGeoServiceProvider *provider = new QGeoServiceProvider("qmlgeo.test.plugin");
- provider->setAllowExperimental(true);
- QGeoMappingManager *mappingManager = provider->mappingManager();
- QVERIFY2(provider->error() == QGeoServiceProvider::NoError, "Could not load plugin: " + provider->errorString().toLatin1());
-
- m_map.reset(static_cast<QGeoTiledMapTest*>(mappingManager->createMap(this)));
- QVERIFY(m_map);
- m_map->resize(100, 100);
-
- m_signalCenterChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::centerChanged));
- m_signalBearingChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::bearingChanged));
- m_signalTiltChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::tiltChanged));
- m_signalRollChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::rollChanged));
- m_signalZoomChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::zoomChanged));
-}
-
-void tst_QGeoMapController::clearSignalSpies()
-{
- m_signalCenterChanged->clear();
- m_signalBearingChanged->clear();
- m_signalTiltChanged->clear();
- m_signalRollChanged->clear();
- m_signalZoomChanged->clear();
-}
-
-void tst_QGeoMapController::signalsConstructedTest()
-{
- QVERIFY(m_signalCenterChanged->isValid());
- QVERIFY(m_signalBearingChanged->isValid());
- QVERIFY(m_signalTiltChanged->isValid());
- QVERIFY(m_signalRollChanged->isValid());
- QVERIFY(m_signalZoomChanged->isValid());
-}
-
-void tst_QGeoMapController::constructorTest_data()
-{
- QTest::addColumn<QGeoCoordinate>("center");
- QTest::addColumn<QGeoCoordinate>("expectedCenter");
- QTest::addColumn<double>("bearing");
- QTest::addColumn<double>("tilt");
- QTest::addColumn<double>("roll");
- QTest::addColumn<double>("zoom");
- QTest::newRow("zeros") << QGeoCoordinate() << QGeoCoordinate() << 0.0 << 0.0 << 0.0 << 0.0;
- QTest::newRow("valid") << QGeoCoordinate(10.0, 20.5, 30.8) << QGeoCoordinate(10.0, 20.5, 30.8) << 0.1 << 0.2 << 0.3 << 2.0;
- QTest::newRow("negative values") << QGeoCoordinate(-50, -20, 100) << QGeoCoordinate(-50, -20, 100) << -0.1 << -0.2 << -0.3 << 1.0;
- QTest::newRow("clamped center negative") << QGeoCoordinate(-89, -45, 0) << QGeoCoordinate(-80.8728, -45, 0) << -0.1 << -0.2 << -0.3 << 1.0;
- QTest::newRow("clamped center positive") << QGeoCoordinate(86, 38, 0) << QGeoCoordinate(80.8728, 38, 0) << -0.1 << -0.2 << -0.3 << 1.0;
-}
-
-bool almostEqual(float x, float y) // qFuzzyCompare is too strict for this test
-{
- const float epsilon = 1e-5;
- return std::abs(x - y) <= epsilon * std::abs(x);
- // see Knuth section 4.2.2 pages 217-218
-}
-
-void tst_QGeoMapController::constructorTest()
-{
- QFETCH(QGeoCoordinate, center);
- QFETCH(QGeoCoordinate, expectedCenter);
- QFETCH(double, bearing);
- QFETCH(double, tilt);
- QFETCH(double, roll);
- QFETCH(double, zoom);
-
- // test whether the map controller picks up the camera data
- // from the map during construction
- QGeoCameraData cameraData;
- cameraData.setCenter(center);
- cameraData.setBearing(bearing);
- cameraData.setTilt(tilt);
- cameraData.setRoll(roll);
- cameraData.setZoomLevel(zoom);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
-
-
- // make sure the values come out the same
- // also make sure the values match what they were actually set to
- if (qIsNaN(cameraData.center().longitude())) {
- QVERIFY(qIsNaN(mapController.center().longitude()));
- } else {
- QCOMPARE(mapController.center().longitude(), expectedCenter.longitude());
- }
- if (qIsNaN(cameraData.center().altitude())) {
- QVERIFY(qIsNaN(mapController.center().altitude()));
- } else {
- QCOMPARE(mapController.center().altitude(), expectedCenter.altitude());
- }
-
- // Verify that the latitude is either what was set or that it has been clamped correctly
- if (qIsNaN(cameraData.center().latitude())) {
- QVERIFY(qIsNaN(mapController.center().latitude()));
- } else {
- QVERIFY(almostEqual(mapController.center().latitude(), expectedCenter.latitude()));
- }
-
- QCOMPARE(mapController.zoom(), cameraData.zoomLevel());
- QCOMPARE(mapController.zoom(), zoom);
-
- if (m_map->cameraCapabilities().supportsBearing()){
- QCOMPARE(mapController.bearing(), cameraData.bearing());
- QCOMPARE(mapController.bearing(), bearing);
- }
- if (m_map->cameraCapabilities().supportsTilting()){
- QCOMPARE(mapController.tilt(), cameraData.tilt());
- QCOMPARE(mapController.tilt(), tilt);
- }
- if (m_map->cameraCapabilities().supportsRolling()){
- QCOMPARE(mapController.roll(), cameraData.roll());
- QCOMPARE(mapController.roll(), roll);
- }
-}
-
-void tst_QGeoMapController::centerTest()
-{
- QGeoCameraData cameraData;
- cameraData.setCenter(QGeoCoordinate(10.0,-20.4,30.8));
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.center(),QGeoCoordinate(10.0,-20.4,30.8));
-
- QGeoCoordinate coord(10.0,20.4,30.8);
- clearSignalSpies();
- mapController.setCenter(coord);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),1);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
-
- QCOMPARE(mapController.center(),QGeoCoordinate(10.0,20.4,30.8));
-
- mapController.setCenter(QGeoCoordinate(10.0,20.4,30.9));
- QCOMPARE(mapController.center(),QGeoCoordinate(10.0,20.4,30.9));
-}
-
-void tst_QGeoMapController::bearingTest()
-{
- if (m_map->cameraCapabilities().supportsBearing()){
- qreal bearing = 1.4;
-
- QGeoCameraData cameraData;
- cameraData.setBearing(bearing);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.bearing(),bearing);
-
- clearSignalSpies();
- mapController.setBearing(-1.5);
- QCOMPARE(mapController.bearing(),-1.5);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),1);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
- }
-}
-
-void tst_QGeoMapController::tiltTest()
-{
- if (m_map->cameraCapabilities().supportsTilting()){
- qreal tilt = m_map->cameraCapabilities().maximumTilt();
-
- QGeoCameraData cameraData;
- cameraData.setTilt(tilt);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.tilt(),tilt);
-
- tilt = m_map->cameraCapabilities().minimumTilt();
- clearSignalSpies();
- mapController.setTilt(tilt);
- QCOMPARE(mapController.tilt(),tilt);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),1);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
- }
-}
-
-void tst_QGeoMapController::rollTest()
-{
- if (m_map->cameraCapabilities().supportsRolling()){
- qreal roll = 1.4;
-
- QGeoCameraData cameraData;
- cameraData.setRoll(roll);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.roll(),roll);
-
- clearSignalSpies();
- mapController.setRoll(-1.5);
- QCOMPARE(mapController.roll(),-1.5);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),1);
- QCOMPARE(m_signalZoomChanged->count(),0);
- }
-}
-
-void tst_QGeoMapController::panTest()
-{
- QGeoMapController mapController(m_map.data());
-
- mapController.setCenter(QGeoCoordinate(-1.0,-2.4,3.8));
-
- // check that pan of zero leaves the camera centre unaltered
- mapController.pan(0, 0);
- QCOMPARE(mapController.center().altitude(), 3.8);
- QCOMPARE(mapController.center().latitude(), -1.0);
- QCOMPARE(mapController.center().longitude(), -2.4);
-
- qreal dx = 13.1;
- qreal dy = -9.3;
- clearSignalSpies();
- mapController.pan(dx, dy);
-
- // rather than verify the exact new position, we check that the position has changed and the altitude
- // is unaffected
- QCOMPARE(mapController.center().altitude(), 3.8);
- QVERIFY(qFuzzyCompare(mapController.center().latitude(), -1.0) == false);
- QVERIFY(qFuzzyCompare(mapController.center().longitude(), -2.4) == false);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),1);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
-}
-
-void tst_QGeoMapController::zoomTest()
-{
- QGeoCameraData cameraData;
- cameraData.setZoomLevel(1.4);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
-
- QCOMPARE(mapController.zoom(),1.4);
- mapController.setZoom(1.4);
- QCOMPARE(mapController.zoom(),1.4);
- clearSignalSpies();
- mapController.setZoom(1.5);
- QCOMPARE(mapController.zoom(),1.5);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),1);
-}
-
-
-QTEST_MAIN(tst_QGeoMapController)
-
-#include "tst_qgeomapcontroller.moc"