Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Nov 2, 2023
1 parent fc36579 commit e6bdcc6
Showing 1 changed file with 81 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,87 @@ Scalar CalculateSigmaForBlurRadius(Scalar blur_radius) {

class DirectionalGaussianBlurFilterContentsTest : public ::testing::Test {
public:
void SetUp() override { capabilities_ = mock_capabilities_; }
void SetUp() override {
mock_render_target_allocator_ =
std::make_shared<MockRenderTargetAllocator>(mock_allocator_);
capabilities_ = mock_capabilities_;
}

// Stubs in the minimal support to make rendering pass.
void SetupMinimalContext() {
EXPECT_CALL(*mock_context_, GetCapabilities())
.WillRepeatedly(ReturnRef(capabilities_));
EXPECT_CALL(*mock_context_, IsValid()).WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pipeline_library_, GetPipeline(An<PipelineDescriptor>()))
.WillRepeatedly(Invoke([mock_pipeline_library =
std::weak_ptr<MockPipelineLibrary>(
mock_pipeline_library_)](
PipelineDescriptor descriptor) {
PipelineFuture<PipelineDescriptor> result;
std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
auto mock_pipeline =
std::make_shared<MockPipeline<PipelineDescriptor>>(
mock_pipeline_library, descriptor);
EXPECT_CALL(*mock_pipeline, IsValid()).WillRepeatedly(Return(true));
promise.set_value(mock_pipeline);
result.descriptor = descriptor;
result.future = promise.get_future();
return result;
}));
EXPECT_CALL(*mock_shader_library_, GetFunction(_, _))
.WillRepeatedly(Invoke([](std::string_view name, ShaderStage stage) {
return std::make_shared<MockShaderFunction>(UniqueID(),
std::string(name), stage);
}));
EXPECT_CALL(*mock_context_, GetSamplerLibrary())
.WillRepeatedly(Return(mock_sampler_library_));
EXPECT_CALL(*mock_context_, GetShaderLibrary())
.WillRepeatedly(Return(mock_shader_library_));
EXPECT_CALL(*mock_context_, GetPipelineLibrary())
.WillRepeatedly(Return(mock_pipeline_library_));
EXPECT_CALL(*mock_context_, CreateCommandBuffer())
.WillRepeatedly(Invoke(([mock_context =
std::weak_ptr<MockImpellerContext>(
mock_context_)]() {
auto result = std::make_shared<MockCommandBuffer>(mock_context);
EXPECT_CALL(*result, IsValid()).WillRepeatedly(Return(true));
EXPECT_CALL(*result, OnSubmitCommands(_))
.WillRepeatedly(Return(true));
EXPECT_CALL(*result, OnCreateRenderPass(_))
.WillRepeatedly(
Invoke(([mock_context](const RenderTarget& render_target) {
auto result = std::make_shared<MockRenderPass>(
mock_context, render_target);
EXPECT_CALL(*result, IsValid).WillRepeatedly(Return(true));
EXPECT_CALL(*result, OnEncodeCommands(_))
.WillRepeatedly(Return(true));
return result;
})));
return result;
})));
EXPECT_CALL(*mock_render_target_allocator_, CreateTexture(_))
.WillRepeatedly(Invoke(([](const TextureDescriptor& desc) {
auto result = std::make_shared<MockTexture>(desc);
EXPECT_CALL(*result, IsValid()).WillRepeatedly(Return(true));
return result;
})));
}

std::shared_ptr<MockImpellerContext> mock_context_ =
std::make_shared<MockImpellerContext>();
std::shared_ptr<MockCapabilities> mock_capabilities_ =
std::make_shared<MockCapabilities>();
std::shared_ptr<MockSamplerLibrary> mock_sampler_library_ =
std::make_shared<MockSamplerLibrary>();
std::shared_ptr<MockShaderLibrary> mock_shader_library_ =
std::make_shared<MockShaderLibrary>();
std::shared_ptr<MockPipelineLibrary> mock_pipeline_library_ =
std::make_shared<MockPipelineLibrary>();
std::shared_ptr<MockTypographerContext> mock_typographer_context_ =
std::make_shared<MockTypographerContext>();
std::shared_ptr<MockAllocator> mock_allocator_ =
std::make_shared<MockAllocator>();
std::shared_ptr<MockRenderTargetAllocator> mock_render_target_allocator_;
std::shared_ptr<const Capabilities> capabilities_;
};

