summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-20 17:11:50 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-02 08:45:09 -0700
commit3f0c89d633a5056006557ad5f4b9e446807d00ee (patch)
tree5405c50dd26a5a393a982e8e0f76b764dbbccf48 /test
parent197751bace6181f2c2dbe4c890f277a0dc7e58b1 (diff)
downloadqtlocation-mapboxgl-3f0c89d633a5056006557ad5f4b9e446807d00ee.tar.gz
[core] Refactor Source::*Impls into RenderSources and TilePyramid
Diffstat (limited to 'test')
-rw-r--r--test/src/mbgl/test/stub_render_source_observer.hpp23
-rw-r--r--test/src/mbgl/test/stub_style_observer.hpp11
-rw-r--r--test/style/source.test.cpp226
-rw-r--r--test/tile/geojson_tile.test.cpp16
4 files changed, 139 insertions, 137 deletions
diff --git a/test/src/mbgl/test/stub_render_source_observer.hpp b/test/src/mbgl/test/stub_render_source_observer.hpp
new file mode 100644
index 0000000000..ff20fff80c
--- /dev/null
+++ b/test/src/mbgl/test/stub_render_source_observer.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <mbgl/renderer/render_source_observer.hpp>
+
+using namespace mbgl;
+
+/**
+ * An implementation of style::Observer that forwards all methods to dynamically-settable lambdas.
+ */
+class StubRenderSourceObserver : public RenderSourceObserver {
+public:
+ void onTileChanged(RenderSource& source, const OverscaledTileID& tileID) override {
+ if (tileChanged) tileChanged(source, tileID);
+ };
+
+ void
+ onTileError(RenderSource& source, const OverscaledTileID& tileID, std::exception_ptr error) override {
+ if (tileError) tileError(source, tileID, error);
+ }
+
+ std::function<void (RenderSource&, const OverscaledTileID&)> tileChanged;
+ std::function<void (RenderSource&, const OverscaledTileID&, std::exception_ptr)> tileError;
+};
diff --git a/test/src/mbgl/test/stub_style_observer.hpp b/test/src/mbgl/test/stub_style_observer.hpp
index 9312cfa550..7e22c68823 100644
--- a/test/src/mbgl/test/stub_style_observer.hpp
+++ b/test/src/mbgl/test/stub_style_observer.hpp
@@ -42,15 +42,6 @@ public:
if (sourceDescriptionChanged) sourceDescriptionChanged(source);
}
- void onTileChanged(Source& source, const OverscaledTileID& tileID) override {
- if (tileChanged) tileChanged(source, tileID);
- };
-
- void
- onTileError(Source& source, const OverscaledTileID& tileID, std::exception_ptr error) override {
- if (tileError) tileError(source, tileID, error);
- }
-
void onResourceError(std::exception_ptr error) override {
if (resourceError) resourceError(error);
};
@@ -63,7 +54,5 @@ public:
std::function<void (Source&)> sourceChanged;
std::function<void (Source&, std::exception_ptr)> sourceError;
std::function<void (Source&)> sourceDescriptionChanged;
- std::function<void (Source&, const OverscaledTileID&)> tileChanged;
- std::function<void (Source&, const OverscaledTileID&, std::exception_ptr)> tileError;
std::function<void (std::exception_ptr)> resourceError;
};
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index 24ddba8aaf..6a336a8c23 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -1,12 +1,17 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/stub_style_observer.hpp>
+#include <mbgl/test/stub_render_source_observer.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/raster_source.hpp>
#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/renderer/sources/render_raster_source.hpp>
+#include <mbgl/renderer/sources/render_vector_source.hpp>
+#include <mbgl/renderer/sources/render_geojson_source.hpp>
+
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/io.hpp>
@@ -33,7 +38,8 @@ class SourceTest {
public:
util::RunLoop loop;
StubFileSource fileSource;
- StubStyleObserver observer;
+ StubStyleObserver styleObserver;
+ StubRenderSourceObserver renderSourceObserver;
Transform transform;
TransformState transformState;
ThreadPool threadPool { 1 };
@@ -70,32 +76,6 @@ public:
}
};
-TEST(Source, DefaultZoomRange) {
- VectorSource vectorSource("vectorSource", "url");
- EXPECT_FALSE(vectorSource.getZoomRange());
- vectorSource.baseImpl->loaded = true;
- EXPECT_EQ(vectorSource.getZoomRange()->min, 0u);
- EXPECT_EQ(vectorSource.getZoomRange()->max, 22u);
-
- GeoJSONSource geojsonSource("source");
- EXPECT_FALSE(geojsonSource.getZoomRange());
- geojsonSource.baseImpl->loaded = true;
- EXPECT_EQ(geojsonSource.getZoomRange()->min, 0u);
- EXPECT_EQ(geojsonSource.getZoomRange()->max, 18u);
-
- Tileset tileset;
- RasterSource rasterSource("source", tileset, 512);
- EXPECT_FALSE(rasterSource.getZoomRange());
- rasterSource.baseImpl->loaded = true;
- EXPECT_EQ(rasterSource.getZoomRange()->min, 0u);
- EXPECT_EQ(rasterSource.getZoomRange()->max, 22u);
- EXPECT_EQ(*rasterSource.getZoomRange(), tileset.zoomRange);
-
- AnnotationSource annotationSource;
- EXPECT_EQ(annotationSource.getZoomRange()->min, 0u);
- EXPECT_EQ(annotationSource.getZoomRange()->max, 22u);
-}
-
TEST(Source, LoadingFail) {
SourceTest test;
@@ -108,14 +88,14 @@ TEST(Source, LoadingFail) {
return response;
};
- test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
+ test.styleObserver.sourceError = [&] (Source& source, std::exception_ptr error) {
EXPECT_EQ("source", source.getID());
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
VectorSource source("source", "url");
- source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->setObserver(&test.styleObserver);
source.baseImpl->loadDescription(test.fileSource);
test.run();
@@ -131,14 +111,14 @@ TEST(Source, LoadingCorrupt) {
return response;
};
- test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
+ test.styleObserver.sourceError = [&] (Source& source, std::exception_ptr error) {
EXPECT_EQ("source", source.getID());
EXPECT_EQ("0 - Invalid value.", util::toString(error));
test.end();
};
VectorSource source("source", "url");
- source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->setObserver(&test.styleObserver);
source.baseImpl->loadDescription(test.fileSource);
test.run();
@@ -153,22 +133,24 @@ TEST(Source, RasterTileEmpty) {
return response;
};
- test.observer.tileChanged = [&] (Source& source, const OverscaledTileID&) {
- EXPECT_EQ("source", source.getID());
+ Tileset tileset;
+ tileset.tiles = { "tiles" };
+
+ RasterSource source("source", tileset, 512);
+ source.baseImpl->loadDescription(test.fileSource);
+
+ test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
+ EXPECT_EQ("source", source_.baseImpl.id);
test.end();
};
- test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) {
+ test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
- Tileset tileset;
- tileset.tiles = { "tiles" };
-
- RasterSource source("source", tileset, 512);
- source.baseImpl->setObserver(&test.observer);
- source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+ RenderRasterSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -182,22 +164,24 @@ TEST(Source, VectorTileEmpty) {
return response;
};
- test.observer.tileChanged = [&] (Source& source, const OverscaledTileID&) {
- EXPECT_EQ("source", source.getID());
+ Tileset tileset;
+ tileset.tiles = { "tiles" };
+
+ VectorSource source("source", tileset);
+ source.baseImpl->loadDescription(test.fileSource);
+
+ test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
+ EXPECT_EQ("source", source_.baseImpl.id);
test.end();
};
- test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) {
+ test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
- Tileset tileset;
- tileset.tiles = { "tiles" };
-
- VectorSource source("source", tileset);
- source.baseImpl->setObserver(&test.observer);
- source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+ RenderVectorSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -213,20 +197,22 @@ TEST(Source, RasterTileFail) {
return response;
};
- test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(SourceType::Raster, source.baseImpl->type);
- EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
- EXPECT_EQ("Failed by the test case", util::toString(error));
- test.end();
- };
-
Tileset tileset;
tileset.tiles = { "tiles" };
RasterSource source("source", tileset, 512);
- source.baseImpl->setObserver(&test.observer);
source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+
+ test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
+ EXPECT_EQ(SourceType::Raster, source_.baseImpl.type);
+ EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
+ EXPECT_EQ("Failed by the test case", util::toString(error));
+ test.end();
+ };
+
+ RenderRasterSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -242,20 +228,22 @@ TEST(Source, VectorTileFail) {
return response;
};
- test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(SourceType::Vector, source.baseImpl->type);
- EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
- EXPECT_EQ("Failed by the test case", util::toString(error));
- test.end();
- };
-
Tileset tileset;
tileset.tiles = { "tiles" };
VectorSource source("source", tileset);
- source.baseImpl->setObserver(&test.observer);
source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+
+ test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
+ EXPECT_EQ(SourceType::Vector, source_.baseImpl.type);
+ EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
+ EXPECT_EQ("Failed by the test case", util::toString(error));
+ test.end();
+ };
+
+ RenderVectorSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -269,21 +257,23 @@ TEST(Source, RasterTileCorrupt) {
return response;
};
- test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(source.baseImpl->type, SourceType::Raster);
+ Tileset tileset;
+ tileset.tiles = { "tiles" };
+
+ RasterSource source("source", tileset, 512);
+ source.baseImpl->loadDescription(test.fileSource);
+
+ test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
+ EXPECT_EQ(source_.baseImpl.type, SourceType::Raster);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_TRUE(bool(error));
// Not asserting on platform-specific error text.
test.end();
};
- Tileset tileset;
- tileset.tiles = { "tiles" };
-
- RasterSource source("source", tileset, 512);
- source.baseImpl->setObserver(&test.observer);
- source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+ RenderRasterSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -297,13 +287,6 @@ TEST(Source, VectorTileCorrupt) {
return response;
};
- test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(source.baseImpl->type, SourceType::Vector);
- EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
- EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
- test.end();
- };
-
// Need to have at least one layer that uses the source.
auto layer = std::make_unique<LineLayer>("id", "source");
layer->setSourceLayer("water");
@@ -313,9 +296,18 @@ TEST(Source, VectorTileCorrupt) {
tileset.tiles = { "tiles" };
VectorSource source("source", tileset);
- source.baseImpl->setObserver(&test.observer);
source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+
+ test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
+ EXPECT_EQ(source_.baseImpl.type, SourceType::Vector);
+ EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
+ EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
+ test.end();
+ };
+
+ RenderVectorSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -328,21 +320,23 @@ TEST(Source, RasterTileCancel) {
return optional<Response>();
};
- test.observer.tileChanged = [&] (Source&, const OverscaledTileID&) {
+ Tileset tileset;
+ tileset.tiles = { "tiles" };
+
+ RasterSource source("source", tileset, 512);
+ source.baseImpl->loadDescription(test.fileSource);
+
+ test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) {
FAIL() << "Should never be called";
};
- test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) {
+ test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
- Tileset tileset;
- tileset.tiles = { "tiles" };
-
- RasterSource source("source", tileset, 512);
- source.baseImpl->setObserver(&test.observer);
- source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+ RenderRasterSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -355,21 +349,23 @@ TEST(Source, VectorTileCancel) {
return optional<Response>();
};
- test.observer.tileChanged = [&] (Source&, const OverscaledTileID&) {
+ Tileset tileset;
+ tileset.tiles = { "tiles" };
+
+ VectorSource source("source", tileset);
+ source.baseImpl->loadDescription(test.fileSource);
+
+ test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) {
FAIL() << "Should never be called";
};
- test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) {
+ test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
- Tileset tileset;
- tileset.tiles = { "tiles" };
-
- VectorSource source("source", tileset);
- source.baseImpl->setObserver(&test.observer);
- source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+ RenderVectorSource renderSource(*source.impl);
+ renderSource.setObserver(&test.renderSourceObserver);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -395,20 +391,18 @@ TEST(Source, RasterTileAttribution) {
return response;
};
- test.observer.sourceChanged = [&] (Source& source) {
+ test.styleObserver.sourceChanged = [&] (Source& source) {
EXPECT_EQ(mapboxOSM, source.getAttribution());
EXPECT_FALSE(mapboxOSM.find("©️ OpenStreetMap") == std::string::npos);
test.end();
};
- test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) {
- FAIL() << "Should never be called";
- };
-
RasterSource source("source", "url", 512);
- source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->setObserver(&test.styleObserver);
source.baseImpl->loadDescription(test.fileSource);
- source.baseImpl->updateTiles(test.updateParameters);
+
+ RenderRasterSource renderSource(*source.impl);
+ renderSource.updateTiles(test.updateParameters);
test.run();
}
@@ -423,17 +417,13 @@ TEST(Source, GeoJSonSourceUrlUpdate) {
return response;
};
- test.observer.sourceDescriptionChanged = [&] (Source&) {
+ test.styleObserver.sourceDescriptionChanged = [&] (Source&) {
// Should be called (test will hang if it doesn't)
test.end();
};
- test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) {
- FAIL() << "Should never be called";
- };
-
GeoJSONSource source("source");
- source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->setObserver(&test.styleObserver);
// Load initial, so the source state will be loaded=true
source.baseImpl->loadDescription(test.fileSource);
diff --git a/test/tile/geojson_tile.test.cpp b/test/tile/geojson_tile.test.cpp
index 46cbe209b6..f39ff0a4cd 100644
--- a/test/tile/geojson_tile.test.cpp
+++ b/test/tile/geojson_tile.test.cpp
@@ -41,26 +41,26 @@ public:
TEST(GeoJSONTile, Issue7648) {
GeoJSONTileTest test;
- GeoJSONTile tile(OverscaledTileID(0, 0, 0), "source", test.updateParameters);
test.style.addLayer(std::make_unique<CircleLayer>("circle", "source"));
+ mapbox::geometry::feature_collection<int16_t> features;
+ features.push_back(mapbox::geometry::feature<int16_t> {
+ mapbox::geometry::point<int16_t>(0, 0)
+ });
+
+ GeoJSONTile tile(OverscaledTileID(0, 0, 0), "source", test.updateParameters, features);
+
StubTileObserver observer;
observer.tileChanged = [&] (const Tile&) {
// Once present, the bucket should never "disappear", which would cause
// flickering.
ASSERT_NE(nullptr, tile.getBucket(*test.style.getRenderLayer("circle")));
};
- tile.setObserver(&observer);
+ tile.setObserver(&observer);
tile.setPlacementConfig({});
- mapbox::geometry::feature_collection<int16_t> features;
- features.push_back(mapbox::geometry::feature<int16_t> {
- mapbox::geometry::point<int16_t>(0, 0)
- });
-
- tile.updateData(features);
while (!tile.isComplete()) {
test.loop.runOnce();
}