]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H | |
5 | #define CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H | |
6 | ||
7 | #include "test/librbd/test_fixture.h" | |
8 | #include "test/librbd/mock/MockImageCtx.h" | |
9 | #include "test/librados_test_stub/LibradosTestStub.h" | |
f67539c2 | 10 | #include "librbd/asio/ContextWQ.h" |
7c673cae FG |
11 | #include <boost/shared_ptr.hpp> |
12 | #include <gmock/gmock.h> | |
13 | ||
14 | namespace librados { | |
15 | class TestCluster; | |
16 | class MockTestMemCluster; | |
17 | class MockTestMemIoCtxImpl; | |
18 | class MockTestMemRadosClient; | |
19 | } | |
20 | namespace librbd { | |
21 | class MockImageCtx; | |
22 | } | |
23 | ||
24 | ACTION_P(CopyInBufferlist, str) { | |
25 | arg0->append(str); | |
26 | } | |
27 | ||
28 | ACTION_P2(CompleteContext, r, wq) { | |
f67539c2 TL |
29 | librbd::asio::ContextWQ *context_wq = reinterpret_cast< |
30 | librbd::asio::ContextWQ *>(wq); | |
7c673cae FG |
31 | if (context_wq != NULL) { |
32 | context_wq->queue(arg0, r); | |
33 | } else { | |
34 | arg0->complete(r); | |
35 | } | |
36 | } | |
37 | ||
38 | ACTION_P(DispatchContext, wq) { | |
39 | wq->queue(arg0, arg1); | |
40 | } | |
41 | ||
42 | ACTION_P3(FinishRequest, request, r, mock) { | |
43 | librbd::MockImageCtx *mock_image_ctx = | |
44 | reinterpret_cast<librbd::MockImageCtx *>(mock); | |
45 | mock_image_ctx->image_ctx->op_work_queue->queue(request->on_finish, r); | |
46 | } | |
47 | ||
48 | ACTION_P(GetReference, ref_object) { | |
49 | ref_object->get(); | |
50 | } | |
51 | ||
7c673cae FG |
52 | MATCHER_P(ContentsEqual, bl, "") { |
53 | // TODO fix const-correctness of bufferlist | |
54 | return const_cast<bufferlist &>(arg).contents_equal( | |
55 | const_cast<bufferlist &>(bl)); | |
56 | } | |
57 | ||
58 | class TestMockFixture : public TestFixture { | |
59 | public: | |
60 | typedef boost::shared_ptr<librados::TestCluster> TestClusterRef; | |
61 | ||
62 | static void SetUpTestCase(); | |
63 | static void TearDownTestCase(); | |
64 | ||
65 | void TearDown() override; | |
66 | ||
67 | void expect_op_work_queue(librbd::MockImageCtx &mock_image_ctx); | |
68 | void expect_unlock_exclusive_lock(librbd::ImageCtx &ictx); | |
69 | ||
70 | void initialize_features(librbd::ImageCtx *ictx, | |
71 | librbd::MockImageCtx &mock_image_ctx, | |
72 | librbd::MockExclusiveLock &mock_exclusive_lock, | |
73 | librbd::MockJournal &mock_journal, | |
74 | librbd::MockObjectMap &mock_object_map); | |
75 | ||
76 | void expect_is_journal_appending(librbd::MockJournal &mock_journal, | |
77 | bool appending); | |
78 | void expect_is_journal_replaying(librbd::MockJournal &mock_journal); | |
79 | void expect_is_journal_ready(librbd::MockJournal &mock_journal); | |
80 | void expect_allocate_op_tid(librbd::MockImageCtx &mock_image_ctx); | |
81 | void expect_append_op_event(librbd::MockImageCtx &mock_image_ctx, | |
82 | bool can_affect_io, int r); | |
83 | void expect_commit_op_event(librbd::MockImageCtx &mock_image_ctx, int r); | |
84 | ||
85 | private: | |
86 | static TestClusterRef s_test_cluster; | |
87 | }; | |
88 | ||
89 | #endif // CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H |