1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "test/rbd_mirror/test_mock_fixture.h"
5 #include "include/rbd/librbd.hpp"
6 #include "test/librados_test_stub/LibradosTestStub.h"
7 #include "test/librados_test_stub/MockTestMemCluster.h"
8 #include "test/librados_test_stub/MockTestMemRadosClient.h"
9 #include "test/librbd/mock/MockImageCtx.h"
15 using ::testing::Invoke;
16 using ::testing::WithArg;
18 TestMockFixture::TestClusterRef TestMockFixture::s_test_cluster;
20 void TestMockFixture::SetUpTestCase() {
21 s_test_cluster = librados_test_stub::get_cluster();
23 // use a mock version of the in-memory rados client
24 librados_test_stub::set_cluster(boost::shared_ptr<librados::TestCluster>(
25 new librados::MockTestMemCluster()));
26 TestFixture::SetUpTestCase();
29 void TestMockFixture::TearDownTestCase() {
30 TestFixture::TearDownTestCase();
31 librados_test_stub::set_cluster(s_test_cluster);
34 void TestMockFixture::TearDown() {
35 // Mock rados client lives across tests -- reset it to initial state
36 librados::MockTestMemRadosClient *mock_rados_client =
37 get_mock_io_ctx(m_local_io_ctx).get_mock_rados_client();
38 ASSERT_TRUE(mock_rados_client != nullptr);
40 ::testing::Mock::VerifyAndClear(mock_rados_client);
41 mock_rados_client->default_to_dispatch();
43 TestFixture::TearDown();
46 void TestMockFixture::expect_test_features(librbd::MockImageCtx &mock_image_ctx) {
47 EXPECT_CALL(mock_image_ctx, test_features(_, _))
48 .WillRepeatedly(WithArg<0>(Invoke([&mock_image_ctx](uint64_t features) {
49 return (mock_image_ctx.features & features) != 0;