diff options
-rw-r--r-- | src/filesystem.c | 22 | ||||
-rw-r--r-- | src/filesystem.h | 15 | ||||
-rw-r--r-- | test/lilv_test_utils.c | 32 | ||||
-rw-r--r-- | test/lilv_test_utils.h | 12 | ||||
-rw-r--r-- | test/test_bad_port_index.c | 6 | ||||
-rw-r--r-- | test/test_bad_port_symbol.c | 6 | ||||
-rw-r--r-- | test/test_classes.c | 7 | ||||
-rw-r--r-- | test/test_discovery.c | 5 | ||||
-rw-r--r-- | test/test_get_symbol.c | 5 | ||||
-rw-r--r-- | test/test_no_author.c | 5 | ||||
-rw-r--r-- | test/test_no_verify.c | 5 | ||||
-rw-r--r-- | test/test_plugin.c | 9 | ||||
-rw-r--r-- | test/test_port.c | 5 | ||||
-rw-r--r-- | test/test_preset.c | 5 | ||||
-rw-r--r-- | test/test_project.c | 5 | ||||
-rw-r--r-- | test/test_project_no_author.c | 6 | ||||
-rw-r--r-- | test/test_prototype.c | 5 | ||||
-rw-r--r-- | test/test_reload_bundle.c | 14 | ||||
-rw-r--r-- | test/test_ui.c | 6 | ||||
-rw-r--r-- | test/test_value.c | 5 | ||||
-rw-r--r-- | test/test_verify.c | 5 |
21 files changed, 136 insertions, 49 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index 38af498..03614ce 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -426,7 +426,7 @@ lilv_dir_for_each(const char* path, } char* -lilv_create_temporary_directory(const char* pattern) +lilv_create_temporary_directory_in(const char* pattern, const char* parent) { #ifdef _WIN32 static const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -438,13 +438,10 @@ lilv_create_temporary_directory(const char* pattern) return NULL; } - char* const tmpdir = lilv_temp_directory_path(); - char* const path_pattern = lilv_path_join(tmpdir, pattern); + char* const path_pattern = lilv_path_join(parent, pattern); const size_t path_pattern_len = strlen(path_pattern); char* const suffix = path_pattern + path_pattern_len - 6; - free(tmpdir); - for (unsigned attempt = 0; attempt < 128; ++attempt) { for (unsigned i = 0; i < 6; ++i) { suffix[i] = chars[rand() % n_chars]; @@ -457,14 +454,23 @@ lilv_create_temporary_directory(const char* pattern) return NULL; #else - char* const tmpdir = lilv_temp_directory_path(); - char* const path_pattern = lilv_path_join(tmpdir, pattern); + char* const path_pattern = lilv_path_join(parent, pattern); - free(tmpdir); return mkdtemp(path_pattern); // NOLINT (not a leak) #endif } +char* +lilv_create_temporary_directory(const char* pattern) +{ + char* const tmpdir = lilv_temp_directory_path(); + char* const result = lilv_create_temporary_directory_in(pattern, tmpdir); + + free(tmpdir); + + return result; +} + int lilv_create_directories(const char* dir_path) { diff --git a/src/filesystem.h b/src/filesystem.h index a82ec6c..1a8dc68 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -146,12 +146,21 @@ lilv_dir_for_each(const char* path, void (*f)(const char* path, const char* name, void* data)); /** - Create a unique temporary directory. + Create a unique temporary directory in a specific directory. The last six characters of `pattern` must be `XXXXXX` and will be replaced with random characters. This works roughly like mkdtemp, except the pattern - should only be a directory name, not a full path. The returned path will be - in a suitable system temporary directory. + should only be a directory name, not a full path. The created path will be + a child of the given parent directory. +*/ +char* +lilv_create_temporary_directory_in(const char* pattern, const char* parent); + +/** + Create a unique temporary directory. + + This is like lilv_create_temporary_directory_in(), except it creates the + directory in the system temporary directory. */ char* lilv_create_temporary_directory(const char* pattern); diff --git a/test/lilv_test_utils.c b/test/lilv_test_utils.c index 783ed61..f658f1b 100644 --- a/test/lilv_test_utils.c +++ b/test/lilv_test_utils.c @@ -71,14 +71,19 @@ lilv_test_env_free(LilvTestEnv* env) } int -create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin) +create_bundle(LilvTestEnv* env, + const char* name, + const char* manifest, + const char* plugin) { { - static const char* const bundle_path = "/test_lv2_path/lilv-test.lv2"; + char* const test_dir = lilv_path_canonical(LILV_TEST_DIR); + char* const bundle_dir = lilv_path_join(test_dir, name); - char* const test_path = lilv_path_canonical(LILV_TEST_DIR); - env->test_bundle_path = lilv_strjoin(test_path, bundle_path, NULL); - lilv_free(test_path); + env->test_bundle_path = lilv_path_join(bundle_dir, ""); + + lilv_free(bundle_dir); + lilv_free(test_dir); } if (lilv_create_directories(env->test_bundle_path)) { @@ -92,11 +97,10 @@ create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin) SerdNode s = serd_node_new_file_uri( (const uint8_t*)env->test_bundle_path, NULL, NULL, true); - env->test_bundle_uri = lilv_strjoin((const char*)s.buf, "/", NULL); + env->test_bundle_uri = lilv_new_uri(env->world, (const char*)s.buf); env->test_manifest_path = - lilv_strjoin(env->test_bundle_path, "/manifest.ttl", NULL); - env->test_content_path = - lilv_strjoin(env->test_bundle_path, "/plugin.ttl", NULL); + lilv_path_join(env->test_bundle_path, "manifest.ttl"); + env->test_content_path = lilv_path_join(env->test_bundle_path, "plugin.ttl"); serd_node_free(&s); @@ -130,13 +134,17 @@ create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin) } int -start_bundle(LilvTestEnv* env, const char* manifest, const char* plugin) +start_bundle(LilvTestEnv* env, + const char* name, + const char* manifest, + const char* plugin) { - if (create_bundle(env, manifest, plugin)) { + if (create_bundle(env, name, manifest, plugin)) { return 1; } - lilv_world_load_all(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + return 0; } diff --git a/test/lilv_test_utils.h b/test/lilv_test_utils.h index b5cddb1..76d9bc1 100644 --- a/test/lilv_test_utils.h +++ b/test/lilv_test_utils.h @@ -55,7 +55,7 @@ typedef struct { LilvNode* plugin1_uri; LilvNode* plugin2_uri; char* test_bundle_path; - char* test_bundle_uri; + LilvNode* test_bundle_uri; char* test_manifest_path; char* test_content_path; int test_count; @@ -72,11 +72,17 @@ lilv_test_env_free(LilvTestEnv* env); // Create a bundle with a manifest and plugin files, without loading anything int -create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin); +create_bundle(LilvTestEnv* env, + const char* name, + const char* manifest, + const char* plugin); // Create a bundle with a manifest and plugin files, then load everything int -start_bundle(LilvTestEnv* env, const char* manifest, const char* plugin); +start_bundle(LilvTestEnv* env, + const char* name, + const char* manifest, + const char* plugin); // Remove the created bundle from the file system and free its paths in `env` void diff --git a/test/test_bad_port_index.c b/test/test_bad_port_index.c index b5d6547..985d74e 100644 --- a/test/test_bad_port_index.c +++ b/test/test_bad_port_index.c @@ -41,10 +41,14 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle( + env, "bad_port_index.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); diff --git a/test/test_bad_port_symbol.c b/test/test_bad_port_symbol.c index 8d7d69b..ae34ad0 100644 --- a/test/test_bad_port_symbol.c +++ b/test/test_bad_port_symbol.c @@ -41,10 +41,14 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle( + env, "bad_port_symbol.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); diff --git a/test/test_classes.c b/test/test_classes.c index 3e9e21b..332d847 100644 --- a/test/test_classes.c +++ b/test/test_classes.c @@ -41,10 +41,15 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + lilv_world_load_all(world); + + if (create_bundle(env, "classes.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPluginClass* plugin = lilv_world_get_plugin_class(world); const LilvPluginClasses* classes = lilv_world_get_plugin_classes(world); LilvPluginClasses* children = lilv_plugin_class_get_children(plugin); diff --git a/test/test_discovery.c b/test/test_discovery.c index a559970..f7f30ea 100644 --- a/test/test_discovery.c +++ b/test/test_discovery.c @@ -59,10 +59,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "discovery.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); assert(lilv_plugins_size(plugins) > 0); diff --git a/test/test_get_symbol.c b/test/test_get_symbol.c index 06707c1..5337c63 100644 --- a/test/test_get_symbol.c +++ b/test/test_get_symbol.c @@ -40,10 +40,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, manifest_ttl, plugin_ttl)) { + if (create_bundle(env, "get_symbol.lv2", manifest_ttl, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + LilvNode* plug_sym = lilv_world_get_symbol(world, env->plugin1_uri); LilvNode* path = lilv_new_uri(world, "http://example.org/foo"); LilvNode* path_sym = lilv_world_get_symbol(world, path); diff --git a/test/test_no_author.c b/test/test_no_author.c index fb05559..aa91198 100644 --- a/test/test_no_author.c +++ b/test/test_no_author.c @@ -63,10 +63,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "no_author.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_no_verify.c b/test/test_no_verify.c index cf063d1..e71c483 100644 --- a/test/test_no_verify.c +++ b/test/test_no_verify.c @@ -30,10 +30,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "no_verify.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); diff --git a/test/test_plugin.c b/test/test_plugin.c index a51c849..2a427dc 100644 --- a/test/test_plugin.c +++ b/test/test_plugin.c @@ -82,10 +82,15 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + lilv_world_load_all(world); + + if (create_bundle(env, "plugin.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); @@ -104,7 +109,7 @@ main(void) assert(!lilv_plugin_get_related(plug, NULL)); const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug); - assert(!strcmp(lilv_node_as_string(plug_bundle_uri), env->test_bundle_uri)); + assert(lilv_node_equals(plug_bundle_uri, env->test_bundle_uri)); const LilvNodes* data_uris = lilv_plugin_get_data_uris(plug); assert(lilv_nodes_size(data_uris) == 2); diff --git a/test/test_port.c b/test/test_port.c index 2c9db2f..3ea0abc 100644 --- a/test/test_port.c +++ b/test/test_port.c @@ -80,10 +80,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "port.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_preset.c b/test/test_preset.c index c66f72b..151b0e6 100644 --- a/test/test_preset.c +++ b/test/test_preset.c @@ -70,10 +70,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "preset.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_project.c b/test/test_project.c index b75f056..7da42bd 100644 --- a/test/test_project.c +++ b/test/test_project.c @@ -69,10 +69,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "project.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_project_no_author.c b/test/test_project_no_author.c index 7ac9369..3ee9c85 100644 --- a/test/test_project_no_author.c +++ b/test/test_project_no_author.c @@ -63,10 +63,14 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle( + env, "project_no_author.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_prototype.c b/test/test_prototype.c index 493a60a..10a3657 100644 --- a/test/test_prototype.c +++ b/test/test_prototype.c @@ -76,10 +76,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, manifest_ttl, plugin_ttl)) { + if (create_bundle(env, "prototype.lv2", manifest_ttl, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_reload_bundle.c b/test/test_reload_bundle.c index c48a295..a8f9044 100644 --- a/test/test_reload_bundle.c +++ b/test/test_reload_bundle.c @@ -29,8 +29,11 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; + lilv_world_load_all(world); + // Create a simple plugin bundle create_bundle(env, + "reload_bundle.lv2", ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n", ":plug a lv2:Plugin ; " @@ -39,8 +42,7 @@ main(void) lilv_world_load_specifications(world); // Load bundle - LilvNode* bundle_uri = lilv_new_uri(world, env->test_bundle_uri); - lilv_world_load_bundle(world, bundle_uri); + lilv_world_load_bundle(world, env->test_bundle_uri); // Check that plugin is present const LilvPlugins* plugins = lilv_world_get_all_plugins(world); @@ -53,11 +55,12 @@ main(void) lilv_node_free(name); // Unload bundle from world and delete it - lilv_world_unload_bundle(world, bundle_uri); + lilv_world_unload_bundle(world, env->test_bundle_uri); delete_bundle(env); // Create a new version of the same bundle, but with a different name create_bundle(env, + "test_reload_bundle.lv2", ":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT "> ; rdfs:seeAlso <plugin.ttl> .\n", ":plug a lv2:Plugin ; " @@ -67,7 +70,7 @@ main(void) assert(lilv_plugins_size(plugins) == 0); // Load new bundle - lilv_world_load_bundle(world, bundle_uri); + lilv_world_load_bundle(world, env->test_bundle_uri); // Check that plugin is present again and is the same LilvPlugin const LilvPlugin* plug2 = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); @@ -81,9 +84,8 @@ main(void) lilv_node_free(name2); // Load new bundle again (noop) - lilv_world_load_bundle(world, bundle_uri); + lilv_world_load_bundle(world, env->test_bundle_uri); - lilv_node_free(bundle_uri); delete_bundle(env); lilv_test_env_free(env); diff --git a/test/test_ui.c b/test/test_ui.c index e84b147..d14f54f 100644 --- a/test/test_ui.c +++ b/test/test_ui.c @@ -95,9 +95,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "ui.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); assert(plug); diff --git a/test/test_value.c b/test/test_value.c index e2a75cf..8061029 100644 --- a/test/test_value.c +++ b/test/test_value.c @@ -42,10 +42,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "value.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + LilvNode* uval = lilv_new_uri(world, "http://example.org"); LilvNode* sval = lilv_new_string(world, "Foo"); LilvNode* ival = lilv_new_int(world, 42); diff --git a/test/test_verify.c b/test/test_verify.c index 8f6b50f..d20712e 100644 --- a/test/test_verify.c +++ b/test/test_verify.c @@ -39,10 +39,13 @@ main(void) LilvTestEnv* const env = lilv_test_env_new(); LilvWorld* const world = env->world; - if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) { + if (create_bundle(env, "verify.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) { return 1; } + lilv_world_load_specifications(env->world); + lilv_world_load_bundle(env->world, env->test_bundle_uri); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri); |