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.

76 lines
2.7KB

  1. #include "unit-tests.h"
  2. #include <src/midi_UsbDefs.h>
  3. BEGIN_MIDI_NAMESPACE
  4. END_MIDI_NAMESPACE
  5. // -----------------------------------------------------------------------------
  6. BEGIN_UNNAMED_NAMESPACE
  7. TEST(MidiUsb, codeIndexNumberSizes)
  8. {
  9. typedef midi::CodeIndexNumbers CIN;
  10. EXPECT_EQ(CIN::getSize(CIN::reserved), 0);
  11. EXPECT_EQ(CIN::getSize(CIN::misc), 0);
  12. EXPECT_EQ(CIN::getSize(CIN::cableEvent), 0);
  13. EXPECT_EQ(CIN::getSize(CIN::systemCommon2Bytes), 2);
  14. EXPECT_EQ(CIN::getSize(CIN::systemCommon3Bytes), 3);
  15. EXPECT_EQ(CIN::getSize(CIN::sysExStart), 3);
  16. EXPECT_EQ(CIN::getSize(CIN::sysExContinue), 3);
  17. EXPECT_EQ(CIN::getSize(CIN::systemCommon1Byte), 1);
  18. EXPECT_EQ(CIN::getSize(CIN::sysExEnds1Byte), 1);
  19. EXPECT_EQ(CIN::getSize(CIN::sysExEnds2Bytes), 2);
  20. EXPECT_EQ(CIN::getSize(CIN::sysExEnds3Bytes), 3);
  21. EXPECT_EQ(CIN::getSize(CIN::noteOff), 3);
  22. EXPECT_EQ(CIN::getSize(CIN::noteOn), 3);
  23. EXPECT_EQ(CIN::getSize(CIN::polyPressure), 3);
  24. EXPECT_EQ(CIN::getSize(CIN::controlChange), 3);
  25. EXPECT_EQ(CIN::getSize(CIN::programChange), 2);
  26. EXPECT_EQ(CIN::getSize(CIN::channelPressure), 2);
  27. EXPECT_EQ(CIN::getSize(CIN::pitchBend), 3);
  28. EXPECT_EQ(CIN::getSize(CIN::singleByte), 1);
  29. }
  30. TEST(MidiUsb, UsbMidiEventPacket)
  31. {
  32. midi::UsbMidiEventPacket packet;
  33. EXPECT_EQ(packet.mData[0], 0);
  34. EXPECT_EQ(packet.mData[1], 0);
  35. EXPECT_EQ(packet.mData[2], 0);
  36. EXPECT_EQ(packet.mData[3], 0);
  37. EXPECT_EQ(packet.getCableNumber(), 0);
  38. EXPECT_EQ(packet.getCodeIndexNumber(), 0);
  39. packet.setHeader(12, 7);
  40. EXPECT_EQ(packet.mData[0], 0xc7);
  41. EXPECT_EQ(packet.getCableNumber(), 12);
  42. EXPECT_EQ(packet.getCodeIndexNumber(), 7);
  43. const byte midiData[3] = { 12, 42, 47 };
  44. packet.setMidiData(midiData);
  45. EXPECT_EQ(packet.mData[0], 0xc7);
  46. EXPECT_EQ(packet.mData[1], 12);
  47. EXPECT_EQ(packet.mData[2], 42);
  48. EXPECT_EQ(packet.mData[3], 47);
  49. const byte fullData[4] = { 12, 34, 56, 78 };
  50. packet = fullData;
  51. EXPECT_EQ(packet.mData[0], 12);
  52. EXPECT_EQ(packet.mData[1], 34);
  53. EXPECT_EQ(packet.mData[2], 56);
  54. EXPECT_EQ(packet.mData[3], 78);
  55. const byte* midiDataConst = packet.getMidiData();
  56. EXPECT_EQ(midiDataConst[0], 34);
  57. EXPECT_EQ(midiDataConst[1], 56);
  58. EXPECT_EQ(midiDataConst[2], 78);
  59. byte* midiDataMutable = packet.getMidiData();
  60. EXPECT_EQ(midiDataMutable[0], 34);
  61. EXPECT_EQ(midiDataMutable[1], 56);
  62. EXPECT_EQ(midiDataMutable[2], 78);
  63. }
  64. END_UNNAMED_NAMESPACE