summaryrefslogtreecommitdiff
path: root/test/resources/mock_file_source.hpp
blob: bb9fb55a30abf110a2a3e7f3eadd8cb4c86801bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef TEST_RESOURCES_MOCK_FILE_SOURCE
#define TEST_RESOURCES_MOCK_FILE_SOURCE

#include <mbgl/storage/file_source.hpp>

#include <string>
#include <memory>

namespace mbgl {

namespace util {
template <typename T> class Thread;
}

// This mock FileSource will read data from the disk and will fail
// the request if the URL matches a string.
class MockFileSource : public FileSource {
public:
    enum Type {
        Success,
        RequestFail,
        RequestWithCorruptedData
    };

    class Impl;

    MockFileSource(Type type, const std::string& match);
    ~MockFileSource() override = default;

    // FileSource implementation.
    Request* request(const Resource&, uv_loop_t*, Callback) override;
    void cancel(Request*) override;

private:
    const std::unique_ptr<util::Thread<Impl>> thread_;
};

}

#endif