summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-07-03 15:20:46 +0200
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-02-09 13:58:43 +0000
commit5fd9681a3563e2346c722bcd779e2b16cd4ac9fd (patch)
tree0d85e40638232803e25c0b42f0715e7d363a07ad /tests
parentf5f23c4279b454e2465e7f9835b04cc80332f3a0 (diff)
downloadqtlocation-5fd9681a3563e2346c722bcd779e2b16cd4ac9fd.tar.gz
Refactor prefetching tiles
Current implementation uses same QGeoCameraTiles object to calculate visible tiles and tiles which should be prefetched. This is semi optimal since frustum intersection algorithm uses bunch of different parameters. Simplify the logic and use separate objects, this way values in both cases are cached and calculation is done when required. This is important since prefetchData can be called anytime from map's API. Remove textured tiles from scene when clearCache called, this will force redownload of all the tiles. Add new unit test qgeotiledmap and move prefetch test due to refactoring. Change-Id: I6a906df405f212436cdd35ac76f95b559e6b7aae Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/geotestplugin/qgeotiledmap_test.h13
-rw-r--r--tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h19
-rw-r--r--tests/auto/geotestplugin/qgeotilefetcher_test.h11
-rw-r--r--tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp83
-rw-r--r--tests/auto/qgeomapscene/tst_qgeomapscene.cpp11
-rw-r--r--tests/auto/qgeotiledmap/qgeotiledmap.pro9
-rw-r--r--tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp208
8 files changed, 257 insertions, 98 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index dd95998e..86abefd6 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -50,6 +50,7 @@ qtHaveModule(location) {
qgeoroutingmanager \
qgeoroutingmanagerplugins \
qgeoserviceprovider \
+ qgeotiledmap \
qgeotilespec \
qgeoroutexmlparser \
qgeomapcontroller \
diff --git a/tests/auto/geotestplugin/qgeotiledmap_test.h b/tests/auto/geotestplugin/qgeotiledmap_test.h
index 6cb99806..27ff7164 100644
--- a/tests/auto/geotestplugin/qgeotiledmap_test.h
+++ b/tests/auto/geotestplugin/qgeotiledmap_test.h
@@ -29,20 +29,21 @@
#ifndef QGEOTILEDMAP_TEST_H
#define QGEOTILEDMAP_TEST_H
+#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h>
#include <QtLocation/private/qgeotiledmap_p.h>
QT_USE_NAMESPACE
-
-
+class QGeoTiledMappingManagerEngineTest;
class QGeoTiledMapTest: public QGeoTiledMap
{
Q_OBJECT
public:
- QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0)
- : QGeoTiledMap(engine, parent) {}
+ QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0):
+ QGeoTiledMap(engine, parent),
+ m_engine(engine){}
public:
- using QGeoTiledMap::setCameraData;
-
+ using QGeoTiledMap::setCameraData;
+ QGeoTiledMappingManagerEngine *m_engine;
};
#endif
diff --git a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
index 608edaea..2765c268 100644
--- a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
@@ -57,8 +57,6 @@ public:
capabilities.setMinimumZoomLevel(0.0);
capabilities.setMaximumZoomLevel(20.0);
capabilities.setSupportsBearing(true);
- setCameraCapabilities(capabilities);
-
setTileSize(QSize(256, 256));
QList<QGeoMapType> mapTypes;
@@ -68,14 +66,25 @@ public:
setSupportedMapTypes(mapTypes);
QGeoTileFetcherTest *fetcher = new QGeoTileFetcherTest(this);
- fetcher->setParams(parameters);
- fetcher->setTileSize(QSize(256, 255));
+ if (parameters.contains(QStringLiteral("finishRequestImmediately")))
+ fetcher->setFinishRequestImmediately(parameters.value(QStringLiteral("finishRequestImmediately")).toBool());
+ if (parameters.contains(QStringLiteral("tileSize"))) {
+ int tileSize = parameters.value(QStringLiteral("tileSize")).toInt();
+ setTileSize(QSize(tileSize, tileSize));
+ }
+ if (parameters.contains(QStringLiteral("maxZoomLevel"))) {
+ double maxZoomLevel = parameters.value(QStringLiteral("maxZoomLevel")).toDouble();
+ capabilities.setMaximumZoomLevel(maxZoomLevel);
+ }
+
+ setCameraCapabilities(capabilities);
+ fetcher->setTileSize(tileSize());
setTileFetcher(fetcher);
}
QGeoMap *createMap()
{
- return new QGeoTiledMapTest(this);;
+ return new QGeoTiledMapTest(this);
}
};
diff --git a/tests/auto/geotestplugin/qgeotilefetcher_test.h b/tests/auto/geotestplugin/qgeotilefetcher_test.h
index 29a18cf4..a25b0119 100644
--- a/tests/auto/geotestplugin/qgeotilefetcher_test.h
+++ b/tests/auto/geotestplugin/qgeotilefetcher_test.h
@@ -121,10 +121,9 @@ public:
return mappingReply;
}
- void setParams(const QVariantMap &parameters)
+ void setFinishRequestImmediately(bool enabled)
{
- if (parameters.contains(QStringLiteral("finishRequestImmediately")))
- finishRequestImmediately_ = parameters.value(QStringLiteral("finishRequestImmediately")).toBool();
+ finishRequestImmediately_ = enabled;
}
void setTileSize(QSize tileSize)
@@ -139,6 +138,8 @@ public Q_SLOTS:
errorString_.clear();
errorCode_ = QGeoTiledMapReply::NoError;
}
+Q_SIGNALS:
+ void tileFetched(const QGeoTileSpec&);
protected:
void updateRequest(TiledMapReplyTest* mappingReply)
@@ -149,6 +150,7 @@ protected:
} else {
mappingReply->callSetError(QGeoTiledMapReply::NoError, "no error");
mappingReply->callSetFinished(true);
+ emit tileFetched(mappingReply->tileSpec());
}
}
@@ -159,8 +161,9 @@ protected:
return;
}
updateRequest(m_queue.takeFirst());
- if (m_queue.isEmpty())
+ if (m_queue.isEmpty()) {
timer_.stop();
+ }
}
private:
diff --git a/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp b/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp
index 74d6c580..8d9cec3a 100644
--- a/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp
+++ b/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp
@@ -42,8 +42,6 @@
QT_USE_NAMESPACE
-Q_DECLARE_METATYPE(QGeoCameraTiles::PrefetchStle)
-
struct PositionTestInfo {
QString xyString;
QString zoomString;
@@ -71,8 +69,6 @@ private slots:
void tilesMapType();
void tilesPositions();
void tilesPositions_data();
- void fetchTiles();
- void fetchTiles_data();
};
void tst_QGeoCameraTiles::row(const PositionTestInfo &pti, int xOffset, int yOffset, int tileX, int tileY, int tileW, int tileH)
@@ -127,17 +123,16 @@ void tst_QGeoCameraTiles::tilesPlugin()
camera.setCenter(QGeoCoordinate(0.0, 0.0));
QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
ct.setTileSize(16);
ct.setCameraData(camera);
ct.setScreenSize(QSize(32, 32));
ct.setMapType(QGeoMapType(QGeoMapType::StreetMap, "street map", "street map", false, false, 1));
- QSet<QGeoTileSpec> tiles1 = ct.visibleTiles();
+ QSet<QGeoTileSpec> tiles1 = ct.createTiles();
ct.setPluginString("pluginA");
- QSet<QGeoTileSpec> tiles2 = ct.visibleTiles();
+ QSet<QGeoTileSpec> tiles2 = ct.createTiles();
typedef QSet<QGeoTileSpec>::const_iterator iter;
iter i1 = tiles1.constBegin();
@@ -154,7 +149,7 @@ void tst_QGeoCameraTiles::tilesPlugin()
ct.setPluginString("pluginB");
- QSet<QGeoTileSpec> tiles3 = ct.visibleTiles();
+ QSet<QGeoTileSpec> tiles3 = ct.createTiles();
iter i2 = tiles2.constBegin();
iter end2 = tiles2.constEnd();
@@ -176,18 +171,17 @@ void tst_QGeoCameraTiles::tilesMapType()
camera.setCenter(QGeoCoordinate(0.0, 0.0));
QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
ct.setTileSize(16);
ct.setCameraData(camera);
ct.setScreenSize(QSize(32, 32));
ct.setPluginString("pluginA");
- QSet<QGeoTileSpec> tiles1 = ct.visibleTiles();
+ QSet<QGeoTileSpec> tiles1 = ct.createTiles();
QGeoMapType mapType1 = QGeoMapType(QGeoMapType::StreetMap, "street map", "street map", false, false, 1);
ct.setMapType(mapType1);
- QSet<QGeoTileSpec> tiles2 = ct.visibleTiles();
+ QSet<QGeoTileSpec> tiles2 = ct.createTiles();
typedef QSet<QGeoTileSpec>::const_iterator iter;
iter i1 = tiles1.constBegin();
@@ -205,7 +199,7 @@ void tst_QGeoCameraTiles::tilesMapType()
QGeoMapType mapType2 = QGeoMapType(QGeoMapType::StreetMap, "satellite map", "satellite map", false, false, 2);
ct.setMapType(mapType2);
- QSet<QGeoTileSpec> tiles3 = ct.visibleTiles();
+ QSet<QGeoTileSpec> tiles3 = ct.createTiles();
iter i2 = tiles2.constBegin();
iter end2 = tiles2.constEnd();
@@ -235,7 +229,6 @@ void tst_QGeoCameraTiles::tilesPositions()
camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(mercatorX, mercatorY)));
QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
ct.setTileSize(16);
ct.setCameraData(camera);
ct.setScreenSize(QSize(qCeil(width), qCeil(height)));
@@ -247,7 +240,7 @@ void tst_QGeoCameraTiles::tilesPositions()
for (int i = 0; i < tilesX.size(); ++i)
tiles.insert(QGeoTileSpec("", 0, static_cast<int>(qFloor(zoom)), tilesX.at(i), tilesY.at(i)));
- QCOMPARE(ct.visibleTiles(), tiles);
+ QCOMPARE(ct.createTiles(), tiles);
}
void tst_QGeoCameraTiles::tilesPositions_data()
@@ -1809,67 +1802,5 @@ void tst_QGeoCameraTiles::tilesPositions_data()
test_group(pti, right_t2p1x, right_t2p1w, mid_t2p1x, mid_t2p1w);
}
-void tst_QGeoCameraTiles::fetchTiles()
-{
- QFETCH(double, zoomLevel);
- QFETCH(int, visibleCount);
- QFETCH(int, prefetchCount);
- QFETCH(QGeoCameraTiles::PrefetchStle, style);
- QFETCH(int, nearestNeighbourLayer);
-
- QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
- ct.setTileSize(16);
- ct.setScreenSize(QSize(16, 16));
-
- QGeoCameraData camera;
- camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D( 0.5 , 0.5 )));
-
- camera.setZoomLevel(zoomLevel - 1);
- ct.setCameraData(camera);
- QSet<QGeoTileSpec> prev_visible = ct.visibleTiles();
- camera.setZoomLevel(zoomLevel);
- ct.setCameraData(camera);
- QSet<QGeoTileSpec> visible = ct.visibleTiles();
- QSet<QGeoTileSpec> prefetched = ct.prefetchTiles(style);
- camera.setZoomLevel(zoomLevel + 1);
- ct.setCameraData(camera);
- QSet<QGeoTileSpec> next_visible = ct.visibleTiles();
-
- QVERIFY2(visibleCount == visible.size(), "visible count incorrect");
- QVERIFY2(prefetchCount == prefetched.size(), "prefetch count incorrect");
- QSetIterator<QGeoTileSpec> i(visible);
- while (i.hasNext())
- QVERIFY2(prefetched.contains(i.next()),"visible tile missing from prefetched tiles");
-
- //for zoomLevels wihtout fractions more tiles are fetched for current zoomlevel due to ViewExpansion
- if (qCeil(zoomLevel) != zoomLevel && style == QGeoCameraTiles::PrefetchNeighbourLayer && nearestNeighbourLayer < zoomLevel)
- QVERIFY2(prefetched == prev_visible + visible, "wrongly prefetched tiles");
-
- if (qCeil(zoomLevel) != zoomLevel && style == QGeoCameraTiles::PrefetchNeighbourLayer && nearestNeighbourLayer > zoomLevel)
- QVERIFY2(prefetched == next_visible + visible, "wrongly prefetched tiles");
-
- if (qCeil(zoomLevel) != zoomLevel && style == QGeoCameraTiles::PrefetchTwoNeighbourLayers)
- QVERIFY2(prefetched == prev_visible + visible + next_visible, "wrongly prefetched tiles");
-}
-
-void tst_QGeoCameraTiles::fetchTiles_data()
-{
- QTest::addColumn<double>("zoomLevel");
- QTest::addColumn<int>("visibleCount");
- QTest::addColumn<int>("prefetchCount");
- QTest::addColumn<QGeoCameraTiles::PrefetchStle>("style");
- QTest::addColumn<int>("nearestNeighbourLayer");
- QTest::newRow("zoomLevel: 4 , visible count: 4 : prefetch count: 16") << 4.0 << 4 << 4 + 16 << QGeoCameraTiles::PrefetchNeighbourLayer << 3;
- QTest::newRow("zoomLevel: 4.01 , visible count: 4 : prefetch count: 4") << 4.01 << 4 << 4 + 4 << QGeoCameraTiles::PrefetchNeighbourLayer << 3;
- QTest::newRow("zoomLevel: 4.1 , visible count: 4 : prefetch count: 4") << 4.1 << 4 << 4 + 4 << QGeoCameraTiles::PrefetchNeighbourLayer << 3;
- QTest::newRow("zoomLevel: 4.5 , visible count: 4 : prefetch count: 4") << 4.5 << 4 << 4 + 4 << QGeoCameraTiles::PrefetchNeighbourLayer << 3;
- QTest::newRow("zoomLevel: 4.6 , visible count: 4 : prefetch count: 4") << 4.6 << 4 << 4 + 4 << QGeoCameraTiles::PrefetchNeighbourLayer << 5;
- QTest::newRow("zoomLevel: 4.9 , visible count: 4 : prefetch count: 4") << 4.9 << 4 <<4 + 4 << QGeoCameraTiles::PrefetchNeighbourLayer << 5;
- QTest::newRow("zoomLevel: 4 , visible count: 4 : prefetch count: 4") << 4.0 << 4 << 16 + 4 + 4 << QGeoCameraTiles::PrefetchTwoNeighbourLayers << 3;
- QTest::newRow("zoomLevel: 4.1 , visible count: 4 : prefetch count: 4") << 4.1 << 4 << 4 + 4 + 4 << QGeoCameraTiles::PrefetchTwoNeighbourLayers << 3;
- QTest::newRow("zoomLevel: 4.6 ,visible count: 4 : prefetch count: 4") << 4.6 << 4 << 4 + 4 + 4 << QGeoCameraTiles::PrefetchTwoNeighbourLayers << 5;
-}
-
QTEST_GUILESS_MAIN(tst_QGeoCameraTiles)
#include "tst_qgeocameratiles.moc"
diff --git a/tests/auto/qgeomapscene/tst_qgeomapscene.cpp b/tests/auto/qgeomapscene/tst_qgeomapscene.cpp
index 0b4c7def..c6943650 100644
--- a/tests/auto/qgeomapscene/tst_qgeomapscene.cpp
+++ b/tests/auto/qgeomapscene/tst_qgeomapscene.cpp
@@ -277,7 +277,6 @@ class tst_QGeoMapScene : public QObject
camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(0.0, 0.0)));
QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
ct.setTileSize(16);
ct.setCameraData(camera);
ct.setScreenSize(QSize(16,16));
@@ -288,7 +287,7 @@ class tst_QGeoMapScene : public QObject
mapScene.setCameraData(camera);
QVERIFY(!mapScene.verticalLock());
mapScene.setUseVerticalLock(true);
- mapScene.setVisibleTiles(ct.visibleTiles());
+ mapScene.setVisibleTiles(ct.createTiles());
QVERIFY(mapScene.verticalLock());
// Test the case when setting vertical lock has no effect
@@ -298,7 +297,7 @@ class tst_QGeoMapScene : public QObject
mapScene2.setCameraData(camera);
QVERIFY(!mapScene2.verticalLock());
mapScene2.setUseVerticalLock(true);
- mapScene2.setVisibleTiles(ct.visibleTiles());
+ mapScene2.setVisibleTiles(ct.createTiles());
QVERIFY(!mapScene2.verticalLock());
}
@@ -319,7 +318,6 @@ class tst_QGeoMapScene : public QObject
camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(cameraCenterX, cameraCenterY)));
QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
ct.setTileSize(tileSize);
ct.setCameraData(camera);
ct.setScreenSize(QSize(screenWidth,screenHeight));
@@ -328,7 +326,7 @@ class tst_QGeoMapScene : public QObject
mapGeometry.setTileSize(tileSize);
mapGeometry.setScreenSize(QSize(screenWidth,screenHeight));
mapGeometry.setCameraData(camera);
- mapGeometry.setVisibleTiles(ct.visibleTiles());
+ mapGeometry.setVisibleTiles(ct.createTiles());
QDoubleVector2D point(screenX,screenY);
QDoubleVector2D mecartorPos = mapGeometry.itemPositionToMercator(point);
@@ -359,7 +357,6 @@ class tst_QGeoMapScene : public QObject
camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(cameraCenterX, cameraCenterY)));
QGeoCameraTiles ct;
- ct.setMaximumZoomLevel(8);
ct.setTileSize(tileSize);
ct.setCameraData(camera);
ct.setScreenSize(QSize(screenWidth,screenHeight));
@@ -368,7 +365,7 @@ class tst_QGeoMapScene : public QObject
mapGeometry.setTileSize(tileSize);
mapGeometry.setScreenSize(QSize(screenWidth,screenHeight));
mapGeometry.setCameraData(camera);
- mapGeometry.setVisibleTiles(ct.visibleTiles());
+ mapGeometry.setVisibleTiles(ct.createTiles());
QDoubleVector2D mercatorPos(mercatorX, mercatorY);
QPointF point = mapGeometry.mercatorToItemPosition(mercatorPos).toPointF();
diff --git a/tests/auto/qgeotiledmap/qgeotiledmap.pro b/tests/auto/qgeotiledmap/qgeotiledmap.pro
new file mode 100644
index 00000000..b4850221
--- /dev/null
+++ b/tests/auto/qgeotiledmap/qgeotiledmap.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+CONFIG += testcase
+TARGET = tst_qgeotiledmap
+INCLUDEPATH += ../geotestplugin
+
+SOURCES += tst_qgeotiledmap.cpp
+
+QT += location-private positioning-private testlib
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
new file mode 100644
index 00000000..a8f053e9
--- /dev/null
+++ b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
@@ -0,0 +1,208 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeotiledmap_test.h"
+#include "qgeotilefetcher_test.h"
+#include "qgeotiledmappingmanagerengine_test.h"
+#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>
+
+QT_USE_NAMESPACE
+
+Q_DECLARE_METATYPE(QGeoTiledMap::PrefetchStyle)
+
+class FetchTileCounter: public QObject
+{
+ Q_OBJECT
+public Q_SLOTS:
+ void tileFetched(const QGeoTileSpec& spec) {
+ m_tiles << spec;
+ }
+public:
+ QSet<QGeoTileSpec> m_tiles;
+};
+
+class tst_QGeoTiledMap : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGeoTiledMap();
+ ~tst_QGeoTiledMap();
+
+private:
+ void waitForFetch(int count);
+
+private Q_SLOTS:
+ void initTestCase();
+ void fetchTiles();
+ void fetchTiles_data();
+
+private:
+ QScopedPointer<QGeoTiledMapTest> m_map;
+ QScopedPointer<FetchTileCounter> m_tilesCounter;
+ QGeoTileFetcherTest *m_fetcher;
+
+};
+
+tst_QGeoTiledMap::tst_QGeoTiledMap():
+ m_fetcher(0)
+{
+}
+
+tst_QGeoTiledMap::~tst_QGeoTiledMap()
+{
+}
+
+void tst_QGeoTiledMap::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
+ QVariantMap parameters;
+ parameters["tileSize"] = 16;
+ parameters["maxZoomLevel"] = 8;
+ parameters["finishRequestImmediately"] = true;
+ QGeoServiceProvider *provider = new QGeoServiceProvider("qmlgeo.test.plugin",parameters);
+ 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(16, 16);
+ m_fetcher = static_cast<QGeoTileFetcherTest*>(m_map->m_engine->tileFetcher());
+ m_tilesCounter.reset(new FetchTileCounter());
+ connect(m_fetcher, SIGNAL(tileFetched(const QGeoTileSpec&)), m_tilesCounter.data(), SLOT(tileFetched(const QGeoTileSpec&)));
+}
+
+void tst_QGeoTiledMap::fetchTiles()
+{
+ QFETCH(double, zoomLevel);
+ QFETCH(int, visibleCount);
+ QFETCH(int, prefetchCount);
+ QFETCH(QGeoTiledMap::PrefetchStyle, style);
+ QFETCH(int, nearestNeighbourLayer);
+
+ m_map->setPrefetchStyle(style);
+
+ QGeoCameraData camera;
+ camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D( 0.5 , 0.5 )));
+
+ //prev_visible
+ camera.setZoomLevel(zoomLevel-1);
+ m_map->clearData();
+ m_tilesCounter->m_tiles.clear();
+ m_map->setCameraData(camera);
+ waitForFetch(visibleCount);
+ QSet<QGeoTileSpec> prev_visible = m_tilesCounter->m_tiles;
+
+ //visible + prefetch
+ camera.setZoomLevel(zoomLevel);
+ m_map->clearData();
+ m_tilesCounter->m_tiles.clear();
+ m_map->setCameraData(camera);
+ waitForFetch(visibleCount);
+ QSet<QGeoTileSpec> visible = m_tilesCounter->m_tiles;
+ m_map->clearData();
+ m_tilesCounter->m_tiles.clear();
+ m_map->prefetchData();
+ waitForFetch(prefetchCount);
+ QSet<QGeoTileSpec> prefetched = m_tilesCounter->m_tiles;
+
+ //next visible
+ camera.setZoomLevel(zoomLevel + 1);
+ m_map->clearData();
+ m_tilesCounter->m_tiles.clear();
+ m_map->setCameraData(camera);
+ waitForFetch(visibleCount);
+ QSet<QGeoTileSpec> next_visible = m_tilesCounter->m_tiles;
+
+ QVERIFY2(visibleCount == visible.size(), "visible count incorrect");
+ QVERIFY2(prefetchCount == prefetched.size(), "prefetch count incorrect");
+ QSetIterator<QGeoTileSpec> i(visible);
+ while (i.hasNext())
+ QVERIFY2(prefetched.contains(i.next()),"visible tile missing from prefetched tiles");
+
+ //for zoomLevels wihtout fractions more tiles are fetched for current zoomlevel due to ViewExpansion
+ if (qCeil(zoomLevel) != zoomLevel && style == QGeoTiledMap::PrefetchNeighbourLayer && nearestNeighbourLayer < zoomLevel)
+ QVERIFY2(prefetched == prev_visible + visible, "wrongly prefetched tiles");
+
+ if (qCeil(zoomLevel) != zoomLevel && style == QGeoTiledMap::PrefetchNeighbourLayer && nearestNeighbourLayer > zoomLevel)
+ QVERIFY2(prefetched == next_visible + visible, "wrongly prefetched tiles");
+
+ if (qCeil(zoomLevel) != zoomLevel && style == QGeoTiledMap::PrefetchTwoNeighbourLayers)
+ QVERIFY2(prefetched == prev_visible + visible + next_visible, "wrongly prefetched tiles");
+}
+
+void tst_QGeoTiledMap::fetchTiles_data()
+{
+ QTest::addColumn<double>("zoomLevel");
+ QTest::addColumn<int>("visibleCount");
+ QTest::addColumn<int>("prefetchCount");
+ QTest::addColumn<QGeoTiledMap::PrefetchStyle>("style");
+ QTest::addColumn<int>("nearestNeighbourLayer");
+ QTest::newRow("zoomLevel: 4 , visible count: 4 : prefetch count: 16") << 4.0 << 4 << 4 + 16 << QGeoTiledMap::PrefetchNeighbourLayer << 3;
+ QTest::newRow("zoomLevel: 4.06 , visible count: 4 : prefetch count: 4") << 4.06 << 4 << 4 + 4 << QGeoTiledMap::PrefetchNeighbourLayer << 3;
+ QTest::newRow("zoomLevel: 4.1 , visible count: 4 : prefetch count: 4") << 4.1 << 4 << 4 + 4 << QGeoTiledMap::PrefetchNeighbourLayer << 3;
+ QTest::newRow("zoomLevel: 4.5 , visible count: 4 : prefetch count: 4") << 4.5 << 4 << 4 + 4 << QGeoTiledMap::PrefetchNeighbourLayer << 3;
+ QTest::newRow("zoomLevel: 4.6 , visible count: 4 : prefetch count: 4") << 4.6 << 4 << 4 + 4 << QGeoTiledMap::PrefetchNeighbourLayer << 5;
+ QTest::newRow("zoomLevel: 4.9 , visible count: 4 : prefetch count: 4") << 4.9 << 4 <<4 + 4 << QGeoTiledMap::PrefetchNeighbourLayer << 5;
+ QTest::newRow("zoomLevel: 4 , visible count: 4 : prefetch count: 4") << 4.0 << 4 << 16 + 4 + 4 << QGeoTiledMap::PrefetchTwoNeighbourLayers << 3;
+ QTest::newRow("zoomLevel: 4.1 , visible count: 4 : prefetch count: 4") << 4.1 << 4 << 4 + 4 + 4 << QGeoTiledMap::PrefetchTwoNeighbourLayers << 3;
+ QTest::newRow("zoomLevel: 4.6 ,visible count: 4 : prefetch count: 4") << 4.6 << 4 << 4 + 4 + 4 << QGeoTiledMap::PrefetchTwoNeighbourLayers << 5;
+}
+
+void tst_QGeoTiledMap::waitForFetch(int count)
+{
+ int timeout = 0;
+ while (m_tilesCounter->m_tiles.count() < count && timeout < count) {
+ //250ms for each tile fetch
+ QTest::qWait(250);
+ timeout++;
+ }
+}
+
+QTEST_MAIN(tst_QGeoTiledMap)
+
+#include "tst_qgeotiledmap.moc"