1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H
5 #define LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H
7 #include "test/librados_test_stub/TestMemRadosClient.h"
8 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
9 #include "gmock/gmock.h"
15 class MockTestMemRadosClient
: public TestMemRadosClient
{
17 MockTestMemRadosClient(CephContext
*cct
, TestMemCluster
*test_mem_cluster
)
18 : TestMemRadosClient(cct
, test_mem_cluster
) {
19 default_to_dispatch();
22 MOCK_METHOD0(connect
, int());
24 return TestMemRadosClient::connect();
27 MOCK_METHOD2(create_ioctx
, TestIoCtxImpl
*(int64_t pool_id
,
28 const std::string
&pool_name
));
29 MockTestMemIoCtxImpl
* do_create_ioctx(int64_t pool_id
,
30 const std::string
&pool_name
) {
31 return new ::testing::NiceMock
<MockTestMemIoCtxImpl
>(
32 this, this, pool_id
, pool_name
,
33 get_mem_cluster()->get_pool(pool_name
));
36 MOCK_METHOD2(blacklist_add
, int(const std::string
& client_address
,
37 uint32_t expire_seconds
));
38 int do_blacklist_add(const std::string
& client_address
,
39 uint32_t expire_seconds
) {
40 return TestMemRadosClient::blacklist_add(client_address
, expire_seconds
);
43 MOCK_METHOD1(get_min_compatible_osd
, int(int8_t*));
44 int do_get_min_compatible_osd(int8_t* require_osd_release
) {
45 return TestMemRadosClient::get_min_compatible_osd(require_osd_release
);
48 MOCK_METHOD2(get_min_compatible_client
, int(int8_t*, int8_t*));
49 int do_get_min_compatible_client(int8_t* min_compat_client
,
50 int8_t* require_min_compat_client
) {
51 return TestMemRadosClient::get_min_compatible_client(
52 min_compat_client
, require_min_compat_client
);
55 MOCK_METHOD3(service_daemon_register
,
56 int(const std::string
&,
58 const std::map
<std::string
,std::string
>&));
59 int do_service_daemon_register(const std::string
& service
,
60 const std::string
& name
,
61 const std::map
<std::string
,std::string
>& metadata
) {
62 return TestMemRadosClient::service_daemon_register(service
, name
, metadata
);
65 // workaround of https://github.com/google/googletest/issues/1155
66 MOCK_METHOD1(service_daemon_update_status_r
,
67 int(const std::map
<std::string
,std::string
>&));
68 int do_service_daemon_update_status_r(const std::map
<std::string
,std::string
>& status
) {
70 return TestMemRadosClient::service_daemon_update_status(std::move(s
));
73 void default_to_dispatch() {
74 using namespace ::testing
;
76 ON_CALL(*this, connect()).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_connect
));
77 ON_CALL(*this, create_ioctx(_
, _
)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_create_ioctx
));
78 ON_CALL(*this, blacklist_add(_
, _
)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_blacklist_add
));
79 ON_CALL(*this, get_min_compatible_osd(_
)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_get_min_compatible_osd
));
80 ON_CALL(*this, get_min_compatible_client(_
, _
)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_get_min_compatible_client
));
81 ON_CALL(*this, service_daemon_register(_
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_service_daemon_register
));
82 ON_CALL(*this, service_daemon_update_status_r(_
)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_service_daemon_update_status_r
));
86 } // namespace librados
88 #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H