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.

unit-tests_MidiMessage.cpp 2.3KB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "unit-tests.h"
  2. #include <src/midi_Message.h>
  3. BEGIN_MIDI_NAMESPACE
  4. // Declare references:
  5. // http://stackoverflow.com/questions/4891067/weird-undefined-symbols-of-static-constants-inside-a-struct-class
  6. template<unsigned Size>
  7. const unsigned Message<Size>::sSysExMaxSize;
  8. END_MIDI_NAMESPACE
  9. // -----------------------------------------------------------------------------
  10. BEGIN_UNNAMED_NAMESPACE
  11. TEST(MidiMessage, hasTheRightProperties)
  12. {
  13. typedef midi::Message<42> Message;
  14. const Message message = Message();
  15. EXPECT_EQ(message.channel, 0);
  16. EXPECT_EQ(message.type, 0);
  17. EXPECT_EQ(message.data1, 0);
  18. EXPECT_EQ(message.data2, 0);
  19. EXPECT_EQ(message.valid, false);
  20. EXPECT_EQ(message.getSysExSize(), unsigned(0));
  21. }
  22. template<typename Message>
  23. inline void setSysExSize(Message& ioMessage, unsigned inSize)
  24. {
  25. ioMessage.data2 = inSize >> 8; // MSB
  26. ioMessage.data1 = inSize & 0xff; // LSB
  27. }
  28. TEST(MidiMessage, getSysExSize)
  29. {
  30. // Small message
  31. {
  32. typedef midi::Message<32> Message;
  33. ASSERT_EQ(Message::sSysExMaxSize, unsigned(32));
  34. Message message = Message();
  35. const unsigned sizeUnder = 20;
  36. setSysExSize(message, sizeUnder);
  37. ASSERT_EQ(message.getSysExSize(), sizeUnder);
  38. const unsigned sizeOver = 64;
  39. setSysExSize(message, sizeOver);
  40. ASSERT_EQ(message.getSysExSize(), unsigned(32));
  41. }
  42. // Medium message
  43. {
  44. typedef midi::Message<256> Message;
  45. ASSERT_EQ(Message::sSysExMaxSize, unsigned(256));
  46. Message message = Message();
  47. const unsigned sizeUnder = 200;
  48. setSysExSize(message, sizeUnder);
  49. ASSERT_EQ(message.getSysExSize(), sizeUnder);
  50. const unsigned sizeOver = 300;
  51. setSysExSize(message, sizeOver);
  52. ASSERT_EQ(message.getSysExSize(), unsigned(256));
  53. }
  54. // Large message
  55. {
  56. typedef midi::Message<1024> Message;
  57. ASSERT_EQ(Message::sSysExMaxSize, unsigned(1024));
  58. Message message = Message();
  59. const unsigned sizeUnder = 1000;
  60. setSysExSize(message, sizeUnder);
  61. ASSERT_EQ(message.getSysExSize(), sizeUnder);
  62. const unsigned sizeOver = 2000;
  63. setSysExSize(message, sizeOver);
  64. ASSERT_EQ(message.getSysExSize(), unsigned(1024));
  65. }
  66. }
  67. END_UNNAMED_NAMESPACE