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.

lilv_test.c 51KB

12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  1. /*
  2. Copyright 2007-2011 David Robillard <http://drobilla.net>
  3. Copyright 2008 Krzysztof Foltman
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #define _POSIX_C_SOURCE 200112L /* for setenv */
  16. #include <assert.h>
  17. #include <ctype.h>
  18. #include <errno.h>
  19. #include <float.h>
  20. #include <limits.h>
  21. #include <math.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <sys/stat.h>
  26. #ifdef _WIN32
  27. # include <direct.h>
  28. # define mkdir(path, flags) _mkdir(path)
  29. # define setenv(n, v, r) SetEnvironmentVariable((n), (v))
  30. # define unsetenv(n) SetEnvironmentVariable((n), NULL)
  31. #else
  32. # include <dirent.h>
  33. # include <unistd.h>
  34. #endif
  35. #include "lilv/lilv.h"
  36. #include "../src/lilv_internal.h"
  37. #include "lv2/lv2plug.in/ns/ext/state/state.h"
  38. #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
  39. #define TEST_PATH_MAX 1024
  40. #if defined(__APPLE__)
  41. # define SHLIB_EXT ".dylib"
  42. #elif defined(_WIN32)
  43. # define SHLIB_EXT ".dll"
  44. #else
  45. # define SHLIB_EXT ".so"
  46. #endif
  47. static char bundle_dir_name[TEST_PATH_MAX];
  48. static char bundle_dir_uri[TEST_PATH_MAX];
  49. static char manifest_name[TEST_PATH_MAX];
  50. static char content_name[TEST_PATH_MAX];
  51. static LilvWorld* world;
  52. int test_count = 0;
  53. int error_count = 0;
  54. static void
  55. delete_bundle(void)
  56. {
  57. unlink(content_name);
  58. unlink(manifest_name);
  59. remove(bundle_dir_name);
  60. }
  61. static void
  62. init_tests(void)
  63. {
  64. strncpy(bundle_dir_name, getenv("HOME"), 900);
  65. strcat(bundle_dir_name, "/.lv2");
  66. mkdir(bundle_dir_name, 0700);
  67. strcat(bundle_dir_name, "/lilv-test.lv2");
  68. sprintf(bundle_dir_uri, "file://%s/", bundle_dir_name);
  69. sprintf(manifest_name, "%s/manifest.ttl", bundle_dir_name);
  70. sprintf(content_name, "%s/plugin.ttl", bundle_dir_name);
  71. delete_bundle();
  72. }
  73. static void
  74. fatal_error(const char* err, const char* arg)
  75. {
  76. /* TODO: possibly change to vfprintf later */
  77. fprintf(stderr, err, arg);
  78. /* IMHO, the bundle should be left in place after an error, for possible investigation */
  79. /* delete_bundle(); */
  80. exit(1);
  81. }
  82. static void
  83. write_file(const char* name, const char* content)
  84. {
  85. FILE* f = fopen(name, "w");
  86. size_t len = strlen(content);
  87. if (fwrite(content, 1, len, f) != len)
  88. fatal_error("Cannot write file %s\n", name);
  89. fclose(f);
  90. }
  91. static int
  92. init_world(void)
  93. {
  94. world = lilv_world_new();
  95. return world != NULL;
  96. }
  97. static int
  98. load_all_bundles(void)
  99. {
  100. if (!init_world())
  101. return 0;
  102. lilv_world_load_all(world);
  103. return 1;
  104. }
  105. static void
  106. create_bundle(const char* manifest, const char* content)
  107. {
  108. if (mkdir(bundle_dir_name, 0700) && errno != EEXIST)
  109. fatal_error("Cannot create directory %s\n", bundle_dir_name);
  110. write_file(manifest_name, manifest);
  111. write_file(content_name, content);
  112. }
  113. static int
  114. start_bundle(const char* manifest, const char* content)
  115. {
  116. create_bundle(manifest, content);
  117. return load_all_bundles();
  118. }
  119. static void
  120. unload_bundle(void)
  121. {
  122. if (world)
  123. lilv_world_free(world);
  124. world = NULL;
  125. }
  126. static void
  127. cleanup(void)
  128. {
  129. delete_bundle();
  130. }
  131. /*****************************************************************************/
  132. #define TEST_CASE(name) { #name, test_##name }
  133. #define TEST_ASSERT(check) do {\
  134. test_count++;\
  135. if (!(check)) {\
  136. error_count++;\
  137. fprintf(stderr, "lilv_test.c:%d: error: %s\n", __LINE__, #check);\
  138. }\
  139. } while (0)
  140. typedef int (*TestFunc)(void);
  141. struct TestCase {
  142. const char* title;
  143. TestFunc func;
  144. };
  145. #define PREFIX_LINE "@prefix : <http://example.org/> .\n"
  146. #define PREFIX_LV2 "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n"
  147. #define PREFIX_LV2EV "@prefix lv2ev: <http://lv2plug.in/ns/ext/event#> . \n"
  148. #define PREFIX_LV2UI "@prefix lv2ui: <http://lv2plug.in/ns/extensions/ui#> .\n"
  149. #define PREFIX_RDF "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"
  150. #define PREFIX_RDFS "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
  151. #define PREFIX_FOAF "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n"
  152. #define PREFIX_DOAP "@prefix doap: <http://usefulinc.com/ns/doap#> .\n"
  153. #define MANIFEST_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDFS
  154. #define BUNDLE_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDF PREFIX_RDFS PREFIX_FOAF PREFIX_DOAP
  155. #define PLUGIN_NAME(name) "doap:name \"" name "\""
  156. #define LICENSE_GPL "doap:license <http://usefulinc.com/doap/licenses/gpl>"
  157. static const char* uris_plugin = "http://example.org/plug";
  158. static LilvNode* plugin_uri_value;
  159. static LilvNode* plugin2_uri_value;
  160. /*****************************************************************************/
  161. static void
  162. init_uris(void)
  163. {
  164. plugin_uri_value = lilv_new_uri(world, uris_plugin);
  165. plugin2_uri_value = lilv_new_uri(world, "http://example.org/foobar");
  166. TEST_ASSERT(plugin_uri_value);
  167. TEST_ASSERT(plugin2_uri_value);
  168. }
  169. static void
  170. cleanup_uris(void)
  171. {
  172. lilv_node_free(plugin2_uri_value);
  173. lilv_node_free(plugin_uri_value);
  174. plugin2_uri_value = NULL;
  175. plugin_uri_value = NULL;
  176. }
  177. /*****************************************************************************/
  178. static int
  179. test_utils(void)
  180. {
  181. TEST_ASSERT(!strcmp(lilv_uri_to_path("file:///tmp/blah"), "/tmp/blah"));
  182. TEST_ASSERT(!lilv_uri_to_path("file:/example.org/blah"));
  183. TEST_ASSERT(!lilv_uri_to_path("http://example.org/blah"));
  184. return 1;
  185. }
  186. /*****************************************************************************/
  187. static int
  188. test_value(void)
  189. {
  190. if (!start_bundle(MANIFEST_PREFIXES
  191. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  192. BUNDLE_PREFIXES
  193. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  194. PLUGIN_NAME("Test plugin") " ; "
  195. LICENSE_GPL " ; "
  196. "lv2:port [ "
  197. " a lv2:ControlPort ; a lv2:InputPort ; "
  198. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; "
  199. "] ."))
  200. return 0;
  201. init_uris();
  202. LilvNode* uval = lilv_new_uri(world, "http://example.org");
  203. LilvNode* sval = lilv_new_string(world, "Foo");
  204. LilvNode* ival = lilv_new_int(world, 42);
  205. LilvNode* fval = lilv_new_float(world, 1.6180);
  206. TEST_ASSERT(lilv_node_is_uri(uval));
  207. TEST_ASSERT(lilv_node_is_string(sval));
  208. TEST_ASSERT(lilv_node_is_int(ival));
  209. TEST_ASSERT(lilv_node_is_float(fval));
  210. TEST_ASSERT(!lilv_node_is_literal(uval));
  211. TEST_ASSERT(lilv_node_is_literal(sval));
  212. TEST_ASSERT(lilv_node_is_literal(ival));
  213. TEST_ASSERT(lilv_node_is_literal(fval));
  214. TEST_ASSERT(!strcmp(lilv_node_as_uri(uval), "http://example.org"));
  215. TEST_ASSERT(!strcmp(lilv_node_as_string(sval), "Foo"));
  216. TEST_ASSERT(lilv_node_as_int(ival) == 42);
  217. TEST_ASSERT(fabs(lilv_node_as_float(fval) - 1.6180) < FLT_EPSILON);
  218. char* tok = lilv_node_get_turtle_token(uval);
  219. TEST_ASSERT(!strcmp(tok, "<http://example.org>"));
  220. free(tok);
  221. tok = lilv_node_get_turtle_token(sval);
  222. TEST_ASSERT(!strcmp(tok, "Foo"));
  223. free(tok);
  224. tok = lilv_node_get_turtle_token(ival);
  225. TEST_ASSERT(!strcmp(tok, "42"));
  226. free(tok);
  227. tok = lilv_node_get_turtle_token(fval);
  228. TEST_ASSERT(!strncmp(tok, "1.6180", 6));
  229. free(tok);
  230. LilvNode* uval_e = lilv_new_uri(world, "http://example.org");
  231. LilvNode* sval_e = lilv_new_string(world, "Foo");
  232. LilvNode* ival_e = lilv_new_int(world, 42);
  233. LilvNode* fval_e = lilv_new_float(world, 1.6180);
  234. LilvNode* uval_ne = lilv_new_uri(world, "http://no-example.org");
  235. LilvNode* sval_ne = lilv_new_string(world, "Bar");
  236. LilvNode* ival_ne = lilv_new_int(world, 24);
  237. LilvNode* fval_ne = lilv_new_float(world, 3.14159);
  238. TEST_ASSERT(lilv_node_equals(uval, uval_e));
  239. TEST_ASSERT(lilv_node_equals(sval, sval_e));
  240. TEST_ASSERT(lilv_node_equals(ival, ival_e));
  241. TEST_ASSERT(lilv_node_equals(fval, fval_e));
  242. TEST_ASSERT(!lilv_node_equals(uval, uval_ne));
  243. TEST_ASSERT(!lilv_node_equals(sval, sval_ne));
  244. TEST_ASSERT(!lilv_node_equals(ival, ival_ne));
  245. TEST_ASSERT(!lilv_node_equals(fval, fval_ne));
  246. TEST_ASSERT(!lilv_node_equals(uval, sval));
  247. TEST_ASSERT(!lilv_node_equals(sval, ival));
  248. TEST_ASSERT(!lilv_node_equals(ival, fval));
  249. LilvNode* uval_dup = lilv_node_duplicate(uval);
  250. TEST_ASSERT(lilv_node_equals(uval, uval_dup));
  251. LilvNode* ifval = lilv_new_float(world, 42.0);
  252. TEST_ASSERT(!lilv_node_equals(ival, ifval));
  253. lilv_node_free(ifval);
  254. LilvNode* nil = NULL;
  255. TEST_ASSERT(!lilv_node_equals(uval, nil));
  256. TEST_ASSERT(!lilv_node_equals(nil, uval));
  257. TEST_ASSERT(lilv_node_equals(nil, nil));
  258. LilvNode* nil2 = lilv_node_duplicate(nil);
  259. TEST_ASSERT(lilv_node_equals(nil, nil2));
  260. lilv_node_free(uval);
  261. lilv_node_free(sval);
  262. lilv_node_free(ival);
  263. lilv_node_free(fval);
  264. lilv_node_free(uval_e);
  265. lilv_node_free(sval_e);
  266. lilv_node_free(ival_e);
  267. lilv_node_free(fval_e);
  268. lilv_node_free(uval_ne);
  269. lilv_node_free(sval_ne);
  270. lilv_node_free(ival_ne);
  271. lilv_node_free(fval_ne);
  272. lilv_node_free(uval_dup);
  273. lilv_node_free(nil2);
  274. cleanup_uris();
  275. return 1;
  276. }
  277. /*****************************************************************************/
  278. static int discovery_plugin_found = 0;
  279. static void
  280. discovery_verify_plugin(const LilvPlugin* plugin)
  281. {
  282. const LilvNode* value = lilv_plugin_get_uri(plugin);
  283. if (lilv_node_equals(value, plugin_uri_value)) {
  284. const LilvNode* lib_uri = NULL;
  285. TEST_ASSERT(!lilv_node_equals(value, plugin2_uri_value));
  286. discovery_plugin_found = 1;
  287. lib_uri = lilv_plugin_get_library_uri(plugin);
  288. TEST_ASSERT(lib_uri);
  289. TEST_ASSERT(lilv_node_is_uri(lib_uri));
  290. TEST_ASSERT(lilv_node_as_uri(lib_uri));
  291. TEST_ASSERT(strstr(lilv_node_as_uri(lib_uri), "foo" SHLIB_EXT));
  292. TEST_ASSERT(lilv_plugin_verify(plugin));
  293. }
  294. }
  295. static int
  296. test_discovery(void)
  297. {
  298. if (!start_bundle(MANIFEST_PREFIXES
  299. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  300. BUNDLE_PREFIXES
  301. ":plug a lv2:Plugin ;"
  302. PLUGIN_NAME("Test plugin") " ; "
  303. LICENSE_GPL " ; "
  304. "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;"
  305. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; ] ."))
  306. return 0;
  307. init_uris();
  308. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  309. TEST_ASSERT(lilv_plugins_size(plugins) > 0);
  310. const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  311. TEST_ASSERT(explug != NULL);
  312. const LilvPlugin* explug2 = lilv_plugins_get_by_uri(plugins, plugin2_uri_value);
  313. TEST_ASSERT(explug2 == NULL);
  314. if (explug) {
  315. LilvNode* name = lilv_plugin_get_name(explug);
  316. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "Test plugin"));
  317. lilv_node_free(name);
  318. }
  319. discovery_plugin_found = 0;
  320. LILV_FOREACH(plugins, i, plugins)
  321. discovery_verify_plugin(lilv_plugins_get(plugins, i));
  322. TEST_ASSERT(discovery_plugin_found);
  323. plugins = NULL;
  324. cleanup_uris();
  325. return 1;
  326. }
  327. /*****************************************************************************/
  328. static int
  329. test_lv2_path(void)
  330. {
  331. #ifndef _WIN32
  332. char* orig_lv2_path = lilv_strdup(getenv("LV2_PATH"));
  333. setenv("LV2_PATH", "~/.lv2:/usr/local/lib/lv2:/usr/lib/lv2", 1);
  334. world = lilv_world_new();
  335. lilv_world_load_all(world);
  336. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  337. const size_t n_plugins = lilv_plugins_size(plugins);
  338. lilv_world_free(world);
  339. setenv("LV2_PATH", "$HOME/.lv2:/usr/local/lib/lv2:/usr/lib/lv2", 1);
  340. world = lilv_world_new();
  341. lilv_world_load_all(world);
  342. plugins = lilv_world_get_all_plugins(world);
  343. TEST_ASSERT(lilv_plugins_size(plugins) == n_plugins);
  344. lilv_world_free(world);
  345. world = NULL;
  346. if (orig_lv2_path) {
  347. setenv("LV2_PATH", orig_lv2_path, 1);
  348. } else {
  349. unsetenv("LV2_PATH");
  350. }
  351. free(orig_lv2_path);
  352. #endif
  353. return 1;
  354. }
  355. /*****************************************************************************/
  356. static int
  357. test_verify(void)
  358. {
  359. if (!start_bundle(MANIFEST_PREFIXES
  360. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  361. BUNDLE_PREFIXES
  362. ":plug a lv2:Plugin ; "
  363. PLUGIN_NAME("Test plugin") " ; "
  364. LICENSE_GPL " ; "
  365. "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;"
  366. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ] ."))
  367. return 0;
  368. init_uris();
  369. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  370. const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  371. TEST_ASSERT(explug);
  372. TEST_ASSERT(lilv_plugin_verify(explug));
  373. cleanup_uris();
  374. return 1;
  375. }
  376. /*****************************************************************************/
  377. static int
  378. test_no_verify(void)
  379. {
  380. if (!start_bundle(MANIFEST_PREFIXES
  381. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  382. BUNDLE_PREFIXES
  383. ":plug a lv2:Plugin . "))
  384. return 0;
  385. init_uris();
  386. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  387. const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  388. TEST_ASSERT(explug);
  389. TEST_ASSERT(!lilv_plugin_verify(explug));
  390. cleanup_uris();
  391. return 1;
  392. }
  393. /*****************************************************************************/
  394. static int
  395. test_classes(void)
  396. {
  397. if (!start_bundle(MANIFEST_PREFIXES
  398. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  399. BUNDLE_PREFIXES
  400. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  401. PLUGIN_NAME("Test plugin") " ; "
  402. LICENSE_GPL " ; "
  403. "lv2:port [ "
  404. " a lv2:ControlPort ; a lv2:InputPort ; "
  405. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; "
  406. "] ."))
  407. return 0;
  408. init_uris();
  409. const LilvPluginClass* plugin = lilv_world_get_plugin_class(world);
  410. const LilvPluginClasses* classes = lilv_world_get_plugin_classes(world);
  411. LilvPluginClasses* children = lilv_plugin_class_get_children(plugin);
  412. TEST_ASSERT(lilv_plugin_class_get_parent_uri(plugin) == NULL);
  413. TEST_ASSERT(lilv_plugin_classes_size(classes) > lilv_plugin_classes_size(children));
  414. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_plugin_class_get_label(plugin)), "Plugin"));
  415. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_plugin_class_get_uri(plugin)),
  416. "http://lv2plug.in/ns/lv2core#Plugin"));
  417. LILV_FOREACH(plugin_classes, i, children) {
  418. TEST_ASSERT(lilv_node_equals(
  419. lilv_plugin_class_get_parent_uri(lilv_plugin_classes_get(children, i)),
  420. lilv_plugin_class_get_uri(plugin)));
  421. }
  422. LilvNode* some_uri = lilv_new_uri(world, "http://example.org/whatever");
  423. TEST_ASSERT(lilv_plugin_classes_get_by_uri(classes, some_uri) == NULL);
  424. lilv_node_free(some_uri);
  425. lilv_plugin_classes_free(children);
  426. cleanup_uris();
  427. return 1;
  428. }
  429. /*****************************************************************************/
  430. static int
  431. test_plugin(void)
  432. {
  433. if (!start_bundle(MANIFEST_PREFIXES
  434. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  435. BUNDLE_PREFIXES
  436. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  437. PLUGIN_NAME("Test plugin") " ; "
  438. LICENSE_GPL " ; "
  439. "lv2:optionalFeature lv2:hardRTCapable ; "
  440. "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
  441. "lv2:extensionData <http://example.org/extdata> ;"
  442. ":foo 1.6180 ; "
  443. ":bar true ; "
  444. ":baz false ; "
  445. ":blank [ a <http://example.org/blank> ] ; "
  446. "doap:maintainer [ foaf:name \"David Robillard\" ; "
  447. " foaf:homepage <http://drobilla.net> ; foaf:mbox <mailto:d@drobilla.net> ] ; "
  448. "lv2:port [ "
  449. " a lv2:ControlPort ; a lv2:InputPort ; "
  450. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  451. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  452. "] , [ "
  453. " a lv2:ControlPort ; a lv2:InputPort ; "
  454. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  455. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  456. "] , [ "
  457. " a lv2:ControlPort ; a lv2:OutputPort ; "
  458. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  459. " lv2:portProperty lv2:reportsLatency ; "
  460. " lv2:designation lv2:latency "
  461. "] . \n"
  462. ":thing doap:name \"Something else\" .\n"))
  463. return 0;
  464. init_uris();
  465. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  466. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  467. TEST_ASSERT(plug);
  468. const LilvPluginClass* klass = lilv_plugin_get_class(plug);
  469. const LilvNode* klass_uri = lilv_plugin_class_get_uri(klass);
  470. TEST_ASSERT(!strcmp(lilv_node_as_string(klass_uri),
  471. "http://lv2plug.in/ns/lv2core#CompressorPlugin"));
  472. const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
  473. TEST_ASSERT(!strcmp(lilv_node_as_string(plug_bundle_uri), bundle_dir_uri));
  474. const LilvNodes* data_uris = lilv_plugin_get_data_uris(plug);
  475. TEST_ASSERT(lilv_nodes_size(data_uris) == 2);
  476. char* manifest_uri = (char*)malloc(TEST_PATH_MAX);
  477. char* data_uri = (char*)malloc(TEST_PATH_MAX);
  478. snprintf(manifest_uri, TEST_PATH_MAX, "%s%s",
  479. lilv_node_as_string(plug_bundle_uri), "manifest.ttl");
  480. snprintf(data_uri, TEST_PATH_MAX, "%s%s",
  481. lilv_node_as_string(plug_bundle_uri), "plugin.ttl");
  482. LilvNode* manifest_uri_val = lilv_new_uri(world, manifest_uri);
  483. TEST_ASSERT(lilv_nodes_contains(data_uris, manifest_uri_val));
  484. lilv_node_free(manifest_uri_val);
  485. LilvNode* data_uri_val = lilv_new_uri(world, data_uri);
  486. TEST_ASSERT(lilv_nodes_contains(data_uris, data_uri_val));
  487. lilv_node_free(data_uri_val);
  488. free(manifest_uri);
  489. free(data_uri);
  490. float mins[3];
  491. float maxs[3];
  492. float defs[3];
  493. lilv_plugin_get_port_ranges_float(plug, mins, maxs, defs);
  494. TEST_ASSERT(mins[0] == -1.0f);
  495. TEST_ASSERT(maxs[0] == 1.0f);
  496. TEST_ASSERT(defs[0] == 0.5f);
  497. LilvNode* audio_class = lilv_new_uri(world,
  498. "http://lv2plug.in/ns/lv2core#AudioPort");
  499. LilvNode* control_class = lilv_new_uri(world,
  500. "http://lv2plug.in/ns/lv2core#ControlPort");
  501. LilvNode* in_class = lilv_new_uri(world,
  502. "http://lv2plug.in/ns/lv2core#InputPort");
  503. LilvNode* out_class = lilv_new_uri(world,
  504. "http://lv2plug.in/ns/lv2core#OutputPort");
  505. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, NULL) == 3);
  506. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, NULL) == 0);
  507. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, in_class, NULL) == 2);
  508. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, out_class, NULL) == 1);
  509. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, in_class, NULL) == 2);
  510. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, out_class, NULL) == 1);
  511. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, in_class, NULL) == 0);
  512. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, out_class, NULL) == 0);
  513. TEST_ASSERT(lilv_plugin_has_latency(plug));
  514. TEST_ASSERT(lilv_plugin_get_latency_port_index(plug) == 2);
  515. LilvNode* lv2_latency = lilv_new_uri(world,
  516. "http://lv2plug.in/ns/lv2core#latency");
  517. LilvPort* latency_port = lilv_plugin_get_port_by_designation(
  518. plug, out_class, lv2_latency);
  519. lilv_node_free(lv2_latency);
  520. TEST_ASSERT(latency_port);
  521. TEST_ASSERT(lilv_port_get_index(plug, latency_port) == 2);
  522. LilvNode* rt_feature = lilv_new_uri(world,
  523. "http://lv2plug.in/ns/lv2core#hardRTCapable");
  524. LilvNode* event_feature = lilv_new_uri(world,
  525. "http://lv2plug.in/ns/ext/event");
  526. LilvNode* pretend_feature = lilv_new_uri(world,
  527. "http://example.org/solvesWorldHunger");
  528. TEST_ASSERT(lilv_plugin_has_feature(plug, rt_feature));
  529. TEST_ASSERT(lilv_plugin_has_feature(plug, event_feature));
  530. TEST_ASSERT(!lilv_plugin_has_feature(plug, pretend_feature));
  531. lilv_node_free(rt_feature);
  532. lilv_node_free(event_feature);
  533. lilv_node_free(pretend_feature);
  534. LilvNodes* supported = lilv_plugin_get_supported_features(plug);
  535. LilvNodes* required = lilv_plugin_get_required_features(plug);
  536. LilvNodes* optional = lilv_plugin_get_optional_features(plug);
  537. TEST_ASSERT(lilv_nodes_size(supported) == 2);
  538. TEST_ASSERT(lilv_nodes_size(required) == 1);
  539. TEST_ASSERT(lilv_nodes_size(optional) == 1);
  540. lilv_nodes_free(supported);
  541. lilv_nodes_free(required);
  542. lilv_nodes_free(optional);
  543. LilvNode* foo_p = lilv_new_uri(world, "http://example.org/foo");
  544. LilvNodes* foos = lilv_plugin_get_value(plug, foo_p);
  545. TEST_ASSERT(lilv_nodes_size(foos) == 1);
  546. TEST_ASSERT(fabs(lilv_node_as_float(lilv_nodes_get_first(foos)) - 1.6180) < FLT_EPSILON);
  547. lilv_node_free(foo_p);
  548. lilv_nodes_free(foos);
  549. LilvNode* bar_p = lilv_new_uri(world, "http://example.org/bar");
  550. LilvNodes* bars = lilv_plugin_get_value(plug, bar_p);
  551. TEST_ASSERT(lilv_nodes_size(bars) == 1);
  552. TEST_ASSERT(lilv_node_as_bool(lilv_nodes_get_first(bars)) == true);
  553. lilv_node_free(bar_p);
  554. lilv_nodes_free(bars);
  555. LilvNode* baz_p = lilv_new_uri(world, "http://example.org/baz");
  556. LilvNodes* bazs = lilv_plugin_get_value(plug, baz_p);
  557. TEST_ASSERT(lilv_nodes_size(bazs) == 1);
  558. TEST_ASSERT(lilv_node_as_bool(lilv_nodes_get_first(bazs)) == false);
  559. lilv_node_free(baz_p);
  560. lilv_nodes_free(bazs);
  561. LilvNode* blank_p = lilv_new_uri(world, "http://example.org/blank");
  562. LilvNodes* blanks = lilv_plugin_get_value(plug, blank_p);
  563. TEST_ASSERT(lilv_nodes_size(blanks) == 1);
  564. LilvNode* blank = lilv_nodes_get_first(blanks);
  565. TEST_ASSERT(lilv_node_is_blank(blank));
  566. const char* blank_str = lilv_node_as_blank(blank);
  567. char* blank_tok = lilv_node_get_turtle_token(blank);
  568. TEST_ASSERT(!strncmp(blank_tok, "_:", 2));
  569. TEST_ASSERT(!strcmp(blank_tok + 2, blank_str));
  570. free(blank_tok);
  571. lilv_node_free(blank_p);
  572. lilv_nodes_free(blanks);
  573. LilvNode* author_name = lilv_plugin_get_author_name(plug);
  574. TEST_ASSERT(!strcmp(lilv_node_as_string(author_name), "David Robillard"));
  575. lilv_node_free(author_name);
  576. LilvNode* author_email = lilv_plugin_get_author_email(plug);
  577. TEST_ASSERT(!strcmp(lilv_node_as_string(author_email), "mailto:d@drobilla.net"));
  578. lilv_node_free(author_email);
  579. LilvNode* author_homepage = lilv_plugin_get_author_homepage(plug);
  580. TEST_ASSERT(!strcmp(lilv_node_as_string(author_homepage), "http://drobilla.net"));
  581. lilv_node_free(author_homepage);
  582. LilvNode* thing_uri = lilv_new_uri(world, "http://example.org/thing");
  583. LilvNode* name_p = lilv_new_uri(world, "http://usefulinc.com/ns/doap#name");
  584. LilvNodes* thing_names = lilv_world_find_nodes(world, thing_uri, name_p, NULL);
  585. TEST_ASSERT(lilv_nodes_size(thing_names) == 1);
  586. LilvNode* thing_name = lilv_nodes_get_first(thing_names);
  587. TEST_ASSERT(thing_name);
  588. TEST_ASSERT(lilv_node_is_string(thing_name));
  589. TEST_ASSERT(!strcmp(lilv_node_as_string(thing_name), "Something else"));
  590. LilvUIs* uis = lilv_plugin_get_uis(plug);
  591. TEST_ASSERT(lilv_uis_size(uis) == 0);
  592. lilv_uis_free(uis);
  593. LilvNode* extdata = lilv_new_uri(world, "http://example.org/extdata");
  594. LilvNode* noextdata = lilv_new_uri(world, "http://example.org/noextdata");
  595. LilvNodes* extdatas = lilv_plugin_get_extension_data(plug);
  596. TEST_ASSERT(lilv_plugin_has_extension_data(plug, extdata));
  597. TEST_ASSERT(!lilv_plugin_has_extension_data(plug, noextdata));
  598. TEST_ASSERT(lilv_nodes_size(extdatas) == 1);
  599. TEST_ASSERT(lilv_node_equals(lilv_nodes_get_first(extdatas), extdata));
  600. lilv_node_free(noextdata);
  601. lilv_node_free(extdata);
  602. lilv_nodes_free(extdatas);
  603. lilv_nodes_free(thing_names);
  604. lilv_node_free(thing_uri);
  605. lilv_node_free(name_p);
  606. lilv_node_free(control_class);
  607. lilv_node_free(audio_class);
  608. lilv_node_free(in_class);
  609. lilv_node_free(out_class);
  610. cleanup_uris();
  611. return 1;
  612. }
  613. /*****************************************************************************/
  614. static int
  615. test_port(void)
  616. {
  617. if (!start_bundle(MANIFEST_PREFIXES
  618. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  619. BUNDLE_PREFIXES PREFIX_LV2EV
  620. ":plug a lv2:Plugin ; "
  621. PLUGIN_NAME("Test plugin") " ; "
  622. LICENSE_GPL " ; "
  623. "doap:homepage <http://example.org/someplug> ; "
  624. "lv2:port [ "
  625. " a lv2:ControlPort ; a lv2:InputPort ; "
  626. " lv2:index 0 ; lv2:symbol \"foo\" ; "
  627. " lv2:name \"store\" ; "
  628. " lv2:name \"dépanneur\"@fr-ca ; lv2:name \"épicerie\"@fr-fr ; "
  629. " lv2:name \"tienda\"@es ; "
  630. " rdfs:comment \"comment\"@en , \"commentaires\"@fr ; "
  631. " lv2:portProperty lv2:integer ; "
  632. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 ; "
  633. " lv2:scalePoint [ rdfs:label \"Sin\"; rdf:value 3 ] ; "
  634. " lv2:scalePoint [ rdfs:label \"Cos\"; rdf:value 4 ] "
  635. "] , [\n"
  636. " a lv2:EventPort ; a lv2:InputPort ; "
  637. " lv2:index 1 ; lv2:symbol \"event_in\" ; "
  638. " lv2:name \"Event Input\" ; "
  639. " lv2ev:supportsEvent <http://example.org/event> "
  640. "] ."))
  641. return 0;
  642. init_uris();
  643. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  644. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  645. TEST_ASSERT(plug);
  646. LilvNode* psym = lilv_new_string(world, "foo");
  647. const LilvPort* p = lilv_plugin_get_port_by_index(plug, 0);
  648. const LilvPort* p2 = lilv_plugin_get_port_by_symbol(plug, psym);
  649. lilv_node_free(psym);
  650. TEST_ASSERT(p != NULL);
  651. TEST_ASSERT(p2 != NULL);
  652. TEST_ASSERT(p == p2);
  653. LilvNode* nopsym = lilv_new_string(world, "thisaintnoportfoo");
  654. const LilvPort* p3 = lilv_plugin_get_port_by_symbol(plug, nopsym);
  655. TEST_ASSERT(p3 == NULL);
  656. lilv_node_free(nopsym);
  657. LilvNode* audio_class = lilv_new_uri(world,
  658. "http://lv2plug.in/ns/lv2core#AudioPort");
  659. LilvNode* control_class = lilv_new_uri(world,
  660. "http://lv2plug.in/ns/lv2core#ControlPort");
  661. LilvNode* in_class = lilv_new_uri(world,
  662. "http://lv2plug.in/ns/lv2core#InputPort");
  663. TEST_ASSERT(lilv_nodes_size(lilv_port_get_classes(plug, p)) == 2);
  664. TEST_ASSERT(lilv_plugin_get_num_ports(plug) == 2);
  665. TEST_ASSERT(lilv_port_is_a(plug, p, control_class));
  666. TEST_ASSERT(lilv_port_is_a(plug, p, in_class));
  667. TEST_ASSERT(!lilv_port_is_a(plug, p, audio_class));
  668. LilvNodes* port_properties = lilv_port_get_properties(plug, p);
  669. TEST_ASSERT(lilv_nodes_size(port_properties) == 1);
  670. lilv_nodes_free(port_properties);
  671. // Untranslated name (current locale is set to "C" in main)
  672. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_port_get_symbol(plug, p)), "foo"));
  673. LilvNode* name = lilv_port_get_name(plug, p);
  674. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
  675. lilv_node_free(name);
  676. // Exact language match
  677. setenv("LANG", "fr_FR", 1);
  678. name = lilv_port_get_name(plug, p);
  679. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "épicerie"));
  680. lilv_node_free(name);
  681. // Exact language match (with charset suffix)
  682. setenv("LANG", "fr_CA.utf8", 1);
  683. name = lilv_port_get_name(plug, p);
  684. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "dépanneur"));
  685. lilv_node_free(name);
  686. // Partial language match (choose value translated for different country)
  687. setenv("LANG", "fr_BE", 1);
  688. name = lilv_port_get_name(plug, p);
  689. TEST_ASSERT((!strcmp(lilv_node_as_string(name), "dépanneur"))
  690. ||(!strcmp(lilv_node_as_string(name), "épicerie")));
  691. lilv_node_free(name);
  692. // Partial language match (choose country-less language tagged value)
  693. setenv("LANG", "es_MX", 1);
  694. name = lilv_port_get_name(plug, p);
  695. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "tienda"));
  696. lilv_node_free(name);
  697. // No language match (choose untranslated value)
  698. setenv("LANG", "cn", 1);
  699. name = lilv_port_get_name(plug, p);
  700. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
  701. lilv_node_free(name);
  702. setenv("LANG", "en_CA.utf-8", 1);
  703. // Language tagged value with no untranslated values
  704. LilvNode* rdfs_comment = lilv_new_uri(world, LILV_NS_RDFS "comment");
  705. LilvNodes* comments = lilv_port_get_value(plug, p, rdfs_comment);
  706. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(comments)),
  707. "comment"));
  708. lilv_nodes_free(comments);
  709. setenv("LANG", "fr", 1);
  710. comments = lilv_port_get_value(plug, p, rdfs_comment);
  711. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(comments)),
  712. "commentaires"));
  713. lilv_nodes_free(comments);
  714. setenv("LANG", "cn", 1);
  715. comments = lilv_port_get_value(plug, p, rdfs_comment);
  716. TEST_ASSERT(!comments);
  717. lilv_nodes_free(comments);
  718. lilv_node_free(rdfs_comment);
  719. setenv("LANG", "C", 1); // Reset locale
  720. LilvScalePoints* points = lilv_port_get_scale_points(plug, p);
  721. TEST_ASSERT(lilv_scale_points_size(points) == 2);
  722. LilvIter* sp_iter = lilv_scale_points_begin(points);
  723. const LilvScalePoint* sp0 = lilv_scale_points_get(points, sp_iter);
  724. TEST_ASSERT(sp0);
  725. sp_iter = lilv_scale_points_next(points, sp_iter);
  726. const LilvScalePoint* sp1 = lilv_scale_points_get(points, sp_iter);
  727. TEST_ASSERT(sp1);
  728. TEST_ASSERT(
  729. ((!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp0)), "Sin")
  730. && lilv_node_as_float(lilv_scale_point_get_value(sp0)) == 3)
  731. &&
  732. (!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp1)), "Cos")
  733. && lilv_node_as_float(lilv_scale_point_get_value(sp1)) == 4))
  734. ||
  735. ((!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp0)), "Cos")
  736. && lilv_node_as_float(lilv_scale_point_get_value(sp0)) == 4)
  737. &&
  738. (!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp1)), "Sin")
  739. && lilv_node_as_float(lilv_scale_point_get_value(sp1)) == 3)));
  740. LilvNode* homepage_p = lilv_new_uri(world, "http://usefulinc.com/ns/doap#homepage");
  741. LilvNodes* homepages = lilv_plugin_get_value(plug, homepage_p);
  742. TEST_ASSERT(lilv_nodes_size(homepages) == 1);
  743. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(homepages)),
  744. "http://example.org/someplug"));
  745. LilvNode *min, *max, *def;
  746. lilv_port_get_range(plug, p, &def, &min, &max);
  747. TEST_ASSERT(def);
  748. TEST_ASSERT(min);
  749. TEST_ASSERT(max);
  750. TEST_ASSERT(lilv_node_as_float(def) == 0.5);
  751. TEST_ASSERT(lilv_node_as_float(min) == -1.0);
  752. TEST_ASSERT(lilv_node_as_float(max) == 1.0);
  753. LilvNode* integer_prop = lilv_new_uri(world, "http://lv2plug.in/ns/lv2core#integer");
  754. LilvNode* toggled_prop = lilv_new_uri(world, "http://lv2plug.in/ns/lv2core#toggled");
  755. TEST_ASSERT(lilv_port_has_property(plug, p, integer_prop));
  756. TEST_ASSERT(!lilv_port_has_property(plug, p, toggled_prop));
  757. const LilvPort* ep = lilv_plugin_get_port_by_index(plug, 1);
  758. LilvNode* event_type = lilv_new_uri(world, "http://example.org/event");
  759. LilvNode* event_type_2 = lilv_new_uri(world, "http://example.org/otherEvent");
  760. TEST_ASSERT(lilv_port_supports_event(plug, ep, event_type));
  761. TEST_ASSERT(!lilv_port_supports_event(plug, ep, event_type_2));
  762. LilvNode* name_p = lilv_new_uri(world, "http://lv2plug.in/ns/lv2core#name");
  763. LilvNodes* names = lilv_port_get_value(plug, p, name_p);
  764. TEST_ASSERT(lilv_nodes_size(names) == 1);
  765. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(names)),
  766. "store"));
  767. lilv_nodes_free(names);
  768. LilvNode* true_val = lilv_new_bool(world, true);
  769. LilvNode* false_val = lilv_new_bool(world, false);
  770. TEST_ASSERT(!lilv_node_equals(true_val, false_val));
  771. lilv_world_set_option(world, LILV_OPTION_FILTER_LANG, false_val);
  772. names = lilv_port_get_value(plug, p, name_p);
  773. TEST_ASSERT(lilv_nodes_size(names) == 4);
  774. lilv_nodes_free(names);
  775. lilv_world_set_option(world, LILV_OPTION_FILTER_LANG, true_val);
  776. lilv_node_free(false_val);
  777. lilv_node_free(true_val);
  778. names = lilv_port_get_value(plug, ep, name_p);
  779. TEST_ASSERT(lilv_nodes_size(names) == 1);
  780. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(names)),
  781. "Event Input"));
  782. lilv_nodes_free(names);
  783. lilv_node_free(name_p);
  784. lilv_node_free(integer_prop);
  785. lilv_node_free(toggled_prop);
  786. lilv_node_free(event_type);
  787. lilv_node_free(event_type_2);
  788. lilv_node_free(min);
  789. lilv_node_free(max);
  790. lilv_node_free(def);
  791. lilv_node_free(homepage_p);
  792. lilv_nodes_free(homepages);
  793. lilv_scale_points_free(points);
  794. lilv_node_free(control_class);
  795. lilv_node_free(audio_class);
  796. lilv_node_free(in_class);
  797. cleanup_uris();
  798. return 1;
  799. }
  800. /*****************************************************************************/
  801. static unsigned
  802. ui_supported(const char* container_type_uri,
  803. const char* ui_type_uri)
  804. {
  805. return !strcmp(container_type_uri, ui_type_uri);
  806. }
  807. static int
  808. test_ui(void)
  809. {
  810. if (!start_bundle(MANIFEST_PREFIXES
  811. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  812. BUNDLE_PREFIXES PREFIX_LV2UI
  813. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  814. PLUGIN_NAME("Test plugin") " ; "
  815. LICENSE_GPL " ; "
  816. "lv2:optionalFeature lv2:hardRTCapable ; "
  817. "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
  818. "lv2ui:ui :ui , :ui2 , :ui3 , :ui4 ; "
  819. "doap:maintainer [ foaf:name \"David Robillard\" ; "
  820. " foaf:homepage <http://drobilla.net> ; foaf:mbox <mailto:d@drobilla.net> ] ; "
  821. "lv2:port [ "
  822. " a lv2:ControlPort ; a lv2:InputPort ; "
  823. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  824. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  825. "] , [ "
  826. " a lv2:ControlPort ; a lv2:InputPort ; "
  827. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  828. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  829. "] , [ "
  830. " a lv2:ControlPort ; a lv2:OutputPort ; "
  831. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  832. " lv2:portProperty lv2:reportsLatency "
  833. "] .\n"
  834. ":ui a lv2ui:GtkUI ; "
  835. " lv2ui:requiredFeature lv2ui:makeResident ; "
  836. " lv2ui:binary <ui" SHLIB_EXT "> ; "
  837. " lv2ui:optionalFeature lv2ui:ext_presets . "
  838. ":ui2 a lv2ui:GtkUI ; lv2ui:binary <ui2" SHLIB_EXT "> . "
  839. ":ui3 a lv2ui:GtkUI ; lv2ui:binary <ui3" SHLIB_EXT "> . "
  840. ":ui4 a lv2ui:GtkUI ; lv2ui:binary <ui4" SHLIB_EXT "> . "))
  841. return 0;
  842. init_uris();
  843. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  844. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  845. TEST_ASSERT(plug);
  846. LilvUIs* uis = lilv_plugin_get_uis(plug);
  847. TEST_ASSERT(lilv_uis_size(uis) == 4);
  848. const LilvUI* ui0 = lilv_uis_get(uis, lilv_uis_begin(uis));
  849. TEST_ASSERT(ui0);
  850. LilvNode* ui_uri = lilv_new_uri(world, "http://example.org/ui");
  851. LilvNode* ui2_uri = lilv_new_uri(world, "http://example.org/ui3");
  852. LilvNode* ui3_uri = lilv_new_uri(world, "http://example.org/ui4");
  853. LilvNode* noui_uri = lilv_new_uri(world, "http://example.org/notaui");
  854. const LilvUI* ui0_2 = lilv_uis_get_by_uri(uis, ui_uri);
  855. TEST_ASSERT(ui0 == ui0_2);
  856. TEST_ASSERT(lilv_node_equals(lilv_ui_get_uri(ui0_2), ui_uri));
  857. const LilvUI* ui2 = lilv_uis_get_by_uri(uis, ui2_uri);
  858. TEST_ASSERT(ui2 != ui0);
  859. const LilvUI* ui3 = lilv_uis_get_by_uri(uis, ui3_uri);
  860. TEST_ASSERT(ui3 != ui0);
  861. const LilvUI* noui = lilv_uis_get_by_uri(uis, noui_uri);
  862. TEST_ASSERT(noui == NULL);
  863. const LilvNodes* classes = lilv_ui_get_classes(ui0);
  864. TEST_ASSERT(lilv_nodes_size(classes) == 1);
  865. LilvNode* ui_class_uri = lilv_new_uri(world,
  866. "http://lv2plug.in/ns/extensions/ui#GtkUI");
  867. TEST_ASSERT(lilv_node_equals(lilv_nodes_get_first(classes), ui_class_uri));
  868. TEST_ASSERT(lilv_ui_is_a(ui0, ui_class_uri));
  869. const LilvNode* ui_type = NULL;
  870. TEST_ASSERT(lilv_ui_is_supported(ui0, ui_supported, ui_class_uri, &ui_type));
  871. TEST_ASSERT(lilv_node_equals(ui_type, ui_class_uri));
  872. const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
  873. const LilvNode* ui_bundle_uri = lilv_ui_get_bundle_uri(ui0);
  874. TEST_ASSERT(lilv_node_equals(plug_bundle_uri, ui_bundle_uri));
  875. char* ui_binary_uri_str = (char*)malloc(TEST_PATH_MAX);
  876. snprintf(ui_binary_uri_str, TEST_PATH_MAX, "%s%s",
  877. lilv_node_as_string(plug_bundle_uri), "ui" SHLIB_EXT);
  878. const LilvNode* ui_binary_uri = lilv_ui_get_binary_uri(ui0);
  879. LilvNode* expected_uri = lilv_new_uri(world, ui_binary_uri_str);
  880. TEST_ASSERT(lilv_node_equals(expected_uri, ui_binary_uri));
  881. free(ui_binary_uri_str);
  882. lilv_node_free(ui_class_uri);
  883. lilv_node_free(ui_uri);
  884. lilv_node_free(ui2_uri);
  885. lilv_node_free(ui3_uri);
  886. lilv_node_free(noui_uri);
  887. lilv_node_free(expected_uri);
  888. lilv_uis_free(uis);
  889. cleanup_uris();
  890. return 1;
  891. }
  892. /*****************************************************************************/
  893. uint32_t atom_Float = 0;
  894. float in = 1.0;
  895. float out = 42.0;
  896. static const void*
  897. get_port_value(const char* port_symbol,
  898. void* user_data,
  899. uint32_t* size,
  900. uint32_t* type)
  901. {
  902. if (!strcmp(port_symbol, "input")) {
  903. *size = sizeof(float);
  904. *type = atom_Float;
  905. return &in;
  906. } else if (!strcmp(port_symbol, "output")) {
  907. *size = sizeof(float);
  908. *type = atom_Float;
  909. return &out;
  910. } else {
  911. fprintf(stderr, "error: get_port_value for nonexistent port `%s'\n",
  912. port_symbol);
  913. *size = *type = 0;
  914. return NULL;
  915. }
  916. }
  917. static void
  918. set_port_value(const char* port_symbol,
  919. void* user_data,
  920. const void* value,
  921. uint32_t size,
  922. uint32_t type)
  923. {
  924. if (!strcmp(port_symbol, "input")) {
  925. in = *(float*)value;
  926. } else if (!strcmp(port_symbol, "output")) {
  927. out = *(float*)value;
  928. } else {
  929. fprintf(stderr, "error: set_port_value for nonexistent port `%s'\n",
  930. port_symbol);
  931. }
  932. }
  933. char** uris = NULL;
  934. size_t n_uris = 0;
  935. static LV2_URID
  936. map_uri(LV2_URID_Map_Handle handle,
  937. const char* uri)
  938. {
  939. for (size_t i = 0; i < n_uris; ++i) {
  940. if (!strcmp(uris[i], uri)) {
  941. return i + 1;
  942. }
  943. }
  944. assert(serd_uri_string_has_scheme((const uint8_t*)uri));
  945. uris = (char**)realloc(uris, ++n_uris * sizeof(char*));
  946. uris[n_uris - 1] = lilv_strdup(uri);
  947. return n_uris;
  948. }
  949. static const char*
  950. unmap_uri(LV2_URID_Map_Handle handle,
  951. LV2_URID urid)
  952. {
  953. if (urid > 0 && urid <= n_uris) {
  954. return uris[urid - 1];
  955. }
  956. return NULL;
  957. }
  958. static char* temp_dir = NULL;
  959. static char*
  960. lilv_make_path(LV2_State_Make_Path_Handle handle,
  961. const char* path)
  962. {
  963. return lilv_path_join(temp_dir, path);
  964. }
  965. static int
  966. test_state(void)
  967. {
  968. init_world();
  969. uint8_t* abs_bundle = (uint8_t*)lilv_path_absolute(LILV_TEST_BUNDLE);
  970. SerdNode bundle = serd_node_new_file_uri(abs_bundle, 0, 0, true);
  971. LilvNode* bundle_uri = lilv_new_uri(world, (const char*)bundle.buf);
  972. LilvNode* plugin_uri = lilv_new_uri(world,
  973. "http://example.org/lilv-test-plugin");
  974. lilv_world_load_bundle(world, bundle_uri);
  975. free(abs_bundle);
  976. serd_node_free(&bundle);
  977. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  978. const LilvPlugin* plugin = lilv_plugins_get_by_uri(plugins, plugin_uri);
  979. TEST_ASSERT(plugin);
  980. LV2_URID_Map map = { NULL, map_uri };
  981. LV2_Feature map_feature = { LV2_URID_MAP_URI, &map };
  982. LV2_URID_Unmap unmap = { NULL, unmap_uri };
  983. LV2_Feature unmap_feature = { LV2_URID_UNMAP_URI, &unmap };
  984. const LV2_Feature* features[] = { &map_feature, &unmap_feature, NULL };
  985. atom_Float = map.map(map.handle, "http://lv2plug.in/ns/ext/atom#Float");
  986. LilvNode* num = lilv_new_int(world, 5);
  987. LilvState* nostate = lilv_state_new_from_file(world, &map, num, "/junk");
  988. TEST_ASSERT(!nostate);
  989. LilvInstance* instance = lilv_plugin_instantiate(plugin, 48000.0, features);
  990. TEST_ASSERT(instance);
  991. lilv_instance_activate(instance);
  992. lilv_instance_connect_port(instance, 0, &in);
  993. lilv_instance_connect_port(instance, 1, &out);
  994. lilv_instance_run(instance, 1);
  995. TEST_ASSERT(in == 1.0);
  996. TEST_ASSERT(out == 1.0);
  997. temp_dir = lilv_realpath("temp");
  998. const char* file_dir = NULL;
  999. char* copy_dir = NULL;
  1000. char* link_dir = NULL;
  1001. char* save_dir = NULL;
  1002. // Get instance state state
  1003. LilvState* state = lilv_state_new_from_instance(
  1004. plugin, instance, &map,
  1005. file_dir, copy_dir, link_dir, save_dir,
  1006. get_port_value, world, 0, NULL);
  1007. // Get another instance state
  1008. LilvState* state2 = lilv_state_new_from_instance(
  1009. plugin, instance, &map,
  1010. file_dir, copy_dir, link_dir, save_dir,
  1011. get_port_value, world, 0, NULL);
  1012. // Ensure they are equal
  1013. TEST_ASSERT(lilv_state_equals(state, state2));
  1014. // Save state to a string
  1015. char* state1_str = lilv_state_to_string(
  1016. world, &map, &unmap, state, "http://example.org/state1", NULL);
  1017. // Restore from string
  1018. LilvState* from_str = lilv_state_new_from_string(world, &map, state1_str);
  1019. // Ensure they are equal
  1020. TEST_ASSERT(lilv_state_equals(state, from_str));
  1021. free(state1_str);
  1022. const LilvNode* state_plugin_uri = lilv_state_get_plugin_uri(state);
  1023. TEST_ASSERT(lilv_node_equals(state_plugin_uri, plugin_uri));
  1024. // Tinker with the label of the first state
  1025. TEST_ASSERT(lilv_state_get_label(state) == NULL);
  1026. lilv_state_set_label(state, "Test State Old Label");
  1027. TEST_ASSERT(!strcmp(lilv_state_get_label(state), "Test State Old Label"));
  1028. lilv_state_set_label(state, "Test State");
  1029. TEST_ASSERT(!strcmp(lilv_state_get_label(state), "Test State"));
  1030. TEST_ASSERT(!lilv_state_equals(state, state2)); // Label changed
  1031. // Run and get a new instance state (which should now differ)
  1032. lilv_instance_run(instance, 1);
  1033. LilvState* state3 = lilv_state_new_from_instance(
  1034. plugin, instance, &map,
  1035. file_dir, copy_dir, link_dir, save_dir,
  1036. get_port_value, world, 0, NULL);
  1037. TEST_ASSERT(!lilv_state_equals(state2, state3)); // num_runs changed
  1038. // Restore instance state to original state
  1039. lilv_state_restore(state2, instance, set_port_value, NULL, 0, NULL);
  1040. // Take a new snapshot and ensure it matches the set state
  1041. LilvState* state4 = lilv_state_new_from_instance(
  1042. plugin, instance, &map,
  1043. file_dir, copy_dir, link_dir, save_dir,
  1044. get_port_value, world, 0, NULL);
  1045. TEST_ASSERT(lilv_state_equals(state2, state4));
  1046. // Save state to a directory
  1047. int ret = lilv_state_save(world, &map, &unmap, state, NULL,
  1048. "state.lv2", "state.ttl");
  1049. TEST_ASSERT(!ret);
  1050. // Load state from directory
  1051. LilvState* state5 = lilv_state_new_from_file(world, &map, NULL,
  1052. "state.lv2/state.ttl");
  1053. TEST_ASSERT(lilv_state_equals(state, state5)); // Round trip accuracy
  1054. // Save state with URI to a directory
  1055. const char* state_uri = "http://example.org/state";
  1056. ret = lilv_state_save(world, &map, &unmap, state, state_uri,
  1057. "state6.lv2", "state6.ttl");
  1058. TEST_ASSERT(!ret);
  1059. // Load default bundle into world and load state from it
  1060. uint8_t* state6_path = (uint8_t*)lilv_path_absolute("state6.lv2/");
  1061. SerdNode state6_uri = serd_node_new_file_uri(state6_path, 0, 0, true);
  1062. LilvNode* test_state_bundle = lilv_new_uri(world, (const char*)state6_uri.buf);
  1063. LilvNode* test_state_node = lilv_new_uri(world, state_uri);
  1064. lilv_world_load_bundle(world, test_state_bundle);
  1065. lilv_world_load_resource(world, test_state_node);
  1066. serd_node_free(&state6_uri);
  1067. free(state6_path);
  1068. LilvState* state6 = lilv_state_new_from_world(world, &map, test_state_node);
  1069. TEST_ASSERT(lilv_state_equals(state, state6)); // Round trip accuracy
  1070. lilv_node_free(test_state_bundle);
  1071. lilv_node_free(test_state_node);
  1072. unsetenv("LV2_STATE_BUNDLE");
  1073. // Make directories and test files support
  1074. mkdir("temp", 0700);
  1075. file_dir = temp_dir;
  1076. mkdir("files", 0700);
  1077. copy_dir = lilv_realpath("files");
  1078. mkdir("links", 0700);
  1079. link_dir = lilv_realpath("links");
  1080. LV2_State_Make_Path make_path = { NULL, lilv_make_path };
  1081. LV2_Feature make_path_feature = { LV2_STATE__makePath, &make_path };
  1082. const LV2_Feature* ffeatures[] = { &make_path_feature, &map_feature, NULL };
  1083. lilv_instance_deactivate(instance);
  1084. lilv_instance_free(instance);
  1085. instance = lilv_plugin_instantiate(plugin, 48000.0, ffeatures);
  1086. lilv_instance_activate(instance);
  1087. lilv_instance_connect_port(instance, 0, &in);
  1088. lilv_instance_connect_port(instance, 1, &out);
  1089. lilv_instance_run(instance, 1);
  1090. // Get instance state state
  1091. LilvState* fstate = lilv_state_new_from_instance(
  1092. plugin, instance, &map,
  1093. file_dir, copy_dir, link_dir, "fstate.lv2",
  1094. get_port_value, world, 0, ffeatures);
  1095. // Get another instance state
  1096. LilvState* fstate2 = lilv_state_new_from_instance(
  1097. plugin, instance, &map,
  1098. file_dir, copy_dir, link_dir, "fstate2.lv2",
  1099. get_port_value, world, 0, ffeatures);
  1100. // Should be identical
  1101. TEST_ASSERT(lilv_state_equals(fstate, fstate2));
  1102. // Run, writing more to rec file
  1103. lilv_instance_run(instance, 2);
  1104. // Get yet another instance state
  1105. LilvState* fstate3 = lilv_state_new_from_instance(
  1106. plugin, instance, &map, file_dir, copy_dir, link_dir, "fstate3.lv2",
  1107. get_port_value, world, 0, ffeatures);
  1108. // Should be different
  1109. TEST_ASSERT(!lilv_state_equals(fstate, fstate3));
  1110. // Save state to a directory
  1111. ret = lilv_state_save(world, &map, &unmap, fstate, NULL,
  1112. "fstate.lv2", "fstate.ttl");
  1113. TEST_ASSERT(!ret);
  1114. // Load state from directory
  1115. LilvState* fstate4 = lilv_state_new_from_file(world, &map, NULL,
  1116. "fstate.lv2/fstate.ttl");
  1117. TEST_ASSERT(lilv_state_equals(fstate, fstate4)); // Round trip accuracy
  1118. // Restore instance state to loaded state
  1119. lilv_state_restore(fstate4, instance, set_port_value, NULL, 0, ffeatures);
  1120. // Take a new snapshot and ensure it matches
  1121. LilvState* fstate5 = lilv_state_new_from_instance(
  1122. plugin, instance, &map,
  1123. file_dir, copy_dir, link_dir, "fstate5.lv2",
  1124. get_port_value, world, 0, ffeatures);
  1125. TEST_ASSERT(lilv_state_equals(fstate3, fstate5));
  1126. // Save state to a (different) directory again
  1127. ret = lilv_state_save(world, &map, &unmap, fstate, NULL,
  1128. "fstate6.lv2", "fstate6.ttl");
  1129. TEST_ASSERT(!ret);
  1130. // Reload it and ensure it's identical to the other loaded version
  1131. LilvState* fstate6 = lilv_state_new_from_file(world, &map, NULL,
  1132. "fstate6.lv2/fstate6.ttl");
  1133. TEST_ASSERT(lilv_state_equals(fstate4, fstate6));
  1134. // Run, changing rec file (without changing size)
  1135. lilv_instance_run(instance, 3);
  1136. // Take a new snapshot
  1137. LilvState* fstate7 = lilv_state_new_from_instance(
  1138. plugin, instance, &map,
  1139. file_dir, copy_dir, link_dir, "fstate7.lv2",
  1140. get_port_value, world, 0, ffeatures);
  1141. TEST_ASSERT(!lilv_state_equals(fstate6, fstate7));
  1142. // Save the changed state to a (different) directory again
  1143. ret = lilv_state_save(world, &map, &unmap, fstate7, NULL,
  1144. "fstate7.lv2", "fstate7.ttl");
  1145. TEST_ASSERT(!ret);
  1146. // Reload it and ensure it's changed
  1147. LilvState* fstate72 = lilv_state_new_from_file(world, &map, NULL,
  1148. "fstate7.lv2/fstate7.ttl");
  1149. TEST_ASSERT(lilv_state_equals(fstate72, fstate7));
  1150. TEST_ASSERT(!lilv_state_equals(fstate6, fstate72));
  1151. lilv_instance_deactivate(instance);
  1152. lilv_instance_free(instance);
  1153. lilv_node_free(num);
  1154. lilv_state_free(state);
  1155. lilv_state_free(from_str);
  1156. lilv_state_free(state2);
  1157. lilv_state_free(state3);
  1158. lilv_state_free(state4);
  1159. lilv_state_free(state5);
  1160. lilv_state_free(state6);
  1161. lilv_state_free(fstate);
  1162. lilv_state_free(fstate2);
  1163. lilv_state_free(fstate3);
  1164. lilv_state_free(fstate4);
  1165. lilv_state_free(fstate5);
  1166. lilv_state_free(fstate6);
  1167. lilv_state_free(fstate7);
  1168. lilv_state_free(fstate72);
  1169. // Free URI map
  1170. for (size_t i = 0; i < n_uris; ++i) {
  1171. free(uris[i]);
  1172. }
  1173. free(uris);
  1174. n_uris = 0;
  1175. lilv_node_free(plugin_uri);
  1176. lilv_node_free(bundle_uri);
  1177. free(link_dir);
  1178. free(copy_dir);
  1179. free(temp_dir);
  1180. cleanup_uris();
  1181. return 1;
  1182. }
  1183. /*****************************************************************************/
  1184. static int
  1185. test_bad_port_symbol(void)
  1186. {
  1187. if (!start_bundle(MANIFEST_PREFIXES
  1188. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  1189. BUNDLE_PREFIXES PREFIX_LV2EV
  1190. ":plug a lv2:Plugin ; "
  1191. PLUGIN_NAME("Test plugin") " ; "
  1192. LICENSE_GPL " ; "
  1193. "doap:homepage <http://example.org/someplug> ; "
  1194. "lv2:port [ "
  1195. " a lv2:ControlPort ; a lv2:InputPort ; "
  1196. " lv2:index 0 ; lv2:symbol \"0invalid\" ;"
  1197. " lv2:name \"Invalid\" ; "
  1198. "] ."))
  1199. return 0;
  1200. init_uris();
  1201. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  1202. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  1203. uint32_t n_ports = lilv_plugin_get_num_ports(plug);
  1204. TEST_ASSERT(n_ports == 0);
  1205. cleanup_uris();
  1206. return 1;
  1207. }
  1208. /*****************************************************************************/
  1209. static int
  1210. test_bad_port_index(void)
  1211. {
  1212. if (!start_bundle(MANIFEST_PREFIXES
  1213. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  1214. BUNDLE_PREFIXES PREFIX_LV2EV
  1215. ":plug a lv2:Plugin ; "
  1216. PLUGIN_NAME("Test plugin") " ; "
  1217. LICENSE_GPL " ; "
  1218. "doap:homepage <http://example.org/someplug> ; "
  1219. "lv2:port [ "
  1220. " a lv2:ControlPort ; a lv2:InputPort ; "
  1221. " lv2:index \"notaninteger\" ; lv2:symbol \"invalid\" ;"
  1222. " lv2:name \"Invalid\" ; "
  1223. "] ."))
  1224. return 0;
  1225. init_uris();
  1226. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  1227. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  1228. uint32_t n_ports = lilv_plugin_get_num_ports(plug);
  1229. TEST_ASSERT(n_ports == 0);
  1230. cleanup_uris();
  1231. return 1;
  1232. }
  1233. /*****************************************************************************/
  1234. static int
  1235. test_string(void)
  1236. {
  1237. char* s = NULL;
  1238. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar")), "/foo")); free(s);
  1239. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar/")), "/foo")); free(s);
  1240. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar/")), "/foo")); free(s);
  1241. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar//")), "/foo")); free(s);
  1242. TEST_ASSERT(!strcmp((s = lilv_dirname("foo")), ".")); free(s);
  1243. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo")), "/")); free(s);
  1244. TEST_ASSERT(!strcmp((s = lilv_dirname("/")), "/")); free(s);
  1245. TEST_ASSERT(!strcmp((s = lilv_dirname("//")), "/")); free(s);
  1246. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b", "/a/")), "b")); free(s);
  1247. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a", "/b/c/")), "/a")); free(s);
  1248. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/")), "../c")); free(s);
  1249. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/e/")), "../../c")); free(s);
  1250. TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "b")), "/a/b")); free(s);
  1251. TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "/b")), "/a/b")); free(s);
  1252. TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "/b")), "/a/b")); free(s);
  1253. TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b")); free(s);
  1254. TEST_ASSERT(!strcmp((s = lilv_path_join("/a", NULL)), "/a/")); free(s);
  1255. #ifndef _WIN32
  1256. setenv("LILV_TEST_1", "test", 1);
  1257. char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL);
  1258. TEST_ASSERT(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test")); free(s);
  1259. TEST_ASSERT(!strcmp((s = lilv_expand("~")), getenv("HOME"))); free(s);
  1260. TEST_ASSERT(!strcmp((s = lilv_expand("~foo")), "~foo")); free(s);
  1261. TEST_ASSERT(!strcmp((s = lilv_expand("~/foo")), home_foo)); free(s);
  1262. TEST_ASSERT(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR")); free(s);
  1263. free(home_foo);
  1264. unsetenv("LILV_TEST_1");
  1265. #endif
  1266. return 1;
  1267. }
  1268. /*****************************************************************************/
  1269. /* add tests here */
  1270. static struct TestCase tests[] = {
  1271. TEST_CASE(utils),
  1272. TEST_CASE(value),
  1273. TEST_CASE(verify),
  1274. TEST_CASE(no_verify),
  1275. TEST_CASE(discovery),
  1276. TEST_CASE(lv2_path),
  1277. TEST_CASE(classes),
  1278. TEST_CASE(plugin),
  1279. TEST_CASE(port),
  1280. TEST_CASE(ui),
  1281. TEST_CASE(bad_port_symbol),
  1282. TEST_CASE(bad_port_index),
  1283. TEST_CASE(bad_port_index),
  1284. TEST_CASE(string),
  1285. TEST_CASE(state),
  1286. { NULL, NULL }
  1287. };
  1288. static void
  1289. run_tests(void)
  1290. {
  1291. int i;
  1292. for (i = 0; tests[i].title; i++) {
  1293. printf("*** Test %s\n", tests[i].title);
  1294. if (!tests[i].func()) {
  1295. printf("\nTest failed\n");
  1296. /* test case that wasn't able to be executed at all counts as 1 test + 1 error */
  1297. error_count++;
  1298. test_count++;
  1299. }
  1300. unload_bundle();
  1301. cleanup();
  1302. }
  1303. }
  1304. int
  1305. main(int argc, char* argv[])
  1306. {
  1307. if (argc != 1) {
  1308. printf("Syntax: %s\n", argv[0]);
  1309. return 0;
  1310. }
  1311. setenv("LANG", "C", 1);
  1312. init_tests();
  1313. run_tests();
  1314. cleanup();
  1315. printf("\n*** Test Results: %d tests, %d errors\n\n", test_count, error_count);
  1316. return error_count ? 1 : 0;
  1317. }