blob: bdbb052c3960f6ad7369a82bc0a9d65bb4e9bf4f [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 Yi6967b772019-02-22 13:48:12 -080029 ON_CALL(*this, read)
30 .WillByDefault(Invoke(&real_store_, &BinaryStore::read));
31 ON_CALL(*this, write)
32 .WillByDefault(Invoke(&real_store_, &BinaryStore::write));
Kun Yi64dc05c2018-12-19 13:19:03 -080033 }
Kun Yi68c81142018-12-18 11:17:14 -080034 MOCK_CONST_METHOD0(getBaseBlobId, std::string());
Kun Yi68c81142018-12-18 11:17:14 -080035 MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>());
Kun Yi38146a02018-12-18 21:54:26 -080036 MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t));
Kun Yic0adbc32018-12-18 22:35:29 -080037 MOCK_METHOD1(deleteBlob, bool(const std::string&));
Kun Yi68c81142018-12-18 11:17:14 -080038 MOCK_METHOD2(read, std::vector<uint8_t>(uint32_t, uint32_t));
39 MOCK_METHOD2(write, bool(uint32_t, const std::vector<uint8_t>&));
40 MOCK_METHOD0(commit, bool());
41 MOCK_METHOD0(close, bool());
42 MOCK_METHOD0(stat, bool());
Kun Yi64dc05c2018-12-19 13:19:03 -080043
44 private:
45 BinaryStore real_store_;
Kun Yi68c81142018-12-18 11:17:14 -080046};
47
48} // namespace binstore