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.

616 lines
18KB

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