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