aboutsummaryrefslogtreecommitdiff
path: root/devices/uart/sys_io.hh
blob: 142c9c1782b83cf6b1fc48e6d34c3b01280bcf5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
}
}