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 ACTION_P(Notify, ctx) {
55 MATCHER_P(ContentsEqual, bl, "") {
56 // TODO fix const-correctness of bufferlist
57 return const_cast<bufferlist &>(arg).contents_equal(
58 const_cast<bufferlist &>(bl));
61 class TestMockFixture : public TestFixture {
63 typedef boost::shared_ptr<librados::TestCluster> TestClusterRef;
65 static void SetUpTestCase();
66 static void TearDownTestCase();
68 void TearDown() override;
70 void expect_op_work_queue(librbd::MockImageCtx &mock_image_ctx);
71 void expect_unlock_exclusive_lock(librbd::ImageCtx &ictx);
73 void initialize_features(librbd::ImageCtx *ictx,
74 librbd::MockImageCtx &mock_image_ctx,
75 librbd::MockExclusiveLock &mock_exclusive_lock,
76 librbd::MockJournal &mock_journal,
77 librbd::MockObjectMap &mock_object_map);
79 void expect_is_journal_appending(librbd::MockJournal &mock_journal,
81 void expect_is_journal_replaying(librbd::MockJournal &mock_journal);
82 void expect_is_journal_ready(librbd::MockJournal &mock_journal);
83 void expect_allocate_op_tid(librbd::MockImageCtx &mock_image_ctx);
84 void expect_append_op_event(librbd::MockImageCtx &mock_image_ctx,
85 bool can_affect_io, int r);
86 void expect_commit_op_event(librbd::MockImageCtx &mock_image_ctx, int r);
89 static TestClusterRef s_test_cluster;
92 #endif // CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H