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.

192 lines
4.8KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013-2014 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 "../backend/engine/CarlaEngineInternal.hpp"
  18. #include "CarlaPlugin.hpp"
  19. #include "CarlaHost.h"
  20. #include "CarlaUtils.hpp"
  21. // -----------------------------------------------------------------------
  22. CARLA_BACKEND_START_NAMESPACE
  23. class CarlaEngineDummy : public CarlaEngine
  24. {
  25. public:
  26. CarlaEngineDummy()
  27. : CarlaEngine(),
  28. fIsRunning(false)
  29. {
  30. }
  31. bool init(const char* const clientName) override
  32. {
  33. fIsRunning = true;
  34. pData->bufferSize = 512;
  35. pData->sampleRate = 44100.0;
  36. return CarlaEngine::init(clientName);
  37. }
  38. bool close() override
  39. {
  40. fIsRunning = false;
  41. return CarlaEngine::close();
  42. }
  43. bool isRunning() const noexcept override
  44. {
  45. return fIsRunning;
  46. }
  47. bool isOffline() const noexcept override
  48. {
  49. return false;
  50. }
  51. EngineType getType() const noexcept override
  52. {
  53. return kEngineTypePlugin;
  54. }
  55. const char* getCurrentDriverName() const noexcept override
  56. {
  57. return "Dummy";
  58. }
  59. private:
  60. bool fIsRunning;
  61. };
  62. CARLA_BACKEND_END_NAMESPACE
  63. // -----------------------------------------------------------------------
  64. CARLA_BACKEND_USE_NAMESPACE
  65. #define TEST_NAME "TestName"
  66. void testEngine(CarlaEngine* const eng)
  67. {
  68. assert(eng->getMaxClientNameSize() != 0);
  69. assert(eng->getMaxPortNameSize() != 0);
  70. assert(eng->getCurrentPluginCount() == 0);
  71. assert(eng->getMaxPluginNumber() == 0);
  72. assert(! eng->isRunning());
  73. assert(eng->getPlugin(0) == nullptr);
  74. const char* name1 = eng->getUniquePluginName(TEST_NAME);
  75. const char* name2 = eng->getUniquePluginName(TEST_NAME);
  76. const char* name3 = eng->getUniquePluginName(TEST_NAME);
  77. assert(name1 != nullptr);
  78. assert(name2 != nullptr);
  79. assert(name3 != nullptr);
  80. assert(std::strcmp(name1, TEST_NAME) == 0);
  81. assert(std::strcmp(name2, TEST_NAME) == 0);
  82. assert(std::strcmp(name3, TEST_NAME) == 0);
  83. delete[] name1;
  84. delete[] name2;
  85. delete[] name3;
  86. eng->init("test");
  87. assert(eng->getCurrentPluginCount() == 0);
  88. assert(eng->getMaxPluginNumber() != 0);
  89. assert(eng->isRunning());
  90. assert(eng->getPlugin(0) == nullptr);
  91. name1 = eng->getUniquePluginName(TEST_NAME);
  92. name2 = eng->getUniquePluginName(TEST_NAME);
  93. name3 = eng->getUniquePluginName(TEST_NAME);
  94. assert(name1 != nullptr);
  95. assert(name2 != nullptr);
  96. assert(name3 != nullptr);
  97. assert(std::strcmp(name1, TEST_NAME) == 0);
  98. assert(std::strcmp(name2, TEST_NAME) == 0);
  99. assert(std::strcmp(name3, TEST_NAME) == 0);
  100. delete[] name1;
  101. delete[] name2;
  102. delete[] name3;
  103. eng->close();
  104. // test quick init & close 3 times
  105. eng->init("test1");
  106. eng->close();
  107. eng->init("test2");
  108. eng->close();
  109. eng->init("test3");
  110. eng->close();
  111. // leave it open
  112. eng->init("test");
  113. // add as much plugins as possible
  114. for (;;)
  115. {
  116. if (! eng->addPlugin(PLUGIN_INTERNAL, nullptr, TEST_NAME, "bypass"))
  117. break;
  118. }
  119. assert(eng->getCurrentPluginCount() != 0);
  120. assert(eng->getCurrentPluginCount() == eng->getMaxPluginNumber());
  121. assert(eng->getCurrentPluginCount() == MAX_DEFAULT_PLUGINS);
  122. eng->close();
  123. }
  124. int main()
  125. {
  126. assert(CarlaEngine::getDriverCount() != 0);
  127. #if 0
  128. for (uint i=0, count=CarlaEngine::getDriverCount(); i < count && i < 4; ++i)
  129. {
  130. if (i == 1 || i == 2) continue;
  131. carla_stdout("driver %i/%i: %s", i+1, count, CarlaEngine::getDriverName(i));
  132. if (const char* const* const devNames = CarlaEngine::getDriverDeviceNames(i))
  133. {
  134. for (uint j=0; devNames[j] != nullptr; ++j)
  135. {
  136. CarlaEngine::getDriverDeviceInfo(i, devNames[j]);
  137. }
  138. }
  139. }
  140. #endif
  141. assert(CarlaPlugin::getNativePluginCount() != 0);
  142. for (size_t i=0, count=CarlaPlugin::getNativePluginCount(); i < count; ++i)
  143. {
  144. assert(CarlaPlugin::getNativePluginDescriptor(i) != nullptr);
  145. }
  146. CarlaEngineDummy e;
  147. testEngine(&e);
  148. // if (CarlaEngine* const eng = CarlaEngine::newDriverByName("PulseAudio"))
  149. // {
  150. // testEngine(eng);
  151. // delete eng;
  152. // }
  153. return 0;
  154. }