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