From: "CrossedCarpet" <crossedcarpet@hotmail.com>
To: CrossedCarpet <crossedcarpet@hotmail.com>,devel@edk2.groups.io
Subject: Re: [edk2-devel] Problems mocking UEFI Protocol in gMock
Date: Fri, 22 Sep 2023 08:04:09 -0700 [thread overview]
Message-ID: <10445.1695395049741883261@groups.io> (raw)
In-Reply-To: <aQ2j.1694704934840190739.mlnl@groups.io>
[-- Attachment #1: Type: text/plain, Size: 1571 bytes --]
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 w ould be worth documenting?
Best Regards,
Me & Gpt
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109013): https://edk2.groups.io/g/devel/message/109013
Mute This Topic: https://groups.io/mt/101360319/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
[-- Attachment #2: Type: text/html, Size: 5776 bytes --]
next prev parent reply other threads:[~2023-09-22 15:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 15:22 [edk2-devel] Problems mocking UEFI Protocol in gMock CrossedCarpet
2023-09-22 15:04 ` CrossedCarpet [this message]
2023-09-29 16:47 ` CrossedCarpet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10445.1695395049741883261@groups.io \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox