16
16
* Authored by: Thomas Voss <thomas.voss@canonical.com>
19
#include "mock_buffer.h"
20
#include "mock_graphic_buffer_allocator.h"
19
22
#include "mir/compositor/buffer.h"
20
#include "mir/compositor/buffer_manager.h"
21
#include "mir/compositor/buffer_manager_client.h"
23
#include "mir/compositor/buffer_allocation_strategy.h"
24
#include "mir/compositor/buffer_bundle_manager.h"
25
#include "mir/compositor/buffer_bundle.h"
22
26
#include "mir/compositor/graphic_buffer_allocator.h"
24
28
#include <gmock/gmock.h>
41
struct MockGraphicBufferAllocator : mc::GraphicBufferAllocator
45
struct MockBufferAllocationStrategy : public mc::BufferAllocationStrategy
44
MOCK_METHOD3(alloc_buffer, std::shared_ptr<mc::Buffer>(geom::Width, geom::Height, mc::PixelFormat));
45
MOCK_METHOD1(free_buffer, void(std::shared_ptr<mc::Buffer>));
47
MockBufferAllocationStrategy(std::shared_ptr<mc::GraphicBufferAllocator> allocator)
48
: mc::BufferAllocationStrategy(allocator)
53
allocate_buffers_for_bundle,
54
void(geom::Width, geom::Height, mc::PixelFormat, mc::BufferBundle* bundle));
48
57
const geom::Width width{1024};
50
59
const geom::Stride stride{geom::dim_cast<geom::Stride>(width)};
51
60
const mc::PixelFormat pixel_format{mc::PixelFormat::rgba_8888};
53
struct MockBuffer : public mc::Buffer
58
using namespace testing;
59
ON_CALL(*this, width()). WillByDefault(Return(::width));
60
ON_CALL(*this, height()). WillByDefault(Return(::height));
61
ON_CALL(*this, stride()). WillByDefault(Return(::stride));
62
ON_CALL(*this, pixel_format()).WillByDefault(Return(::pixel_format));
65
MOCK_CONST_METHOD0(width, geom::Width());
66
MOCK_CONST_METHOD0(height, geom::Height());
67
MOCK_CONST_METHOD0(stride, geom::Stride());
68
MOCK_CONST_METHOD0(pixel_format, mc::PixelFormat());
72
64
TEST(buffer_manager, create_buffer)
74
66
using namespace testing;
76
MockBuffer mock_buffer;
77
std::shared_ptr<MockBuffer> default_buffer(
68
mc::MockBuffer mock_buffer{width, height, stride, pixel_format};
69
std::shared_ptr<mc::MockBuffer> default_buffer(
80
MockGraphicBufferAllocator graphic_allocator;
81
mc::BufferManager buffer_manager(&graphic_allocator);
83
EXPECT_CALL(graphic_allocator, alloc_buffer(Eq(width), Eq(height), Eq(pixel_format))).
84
Times(AtLeast(1)).WillRepeatedly(Return(default_buffer));
86
mc::BufferManagerClient *client = nullptr;
87
client = buffer_manager.create_client(
92
EXPECT_TRUE(client != nullptr);
94
//TODO this is a frig to keep valgrind happy
72
mc::MockGraphicBufferAllocator graphic_allocator;
73
std::shared_ptr<mc::GraphicBufferAllocator> allocator(&graphic_allocator, EmptyDeleter());
74
MockBufferAllocationStrategy allocation_strategy(allocator);
76
mc::BufferBundleManager buffer_bundle_manager(
77
&allocation_strategy);
79
/* note: this is somewhat of a weak test, some create_clients will create a varied amount
83
alloc_buffer(Eq(width), Eq(height), Eq(pixel_format)))
86
EXPECT_CALL(allocation_strategy, allocate_buffers_for_bundle(Eq(width), Eq(height), Eq(pixel_format), _)).Times(AtLeast(1));
88
std::shared_ptr<mc::BufferBundle> bundle{
89
buffer_bundle_manager.create_buffer_bundle(
94
EXPECT_TRUE(bundle != nullptr);