1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H
5 #define CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H
7 #include "test/librbd/test_fixture.h"
8 #include "test/librbd/mock/MockImageCtx.h"
9 #include "test/librados_test_stub/LibradosTestStub.h"
10 #include "common/WorkQueue.h"
11 #include <boost/shared_ptr.hpp>
12 #include <gmock/gmock.h>
16 class MockTestMemCluster
;
17 class MockTestMemIoCtxImpl
;
18 class MockTestMemRadosClient
;
24 ACTION_P(CopyInBufferlist
, str
) {
28 ACTION_P2(CompleteContext
, r
, wq
) {
29 ContextWQ
*context_wq
= reinterpret_cast<ContextWQ
*>(wq
);
30 if (context_wq
!= NULL
) {
31 context_wq
->queue(arg0
, r
);
37 ACTION_P(DispatchContext
, wq
) {
38 wq
->queue(arg0
, arg1
);
41 ACTION_P3(FinishRequest
, request
, r
, mock
) {
42 librbd::MockImageCtx
*mock_image_ctx
=
43 reinterpret_cast<librbd::MockImageCtx
*>(mock
);
44 mock_image_ctx
->image_ctx
->op_work_queue
->queue(request
->on_finish
, r
);
47 ACTION_P(GetReference
, ref_object
) {
51 MATCHER_P(ContentsEqual
, bl
, "") {
52 // TODO fix const-correctness of bufferlist
53 return const_cast<bufferlist
&>(arg
).contents_equal(
54 const_cast<bufferlist
&>(bl
));
57 class TestMockFixture
: public TestFixture
{
59 typedef boost::shared_ptr
<librados::TestCluster
> TestClusterRef
;
61 static void SetUpTestCase();
62 static void TearDownTestCase();
64 void TearDown() override
;
66 void expect_op_work_queue(librbd::MockImageCtx
&mock_image_ctx
);
67 void expect_unlock_exclusive_lock(librbd::ImageCtx
&ictx
);
69 void initialize_features(librbd::ImageCtx
*ictx
,
70 librbd::MockImageCtx
&mock_image_ctx
,
71 librbd::MockExclusiveLock
&mock_exclusive_lock
,
72 librbd::MockJournal
&mock_journal
,
73 librbd::MockObjectMap
&mock_object_map
);
75 void expect_is_journal_appending(librbd::MockJournal
&mock_journal
,
77 void expect_is_journal_replaying(librbd::MockJournal
&mock_journal
);
78 void expect_is_journal_ready(librbd::MockJournal
&mock_journal
);
79 void expect_allocate_op_tid(librbd::MockImageCtx
&mock_image_ctx
);
80 void expect_append_op_event(librbd::MockImageCtx
&mock_image_ctx
,
81 bool can_affect_io
, int r
);
82 void expect_commit_op_event(librbd::MockImageCtx
&mock_image_ctx
, int r
);
85 static TestClusterRef s_test_cluster
;
88 #endif // CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H