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.

839 lines
24KB

  1. /*
  2. * Carla Utility 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. #ifdef NDEBUG
  18. # error Build this file with debug ON please
  19. #endif
  20. #define HAVE_JUCE
  21. #define VESTIGE_HEADER
  22. #include "CarlaUtils.hpp"
  23. #include "CarlaMathUtils.hpp"
  24. #undef NULL
  25. #define NULL nullptr
  26. #include "CarlaBackendUtils.hpp"
  27. #include "CarlaEngineUtils.hpp"
  28. #include "CarlaLadspaUtils.hpp"
  29. #include "CarlaDssiUtils.hpp"
  30. #include "CarlaLv2Utils.hpp"
  31. #include "CarlaVstUtils.hpp"
  32. #include "CarlaBridgeUtils.hpp"
  33. #include "CarlaJuceUtils.hpp"
  34. #include "CarlaLibCounter.hpp"
  35. #include "CarlaOscUtils.hpp" // TODO
  36. #include "CarlaPatchbayUtils.hpp" // TODO
  37. // #include "CarlaPipeUtils.hpp"
  38. // #include "CarlaStateUtils.hpp"
  39. #include "CarlaShmUtils.hpp"
  40. // used in dssi utils
  41. #include "juce_core.h"
  42. #include <QtCore/QDir>
  43. #include <QtCore/QFileInfo>
  44. #include <QtCore/QStringList>
  45. #if 0
  46. // -----------------------------------------------------------------------
  47. static void test_CarlaUtils()
  48. {
  49. // -------------------------------------------------------------------
  50. // misc functions
  51. {
  52. bool2str(false);
  53. bool2str(true);
  54. pass();
  55. char strBuf[1];
  56. nullStrBuf(strBuf);
  57. }
  58. // -------------------------------------------------------------------
  59. // string print functions
  60. {
  61. carla_debug("DEBUG");
  62. carla_stdout("STDOUT %s", bool2str(true));
  63. carla_stderr("STDERR %s", bool2str(false));
  64. carla_stderr2("STDERR2 " P_UINT64, 0xffffffff); // 4294967295
  65. }
  66. // -------------------------------------------------------------------
  67. // carla_*sleep
  68. {
  69. //carla_sleep(1);
  70. //carla_msleep(1);
  71. }
  72. // -------------------------------------------------------------------
  73. // carla_setenv
  74. {
  75. carla_setenv("THIS", "THAT");
  76. assert(std::strcmp(std::getenv("THIS"), "THAT") == 0);
  77. }
  78. // -------------------------------------------------------------------
  79. // carla_strdup
  80. {
  81. // with variables
  82. const char* const str1(carla_strdup("string1"));
  83. const char* const strF(carla_strdup_free(strdup("string2")));
  84. delete[] str1;
  85. delete[] strF;
  86. // without variables
  87. delete[] carla_strdup("string3");
  88. delete[] carla_strdup_free(strdup("string4"));
  89. // common use case in Carla code
  90. struct TestStruct {
  91. const char* str1;
  92. const char* str2;
  93. const char* str3;
  94. const char* str4;
  95. TestStruct()
  96. : str1(carla_strdup("str1")),
  97. str2(carla_strdup("str2")),
  98. str3(nullptr),
  99. str4(carla_strdup("str4")) {}
  100. ~TestStruct() noexcept
  101. {
  102. if (str1 != nullptr)
  103. {
  104. delete[] str1;
  105. str1 = nullptr;
  106. }
  107. if (str2 != nullptr)
  108. {
  109. delete[] str2;
  110. str2 = nullptr;
  111. }
  112. if (str3 != nullptr)
  113. {
  114. delete[] str3;
  115. str3 = nullptr;
  116. }
  117. if (str4 != nullptr)
  118. {
  119. delete[] str4;
  120. str4 = nullptr;
  121. }
  122. }
  123. };
  124. TestStruct a, b, c;
  125. }
  126. // -------------------------------------------------------------------
  127. // memory functions
  128. {
  129. int a[] = { 4, 3, 2, 1 };
  130. int b[] = { 1, 2, 3, 4 };
  131. carla_add(a, b, 4);
  132. assert(a[0] == 5);
  133. assert(a[1] == 5);
  134. assert(a[2] == 5);
  135. assert(a[3] == 5);
  136. int c[] = { 4, 3, 2, 1 };
  137. carla_add(b, c, 4);
  138. assert(a[0] == b[0]);
  139. assert(a[1] == b[1]);
  140. assert(a[2] == b[2]);
  141. assert(a[3] == b[3]);
  142. carla_copy(a, c, 2);
  143. carla_copy(b+2, c+2, 2);
  144. assert(a[0] == c[0]);
  145. assert(a[1] == c[1]);
  146. assert(b[2] == c[2]);
  147. assert(b[3] == c[3]);
  148. carla_copy(c, a, 4);
  149. assert(a[0] == c[0]);
  150. assert(a[1] == c[1]);
  151. assert(a[2] == c[2]);
  152. assert(a[3] == c[3]);
  153. carla_fill(a, 0, 4);
  154. assert(a[0] == 0);
  155. assert(a[1] == 0);
  156. assert(a[2] == 0);
  157. assert(a[3] == 0);
  158. carla_fill(a, -11, 4);
  159. assert(a[0] == -11);
  160. assert(a[1] == -11);
  161. assert(a[2] == -11);
  162. assert(a[3] == -11);
  163. carla_fill(a+0, 17, 2);
  164. carla_fill(a+2, 23, 2);
  165. assert(a[0] == 17);
  166. assert(a[1] == 17);
  167. assert(a[2] == 23);
  168. assert(a[3] == 23);
  169. carla_zeroBytes(a, sizeof(int)*4);
  170. assert(a[0] == 0);
  171. assert(a[1] == 0);
  172. assert(a[2] == 0);
  173. assert(a[3] == 0);
  174. char strBuf[501];
  175. strBuf[0] = strBuf[499] = strBuf[500] = '!';
  176. carla_zeroChar(strBuf, 501);
  177. for (int i=0; i<501; ++i)
  178. assert(strBuf[i] == '\0');
  179. int d = 1527, e = 0;
  180. carla_add(&d, &d, 1);
  181. carla_add(&d, &e, 1);
  182. carla_add(&e, &d, 1);
  183. assert(d == 1527*2);
  184. assert(d == e);
  185. e = -e;
  186. carla_add(&d, &e, 1);
  187. assert(d == 0);
  188. carla_copy(&d, &e, 1);
  189. assert(d == -1527*2);
  190. assert(d == e);
  191. carla_fill(&d, 9999, 1);
  192. carla_fill(&e, 123, 1);
  193. assert(d == 9999);
  194. assert(e == 123);
  195. carla_zeroStruct(d);
  196. assert(d == 0);
  197. carla_copyStruct(d, e);
  198. assert(d != 0);
  199. assert(d == e);
  200. carla_fill(a+0, 1, 1);
  201. carla_fill(a+1, 2, 1);
  202. carla_fill(a+2, 3, 1);
  203. carla_fill(a+3, 4, 1);
  204. assert(a[0] == 1);
  205. assert(a[1] == 2);
  206. assert(a[2] == 3);
  207. assert(a[3] == 4);
  208. carla_copyStruct(c, a, 4);
  209. assert(c[0] == a[0]);
  210. assert(c[1] == a[1]);
  211. assert(c[2] == a[2]);
  212. assert(c[3] == a[3]);
  213. carla_zeroStruct(c, 4);
  214. assert(c[0] == 0);
  215. assert(c[1] == 0);
  216. assert(c[2] == 0);
  217. assert(c[3] == 0);
  218. float fl[5];
  219. carla_fill(fl, 1.11f, 5);
  220. assert(fl[0] == 1.11f);
  221. assert(fl[1] == 1.11f);
  222. assert(fl[2] == 1.11f);
  223. assert(fl[3] == 1.11f);
  224. assert(fl[4] == 1.11f);
  225. carla_add(fl, fl, 5);
  226. assert(fl[0] == 1.11f*2);
  227. assert(fl[1] == 1.11f*2);
  228. assert(fl[2] == 1.11f*2);
  229. assert(fl[3] == 1.11f*2);
  230. assert(fl[4] == 1.11f*2);
  231. carla_add(fl, fl, 4);
  232. assert(fl[0] == 1.11f*4);
  233. assert(fl[1] == 1.11f*4);
  234. assert(fl[2] == 1.11f*4);
  235. assert(fl[3] == 1.11f*4);
  236. assert(fl[4] == 1.11f*2);
  237. carla_add(fl, fl, 3);
  238. assert(fl[0] == 1.11f*8);
  239. assert(fl[1] == 1.11f*8);
  240. assert(fl[2] == 1.11f*8);
  241. assert(fl[3] == 1.11f*4);
  242. assert(fl[4] == 1.11f*2);
  243. carla_add(fl, fl, 2);
  244. assert(fl[0] == 1.11f*16);
  245. assert(fl[1] == 1.11f*16);
  246. assert(fl[2] == 1.11f*8);
  247. assert(fl[3] == 1.11f*4);
  248. assert(fl[4] == 1.11f*2);
  249. carla_add(fl, fl, 1);
  250. assert(fl[0] == 1.11f*32);
  251. assert(fl[1] == 1.11f*16);
  252. assert(fl[2] == 1.11f*8);
  253. assert(fl[3] == 1.11f*4);
  254. assert(fl[4] == 1.11f*2);
  255. }
  256. }
  257. // -----------------------------------------------------------------------
  258. static void test_CarlaMathUtils() noexcept
  259. {
  260. // -------------------------------------------------------------------
  261. // math functions (base)
  262. // Return the lower of 2 values, with 'min' as the minimum possible value.
  263. assert(carla_min(0, 0, 0) == 0);
  264. assert(carla_min(0, 3, 0) == 0);
  265. assert(carla_min(3, 0, 0) == 0);
  266. assert(carla_min(0, 0, 3) == 3);
  267. assert(carla_min(0, 1, 3) == 3);
  268. assert(carla_min(0, 2, 3) == 3);
  269. assert(carla_min(0, 3, 3) == 3);
  270. assert(carla_min(0, 4, 3) == 3);
  271. assert(carla_min(5, 0, 3) == 3);
  272. assert(carla_min(5, 1, 3) == 3);
  273. assert(carla_min(5, 2, 3) == 3);
  274. assert(carla_min(5, 3, 3) == 3);
  275. assert(carla_min(5, 4, 3) == 4);
  276. assert(carla_min(5, 5, 3) == 5);
  277. assert(carla_min(5, 6, 3) == 5);
  278. assert(carla_min(2, -2, 0) == 0);
  279. assert(carla_min(2, -1, 0) == 0);
  280. assert(carla_min(2, 0, 0) == 0);
  281. assert(carla_min(2, 1, 0) == 1);
  282. assert(carla_min(2, 2, 0) == 2);
  283. assert(carla_min(5, -6, 3) == 3);
  284. assert(carla_min(5, -5, 3) == 3);
  285. assert(carla_min(5, -4, 3) == 3);
  286. assert(carla_min(5, -3, 3) == 3);
  287. assert(carla_min(5, -2, 3) == 3);
  288. assert(carla_min(5, -1, 3) == 3);
  289. assert(carla_min(5, 0, 3) == 3);
  290. assert(carla_min(5, 1, 3) == 3);
  291. assert(carla_min(5, 2, 3) == 3);
  292. assert(carla_min(5, 3, 3) == 3);
  293. assert(carla_min(5, 4, 3) == 4);
  294. assert(carla_min(5, 5, 3) == 5);
  295. assert(carla_min(5, 6, 3) == 5);
  296. assert(carla_min(5, -6, -3) == -3);
  297. assert(carla_min(5, -5, -3) == -3);
  298. assert(carla_min(5, -4, -3) == -3);
  299. assert(carla_min(5, -3, -3) == -3);
  300. assert(carla_min(5, -2, -3) == -2);
  301. assert(carla_min(5, -1, -3) == -1);
  302. assert(carla_min(5, 0, -3) == 0);
  303. assert(carla_min(5, 1, -3) == 1);
  304. assert(carla_min(5, 2, -3) == 2);
  305. assert(carla_min(5, 3, -3) == 3);
  306. assert(carla_min(5, 4, -3) == 4);
  307. assert(carla_min(5, 5, -3) == 5);
  308. assert(carla_min(5, 6, -3) == 5);
  309. // Return the lower positive of 2 values.
  310. assert(carla_minPositive(0, 0) == 0);
  311. assert(carla_minPositive(0, 1) == 0);
  312. assert(carla_minPositive(0, 2) == 0);
  313. assert(carla_minPositive(0, 3) == 0);
  314. assert(carla_minPositive(1, 0) == 0);
  315. assert(carla_minPositive(1, 1) == 1);
  316. assert(carla_minPositive(1, 2) == 1);
  317. assert(carla_minPositive(1, 3) == 1);
  318. assert(carla_minPositive(3, 0) == 0);
  319. assert(carla_minPositive(3, 1) == 1);
  320. assert(carla_minPositive(3, 2) == 2);
  321. assert(carla_minPositive(3, 3) == 3);
  322. assert(carla_minPositive(-1, 0) == 0);
  323. assert(carla_minPositive(-1, 1) == 1);
  324. assert(carla_minPositive(-1, 2) == 2);
  325. assert(carla_minPositive(-1, 3) == 3);
  326. // Return the higher of 2 values, with 'max' as the maximum possible value.
  327. assert(carla_max(0, 0, 0) == 0);
  328. assert(carla_max(0, 3, 0) == 0);
  329. assert(carla_max(3, 0, 0) == 0);
  330. assert(carla_max(0, 0, 3) == 0);
  331. assert(carla_max(0, 1, 3) == 1);
  332. assert(carla_max(0, 2, 3) == 2);
  333. assert(carla_max(0, 3, 3) == 3);
  334. assert(carla_max(0, 4, 3) == 3);
  335. assert(carla_max(5, 0, 3) == 3);
  336. assert(carla_max(5, 1, 3) == 3);
  337. assert(carla_max(5, 2, 3) == 3);
  338. assert(carla_max(5, 3, 3) == 3);
  339. assert(carla_max(5, 4, 3) == 3);
  340. assert(carla_max(5, 5, 3) == 3);
  341. assert(carla_max(5, 6, 3) == 3);
  342. // Fix bounds of 'value' between 'min' and 'max'.
  343. assert(carla_fixValue(0, 1, -1) == 0);
  344. assert(carla_fixValue(0, 1, 0) == 0);
  345. assert(carla_fixValue(0, 1, 1) == 1);
  346. assert(carla_fixValue(0, 1, 2) == 1);
  347. assert(carla_fixValue(0.0, 1.0, -1.0) == 0.0);
  348. assert(carla_fixValue(0.0, 1.0, 0.0) == 0.0);
  349. assert(carla_fixValue(0.0, 1.0, 1.0) == 1.0);
  350. assert(carla_fixValue(0.0, 1.0, 2.0) == 1.0);
  351. assert(carla_fixValue(0.0, 1.0, -0.1) == 0.0);
  352. assert(carla_fixValue(0.0, 1.0, 1.1) == 1.0);
  353. // Get next power of 2.
  354. assert(carla_nextPowerOf2(0) == 0);
  355. assert(carla_nextPowerOf2(1) == 1);
  356. assert(carla_nextPowerOf2(2) == 2);
  357. assert(carla_nextPowerOf2(4) == 4);
  358. assert(carla_nextPowerOf2(5) == 8);
  359. assert(carla_nextPowerOf2(6) == 8);
  360. assert(carla_nextPowerOf2(7) == 8);
  361. assert(carla_nextPowerOf2(8) == 8);
  362. assert(carla_nextPowerOf2(9) == 16);
  363. uint32_t power = 1;
  364. assert((power = carla_nextPowerOf2(power+1)) == 2);
  365. assert((power = carla_nextPowerOf2(power+1)) == 4);
  366. assert((power = carla_nextPowerOf2(power+1)) == 8);
  367. assert((power = carla_nextPowerOf2(power+1)) == 16);
  368. assert((power = carla_nextPowerOf2(power+1)) == 32);
  369. assert((power = carla_nextPowerOf2(power+1)) == 64);
  370. assert((power = carla_nextPowerOf2(power+1)) == 128);
  371. assert((power = carla_nextPowerOf2(power+1)) == 256);
  372. assert((power = carla_nextPowerOf2(power+1)) == 512);
  373. assert((power = carla_nextPowerOf2(power+1)) == 1024);
  374. assert((power = carla_nextPowerOf2(power+1)) == 2048);
  375. assert((power = carla_nextPowerOf2(power+1)) == 4096);
  376. assert((power = carla_nextPowerOf2(power+1)) == 8192);
  377. assert((power = carla_nextPowerOf2(power+1)) == 16384);
  378. assert((power = carla_nextPowerOf2(power+1)) == 32768);
  379. assert((power = carla_nextPowerOf2(power+1)) == 65536);
  380. assert((power = carla_nextPowerOf2(power+1)) == 131072);
  381. // -------------------------------------------------------------------
  382. // math functions (extended)
  383. // carla_addFloat, carla_copyFloat & carla_zeroFloat tests skipped
  384. // mostly unused due to juce::FloatVectorOperations
  385. }
  386. // -----------------------------------------------------------------------
  387. static void test_CarlaBackendUtils() noexcept
  388. {
  389. CARLA_BACKEND_USE_NAMESPACE
  390. carla_stdout(PluginOption2Str(PLUGIN_OPTION_FIXED_BUFFERS));
  391. carla_stdout(BinaryType2Str(BINARY_NONE));
  392. carla_stdout(PluginType2Str(PLUGIN_NONE));
  393. carla_stdout(PluginCategory2Str(PLUGIN_CATEGORY_NONE));
  394. carla_stdout(ParameterType2Str(PARAMETER_UNKNOWN));
  395. carla_stdout(InternalParameterIndex2Str(PARAMETER_NULL));
  396. carla_stdout(EngineCallbackOpcode2Str(ENGINE_CALLBACK_DEBUG));
  397. carla_stdout(EngineOption2Str(ENGINE_OPTION_DEBUG));
  398. carla_stdout(EngineProcessMode2Str(ENGINE_PROCESS_MODE_SINGLE_CLIENT));
  399. carla_stdout(EngineTransportMode2Str(ENGINE_TRANSPORT_MODE_INTERNAL));
  400. carla_stdout(FileCallbackOpcode2Str(FILE_CALLBACK_DEBUG));
  401. carla_stdout(getPluginTypeAsString(PLUGIN_INTERNAL));
  402. carla_stdout(PatchbayIcon2Str(PATCHBAY_ICON_APPLICATION));
  403. getPluginTypeFromString("none");
  404. getPluginCategoryFromName("cat");
  405. }
  406. // -----------------------------------------------------------------------
  407. static void test_CarlaEngineUtils() noexcept
  408. {
  409. CARLA_BACKEND_USE_NAMESPACE
  410. carla_stdout(EngineType2Str(kEngineTypeNull));
  411. carla_stdout(EnginePortType2Str(kEnginePortTypeNull));
  412. carla_stdout(EngineEventType2Str(kEngineEventTypeNull));
  413. carla_stdout(EngineControlEventType2Str(kEngineControlEventTypeNull));
  414. }
  415. // -----------------------------------------------------------------------
  416. static void test_CarlaLadspaUtils()
  417. {
  418. LADSPA_Descriptor desc;
  419. carla_zeroStruct(desc);
  420. LADSPA_RDF_Descriptor rdfDesc;
  421. delete ladspa_rdf_dup(&rdfDesc);
  422. is_ladspa_port_good(0x0, 0x0);
  423. is_ladspa_rdf_descriptor_valid(&rdfDesc, &desc);
  424. get_default_ladspa_port_value(0x0, -1.0f, 1.0f);
  425. }
  426. // -----------------------------------------------------------------------
  427. namespace dssi_juce {
  428. const char* find_dssi_ui(const char* const filename, const char* const label) noexcept;
  429. #define HAVE_JUCE
  430. #include "CarlaDssiUtils.cpp"
  431. }
  432. namespace dssi_qt {
  433. const char* find_dssi_ui(const char* const filename, const char* const label) noexcept;
  434. #undef HAVE_JUCE
  435. #include "CarlaDssiUtils.cpp"
  436. }
  437. static void test_CarlaDssiUtils() noexcept
  438. {
  439. const char* const ui_juce = dssi_juce::find_dssi_ui("/usr/lib/dssi/trivial_sampler.so", "aa");
  440. const char* const ui_qt = dssi_qt::find_dssi_ui("/usr/lib/dssi/trivial_sampler.so", "aa");
  441. CARLA_SAFE_ASSERT(ui_juce != nullptr);
  442. CARLA_SAFE_ASSERT(ui_qt != nullptr);
  443. if (ui_juce != nullptr)
  444. {
  445. carla_stdout("%s", ui_juce);
  446. assert(std::strcmp(ui_juce, "/usr/lib/dssi/trivial_sampler/trivial_sampler_qt") == 0);
  447. delete[] ui_juce;
  448. }
  449. if (ui_qt != nullptr)
  450. {
  451. carla_stdout("%s", ui_qt);
  452. assert(std::strcmp(ui_qt, "/usr/lib/dssi/trivial_sampler/trivial_sampler_qt") == 0);
  453. delete[] ui_qt;
  454. }
  455. }
  456. // -----------------------------------------------------------------------
  457. static LV2_URID test_lv2_uridMap(LV2_URID_Map_Handle, const char*)
  458. {
  459. return 1;
  460. }
  461. static void test_CarlaLv2Utils()
  462. {
  463. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  464. lv2World.initIfNeeded();
  465. // getPlugin
  466. const LilvPlugin* const plugin(lv2World.getPlugin("urn:juced:DrumSynth"));
  467. CARLA_SAFE_ASSERT(plugin != nullptr);
  468. // getState
  469. LV2_URID_Map uridMap = { nullptr, test_lv2_uridMap };
  470. LilvState* const state(lv2World.getState("http://arcticanaudio.com/plugins/thefunction#preset001", &uridMap));
  471. CARLA_SAFE_ASSERT(state != nullptr);
  472. if (state != nullptr) lilv_state_free(state);
  473. // load a bunch of plugins to stress test lilv
  474. delete lv2_rdf_new("http://arcticanaudio.com/plugins/thefunction", true);
  475. delete lv2_rdf_new("http://kunz.corrupt.ch/products/tal-noisemaker", true);
  476. delete lv2_rdf_new("http://calf.sourceforge.net/plugins/Reverb", true);
  477. delete lv2_rdf_new("http://www.openavproductions.com/fabla", true);
  478. delete lv2_rdf_new("http://invadarecords.com/plugins/lv2/meter", true);
  479. delete lv2_rdf_new("http://gareus.org/oss/lv2/meters#spectr30stereo", true);
  480. delete lv2_rdf_new("http://plugin.org.uk/swh-plugins/revdelay", true);
  481. delete lv2_rdf_new("http://lv2plug.in/plugins/eg-scope#Stereo", true);
  482. delete lv2_rdf_new("http://kxstudio.sf.net/carla/plugins/carlarack", true);
  483. delete lv2_rdf_new("http://guitarix.sourceforge.net/plugins/gxautowah#autowah", true);
  484. delete lv2_rdf_new("http://github.com/blablack/ams-lv2/mixer_4ch", true);
  485. delete lv2_rdf_new("http://drumgizmo.org/lv2", true);
  486. delete lv2_rdf_new("http://synthv1.sourceforge.net/lv2", true);
  487. delete lv2_rdf_new("urn:juced:DrumSynth", true);
  488. // misc
  489. is_lv2_port_supported(0x0);
  490. is_lv2_feature_supported("test1");
  491. is_lv2_ui_feature_supported("test2");
  492. }
  493. // -----------------------------------------------------------------------
  494. static intptr_t test_vst_dispatcher(AEffect*, int, int, intptr_t, void*, float)
  495. {
  496. return 0;
  497. }
  498. static void test_CarlaVstUtils() noexcept
  499. {
  500. AEffect effect;
  501. carla_zeroStruct(effect);
  502. effect.dispatcher = test_vst_dispatcher;
  503. vstPluginCanDo(&effect, "test");
  504. carla_stdout(vstEffectOpcode2str(effOpen));
  505. carla_stdout(vstMasterOpcode2str(audioMasterAutomate));
  506. }
  507. // -----------------------------------------------------------------------
  508. static void test_CarlaBridgeUtils() noexcept
  509. {
  510. carla_stdout(PluginBridgeInfoType2str(kPluginBridgePong));
  511. carla_stdout(PluginBridgeOpcode2str(kPluginBridgeOpcodeNull));
  512. }
  513. #endif
  514. // -----------------------------------------------------------------------
  515. class LeakTestClass
  516. {
  517. public:
  518. LeakTestClass()noexcept
  519. : i(0) {}
  520. private:
  521. int i;
  522. CARLA_LEAK_DETECTOR(LeakTestClass)
  523. };
  524. static void test_CarlaJuceUtils()
  525. {
  526. LeakTestClass a, b;
  527. LeakTestClass* e;
  528. LeakTestClass* f = nullptr;
  529. e = new LeakTestClass;
  530. f = new LeakTestClass;
  531. delete e; delete f;
  532. delete new LeakTestClass;
  533. int x = 1;
  534. {
  535. assert(x == 1);
  536. ScopedValueSetter<int> s(x, 2);
  537. assert(x == 2);
  538. }
  539. assert(x == 1);
  540. {
  541. assert(x == 1);
  542. ScopedValueSetter<int> s(x, 3, 4);
  543. assert(x == 3);
  544. }
  545. assert(x == 4);
  546. }
  547. #if 0
  548. // -----------------------------------------------------------------------
  549. static void test_CarlaLibUtils() noexcept
  550. {
  551. void* const libNot = lib_open("/libzzzzz...");
  552. assert(libNot == nullptr);
  553. carla_stdout("Force lib_open fail error results in: %s", lib_error("/libzzzzz..."));
  554. void* const lib = lib_open("/usr/lib/liblo.so");
  555. CARLA_SAFE_ASSERT_RETURN(lib != nullptr,);
  556. void* const libS = lib_symbol(lib, "lo_server_new");
  557. CARLA_SAFE_ASSERT(libS != nullptr);
  558. const bool closed = lib_close(lib);
  559. CARLA_SAFE_ASSERT(closed);
  560. LibCounter lc;
  561. void* const test1 = lc.open("/usr/lib/liblo.so");
  562. void* const test2 = lc.open("/usr/lib/liblo.so");
  563. void* const test3 = lc.open("/usr/lib/liblo.so");
  564. assert(test1 == test2);
  565. assert(test2 == test3);
  566. lc.close(test1); lc.close(test2); lc.close(test3);
  567. // test if the pointer changes after all closed
  568. void* const test1b = lc.open("/usr/lib/liblo.so");
  569. assert(test1 != test1b);
  570. lc.close(test1b);
  571. // test non-delete flag
  572. void* const test4 = lc.open("/usr/lib/liblrdf.so.0", false);
  573. lc.close(test4);
  574. void* const test5 = lc.open("/usr/lib/liblrdf.so.0");
  575. assert(test4 == test5);
  576. lc.close(test5);
  577. // open non-delete a few times, tests for cleanup on destruction
  578. lc.open("/usr/lib/liblrdf.so.0");
  579. lc.open("/usr/lib/liblrdf.so.0");
  580. lc.open("/usr/lib/liblrdf.so.0");
  581. }
  582. // -----------------------------------------------------------------------
  583. struct ShmStruct {
  584. char stringStart[255];
  585. bool boolean;
  586. int integer;
  587. float floating;
  588. char stringEnd[255];
  589. };
  590. static void test_CarlaShmUtils() noexcept
  591. {
  592. shm_t shm, shma;
  593. ShmStruct* shmStruct1;
  594. ShmStruct* shmStruct2;
  595. // base tests first
  596. carla_shm_init(shm);
  597. assert(! carla_is_shm_valid(shm));
  598. shm = carla_shm_create("/carla-shm-test1");
  599. carla_stdout("test %i", shm);
  600. assert(carla_is_shm_valid(shm));
  601. carla_shm_close(shm);
  602. assert(! carla_is_shm_valid(shm));
  603. shm = carla_shm_create("/carla-shm-test1");
  604. assert(carla_is_shm_valid(shm));
  605. shma = carla_shm_attach("/carla-shm-test1");
  606. assert(carla_is_shm_valid(shma));
  607. carla_shm_close(shm);
  608. carla_shm_close(shma);
  609. assert(! carla_is_shm_valid(shm));
  610. assert(! carla_is_shm_valid(shma));
  611. // test attach invalid
  612. shma = carla_shm_attach("/carla-shm-test-NOT");
  613. assert(! carla_is_shm_valid(shma));
  614. // test memory, start
  615. shm = carla_shm_create("/carla-shm-test1");
  616. assert(carla_is_shm_valid(shm));
  617. shma = carla_shm_attach("/carla-shm-test1");
  618. assert(carla_is_shm_valid(shma));
  619. // test memory, check valid
  620. shmStruct1 = carla_shm_map<ShmStruct>(shm);
  621. assert(shmStruct1 != nullptr);
  622. shmStruct2 = carla_shm_map<ShmStruct>(shma);
  623. assert(shmStruct2 != nullptr);
  624. carla_shm_unmap(shma, shmStruct2);
  625. assert(shmStruct2 == nullptr);
  626. carla_shm_unmap(shm, shmStruct1);
  627. assert(shmStruct1 == nullptr);
  628. // test memory, check if write data matches
  629. shmStruct1 = carla_shm_map<ShmStruct>(shm);
  630. assert(shmStruct1 != nullptr);
  631. shmStruct2 = carla_shm_map<ShmStruct>(shma);
  632. assert(shmStruct2 != nullptr);
  633. carla_zeroStruct(*shmStruct1);
  634. assert(shmStruct1->stringStart[0] == '\0');
  635. assert(shmStruct2->stringStart[0] == '\0');
  636. assert(shmStruct1->stringEnd[0] == '\0');
  637. assert(shmStruct2->stringEnd[0] == '\0');
  638. assert(! shmStruct1->boolean);
  639. assert(! shmStruct2->boolean);
  640. shmStruct1->boolean = true;
  641. shmStruct1->integer = 232312;
  642. assert(shmStruct1->boolean == shmStruct2->boolean);
  643. assert(shmStruct1->integer == shmStruct2->integer);
  644. shmStruct2->floating = 2342.231f;
  645. std::strcpy(shmStruct2->stringStart, "test1start");
  646. std::strcpy(shmStruct2->stringEnd, "test2end");
  647. assert(shmStruct1->floating == shmStruct2->floating);
  648. assert(std::strcmp(shmStruct1->stringStart, "test1start") == 0);
  649. assert(std::strcmp(shmStruct1->stringStart, shmStruct2->stringStart) == 0);
  650. assert(std::strcmp(shmStruct1->stringEnd, "test2end") == 0);
  651. assert(std::strcmp(shmStruct1->stringEnd, shmStruct2->stringEnd) == 0);
  652. carla_shm_unmap(shma, shmStruct2);
  653. assert(shmStruct2 == nullptr);
  654. carla_shm_unmap(shm, shmStruct1);
  655. assert(shmStruct1 == nullptr);
  656. // test memory, done
  657. carla_shm_close(shm);
  658. carla_shm_close(shma);
  659. assert(! carla_is_shm_valid(shm));
  660. assert(! carla_is_shm_valid(shma));
  661. }
  662. #endif
  663. // -----------------------------------------------------------------------
  664. // main
  665. int main()
  666. {
  667. #if 0
  668. // already tested, skip for now
  669. test_CarlaUtils();
  670. test_CarlaMathUtils();
  671. test_CarlaBackendUtils();
  672. test_CarlaEngineUtils();
  673. test_CarlaLadspaUtils();
  674. test_CarlaDssiUtils();
  675. test_CarlaLv2Utils();
  676. test_CarlaVstUtils();
  677. #endif
  678. //test_CarlaBridgeUtils();
  679. //test_CarlaLibUtils();
  680. test_CarlaJuceUtils();
  681. //test_CarlaShmUtils();
  682. return 0;
  683. }
  684. // -----------------------------------------------------------------------