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.

140 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaUtils.hpp"
  18. struct MyStruct {
  19. char pad[100];
  20. int i;
  21. double d;
  22. intptr_t ptr;
  23. };
  24. int main()
  25. {
  26. // misc functions
  27. bool2str(false);
  28. bool2str(true);
  29. pass();
  30. // string print functions, handled in Print
  31. // carla_*sleep
  32. carla_sleep(1);
  33. carla_msleep(1);
  34. // carla_setenv
  35. carla_setenv("THIS", "THAT");
  36. assert(std::strcmp(getenv("THIS"), "THAT") == 0);
  37. // carla_strdup
  38. const char* const str1 = carla_strdup("string1");
  39. const char* const strF = carla_strdup_free(strdup("stringFree"));
  40. delete[] str1;
  41. delete[] strF;
  42. {
  43. struct TestStruct {
  44. const char* str1;
  45. const char* str2;
  46. const char* str3;
  47. const char* str4;
  48. TestStruct()
  49. : str1(carla_strdup("str1")),
  50. str2(carla_strdup("str2")),
  51. str3(nullptr),
  52. str4(carla_strdup("str4")) {}
  53. ~TestStruct()
  54. {
  55. if (str1 != nullptr)
  56. {
  57. delete[] str1;
  58. str1 = nullptr;
  59. }
  60. if (str2 != nullptr)
  61. {
  62. delete[] str2;
  63. str2 = nullptr;
  64. }
  65. if (str3 != nullptr)
  66. {
  67. delete[] str3;
  68. str3 = nullptr;
  69. }
  70. if (str4 != nullptr)
  71. {
  72. delete[] str4;
  73. str4 = nullptr;
  74. }
  75. }
  76. };
  77. TestStruct a, b, c;
  78. }
  79. // math functions
  80. carla_min<int32_t>(0, -5, 8);
  81. carla_fixValue<float>(0.0f, 1.0f, 1.1f);
  82. {
  83. int v1 = 6;
  84. int v2 = 8;
  85. const int v3 = 9;
  86. assert(v1 == 6 && v2 == 8 && v3 == 9);
  87. carla_copy<int>(&v1, &v2, 1);
  88. assert(v1 == 8 && v2 == 8 && v3 == 9);
  89. carla_copy<int>(&v2, &v3, 1);
  90. assert(v1 == 8 && v2 == 9 && v3 == 9);
  91. }
  92. {
  93. float data1[500];
  94. float data2[500];
  95. float data0[500];
  96. float data3[500];
  97. carla_zeroFloat(data0, 500);
  98. carla_fill<float>(data1, 500, 6.41f);
  99. carla_copy<float>(data2, data1, 500);
  100. carla_copyFloat(data3, data2, 500);
  101. carla_zeroMem(data2, sizeof(float)*500);
  102. for (int i=0; i < 500; ++i)
  103. {
  104. assert(data0[i] == 0.0f);
  105. assert(data1[i] == 6.41f);
  106. assert(data2[i] == 0.0f);
  107. assert(data3[i] == 6.41f);
  108. }
  109. }
  110. {
  111. MyStruct a, b, c, d;
  112. carla_zeroStruct<MyStruct>(a);
  113. carla_zeroStruct<MyStruct>(b);
  114. carla_zeroStruct<MyStruct>(c);
  115. carla_zeroStruct<MyStruct>(d);
  116. }
  117. return 0;
  118. }