blob: 34bec6a01c361af408cc8671d881e78eda4fac4b [file] [log] [blame]
Kun Yi68c81142018-12-18 11:17:14 -08001#pragma once
2
3#include "binarystore.hpp"
4
5#include <gmock/gmock.h>
6
Kun Yi64dc05c2018-12-19 13:19:03 -08007using ::testing::Invoke;
8
Kun Yi68c81142018-12-18 11:17:14 -08009namespace binstore
10{
11
12class MockBinaryStore : public BinaryStoreInterface
13{
14 public:
Kun Yi64dc05c2018-12-19 13:19:03 -080015 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 Yi6baa7132019-01-08 21:21:02 -080024 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 Yi64dc05c2018-12-19 13:19:03 -080029 }
Kun Yi68c81142018-12-18 11:17:14 -080030 MOCK_CONST_METHOD0(getBaseBlobId, std::string());
Kun Yi68c81142018-12-18 11:17:14 -080031 MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>());
Kun Yi38146a02018-12-18 21:54:26 -080032 MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t));
Kun Yic0adbc32018-12-18 22:35:29 -080033 MOCK_METHOD1(deleteBlob, bool(const std::string&));
Kun Yi68c81142018-12-18 11:17:14 -080034 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 Yi64dc05c2018-12-19 13:19:03 -080039
40 private:
41 BinaryStore real_store_;
Kun Yi68c81142018-12-18 11:17:14 -080042};
43
44} // namespace binstore