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.

142 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_usleep(1);
  29. // carla_setenv
  30. carla_setenv("THIS", "THAT");
  31. // carla_setprocname
  32. carla_setprocname("test-proc");
  33. // carla_strdup
  34. const char* const str1 = carla_strdup("string1");
  35. const char* const strF = carla_strdup_free(strdup("stringFree"));
  36. delete[] str1;
  37. delete[] strF;
  38. {
  39. struct TestStruct {
  40. const char* str1;
  41. const char* str2;
  42. const char* str3;
  43. const char* str4;
  44. TestStruct()
  45. : str1(carla_strdup("str1")),
  46. str2(carla_strdup("str2")),
  47. str3(nullptr),
  48. str4(carla_strdup("str4")) {}
  49. ~TestStruct()
  50. {
  51. if (str1 != nullptr)
  52. {
  53. delete[] str1;
  54. str1 = nullptr;
  55. }
  56. if (str2 != nullptr)
  57. {
  58. delete[] str2;
  59. str2 = nullptr;
  60. }
  61. if (str3 != nullptr)
  62. {
  63. delete[] str3;
  64. str3 = nullptr;
  65. }
  66. if (str4 != nullptr)
  67. {
  68. delete[] str4;
  69. str4 = nullptr;
  70. }
  71. }
  72. };
  73. TestStruct a, b, c;
  74. }
  75. // math functions
  76. carla_min<int32_t>(0, -5, 8);
  77. carla_fixValue<float>(0.0f, 1.0f, 1.1f);
  78. {
  79. int v1 = 6;
  80. int v2 = 8;
  81. const int v3 = 9;
  82. assert(v1 == 6 && v2 == 8 && v3 == 9);
  83. carla_copy<int>(&v1, &v2, 1);
  84. assert(v1 == 8 && v2 == 8 && v3 == 9);
  85. carla_copy<int>(&v2, &v3, 1);
  86. assert(v1 == 8 && v2 == 9 && v3 == 9);
  87. }
  88. {
  89. float data1[500];
  90. float data2[500];
  91. float data0[500];
  92. float data3[500];
  93. carla_zeroFloat(data0, 500);
  94. carla_fill<float>(data1, 500, 6.41f);
  95. carla_copy<float>(data2, data1, 500);
  96. carla_copyFloat(data3, data2, 500);
  97. carla_zeroMem(data2, sizeof(float)*500);
  98. for (int i=0; i < 500; ++i)
  99. {
  100. assert(data0[i] == 0.0f);
  101. assert(data1[i] == 6.41f);
  102. assert(data2[i] == 0.0f);
  103. assert(data3[i] == 6.41f);
  104. }
  105. }
  106. {
  107. struct MyStruct {
  108. char pad[100];
  109. int i;
  110. double d;
  111. intptr_t ptr;
  112. };
  113. MyStruct a, b, c, d;
  114. carla_zeroStruct<MyStruct>(a);
  115. carla_zeroStruct<MyStruct>(b);
  116. carla_zeroStruct<MyStruct>(c);
  117. carla_zeroStruct<MyStruct>(d);
  118. }
  119. return 0;
  120. }