Expand Down Expand Up @@ -83,6 +160,7 @@ TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderNoCoverage) {
}

TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderSomething) {
SetupMinimalContext();
TextureDescriptor desc = {
.size = ISize(100, 100),
};
Expand All @@ -93,67 +171,8 @@ TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderSomething) {
contents->SetSigma(Sigma{sigma_radius_1});
contents->SetDirection({1.0, 0.0});
contents->SetInputs({FilterInput::Make(texture)});
auto mock_context = std::make_shared<MockImpellerContext>();
EXPECT_CALL(*mock_context, GetCapabilities())
.WillRepeatedly(ReturnRef(capabilities_));
EXPECT_CALL(*mock_context, IsValid()).WillRepeatedly(Return(true));
auto mock_sampler_library = std::make_shared<MockSamplerLibrary>();
auto mock_shader_library = std::make_shared<MockShaderLibrary>();
auto mock_pipeline_library = std::make_shared<MockPipelineLibrary>();
EXPECT_CALL(*mock_pipeline_library, GetPipeline(An<PipelineDescriptor>()))
.WillRepeatedly(
Invoke([&mock_pipeline_library](PipelineDescriptor descriptor) {
PipelineFuture<PipelineDescriptor> result;
std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
auto mock_pipeline =
std::make_shared<MockPipeline<PipelineDescriptor>>(
mock_pipeline_library, descriptor);
EXPECT_CALL(*mock_pipeline, IsValid()).WillRepeatedly(Return(true));
promise.set_value(mock_pipeline);
result.descriptor = descriptor;
result.future = promise.get_future();
return result;
}));
EXPECT_CALL(*mock_shader_library, GetFunction(_, _))
.WillRepeatedly(Invoke([](std::string_view name, ShaderStage stage) {
return std::make_shared<MockShaderFunction>(UniqueID(),
std::string(name), stage);
}));
EXPECT_CALL(*mock_context, GetSamplerLibrary())
.WillRepeatedly(Return(mock_sampler_library));
EXPECT_CALL(*mock_context, GetShaderLibrary())
.WillRepeatedly(Return(mock_shader_library));
EXPECT_CALL(*mock_context, GetPipelineLibrary())
.WillRepeatedly(Return(mock_pipeline_library));
EXPECT_CALL(*mock_context, CreateCommandBuffer())
.WillRepeatedly(Invoke(([&mock_context]() {
auto result = std::make_shared<MockCommandBuffer>(mock_context);
EXPECT_CALL(*result, IsValid()).WillRepeatedly(Return(true));
EXPECT_CALL(*result, OnSubmitCommands(_)).WillRepeatedly(Return(true));
EXPECT_CALL(*result, OnCreateRenderPass(_))
.WillRepeatedly(
Invoke(([&mock_context](const RenderTarget& render_target) {
auto result = std::make_shared<MockRenderPass>(mock_context,
render_target);
EXPECT_CALL(*result, IsValid).WillRepeatedly(Return(true));
EXPECT_CALL(*result, OnEncodeCommands(_))
.WillRepeatedly(Return(true));
return result;
})));
return result;
})));
auto mock_typographer_context = std::make_shared<MockTypographerContext>();
auto mock_allocator = std::make_shared<MockAllocator>();
auto mock_render_target_allocator =
std::make_shared<MockRenderTargetAllocator>(mock_allocator);
EXPECT_CALL(*mock_render_target_allocator, CreateTexture(_))
.WillRepeatedly(Invoke(([](const TextureDescriptor& desc) {
auto result = std::make_shared<MockTexture>(desc);
EXPECT_CALL(*result, IsValid()).WillRepeatedly(Return(true));
return result;
})));
ContentContext renderer(mock_context, mock_typographer_context,
mock_render_target_allocator);
ContentContext renderer(mock_context_, mock_typographer_context_,
mock_render_target_allocator_);
Entity entity;
Rect coverage_hint = Rect::MakeLTRB(0, 0, 0, 0);
std::optional<Entity> result =
Expand Down

0 comments on commit e6bdcc6

Please sign in to comment.