diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-10 13:22:09 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-10 15:40:20 -0800 |
commit | 0cf450e3e529423737c6b4aa196b271442530345 (patch) | |
tree | fc5f49156dc43420962bce604603a145b75595dc /test/fixtures | |
parent | a9e0c1b99a0489c6bc192c0681fa1dfc6e565bbe (diff) | |
download | qtlocation-mapboxgl-0cf450e3e529423737c6b4aa196b271442530345.tar.gz |
[core] Retry errors encountered during offline downloads
Diffstat (limited to 'test/fixtures')
-rw-r--r-- | test/fixtures/stub_file_source.cpp | 11 | ||||
-rw-r--r-- | test/fixtures/stub_file_source.hpp | 18 |
2 files changed, 16 insertions, 13 deletions
diff --git a/test/fixtures/stub_file_source.cpp b/test/fixtures/stub_file_source.cpp index 9eb37b7928..b41eded084 100644 --- a/test/fixtures/stub_file_source.cpp +++ b/test/fixtures/stub_file_source.cpp @@ -19,11 +19,12 @@ public: StubFileSource::StubFileSource() { timer.start(10ms, 10ms, [this] { - // Explicit move to avoid iterator invalidation if ~StubFileRequest gets called within the loop. - auto pending_ = std::move(pending); + // Explicit copy to avoid iterator invalidation if ~StubFileRequest gets called within the loop. + auto pending_ = pending; for (auto& pair : pending_) { - if (pair.second.first) { - pair.second.second(*pair.second.first); + optional<Response> res = std::get<1>(pair.second)(std::get<0>(pair.second)); + if (res) { + std::get<2>(pair.second)(*res); } } }); @@ -33,7 +34,7 @@ StubFileSource::~StubFileSource() = default; std::unique_ptr<FileRequest> StubFileSource::request(const Resource& resource, Callback callback) { auto req = std::make_unique<StubFileRequest>(*this); - pending.emplace(req.get(), std::make_pair(response(resource), callback)); + pending.emplace(req.get(), std::make_tuple(resource, response, callback)); return std::move(req); } diff --git a/test/fixtures/stub_file_source.hpp b/test/fixtures/stub_file_source.hpp index 344dff6073..dbb584fdcc 100644 --- a/test/fixtures/stub_file_source.hpp +++ b/test/fixtures/stub_file_source.hpp @@ -15,18 +15,20 @@ public: std::unique_ptr<FileRequest> request(const Resource&, Callback) override; + using ResponseFunction = std::function<optional<Response> (const Resource&)>; + // You can set the response callback on a global level by assigning this callback: - std::function<optional<Response> (const Resource&)> response = [this] (const Resource& resource) { + ResponseFunction response = [this] (const Resource& resource) { return defaultResponse(resource); }; // Or set per-kind responses by setting these callbacks: - std::function<optional<Response> (const Resource&)> styleResponse; - std::function<optional<Response> (const Resource&)> sourceResponse; - std::function<optional<Response> (const Resource&)> tileResponse; - std::function<optional<Response> (const Resource&)> glyphsResponse; - std::function<optional<Response> (const Resource&)> spriteJSONResponse; - std::function<optional<Response> (const Resource&)> spriteImageResponse; + ResponseFunction styleResponse; + ResponseFunction sourceResponse; + ResponseFunction tileResponse; + ResponseFunction glyphsResponse; + ResponseFunction spriteJSONResponse; + ResponseFunction spriteImageResponse; private: friend class StubFileRequest; @@ -34,7 +36,7 @@ private: // The default behavior is to throw if no per-kind callback has been set. optional<Response> defaultResponse(const Resource&); - std::unordered_map<FileRequest*, std::pair<optional<Response>, Callback>> pending; + std::unordered_map<FileRequest*, std::tuple<Resource, ResponseFunction, Callback>> pending; util::Timer timer; }; |