Greetings,
A week long collaboration between me and Gpt yielded this functioning mock of a sample UEFI Protocol:
struct SampleProtocol {
INTN (*GetVersion)(
);
};
struct MockSampleProtocol : public SampleProtocol {
static MockSampleProtocol *instance;
MockSampleProtocol (
)
{
// Assign the instance pointer
instance = this;
// Point the function pointer in TestStruct to the static method
GetVersion = StaticGetVersion;
}
// Define a static method that forwards the call to the mock method
static INTN
StaticGetVersion (
)
{
return instance->MockGetVersion ();
}
MOCK_METHOD (INTN, MockGetVersion, ());
};
MockSampleProtocol *MockSampleProtocol::instance = nullptr;
TEST (SampleProtocolTest, SampleTest) {
MockSampleProtocol mockSampleProtocol;
SampleProtocol *sampleProtocol;
sampleProtocol = &mockSampleProtocol;
EXPECT_CALL (mockSampleProtocol, MockGetVersion)
.WillOnce (Return (42));
ASSERT_EQ (42, sampleProtocol->GetVersion ());
}
In your opinion, is this an appropriate approach?
I suppose that mocking a UEFI protocol is something common, so I wonder if this would be worth documenting?
Best Regards,
Me & Gpt
_._,_._,_
Groups.io Links:
You receive all messages sent to this group.
View/Reply Online (#109013) |
|
Mute This Topic
| New Topic
Your Subscription |
Contact Group Owner |
Unsubscribe
[rebecca@openfw.io]
_._,_._,_