summaryrefslogtreecommitdiffstats
path: root/test/test_plugin.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-01-28 01:37:28 +0000
committerDavid Robillard <d@drobilla.net>2012-01-28 01:37:28 +0000
commitce2c5cc2036154c2b3ce8850c35e34c0bffeef1f (patch)
tree4dea45a4376110c75fdb8d1c6b9bf3b87b002635 /test/test_plugin.c
parente4d3f6140cc167580ec43de6fc3ea4562aaba63e (diff)
downloadlilv-ce2c5cc2036154c2b3ce8850c35e34c0bffeef1f.tar.gz
lilv-ce2c5cc2036154c2b3ce8850c35e34c0bffeef1f.tar.bz2
lilv-ce2c5cc2036154c2b3ce8850c35e34c0bffeef1f.zip
Update state interface to support multiple state snapshots with shared files.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3967 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'test/test_plugin.c')
-rw-r--r--test/test_plugin.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/test/test_plugin.c b/test/test_plugin.c
index ef66863..9eda8de 100644
--- a/test/test_plugin.c
+++ b/test/test_plugin.c
@@ -140,7 +140,13 @@ run(LV2_Handle instance,
if (sample_count == 1) {
++test->num_runs;
} else if (sample_count == 2 && test->rec_file) {
+ // Append to rec file (changes size)
fprintf(test->rec_file, "run\n");
+ } else if (sample_count == 3 && test->rec_file) {
+ // Change the first byte of rec file (doesn't change size)
+ fseek(test->rec_file, 0, SEEK_SET);
+ fprintf(test->rec_file, "X");
+ fseek(test->rec_file, 0, SEEK_END);
}
}
@@ -160,13 +166,13 @@ save(LV2_Handle instance,
Test* plugin = (Test*)instance;
LV2_State_Map_Path* map_path = NULL;
- //LV2_State_Make_Path* make_path = NULL;
+ LV2_State_Make_Path* make_path = NULL;
for (int i = 0; features && features[i]; ++i) {
if (!strcmp(features[i]->URI, LV2_STATE_MAP_PATH_URI)) {
map_path = (LV2_State_Map_Path*)features[i]->data;
- }/* else if (!strcmp(features[i]->URI, LV2_STATE_MAKE_PATH_URI)) {
+ } else if (!strcmp(features[i]->URI, LV2_STATE_MAKE_PATH_URI)) {
make_path = (LV2_State_Make_Path*)features[i]->data;
- }*/
+ }
}
store(callback_data,
@@ -261,6 +267,22 @@ save(LV2_Handle instance,
free(apath);
}
+
+ if (make_path) {
+ char* spath = make_path->path(make_path->handle, "save");
+ FILE* sfile = fopen(spath, "w");
+ fprintf(sfile, "save");
+ fclose(sfile);
+
+ apath = map_path->abstract_path(map_path->handle, spath);
+ store(callback_data,
+ map_uri(plugin, "http://example.org/save-file"),
+ apath,
+ strlen(apath) + 1,
+ map_uri(plugin, LV2_STATE_PATH_URI),
+ LV2_STATE_IS_PORTABLE);
+ free(apath);
+ }
}
}
@@ -289,12 +311,16 @@ restore(LV2_Handle instance,
map_uri(plugin, "http://example.org/num-runs"),
&size, &type, &valflags);
+ if (!map_path) {
+ return;
+ }
+
char* apath = (char*)retrieve(
callback_data,
map_uri(plugin, "http://example.org/extfile"),
&size, &type, &valflags);
- if (map_path && apath) {
+ if (apath) {
char* path = map_path->absolute_path(map_path->handle, apath);
char* real_path = realpath(path, NULL);
if (strcmp(real_path, plugin->tmp_file_path)) {
@@ -304,6 +330,22 @@ restore(LV2_Handle instance,
free(real_path);
free(path);
}
+
+ apath = (char*)retrieve(
+ callback_data,
+ map_uri(plugin, "http://example.org/save-file"),
+ &size, &type, &valflags);
+ if (apath) {
+ char* spath = map_path->absolute_path(map_path->handle, apath);
+ FILE* sfile = fopen(spath, "r");
+ if (!sfile) {
+ fprintf(stderr, "error: Failed to open save file %s\n", spath);
+ } else {
+ fclose(sfile);
+ }
+ } else {
+ fprintf(stderr, "error: Failed to restore save file.\n");
+ }
}
const void*