diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-12-23 15:47:26 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-12-24 08:17:42 -0800 |
commit | 845699e69899cec95254ce5ab244e88210b23298 (patch) | |
tree | 4f117e8ece66d57f55bd5bb571c48dba3e5f28ff /test/fixtures/mock_file_source.hpp | |
parent | 338f94e7ed73f6b0685f406ac1a8cf389b2aacbb (diff) | |
download | qtlocation-mapboxgl-845699e69899cec95254ce5ab244e88210b23298.tar.gz |
[tests] Simplify MockFileSource
Diffstat (limited to 'test/fixtures/mock_file_source.hpp')
-rw-r--r-- | test/fixtures/mock_file_source.hpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/test/fixtures/mock_file_source.hpp b/test/fixtures/mock_file_source.hpp index f41f808e36..245e0da0eb 100644 --- a/test/fixtures/mock_file_source.hpp +++ b/test/fixtures/mock_file_source.hpp @@ -2,10 +2,10 @@ #define TEST_RESOURCES_MOCK_FILE_SOURCE #include <mbgl/storage/file_source.hpp> -#include <mbgl/util/thread.hpp> +#include <mbgl/util/timer.hpp> #include <string> -#include <memory> +#include <unordered_map> namespace mbgl { @@ -16,12 +16,6 @@ public: // Success: // Will reply to every request correctly with valid data. // - // SuccessWithDelay: - // Will reply to every request correctly with valid data, - // but the ones that contains the "match" string on the - // URL will be answered after a delay. This can be useful - // for testing request cancellation. - // // RequestFail: // Will reply with an error to requests that contains // the "match" string on the URL. @@ -32,28 +26,28 @@ public: // string on the URL. enum Type { Success, - SuccessWithDelay, RequestFail, RequestWithCorruptedData }; - class Impl; - - MockFileSource(Type type, const std::string& match); - ~MockFileSource() override = default; + MockFileSource(Type, const std::string& match); + ~MockFileSource() override; - // Function that gets called when a delayed resource is enqueued. The - // callback must be safe to call from any thread. - void setOnRequestDelayedCallback(std::function<void(void)> callback); + // Function that gets called when a matching resource is enqueued. + std::function<void (void)> requestEnqueuedCallback; // FileSource implementation. std::unique_ptr<FileRequest> request(const Resource&, Callback) override; private: + void respond(Resource, Callback) const; + friend class MockFileRequest; - void cancel(FileRequest*); - const std::unique_ptr<util::Thread<Impl>> thread_; + Type type; + std::string match; + std::unordered_map<FileRequest*, std::pair<Resource, Callback>> pending; + util::Timer timer; }; } |