summaryrefslogtreecommitdiff
path: root/test/fixtures/mock_file_source.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/fixtures/mock_file_source.hpp')
-rw-r--r--test/fixtures/mock_file_source.hpp30
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;
};
}