From 7f33df4629d6a1b44b9dabd84823ff51db05f85d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sat, 31 Aug 2019 08:56:34 -0700 Subject: add testcase for #15514 --- test/storage/sync_file_source.test.cpp | 47 ++++++++++++++++++++++++++++++++++ test/test-files.json | 1 + 2 files changed, 48 insertions(+) create mode 100644 test/storage/sync_file_source.test.cpp diff --git a/test/storage/sync_file_source.test.cpp b/test/storage/sync_file_source.test.cpp new file mode 100644 index 0000000000..5de6bc5187 --- /dev/null +++ b/test/storage/sync_file_source.test.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace mbgl; + +class SyncFileSource : public FileSource { + public: + + std::unique_ptr request(const Resource& resource, FileSource::Callback callback) { + Response response; + auto it = assets.find(resource.url); + if (it == assets.end()) { + response.error = std::make_unique(Response::Error::Reason::NotFound, std::string{"Not Found: "} + resource.url); + } else { + response.data = it->second; + } + callback(response); + return nullptr; + } + + void add(std::string const& key, std::string const& data) { + assets.emplace(key, std::make_shared(data)); + }; + + private: + std::unordered_map> assets; +}; + +TEST(SyncFileSource, LoadSyncRender) { + util::RunLoop loop; + auto fs = std::make_shared(); + fs->add("mapbox://mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7",util::read_file("./test/fixtures/resources/source_vector.json")); + fs->add("mapbox://sprites/mapbox/streets-v9.png",util::read_file("./test/fixtures/resources/sprite.png")); + fs->add("mapbox://sprites/mapbox/streets-v9.json",util::read_file("./test/fixtures/resources/sprite.json")); + HeadlessFrontend frontend{{512,512}, 1.0}; + MapAdapter map{frontend, MapObserver::nullObserver(), fs, MapOptions()}; + map.getStyle().loadJSON(util::read_file("./test/fixtures/resources/style_vector.json")); +} diff --git a/test/test-files.json b/test/test-files.json index e46f833269..801a1fac85 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -35,6 +35,7 @@ "test/src/mbgl/test/stub_file_source.cpp", "test/src/mbgl/test/test.cpp", "test/src/mbgl/test/util.cpp", + "test/storage/sync_file_source.test.cpp", "test/storage/asset_file_source.test.cpp", "test/storage/default_file_source.test.cpp", "test/storage/headers.test.cpp", -- cgit v1.2.1