blob: 3c7e6c80f20a20580154aad624f406e4a909faf0 [file] [log] [blame]
Kun Yi68c81142018-12-18 11:17:14 -08001#pragma once
2
3#include "binarystore.hpp"
Kun Yi2765b642019-01-16 11:11:24 -08004#include "sys_file.hpp"
Kun Yi68c81142018-12-18 11:17:14 -08005
6#include <gmock/gmock.h>
7
Kun Yi64dc05c2018-12-19 13:19:03 -08008using ::testing::Invoke;
9
Kun Yi68c81142018-12-18 11:17:14 -080010namespace binstore
11{
12
13class MockBinaryStore : public BinaryStoreInterface
14{
15 public:
Kun Yi2765b642019-01-16 11:11:24 -080016 MockBinaryStore(const std::string& baseBlobId,
17 std::unique_ptr<SysFile> file, uint32_t maxSize) :
18 real_store_(baseBlobId, std::move(file), maxSize)
Kun Yi64dc05c2018-12-19 13:19:03 -080019 {
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 Yi6baa7132019-01-08 21:21:02 -080025 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 Yi6967b772019-02-22 13:48:12 -080030 ON_CALL(*this, read)
31 .WillByDefault(Invoke(&real_store_, &BinaryStore::read));
32 ON_CALL(*this, write)
33 .WillByDefault(Invoke(&real_store_, &BinaryStore::write));
Kun Yid297c9f2019-01-09 13:52:30 -080034 ON_CALL(*this, commit)
35 .WillByDefault(Invoke(&real_store_, &BinaryStore::commit));
Kun Yi64dc05c2018-12-19 13:19:03 -080036 }
Kun Yi68c81142018-12-18 11:17:14 -080037 MOCK_CONST_METHOD0(getBaseBlobId, std::string());
Kun Yi68c81142018-12-18 11:17:14 -080038 MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>());
Kun Yi38146a02018-12-18 21:54:26 -080039 MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t));
Kun Yic0adbc32018-12-18 22:35:29 -080040 MOCK_METHOD1(deleteBlob, bool(const std::string&));
Kun Yi68c81142018-12-18 11:17:14 -080041 MOCK_METHOD2(read, std::vector<uint8_t>(uint32_t, uint32_t));
42 MOCK_METHOD2(write, bool(uint32_t, const std::vector<uint8_t>&));
43 MOCK_METHOD0(commit, bool());
44 MOCK_METHOD0(close, bool());
45 MOCK_METHOD0(stat, bool());
Kun Yi64dc05c2018-12-19 13:19:03 -080046
47 private:
48 BinaryStore real_store_;
Kun Yi68c81142018-12-18 11:17:14 -080049};
50
51} // namespace binstore