[general] moving ios and android project under ./platform folder
This commit is contained in:
53
test/storage/sync_file_source.test.cpp
Normal file
53
test/storage/sync_file_source.test.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <mbgl/gfx/headless_frontend.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/map_impl.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/test/map_adapter.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
class SyncFileSource : public FileSource {
|
||||
public:
|
||||
std::unique_ptr<AsyncRequest> request(const Resource& resource, FileSource::Callback callback) override {
|
||||
Response response;
|
||||
auto it = assets.find(resource.url);
|
||||
if (it == assets.end()) {
|
||||
response.error = std::make_unique<Response::Error>(
|
||||
Response::Error::Reason::NotFound, std::string{ "Not Found: " } + resource.url);
|
||||
} else {
|
||||
response.data = it->second;
|
||||
}
|
||||
callback(response);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool canRequest(const Resource&) const override { return true; }
|
||||
|
||||
void add(std::string const& key, std::string const& data) {
|
||||
assets.emplace(key, std::make_shared<std::string>(data));
|
||||
};
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<std::string>> assets;
|
||||
};
|
||||
|
||||
TEST(SyncFileSource, LoadSyncRender) {
|
||||
util::RunLoop loop;
|
||||
auto fs = std::make_shared<SyncFileSource>();
|
||||
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"));
|
||||
}
|
||||
Reference in New Issue
Block a user