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.

660 lines
19KB

  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. #undef NDEBUG
  18. #undef DEBUG
  19. #define DEBUG 1
  20. #define RING_BUFFER_SIZE 48
  21. // 0 - base
  22. // 1 - utils
  23. // 2 - engine
  24. // 3 - plugin
  25. // 4 - standalone
  26. #define ANSI_TEST_N 0
  27. #if ANSI_TEST_N == 0
  28. // utils
  29. #include "CarlaUtils.hpp"
  30. // Carla Backend API
  31. #include "CarlaBackend.hpp"
  32. #endif
  33. #if ANSI_TEST_N == 1
  34. // includes
  35. #include "CarlaDefines.hpp"
  36. #include "CarlaMIDI.h"
  37. #include "ladspa_rdf.hpp"
  38. #include "lv2_rdf.hpp"
  39. // Carla Backend API
  40. #include "CarlaBackend.hpp"
  41. // Carla utils (part 1/4)
  42. #include "CarlaUtils.hpp"
  43. #include "CarlaJuceUtils.hpp"
  44. // Carla utils (part 2/4)
  45. #include "CarlaMutex.hpp"
  46. #include "CarlaRingBuffer.hpp"
  47. #include "CarlaString.hpp"
  48. #include "RtList.hpp"
  49. // Carla utils (part 3/4)
  50. #include "CarlaBackendUtils.hpp"
  51. #include "CarlaBridgeUtils.hpp"
  52. #include "CarlaLadspaUtils.hpp"
  53. #include "CarlaLibUtils.hpp"
  54. #include "CarlaLv2Utils.hpp"
  55. #include "CarlaOscUtils.hpp"
  56. #include "CarlaShmUtils.hpp"
  57. #include "CarlaStateUtils.hpp"
  58. #include "CarlaVstUtils.hpp"
  59. // Carla utils (part 4/4)
  60. #include "Lv2AtomQueue.hpp"
  61. // Carla Native Plugin API
  62. #include "CarlaNative.h"
  63. // Carla Native Plugin API (C++)
  64. #include "CarlaNative.hpp"
  65. // Carla Plugin API
  66. #include "CarlaPlugin.hpp"
  67. // Carla Engine API
  68. #include "CarlaEngine.hpp"
  69. // Carla Host API
  70. #include "CarlaHost.hpp"
  71. // ANSI_TEST_N == 1
  72. #endif
  73. #if ANSI_TEST_N == 2
  74. // Carla Engine
  75. #include "engine/CarlaEngineThread.hpp"
  76. #endif
  77. #if ANSI_TEST_N == 3
  78. // Carla Plugin
  79. #include "plugin/CarlaPluginThread.hpp"
  80. #include "plugin/CarlaPluginInternal.hpp"
  81. #endif
  82. #if ANSI_TEST_N == 4
  83. // Carla Host Standalone
  84. #include "CarlaHost.hpp"
  85. #include "CarlaUtils.hpp"
  86. #endif
  87. #if ANSI_TEST_N == 1
  88. // -----------------------------------------------------------------------
  89. namespace CB = CarlaBackend;
  90. using juce::ScopedPointer;
  91. int safe_assert_return_test(bool test)
  92. {
  93. CARLA_SAFE_ASSERT_RETURN(test, 1);
  94. return 0;
  95. }
  96. #endif
  97. // -----------------------------------------------------------------------
  98. int main()
  99. {
  100. #if ANSI_TEST_N == 0
  101. CARLA_BACKEND_USE_NAMESPACE
  102. BinaryType b;
  103. CallbackType c;
  104. CARLA_ASSERT(sizeof(b) == sizeof(BinaryType));
  105. CARLA_ASSERT(sizeof(b) == sizeof(int));
  106. CARLA_ASSERT(sizeof(BinaryType) == sizeof(int));
  107. CARLA_ASSERT(sizeof(c) == sizeof(CallbackType));
  108. CARLA_ASSERT(sizeof(c) == sizeof(int));
  109. CARLA_ASSERT(sizeof(CallbackType) == sizeof(int));
  110. #endif
  111. #if ANSI_TEST_N == 1
  112. // ladspa rdf
  113. {
  114. LADSPA_RDF_ScalePoint a;
  115. LADSPA_RDF_Port b;
  116. LADSPA_RDF_Descriptor c;
  117. }
  118. // lv2 rdf
  119. {
  120. LV2_RDF_PortMidiMap a;
  121. LV2_RDF_PortPoints b;
  122. LV2_RDF_PortUnit c;
  123. LV2_RDF_PortScalePoint d;
  124. LV2_RDF_Port e;
  125. LV2_RDF_Preset f;
  126. LV2_RDF_Feature g;
  127. LV2_RDF_UI h;
  128. LV2_RDF_Descriptor i;
  129. }
  130. // Carla Backend API
  131. {
  132. CB::BinaryType a = CB::BINARY_NONE;
  133. CB::PluginType b = CB::PLUGIN_NONE;
  134. CB::PluginCategory c = CB::PLUGIN_CATEGORY_NONE;
  135. CB::ParameterType d = CB::PARAMETER_UNKNOWN;
  136. CB::InternalParametersIndex e = CB::PARAMETER_NULL;
  137. CB::PatchbayIconType f = CB::PATCHBAY_ICON_APPLICATION;
  138. CB::OptionsType g = CB::OPTION_PROCESS_NAME;
  139. CB::CallbackType h = CB::CALLBACK_DEBUG;
  140. CB::ProcessMode i = CB::PROCESS_MODE_SINGLE_CLIENT;
  141. CB::TransportMode j = CB::TRANSPORT_MODE_INTERNAL;
  142. CB::CallbackFunc k = nullptr;
  143. CB::ParameterData l;
  144. CB::ParameterRanges m;
  145. CB::MidiProgramData n;
  146. CB::CustomData o;
  147. a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;
  148. }
  149. // Carla Native Plugin API
  150. {
  151. HostHandle a = nullptr;
  152. PluginHandle b = nullptr;
  153. PluginCategory c = PLUGIN_CATEGORY_NONE;
  154. PluginHints d = static_cast<PluginHints>(0x0);
  155. PluginSupports e = static_cast<PluginSupports>(0x0);
  156. ParameterHints f = static_cast<ParameterHints>(0x0);
  157. PluginDispatcherOpcode g = PLUGIN_OPCODE_NULL;
  158. HostDispatcherOpcode h = HOST_OPCODE_NULL;
  159. ParameterScalePoint i;
  160. ParameterRanges j;
  161. Parameter k;
  162. MidiEvent l;
  163. MidiProgram m;
  164. TimeInfoBBT n;
  165. TimeInfo o;
  166. HostDescriptor p;
  167. PluginDescriptor q = { c, d, e,
  168. 0, 0, 0, 0, 0, 0,
  169. nullptr, nullptr, nullptr, nullptr,
  170. nullptr, nullptr,
  171. nullptr, nullptr, nullptr, nullptr,
  172. nullptr, nullptr,
  173. nullptr, nullptr, nullptr,
  174. nullptr, nullptr,
  175. nullptr, nullptr, nullptr,
  176. nullptr, nullptr, nullptr,
  177. nullptr, nullptr,
  178. nullptr };
  179. a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;p=p;
  180. (void)q;
  181. }
  182. // Carla common utils
  183. {
  184. bool2str(true);
  185. pass();
  186. carla_debug("DEBUG");
  187. carla_stdout("OUT");
  188. carla_stderr("ERR");
  189. carla_stderr2("ERR2");
  190. carla_sleep(1);
  191. carla_msleep(1);
  192. carla_setenv("x", "y");
  193. carla_setprocname("ANSI-Test");
  194. assert(safe_assert_return_test(true) == 0);
  195. assert(safe_assert_return_test(false) == 1);
  196. // carla_strdup
  197. {
  198. const char* s1 = carla_strdup("s1");
  199. const char* s2 = carla_strdup_free(strdup("s2"));
  200. delete[] s1;
  201. delete[] s2;
  202. }
  203. // carla_min
  204. {
  205. assert(carla_min<int>( 1, 2, -1) == 1);
  206. assert(carla_min<int>( 1, 2, 0) == 1);
  207. assert(carla_min<int>( 1, 2, 1) == 1);
  208. assert(carla_min<int>( 1, 2, 2) == 2);
  209. assert(carla_min<int>( 1, 2, 3) == 3);
  210. assert(carla_min<int>( 2, 2, -1) == 2);
  211. assert(carla_min<int>( 1, 2, -1) == 1);
  212. assert(carla_min<int>( 0, 2, -1) == 0);
  213. assert(carla_min<int>(-1, 2, -1) == -1);
  214. assert(carla_min<int>(-2, 2, -1) == -1);
  215. assert(carla_min<int>(-1, 2, 0) == 0);
  216. assert(carla_min<int>(-1, 1, 0) == 0);
  217. assert(carla_min<int>(-1, 0, 0) == 0);
  218. assert(carla_min<int>(-1, -1, 0) == 0);
  219. assert(carla_min<int>(-1, -2, 0) == 0);
  220. unsigned u1 = static_cast<unsigned>(-1);
  221. unsigned u2 = static_cast<unsigned>(-2);
  222. assert(carla_min<unsigned>(u1, u2, 0) == u2);
  223. assert(carla_min<unsigned>(u1, u2, u1) == u1);
  224. assert(carla_min<unsigned>(u1, u2, u2) == u2);
  225. assert(carla_min<unsigned>(u1, 2, 0) == 2);
  226. assert(carla_min<unsigned>( 2, u1, 0) == 2);
  227. assert(carla_min<unsigned>( 2, 2, u1) == u1);
  228. }
  229. // carla_max (same as min)
  230. {
  231. assert(carla_max<int>( 1, 2, -1) == -1);
  232. assert(carla_max<int>( 1, 2, 0) == 0);
  233. assert(carla_max<int>( 1, 2, 1) == 1);
  234. assert(carla_max<int>( 1, 2, 2) == 2);
  235. assert(carla_max<int>( 1, 2, 3) == 2);
  236. assert(carla_max<int>( 2, 2, -1) == -1);
  237. assert(carla_max<int>( 1, 2, -1) == -1);
  238. assert(carla_max<int>( 0, 2, -1) == -1);
  239. assert(carla_max<int>(-1, 2, -1) == -1);
  240. assert(carla_max<int>(-2, 2, -1) == -1);
  241. assert(carla_max<int>(-1, 2, 0) == 0);
  242. assert(carla_max<int>(-1, 1, 0) == 0);
  243. assert(carla_max<int>(-1, 0, 0) == 0);
  244. assert(carla_max<int>(-1, -1, 0) == -1);
  245. assert(carla_max<int>(-1, -2, 0) == -1);
  246. unsigned u1 = static_cast<unsigned>(-1);
  247. unsigned u2 = static_cast<unsigned>(-2);
  248. assert(carla_max<unsigned>(u1, u2, 0) == 0);
  249. assert(carla_max<unsigned>(u1, u2, u1) == u1);
  250. assert(carla_max<unsigned>(u1, u2, u2) == u2);
  251. assert(carla_max<unsigned>(u1, 2, 0) == 0);
  252. assert(carla_max<unsigned>( 2, u1, 0) == 0);
  253. assert(carla_max<unsigned>( 2, 2, u1) == 2);
  254. }
  255. // carla_fixValue (same as min)
  256. {
  257. assert(carla_fixValue<int>( 1, 2, -1) == 1);
  258. assert(carla_fixValue<int>( 1, 2, 0) == 1);
  259. assert(carla_fixValue<int>( 1, 2, 1) == 1);
  260. assert(carla_fixValue<int>( 1, 2, 2) == 2);
  261. assert(carla_fixValue<int>( 1, 2, 3) == 2);
  262. assert(carla_fixValue<int>( 1, 2, -1) == 1);
  263. assert(carla_fixValue<int>( 0, 2, -1) == 0);
  264. assert(carla_fixValue<int>(-1, 2, -1) == -1);
  265. assert(carla_fixValue<int>(-2, 2, -1) == -1);
  266. assert(carla_fixValue<int>(-1, 2, 0) == 0);
  267. assert(carla_fixValue<int>(-1, 1, 0) == 0);
  268. assert(carla_fixValue<int>(-1, 0, 0) == 0);
  269. unsigned u1 = static_cast<unsigned>(-1);
  270. unsigned u2 = static_cast<unsigned>(-2);
  271. assert(carla_fixValue<unsigned>(u2, u1, 0) == u2);
  272. assert(carla_fixValue<unsigned>(u2, u1, u1) == u1);
  273. assert(carla_fixValue<unsigned>(u2, u1, u2) == u2);
  274. }
  275. // carla_add (copy and fill are very similar, so they are ignored here)
  276. {
  277. int a = 0;
  278. int b = 1;
  279. int c = 2;
  280. carla_add<int>(&a, &a, 1);
  281. assert(a == 0);
  282. carla_add<int>(&a, &b, 1);
  283. assert(a == 1);
  284. carla_add<int>(&a, &c, 1);
  285. assert(a == 3);
  286. float d = 10.0f;
  287. float e = 0.11f;
  288. carla_add<float>(&d, &e, 1);
  289. assert(d == 10.11f);
  290. float f[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
  291. float g[5] = { 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
  292. carla_add<float>(f, g, 5);
  293. assert(f[0] == f[0]);
  294. assert(f[1] == f[1]);
  295. assert(f[2] == f[2]);
  296. assert(f[3] == f[3]);
  297. assert(f[4] == f[4]);
  298. assert(f[0] == g[0]);
  299. assert(f[1] == g[1]);
  300. assert(f[2] == g[2]);
  301. assert(f[3] == g[3]);
  302. assert(f[4] == g[4]);
  303. carla_add<float>(g, f, 1);
  304. carla_add<float>(g, f, 2);
  305. carla_addFloat(g, f, 3);
  306. carla_add(g, f, 4);
  307. carla_add(g, f, 5);
  308. assert(g[0] == f[0]*6);
  309. assert(g[1] == f[1]*5);
  310. assert(g[2] == f[2]*4);
  311. assert(g[3] == f[3]*3);
  312. assert(g[4] == f[4]*2);
  313. carla_stdout("f: %f,%f,%f,%f,%f", f[0], f[1], f[2], f[3], f[4]);
  314. assert(f[0] != g[0]);
  315. assert(f[1] != g[1]);
  316. assert(f[2] != g[2]);
  317. assert(f[3] != g[3]);
  318. assert(f[4] != g[4]);
  319. carla_copy(f, g, 3);
  320. assert(f[0] == g[0]);
  321. assert(f[1] == g[1]);
  322. assert(f[2] == g[2]);
  323. assert(f[3] != g[3]);
  324. assert(f[4] != g[4]);
  325. carla_stdout("f: %f,%f,%f,%f,%f", f[0], f[1], f[2], f[3], f[4]);
  326. }
  327. // memory functions
  328. {
  329. uint64_t a[100];
  330. uint64_t at = 9999;
  331. carla_fill<uint64_t>(a, 100, 1);
  332. assert(a[99] == 1);
  333. assert(at == 9999);
  334. carla_zeroMem(a, sizeof(uint64_t)*100);
  335. assert(a[0] == 0);
  336. assert(a[99] == 0);
  337. assert(at == 9999);
  338. uint64_t b[100];
  339. uint64_t bt = 9999;
  340. carla_fill<uint64_t>(b, 100, 2);
  341. assert(b[99] == 2);
  342. assert(at == 9999);
  343. carla_zeroStruct(b);
  344. assert(b[0] == 0);
  345. assert(b[99] == 0);
  346. assert(bt == 9999);
  347. uint64_t c[100];
  348. uint64_t ct = 9999;
  349. carla_fill<uint64_t>(c, 100, 3);
  350. assert(c[99] == 3);
  351. assert(at == 9999);
  352. carla_zeroStruct(c, 100);
  353. assert(c[0] == 0);
  354. assert(c[99] == 0);
  355. assert(ct == 9999);
  356. struct Test { bool b; void* p; int i; };
  357. Test d, e[11], f[9];
  358. carla_zeroStruct<Test>(d);
  359. carla_zeroStruct<Test>(e, 11);
  360. carla_zeroStruct<Test>(f, 9);
  361. Test* h(new Test);
  362. h->i = 9;
  363. carla_zeroStruct<Test>(h, 1);
  364. assert(h->i == 0);
  365. delete h;
  366. Test* i(new Test[2]);
  367. carla_zeroStruct<Test>(i, 2);
  368. delete[] i;
  369. }
  370. }
  371. // Carla misc utils imported from Juce source code
  372. {
  373. struct Test { char s[24]; void* p; };
  374. ScopedPointer<int> a(new int);
  375. ScopedPointer<long long> b(new long long);
  376. ScopedPointer<Test> c(new Test);
  377. ScopedPointer<Test> d(new Test);
  378. ScopedPointer<Test> e(new Test);
  379. e = nullptr;
  380. delete d.release();
  381. delete e.release();
  382. ScopedPointer<Test> f(nullptr);
  383. }
  384. // Carla Native Plugin API (C++)
  385. {
  386. class PluginClassTest : public PluginClass
  387. {
  388. public:
  389. PluginDescriptorClassTest(const HostDescriptor* const host)
  390. : PluginClass(host) {}
  391. protected:
  392. void process(float** const, float** const, const uint32_t, const MidiEvent* const, const uint32_t) {}
  393. PluginClassEND(PluginClassTest)
  394. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginClassTest)
  395. };
  396. const HostDescriptor a = { nullptr, nullptr, nullptr,
  397. nullptr, nullptr, nullptr,
  398. nullptr, nullptr,
  399. nullptr, nullptr, nullptr, nullptr,
  400. nullptr, nullptr,
  401. nullptr };
  402. PluginDescriptor b = { PLUGIN_CATEGORY_NONE, PLUGIN_IS_RTSAFE, PLUGIN_SUPPORTS_EVERYTHING,
  403. 0, 0, 0, 0, 0, 0,
  404. nullptr, nullptr, nullptr, nullptr,
  405. PluginDescriptorFILL(PluginDescriptorClassTest) };
  406. (void)b;
  407. ScopedPointer<PluginDescriptorClassTest> c;
  408. c = new PluginDescriptorClassTest(&a);
  409. }
  410. // Carla Backend utils
  411. {
  412. class TestClass { public: int i; char pad[50]; };
  413. TestClass a, b, c;
  414. uintptr_t ad = CarlaBackend::getAddressFromPointer(&a);
  415. uintptr_t bd = CarlaBackend::getAddressFromPointer(&b);
  416. uintptr_t cd = CarlaBackend::getAddressFromPointer(&c);
  417. assert(bd > ad);
  418. assert(cd > bd);
  419. TestClass* ap = CarlaBackend::getPointerFromAddress<TestClass>(ad);
  420. TestClass* bp = CarlaBackend::getPointerFromAddress<TestClass>(bd);
  421. TestClass* cp = CarlaBackend::getPointerFromAddress<TestClass>(cd);
  422. assert(ap == &a);
  423. assert(bp == &b);
  424. assert(cp == &c);
  425. ap->i = 4;
  426. bp->i = 5;
  427. cp->i = 6;
  428. assert(a.i == 4);
  429. assert(b.i == 5);
  430. assert(c.i == 6);
  431. }
  432. // Carla Mutex
  433. {
  434. CarlaMutex m;
  435. m.tryLock();
  436. m.unlock();
  437. const CarlaMutex::ScopedLocker sl(m);
  438. }
  439. // RingBuffer
  440. {
  441. RingBuffer buf;
  442. RingBufferControl ctrl(&buf);
  443. assert(! ctrl.dataAvailable());
  444. assert(ctrl.readInt() == 0);
  445. assert(ctrl.readFloat() == 0.0f);
  446. assert(! ctrl.dataAvailable());
  447. ctrl.writeChar('z');
  448. ctrl.commitWrite();
  449. assert(ctrl.dataAvailable());
  450. const char c = ctrl.readChar();
  451. carla_stdout("BufRead c = \"%c\"", c);
  452. assert(c != '\0');
  453. assert(c == 'z');
  454. assert(! ctrl.dataAvailable());
  455. ctrl.writeInt(9999);
  456. ctrl.commitWrite();
  457. const int i = ctrl.readInt();
  458. carla_stdout("BufRead i = \"%i\"", i);
  459. assert(i != 0);
  460. assert(i == 9999);
  461. ctrl.writeLong(-88088);
  462. ctrl.commitWrite();
  463. const long l = ctrl.readLong();
  464. carla_stdout("BufRead l = \"%li\"", l);
  465. assert(l != 0);
  466. assert(l == -88088);
  467. ctrl.writeFloat(5.6789f);
  468. ctrl.commitWrite();
  469. const float f = ctrl.readFloat();
  470. carla_stdout("BufRead f = \"%f\"", f);
  471. assert(f != 0.0f);
  472. assert(f == 5.6789f);
  473. assert(! ctrl.dataAvailable());
  474. for (char i='1'; i <= 'z'; ++i)
  475. {
  476. ctrl.writeChar(char(i));
  477. ctrl.commitWrite();
  478. }
  479. assert(ctrl.dataAvailable());
  480. printf("CHAR DUMP:\n");
  481. while (ctrl.dataAvailable())
  482. printf("%c", ctrl.readChar());
  483. assert(! ctrl.dataAvailable());
  484. printf("\nDUMP FINISHED\n");
  485. }
  486. // RtList
  487. {
  488. class ListTester
  489. {
  490. public:
  491. struct CountObj {
  492. CountObj() : count(0) {}
  493. volatile int count;
  494. };
  495. ListTester()
  496. {
  497. ++getCounter().count;
  498. }
  499. ~ListTester()
  500. {
  501. --getCounter().count;
  502. }
  503. static CountObj& getCounter()
  504. {
  505. static CountObj counter;
  506. return counter;
  507. }
  508. };
  509. ListTester::CountObj& obj = ListTester::getCounter();
  510. assert(obj.count == 0);
  511. NonRtList<ListTester> list;
  512. obj = ListTester::getCounter();
  513. assert(obj.count == 1); // List fRetValue
  514. ListTester t1;
  515. obj = ListTester::getCounter();
  516. assert(obj.count == 2); // List fRetValue + t1
  517. list.append(t1);
  518. list.append(t1);
  519. list.append(t1);
  520. obj = ListTester::getCounter();
  521. assert(obj.count == 5); // List fRetValue + t1 + 3 appends
  522. list.clear();
  523. obj = ListTester::getCounter();
  524. assert(obj.count == 2); // List fRetValue + t1
  525. }
  526. // ANSI_TEST_N == 1
  527. #endif
  528. #if ANSI_TEST_N == 2
  529. // ANSI_TEST_N == 2
  530. #endif
  531. #if ANSI_TEST_N == 3
  532. // ANSI_TEST_N == 3
  533. #endif
  534. #if ANSI_TEST_N == 4
  535. carla_stdout("NOTICE LICENSE:");
  536. carla_stdout(carla_get_extended_license_text());
  537. carla_stdout("");
  538. carla_stdout("FILETYPES:");
  539. carla_stdout(carla_get_supported_file_types());
  540. carla_stdout("");
  541. carla_engine_init("beh", "bah");
  542. carla_stdout(carla_get_last_error());
  543. carla_engine_close();
  544. carla_stdout(carla_get_last_error());
  545. // ANSI_TEST_N == 4
  546. #endif
  547. return 0;
  548. }
  549. // -----------------------------------------------------------------------