PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

124 Zeilen
3.3KB

  1. #include <ArduinoUnit.h>
  2. #include <OSCBundle.h>
  3. #include "TestPrint.h"
  4. #define HAS_DOUBLE sizeof(double) == 8
  5. test(bundle_address){
  6. OSCBundle bundle;
  7. bundle.add("/address").add(1);
  8. assertEqual(bundle.size(), 1);
  9. OSCMessage msg = bundle.getOSCMessage("/address");
  10. assertTrue(msg.isInt(0));
  11. assertEqual(msg.getInt(0), 1);
  12. }
  13. test(bundle_message_position){
  14. OSCBundle bundle;
  15. bundle.add("/one").add(1);
  16. bundle.add("/two").add(2);
  17. assertEqual(bundle.size(), 2);
  18. OSCMessage msg0 = bundle.getOSCMessage(0);
  19. assertTrue(msg0.isInt(0));
  20. assertEqual(msg0.getInt(0), 1);
  21. OSCMessage msg1 = bundle.getOSCMessage(1);
  22. assertTrue(msg1.isInt(0));
  23. assertEqual(msg1.getInt(0), 2);
  24. }
  25. test(bundle_add_message){
  26. OSCMessage msg("/msg");
  27. OSCBundle bundle;
  28. bundle.add(msg).add(1);
  29. assertEqual(bundle.size(), 1);
  30. OSCMessage test_msg = bundle.getOSCMessage(0);
  31. assertTrue(test_msg.isInt(0));
  32. assertEqual(test_msg.getInt(0), 1);
  33. }
  34. void routeA(OSCMessage & msg, int offset){
  35. assertTrue(msg.isInt(0));
  36. assertEqual(msg.getInt(0), 1);
  37. }
  38. void routeB(OSCMessage & msg, int offset){
  39. assertTrue(msg.isInt(0));
  40. assertEqual(msg.getInt(0), 2);
  41. }
  42. test(bundle_route){
  43. OSCMessage msg("/msg");
  44. OSCBundle bundle;
  45. bundle.add("/a").add(1);
  46. bundle.add("/b/1").add(2);
  47. assertEqual(bundle.size(), 2);
  48. assertTrue(bundle.route("/a", routeA));
  49. assertTrue(bundle.route("/b", routeB));
  50. }
  51. void dispatchA(OSCMessage & msg){
  52. assertTrue(msg.isInt(0));
  53. assertEqual(msg.getInt(0), 1);
  54. }
  55. void dispatchB(OSCMessage & msg){
  56. assertTrue(msg.isInt(0));
  57. assertEqual(msg.getInt(0), 2);
  58. }
  59. test(bundle_dispatch){
  60. OSCMessage msg("/msg");
  61. OSCBundle bundle;
  62. bundle.add("/a").add(1);
  63. bundle.add("/b").add(2);
  64. assertEqual(bundle.size(), 2);
  65. assertTrue(bundle.route("/a", routeA));
  66. assertTrue(bundle.route("/b", routeB));
  67. }
  68. test(bundle_encode){
  69. TestPrint printer;
  70. //this is the desired output
  71. uint8_t testBuffer[] = {35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 47, 97, 0, 0, 44, 105, 0, 0, 0, 0, 0, 1, 0, 0, 0, 12, 47, 98, 0, 0, 44, 105, 0, 0, 0, 0, 0, 2};
  72. OSCBundle bundle;
  73. bundle.add("/a").add(1);
  74. bundle.add("/b").add(2);
  75. bundle.send(printer);
  76. assertEqual(printer.size(), sizeof(testBuffer));
  77. for (int i = 0; i < sizeof(testBuffer); i++){
  78. assertEqual(testBuffer[i], printer.at(i));
  79. }
  80. }
  81. test(bundle_decode){
  82. uint8_t testBuffer[] = {35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 47, 97, 0, 0, 44, 105, 0, 0, 0, 0, 0, 1, 0, 0, 0, 12, 47, 98, 0, 0, 44, 105, 0, 0, 0, 0, 0, 2};
  83. OSCBundle bundle;
  84. bundle.fill(testBuffer, sizeof(testBuffer));
  85. assertEqual(bundle.size(), 2);
  86. OSCMessage msgA = bundle.getOSCMessage("/a");
  87. assertTrue(msgA.isInt(0));
  88. assertEqual(msgA.getInt(0), 1);
  89. OSCMessage msgB = bundle.getOSCMessage("/b");
  90. assertTrue(msgB.isInt(0));
  91. assertEqual(msgB.getInt(0), 2);
  92. }
  93. test(bundle_decode_invalid){
  94. uint8_t testBuffer[] = {35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 47, 97, 0, 0, 44, 105, 0, 0, 0, 0, 0, 1, 0, 0, 0, 12, 47, 98, 0, 0, 44, 105, 0, 0, 0, 0, 2};
  95. OSCBundle bundle;
  96. bundle.fill(testBuffer, sizeof(testBuffer));
  97. assertTrue(bundle.hasError());
  98. }
  99. void setup()
  100. {
  101. Serial.begin(9600);
  102. while(!Serial); // for the Arduino Leonardo/Micro only
  103. }
  104. void loop()
  105. {
  106. Test::run();
  107. }