summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-10-11 15:16:48 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-10-11 16:51:27 -0700
commitfa81ebc2bff3db41c1d12d0be16ea835a666c030 (patch)
tree87ee50fdb9d642486b06930b7671df58cca8a87e
parentf381388b1c6bd10deffbc8b83bb9b37c21dda90c (diff)
downloadqtlocation-mapboxgl-fa81ebc2bff3db41c1d12d0be16ea835a666c030.tar.gz
[core] Tests for CustomVectorSource and CustomTile
-rw-r--r--cmake/test-files.cmake2
-rw-r--r--src/mbgl/style/custom_tile_loader.cpp17
-rw-r--r--src/mbgl/style/custom_tile_loader.hpp3
-rw-r--r--src/mbgl/tile/custom_tile.cpp1
-rw-r--r--test/style/custom_vector_source.test.cpp12
-rw-r--r--test/style/source.test.cpp37
-rw-r--r--test/tile/custom_tile.test.cpp131
7 files changed, 187 insertions, 16 deletions
diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake
index 39b619a6ac..8d3e8bd346 100644
--- a/cmake/test-files.cmake
+++ b/cmake/test-files.cmake
@@ -89,7 +89,6 @@ set(MBGL_TEST_FILES
test/style/conversion/stringify.test.cpp
# style
- test/style/custom_vector_source.test.cpp
test/style/filter.test.cpp
# style/function
@@ -114,6 +113,7 @@ set(MBGL_TEST_FILES
# tile
test/tile/annotation_tile.test.cpp
+ test/tile/custom_tile.test.cpp
test/tile/geojson_tile.test.cpp
test/tile/geometry_tile_data.test.cpp
test/tile/raster_tile.test.cpp
diff --git a/src/mbgl/style/custom_tile_loader.cpp b/src/mbgl/style/custom_tile_loader.cpp
index da4ade6734..942216d26e 100644
--- a/src/mbgl/style/custom_tile_loader.cpp
+++ b/src/mbgl/style/custom_tile_loader.cpp
@@ -11,7 +11,7 @@ CustomTileLoader::CustomTileLoader(const TileFunction& fetchTileFn, const TileFu
void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<SetTileDataFunction> callbackRef) {
auto cachedTileData = dataCache.find(tileID.canonical);
if (cachedTileData == dataCache.end()) {
- fetchTileFunction(tileID.canonical);
+ invokeTileFetch(tileID.canonical);
} else {
callbackRef.invoke(&SetTileDataFunction::operator(), *(cachedTileData->second));
}
@@ -33,7 +33,7 @@ void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<SetTil
void CustomTileLoader::cancelTile(const OverscaledTileID& tileID) {
if(tileCallbackMap.find(tileID.canonical) != tileCallbackMap.end()) {
- cancelTileFunction(tileID.canonical);
+ invokeTileCancel(tileID.canonical);
}
}
@@ -50,7 +50,6 @@ void CustomTileLoader::removeTile(const OverscaledTileID& tileID) {
tileCallbackMap.erase(tileCallbacks);
dataCache.erase(tileID.canonical);
}
-
}
void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const GeoJSON& data) {
@@ -63,5 +62,17 @@ void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const GeoJSON&
}
}
+void CustomTileLoader::invokeTileFetch(const CanonicalTileID& tileID) {
+ if (fetchTileFunction != nullptr) {
+ fetchTileFunction(tileID);
+ }
+}
+
+void CustomTileLoader::invokeTileCancel(const CanonicalTileID& tileID) {
+ if (cancelTileFunction != nullptr) {
+ cancelTileFunction(tileID);
+ }
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/custom_tile_loader.hpp b/src/mbgl/style/custom_tile_loader.hpp
index 12b2dd525b..e993294f94 100644
--- a/src/mbgl/style/custom_tile_loader.hpp
+++ b/src/mbgl/style/custom_tile_loader.hpp
@@ -26,6 +26,9 @@ public:
void setTileData(const CanonicalTileID& tileID, const GeoJSON& data);
private:
+ void invokeTileFetch(const CanonicalTileID& tileID);
+ void invokeTileCancel(const CanonicalTileID& tileID);
+
TileFunction fetchTileFunction;
TileFunction cancelTileFunction;
std::unordered_map<CanonicalTileID, std::vector<OverscaledIDFunctionTuple>> tileCallbackMap;
diff --git a/src/mbgl/tile/custom_tile.cpp b/src/mbgl/tile/custom_tile.cpp
index 710c6f6691..7662085499 100644
--- a/src/mbgl/tile/custom_tile.cpp
+++ b/src/mbgl/tile/custom_tile.cpp
@@ -3,6 +3,7 @@
#include <mbgl/renderer/query.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/actor/scheduler.hpp>
+#include <mbgl/style/filter_evaluator.hpp>
#include <mapbox/geojsonvt.hpp>
diff --git a/test/style/custom_vector_source.test.cpp b/test/style/custom_vector_source.test.cpp
deleted file mode 100644
index 1d9be99a58..0000000000
--- a/test/style/custom_vector_source.test.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <mbgl/test/util.hpp>
-
-#include <mbgl/style/sources/custom_vector_source.hpp>
-#include <mbgl/style/sources/geojson_source.hpp>
-#include <mbgl/tile/tile_id.hpp>
-#include <mbgl/util/geo.hpp>
-
-using namespace mbgl;
-
-//TODO: AHM: Add tests with real expectations
-TEST(CustomVectorSource, EmptyTest) {
-}
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index 919260ffe9..c9a6c13992 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -9,6 +9,7 @@
#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/sources/image_source.hpp>
+#include <mbgl/style/sources/custom_vector_source.hpp>
#include <mbgl/style/layers/raster_layer.cpp>
#include <mbgl/style/layers/line_layer.hpp>
@@ -547,3 +548,39 @@ TEST(Source, ImageSourceImageUpdate) {
test.run();
}
+
+TEST(Source, CustomVectorSourceSetTileData) {
+ SourceTest test;
+
+ CustomVectorSource source("source", CustomVectorSource::Options());
+ source.loadDescription(test.fileSource);
+
+ LineLayer layer("id", "source");
+ layer.setSourceLayer("water");
+ std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }};
+
+ test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
+ EXPECT_EQ("source", source_.baseImpl->id);
+ test.end();
+ };
+
+ test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
+ FAIL() << "Should never be called";
+ };
+
+ auto renderSource = RenderSource::create(source.baseImpl);
+ renderSource->setObserver(&test.renderSourceObserver);
+ renderSource->update(source.baseImpl,
+ layers,
+ true,
+ true,
+ test.tileParameters);
+
+ test.loop.invoke([&] () {
+ // Set Tile Data
+ source.setTileData(CanonicalTileID(0, 0, 0), GeoJSON{ FeatureCollection{} });
+ });
+
+ test.run();
+}
+
diff --git a/test/tile/custom_tile.test.cpp b/test/tile/custom_tile.test.cpp
new file mode 100644
index 0000000000..1842bee1f5
--- /dev/null
+++ b/test/tile/custom_tile.test.cpp
@@ -0,0 +1,131 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/test/fake_file_source.hpp>
+#include <mbgl/test/stub_tile_observer.hpp>
+#include <mbgl/style/sources/custom_vector_source.hpp>
+#include <mbgl/tile/custom_tile.hpp>
+#include <mbgl/style/custom_tile_loader.hpp>
+
+#include <mbgl/util/default_thread_pool.hpp>
+#include <mbgl/util/run_loop.hpp>
+#include <mbgl/map/transform.hpp>
+#include <mbgl/renderer/tile_parameters.hpp>
+#include <mbgl/style/style.hpp>
+#include <mbgl/style/layers/circle_layer.hpp>
+#include <mbgl/annotation/annotation_manager.hpp>
+#include <mbgl/renderer/image_manager.hpp>
+#include <mbgl/text/glyph_manager.hpp>
+
+#include <memory>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+class CustomTileTest {
+public:
+ FakeFileSource fileSource;
+ TransformState transformState;
+ util::RunLoop loop;
+ ThreadPool threadPool { 1 };
+ style::Style style { loop, fileSource, 1 };
+ AnnotationManager annotationManager { style };
+ ImageManager imageManager;
+ GlyphManager glyphManager { fileSource };
+
+ TileParameters tileParameters {
+ 1.0,
+ MapDebugOptions(),
+ transformState,
+ threadPool,
+ fileSource,
+ MapMode::Continuous,
+ annotationManager,
+ imageManager,
+ glyphManager,
+ 0
+ };
+};
+
+TEST(CustomTile, InvokeFetchTile) {
+ CustomTileTest test;
+
+ CircleLayer layer("circle", "source");
+
+ mapbox::geometry::feature_collection<double> features;
+ features.push_back(mapbox::geometry::feature<double> {
+ mapbox::geometry::point<double>(0, 0)
+ });
+ CustomTileLoader loader([&](const CanonicalTileID& tileId) {
+ EXPECT_EQ(tileId, CanonicalTileID(0,0,0));
+ test.loop.stop();
+ }, [&](const CanonicalTileID&) {
+
+ });
+ auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent());
+ ActorRef<CustomTileLoader> loaderActor(loader, mb);
+
+ CustomTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomVectorSource::TileOptions(),
+ loaderActor);
+
+ tile.setNecessity(Resource::Necessity::Required);
+
+ test.loop.run();
+}
+
+TEST(CustomTile, InvokeCancelTile) {
+ CustomTileTest test;
+
+ CircleLayer layer("circle", "source");
+
+ mapbox::geometry::feature_collection<double> features;
+ features.push_back(mapbox::geometry::feature<double> {
+ mapbox::geometry::point<double>(0, 0)
+ });
+
+ CustomTileLoader loader([&](const CanonicalTileID&) { }, [&](const CanonicalTileID& tileId) {
+ EXPECT_EQ(tileId, CanonicalTileID(0,0,0));
+ test.loop.stop();
+ });
+ auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent());
+ ActorRef<CustomTileLoader> loaderActor(loader, mb);
+
+ CustomTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomVectorSource::TileOptions(),
+ loaderActor);
+
+ tile.setNecessity(Resource::Necessity::Required);
+ tile.setNecessity(Resource::Necessity::Optional);
+ test.loop.run();
+}
+
+TEST(CustomTile, InvokeTileChanged) {
+ CustomTileTest test;
+
+ CircleLayer layer("circle", "source");
+
+ mapbox::geometry::feature_collection<double> features;
+ features.push_back(mapbox::geometry::feature<double> {
+ mapbox::geometry::point<double>(0, 0)
+ });
+
+ CustomTileLoader loader(nullptr, nullptr);
+ auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent());
+ ActorRef<CustomTileLoader> loaderActor(loader, mb);
+
+ CustomTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomVectorSource::TileOptions(),
+ loaderActor);
+
+ StubTileObserver observer;
+ observer.tileChanged = [&] (const Tile&) {
+ // Once present, the bucket should never "disappear", which would cause
+ // flickering.
+ ASSERT_NE(nullptr, tile.getBucket(*layer.baseImpl));
+ };
+
+ tile.setLayers({{ layer.baseImpl }});
+ tile.setObserver(&observer);
+ tile.setPlacementConfig({});
+ tile.setTileData(features);
+
+ while (!tile.isComplete()) {
+ test.loop.runOnce();
+ }
+}