diff options
Diffstat (limited to 'devices/uart/sys_io.hh')
-rw-r--r-- | devices/uart/sys_io.hh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/devices/uart/sys_io.hh b/devices/uart/sys_io.hh new file mode 100644 index 0000000..142c9c1 --- /dev/null +++ b/devices/uart/sys_io.hh @@ -0,0 +1,34 @@ +#pragma once + +#include <gmock/gmock.h> + +class IPort { +public: + virtual unsigned char inb(unsigned short) const = 0; + virtual void outb(unsigned char, unsigned short) const = 0; +}; + +class MockPort : public IPort { +public: + MOCK_METHOD(unsigned char, inb, (unsigned short), (const, override)); + MOCK_METHOD(void, outb, (unsigned char, unsigned short), (const, override)); +}; + +static std::unique_ptr<MockPort> mockPort; + +// mock free functions +extern "C" { +unsigned char +inb(unsigned short v) +{ + EXPECT_TRUE(mockPort) << "MockPort was not set up by the test fixture"; + return mockPort->inb(v); +} + +void +outb(unsigned char p, unsigned short v) +{ + EXPECT_TRUE(mockPort) << "MockPort was not set up by the test fixture"; + return mockPort->outb(p, v); +} +} |