PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.0KB

  1. #pragma once
  2. #include "test-mocks.h"
  3. #include <inttypes.h>
  4. BEGIN_TEST_MOCKS_NAMESPACE
  5. template<typename DataType, int Size>
  6. class RingBuffer
  7. {
  8. public:
  9. RingBuffer();
  10. ~RingBuffer();
  11. public:
  12. int getLength() const;
  13. bool isEmpty() const;
  14. public:
  15. void write(DataType inData);
  16. void write(const DataType* inData, int inSize);
  17. void clear();
  18. public:
  19. DataType peek() const;
  20. DataType read();
  21. void read(DataType* outData, int inSize);
  22. private:
  23. DataType mData[Size];
  24. DataType* mWriteHead;
  25. DataType* mReadHead;
  26. };
  27. template<int BufferSize>
  28. class SerialMock
  29. {
  30. public:
  31. SerialMock();
  32. ~SerialMock();
  33. public: // Arduino Serial API
  34. void begin(int inBaudrate);
  35. int available() const;
  36. void write(uint8_t inData);
  37. uint8_t read();
  38. public: // Test Helpers API
  39. void moveTxToRx(); // Simulate loopback
  40. public:
  41. typedef RingBuffer<uint8_t, BufferSize> Buffer;
  42. Buffer mTxBuffer;
  43. Buffer mRxBuffer;
  44. int mBaudrate;
  45. };
  46. END_TEST_MOCKS_NAMESPACE
  47. #include "test-mocks_SerialMock.hpp"