Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Testing will never be the same
  • Loading branch information
bdero committed Nov 14, 2023
commit d86b778d224e2ecf47a49220c96a22e4c1b6a797
1 change: 1 addition & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impeller_component("entity_unittests") {
"contents/filters/inputs/filter_input_unittests.cc",
"contents/vertices_contents_unittests.cc",
"entity_pass_target_unittests.cc",
"contents/tiled_texture_contents_unittests.cc",
"entity_playground.cc",
"entity_playground.h",
"entity_unittests.cc",
Expand Down
58 changes: 58 additions & 0 deletions impeller/entity/contents/tiled_texture_contents_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#include "impeller/core/sampler_descriptor.h"
#include "impeller/core/texture_descriptor.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/tiled_texture_contents.h"
#include "impeller/renderer/capabilities.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/testing/mocks.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "third_party/googletest/googletest/include/gtest/gtest.h"

namespace impeller {
namespace testing {

TEST(TiledTextureContentsTest, RenderAppendsExpectedCommands) {
auto context = std::make_shared<MockImpellerContext>();

auto sampler_library = std::make_shared<MockSamplerLibrary>();
SamplerDescriptor sampler_desc;
auto sampler = std::make_shared<MockSampler>(sampler_desc);
EXPECT_CALL(*sampler_library, GetSampler)
.WillRepeatedly(::testing::Return(sampler));

EXPECT_CALL(*context, GetSamplerLibrary)
.WillRepeatedly(::testing::Return(sampler_library));

const std::shared_ptr<const Capabilities> capabilities =
std::make_shared<const MockCapabilities>();
EXPECT_CALL(*context, GetCapabilities)
.WillRepeatedly(::testing::ReturnRef(capabilities));

auto content_context =
ContentContext(context, TypographerContextSkia::Make());
auto render_pass = MockRenderPass(context, {});

TextureDescriptor texture_desc;
auto texture = std::make_shared<MockTexture>(texture_desc);
EXPECT_CALL(*texture, GetSize).WillOnce(::testing::Return(ISize(100, 100)));

TiledTextureContents contents;
contents.SetTexture(texture);
contents.SetGeometry(Geometry::MakeCover());

ASSERT_TRUE(contents.Render(content_context, {}, render_pass));
const std::vector<Command>& commands = render_pass.GetCommands();

ASSERT_EQ(commands.size(), 1u);
ASSERT_STREQ(commands[0].pipeline->GetDescriptor().GetLabel().c_str(),
"Something");
}

} // namespace testing
} // namespace impeller
49 changes: 49 additions & 0 deletions impeller/renderer/testing/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include "gmock/gmock.h"
#include "impeller/core/allocator.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/core/texture.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/context.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "impeller/renderer/sampler_library.h"

namespace impeller {
namespace testing {
Expand Down Expand Up @@ -85,6 +88,19 @@ class MockBlitPass : public BlitPass {
(override));
};

class MockRenderPass : public RenderPass {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unused.

public:
MockRenderPass(std::weak_ptr<const Context> context,
const RenderTarget& target)
: RenderPass(std::move(context), target) {}
MOCK_METHOD(bool, IsValid, (), (const, override));
MOCK_METHOD(bool,
OnEncodeCommands,
(const Context& context),
(const, override));
MOCK_METHOD(void, OnSetLabel, (std::string label), (override));
};

class MockCommandBuffer : public CommandBuffer {
public:
MockCommandBuffer(std::weak_ptr<const Context> context)
Expand Down Expand Up @@ -164,5 +180,38 @@ class MockTexture : public Texture {
(override));
};

class MockCapabilities : public Capabilities {
public:
MOCK_METHOD(bool, SupportsOffscreenMSAA, (), (const, override));
MOCK_METHOD(bool, SupportsImplicitResolvingMSAA, (), (const, override));
MOCK_METHOD(bool, SupportsSSBO, (), (const, override));
MOCK_METHOD(bool, SupportsBufferToTextureBlits, (), (const, override));
MOCK_METHOD(bool, SupportsTextureToTextureBlits, (), (const, override));
MOCK_METHOD(bool, SupportsFramebufferFetch, (), (const, override));
MOCK_METHOD(bool, SupportsCompute, (), (const, override));
MOCK_METHOD(bool, SupportsComputeSubgroups, (), (const, override));
MOCK_METHOD(bool, SupportsReadFromOnscreenTexture, (), (const, override));
MOCK_METHOD(bool, SupportsReadFromResolve, (), (const, override));
MOCK_METHOD(bool, SupportsDecalSamplerAddressMode, (), (const, override));
MOCK_METHOD(bool, SupportsDeviceTransientTextures, (), (const, override));
MOCK_METHOD(PixelFormat, GetDefaultColorFormat, (), (const, override));
MOCK_METHOD(PixelFormat, GetDefaultStencilFormat, (), (const, override));
MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat, (), (const, override));
};

class MockSamplerLibrary : public SamplerLibrary {
public:
MOCK_METHOD(std::shared_ptr<const Sampler>,
GetSampler,
(SamplerDescriptor descriptor),
(override));
};

class MockSampler : public Sampler {
public:
explicit MockSampler(const SamplerDescriptor& desc) : Sampler(desc) {}
MOCK_METHOD(bool, IsValid, (), (const, override));
};

} // namespace testing
} // namespace impeller