Skip to content

Commit

Permalink
Revert "Remove deprecated MOCK_METHODx calls (#45307)"
Browse files Browse the repository at this point in the history
This reverts commit 81ed971.
  • Loading branch information
dkwingsmt authored Sep 4, 2023
1 parent 90fec63 commit 2d39e99
Show file tree
Hide file tree
Showing 33 changed files with 624 additions and 973 deletions.
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_METHOD(fml::Milliseconds, GetFrameBudget, (), (const, override));
MOCK_CONST_METHOD0(GetFrameBudget, fml::Milliseconds());
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

} // namespace testing
Expand Down
178 changes: 69 additions & 109 deletions impeller/renderer/testing/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,151 +17,111 @@ 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, SetLabel, (const std::string& label), (override));
MOCK_METHOD1(SetLabel, bool(const std::string& label));

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

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

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

class MockAllocator : public Allocator {
public:
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));
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));
};

class MockBlitPass : public BlitPass {
public:
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));
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));
};

class MockCommandBuffer : public CommandBuffer {
public:
MockCommandBuffer(std::weak_ptr<const Context> context)
: CommandBuffer(context) {}
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));
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));
};

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

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

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

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

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

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

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

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

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

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

class MockTexture : public Texture {
public:
MockTexture(const TextureDescriptor& desc) : Texture(desc) {}
MOCK_METHOD(void, SetLabel, (std::string_view label), (override));
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));
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));
};

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

class MockDlImage : public DlImage {
public:
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));
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());
};

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

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

TEST_F(ShellTest, EncodeImageGivesExternalTypedData) {
Expand Down
Loading

0 comments on commit 2d39e99

Please sign in to comment.