Greetings,
I have successfully mocked standalone functions employing the FunctionMockLib macros.
Nonetheless, I have been stuck in making progress regarding mocking a protocol.
The problem is that the function pointers of the protocol mock structure are not being properly initialized.
Below I try to illustrate with a made up UEFI protocol.
This is the test I want to mock:
// function that uses my mocked function
INTN getCount() {
// successfully mocked: CounterProtocol = mockCounterProtocol;
gBS->LocateProtocol(&gCounterProtocol, (VOID **)&CounterProtocol);
return CounterProtocol->Count();
}
// gTest file
TEST(getCountTest, returnCount) {
MockUefiBootServicesTable mockBootServices;
MockCounterProtocol mockCounterProtocol;
// expect_call on locate_protocol, where I assign &mockCounterProtocol with the custom action macro, ACTION_P
EXPECT_CALL (mockCounterProtocol, Count).WillOnce (Return (42));
getCount(); // seg fault, gdb shows CounterProtocol->Count points to NULL
}
My first attempt employed FunctionMockLib:
// header file
struct MockCounterProtocol {
MOCK_INTERFACE_DECLARATION(MockCounterProtocol);
MOCK_FUNCTION_DECLARTION(INTN, Count, ());
}
// source file
MOCK_INTERFACE_DEFINITION (MockCounterProtocol)
MOCK_FUNCTION_DEFINITION (MockCounterProtocol, Count, 0, EFIAPI)
You receive all messages sent to this group.
View/Reply Online (#108649) |
|
Mute This Topic
| New Topic
Your Subscription |
Contact Group Owner |
Unsubscribe
[rebecca@openfw.io]