@@ -27,10 +27,86 @@ Scalar CalculateSigmaForBlurRadius(Scalar blur_radius) {
2727
2828class DirectionalGaussianBlurFilterContentsTest : public ::testing::Test {
2929 public:
30- void SetUp () override { capabilities_ = mock_capabilities_; }
30+ void SetUp () override {
31+ mock_render_target_allocator_ =
32+ std::make_shared<MockRenderTargetAllocator>(mock_allocator_);
33+ capabilities_ = mock_capabilities_;
34+ }
3135
36+ void SetupDefaultRender () {
37+ EXPECT_CALL (*mock_context_, GetCapabilities ())
38+ .WillRepeatedly (ReturnRef (capabilities_));
39+ EXPECT_CALL (*mock_context_, IsValid ()).WillRepeatedly (Return (true ));
40+ EXPECT_CALL (*mock_pipeline_library_, GetPipeline (An<PipelineDescriptor>()))
41+ .WillRepeatedly (Invoke ([mock_pipeline_library =
42+ std::weak_ptr<MockPipelineLibrary>(
43+ mock_pipeline_library_)](
44+ PipelineDescriptor descriptor) {
45+ PipelineFuture<PipelineDescriptor> result;
46+ std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
47+ auto mock_pipeline =
48+ std::make_shared<MockPipeline<PipelineDescriptor>>(
49+ mock_pipeline_library, descriptor);
50+ EXPECT_CALL (*mock_pipeline, IsValid ()).WillRepeatedly (Return (true ));
51+ promise.set_value (mock_pipeline);
52+ result.descriptor = descriptor;
53+ result.future = promise.get_future ();
54+ return result;
55+ }));
56+ EXPECT_CALL (*mock_shader_library_, GetFunction (_, _))
57+ .WillRepeatedly (Invoke ([](std::string_view name, ShaderStage stage) {
58+ return std::make_shared<MockShaderFunction>(UniqueID (),
59+ std::string (name), stage);
60+ }));
61+ EXPECT_CALL (*mock_context_, GetSamplerLibrary ())
62+ .WillRepeatedly (Return (mock_sampler_library_));
63+ EXPECT_CALL (*mock_context_, GetShaderLibrary ())
64+ .WillRepeatedly (Return (mock_shader_library_));
65+ EXPECT_CALL (*mock_context_, GetPipelineLibrary ())
66+ .WillRepeatedly (Return (mock_pipeline_library_));
67+ EXPECT_CALL (*mock_context_, CreateCommandBuffer ())
68+ .WillRepeatedly (Invoke (([mock_context =
69+ std::weak_ptr<MockImpellerContext>(
70+ mock_context_)]() {
71+ auto result = std::make_shared<MockCommandBuffer>(mock_context);
72+ EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
73+ EXPECT_CALL (*result, OnSubmitCommands (_))
74+ .WillRepeatedly (Return (true ));
75+ EXPECT_CALL (*result, OnCreateRenderPass (_))
76+ .WillRepeatedly (
77+ Invoke (([mock_context](const RenderTarget& render_target) {
78+ auto result = std::make_shared<MockRenderPass>(
79+ mock_context, render_target);
80+ EXPECT_CALL (*result, IsValid).WillRepeatedly (Return (true ));
81+ EXPECT_CALL (*result, OnEncodeCommands (_))
82+ .WillRepeatedly (Return (true ));
83+ return result;
84+ })));
85+ return result;
86+ })));
87+ EXPECT_CALL (*mock_render_target_allocator_, CreateTexture (_))
88+ .WillRepeatedly (Invoke (([](const TextureDescriptor& desc) {
89+ auto result = std::make_shared<MockTexture>(desc);
90+ EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
91+ return result;
92+ })));
93+ }
94+
95+ std::shared_ptr<MockImpellerContext> mock_context_ =
96+ std::make_shared<MockImpellerContext>();
3297 std::shared_ptr<MockCapabilities> mock_capabilities_ =
3398 std::make_shared<MockCapabilities>();
99+ std::shared_ptr<MockSamplerLibrary> mock_sampler_library_ =
100+ std::make_shared<MockSamplerLibrary>();
101+ std::shared_ptr<MockShaderLibrary> mock_shader_library_ =
102+ std::make_shared<MockShaderLibrary>();
103+ std::shared_ptr<MockPipelineLibrary> mock_pipeline_library_ =
104+ std::make_shared<MockPipelineLibrary>();
105+ std::shared_ptr<MockTypographerContext> mock_typographer_context_ =
106+ std::make_shared<MockTypographerContext>();
107+ std::shared_ptr<MockAllocator> mock_allocator_ =
108+ std::make_shared<MockAllocator>();
109+ std::shared_ptr<MockRenderTargetAllocator> mock_render_target_allocator_;
34110 std::shared_ptr<const Capabilities> capabilities_;
35111};
36112
@@ -83,6 +159,7 @@ TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderNoCoverage) {
83159}
84160
85161TEST_F (DirectionalGaussianBlurFilterContentsTest, RenderSomething) {
162+ SetupDefaultRender ();
86163 TextureDescriptor desc = {
87164 .size = ISize (100 , 100 ),
88165 };
@@ -93,67 +170,8 @@ TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderSomething) {
93170 contents->SetSigma (Sigma{sigma_radius_1});
94171 contents->SetDirection ({1.0 , 0.0 });
95172 contents->SetInputs ({FilterInput::Make (texture)});
96- auto mock_context = std::make_shared<MockImpellerContext>();
97- EXPECT_CALL (*mock_context, GetCapabilities ())
98- .WillRepeatedly (ReturnRef (capabilities_));
99- EXPECT_CALL (*mock_context, IsValid ()).WillRepeatedly (Return (true ));
100- auto mock_sampler_library = std::make_shared<MockSamplerLibrary>();
101- auto mock_shader_library = std::make_shared<MockShaderLibrary>();
102- auto mock_pipeline_library = std::make_shared<MockPipelineLibrary>();
103- EXPECT_CALL (*mock_pipeline_library, GetPipeline (An<PipelineDescriptor>()))
104- .WillRepeatedly (
105- Invoke ([&mock_pipeline_library](PipelineDescriptor descriptor) {
106- PipelineFuture<PipelineDescriptor> result;
107- std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
108- auto mock_pipeline =
109- std::make_shared<MockPipeline<PipelineDescriptor>>(
110- mock_pipeline_library, descriptor);
111- EXPECT_CALL (*mock_pipeline, IsValid ()).WillRepeatedly (Return (true ));
112- promise.set_value (mock_pipeline);
113- result.descriptor = descriptor;
114- result.future = promise.get_future ();
115- return result;
116- }));
117- EXPECT_CALL (*mock_shader_library, GetFunction (_, _))
118- .WillRepeatedly (Invoke ([](std::string_view name, ShaderStage stage) {
119- return std::make_shared<MockShaderFunction>(UniqueID (),
120- std::string (name), stage);
121- }));
122- EXPECT_CALL (*mock_context, GetSamplerLibrary ())
123- .WillRepeatedly (Return (mock_sampler_library));
124- EXPECT_CALL (*mock_context, GetShaderLibrary ())
125- .WillRepeatedly (Return (mock_shader_library));
126- EXPECT_CALL (*mock_context, GetPipelineLibrary ())
127- .WillRepeatedly (Return (mock_pipeline_library));
128- EXPECT_CALL (*mock_context, CreateCommandBuffer ())
129- .WillRepeatedly (Invoke (([&mock_context]() {
130- auto result = std::make_shared<MockCommandBuffer>(mock_context);
131- EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
132- EXPECT_CALL (*result, OnSubmitCommands (_)).WillRepeatedly (Return (true ));
133- EXPECT_CALL (*result, OnCreateRenderPass (_))
134- .WillRepeatedly (
135- Invoke (([&mock_context](const RenderTarget& render_target) {
136- auto result = std::make_shared<MockRenderPass>(mock_context,
137- render_target);
138- EXPECT_CALL (*result, IsValid).WillRepeatedly (Return (true ));
139- EXPECT_CALL (*result, OnEncodeCommands (_))
140- .WillRepeatedly (Return (true ));
141- return result;
142- })));
143- return result;
144- })));
145- auto mock_typographer_context = std::make_shared<MockTypographerContext>();
146- auto mock_allocator = std::make_shared<MockAllocator>();
147- auto mock_render_target_allocator =
148- std::make_shared<MockRenderTargetAllocator>(mock_allocator);
149- EXPECT_CALL (*mock_render_target_allocator, CreateTexture (_))
150- .WillRepeatedly (Invoke (([](const TextureDescriptor& desc) {
151- auto result = std::make_shared<MockTexture>(desc);
152- EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
153- return result;
154- })));
155- ContentContext renderer (mock_context, mock_typographer_context,
156- mock_render_target_allocator);
173+ ContentContext renderer (mock_context_, mock_typographer_context_,
174+ mock_render_target_allocator_);
157175 Entity entity;
158176 Rect coverage_hint = Rect::MakeLTRB (0 , 0 , 0 , 0 );
159177 std::optional<Entity> result =
0 commit comments