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.

OSCData_test.ino 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <ArduinoUnit.h>
  2. #include <OSCData.h>
  3. #define HAS_DOUBLE sizeof(double) == 8
  4. test(data_int){
  5. int i = 1;
  6. OSCData datum(i);
  7. assertEqual(datum.getInt(), i);
  8. assertEqual(datum.type, 'i');
  9. }
  10. test(data_float){
  11. float f = 1.1;
  12. OSCData datum(f);
  13. assertEqual(datum.getFloat(), f);
  14. assertEqual(datum.type, 'f');
  15. }
  16. test(data_string){
  17. char * testStr = "data";
  18. int testStrLen = strlen(testStr) + 1;
  19. OSCData datum(testStr);
  20. char str[testStrLen];
  21. datum.getString(str, testStrLen);
  22. assertEqual(strcmp(str, testStr), 0);
  23. assertEqual(datum.type, 's');
  24. }
  25. test(data_string_partial_copy){
  26. char * testStr = "data";
  27. int testStrLen = strlen(testStr) + 1;
  28. OSCData datum(testStr);
  29. char str[testStrLen];
  30. assertEqual(datum.getString(str, 2), 2);
  31. assertEqual(strncmp(str, testStr, 2), 0);
  32. }
  33. test(data_bool){
  34. bool f = false;
  35. OSCData datum(f);
  36. assertFalse(datum.getBoolean());
  37. }
  38. test(has_double){
  39. assertEqual(sizeof(double), 8);
  40. }
  41. test(data_double){
  42. if (HAS_DOUBLE){
  43. double d = 1.1;
  44. OSCData datum = OSCData(d);
  45. assertEqual(datum.getDouble(), d);
  46. assertEqual(datum.type, 'd');
  47. }
  48. }
  49. test(data_blob){
  50. uint8_t b[] = {0, 1, 2, 3};
  51. OSCData datum(b, 4);
  52. uint8_t blob[4];
  53. datum.getBlob(blob, 4);
  54. for (int i = 0; i < 4; i++){
  55. assertEqual(blob[i], b[i]);
  56. }
  57. assertEqual(datum.type, 'b');
  58. }
  59. test(data_blob_partial_copy){
  60. uint8_t b[] = {0, 1, 2, 3};
  61. OSCData datum(b, 4);
  62. uint8_t blob[4];
  63. assertEqual(datum.getBlob(blob, 2), 2);
  64. for (int i = 0; i < 2; i++){
  65. assertEqual(blob[i], b[i]);
  66. }
  67. }
  68. test(data_copy){
  69. OSCData datum = OSCData(1);
  70. OSCData cpy(datum);
  71. assertEqual(cpy.getInt(), 1);
  72. assertEqual(cpy.type, 'i');
  73. }
  74. void setup()
  75. {
  76. Serial.begin(9600);
  77. while(!Serial); // for the Arduino Leonardo/Micro only
  78. }
  79. void loop()
  80. {
  81. Test::run();
  82. }