Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "binarystore.hpp" |
Patrick Venture | 15f0f94 | 2020-07-09 09:38:18 -0700 | [diff] [blame] | 4 | #include "binarystore_interface.hpp" |
Kun Yi | 2765b64 | 2019-01-16 11:11:24 -0800 | [diff] [blame] | 5 | #include "sys_file.hpp" |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 6 | |
Patrick Venture | 15f0f94 | 2020-07-09 09:38:18 -0700 | [diff] [blame] | 7 | #include <memory> |
Willy Tu | 67391d5 | 2021-12-07 19:53:49 -0800 | [diff] [blame^] | 8 | #include <optional> |
Patrick Venture | 15f0f94 | 2020-07-09 09:38:18 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 12 | #include <gmock/gmock.h> |
| 13 | |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 14 | using ::testing::Invoke; |
| 15 | |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 16 | namespace binstore |
| 17 | { |
| 18 | |
| 19 | class MockBinaryStore : public BinaryStoreInterface |
| 20 | { |
| 21 | public: |
Kun Yi | 2765b64 | 2019-01-16 11:11:24 -0800 | [diff] [blame] | 22 | MockBinaryStore(const std::string& baseBlobId, |
Willy Tu | 67391d5 | 2021-12-07 19:53:49 -0800 | [diff] [blame^] | 23 | std::unique_ptr<SysFile> file, |
| 24 | std::optional<uint32_t> maxSize = std::nullopt) : |
| 25 | real_store_(baseBlobId, std::move(file), maxSize) |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 26 | { |
| 27 | // Implemented calls in BinaryStore will be directed to the real object. |
| 28 | ON_CALL(*this, getBaseBlobId) |
| 29 | .WillByDefault(Invoke(&real_store_, &BinaryStore::getBaseBlobId)); |
| 30 | ON_CALL(*this, getBlobIds) |
| 31 | .WillByDefault(Invoke(&real_store_, &BinaryStore::getBlobIds)); |
Kun Yi | 6baa713 | 2019-01-08 21:21:02 -0800 | [diff] [blame] | 32 | ON_CALL(*this, openOrCreateBlob) |
| 33 | .WillByDefault( |
| 34 | Invoke(&real_store_, &BinaryStore::openOrCreateBlob)); |
| 35 | ON_CALL(*this, close) |
| 36 | .WillByDefault(Invoke(&real_store_, &BinaryStore::close)); |
Kun Yi | 6967b77 | 2019-02-22 13:48:12 -0800 | [diff] [blame] | 37 | ON_CALL(*this, read) |
| 38 | .WillByDefault(Invoke(&real_store_, &BinaryStore::read)); |
| 39 | ON_CALL(*this, write) |
| 40 | .WillByDefault(Invoke(&real_store_, &BinaryStore::write)); |
Kun Yi | d297c9f | 2019-01-09 13:52:30 -0800 | [diff] [blame] | 41 | ON_CALL(*this, commit) |
| 42 | .WillByDefault(Invoke(&real_store_, &BinaryStore::commit)); |
Kun Yi | 1a25e0d | 2020-05-11 12:28:53 -0700 | [diff] [blame] | 43 | ON_CALL(*this, stat) |
| 44 | .WillByDefault(Invoke(&real_store_, &BinaryStore::stat)); |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 45 | } |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 46 | MOCK_CONST_METHOD0(getBaseBlobId, std::string()); |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 47 | MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>()); |
Kun Yi | 38146a0 | 2018-12-18 21:54:26 -0800 | [diff] [blame] | 48 | MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t)); |
Kun Yi | c0adbc3 | 2018-12-18 22:35:29 -0800 | [diff] [blame] | 49 | MOCK_METHOD1(deleteBlob, bool(const std::string&)); |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 50 | MOCK_METHOD2(read, std::vector<uint8_t>(uint32_t, uint32_t)); |
| 51 | MOCK_METHOD2(write, bool(uint32_t, const std::vector<uint8_t>&)); |
| 52 | MOCK_METHOD0(commit, bool()); |
| 53 | MOCK_METHOD0(close, bool()); |
Kun Yi | 1a25e0d | 2020-05-11 12:28:53 -0700 | [diff] [blame] | 54 | MOCK_METHOD1(stat, bool(blobs::BlobMeta* meta)); |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 55 | |
Maksym Sloyko | eb27411 | 2021-10-27 23:48:32 +0000 | [diff] [blame] | 56 | std::vector<uint8_t> readBlob(const std::string& blobId) const override |
| 57 | { |
| 58 | return real_store_.readBlob(blobId); |
| 59 | } |
| 60 | |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 61 | private: |
| 62 | BinaryStore real_store_; |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace binstore |