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.

65 lines
1.5KB

  1. #include "unit-tests.h"
  2. #include <test/mocks/test-mocks_SerialMock.h>
  3. BEGIN_UNNAMED_NAMESPACE
  4. USING_NAMESPACE_TEST_MOCKS
  5. using namespace testing;
  6. TEST(RingBuffer, initialState)
  7. {
  8. typedef RingBuffer<uint8, 32> Buffer;
  9. Buffer buffer;
  10. EXPECT_EQ(buffer.getLength(), 0);
  11. EXPECT_EQ(buffer.isEmpty(), true);
  12. buffer.clear();
  13. EXPECT_EQ(buffer.getLength(), 0);
  14. EXPECT_EQ(buffer.isEmpty(), true);
  15. }
  16. TEST(RingBuffer, uint8)
  17. {
  18. typedef RingBuffer<uint8, 8> Buffer;
  19. Buffer buffer;
  20. buffer.write(42);
  21. EXPECT_EQ(buffer.getLength(), 1);
  22. EXPECT_EQ(buffer.isEmpty(), false);
  23. const uint8 read = buffer.read();
  24. EXPECT_EQ(read, 42);
  25. EXPECT_EQ(buffer.getLength(), 0);
  26. EXPECT_EQ(buffer.isEmpty(), true);
  27. const uint8 data[] = "Hello, World!";
  28. buffer.write(data, 13);
  29. EXPECT_EQ(buffer.getLength(), 5); // 13 % 8
  30. EXPECT_EQ(buffer.isEmpty(), false);
  31. uint8 output[8] = { 0 };
  32. buffer.read(output, 8);
  33. const uint8 expected[8] = {
  34. 'o', 'r', 'l', 'd', '!', ',', ' ', 'W',
  35. };
  36. EXPECT_THAT(output, ContainerEq(expected));
  37. buffer.clear();
  38. EXPECT_EQ(buffer.getLength(), 0);
  39. EXPECT_EQ(buffer.isEmpty(), true);
  40. }
  41. TEST(RingBuffer, uint32)
  42. {
  43. typedef RingBuffer<uint32_t, 32> Buffer;
  44. Buffer buffer;
  45. buffer.write(42);
  46. EXPECT_EQ(buffer.getLength(), 1);
  47. EXPECT_EQ(buffer.isEmpty(), false);
  48. const uint8 read = buffer.read();
  49. EXPECT_EQ(read, 42);
  50. EXPECT_EQ(buffer.getLength(), 0);
  51. EXPECT_EQ(buffer.isEmpty(), true);
  52. }
  53. END_UNNAMED_NAMESPACE