Audio plugin host https://kx.studio/carla
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.

141 lines
3.4KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #include "CarlaUtils.hpp"
  18. int main()
  19. {
  20. // misc functions
  21. bool2str(false);
  22. bool2str(true);
  23. pass();
  24. // string print functions, handled in Print
  25. // carla_*sleep
  26. carla_sleep(1);
  27. carla_msleep(1);
  28. // carla_setenv
  29. carla_setenv("THIS", "THAT");
  30. // carla_setprocname
  31. carla_setprocname("test-proc");
  32. // carla_strdup
  33. const char* const str1 = carla_strdup("string1");
  34. const char* const strF = carla_strdup_free(strdup("stringFree"));
  35. delete[] str1;
  36. delete[] strF;
  37. {
  38. struct TestStruct {
  39. const char* str1;
  40. const char* str2;
  41. const char* str3;
  42. const char* str4;
  43. TestStruct()
  44. : str1(carla_strdup("str1")),
  45. str2(carla_strdup("str2")),
  46. str3(nullptr),
  47. str4(carla_strdup("str4")) {}
  48. ~TestStruct()
  49. {
  50. if (str1 != nullptr)
  51. {
  52. delete[] str1;
  53. str1 = nullptr;
  54. }
  55. if (str2 != nullptr)
  56. {
  57. delete[] str2;
  58. str2 = nullptr;
  59. }
  60. if (str3 != nullptr)
  61. {
  62. delete[] str3;
  63. str3 = nullptr;
  64. }
  65. if (str4 != nullptr)
  66. {
  67. delete[] str4;
  68. str4 = nullptr;
  69. }
  70. }
  71. };
  72. TestStruct a, b, c;
  73. }
  74. // math functions
  75. carla_min<int32_t>(0, -5, 8);
  76. carla_fixValue<float>(0.0f, 1.0f, 1.1f);
  77. {
  78. int v1 = 6;
  79. int v2 = 8;
  80. const int v3 = 9;
  81. assert(v1 == 6 && v2 == 8 && v3 == 9);
  82. carla_copy<int>(&v1, &v2, 1);
  83. assert(v1 == 8 && v2 == 8 && v3 == 9);
  84. carla_copy<int>(&v2, &v3, 1);
  85. assert(v1 == 8 && v2 == 9 && v3 == 9);
  86. }
  87. {
  88. float data1[500];
  89. float data2[500];
  90. float data0[500];
  91. float data3[500];
  92. carla_zeroFloat(data0, 500);
  93. carla_fill<float>(data1, 500, 6.41f);
  94. carla_copy<float>(data2, data1, 500);
  95. carla_copyFloat(data3, data2, 500);
  96. carla_zeroMem(data2, sizeof(float)*500);
  97. for (int i=0; i < 500; ++i)
  98. {
  99. assert(data0[i] == 0.0f);
  100. assert(data1[i] == 6.41f);
  101. assert(data2[i] == 0.0f);
  102. assert(data3[i] == 6.41f);
  103. }
  104. }
  105. {
  106. struct MyStruct {
  107. char pad[100];
  108. int i;
  109. double d;
  110. intptr_t ptr;
  111. };
  112. MyStruct a, b, c, d;
  113. carla_zeroStruct<MyStruct>(a);
  114. carla_zeroStruct<MyStruct>(b);
  115. carla_zeroStruct<MyStruct>(c);
  116. carla_zeroStruct<MyStruct>(d);
  117. }
  118. return 0;
  119. }