Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated MOCK_METHODx calls #45307

Merged
merged 8 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
2 changes: 1 addition & 1 deletion flow/stopwatch_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace testing {

class MockRefreshRateUpdater : public Stopwatch::RefreshRateUpdater {
public:
MOCK_CONST_METHOD0(GetFrameBudget, fml::Milliseconds());
MOCK_METHOD(fml::Milliseconds, GetFrameBudget, (), (const, override));
};

TEST(Instrumentation, GetDefaultFrameBudgetTest) {
Expand Down
74 changes: 52 additions & 22 deletions impeller/aiks/testing/context_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,50 @@ class CommandBufferMock : public CommandBuffer {
CommandBufferMock(std::weak_ptr<const Context> context)
: CommandBuffer(context) {}

MOCK_CONST_METHOD0(IsValid, bool());
MOCK_METHOD(bool, IsValid, (), (const, override));

MOCK_CONST_METHOD1(SetLabel, void(const std::string& label));
MOCK_METHOD(void, SetLabel, (const std::string& label), (const, override));

MOCK_METHOD1(SubmitCommandsAsync,
bool(std::shared_ptr<RenderPass> render_pass));
MOCK_METHOD(bool,
SubmitCommandsAsync,
(std::shared_ptr<RenderPass> render_pass),
(override));

MOCK_METHOD1(OnCreateRenderPass,
std::shared_ptr<RenderPass>(RenderTarget render_target));
MOCK_METHOD(std::shared_ptr<RenderPass>,
OnCreateRenderPass,
(RenderTarget render_target),
(override));

static std::shared_ptr<RenderPass> ForwardOnCreateRenderPass(
CommandBuffer* command_buffer,
RenderTarget render_target) {
return command_buffer->OnCreateRenderPass(render_target);
}

MOCK_METHOD0(OnCreateBlitPass, std::shared_ptr<BlitPass>());
MOCK_METHOD(std::shared_ptr<BlitPass>, OnCreateBlitPass, (), (override));
static std::shared_ptr<BlitPass> ForwardOnCreateBlitPass(
CommandBuffer* command_buffer) {
return command_buffer->OnCreateBlitPass();
}

MOCK_METHOD1(OnSubmitCommands, bool(CompletionCallback callback));
MOCK_METHOD(bool,
OnSubmitCommands,
(CompletionCallback callback),
(override));
static bool ForwardOnSubmitCommands(CommandBuffer* command_buffer,
CompletionCallback callback) {
return command_buffer->OnSubmitCommands(callback);
}

MOCK_METHOD0(OnWaitUntilScheduled, void());
MOCK_METHOD(void, OnWaitUntilScheduled, (), (override));
static void ForwardOnWaitUntilScheduled(CommandBuffer* command_buffer) {
return command_buffer->OnWaitUntilScheduled();
}

MOCK_METHOD0(OnCreateComputePass, std::shared_ptr<ComputePass>());
MOCK_METHOD(std::shared_ptr<ComputePass>,
OnCreateComputePass,
(),
(override));
static std::shared_ptr<ComputePass> ForwardOnCreateComputePass(
CommandBuffer* command_buffer) {
return command_buffer->OnCreateComputePass();
Expand All @@ -63,28 +73,48 @@ class CommandBufferMock : public CommandBuffer {

class ContextMock : public Context {
public:
MOCK_CONST_METHOD0(DescribeGpuModel, std::string());
MOCK_METHOD(std::string, DescribeGpuModel, (), (const, override));

MOCK_CONST_METHOD0(GetBackendType, Context::BackendType());
MOCK_METHOD(Context::BackendType, GetBackendType, (), (const, override));

MOCK_CONST_METHOD0(IsValid, bool());
MOCK_METHOD(bool, IsValid, (), (const, override));

MOCK_CONST_METHOD0(GetCapabilities,
const std::shared_ptr<const Capabilities>&());
MOCK_METHOD(const std::shared_ptr<const Capabilities>&,
GetCapabilities,
(),
(const, override));

MOCK_METHOD1(UpdateOffscreenLayerPixelFormat, bool(PixelFormat format));
MOCK_METHOD(bool,
UpdateOffscreenLayerPixelFormat,
(PixelFormat format),
(override));

MOCK_CONST_METHOD0(GetResourceAllocator, std::shared_ptr<Allocator>());
MOCK_METHOD(std::shared_ptr<Allocator>,
GetResourceAllocator,
(),
(const, override));

MOCK_CONST_METHOD0(GetShaderLibrary, std::shared_ptr<ShaderLibrary>());
MOCK_METHOD(std::shared_ptr<ShaderLibrary>,
GetShaderLibrary,
(),
(const, override));

MOCK_CONST_METHOD0(GetSamplerLibrary, std::shared_ptr<SamplerLibrary>());
MOCK_METHOD(std::shared_ptr<SamplerLibrary>,
GetSamplerLibrary,
(),
(const, override));

MOCK_CONST_METHOD0(GetPipelineLibrary, std::shared_ptr<PipelineLibrary>());
MOCK_METHOD(std::shared_ptr<PipelineLibrary>,
GetPipelineLibrary,
(),
(const, override));

MOCK_CONST_METHOD0(CreateCommandBuffer, std::shared_ptr<CommandBuffer>());
MOCK_METHOD(std::shared_ptr<CommandBuffer>,
CreateCommandBuffer,
(),
(const, override));

MOCK_METHOD0(Shutdown, void());
MOCK_METHOD(void, Shutdown, (), (override));
};

} // namespace testing
Expand Down
183 changes: 114 additions & 69 deletions impeller/renderer/testing/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,111 +17,156 @@ namespace testing {
class MockDeviceBuffer : public DeviceBuffer {
public:
MockDeviceBuffer(const DeviceBufferDescriptor& desc) : DeviceBuffer(desc) {}
MOCK_METHOD3(CopyHostBuffer,
bool(const uint8_t* source, Range source_range, size_t offset));
// MOCK_METHOD(bool, CopyHostBuffer, (const uint8_t* source, Range
// source_range, size_t offset), (override));
Copy link
Contributor Author

@dkwingsmt dkwingsmt Sep 1, 2023

Choose a reason for hiding this comment

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

Since this method is not virtual, and its mock is not used, this mock is removed.


MOCK_METHOD1(SetLabel, bool(const std::string& label));
MOCK_METHOD(bool, SetLabel, (const std::string& label), (override));

MOCK_METHOD2(SetLabel, bool(const std::string& label, Range range));
MOCK_METHOD(bool,
SetLabel,
(const std::string& label, Range range),
(override));

MOCK_CONST_METHOD0(OnGetContents, uint8_t*());
MOCK_METHOD(uint8_t*, OnGetContents, (), (const, override));

MOCK_METHOD3(OnCopyHostBuffer,
bool(const uint8_t* source, Range source_range, size_t offset));
MOCK_METHOD(bool,
OnCopyHostBuffer,
(const uint8_t* source, Range source_range, size_t offset),
(override));
};

class MockAllocator : public Allocator {
public:
MOCK_CONST_METHOD0(GetMaxTextureSizeSupported, ISize());
MOCK_METHOD1(
OnCreateBuffer,
std::shared_ptr<DeviceBuffer>(const DeviceBufferDescriptor& desc));
MOCK_METHOD1(OnCreateTexture,
std::shared_ptr<Texture>(const TextureDescriptor& desc));
MOCK_METHOD(ISize, GetMaxTextureSizeSupported, (), (const, override));
MOCK_METHOD(std::shared_ptr<DeviceBuffer>,
OnCreateBuffer,
(const DeviceBufferDescriptor& desc),
(override));
MOCK_METHOD(std::shared_ptr<Texture>,
OnCreateTexture,
(const TextureDescriptor& desc),
(override));
};

class MockBlitPass : public BlitPass {
public:
MOCK_CONST_METHOD0(IsValid, bool());
MOCK_CONST_METHOD1(
EncodeCommands,
bool(const std::shared_ptr<Allocator>& transients_allocator));
MOCK_METHOD1(OnSetLabel, void(std::string label));

MOCK_METHOD5(OnCopyTextureToTextureCommand,
bool(std::shared_ptr<Texture> source,
std::shared_ptr<Texture> destination,
IRect source_region,
IPoint destination_origin,
std::string label));

MOCK_METHOD5(OnCopyTextureToBufferCommand,
bool(std::shared_ptr<Texture> source,
std::shared_ptr<DeviceBuffer> destination,
IRect source_region,
size_t destination_offset,
std::string label));
MOCK_METHOD4(OnCopyBufferToTextureCommand,
bool(BufferView source,
std::shared_ptr<Texture> destination,
IPoint destination_origin,
std::string label));
MOCK_METHOD2(OnGenerateMipmapCommand,
bool(std::shared_ptr<Texture> texture, std::string label));
MOCK_METHOD(bool, IsValid, (), (const, override));
MOCK_METHOD(bool,
EncodeCommands,
(const std::shared_ptr<Allocator>& transients_allocator),
(const, override));
MOCK_METHOD(void, OnSetLabel, (std::string label), (override));

MOCK_METHOD(bool,
OnCopyTextureToTextureCommand,
(std::shared_ptr<Texture> source,
std::shared_ptr<Texture> destination,
IRect source_region,
IPoint destination_origin,
std::string label),
(override));

MOCK_METHOD(bool,
OnCopyTextureToBufferCommand,
(std::shared_ptr<Texture> source,
std::shared_ptr<DeviceBuffer> destination,
IRect source_region,
size_t destination_offset,
std::string label),
(override));
MOCK_METHOD(bool,
OnCopyBufferToTextureCommand,
(BufferView source,
std::shared_ptr<Texture> destination,
IPoint destination_origin,
std::string label),
(override));
MOCK_METHOD(bool,
OnGenerateMipmapCommand,
(std::shared_ptr<Texture> texture, std::string label),
(override));
};

class MockCommandBuffer : public CommandBuffer {
public:
MockCommandBuffer(std::weak_ptr<const Context> context)
: CommandBuffer(context) {}
MOCK_CONST_METHOD0(IsValid, bool());
MOCK_CONST_METHOD1(SetLabel, void(const std::string& label));
MOCK_METHOD0(OnCreateBlitPass, std::shared_ptr<BlitPass>());
MOCK_METHOD1(OnSubmitCommands, bool(CompletionCallback callback));
MOCK_METHOD0(OnWaitUntilScheduled, void());
MOCK_METHOD0(OnCreateComputePass, std::shared_ptr<ComputePass>());
MOCK_METHOD1(OnCreateRenderPass,
std::shared_ptr<RenderPass>(RenderTarget render_target));
MOCK_METHOD(bool, IsValid, (), (const, override));
MOCK_METHOD(void, SetLabel, (const std::string& label), (const, override));
MOCK_METHOD(std::shared_ptr<BlitPass>, OnCreateBlitPass, (), (override));
MOCK_METHOD(bool,
OnSubmitCommands,
(CompletionCallback callback),
(override));
MOCK_METHOD(void, OnWaitUntilScheduled, (), (override));
MOCK_METHOD(std::shared_ptr<ComputePass>,
OnCreateComputePass,
(),
(override));
MOCK_METHOD(std::shared_ptr<RenderPass>,
OnCreateRenderPass,
(RenderTarget render_target),
(override));
};

class MockImpellerContext : public Context {
public:
MOCK_CONST_METHOD0(GetBackendType, Context::BackendType());
MOCK_METHOD(Context::BackendType, GetBackendType, (), (const, override));

MOCK_CONST_METHOD0(DescribeGpuModel, std::string());
MOCK_METHOD(std::string, DescribeGpuModel, (), (const, override));

MOCK_CONST_METHOD0(IsValid, bool());
MOCK_METHOD(bool, IsValid, (), (const, override));

MOCK_METHOD0(Shutdown, void());
MOCK_METHOD(void, Shutdown, (), (override));

MOCK_CONST_METHOD0(GetResourceAllocator, std::shared_ptr<Allocator>());
MOCK_METHOD(std::shared_ptr<Allocator>,
GetResourceAllocator,
(),
(const, override));

MOCK_CONST_METHOD0(GetShaderLibrary, std::shared_ptr<ShaderLibrary>());
MOCK_METHOD(std::shared_ptr<ShaderLibrary>,
GetShaderLibrary,
(),
(const, override));

MOCK_CONST_METHOD0(GetSamplerLibrary, std::shared_ptr<SamplerLibrary>());
MOCK_METHOD(std::shared_ptr<SamplerLibrary>,
GetSamplerLibrary,
(),
(const, override));

MOCK_CONST_METHOD0(GetPipelineLibrary, std::shared_ptr<PipelineLibrary>());
MOCK_METHOD(std::shared_ptr<PipelineLibrary>,
GetPipelineLibrary,
(),
(const, override));

MOCK_CONST_METHOD0(CreateCommandBuffer, std::shared_ptr<CommandBuffer>());
MOCK_METHOD(std::shared_ptr<CommandBuffer>,
CreateCommandBuffer,
(),
(const, override));

MOCK_CONST_METHOD0(GetCapabilities,
const std::shared_ptr<const Capabilities>&());
MOCK_METHOD(const std::shared_ptr<const Capabilities>&,
GetCapabilities,
(),
(const, override));
};

class MockTexture : public Texture {
public:
MockTexture(const TextureDescriptor& desc) : Texture(desc) {}
MOCK_METHOD1(SetLabel, void(std::string_view label));
MOCK_METHOD3(SetContents,
bool(const uint8_t* contents, size_t length, size_t slice));
MOCK_METHOD2(SetContents,
bool(std::shared_ptr<const fml::Mapping> mapping, size_t slice));
MOCK_CONST_METHOD0(IsValid, bool());
MOCK_CONST_METHOD0(GetSize, ISize());
MOCK_METHOD3(OnSetContents,
bool(const uint8_t* contents, size_t length, size_t slice));
MOCK_METHOD2(OnSetContents,
bool(std::shared_ptr<const fml::Mapping> mapping, size_t slice));
MOCK_METHOD(void, SetLabel, (std::string_view label), (override));
// MOCK_METHOD(bool, SetContents, (const uint8_t* contents, size_t length,
// size_t slice), (override)); MOCK_METHOD(bool, SetContents,
// (std::shared_ptr<const fml::Mapping> mapping, size_t slice), (override));
Copy link
Contributor Author

@dkwingsmt dkwingsmt Sep 1, 2023

Choose a reason for hiding this comment

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

Since this method is not virtual, and its mock is not used, this mock is removed.

MOCK_METHOD(bool, IsValid, (), (const, override));
MOCK_METHOD(ISize, GetSize, (), (const, override));
MOCK_METHOD(bool,
OnSetContents,
(const uint8_t* contents, size_t length, size_t slice),
(override));
MOCK_METHOD(bool,
OnSetContents,
(std::shared_ptr<const fml::Mapping> mapping, size_t slice),
(override));
};

} // namespace testing
Expand Down
21 changes: 12 additions & 9 deletions lib/ui/painting/image_encoding_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ fml::AutoResetWaitableEvent message_latch;

class MockDlImage : public DlImage {
public:
MOCK_CONST_METHOD0(skia_image, sk_sp<SkImage>());
MOCK_CONST_METHOD0(impeller_texture, std::shared_ptr<impeller::Texture>());
MOCK_CONST_METHOD0(isOpaque, bool());
MOCK_CONST_METHOD0(isTextureBacked, bool());
MOCK_CONST_METHOD0(isUIThreadSafe, bool());
MOCK_CONST_METHOD0(dimensions, SkISize());
MOCK_CONST_METHOD0(GetApproximateByteSize, size_t());
MOCK_METHOD(sk_sp<SkImage>, skia_image, (), (const, override));
MOCK_METHOD(std::shared_ptr<impeller::Texture>,
impeller_texture,
(),
(const, override));
MOCK_METHOD(bool, isOpaque, (), (const, override));
MOCK_METHOD(bool, isTextureBacked, (), (const, override));
MOCK_METHOD(bool, isUIThreadSafe, (), (const, override));
MOCK_METHOD(SkISize, dimensions, (), (const, override));
MOCK_METHOD(size_t, GetApproximateByteSize, (), (const, override));
};

} // namespace
Expand All @@ -57,8 +60,8 @@ class MockSyncSwitch {
std::function<void()> false_handler = [] {};
};

MOCK_CONST_METHOD1(Execute, void(const Handlers& handlers));
MOCK_METHOD1(SetSwitch, void(bool value));
MOCK_METHOD(void, Execute, (const Handlers& handlers), (const));
MOCK_METHOD(void, SetSwitch, (bool value));
};

TEST_F(ShellTest, EncodeImageGivesExternalTypedData) {
Expand Down
Loading