summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-19 16:57:36 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-20 21:30:08 +0200
commitd5868d3da822f2bf3297229bd879e76853108a63 (patch)
treeb3d28aab92b938cf541f917f1027d2bbd06d9780 /test
parentd1762d7111b39d45430bd7bb75ea60b7a5d85bd2 (diff)
downloadqtlocation-mapboxgl-d5868d3da822f2bf3297229bd879e76853108a63.tar.gz
[core] Remove file source from public Map ctor
Diffstat (limited to 'test')
-rw-r--r--test/api/annotations.test.cpp7
-rw-r--r--test/api/api_misuse.test.cpp10
-rw-r--r--test/api/custom_geometry_source.test.cpp8
-rw-r--r--test/api/custom_layer.test.cpp8
-rw-r--r--test/api/query.test.cpp13
-rw-r--r--test/api/recycle_map.cpp10
-rw-r--r--test/gl/context.test.cpp8
-rw-r--r--test/map/map.test.cpp98
-rw-r--r--test/map/prefetch.test.cpp11
-rw-r--r--test/renderer/image_manager.test.cpp1
-rw-r--r--test/src/mbgl/test/map_adapter.hpp23
-rw-r--r--test/test-files.json1
-rw-r--r--test/text/local_glyph_rasterizer.test.cpp13
-rw-r--r--test/util/memory.test.cpp27
14 files changed, 129 insertions, 109 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index aad85f8d57..2a9737e10b 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -1,11 +1,11 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/map_adapter.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
-#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -28,13 +28,12 @@ std::unique_ptr<style::Image> namedMarker(const std::string& name) {
class AnnotationTest {
public:
util::RunLoop loop;
- StubFileSource fileSource;
ThreadPool threadPool { 4 };
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, threadPool };
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapOptions().withMapMode(MapMode::Static)};
+ MapAdapter map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, std::make_shared<StubFileSource>(),
+ threadPool, MapOptions().withMapMode(MapMode::Static)};
void checkRendering(const char * name) {
test::checkImage(std::string("test/fixtures/annotations/") + name,
diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp
index 2ccfb0a7ff..6fc04ab26f 100644
--- a/test/api/api_misuse.test.cpp
+++ b/test/api/api_misuse.test.cpp
@@ -1,12 +1,11 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/fixture_log_observer.hpp>
+#include <mbgl/test/map_adapter.hpp>
-#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/renderer/backend_scope.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -22,14 +21,13 @@ TEST(API, RenderWithoutCallback) {
util::RunLoop loop;
- StubFileSource fileSource;
ThreadPool threadPool(4);
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, threadPool };
- auto map = std::make_unique<Map>(frontend, MapObserver::nullObserver(), frontend.getSize(),
- pixelRatio, fileSource, threadPool,
- MapOptions().withMapMode(MapMode::Static));
+ auto map = std::make_unique<MapAdapter>(frontend, MapObserver::nullObserver(), frontend.getSize(),
+ pixelRatio, std::make_shared<StubFileSource>(), threadPool,
+ MapOptions().withMapMode(MapMode::Static));
map->renderStill(nullptr);
// Force Map thread to join.
diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp
index 6959a36f15..58af09c1ac 100644
--- a/test/api/custom_geometry_source.test.cpp
+++ b/test/api/custom_geometry_source.test.cpp
@@ -3,8 +3,8 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/shared_thread_pool.hpp>
-#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/gl/headless_frontend.hpp>
+#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
@@ -20,12 +20,12 @@ using namespace mbgl::style;
TEST(CustomGeometrySource, Grid) {
util::RunLoop loop;
- DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
auto threadPool = sharedThreadPool();
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, *threadPool };
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- *threadPool, MapOptions().withMapMode(MapMode::Static));
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, *threadPool,
+ MapOptions().withMapMode(MapMode::Static),
+ ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index 18c6dc1692..e16d2852ec 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -4,9 +4,9 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/default_thread_pool.hpp>
-#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/headless_frontend.hpp>
+#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
@@ -90,12 +90,12 @@ public:
TEST(CustomLayer, Basic) {
util::RunLoop loop;
- DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
ThreadPool threadPool(4);
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, threadPool };
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapOptions().withMapMode(MapMode::Static));
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, threadPool,
+ MapOptions().withMapMode(MapMode::Static),
+ ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
map.getStyle().addLayer(std::make_unique<CustomLayer>(
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index 5567eabc73..b4297bfe82 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -1,4 +1,5 @@
-#include <mbgl/map/map.hpp>
+#include <mbgl/test/map_adapter.hpp>
+
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/test/stub_file_source.hpp>
@@ -33,16 +34,16 @@ public:
}
util::RunLoop loop;
- StubFileSource fileSource;
+ std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
ThreadPool threadPool { 4 };
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, threadPool };
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapOptions().withMapMode(MapMode::Static)};
+ MapAdapter map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
+ threadPool, MapOptions().withMapMode(MapMode::Static)};
};
std::vector<Feature> getTopClusterFeature(QueryTest& test) {
- test.fileSource.sourceResponse = [&] (const Resource& resource) {
+ test.fileSource->sourceResponse = [&] (const Resource& resource) {
EXPECT_EQ("http://url"s, resource.url);
Response response;
response.data = std::make_unique<std::string>(util::read_file("test/fixtures/supercluster/places.json"s));
@@ -54,7 +55,7 @@ std::vector<Feature> getTopClusterFeature(QueryTest& test) {
options.cluster = true;
auto source = std::make_unique<GeoJSONSource>("cluster_source"s, options);
source->setURL("http://url"s);
- source->loadDescription(test.fileSource);
+ source->loadDescription(*test.fileSource);
auto clusterLayer = std::make_unique<SymbolLayer>("cluster_layer"s, "cluster_source"s);
clusterLayer->setIconImage("test-icon"s);
diff --git a/test/api/recycle_map.cpp b/test/api/recycle_map.cpp
index db576b4cf6..7d14bd14de 100644
--- a/test/api/recycle_map.cpp
+++ b/test/api/recycle_map.cpp
@@ -1,11 +1,10 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/map_adapter.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/renderer/backend_scope.hpp>
-#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/image.hpp>
@@ -24,14 +23,13 @@ using namespace mbgl::style;
TEST(API, RecycleMapUpdateImages) {
util::RunLoop loop;
- StubFileSource fileSource;
ThreadPool threadPool(4);
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, threadPool };
- auto map = std::make_unique<Map>(frontend, MapObserver::nullObserver(), frontend.getSize(),
- pixelRatio, fileSource, threadPool,
- MapOptions().withMapMode(MapMode::Static));
+ auto map = std::make_unique<MapAdapter>(frontend, MapObserver::nullObserver(), frontend.getSize(),
+ pixelRatio, std::make_shared<StubFileSource>(), threadPool,
+ MapOptions().withMapMode(MapMode::Static));
EXPECT_TRUE(map);
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index 3c055c2ce0..ff9b2ecac2 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -5,9 +5,9 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/default_thread_pool.hpp>
-#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/headless_frontend.hpp>
+#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
@@ -86,14 +86,14 @@ struct Buffer {
TEST(GLContextMode, Shared) {
util::RunLoop loop;
- DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
ThreadPool threadPool(4);
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, threadPool, {}, GLContextMode::Shared };
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio,
- fileSource, threadPool, MapOptions().withMapMode(MapMode::Static));
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, threadPool,
+ MapOptions().withMapMode(MapMode::Static),
+ ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 410a7e76af..c06fa53744 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -3,12 +3,13 @@
#include <mbgl/test/stub_map_observer.hpp>
#include <mbgl/test/fake_file_source.hpp>
#include <mbgl/test/fixture_log_observer.hpp>
+#include <mbgl/test/map_adapter.hpp>
-#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
+#include <mbgl/storage/resource_options.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/online_file_source.hpp>
@@ -31,27 +32,26 @@ template <class FileSource = StubFileSource>
class MapTest {
public:
util::RunLoop runLoop;
- FileSource fileSource;
+ std::shared_ptr<FileSource> fileSource;
ThreadPool threadPool { 4 };
StubMapObserver observer;
HeadlessFrontend frontend;
- Map map;
+ MapAdapter map;
MapTest(float pixelRatio = 1, MapMode mode = MapMode::Static)
- : frontend(pixelRatio, threadPool)
+ : fileSource(std::make_shared<FileSource>())
+ , frontend(pixelRatio, threadPool)
, map(frontend, observer, frontend.getSize(), pixelRatio,
- fileSource, threadPool, MapOptions().withMapMode(mode)) {
- }
+ fileSource, threadPool, MapOptions().withMapMode(mode)) {}
template <typename T = FileSource>
- MapTest(const std::string& cachePath, const std::string& assetRoot,
+ MapTest(const std::string& cachePath, const std::string& assetPath,
float pixelRatio = 1, MapMode mode = MapMode::Static,
typename std::enable_if<std::is_same<T, DefaultFileSource>::value>::type* = 0)
- : fileSource { cachePath, assetRoot }
+ : fileSource(std::make_shared<T>(cachePath, assetPath))
, frontend(pixelRatio, threadPool)
, map(frontend, observer, frontend.getSize(), pixelRatio,
- fileSource, threadPool, MapOptions().withMapMode(mode)) {
- }
+ fileSource, threadPool, MapOptions().withMapMode(mode)) {}
};
TEST(Map, RendererState) {
@@ -235,12 +235,12 @@ TEST(Map, Offline) {
};
const std::string prefix = "http://127.0.0.1:3000/";
- test.fileSource.put(Resource::style(prefix + "style.json"), expiredItem("style.json"));
- test.fileSource.put(Resource::source(prefix + "streets.json"), expiredItem("streets.json"));
- test.fileSource.put(Resource::spriteJSON(prefix + "sprite", 1.0), expiredItem("sprite.json"));
- test.fileSource.put(Resource::spriteImage(prefix + "sprite", 1.0), expiredItem("sprite.png"));
- test.fileSource.put(Resource::tile(prefix + "{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0, Tileset::Scheme::XYZ), expiredItem("0-0-0.vector.pbf"));
- test.fileSource.put(Resource::glyphs(prefix + "{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("glyph.pbf"));
+ test.fileSource->put(Resource::style(prefix + "style.json"), expiredItem("style.json"));
+ test.fileSource->put(Resource::source(prefix + "streets.json"), expiredItem("streets.json"));
+ test.fileSource->put(Resource::spriteJSON(prefix + "sprite", 1.0), expiredItem("sprite.json"));
+ test.fileSource->put(Resource::spriteImage(prefix + "sprite", 1.0), expiredItem("sprite.png"));
+ test.fileSource->put(Resource::tile(prefix + "{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0, Tileset::Scheme::XYZ), expiredItem("0-0-0.vector.pbf"));
+ test.fileSource->put(Resource::glyphs(prefix + "{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("glyph.pbf"));
NetworkStatus::Set(NetworkStatus::Status::Offline);
test.map.getStyle().loadURL(prefix + "style.json");
@@ -334,7 +334,7 @@ TEST(Map, SetStyleInvalidJSON) {
TEST(Map, SetStyleInvalidURL) {
MapTest<> test;
- test.fileSource.styleResponse = [] (const Resource&) {
+ test.fileSource->styleResponse = [] (const Resource&) {
Response response;
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
@@ -364,14 +364,14 @@ TEST(Map, StyleFresh) {
MapTest<FakeFileSource> test;
test.map.getStyle().loadURL("mapbox://styles/test");
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
response.expires = Timestamp::max();
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
}
TEST(Map, StyleExpired) {
@@ -382,31 +382,31 @@ TEST(Map, StyleExpired) {
MapTest<FakeFileSource> test;
test.map.getStyle().loadURL("mapbox://styles/test");
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
response.expires = util::now() - 1h;
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
// Mutate layer. From now on, sending a response to the style won't overwrite it anymore, but
// we should continue to wait for a fresh response.
test.map.getStyle().addLayer(std::make_unique<style::BackgroundLayer>("bg"));
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
// Send another expired response, and confirm that we didn't overwrite the style, but continue
// to wait for a fresh response.
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
EXPECT_NE(nullptr, test.map.getStyle().getLayer("bg"));
// Send a fresh response, and confirm that we didn't overwrite the style, but continue to wait
// for a fresh response.
response.expires = util::now() + 1h;
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
EXPECT_NE(nullptr, test.map.getStyle().getLayer("bg"));
}
@@ -418,20 +418,20 @@ TEST(Map, StyleExpiredWithAnnotations) {
MapTest<FakeFileSource> test;
test.map.getStyle().loadURL("mapbox://styles/test");
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
response.expires = util::now() - 1h;
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
test.map.addAnnotation(LineAnnotation { LineString<double> {{ { 0, 0 }, { 10, 10 } }} });
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
}
TEST(Map, StyleExpiredWithRender) {
@@ -442,20 +442,20 @@ TEST(Map, StyleExpiredWithRender) {
MapTest<FakeFileSource> test;
test.map.getStyle().loadURL("mapbox://styles/test");
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
response.expires = util::now() - 1h;
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
test.frontend.render(test.map);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
- test.fileSource.respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ test.fileSource->respond(Resource::Style, response);
+ EXPECT_EQ(1u, test.fileSource->requests.size());
}
TEST(Map, StyleEarlyMutation) {
@@ -468,9 +468,9 @@ TEST(Map, StyleEarlyMutation) {
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/water.json"));
- test.fileSource.respond(Resource::Style, response);
+ test.fileSource->respond(Resource::Style, response);
- EXPECT_EQ(1u, test.fileSource.requests.size());
+ EXPECT_EQ(1u, test.fileSource->requests.size());
EXPECT_NE(nullptr, test.map.getStyle().getLayer("water"));
}
@@ -592,7 +592,7 @@ TEST(Map, DisabledSources) {
MapTest<> test;
// Always load the same image tile for raster layers.
- test.fileSource.response = [] (const Resource& res) -> optional<Response> {
+ test.fileSource->response = [] (const Resource& res) -> optional<Response> {
if (res.url == "asset://tile.png") {
Response response;
response.data = std::make_shared<std::string>(
@@ -668,7 +668,7 @@ TEST(Map, DontLoadUnneededTiles) {
using Tiles = std::unordered_set<std::string>;
Tiles tiles;
- test.fileSource.tileResponse = [&](const Resource& rsc) {
+ test.fileSource->tileResponse = [&](const Resource& rsc) {
tiles.emplace(rsc.url);
Response res;
res.noContent = true;
@@ -698,7 +698,6 @@ TEST(Map, DontLoadUnneededTiles) {
TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
util::RunLoop runLoop;
ThreadPool threadPool { 4 };
- DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
float pixelRatio { 1 };
using namespace std::chrono_literals;
@@ -723,8 +722,9 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
});
};
- Map map(frontend, observer, frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapOptions().withMapMode(MapMode::Continuous));
+ Map map(frontend, observer, frontend.getSize(), pixelRatio, threadPool,
+ MapOptions().withMapMode(MapMode::Continuous),
+ ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
runLoop.run();
@@ -739,7 +739,7 @@ TEST(Map, NoContentTiles) {
Response response;
response.noContent = true;
response.expires = util::now() + 1h;
- test.fileSource.put(Resource::tile("http://example.com/{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0,
+ test.fileSource->put(Resource::tile("http://example.com/{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0,
Tileset::Scheme::XYZ),
response);
@@ -776,7 +776,7 @@ TEST(Map, NoContentTiles) {
TEST(Map, Issue12432) {
MapTest<> test { 1, MapMode::Continuous };
- test.fileSource.tileResponse = [&](const Resource&) {
+ test.fileSource->tileResponse = [&](const Resource&) {
Response result;
result.data = std::make_shared<std::string>(util::read_file("test/fixtures/map/issue12432/0-0-0.mvt"));
return result;
diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp
index dfde3a779b..2830045983 100644
--- a/test/map/prefetch.test.cpp
+++ b/test/map/prefetch.test.cpp
@@ -1,11 +1,10 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/stub_map_observer.hpp>
+#include <mbgl/test/map_adapter.hpp>
-#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/image.hpp>
@@ -24,7 +23,7 @@ using namespace std::chrono_literals;
TEST(Map, PrefetchTiles) {
util::RunLoop runLoop;
ThreadPool threadPool(4);
- StubFileSource fileSource;
+ std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
util::Timer emergencyShutoff;
emergencyShutoff.start(10s, 0s, [&] {
@@ -38,12 +37,12 @@ TEST(Map, PrefetchTiles) {
};
HeadlessFrontend frontend { { 512, 512 }, 1, threadPool };
- Map map(frontend, observer, frontend.getSize(), 1, fileSource, threadPool,
- MapOptions().withMapMode(MapMode::Continuous));
+ MapAdapter map(frontend, observer, frontend.getSize(), 1, fileSource, threadPool,
+ MapOptions().withMapMode(MapMode::Continuous));
std::vector<int> tiles;
- fileSource.response = [&] (const Resource& res) -> optional<Response> {
+ fileSource->response = [&] (const Resource& res) -> optional<Response> {
static std::string tile = util::read_file("test/fixtures/map/prefetch/tile.png");
auto zoom = std::stoi(res.url);
diff --git a/test/renderer/image_manager.test.cpp b/test/renderer/image_manager.test.cpp
index 4a838d0f9c..20451827ce 100644
--- a/test/renderer/image_manager.test.cpp
+++ b/test/renderer/image_manager.test.cpp
@@ -1,6 +1,5 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/fixture_log_observer.hpp>
-#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/stub_style_observer.hpp>
#include <mbgl/renderer/image_manager.hpp>
diff --git a/test/src/mbgl/test/map_adapter.hpp b/test/src/mbgl/test/map_adapter.hpp
new file mode 100644
index 0000000000..e0fc449f48
--- /dev/null
+++ b/test/src/mbgl/test/map_adapter.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_impl.hpp>
+
+namespace mbgl {
+
+class FileSource;
+
+// Non-public version of mbgl::Map that accepts a file source as parameter.
+class MapAdapter : public Map {
+public:
+ explicit MapAdapter(RendererFrontend& frontend,
+ MapObserver& observer,
+ Size size,
+ float ratio,
+ std::shared_ptr<FileSource> fileSource,
+ Scheduler& scheduler,
+ const MapOptions& options)
+ : Map(std::make_unique<Map::Impl>(frontend, observer, scheduler, size, ratio, std::move(fileSource), options)) {}
+};
+
+} // namespace mbgl
diff --git a/test/test-files.json b/test/test-files.json
index 498237e072..58970689be 100644
--- a/test/test-files.json
+++ b/test/test-files.json
@@ -114,6 +114,7 @@
"mbgl/test/fake_file_source.hpp": "test/src/mbgl/test/fake_file_source.hpp",
"mbgl/test/fixture_log_observer.hpp": "test/src/mbgl/test/fixture_log_observer.hpp",
"mbgl/test/getrss.hpp": "test/src/mbgl/test/getrss.hpp",
+ "mbgl/test/map_adapter.hpp": "test/src/mbgl/test/map_adapter.hpp",
"mbgl/test/mock.hpp": "test/src/mbgl/test/mock.hpp",
"mbgl/test/sqlite3_test_fs.hpp": "test/src/mbgl/test/sqlite3_test_fs.hpp",
"mbgl/test/stub_file_source.hpp": "test/src/mbgl/test/stub_file_source.hpp",
diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp
index d0fdb5ee57..a266021f25 100644
--- a/test/text/local_glyph_rasterizer.test.cpp
+++ b/test/text/local_glyph_rasterizer.test.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
-#include <mbgl/map/map.hpp>
+#include <mbgl/test/map_adapter.hpp>
+
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -38,12 +39,12 @@ public:
}
util::RunLoop loop;
- StubFileSource fileSource;
+ std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
ThreadPool threadPool { 4 };
float pixelRatio { 1 };
HeadlessFrontend frontend;
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapOptions().withMapMode(MapMode::Static)};
+ MapAdapter map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
+ threadPool, MapOptions().withMapMode(MapMode::Static)};
void checkRendering(const char * name) {
test::checkImage(std::string("test/fixtures/local_glyphs/") + name,
@@ -59,7 +60,7 @@ public:
TEST(LocalGlyphRasterizer, PingFang) {
LocalGlyphRasterizerTest test(std::string("PingFang"));
- test.fileSource.glyphsResponse = [&] (const Resource& resource) {
+ test.fileSource->glyphsResponse = [&] (const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
@@ -80,7 +81,7 @@ TEST(LocalGlyphRasterizer, NoLocal) {
// the output should just contain basic latin characters.
LocalGlyphRasterizerTest test({});
- test.fileSource.glyphsResponse = [&] (const Resource& resource) {
+ test.fileSource->glyphsResponse = [&] (const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index 36bed57ab5..c1ae597986 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -1,8 +1,8 @@
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/getrss.hpp>
#include <mbgl/test/util.hpp>
+#include <mbgl/test/map_adapter.hpp>
-#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
@@ -16,6 +16,7 @@
#include <string>
#include <unordered_map>
#include <utility>
+#include <memory>
#include <cstdlib>
#include <unistd.h>
@@ -26,16 +27,16 @@ using namespace std::literals::string_literals;
class MemoryTest {
public:
MemoryTest() {
- fileSource.styleResponse = [&](const Resource& res) { return response("style_" + getType(res) + ".json");};
- fileSource.tileResponse = [&](const Resource& res) { return response(getType(res) + ".tile"); };
- fileSource.sourceResponse = [&](const Resource& res) { return response("source_" + getType(res) + ".json"); };
- fileSource.glyphsResponse = [&](const Resource&) { return response("glyphs.pbf"); };
- fileSource.spriteJSONResponse = [&](const Resource&) { return response("sprite.json"); };
- fileSource.spriteImageResponse = [&](const Resource&) { return response("sprite.png"); };
+ fileSource->styleResponse = [&](const Resource& res) { return response("style_" + getType(res) + ".json");};
+ fileSource->tileResponse = [&](const Resource& res) { return response(getType(res) + ".tile"); };
+ fileSource->sourceResponse = [&](const Resource& res) { return response("source_" + getType(res) + ".json"); };
+ fileSource->glyphsResponse = [&](const Resource&) { return response("glyphs.pbf"); };
+ fileSource->spriteJSONResponse = [&](const Resource&) { return response("sprite.json"); };
+ fileSource->spriteImageResponse = [&](const Resource&) { return response("sprite.png"); };
}
util::RunLoop runLoop;
- StubFileSource fileSource;
+ std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
ThreadPool threadPool { 4 };
private:
@@ -72,8 +73,8 @@ TEST(Memory, Vector) {
float ratio { 2 };
HeadlessFrontend frontend { { 256, 256 }, ratio, test.threadPool };
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
- test.threadPool, MapOptions().withMapMode(MapMode::Static));
+ MapAdapter map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
+ test.threadPool, MapOptions().withMapMode(MapMode::Static));
map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL("mapbox://streets");
@@ -85,8 +86,8 @@ TEST(Memory, Raster) {
float ratio { 2 };
HeadlessFrontend frontend { { 256, 256 }, ratio, test.threadPool };
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
- test.threadPool, MapOptions().withMapMode(MapMode::Static));
+ MapAdapter map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
+ test.threadPool, MapOptions().withMapMode(MapMode::Static));
map.getStyle().loadURL("mapbox://satellite");
frontend.render(map);
@@ -131,7 +132,7 @@ TEST(Memory, Footprint) {
}
HeadlessFrontend frontend;
- Map map;
+ MapAdapter map;
};
// Warm up buffers and cache.