summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-06-04 19:32:32 +0200
committerDavid Robillard <d@drobilla.net>2019-12-08 13:41:23 +0100
commitac562cafe4c94db6965c4f715e276b2acc82bef0 (patch)
treec00d522cb772193a5dae6c8959ee9a0facfdb027 /test
parent425af428afb969ec2562bdf269967778e067384d (diff)
downloadlilv-ac562cafe4c94db6965c4f715e276b2acc82bef0.tar.gz
lilv-ac562cafe4c94db6965c4f715e276b2acc82bef0.tar.bz2
lilv-ac562cafe4c94db6965c4f715e276b2acc82bef0.zip
Implement state:freePath feature
Diffstat (limited to 'test')
-rw-r--r--test/lilv_test.c12
-rw-r--r--test/test.lv2/test.c56
2 files changed, 46 insertions, 22 deletions
diff --git a/test/lilv_test.c b/test/lilv_test.c
index 7231c24..430187e 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -1572,6 +1572,12 @@ lilv_make_path(LV2_State_Make_Path_Handle handle,
return lilv_path_join(temp_dir, path);
}
+static void
+lilv_free_path(LV2_State_Free_Path_Handle handle, char* path)
+{
+ lilv_free(path);
+}
+
static int
test_state(void)
{
@@ -1768,7 +1774,11 @@ test_state(void)
LV2_State_Make_Path make_path = { NULL, lilv_make_path };
LV2_Feature make_path_feature = { LV2_STATE__makePath, &make_path };
- const LV2_Feature* ffeatures[] = { &make_path_feature, &map_feature, NULL };
+ LV2_State_Free_Path free_path = { NULL, lilv_free_path };
+ LV2_Feature free_path_feature = { LV2_STATE__freePath, &free_path };
+ const LV2_Feature* ffeatures[] = {
+ &make_path_feature, &map_feature, &free_path_feature, NULL
+ };
lilv_instance_deactivate(instance);
lilv_instance_free(instance);
diff --git a/test/test.lv2/test.c b/test/test.lv2/test.c
index d6802a6..fa3fb6e 100644
--- a/test/test.lv2/test.c
+++ b/test/test.lv2/test.c
@@ -43,7 +43,8 @@ enum {
};
typedef struct {
- LV2_URID_Map* map;
+ LV2_URID_Map* map;
+ LV2_State_Free_Path* free_path;
struct {
LV2_URID atom_Float;
@@ -59,23 +60,18 @@ typedef struct {
} Test;
static void
-free_path(char* path)
-{
- /* FIXME: Temporary hack to avoid mismatched malloc/free crashes on
- Windows. The specifications needs a feature for this. */
-#ifndef _WIN32
- free(path);
-#endif
-}
-
-static void
cleanup(LV2_Handle instance)
{
Test* test = (Test*)instance;
if (test->rec_file) {
fclose(test->rec_file);
}
- free_path(test->rec_file_path);
+
+ if (test->free_path) {
+ test->free_path->free_path(test->free_path->handle,
+ test->rec_file_path);
+ }
+
free(instance);
}
@@ -123,6 +119,8 @@ instantiate(const LV2_Descriptor* descriptor,
test->map->handle, LV2_ATOM__Float);
} else if (!strcmp(features[i]->URI, LV2_STATE__makePath)) {
make_path = (LV2_State_Make_Path*)features[i]->data;
+ } else if (!strcmp(features[i]->URI, LV2_STATE__freePath)) {
+ test->free_path = (LV2_State_Free_Path*)features[i]->data;
}
}
@@ -133,6 +131,12 @@ instantiate(const LV2_Descriptor* descriptor,
}
if (make_path) {
+ if (!test->free_path) {
+ fprintf(stderr, "Host provided make_path without free_path\n");
+ free(test);
+ return NULL;
+ }
+
test->rec_file_path = make_path->path(make_path->handle, "recfile");
if (!(test->rec_file = fopen(test->rec_file_path, "w"))) {
fprintf(stderr, "ERROR: Failed to open rec file\n");
@@ -179,14 +183,21 @@ save(LV2_Handle instance,
LV2_State_Map_Path* map_path = NULL;
LV2_State_Make_Path* make_path = NULL;
+ LV2_State_Free_Path* free_path = NULL;
for (int i = 0; features && features[i]; ++i) {
if (!strcmp(features[i]->URI, LV2_STATE__mapPath)) {
map_path = (LV2_State_Map_Path*)features[i]->data;
} else if (!strcmp(features[i]->URI, LV2_STATE__makePath)) {
make_path = (LV2_State_Make_Path*)features[i]->data;
+ } else if (!strcmp(features[i]->URI, LV2_STATE__freePath)) {
+ free_path = (LV2_State_Free_Path*)features[i]->data;
}
}
+ if (!map_path || !free_path) {
+ return LV2_STATE_ERR_NO_FEATURE;
+ }
+
store(callback_data,
map_uri(plugin, "http://example.org/greeting"),
"hello",
@@ -281,8 +292,8 @@ save(LV2_Handle instance,
map_uri(plugin, LV2_ATOM__Path),
LV2_STATE_IS_POD);
- free_path(apath);
- free_path(apath2);
+ free_path->free_path(free_path->handle, apath);
+ free_path->free_path(free_path->handle, apath2);
if (plugin->rec_file) {
fflush(plugin->rec_file);
@@ -296,7 +307,7 @@ save(LV2_Handle instance,
map_uri(plugin, LV2_ATOM__Path),
LV2_STATE_IS_POD);
- free_path(apath);
+ free_path->free_path(free_path->handle, apath);
}
if (make_path) {
@@ -312,8 +323,8 @@ save(LV2_Handle instance,
strlen(apath) + 1,
map_uri(plugin, LV2_ATOM__Path),
LV2_STATE_IS_POD);
- free_path(apath);
- free_path(spath);
+ free_path->free_path(free_path->handle, apath);
+ free_path->free_path(free_path->handle, spath);
}
}
@@ -329,10 +340,13 @@ restore(LV2_Handle instance,
{
Test* plugin = (Test*)instance;
- LV2_State_Map_Path* map_path = NULL;
+ LV2_State_Map_Path* map_path = NULL;
+ LV2_State_Free_Path* free_path = NULL;
for (int i = 0; features && features[i]; ++i) {
if (!strcmp(features[i]->URI, LV2_STATE__mapPath)) {
map_path = (LV2_State_Map_Path*)features[i]->data;
+ } else if (!strcmp(features[i]->URI, LV2_STATE__freePath)) {
+ free_path = (LV2_State_Free_Path*)features[i]->data;
}
}
@@ -345,7 +359,7 @@ restore(LV2_Handle instance,
map_uri(plugin, "http://example.org/num-runs"),
&size, &type, &valflags);
- if (!map_path) {
+ if (!map_path || !free_path) {
return LV2_STATE_ERR_NO_FEATURE;
}
@@ -369,7 +383,7 @@ restore(LV2_Handle instance,
fprintf(stderr, "error: Restored bad file contents `%s' != `Hello'\n",
str);
}
- free_path(path);
+ free_path->free_path(free_path->handle, path);
}
apath = (char*)retrieve(
@@ -384,7 +398,7 @@ restore(LV2_Handle instance,
} else {
fclose(sfile);
}
- free_path(spath);
+ free_path->free_path(free_path->handle, spath);
} else {
fprintf(stderr, "error: Failed to restore save file.\n");
}