- MockFileSource Will load pre-defined resources from the filesystem. It supports passing a string, that when it matches an URL, will simulate a failure. - MockView It is just a no-op to not get in the way when testing resource loading. Few more additions: - style.json Specially crafted style that will look always for the same tile, glyph range, etc at the "test/fixtures/resources/" path. No matter where you look (or at what zoom), you always get the same stuff. - vector.pbf This taken from a part of Taipei that will request several glyph ranges.
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include "mock_file_source.hpp"
|
|
|
|
#include <mbgl/storage/request.hpp>
|
|
#include <mbgl/util/io.hpp>
|
|
#include <mbgl/util/thread.hpp>
|
|
|
|
namespace mbgl {
|
|
|
|
class MockFileSource::Impl {
|
|
public:
|
|
Impl(uv_loop_t*, const std::string& matchFail) : matchFail_(matchFail) {}
|
|
|
|
void handleRequest(Request* req) const;
|
|
|
|
private:
|
|
std::string matchFail_;
|
|
};
|
|
|
|
void MockFileSource::Impl::handleRequest(Request* req) const {
|
|
const Resource& resource = req->resource;
|
|
|
|
std::shared_ptr<Response> response = std::make_shared<Response>();
|
|
if (matchFail_.empty() || resource.url.find(matchFail_) == std::string::npos) {
|
|
response->status = Response::Status::Successful;
|
|
response->data = util::read_file(resource.url.c_str());
|
|
} else {
|
|
response->message = "Failed by the test case";
|
|
}
|
|
|
|
req->notify(response);
|
|
}
|
|
|
|
MockFileSource::MockFileSource(const std::string& matchFail)
|
|
: thread_(util::make_unique<util::Thread<Impl>>("FileSource", util::ThreadPriority::Low, matchFail)) {
|
|
}
|
|
|
|
Request* MockFileSource::request(const Resource& resource, uv_loop_t* loop, Callback callback) {
|
|
Request* req = new Request(resource, loop, std::move(callback));
|
|
thread_->invoke(&Impl::handleRequest, req);
|
|
|
|
return req;
|
|
}
|
|
|
|
void MockFileSource::cancel(Request*) {
|
|
}
|
|
|
|
}
|