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 65KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  1. /*
  2. Copyright 2007-2015 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/presets/presets.h"
  38. #include "lv2/lv2plug.in/ns/ext/state/state.h"
  39. #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
  40. #define TEST_PATH_MAX 1024
  41. #if defined(__APPLE__)
  42. # define SHLIB_EXT ".dylib"
  43. #elif defined(_WIN32)
  44. # define SHLIB_EXT ".dll"
  45. #else
  46. # define SHLIB_EXT ".so"
  47. #endif
  48. static char bundle_dir_name[TEST_PATH_MAX];
  49. static char bundle_dir_uri[TEST_PATH_MAX];
  50. static char manifest_name[TEST_PATH_MAX];
  51. static char content_name[TEST_PATH_MAX];
  52. static LilvWorld* world;
  53. int test_count = 0;
  54. int error_count = 0;
  55. static void
  56. delete_bundle(void)
  57. {
  58. unlink(content_name);
  59. unlink(manifest_name);
  60. remove(bundle_dir_name);
  61. }
  62. static void
  63. init_tests(void)
  64. {
  65. strncpy(bundle_dir_name, getenv("HOME"), 900);
  66. strcat(bundle_dir_name, "/.lv2");
  67. mkdir(bundle_dir_name, 0700);
  68. strcat(bundle_dir_name, "/lilv-test.lv2");
  69. sprintf(bundle_dir_uri, "file://%s/", bundle_dir_name);
  70. sprintf(manifest_name, "%s/manifest.ttl", bundle_dir_name);
  71. sprintf(content_name, "%s/plugin.ttl", bundle_dir_name);
  72. delete_bundle();
  73. }
  74. static void
  75. fatal_error(const char* err, const char* arg)
  76. {
  77. /* TODO: possibly change to vfprintf later */
  78. fprintf(stderr, err, arg);
  79. /* IMHO, the bundle should be left in place after an error, for possible investigation */
  80. /* delete_bundle(); */
  81. exit(1);
  82. }
  83. static void
  84. write_file(const char* name, const char* content)
  85. {
  86. FILE* f = fopen(name, "w");
  87. size_t len = strlen(content);
  88. if (fwrite(content, 1, len, f) != len)
  89. fatal_error("Cannot write file %s\n", name);
  90. fclose(f);
  91. }
  92. static int
  93. init_world(void)
  94. {
  95. world = lilv_world_new();
  96. return world != NULL;
  97. }
  98. static int
  99. load_all_bundles(void)
  100. {
  101. if (!init_world())
  102. return 0;
  103. lilv_world_load_all(world);
  104. return 1;
  105. }
  106. static void
  107. create_bundle(const char* manifest, const char* content)
  108. {
  109. if (mkdir(bundle_dir_name, 0700) && errno != EEXIST)
  110. fatal_error("Cannot create directory %s\n", bundle_dir_name);
  111. write_file(manifest_name, manifest);
  112. write_file(content_name, content);
  113. }
  114. static int
  115. start_bundle(const char* manifest, const char* content)
  116. {
  117. create_bundle(manifest, content);
  118. return load_all_bundles();
  119. }
  120. static void
  121. unload_bundle(void)
  122. {
  123. if (world)
  124. lilv_world_free(world);
  125. world = NULL;
  126. }
  127. static void
  128. cleanup(void)
  129. {
  130. delete_bundle();
  131. }
  132. /*****************************************************************************/
  133. #define TEST_CASE(name) { #name, test_##name }
  134. #define TEST_ASSERT(check) do {\
  135. test_count++;\
  136. if (!(check)) {\
  137. assert(false);\
  138. error_count++;\
  139. fprintf(stderr, "lilv_test.c:%d: error: %s\n", __LINE__, #check);\
  140. }\
  141. } while (0)
  142. typedef int (*TestFunc)(void);
  143. struct TestCase {
  144. const char* title;
  145. TestFunc func;
  146. };
  147. #define PREFIX_ATOM "@prefix atom: <http://lv2plug.in/ns/ext/atom#> . \n"
  148. #define PREFIX_LINE "@prefix : <http://example.org/> .\n"
  149. #define PREFIX_LV2 "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n"
  150. #define PREFIX_LV2EV "@prefix lv2ev: <http://lv2plug.in/ns/ext/event#> . \n"
  151. #define PREFIX_LV2UI "@prefix lv2ui: <http://lv2plug.in/ns/extensions/ui#> .\n"
  152. #define PREFIX_RDF "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"
  153. #define PREFIX_RDFS "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
  154. #define PREFIX_FOAF "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n"
  155. #define PREFIX_DOAP "@prefix doap: <http://usefulinc.com/ns/doap#> .\n"
  156. #define PREFIX_PSET "@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n"
  157. #define MANIFEST_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDFS
  158. #define BUNDLE_PREFIXES PREFIX_ATOM PREFIX_LINE PREFIX_LV2 PREFIX_RDF PREFIX_RDFS PREFIX_FOAF PREFIX_DOAP PREFIX_PSET
  159. #define PLUGIN_NAME(name) "doap:name \"" name "\""
  160. #define LICENSE_GPL "doap:license <http://usefulinc.com/doap/licenses/gpl>"
  161. static const char* uris_plugin = "http://example.org/plug";
  162. static LilvNode* plugin_uri_value;
  163. static LilvNode* plugin2_uri_value;
  164. /*****************************************************************************/
  165. static void
  166. init_uris(void)
  167. {
  168. plugin_uri_value = lilv_new_uri(world, uris_plugin);
  169. plugin2_uri_value = lilv_new_uri(world, "http://example.org/foobar");
  170. TEST_ASSERT(plugin_uri_value);
  171. TEST_ASSERT(plugin2_uri_value);
  172. }
  173. static void
  174. cleanup_uris(void)
  175. {
  176. lilv_node_free(plugin2_uri_value);
  177. lilv_node_free(plugin_uri_value);
  178. plugin2_uri_value = NULL;
  179. plugin_uri_value = NULL;
  180. }
  181. /*****************************************************************************/
  182. static int
  183. test_value(void)
  184. {
  185. if (!start_bundle(MANIFEST_PREFIXES
  186. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  187. BUNDLE_PREFIXES
  188. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  189. PLUGIN_NAME("Test plugin") " ; "
  190. LICENSE_GPL " ; "
  191. "lv2:port [ "
  192. " a lv2:ControlPort ; a lv2:InputPort ; "
  193. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; "
  194. "] ."))
  195. return 0;
  196. init_uris();
  197. LilvNode* uval = lilv_new_uri(world, "http://example.org");
  198. LilvNode* sval = lilv_new_string(world, "Foo");
  199. LilvNode* ival = lilv_new_int(world, 42);
  200. LilvNode* fval = lilv_new_float(world, 1.6180);
  201. TEST_ASSERT(lilv_node_is_uri(uval));
  202. TEST_ASSERT(lilv_node_is_string(sval));
  203. TEST_ASSERT(lilv_node_is_int(ival));
  204. TEST_ASSERT(lilv_node_is_float(fval));
  205. TEST_ASSERT(!lilv_node_is_literal(NULL));
  206. TEST_ASSERT(!lilv_node_is_literal(uval));
  207. TEST_ASSERT(lilv_node_is_literal(sval));
  208. TEST_ASSERT(lilv_node_is_literal(ival));
  209. TEST_ASSERT(lilv_node_is_literal(fval));
  210. TEST_ASSERT(!lilv_node_get_path(fval, NULL));
  211. TEST_ASSERT(!strcmp(lilv_node_as_uri(uval), "http://example.org"));
  212. TEST_ASSERT(!strcmp(lilv_node_as_string(sval), "Foo"));
  213. TEST_ASSERT(lilv_node_as_int(ival) == 42);
  214. TEST_ASSERT(fabs(lilv_node_as_float(fval) - 1.6180) < FLT_EPSILON);
  215. LilvNode* loc_abs = lilv_new_file_uri(world, NULL, "/foo/bar");
  216. LilvNode* loc_rel = lilv_new_file_uri(world, NULL, "foo");
  217. LilvNode* host_abs = lilv_new_file_uri(world, "host", "/foo/bar");
  218. LilvNode* host_rel = lilv_new_file_uri(world, "host", "foo");
  219. TEST_ASSERT(!strcmp(lilv_node_as_uri(loc_abs), "file:///foo/bar"));
  220. TEST_ASSERT(!strncmp(lilv_node_as_uri(loc_rel), "file:///", 8));
  221. TEST_ASSERT(!strcmp(lilv_node_as_uri(host_abs), "file://host/foo/bar"));
  222. TEST_ASSERT(!strncmp(lilv_node_as_uri(host_rel), "file://host/", 12));
  223. lilv_node_free(host_rel);
  224. lilv_node_free(host_abs);
  225. lilv_node_free(loc_rel);
  226. lilv_node_free(loc_abs);
  227. char* tok = lilv_node_get_turtle_token(uval);
  228. TEST_ASSERT(!strcmp(tok, "<http://example.org>"));
  229. lilv_free(tok);
  230. tok = lilv_node_get_turtle_token(sval);
  231. TEST_ASSERT(!strcmp(tok, "Foo"));
  232. lilv_free(tok);
  233. tok = lilv_node_get_turtle_token(ival);
  234. TEST_ASSERT(!strcmp(tok, "42"));
  235. lilv_free(tok);
  236. tok = lilv_node_get_turtle_token(fval);
  237. TEST_ASSERT(!strncmp(tok, "1.6180", 6));
  238. lilv_free(tok);
  239. LilvNode* uval_e = lilv_new_uri(world, "http://example.org");
  240. LilvNode* sval_e = lilv_new_string(world, "Foo");
  241. LilvNode* ival_e = lilv_new_int(world, 42);
  242. LilvNode* fval_e = lilv_new_float(world, 1.6180);
  243. LilvNode* uval_ne = lilv_new_uri(world, "http://no-example.org");
  244. LilvNode* sval_ne = lilv_new_string(world, "Bar");
  245. LilvNode* ival_ne = lilv_new_int(world, 24);
  246. LilvNode* fval_ne = lilv_new_float(world, 3.14159);
  247. TEST_ASSERT(lilv_node_equals(uval, uval_e));
  248. TEST_ASSERT(lilv_node_equals(sval, sval_e));
  249. TEST_ASSERT(lilv_node_equals(ival, ival_e));
  250. TEST_ASSERT(lilv_node_equals(fval, fval_e));
  251. TEST_ASSERT(!lilv_node_equals(uval, uval_ne));
  252. TEST_ASSERT(!lilv_node_equals(sval, sval_ne));
  253. TEST_ASSERT(!lilv_node_equals(ival, ival_ne));
  254. TEST_ASSERT(!lilv_node_equals(fval, fval_ne));
  255. TEST_ASSERT(!lilv_node_equals(uval, sval));
  256. TEST_ASSERT(!lilv_node_equals(sval, ival));
  257. TEST_ASSERT(!lilv_node_equals(ival, fval));
  258. LilvNode* uval_dup = lilv_node_duplicate(uval);
  259. TEST_ASSERT(lilv_node_equals(uval, uval_dup));
  260. LilvNode* ifval = lilv_new_float(world, 42.0);
  261. TEST_ASSERT(!lilv_node_equals(ival, ifval));
  262. lilv_node_free(ifval);
  263. LilvNode* nil = NULL;
  264. TEST_ASSERT(!lilv_node_equals(uval, nil));
  265. TEST_ASSERT(!lilv_node_equals(nil, uval));
  266. TEST_ASSERT(lilv_node_equals(nil, nil));
  267. LilvNode* nil2 = lilv_node_duplicate(nil);
  268. TEST_ASSERT(lilv_node_equals(nil, nil2));
  269. lilv_node_free(uval);
  270. lilv_node_free(sval);
  271. lilv_node_free(ival);
  272. lilv_node_free(fval);
  273. lilv_node_free(uval_e);
  274. lilv_node_free(sval_e);
  275. lilv_node_free(ival_e);
  276. lilv_node_free(fval_e);
  277. lilv_node_free(uval_ne);
  278. lilv_node_free(sval_ne);
  279. lilv_node_free(ival_ne);
  280. lilv_node_free(fval_ne);
  281. lilv_node_free(uval_dup);
  282. lilv_node_free(nil2);
  283. cleanup_uris();
  284. return 1;
  285. }
  286. /*****************************************************************************/
  287. static int
  288. test_util(void)
  289. {
  290. TEST_ASSERT(!lilv_realpath(NULL));
  291. return 1;
  292. }
  293. /*****************************************************************************/
  294. static int discovery_plugin_found = 0;
  295. static void
  296. discovery_verify_plugin(const LilvPlugin* plugin)
  297. {
  298. const LilvNode* value = lilv_plugin_get_uri(plugin);
  299. if (lilv_node_equals(value, plugin_uri_value)) {
  300. const LilvNode* lib_uri = NULL;
  301. TEST_ASSERT(!lilv_node_equals(value, plugin2_uri_value));
  302. discovery_plugin_found = 1;
  303. lib_uri = lilv_plugin_get_library_uri(plugin);
  304. TEST_ASSERT(lib_uri);
  305. TEST_ASSERT(lilv_node_is_uri(lib_uri));
  306. TEST_ASSERT(lilv_node_as_uri(lib_uri));
  307. TEST_ASSERT(strstr(lilv_node_as_uri(lib_uri), "foo" SHLIB_EXT));
  308. TEST_ASSERT(lilv_plugin_verify(plugin));
  309. }
  310. }
  311. static int
  312. test_discovery(void)
  313. {
  314. if (!start_bundle(MANIFEST_PREFIXES
  315. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  316. BUNDLE_PREFIXES
  317. ":plug a lv2:Plugin ;"
  318. PLUGIN_NAME("Test plugin") " ; "
  319. LICENSE_GPL " ; "
  320. "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;"
  321. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; ] ."))
  322. return 0;
  323. init_uris();
  324. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  325. TEST_ASSERT(lilv_plugins_size(plugins) > 0);
  326. const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  327. TEST_ASSERT(explug != NULL);
  328. const LilvPlugin* explug2 = lilv_plugins_get_by_uri(plugins, plugin2_uri_value);
  329. TEST_ASSERT(explug2 == NULL);
  330. if (explug) {
  331. LilvNode* name = lilv_plugin_get_name(explug);
  332. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "Test plugin"));
  333. lilv_node_free(name);
  334. }
  335. discovery_plugin_found = 0;
  336. LILV_FOREACH(plugins, i, plugins)
  337. discovery_verify_plugin(lilv_plugins_get(plugins, i));
  338. TEST_ASSERT(discovery_plugin_found);
  339. plugins = NULL;
  340. cleanup_uris();
  341. return 1;
  342. }
  343. /*****************************************************************************/
  344. static int
  345. test_lv2_path(void)
  346. {
  347. #ifndef _WIN32
  348. char* orig_lv2_path = lilv_strdup(getenv("LV2_PATH"));
  349. setenv("LV2_PATH", "~/.lv2:/usr/local/lib/lv2:/usr/lib/lv2", 1);
  350. world = lilv_world_new();
  351. lilv_world_load_all(world);
  352. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  353. const size_t n_plugins = lilv_plugins_size(plugins);
  354. lilv_world_free(world);
  355. setenv("LV2_PATH", "$HOME/.lv2:/usr/local/lib/lv2:/usr/lib/lv2", 1);
  356. world = lilv_world_new();
  357. lilv_world_load_all(world);
  358. plugins = lilv_world_get_all_plugins(world);
  359. TEST_ASSERT(lilv_plugins_size(plugins) == n_plugins);
  360. lilv_world_free(world);
  361. world = NULL;
  362. if (orig_lv2_path) {
  363. setenv("LV2_PATH", orig_lv2_path, 1);
  364. } else {
  365. unsetenv("LV2_PATH");
  366. }
  367. free(orig_lv2_path);
  368. #endif
  369. return 1;
  370. }
  371. /*****************************************************************************/
  372. static int
  373. test_verify(void)
  374. {
  375. if (!start_bundle(MANIFEST_PREFIXES
  376. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  377. BUNDLE_PREFIXES
  378. ":plug a lv2:Plugin ; "
  379. PLUGIN_NAME("Test plugin") " ; "
  380. LICENSE_GPL " ; "
  381. "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;"
  382. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ] ."))
  383. return 0;
  384. init_uris();
  385. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  386. const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  387. TEST_ASSERT(explug);
  388. TEST_ASSERT(lilv_plugin_verify(explug));
  389. cleanup_uris();
  390. return 1;
  391. }
  392. /*****************************************************************************/
  393. static int
  394. test_no_verify(void)
  395. {
  396. if (!start_bundle(MANIFEST_PREFIXES
  397. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  398. BUNDLE_PREFIXES
  399. ":plug a lv2:Plugin . "))
  400. return 0;
  401. init_uris();
  402. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  403. const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  404. TEST_ASSERT(explug);
  405. TEST_ASSERT(!lilv_plugin_verify(explug));
  406. cleanup_uris();
  407. return 1;
  408. }
  409. /*****************************************************************************/
  410. static int
  411. test_classes(void)
  412. {
  413. if (!start_bundle(MANIFEST_PREFIXES
  414. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  415. BUNDLE_PREFIXES
  416. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  417. PLUGIN_NAME("Test plugin") " ; "
  418. LICENSE_GPL " ; "
  419. "lv2:port [ "
  420. " a lv2:ControlPort ; a lv2:InputPort ; "
  421. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; "
  422. "] ."))
  423. return 0;
  424. init_uris();
  425. const LilvPluginClass* plugin = lilv_world_get_plugin_class(world);
  426. const LilvPluginClasses* classes = lilv_world_get_plugin_classes(world);
  427. LilvPluginClasses* children = lilv_plugin_class_get_children(plugin);
  428. TEST_ASSERT(lilv_plugin_class_get_parent_uri(plugin) == NULL);
  429. TEST_ASSERT(lilv_plugin_classes_size(classes) > lilv_plugin_classes_size(children));
  430. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_plugin_class_get_label(plugin)), "Plugin"));
  431. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_plugin_class_get_uri(plugin)),
  432. "http://lv2plug.in/ns/lv2core#Plugin"));
  433. LILV_FOREACH(plugin_classes, i, children) {
  434. TEST_ASSERT(lilv_node_equals(
  435. lilv_plugin_class_get_parent_uri(lilv_plugin_classes_get(children, i)),
  436. lilv_plugin_class_get_uri(plugin)));
  437. }
  438. LilvNode* some_uri = lilv_new_uri(world, "http://example.org/whatever");
  439. TEST_ASSERT(lilv_plugin_classes_get_by_uri(classes, some_uri) == NULL);
  440. lilv_node_free(some_uri);
  441. lilv_plugin_classes_free(children);
  442. cleanup_uris();
  443. return 1;
  444. }
  445. /*****************************************************************************/
  446. static int
  447. test_plugin(void)
  448. {
  449. if (!start_bundle(MANIFEST_PREFIXES
  450. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  451. BUNDLE_PREFIXES
  452. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  453. PLUGIN_NAME("Test plugin") " ; "
  454. LICENSE_GPL " ; "
  455. "lv2:optionalFeature lv2:hardRTCapable ; "
  456. "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
  457. "lv2:extensionData <http://example.org/extdata> ;"
  458. ":foo 1.6180 ; "
  459. ":bar true ; "
  460. ":baz false ; "
  461. ":blank [ a <http://example.org/blank> ] ; "
  462. "doap:maintainer [ foaf:name \"David Robillard\" ; "
  463. " foaf:homepage <http://drobilla.net> ; foaf:mbox <mailto:d@drobilla.net> ] ; "
  464. "lv2:port [ "
  465. " a lv2:ControlPort ; a lv2:InputPort ; "
  466. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  467. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  468. "] , [ "
  469. " a lv2:ControlPort ; a lv2:InputPort ; "
  470. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  471. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  472. "] , [ "
  473. " a lv2:ControlPort ; a lv2:OutputPort ; "
  474. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  475. " lv2:portProperty lv2:reportsLatency ; "
  476. " lv2:designation lv2:latency "
  477. "] . \n"
  478. ":thing doap:name \"Something else\" .\n"))
  479. return 0;
  480. init_uris();
  481. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  482. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  483. TEST_ASSERT(plug);
  484. const LilvPluginClass* klass = lilv_plugin_get_class(plug);
  485. const LilvNode* klass_uri = lilv_plugin_class_get_uri(klass);
  486. TEST_ASSERT(!strcmp(lilv_node_as_string(klass_uri),
  487. "http://lv2plug.in/ns/lv2core#CompressorPlugin"));
  488. LilvNode* rdf_type = lilv_new_uri(
  489. world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
  490. TEST_ASSERT(lilv_world_ask(world,
  491. lilv_plugin_get_uri(plug),
  492. rdf_type,
  493. klass_uri));
  494. lilv_node_free(rdf_type);
  495. TEST_ASSERT(!lilv_plugin_is_replaced(plug));
  496. TEST_ASSERT(!lilv_plugin_get_related(plug, NULL));
  497. const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
  498. TEST_ASSERT(!strcmp(lilv_node_as_string(plug_bundle_uri), bundle_dir_uri));
  499. const LilvNodes* data_uris = lilv_plugin_get_data_uris(plug);
  500. TEST_ASSERT(lilv_nodes_size(data_uris) == 2);
  501. LilvNode* project = lilv_plugin_get_project(plug);
  502. TEST_ASSERT(!project);
  503. char* manifest_uri = (char*)malloc(TEST_PATH_MAX);
  504. char* data_uri = (char*)malloc(TEST_PATH_MAX);
  505. snprintf(manifest_uri, TEST_PATH_MAX, "%s%s",
  506. lilv_node_as_string(plug_bundle_uri), "manifest.ttl");
  507. snprintf(data_uri, TEST_PATH_MAX, "%s%s",
  508. lilv_node_as_string(plug_bundle_uri), "plugin.ttl");
  509. LilvNode* manifest_uri_val = lilv_new_uri(world, manifest_uri);
  510. TEST_ASSERT(lilv_nodes_contains(data_uris, manifest_uri_val));
  511. lilv_node_free(manifest_uri_val);
  512. LilvNode* data_uri_val = lilv_new_uri(world, data_uri);
  513. TEST_ASSERT(lilv_nodes_contains(data_uris, data_uri_val));
  514. lilv_node_free(data_uri_val);
  515. LilvNode* unknown_uri_val = lilv_new_uri(world, "http://example.org/unknown");
  516. TEST_ASSERT(!lilv_nodes_contains(data_uris, unknown_uri_val));
  517. lilv_node_free(unknown_uri_val);
  518. free(manifest_uri);
  519. free(data_uri);
  520. float mins[3];
  521. float maxs[3];
  522. float defs[3];
  523. lilv_plugin_get_port_ranges_float(plug, mins, maxs, defs);
  524. TEST_ASSERT(mins[0] == -1.0f);
  525. TEST_ASSERT(maxs[0] == 1.0f);
  526. TEST_ASSERT(defs[0] == 0.5f);
  527. LilvNode* audio_class = lilv_new_uri(world,
  528. "http://lv2plug.in/ns/lv2core#AudioPort");
  529. LilvNode* control_class = lilv_new_uri(world,
  530. "http://lv2plug.in/ns/lv2core#ControlPort");
  531. LilvNode* in_class = lilv_new_uri(world,
  532. "http://lv2plug.in/ns/lv2core#InputPort");
  533. LilvNode* out_class = lilv_new_uri(world,
  534. "http://lv2plug.in/ns/lv2core#OutputPort");
  535. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, NULL) == 3);
  536. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, NULL) == 0);
  537. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, in_class, NULL) == 2);
  538. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, out_class, NULL) == 1);
  539. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, in_class, NULL) == 2);
  540. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, out_class, NULL) == 1);
  541. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, in_class, NULL) == 0);
  542. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, out_class, NULL) == 0);
  543. TEST_ASSERT(lilv_plugin_has_latency(plug));
  544. TEST_ASSERT(lilv_plugin_get_latency_port_index(plug) == 2);
  545. LilvNode* lv2_latency = lilv_new_uri(world,
  546. "http://lv2plug.in/ns/lv2core#latency");
  547. const LilvPort* latency_port = lilv_plugin_get_port_by_designation(
  548. plug, out_class, lv2_latency);
  549. lilv_node_free(lv2_latency);
  550. TEST_ASSERT(latency_port);
  551. TEST_ASSERT(lilv_port_get_index(plug, latency_port) == 2);
  552. TEST_ASSERT(lilv_node_is_blank(lilv_port_get_node(plug, latency_port)));
  553. LilvNode* rt_feature = lilv_new_uri(world,
  554. "http://lv2plug.in/ns/lv2core#hardRTCapable");
  555. LilvNode* event_feature = lilv_new_uri(world,
  556. "http://lv2plug.in/ns/ext/event");
  557. LilvNode* pretend_feature = lilv_new_uri(world,
  558. "http://example.org/solvesWorldHunger");
  559. TEST_ASSERT(lilv_plugin_has_feature(plug, rt_feature));
  560. TEST_ASSERT(lilv_plugin_has_feature(plug, event_feature));
  561. TEST_ASSERT(!lilv_plugin_has_feature(plug, pretend_feature));
  562. lilv_node_free(rt_feature);
  563. lilv_node_free(event_feature);
  564. lilv_node_free(pretend_feature);
  565. LilvNodes* supported = lilv_plugin_get_supported_features(plug);
  566. LilvNodes* required = lilv_plugin_get_required_features(plug);
  567. LilvNodes* optional = lilv_plugin_get_optional_features(plug);
  568. TEST_ASSERT(lilv_nodes_size(supported) == 2);
  569. TEST_ASSERT(lilv_nodes_size(required) == 1);
  570. TEST_ASSERT(lilv_nodes_size(optional) == 1);
  571. lilv_nodes_free(supported);
  572. lilv_nodes_free(required);
  573. lilv_nodes_free(optional);
  574. LilvNode* foo_p = lilv_new_uri(world, "http://example.org/foo");
  575. LilvNodes* foos = lilv_plugin_get_value(plug, foo_p);
  576. TEST_ASSERT(lilv_nodes_size(foos) == 1);
  577. TEST_ASSERT(fabs(lilv_node_as_float(lilv_nodes_get_first(foos)) - 1.6180) < FLT_EPSILON);
  578. lilv_node_free(foo_p);
  579. lilv_nodes_free(foos);
  580. LilvNode* bar_p = lilv_new_uri(world, "http://example.org/bar");
  581. LilvNodes* bars = lilv_plugin_get_value(plug, bar_p);
  582. TEST_ASSERT(lilv_nodes_size(bars) == 1);
  583. TEST_ASSERT(lilv_node_as_bool(lilv_nodes_get_first(bars)) == true);
  584. lilv_node_free(bar_p);
  585. lilv_nodes_free(bars);
  586. LilvNode* baz_p = lilv_new_uri(world, "http://example.org/baz");
  587. LilvNodes* bazs = lilv_plugin_get_value(plug, baz_p);
  588. TEST_ASSERT(lilv_nodes_size(bazs) == 1);
  589. TEST_ASSERT(lilv_node_as_bool(lilv_nodes_get_first(bazs)) == false);
  590. lilv_node_free(baz_p);
  591. lilv_nodes_free(bazs);
  592. LilvNode* blank_p = lilv_new_uri(world, "http://example.org/blank");
  593. LilvNodes* blanks = lilv_plugin_get_value(plug, blank_p);
  594. TEST_ASSERT(lilv_nodes_size(blanks) == 1);
  595. LilvNode* blank = lilv_nodes_get_first(blanks);
  596. TEST_ASSERT(lilv_node_is_blank(blank));
  597. const char* blank_str = lilv_node_as_blank(blank);
  598. char* blank_tok = lilv_node_get_turtle_token(blank);
  599. TEST_ASSERT(!strncmp(blank_tok, "_:", 2));
  600. TEST_ASSERT(!strcmp(blank_tok + 2, blank_str));
  601. lilv_free(blank_tok);
  602. lilv_node_free(blank_p);
  603. lilv_nodes_free(blanks);
  604. LilvNode* author_name = lilv_plugin_get_author_name(plug);
  605. TEST_ASSERT(!strcmp(lilv_node_as_string(author_name), "David Robillard"));
  606. lilv_node_free(author_name);
  607. LilvNode* author_email = lilv_plugin_get_author_email(plug);
  608. TEST_ASSERT(!strcmp(lilv_node_as_string(author_email), "mailto:d@drobilla.net"));
  609. lilv_node_free(author_email);
  610. LilvNode* author_homepage = lilv_plugin_get_author_homepage(plug);
  611. TEST_ASSERT(!strcmp(lilv_node_as_string(author_homepage), "http://drobilla.net"));
  612. lilv_node_free(author_homepage);
  613. LilvNode* thing_uri = lilv_new_uri(world, "http://example.org/thing");
  614. LilvNode* name_p = lilv_new_uri(world, "http://usefulinc.com/ns/doap#name");
  615. LilvNodes* thing_names = lilv_world_find_nodes(world, thing_uri, name_p, NULL);
  616. TEST_ASSERT(lilv_nodes_size(thing_names) == 1);
  617. LilvNode* thing_name = lilv_nodes_get_first(thing_names);
  618. TEST_ASSERT(thing_name);
  619. TEST_ASSERT(lilv_node_is_string(thing_name));
  620. TEST_ASSERT(!strcmp(lilv_node_as_string(thing_name), "Something else"));
  621. LilvNode* thing_name2 = lilv_world_get(world, thing_uri, name_p, NULL);
  622. TEST_ASSERT(lilv_node_equals(thing_name, thing_name2));
  623. LilvUIs* uis = lilv_plugin_get_uis(plug);
  624. TEST_ASSERT(lilv_uis_size(uis) == 0);
  625. lilv_uis_free(uis);
  626. LilvNode* extdata = lilv_new_uri(world, "http://example.org/extdata");
  627. LilvNode* noextdata = lilv_new_uri(world, "http://example.org/noextdata");
  628. LilvNodes* extdatas = lilv_plugin_get_extension_data(plug);
  629. TEST_ASSERT(lilv_plugin_has_extension_data(plug, extdata));
  630. TEST_ASSERT(!lilv_plugin_has_extension_data(plug, noextdata));
  631. TEST_ASSERT(lilv_nodes_size(extdatas) == 1);
  632. TEST_ASSERT(lilv_node_equals(lilv_nodes_get_first(extdatas), extdata));
  633. lilv_node_free(noextdata);
  634. lilv_node_free(extdata);
  635. lilv_nodes_free(extdatas);
  636. lilv_nodes_free(thing_names);
  637. lilv_node_free(thing_uri);
  638. lilv_node_free(thing_name2);
  639. lilv_node_free(name_p);
  640. lilv_node_free(control_class);
  641. lilv_node_free(audio_class);
  642. lilv_node_free(in_class);
  643. lilv_node_free(out_class);
  644. cleanup_uris();
  645. return 1;
  646. }
  647. /*****************************************************************************/
  648. static int
  649. test_project(void)
  650. {
  651. if (!start_bundle(MANIFEST_PREFIXES
  652. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  653. BUNDLE_PREFIXES
  654. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  655. PLUGIN_NAME("Test plugin with project") " ; "
  656. LICENSE_GPL " ; "
  657. "lv2:project [ "
  658. " doap:maintainer [ "
  659. " foaf:name \"David Robillard\" ; "
  660. " foaf:homepage <http://drobilla.net> ; foaf:mbox <mailto:d@drobilla.net> ] ; "
  661. "] ; "
  662. "lv2:port [ "
  663. " a lv2:ControlPort ; a lv2:InputPort ; "
  664. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  665. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  666. "] , [ "
  667. " a lv2:ControlPort ; a lv2:InputPort ; "
  668. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  669. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  670. "] , [ "
  671. " a lv2:ControlPort ; a lv2:OutputPort ; "
  672. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  673. " lv2:portProperty lv2:reportsLatency ; "
  674. " lv2:designation lv2:latency "
  675. "] . \n"
  676. ":thing doap:name \"Something else\" .\n"))
  677. return 0;
  678. init_uris();
  679. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  680. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  681. TEST_ASSERT(plug);
  682. LilvNode* author_name = lilv_plugin_get_author_name(plug);
  683. TEST_ASSERT(!strcmp(lilv_node_as_string(author_name), "David Robillard"));
  684. lilv_node_free(author_name);
  685. LilvNode* author_email = lilv_plugin_get_author_email(plug);
  686. TEST_ASSERT(!strcmp(lilv_node_as_string(author_email), "mailto:d@drobilla.net"));
  687. lilv_node_free(author_email);
  688. LilvNode* author_homepage = lilv_plugin_get_author_homepage(plug);
  689. TEST_ASSERT(!strcmp(lilv_node_as_string(author_homepage), "http://drobilla.net"));
  690. lilv_node_free(author_homepage);
  691. cleanup_uris();
  692. return 1;
  693. }
  694. /*****************************************************************************/
  695. static int
  696. test_no_author(void)
  697. {
  698. if (!start_bundle(MANIFEST_PREFIXES
  699. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  700. BUNDLE_PREFIXES
  701. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  702. PLUGIN_NAME("Test plugin with project") " ; "
  703. LICENSE_GPL " ; "
  704. "lv2:port [ "
  705. " a lv2:ControlPort ; a lv2:InputPort ; "
  706. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  707. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  708. "] , [ "
  709. " a lv2:ControlPort ; a lv2:InputPort ; "
  710. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  711. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  712. "] , [ "
  713. " a lv2:ControlPort ; a lv2:OutputPort ; "
  714. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  715. " lv2:portProperty lv2:reportsLatency ; "
  716. " lv2:designation lv2:latency "
  717. "] . \n"
  718. ":thing doap:name \"Something else\" .\n"))
  719. return 0;
  720. init_uris();
  721. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  722. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  723. TEST_ASSERT(plug);
  724. LilvNode* author_name = lilv_plugin_get_author_name(plug);
  725. TEST_ASSERT(!author_name);
  726. LilvNode* author_email = lilv_plugin_get_author_email(plug);
  727. TEST_ASSERT(!author_email);
  728. LilvNode* author_homepage = lilv_plugin_get_author_homepage(plug);
  729. TEST_ASSERT(!author_homepage);
  730. cleanup_uris();
  731. return 1;
  732. }
  733. /*****************************************************************************/
  734. static int
  735. test_project_no_author(void)
  736. {
  737. if (!start_bundle(MANIFEST_PREFIXES
  738. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  739. BUNDLE_PREFIXES
  740. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  741. PLUGIN_NAME("Test plugin with project") " ; "
  742. LICENSE_GPL " ; "
  743. "lv2:project [ "
  744. " doap:name \"Fake project\" ;"
  745. "] ; "
  746. "lv2:port [ "
  747. " a lv2:ControlPort ; a lv2:InputPort ; "
  748. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  749. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  750. "] , [ "
  751. " a lv2:ControlPort ; a lv2:InputPort ; "
  752. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  753. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  754. "] , [ "
  755. " a lv2:ControlPort ; a lv2:OutputPort ; "
  756. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  757. " lv2:portProperty lv2:reportsLatency ; "
  758. " lv2:designation lv2:latency "
  759. "] . \n"
  760. ":thing doap:name \"Something else\" .\n"))
  761. return 0;
  762. init_uris();
  763. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  764. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  765. TEST_ASSERT(plug);
  766. LilvNode* author_name = lilv_plugin_get_author_name(plug);
  767. TEST_ASSERT(!author_name);
  768. LilvNode* author_email = lilv_plugin_get_author_email(plug);
  769. TEST_ASSERT(!author_email);
  770. LilvNode* author_homepage = lilv_plugin_get_author_homepage(plug);
  771. TEST_ASSERT(!author_homepage);
  772. cleanup_uris();
  773. return 1;
  774. }
  775. /*****************************************************************************/
  776. static int
  777. test_preset(void)
  778. {
  779. if (!start_bundle(MANIFEST_PREFIXES
  780. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  781. BUNDLE_PREFIXES
  782. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  783. PLUGIN_NAME("Test plugin with project") " ; "
  784. LICENSE_GPL " ; "
  785. "lv2:project [ "
  786. " doap:name \"Fake project\" ;"
  787. "] ; "
  788. "lv2:port [ "
  789. " a lv2:ControlPort ; a lv2:InputPort ; "
  790. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  791. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  792. "] , [ "
  793. " a lv2:ControlPort ; a lv2:InputPort ; "
  794. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  795. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  796. "] , [ "
  797. " a lv2:ControlPort ; a lv2:OutputPort ; "
  798. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  799. " lv2:portProperty lv2:reportsLatency ; "
  800. " lv2:designation lv2:latency "
  801. "] . \n"
  802. "<http://example.org/preset> a pset:Preset ;"
  803. " lv2:appliesTo :plug ;"
  804. " rdfs:label \"some preset\" .\n"))
  805. return 0;
  806. init_uris();
  807. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  808. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  809. TEST_ASSERT(plug);
  810. LilvNode* pset_Preset = lilv_new_uri(world, LV2_PRESETS__Preset);
  811. LilvNodes* related = lilv_plugin_get_related(plug, pset_Preset);
  812. TEST_ASSERT(lilv_nodes_size(related) == 1);
  813. lilv_node_free(pset_Preset);
  814. lilv_nodes_free(related);
  815. cleanup_uris();
  816. return 1;
  817. }
  818. /*****************************************************************************/
  819. static int
  820. test_prototype(void)
  821. {
  822. if (!start_bundle(MANIFEST_PREFIXES
  823. ":prot a lv2:PluginBase ; rdfs:seeAlso <plugin.ttl> .\n"
  824. ":plug a lv2:Plugin ; lv2:binary <inst" SHLIB_EXT "> ; lv2:prototype :prot .\n",
  825. BUNDLE_PREFIXES
  826. ":prot a lv2:Plugin ; a lv2:CompressorPlugin ; "
  827. LICENSE_GPL " ; "
  828. "lv2:project [ "
  829. " doap:name \"Fake project\" ;"
  830. "] ; "
  831. "lv2:port [ "
  832. " a lv2:ControlPort ; a lv2:InputPort ; "
  833. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  834. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  835. "] , [ "
  836. " a lv2:ControlPort ; a lv2:InputPort ; "
  837. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  838. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  839. "] , [ "
  840. " a lv2:ControlPort ; a lv2:OutputPort ; "
  841. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  842. " lv2:portProperty lv2:reportsLatency ; "
  843. " lv2:designation lv2:latency "
  844. "] . \n"
  845. ":plug doap:name \"Instance\" .\n"))
  846. return 0;
  847. init_uris();
  848. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  849. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  850. TEST_ASSERT(plug);
  851. // Test non-inherited property
  852. LilvNode* name = lilv_plugin_get_name(plug);
  853. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "Instance"));
  854. lilv_node_free(name);
  855. // Test inherited property
  856. const LilvNode* binary = lilv_plugin_get_library_uri(plug);
  857. TEST_ASSERT(strstr(lilv_node_as_string(binary), "inst" SHLIB_EXT));
  858. cleanup_uris();
  859. return 1;
  860. }
  861. /*****************************************************************************/
  862. static int
  863. test_port(void)
  864. {
  865. if (!start_bundle(MANIFEST_PREFIXES
  866. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  867. BUNDLE_PREFIXES PREFIX_LV2EV
  868. ":plug a lv2:Plugin ; "
  869. PLUGIN_NAME("Test plugin") " ; "
  870. LICENSE_GPL " ; "
  871. "doap:homepage <http://example.org/someplug> ; "
  872. "lv2:port [ "
  873. " a lv2:ControlPort ; a lv2:InputPort ; "
  874. " lv2:index 0 ; lv2:symbol \"foo\" ; "
  875. " lv2:name \"store\" ; "
  876. " lv2:name \"dépanneur\"@fr-ca ; lv2:name \"épicerie\"@fr-fr ; "
  877. " lv2:name \"tienda\"@es ; "
  878. " rdfs:comment \"comment\"@en , \"commentaires\"@fr ; "
  879. " lv2:portProperty lv2:integer ; "
  880. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 ; "
  881. " lv2:scalePoint [ rdfs:label \"Sin\"; rdf:value 3 ] ; "
  882. " lv2:scalePoint [ rdfs:label \"Cos\"; rdf:value 4 ] "
  883. "] , [\n"
  884. " a lv2:EventPort ; a lv2:InputPort ; "
  885. " lv2:index 1 ; lv2:symbol \"event_in\" ; "
  886. " lv2:name \"Event Input\" ; "
  887. " lv2ev:supportsEvent <http://example.org/event> ;"
  888. " atom:supports <http://example.org/atomEvent> "
  889. "] , [\n"
  890. " a lv2:AudioPort ; a lv2:InputPort ; "
  891. " lv2:index 2 ; lv2:symbol \"audio_in\" ; "
  892. " lv2:name \"Audio Input\" ; "
  893. "] , [\n"
  894. " a lv2:AudioPort ; a lv2:OutputPort ; "
  895. " lv2:index 3 ; lv2:symbol \"audio_out\" ; "
  896. " lv2:name \"Audio Output\" ; "
  897. "] ."))
  898. return 0;
  899. init_uris();
  900. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  901. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  902. TEST_ASSERT(plug);
  903. LilvNode* psym = lilv_new_string(world, "foo");
  904. const LilvPort* p = lilv_plugin_get_port_by_index(plug, 0);
  905. const LilvPort* p2 = lilv_plugin_get_port_by_symbol(plug, psym);
  906. lilv_node_free(psym);
  907. TEST_ASSERT(p != NULL);
  908. TEST_ASSERT(p2 != NULL);
  909. TEST_ASSERT(p == p2);
  910. LilvNode* nopsym = lilv_new_string(world, "thisaintnoportfoo");
  911. const LilvPort* p3 = lilv_plugin_get_port_by_symbol(plug, nopsym);
  912. TEST_ASSERT(p3 == NULL);
  913. lilv_node_free(nopsym);
  914. // Try getting an invalid property
  915. LilvNode* num = lilv_new_int(world, 1);
  916. LilvNodes* nothing = lilv_port_get_value(plug, p, num);
  917. TEST_ASSERT(!nothing);
  918. lilv_node_free(num);
  919. LilvNode* audio_class = lilv_new_uri(world,
  920. "http://lv2plug.in/ns/lv2core#AudioPort");
  921. LilvNode* control_class = lilv_new_uri(world,
  922. "http://lv2plug.in/ns/lv2core#ControlPort");
  923. LilvNode* in_class = lilv_new_uri(world,
  924. "http://lv2plug.in/ns/lv2core#InputPort");
  925. LilvNode* out_class = lilv_new_uri(world,
  926. "http://lv2plug.in/ns/lv2core#OutputPort");
  927. TEST_ASSERT(lilv_nodes_size(lilv_port_get_classes(plug, p)) == 2);
  928. TEST_ASSERT(lilv_plugin_get_num_ports(plug) == 4);
  929. TEST_ASSERT(lilv_port_is_a(plug, p, control_class));
  930. TEST_ASSERT(lilv_port_is_a(plug, p, in_class));
  931. TEST_ASSERT(!lilv_port_is_a(plug, p, audio_class));
  932. LilvNodes* port_properties = lilv_port_get_properties(plug, p);
  933. TEST_ASSERT(lilv_nodes_size(port_properties) == 1);
  934. lilv_nodes_free(port_properties);
  935. // Untranslated name (current locale is set to "C" in main)
  936. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_port_get_symbol(plug, p)), "foo"));
  937. LilvNode* name = lilv_port_get_name(plug, p);
  938. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
  939. lilv_node_free(name);
  940. // Exact language match
  941. setenv("LANG", "fr_FR", 1);
  942. name = lilv_port_get_name(plug, p);
  943. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "épicerie"));
  944. lilv_node_free(name);
  945. // Exact language match (with charset suffix)
  946. setenv("LANG", "fr_CA.utf8", 1);
  947. name = lilv_port_get_name(plug, p);
  948. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "dépanneur"));
  949. lilv_node_free(name);
  950. // Partial language match (choose value translated for different country)
  951. setenv("LANG", "fr_BE", 1);
  952. name = lilv_port_get_name(plug, p);
  953. TEST_ASSERT((!strcmp(lilv_node_as_string(name), "dépanneur"))
  954. ||(!strcmp(lilv_node_as_string(name), "épicerie")));
  955. lilv_node_free(name);
  956. // Partial language match (choose country-less language tagged value)
  957. setenv("LANG", "es_MX", 1);
  958. name = lilv_port_get_name(plug, p);
  959. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "tienda"));
  960. lilv_node_free(name);
  961. // No language match (choose untranslated value)
  962. setenv("LANG", "cn", 1);
  963. name = lilv_port_get_name(plug, p);
  964. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
  965. lilv_node_free(name);
  966. // Invalid language
  967. setenv("LANG", "1!", 1);
  968. name = lilv_port_get_name(plug, p);
  969. TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
  970. lilv_node_free(name);
  971. setenv("LANG", "en_CA.utf-8", 1);
  972. // Language tagged value with no untranslated values
  973. LilvNode* rdfs_comment = lilv_new_uri(world, LILV_NS_RDFS "comment");
  974. LilvNodes* comments = lilv_port_get_value(plug, p, rdfs_comment);
  975. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(comments)),
  976. "comment"));
  977. LilvNode* comment = lilv_port_get(plug, p, rdfs_comment);
  978. TEST_ASSERT(!strcmp(lilv_node_as_string(comment), "comment"));
  979. lilv_node_free(comment);
  980. lilv_nodes_free(comments);
  981. setenv("LANG", "fr", 1);
  982. comments = lilv_port_get_value(plug, p, rdfs_comment);
  983. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(comments)),
  984. "commentaires"));
  985. lilv_nodes_free(comments);
  986. setenv("LANG", "cn", 1);
  987. comments = lilv_port_get_value(plug, p, rdfs_comment);
  988. TEST_ASSERT(!comments);
  989. lilv_nodes_free(comments);
  990. lilv_node_free(rdfs_comment);
  991. setenv("LANG", "C", 1); // Reset locale
  992. LilvScalePoints* points = lilv_port_get_scale_points(plug, p);
  993. TEST_ASSERT(lilv_scale_points_size(points) == 2);
  994. LilvIter* sp_iter = lilv_scale_points_begin(points);
  995. const LilvScalePoint* sp0 = lilv_scale_points_get(points, sp_iter);
  996. TEST_ASSERT(sp0);
  997. sp_iter = lilv_scale_points_next(points, sp_iter);
  998. const LilvScalePoint* sp1 = lilv_scale_points_get(points, sp_iter);
  999. TEST_ASSERT(sp1);
  1000. TEST_ASSERT(
  1001. ((!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp0)), "Sin")
  1002. && lilv_node_as_float(lilv_scale_point_get_value(sp0)) == 3)
  1003. &&
  1004. (!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp1)), "Cos")
  1005. && lilv_node_as_float(lilv_scale_point_get_value(sp1)) == 4))
  1006. ||
  1007. ((!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp0)), "Cos")
  1008. && lilv_node_as_float(lilv_scale_point_get_value(sp0)) == 4)
  1009. &&
  1010. (!strcmp(lilv_node_as_string(lilv_scale_point_get_label(sp1)), "Sin")
  1011. && lilv_node_as_float(lilv_scale_point_get_value(sp1)) == 3)));
  1012. LilvNode* homepage_p = lilv_new_uri(world, "http://usefulinc.com/ns/doap#homepage");
  1013. LilvNodes* homepages = lilv_plugin_get_value(plug, homepage_p);
  1014. TEST_ASSERT(lilv_nodes_size(homepages) == 1);
  1015. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(homepages)),
  1016. "http://example.org/someplug"));
  1017. LilvNode *min, *max, *def;
  1018. lilv_port_get_range(plug, p, &def, &min, &max);
  1019. TEST_ASSERT(def);
  1020. TEST_ASSERT(min);
  1021. TEST_ASSERT(max);
  1022. TEST_ASSERT(lilv_node_as_float(def) == 0.5);
  1023. TEST_ASSERT(lilv_node_as_float(min) == -1.0);
  1024. TEST_ASSERT(lilv_node_as_float(max) == 1.0);
  1025. LilvNode* integer_prop = lilv_new_uri(world, "http://lv2plug.in/ns/lv2core#integer");
  1026. LilvNode* toggled_prop = lilv_new_uri(world, "http://lv2plug.in/ns/lv2core#toggled");
  1027. TEST_ASSERT(lilv_port_has_property(plug, p, integer_prop));
  1028. TEST_ASSERT(!lilv_port_has_property(plug, p, toggled_prop));
  1029. const LilvPort* ep = lilv_plugin_get_port_by_index(plug, 1);
  1030. LilvNode* event_type = lilv_new_uri(world, "http://example.org/event");
  1031. LilvNode* event_type_2 = lilv_new_uri(world, "http://example.org/otherEvent");
  1032. LilvNode* atom_event = lilv_new_uri(world, "http://example.org/atomEvent");
  1033. TEST_ASSERT(lilv_port_supports_event(plug, ep, event_type));
  1034. TEST_ASSERT(!lilv_port_supports_event(plug, ep, event_type_2));
  1035. TEST_ASSERT(lilv_port_supports_event(plug, ep, atom_event));
  1036. LilvNode* name_p = lilv_new_uri(world, "http://lv2plug.in/ns/lv2core#name");
  1037. LilvNodes* names = lilv_port_get_value(plug, p, name_p);
  1038. TEST_ASSERT(lilv_nodes_size(names) == 1);
  1039. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(names)),
  1040. "store"));
  1041. lilv_nodes_free(names);
  1042. LilvNode* true_val = lilv_new_bool(world, true);
  1043. LilvNode* false_val = lilv_new_bool(world, false);
  1044. TEST_ASSERT(!lilv_node_equals(true_val, false_val));
  1045. lilv_world_set_option(world, LILV_OPTION_FILTER_LANG, false_val);
  1046. names = lilv_port_get_value(plug, p, name_p);
  1047. TEST_ASSERT(lilv_nodes_size(names) == 4);
  1048. lilv_nodes_free(names);
  1049. lilv_world_set_option(world, LILV_OPTION_FILTER_LANG, true_val);
  1050. lilv_node_free(false_val);
  1051. lilv_node_free(true_val);
  1052. names = lilv_port_get_value(plug, ep, name_p);
  1053. TEST_ASSERT(lilv_nodes_size(names) == 1);
  1054. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(names)),
  1055. "Event Input"));
  1056. const LilvPort* ap_in = lilv_plugin_get_port_by_index(plug, 2);
  1057. TEST_ASSERT(lilv_port_is_a(plug, ap_in, in_class));
  1058. TEST_ASSERT(!lilv_port_is_a(plug, ap_in, out_class));
  1059. TEST_ASSERT(lilv_port_is_a(plug, ap_in, audio_class));
  1060. TEST_ASSERT(!lilv_port_is_a(plug, ap_in, control_class));
  1061. const LilvPort* ap_out = lilv_plugin_get_port_by_index(plug, 3);
  1062. TEST_ASSERT(lilv_port_is_a(plug, ap_out, out_class));
  1063. TEST_ASSERT(!lilv_port_is_a(plug, ap_out, in_class));
  1064. TEST_ASSERT(lilv_port_is_a(plug, ap_out, audio_class));
  1065. TEST_ASSERT(!lilv_port_is_a(plug, ap_out, control_class));
  1066. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, in_class , NULL) == 1);
  1067. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class , in_class , NULL) == 1);
  1068. TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class , out_class, NULL) == 1);
  1069. lilv_nodes_free(names);
  1070. lilv_node_free(name_p);
  1071. lilv_node_free(integer_prop);
  1072. lilv_node_free(toggled_prop);
  1073. lilv_node_free(event_type);
  1074. lilv_node_free(event_type_2);
  1075. lilv_node_free(atom_event);
  1076. lilv_node_free(min);
  1077. lilv_node_free(max);
  1078. lilv_node_free(def);
  1079. lilv_node_free(homepage_p);
  1080. lilv_nodes_free(homepages);
  1081. lilv_scale_points_free(points);
  1082. lilv_node_free(control_class);
  1083. lilv_node_free(audio_class);
  1084. lilv_node_free(out_class);
  1085. lilv_node_free(in_class);
  1086. cleanup_uris();
  1087. return 1;
  1088. }
  1089. /*****************************************************************************/
  1090. static unsigned
  1091. ui_supported(const char* container_type_uri,
  1092. const char* ui_type_uri)
  1093. {
  1094. return !strcmp(container_type_uri, ui_type_uri);
  1095. }
  1096. static int
  1097. test_ui(void)
  1098. {
  1099. if (!start_bundle(MANIFEST_PREFIXES
  1100. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  1101. BUNDLE_PREFIXES PREFIX_LV2UI
  1102. ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
  1103. PLUGIN_NAME("Test plugin") " ; "
  1104. LICENSE_GPL " ; "
  1105. "lv2:optionalFeature lv2:hardRTCapable ; "
  1106. "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
  1107. "lv2ui:ui :ui , :ui2 , :ui3 , :ui4 ; "
  1108. "doap:maintainer [ foaf:name \"David Robillard\" ; "
  1109. " foaf:homepage <http://drobilla.net> ; foaf:mbox <mailto:d@drobilla.net> ] ; "
  1110. "lv2:port [ "
  1111. " a lv2:ControlPort ; a lv2:InputPort ; "
  1112. " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
  1113. " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 "
  1114. "] , [ "
  1115. " a lv2:ControlPort ; a lv2:InputPort ; "
  1116. " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; "
  1117. " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 "
  1118. "] , [ "
  1119. " a lv2:ControlPort ; a lv2:OutputPort ; "
  1120. " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
  1121. " lv2:portProperty lv2:reportsLatency "
  1122. "] .\n"
  1123. ":ui a lv2ui:GtkUI ; "
  1124. " lv2ui:requiredFeature lv2ui:makeResident ; "
  1125. " lv2ui:binary <ui" SHLIB_EXT "> ; "
  1126. " lv2ui:optionalFeature lv2ui:ext_presets . "
  1127. ":ui2 a lv2ui:GtkUI ; lv2ui:binary <ui2" SHLIB_EXT "> . "
  1128. ":ui3 a lv2ui:GtkUI ; lv2ui:binary <ui3" SHLIB_EXT "> . "
  1129. ":ui4 a lv2ui:GtkUI ; lv2ui:binary <ui4" SHLIB_EXT "> . "))
  1130. return 0;
  1131. init_uris();
  1132. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  1133. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  1134. TEST_ASSERT(plug);
  1135. LilvUIs* uis = lilv_plugin_get_uis(plug);
  1136. TEST_ASSERT(lilv_uis_size(uis) == 4);
  1137. const LilvUI* ui0 = lilv_uis_get(uis, lilv_uis_begin(uis));
  1138. TEST_ASSERT(ui0);
  1139. LilvNode* ui_uri = lilv_new_uri(world, "http://example.org/ui");
  1140. LilvNode* ui2_uri = lilv_new_uri(world, "http://example.org/ui3");
  1141. LilvNode* ui3_uri = lilv_new_uri(world, "http://example.org/ui4");
  1142. LilvNode* noui_uri = lilv_new_uri(world, "http://example.org/notaui");
  1143. const LilvUI* ui0_2 = lilv_uis_get_by_uri(uis, ui_uri);
  1144. TEST_ASSERT(ui0 == ui0_2);
  1145. TEST_ASSERT(lilv_node_equals(lilv_ui_get_uri(ui0_2), ui_uri));
  1146. const LilvUI* ui2 = lilv_uis_get_by_uri(uis, ui2_uri);
  1147. TEST_ASSERT(ui2 != ui0);
  1148. const LilvUI* ui3 = lilv_uis_get_by_uri(uis, ui3_uri);
  1149. TEST_ASSERT(ui3 != ui0);
  1150. const LilvUI* noui = lilv_uis_get_by_uri(uis, noui_uri);
  1151. TEST_ASSERT(noui == NULL);
  1152. const LilvNodes* classes = lilv_ui_get_classes(ui0);
  1153. TEST_ASSERT(lilv_nodes_size(classes) == 1);
  1154. LilvNode* ui_class_uri = lilv_new_uri(world,
  1155. "http://lv2plug.in/ns/extensions/ui#GtkUI");
  1156. LilvNode* unknown_ui_class_uri = lilv_new_uri(world,
  1157. "http://example.org/mysteryUI");
  1158. TEST_ASSERT(lilv_node_equals(lilv_nodes_get_first(classes), ui_class_uri));
  1159. TEST_ASSERT(lilv_ui_is_a(ui0, ui_class_uri));
  1160. const LilvNode* ui_type = NULL;
  1161. TEST_ASSERT(lilv_ui_is_supported(ui0, ui_supported, ui_class_uri, &ui_type));
  1162. TEST_ASSERT(!lilv_ui_is_supported(ui0, ui_supported, unknown_ui_class_uri, &ui_type));
  1163. TEST_ASSERT(lilv_node_equals(ui_type, ui_class_uri));
  1164. const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
  1165. const LilvNode* ui_bundle_uri = lilv_ui_get_bundle_uri(ui0);
  1166. TEST_ASSERT(lilv_node_equals(plug_bundle_uri, ui_bundle_uri));
  1167. char* ui_binary_uri_str = (char*)malloc(TEST_PATH_MAX);
  1168. snprintf(ui_binary_uri_str, TEST_PATH_MAX, "%s%s",
  1169. lilv_node_as_string(plug_bundle_uri), "ui" SHLIB_EXT);
  1170. const LilvNode* ui_binary_uri = lilv_ui_get_binary_uri(ui0);
  1171. LilvNode* expected_uri = lilv_new_uri(world, ui_binary_uri_str);
  1172. TEST_ASSERT(lilv_node_equals(expected_uri, ui_binary_uri));
  1173. free(ui_binary_uri_str);
  1174. lilv_node_free(unknown_ui_class_uri);
  1175. lilv_node_free(ui_class_uri);
  1176. lilv_node_free(ui_uri);
  1177. lilv_node_free(ui2_uri);
  1178. lilv_node_free(ui3_uri);
  1179. lilv_node_free(noui_uri);
  1180. lilv_node_free(expected_uri);
  1181. lilv_uis_free(uis);
  1182. cleanup_uris();
  1183. return 1;
  1184. }
  1185. /*****************************************************************************/
  1186. uint32_t atom_Float = 0;
  1187. float in = 1.0;
  1188. float out = 42.0;
  1189. static const void*
  1190. get_port_value(const char* port_symbol,
  1191. void* user_data,
  1192. uint32_t* size,
  1193. uint32_t* type)
  1194. {
  1195. if (!strcmp(port_symbol, "input")) {
  1196. *size = sizeof(float);
  1197. *type = atom_Float;
  1198. return &in;
  1199. } else if (!strcmp(port_symbol, "output")) {
  1200. *size = sizeof(float);
  1201. *type = atom_Float;
  1202. return &out;
  1203. } else {
  1204. fprintf(stderr, "error: get_port_value for nonexistent port `%s'\n",
  1205. port_symbol);
  1206. *size = *type = 0;
  1207. return NULL;
  1208. }
  1209. }
  1210. static void
  1211. set_port_value(const char* port_symbol,
  1212. void* user_data,
  1213. const void* value,
  1214. uint32_t size,
  1215. uint32_t type)
  1216. {
  1217. if (!strcmp(port_symbol, "input")) {
  1218. in = *(const float*)value;
  1219. } else if (!strcmp(port_symbol, "output")) {
  1220. out = *(const float*)value;
  1221. } else {
  1222. fprintf(stderr, "error: set_port_value for nonexistent port `%s'\n",
  1223. port_symbol);
  1224. }
  1225. }
  1226. char** uris = NULL;
  1227. size_t n_uris = 0;
  1228. static LV2_URID
  1229. map_uri(LV2_URID_Map_Handle handle,
  1230. const char* uri)
  1231. {
  1232. for (size_t i = 0; i < n_uris; ++i) {
  1233. if (!strcmp(uris[i], uri)) {
  1234. return i + 1;
  1235. }
  1236. }
  1237. assert(serd_uri_string_has_scheme((const uint8_t*)uri));
  1238. uris = (char**)realloc(uris, ++n_uris * sizeof(char*));
  1239. uris[n_uris - 1] = lilv_strdup(uri);
  1240. return n_uris;
  1241. }
  1242. static const char*
  1243. unmap_uri(LV2_URID_Map_Handle handle,
  1244. LV2_URID urid)
  1245. {
  1246. if (urid > 0 && urid <= n_uris) {
  1247. return uris[urid - 1];
  1248. }
  1249. return NULL;
  1250. }
  1251. static char* temp_dir = NULL;
  1252. static char*
  1253. lilv_make_path(LV2_State_Make_Path_Handle handle,
  1254. const char* path)
  1255. {
  1256. return lilv_path_join(temp_dir, path);
  1257. }
  1258. static int
  1259. test_state(void)
  1260. {
  1261. init_world();
  1262. uint8_t* abs_bundle = (uint8_t*)lilv_path_absolute(LILV_TEST_BUNDLE);
  1263. SerdNode bundle = serd_node_new_file_uri(abs_bundle, 0, 0, true);
  1264. LilvNode* bundle_uri = lilv_new_uri(world, (const char*)bundle.buf);
  1265. LilvNode* plugin_uri = lilv_new_uri(world,
  1266. "http://example.org/lilv-test-plugin");
  1267. lilv_world_load_bundle(world, bundle_uri);
  1268. free(abs_bundle);
  1269. serd_node_free(&bundle);
  1270. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  1271. const LilvPlugin* plugin = lilv_plugins_get_by_uri(plugins, plugin_uri);
  1272. TEST_ASSERT(plugin);
  1273. LV2_URID_Map map = { NULL, map_uri };
  1274. LV2_Feature map_feature = { LV2_URID_MAP_URI, &map };
  1275. LV2_URID_Unmap unmap = { NULL, unmap_uri };
  1276. LV2_Feature unmap_feature = { LV2_URID_UNMAP_URI, &unmap };
  1277. const LV2_Feature* features[] = { &map_feature, &unmap_feature, NULL };
  1278. atom_Float = map.map(map.handle, "http://lv2plug.in/ns/ext/atom#Float");
  1279. LilvNode* num = lilv_new_int(world, 5);
  1280. LilvState* nostate = lilv_state_new_from_file(world, &map, num, "/junk");
  1281. TEST_ASSERT(!nostate);
  1282. LilvInstance* instance = lilv_plugin_instantiate(plugin, 48000.0, features);
  1283. TEST_ASSERT(instance);
  1284. lilv_instance_activate(instance);
  1285. lilv_instance_connect_port(instance, 0, &in);
  1286. lilv_instance_connect_port(instance, 1, &out);
  1287. lilv_instance_run(instance, 1);
  1288. TEST_ASSERT(in == 1.0);
  1289. TEST_ASSERT(out == 1.0);
  1290. temp_dir = lilv_realpath("temp");
  1291. const char* file_dir = NULL;
  1292. char* copy_dir = NULL;
  1293. char* link_dir = NULL;
  1294. char* save_dir = NULL;
  1295. // Get instance state state
  1296. LilvState* state = lilv_state_new_from_instance(
  1297. plugin, instance, &map,
  1298. file_dir, copy_dir, link_dir, save_dir,
  1299. get_port_value, world, 0, NULL);
  1300. // Get another instance state
  1301. LilvState* state2 = lilv_state_new_from_instance(
  1302. plugin, instance, &map,
  1303. file_dir, copy_dir, link_dir, save_dir,
  1304. get_port_value, world, 0, NULL);
  1305. // Ensure they are equal
  1306. TEST_ASSERT(lilv_state_equals(state, state2));
  1307. // Check that we can't delete unsaved state
  1308. TEST_ASSERT(lilv_state_delete(world, state));
  1309. // Check that state has no URI
  1310. TEST_ASSERT(!lilv_state_get_uri(state));
  1311. // Check that we can't save a state with no URI
  1312. char* bad_state_str = lilv_state_to_string(
  1313. world, &map, &unmap, state, NULL, NULL);
  1314. TEST_ASSERT(!bad_state_str);
  1315. // Check that we can't restore the NULL string (and it doesn't crash)
  1316. LilvState* bad_state = lilv_state_new_from_string(world, &map, NULL);
  1317. TEST_ASSERT(!bad_state);
  1318. // Save state to a string
  1319. char* state1_str = lilv_state_to_string(
  1320. world, &map, &unmap, state, "http://example.org/state1", NULL);
  1321. // Restore from string
  1322. LilvState* from_str = lilv_state_new_from_string(world, &map, state1_str);
  1323. // Ensure they are equal
  1324. TEST_ASSERT(lilv_state_equals(state, from_str));
  1325. free(state1_str);
  1326. const LilvNode* state_plugin_uri = lilv_state_get_plugin_uri(state);
  1327. TEST_ASSERT(lilv_node_equals(state_plugin_uri, plugin_uri));
  1328. // Tinker with the label of the first state
  1329. TEST_ASSERT(lilv_state_get_label(state) == NULL);
  1330. lilv_state_set_label(state, "Test State Old Label");
  1331. TEST_ASSERT(!strcmp(lilv_state_get_label(state), "Test State Old Label"));
  1332. lilv_state_set_label(state, "Test State");
  1333. TEST_ASSERT(!strcmp(lilv_state_get_label(state), "Test State"));
  1334. TEST_ASSERT(!lilv_state_equals(state, state2)); // Label changed
  1335. // Run and get a new instance state (which should now differ)
  1336. lilv_instance_run(instance, 1);
  1337. LilvState* state3 = lilv_state_new_from_instance(
  1338. plugin, instance, &map,
  1339. file_dir, copy_dir, link_dir, save_dir,
  1340. get_port_value, world, 0, NULL);
  1341. TEST_ASSERT(!lilv_state_equals(state2, state3)); // num_runs changed
  1342. // Restore instance state to original state
  1343. lilv_state_restore(state2, instance, set_port_value, NULL, 0, NULL);
  1344. // Take a new snapshot and ensure it matches the set state
  1345. LilvState* state4 = lilv_state_new_from_instance(
  1346. plugin, instance, &map,
  1347. file_dir, copy_dir, link_dir, save_dir,
  1348. get_port_value, world, 0, NULL);
  1349. TEST_ASSERT(lilv_state_equals(state2, state4));
  1350. // Save state to a directory
  1351. int ret = lilv_state_save(world, &map, &unmap, state, NULL,
  1352. "state/state.lv2", "state.ttl");
  1353. TEST_ASSERT(!ret);
  1354. // Load state from directory
  1355. LilvState* state5 = lilv_state_new_from_file(world, &map, NULL,
  1356. "state/state.lv2/state.ttl");
  1357. TEST_ASSERT(lilv_state_equals(state, state5)); // Round trip accuracy
  1358. // Save state with URI to a directory
  1359. const char* state_uri = "http://example.org/state";
  1360. ret = lilv_state_save(world, &map, &unmap, state, state_uri,
  1361. "state/state6.lv2", "state6.ttl");
  1362. TEST_ASSERT(!ret);
  1363. // Load default bundle into world and load state from it
  1364. uint8_t* state6_path = (uint8_t*)lilv_path_absolute("state/state6.lv2/");
  1365. SerdNode state6_uri = serd_node_new_file_uri(state6_path, 0, 0, true);
  1366. LilvNode* test_state_bundle = lilv_new_uri(world, (const char*)state6_uri.buf);
  1367. LilvNode* test_state_node = lilv_new_uri(world, state_uri);
  1368. lilv_world_load_bundle(world, test_state_bundle);
  1369. lilv_world_load_resource(world, test_state_node);
  1370. serd_node_free(&state6_uri);
  1371. free(state6_path);
  1372. LilvState* state6 = lilv_state_new_from_world(world, &map, test_state_node);
  1373. TEST_ASSERT(lilv_state_equals(state, state6)); // Round trip accuracy
  1374. // Check that loaded state has correct URI
  1375. TEST_ASSERT(lilv_state_get_uri(state6));
  1376. TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_state_get_uri(state6)),
  1377. state_uri));
  1378. lilv_world_unload_resource(world, test_state_node);
  1379. lilv_world_unload_bundle(world, test_state_bundle);
  1380. LilvState* state6_2 = lilv_state_new_from_world(world, &map, test_state_node);
  1381. TEST_ASSERT(!state6_2); // No longer present
  1382. lilv_state_free(state6_2);
  1383. lilv_node_free(test_state_bundle);
  1384. lilv_node_free(test_state_node);
  1385. unsetenv("LV2_STATE_BUNDLE");
  1386. // Make directories and test files support
  1387. mkdir("temp", 0700);
  1388. file_dir = temp_dir;
  1389. mkdir("files", 0700);
  1390. copy_dir = lilv_realpath("files");
  1391. mkdir("links", 0700);
  1392. link_dir = lilv_realpath("links");
  1393. LV2_State_Make_Path make_path = { NULL, lilv_make_path };
  1394. LV2_Feature make_path_feature = { LV2_STATE__makePath, &make_path };
  1395. const LV2_Feature* ffeatures[] = { &make_path_feature, &map_feature, NULL };
  1396. lilv_instance_deactivate(instance);
  1397. lilv_instance_free(instance);
  1398. instance = lilv_plugin_instantiate(plugin, 48000.0, ffeatures);
  1399. lilv_instance_activate(instance);
  1400. lilv_instance_connect_port(instance, 0, &in);
  1401. lilv_instance_connect_port(instance, 1, &out);
  1402. lilv_instance_run(instance, 1);
  1403. // Test instantiating twice
  1404. LilvInstance* instance2 = lilv_plugin_instantiate(plugin, 48000.0, ffeatures);
  1405. if (!instance2) {
  1406. fatal_error("Failed to create multiple instances of <%s>\n",
  1407. lilv_node_as_uri(state_plugin_uri));
  1408. return 0;
  1409. }
  1410. lilv_instance_free(instance2);
  1411. // Get instance state state
  1412. LilvState* fstate = lilv_state_new_from_instance(
  1413. plugin, instance, &map,
  1414. file_dir, copy_dir, link_dir, "state/fstate.lv2",
  1415. get_port_value, world, 0, ffeatures);
  1416. // Get another instance state
  1417. LilvState* fstate2 = lilv_state_new_from_instance(
  1418. plugin, instance, &map,
  1419. file_dir, copy_dir, link_dir, "state/fstate2.lv2",
  1420. get_port_value, world, 0, ffeatures);
  1421. // Should be identical
  1422. TEST_ASSERT(lilv_state_equals(fstate, fstate2));
  1423. // Run, writing more to rec file
  1424. lilv_instance_run(instance, 2);
  1425. // Get yet another instance state
  1426. LilvState* fstate3 = lilv_state_new_from_instance(
  1427. plugin, instance, &map, file_dir, copy_dir, link_dir, "state/fstate3.lv2",
  1428. get_port_value, world, 0, ffeatures);
  1429. // Should be different
  1430. TEST_ASSERT(!lilv_state_equals(fstate, fstate3));
  1431. // Save state to a directory
  1432. ret = lilv_state_save(world, &map, &unmap, fstate, NULL,
  1433. "state/fstate.lv2", "fstate.ttl");
  1434. TEST_ASSERT(!ret);
  1435. // Load state from directory
  1436. LilvState* fstate4 = lilv_state_new_from_file(world, &map, NULL,
  1437. "state/fstate.lv2/fstate.ttl");
  1438. TEST_ASSERT(lilv_state_equals(fstate, fstate4)); // Round trip accuracy
  1439. // Restore instance state to loaded state
  1440. lilv_state_restore(fstate4, instance, set_port_value, NULL, 0, ffeatures);
  1441. // Take a new snapshot and ensure it matches
  1442. LilvState* fstate5 = lilv_state_new_from_instance(
  1443. plugin, instance, &map,
  1444. file_dir, copy_dir, link_dir, "state/fstate5.lv2",
  1445. get_port_value, world, 0, ffeatures);
  1446. TEST_ASSERT(lilv_state_equals(fstate3, fstate5));
  1447. // Save state to a (different) directory again
  1448. ret = lilv_state_save(world, &map, &unmap, fstate, NULL,
  1449. "state/fstate6.lv2", "fstate6.ttl");
  1450. TEST_ASSERT(!ret);
  1451. // Reload it and ensure it's identical to the other loaded version
  1452. LilvState* fstate6 = lilv_state_new_from_file(world, &map, NULL,
  1453. "state/fstate6.lv2/fstate6.ttl");
  1454. TEST_ASSERT(lilv_state_equals(fstate4, fstate6));
  1455. // Run, changing rec file (without changing size)
  1456. lilv_instance_run(instance, 3);
  1457. // Take a new snapshot
  1458. LilvState* fstate7 = lilv_state_new_from_instance(
  1459. plugin, instance, &map,
  1460. file_dir, copy_dir, link_dir, "state/fstate7.lv2",
  1461. get_port_value, world, 0, ffeatures);
  1462. TEST_ASSERT(!lilv_state_equals(fstate6, fstate7));
  1463. // Save the changed state to a (different) directory again
  1464. ret = lilv_state_save(world, &map, &unmap, fstate7, NULL,
  1465. "state/fstate7.lv2", "fstate7.ttl");
  1466. TEST_ASSERT(!ret);
  1467. // Reload it and ensure it's changed
  1468. LilvState* fstate72 = lilv_state_new_from_file(world, &map, NULL,
  1469. "state/fstate7.lv2/fstate7.ttl");
  1470. TEST_ASSERT(lilv_state_equals(fstate72, fstate7));
  1471. TEST_ASSERT(!lilv_state_equals(fstate6, fstate72));
  1472. // Delete saved state
  1473. lilv_state_delete(world, fstate7);
  1474. lilv_instance_deactivate(instance);
  1475. lilv_instance_free(instance);
  1476. lilv_node_free(num);
  1477. lilv_state_free(state);
  1478. lilv_state_free(from_str);
  1479. lilv_state_free(state2);
  1480. lilv_state_free(state3);
  1481. lilv_state_free(state4);
  1482. lilv_state_free(state5);
  1483. lilv_state_free(state6);
  1484. lilv_state_free(fstate);
  1485. lilv_state_free(fstate2);
  1486. lilv_state_free(fstate3);
  1487. lilv_state_free(fstate4);
  1488. lilv_state_free(fstate5);
  1489. lilv_state_free(fstate6);
  1490. lilv_state_free(fstate7);
  1491. lilv_state_free(fstate72);
  1492. // Free URI map
  1493. for (size_t i = 0; i < n_uris; ++i) {
  1494. free(uris[i]);
  1495. }
  1496. free(uris);
  1497. n_uris = 0;
  1498. lilv_node_free(plugin_uri);
  1499. lilv_node_free(bundle_uri);
  1500. free(link_dir);
  1501. free(copy_dir);
  1502. free(temp_dir);
  1503. cleanup_uris();
  1504. return 1;
  1505. }
  1506. /*****************************************************************************/
  1507. static int
  1508. test_bad_port_symbol(void)
  1509. {
  1510. if (!start_bundle(MANIFEST_PREFIXES
  1511. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  1512. BUNDLE_PREFIXES PREFIX_LV2EV
  1513. ":plug a lv2:Plugin ; "
  1514. PLUGIN_NAME("Test plugin") " ; "
  1515. LICENSE_GPL " ; "
  1516. "doap:homepage <http://example.org/someplug> ; "
  1517. "lv2:port [ "
  1518. " a lv2:ControlPort ; a lv2:InputPort ; "
  1519. " lv2:index 0 ; lv2:symbol \"0invalid\" ;"
  1520. " lv2:name \"Invalid\" ; "
  1521. "] ."))
  1522. return 0;
  1523. init_uris();
  1524. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  1525. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  1526. uint32_t n_ports = lilv_plugin_get_num_ports(plug);
  1527. TEST_ASSERT(n_ports == 0);
  1528. cleanup_uris();
  1529. return 1;
  1530. }
  1531. /*****************************************************************************/
  1532. static int
  1533. test_bad_port_index(void)
  1534. {
  1535. if (!start_bundle(MANIFEST_PREFIXES
  1536. ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n",
  1537. BUNDLE_PREFIXES PREFIX_LV2EV
  1538. ":plug a lv2:Plugin ; "
  1539. PLUGIN_NAME("Test plugin") " ; "
  1540. LICENSE_GPL " ; "
  1541. "doap:homepage <http://example.org/someplug> ; "
  1542. "lv2:port [ "
  1543. " a lv2:ControlPort ; a lv2:InputPort ; "
  1544. " lv2:index \"notaninteger\" ; lv2:symbol \"invalid\" ;"
  1545. " lv2:name \"Invalid\" ; "
  1546. "] ."))
  1547. return 0;
  1548. init_uris();
  1549. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  1550. const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value);
  1551. uint32_t n_ports = lilv_plugin_get_num_ports(plug);
  1552. TEST_ASSERT(n_ports == 0);
  1553. cleanup_uris();
  1554. return 1;
  1555. }
  1556. /*****************************************************************************/
  1557. static int
  1558. test_string(void)
  1559. {
  1560. char* s = NULL;
  1561. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar")), "/foo")); free(s);
  1562. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar/")), "/foo")); free(s);
  1563. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar/")), "/foo")); free(s);
  1564. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar//")), "/foo")); free(s);
  1565. TEST_ASSERT(!strcmp((s = lilv_dirname("foo")), ".")); free(s);
  1566. TEST_ASSERT(!strcmp((s = lilv_dirname("/foo")), "/")); free(s);
  1567. TEST_ASSERT(!strcmp((s = lilv_dirname("/")), "/")); free(s);
  1568. TEST_ASSERT(!strcmp((s = lilv_dirname("//")), "/")); free(s);
  1569. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b", "/a/")), "b")); free(s);
  1570. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a", "/b/c/")), "/a")); free(s);
  1571. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/")), "../c")); free(s);
  1572. TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/e/")), "../../c")); free(s);
  1573. TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "b")), "/a/b")); free(s);
  1574. TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "/b")), "/a/b")); free(s);
  1575. TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "/b")), "/a/b")); free(s);
  1576. TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b")); free(s);
  1577. TEST_ASSERT(!strcmp((s = lilv_path_join("/a", NULL)), "/a/")); free(s);
  1578. #ifndef _WIN32
  1579. setenv("LILV_TEST_1", "test", 1);
  1580. char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL);
  1581. TEST_ASSERT(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test")); free(s);
  1582. TEST_ASSERT(!strcmp((s = lilv_expand("~")), getenv("HOME"))); free(s);
  1583. TEST_ASSERT(!strcmp((s = lilv_expand("~foo")), "~foo")); free(s);
  1584. TEST_ASSERT(!strcmp((s = lilv_expand("~/foo")), home_foo)); free(s);
  1585. TEST_ASSERT(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR")); free(s);
  1586. free(home_foo);
  1587. unsetenv("LILV_TEST_1");
  1588. #endif
  1589. return 1;
  1590. }
  1591. /*****************************************************************************/
  1592. static int
  1593. test_world(void)
  1594. {
  1595. if (!init_world()) {
  1596. return 0;
  1597. }
  1598. LilvNode* num = lilv_new_int(world, 4);
  1599. LilvNode* uri = lilv_new_uri(world, "http://example.org/object");
  1600. LilvNodes* matches = lilv_world_find_nodes(world, num, NULL, NULL);
  1601. TEST_ASSERT(!matches);
  1602. matches = lilv_world_find_nodes(world, NULL, num, NULL);
  1603. TEST_ASSERT(!matches);
  1604. matches = lilv_world_find_nodes(world, NULL, uri, NULL);
  1605. TEST_ASSERT(!matches);
  1606. lilv_node_free(uri);
  1607. lilv_node_free(num);
  1608. lilv_world_unload_bundle(world, NULL);
  1609. return 1;
  1610. }
  1611. /*****************************************************************************/
  1612. /* add tests here */
  1613. static struct TestCase tests[] = {
  1614. TEST_CASE(util),
  1615. TEST_CASE(value),
  1616. TEST_CASE(verify),
  1617. TEST_CASE(no_verify),
  1618. TEST_CASE(discovery),
  1619. TEST_CASE(lv2_path),
  1620. TEST_CASE(classes),
  1621. TEST_CASE(plugin),
  1622. TEST_CASE(project),
  1623. TEST_CASE(no_author),
  1624. TEST_CASE(project_no_author),
  1625. TEST_CASE(preset),
  1626. TEST_CASE(prototype),
  1627. TEST_CASE(port),
  1628. TEST_CASE(ui),
  1629. TEST_CASE(bad_port_symbol),
  1630. TEST_CASE(bad_port_index),
  1631. TEST_CASE(bad_port_index),
  1632. TEST_CASE(string),
  1633. TEST_CASE(world),
  1634. TEST_CASE(state),
  1635. { NULL, NULL }
  1636. };
  1637. static void
  1638. run_tests(void)
  1639. {
  1640. int i;
  1641. for (i = 0; tests[i].title; i++) {
  1642. printf("*** Test %s\n", tests[i].title);
  1643. if (!tests[i].func()) {
  1644. printf("\nTest failed\n");
  1645. /* test case that wasn't able to be executed at all counts as 1 test + 1 error */
  1646. error_count++;
  1647. test_count++;
  1648. }
  1649. unload_bundle();
  1650. cleanup();
  1651. }
  1652. }
  1653. int
  1654. main(int argc, char* argv[])
  1655. {
  1656. if (argc != 1) {
  1657. printf("Syntax: %s\n", argv[0]);
  1658. return 0;
  1659. }
  1660. setenv("LANG", "C", 1);
  1661. init_tests();
  1662. run_tests();
  1663. cleanup();
  1664. printf("\n*** Test Results: %d tests, %d errors\n\n", test_count, error_count);
  1665. return error_count ? 1 : 0;
  1666. }