template <typename Derived, typename Protocol>
class MockProtocolBase
Defined at line 44 of file ../../zircon/kernel/lib/efi/testing/include/lib/efi/testing/mock_protocol_base.h
Base class to help wrap EFI protocols in gmock classes.
This does a few nice things that we would otherwise have to repeat in each mock:
1. Provides a protocol() function to access the raw EFI protocol.
2. Provides a mechanism to bounce the C function into the C++ mock class
Example usage:
==============
// Given this EFI protocol:
typedef struct efi_foo_protocol {
efi_status (*Foo)(struct efi_foo_protocol* self, char foo) EFIAPI;
efi_status (*Bar)(struct efi_foo_protocol* self, uint32_t* bar) EFIAPI;
} efi_foo_protocol;
// Defining the mock looks like this:
// 1. Use CRTP to make a MockProtocolBase sub-class.
class MockFooProtocol : public MockProtocolBase
<MockFooProtocol
, efi_foo_protocol> {
public:
// 2. In the constructor, use Bounce
<
> to set up each protocol function.
MockFooProtocol() : MockProtocolBase(
{.Foo = Bounce
<
&MockFooProtocol
::Foo>,
.Bar = Bounce
<
&MockFooProtocol
::Bar>}) {}
// 3. Wrap the protocol functions in MOCK_METHOD(), omitting the |self| param.
MOCK_METHOD(efi_status, Foo, (char foo));
MOCK_METHOD(efi_status, Bar, (uint32_t* bar));
};
==============
Protected Members
Wrapper wrapper_
Public Methods
void MockProtocolBase<Derived, Protocol> (const Protocol & protocol)
Defined at line 46 of file ../../zircon/kernel/lib/efi/testing/include/lib/efi/testing/mock_protocol_base.h
void ~MockProtocolBase<Derived, Protocol> ()
Defined at line 49 of file ../../zircon/kernel/lib/efi/testing/include/lib/efi/testing/mock_protocol_base.h
Protocol * protocol ()
Defined at line 51 of file ../../zircon/kernel/lib/efi/testing/include/lib/efi/testing/mock_protocol_base.h
Protected Methods
template <auto Method, typename... Args>
efi_status Bounce (Protocol * self, Args... args)
Bounces the EFI C function pointer into the mock function..
Defined at line 65 of file ../../zircon/kernel/lib/efi/testing/include/lib/efi/testing/mock_protocol_base.h