Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "binarystore.hpp" |
Kun Yi | 2765b64 | 2019-01-16 11:11:24 -0800 | [diff] [blame^] | 4 | #include "sys_file.hpp" |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 5 | |
| 6 | #include <gmock/gmock.h> |
| 7 | |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 8 | using ::testing::Invoke; |
| 9 | |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 10 | namespace binstore |
| 11 | { |
| 12 | |
| 13 | class MockBinaryStore : public BinaryStoreInterface |
| 14 | { |
| 15 | public: |
Kun Yi | 2765b64 | 2019-01-16 11:11:24 -0800 | [diff] [blame^] | 16 | MockBinaryStore(const std::string& baseBlobId, |
| 17 | std::unique_ptr<SysFile> file, uint32_t maxSize) : |
| 18 | real_store_(baseBlobId, std::move(file), maxSize) |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 19 | { |
| 20 | // Implemented calls in BinaryStore will be directed to the real object. |
| 21 | ON_CALL(*this, getBaseBlobId) |
| 22 | .WillByDefault(Invoke(&real_store_, &BinaryStore::getBaseBlobId)); |
| 23 | ON_CALL(*this, getBlobIds) |
| 24 | .WillByDefault(Invoke(&real_store_, &BinaryStore::getBlobIds)); |
Kun Yi | 6baa713 | 2019-01-08 21:21:02 -0800 | [diff] [blame] | 25 | ON_CALL(*this, openOrCreateBlob) |
| 26 | .WillByDefault( |
| 27 | Invoke(&real_store_, &BinaryStore::openOrCreateBlob)); |
| 28 | ON_CALL(*this, close) |
| 29 | .WillByDefault(Invoke(&real_store_, &BinaryStore::close)); |
Kun Yi | 6967b77 | 2019-02-22 13:48:12 -0800 | [diff] [blame] | 30 | ON_CALL(*this, read) |
| 31 | .WillByDefault(Invoke(&real_store_, &BinaryStore::read)); |
| 32 | ON_CALL(*this, write) |
| 33 | .WillByDefault(Invoke(&real_store_, &BinaryStore::write)); |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 34 | } |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 35 | MOCK_CONST_METHOD0(getBaseBlobId, std::string()); |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 36 | MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>()); |
Kun Yi | 38146a0 | 2018-12-18 21:54:26 -0800 | [diff] [blame] | 37 | MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t)); |
Kun Yi | c0adbc3 | 2018-12-18 22:35:29 -0800 | [diff] [blame] | 38 | MOCK_METHOD1(deleteBlob, bool(const std::string&)); |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 39 | MOCK_METHOD2(read, std::vector<uint8_t>(uint32_t, uint32_t)); |
| 40 | MOCK_METHOD2(write, bool(uint32_t, const std::vector<uint8_t>&)); |
| 41 | MOCK_METHOD0(commit, bool()); |
| 42 | MOCK_METHOD0(close, bool()); |
| 43 | MOCK_METHOD0(stat, bool()); |
Kun Yi | 64dc05c | 2018-12-19 13:19:03 -0800 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | BinaryStore real_store_; |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace binstore |