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.

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