1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "test/librbd/test_mock_fixture.h"
5 #include "test/librbd/test_support.h"
6 #include "test/librbd/mock/MockImageCtx.h"
7 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
8 #include "cls/lock/cls_lock_ops.h"
9 #include "librbd/ObjectMap.h"
10 #include "librbd/object_map/UnlockRequest.h"
12 // template definitions
13 #include "librbd/object_map/UnlockRequest.cc"
16 namespace object_map {
19 using ::testing::InSequence;
20 using ::testing::Return;
21 using ::testing::StrEq;
23 class TestMockObjectMapUnlockRequest : public TestMockFixture {
25 typedef UnlockRequest<MockImageCtx> MockUnlockRequest;
27 void expect_unlock(MockImageCtx &mock_image_ctx, int r) {
28 std::string oid(ObjectMap<>::object_map_name(mock_image_ctx.id,
30 EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
31 exec(oid, _, StrEq("lock"), StrEq("unlock"), _, _, _))
36 TEST_F(TestMockObjectMapUnlockRequest, Success) {
37 librbd::ImageCtx *ictx;
38 ASSERT_EQ(0, open_image(m_image_name, &ictx));
40 MockImageCtx mock_image_ctx(*ictx);
43 MockUnlockRequest *req = new MockUnlockRequest(mock_image_ctx, &ctx);
46 expect_unlock(mock_image_ctx, 0);
49 ASSERT_EQ(0, ctx.wait());
52 TEST_F(TestMockObjectMapUnlockRequest, UnlockError) {
53 librbd::ImageCtx *ictx;
54 ASSERT_EQ(0, open_image(m_image_name, &ictx));
56 MockImageCtx mock_image_ctx(*ictx);
59 MockUnlockRequest *req = new MockUnlockRequest(mock_image_ctx, &ctx);
62 expect_unlock(mock_image_ctx, -ENOENT);
65 ASSERT_EQ(0, ctx.wait());
68 } // namespace object_map