Skip to content

Instantly share code, notes, and snippets.

@kammce
Created December 8, 2020 15:22
Show Gist options
  • Save kammce/f86af0e8a6f521d816d51bdd8396275d to your computer and use it in GitHub Desktop.
Save kammce/f86af0e8a6f521d816d51bdd8396275d to your computer and use it in GitHub Desktop.
Partial implementation of a mock peripheral for SJSU. This was used in test to verify if using a hand written mock was faster than FakeIt (24 seconds for small test). It was, but only by 1s.
namespace sjsu
{
/// Mock Gpio for usage in testing
class MockGpio : public sjsu::Gpio
{
public:
// Return values
std::deque<bool> read_;
std::deque<std::variant<Direction, State, std::pair<InterruptCallback, Edge>>>
captures_;
void Reset()
{
read_.clear();
captures_.clear();
}
void ModuleInitialize() override {}
void ModuleEnable(bool = true) override {}
void SetDirection(Direction dir) override
{
captures_.push_back(dir);
}
void Set(State state) override
{
captures_.push_back(state);
}
void Toggle() override {}
bool Read() override
{
return PopAndReturn(read_);
}
sjsu::Pin & GetPin() override
{
return GetInactive<sjsu::Pin>();
}
void AttachInterrupt(InterruptCallback callback, Edge edge) override
{
captures_.push_back(std::make_pair(callback, edge));
}
void DetachInterrupt() override {}
};
} // namespace sjsu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment