OSCMessage_match_test.ino 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <ArduinoUnit.h>
  2. #include <OSCMessage.h>
  3. test(message_address_match){
  4. OSCMessage msg("/a/0");
  5. assertEqual(msg.match("/a"), 2);
  6. assertEqual(msg.match("/a/0"), 4);
  7. }
  8. test(message_address_match_offset){
  9. OSCMessage msg("/a/0");
  10. assertEqual(msg.match("/0", 2), 2);
  11. assertEqual(msg.match("/1", 2), 0);
  12. }
  13. test(message_address_match_range){
  14. OSCMessage msg("/[a-z]/0");
  15. assertEqual(msg.match("/a"), 6);
  16. assertEqual(msg.match("/b/0"), 8);
  17. }
  18. test(message_address_match_or){
  19. OSCMessage msg("/{a,b}/0");
  20. assertEqual(msg.match("/a/0"), 8);
  21. assertEqual(msg.match("/b/0"), 8);
  22. assertEqual(msg.match("/c/0"), 0);
  23. }
  24. test(message_address_match_char){
  25. OSCMessage msg("/a/?");
  26. assertEqual(msg.match("/a/0"), 4);
  27. assertEqual(msg.match("/a/1"), 4);
  28. assertEqual(msg.match("/a/10"), 0);
  29. }
  30. test(message_address_match_star){
  31. OSCMessage msg("/a/*");
  32. assertEqual(msg.match("/a/0"), 4);
  33. assertEqual(msg.match("/a/10"), 4);
  34. assertEqual(msg.match("/a/100"), 4);
  35. }
  36. test(message_address_fullMatch){
  37. OSCMessage msg("/a/0");
  38. assertTrue(msg.fullMatch("/a/0"));
  39. assertFalse(msg.fullMatch("/a/1"));
  40. assertTrue(msg.fullMatch("/0", 2));
  41. }
  42. void dispatchMsg(OSCMessage &m){
  43. assertTrue(m.isInt(0));
  44. assertEqual(m.getInt(0), 1);
  45. }
  46. test(message_address_dispatch){
  47. OSCMessage msg("/a/[0-9]");
  48. msg.add(1);
  49. assertTrue(msg.dispatch("/a/0", dispatchMsg));
  50. assertTrue(msg.dispatch("/1", dispatchMsg, 2));
  51. }
  52. void routeMsg(OSCMessage &m, int offset){
  53. assertTrue(m.isInt(0));
  54. assertEqual(m.getInt(0), 2);
  55. assertEqual(offset, 2);
  56. }
  57. test(message_address_route){
  58. OSCMessage msg("/?/[0-9]");
  59. msg.add(2);
  60. assertTrue(msg.route("/a", routeMsg));
  61. assertTrue(msg.route("/b", routeMsg));
  62. }
  63. void setup()
  64. {
  65. Serial.begin(9600);
  66. while(!Serial); // for the Arduino Leonardo/Micro only
  67. }
  68. void loop()
  69. {
  70. Test::run();
  71. }