Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit da0d242

Browse files
committed
Testing will never be the same
1 parent 1bed7f4 commit da0d242

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

impeller/entity/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impeller_component("entity_unittests") {
242242

243243
sources = [
244244
"contents/filters/inputs/filter_input_unittests.cc",
245+
"contents/tiled_texture_contents_unittests.cc",
245246
"entity_playground.cc",
246247
"entity_playground.h",
247248
"entity_unittests.cc",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <memory>
6+
7+
#include "impeller/core/sampler_descriptor.h"
8+
#include "impeller/core/texture_descriptor.h"
9+
#include "impeller/entity/contents/content_context.h"
10+
#include "impeller/entity/contents/tiled_texture_contents.h"
11+
#include "impeller/renderer/capabilities.h"
12+
#include "impeller/renderer/sampler_library.h"
13+
#include "impeller/renderer/testing/mocks.h"
14+
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
15+
#include "third_party/googletest/googletest/include/gtest/gtest.h"
16+
17+
namespace impeller {
18+
namespace testing {
19+
20+
TEST(TiledTextureContentsTest, RenderAppendsExpectedCommands) {
21+
auto context = std::make_shared<MockImpellerContext>();
22+
23+
auto sampler_library = std::make_shared<MockSamplerLibrary>();
24+
SamplerDescriptor sampler_desc;
25+
auto sampler = std::make_shared<MockSampler>(sampler_desc);
26+
EXPECT_CALL(*sampler_library, GetSampler)
27+
.WillRepeatedly(::testing::Return(sampler));
28+
29+
EXPECT_CALL(*context, GetSamplerLibrary)
30+
.WillRepeatedly(::testing::Return(sampler_library));
31+
32+
const std::shared_ptr<const Capabilities> capabilities =
33+
std::make_shared<const MockCapabilities>();
34+
EXPECT_CALL(*context, GetCapabilities)
35+
.WillRepeatedly(::testing::ReturnRef(capabilities));
36+
37+
auto content_context =
38+
ContentContext(context, TypographerContextSkia::Make());
39+
auto render_pass = MockRenderPass(context, {});
40+
41+
TextureDescriptor texture_desc;
42+
auto texture = std::make_shared<MockTexture>(texture_desc);
43+
EXPECT_CALL(*texture, GetSize).WillOnce(::testing::Return(ISize(100, 100)));
44+
45+
TiledTextureContents contents;
46+
contents.SetTexture(texture);
47+
contents.SetGeometry(Geometry::MakeCover());
48+
49+
ASSERT_TRUE(contents.Render(content_context, {}, render_pass));
50+
const std::vector<Command>& commands = render_pass.GetCommands();
51+
52+
ASSERT_EQ(commands.size(), 1u);
53+
ASSERT_STREQ(commands[0].pipeline->GetDescriptor().GetLabel().c_str(),
54+
"Something");
55+
}
56+
57+
} // namespace testing
58+
} // namespace impeller

impeller/renderer/testing/mocks.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
#include "gmock/gmock.h"
88
#include "impeller/core/allocator.h"
9+
#include "impeller/core/sampler_descriptor.h"
910
#include "impeller/core/texture.h"
1011
#include "impeller/renderer/command_buffer.h"
1112
#include "impeller/renderer/context.h"
13+
#include "impeller/renderer/render_pass.h"
1214
#include "impeller/renderer/render_target.h"
15+
#include "impeller/renderer/sampler_library.h"
1316

1417
namespace impeller {
1518
namespace testing {
@@ -85,6 +88,19 @@ class MockBlitPass : public BlitPass {
8588
(override));
8689
};
8790

91+
class MockRenderPass : public RenderPass {
92+
public:
93+
MockRenderPass(std::weak_ptr<const Context> context,
94+
const RenderTarget& target)
95+
: RenderPass(std::move(context), target) {}
96+
MOCK_METHOD(bool, IsValid, (), (const, override));
97+
MOCK_METHOD(bool,
98+
OnEncodeCommands,
99+
(const Context& context),
100+
(const, override));
101+
MOCK_METHOD(void, OnSetLabel, (std::string label), (override));
102+
};
103+
88104
class MockCommandBuffer : public CommandBuffer {
89105
public:
90106
MockCommandBuffer(std::weak_ptr<const Context> context)
@@ -164,5 +180,38 @@ class MockTexture : public Texture {
164180
(override));
165181
};
166182

183+
class MockCapabilities : public Capabilities {
184+
public:
185+
MOCK_METHOD(bool, SupportsOffscreenMSAA, (), (const, override));
186+
MOCK_METHOD(bool, SupportsImplicitResolvingMSAA, (), (const, override));
187+
MOCK_METHOD(bool, SupportsSSBO, (), (const, override));
188+
MOCK_METHOD(bool, SupportsBufferToTextureBlits, (), (const, override));
189+
MOCK_METHOD(bool, SupportsTextureToTextureBlits, (), (const, override));
190+
MOCK_METHOD(bool, SupportsFramebufferFetch, (), (const, override));
191+
MOCK_METHOD(bool, SupportsCompute, (), (const, override));
192+
MOCK_METHOD(bool, SupportsComputeSubgroups, (), (const, override));
193+
MOCK_METHOD(bool, SupportsReadFromOnscreenTexture, (), (const, override));
194+
MOCK_METHOD(bool, SupportsReadFromResolve, (), (const, override));
195+
MOCK_METHOD(bool, SupportsDecalSamplerAddressMode, (), (const, override));
196+
MOCK_METHOD(bool, SupportsDeviceTransientTextures, (), (const, override));
197+
MOCK_METHOD(PixelFormat, GetDefaultColorFormat, (), (const, override));
198+
MOCK_METHOD(PixelFormat, GetDefaultStencilFormat, (), (const, override));
199+
MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat, (), (const, override));
200+
};
201+
202+
class MockSamplerLibrary : public SamplerLibrary {
203+
public:
204+
MOCK_METHOD(std::shared_ptr<const Sampler>,
205+
GetSampler,
206+
(SamplerDescriptor descriptor),
207+
(override));
208+
};
209+
210+
class MockSampler : public Sampler {
211+
public:
212+
explicit MockSampler(const SamplerDescriptor& desc) : Sampler(desc) {}
213+
MOCK_METHOD(bool, IsValid, (), (const, override));
214+
};
215+
167216
} // namespace testing
168217
} // namespace impeller

0 commit comments

Comments
 (0)