summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-07-11 19:30:04 -0400
committerDavid Robillard <d@drobilla.net>2016-07-11 20:03:13 -0400
commit05f9e858a5dd4b3a1ba5047aa703e55da70dcfdf (patch)
treeff0f07004bf7430a9faeded9c2c6db77925f6309
parent54f33b063642467adfe369fe1abd76c13af95734 (diff)
downloadlilv-05f9e858a5dd4b3a1ba5047aa703e55da70dcfdf.tar.gz
lilv-05f9e858a5dd4b3a1ba5047aa703e55da70dcfdf.tar.bz2
lilv-05f9e858a5dd4b3a1ba5047aa703e55da70dcfdf.zip
Improve test coverage
-rw-r--r--src/state.c8
-rw-r--r--src/world.c13
-rw-r--r--test/lilv_test.c22
-rw-r--r--test/test.lv2/test.c8
-rw-r--r--test/test.lv2/test.ttl.in6
5 files changed, 42 insertions, 15 deletions
diff --git a/src/state.c b/src/state.c
index 9bc1d6d..137d1a7 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1,5 +1,5 @@
/*
- Copyright 2007-2015 David Robillard <http://drobilla.net>
+ Copyright 2007-2016 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -106,18 +106,18 @@ append_port_value(LilvState* state,
uint32_t size,
uint32_t type)
{
+ PortValue* pv = NULL;
if (value) {
state->values = (PortValue*)realloc(
state->values, (++state->n_values) * sizeof(PortValue));
- PortValue* pv = &state->values[state->n_values - 1];
+ pv = &state->values[state->n_values - 1];
pv->symbol = lilv_strdup(port_symbol);
pv->value = malloc(size);
pv->size = size;
pv->type = type;
memcpy(pv->value, value, size);
- return pv;
}
- return NULL;
+ return pv;
}
static const char*
diff --git a/src/world.c b/src/world.c
index b608261..d08e32d 100644
--- a/src/world.c
+++ b/src/world.c
@@ -335,15 +335,12 @@ lilv_lib_compare(const void* a, const void* b, void* user_data)
static ZixTreeIter*
lilv_collection_find_by_uri(const ZixTree* seq, const LilvNode* uri)
{
- if (!lilv_node_is_uri(uri)) {
- return NULL;
+ ZixTreeIter* i = NULL;
+ if (lilv_node_is_uri(uri)) {
+ struct LilvHeader key = { NULL, (LilvNode*)uri };
+ zix_tree_find(seq, &key, &i);
}
-
- struct LilvHeader key = { NULL, (LilvNode*)uri };
- ZixTreeIter* i = NULL;
- const ZixStatus st = zix_tree_find(seq, &key, &i);
-
- return st ? NULL : i;
+ return i;
}
/** Get an element of a collection of any object with an LilvHeader by URI. */
diff --git a/test/lilv_test.c b/test/lilv_test.c
index f1ddbfd..4215d97 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -1,5 +1,5 @@
/*
- Copyright 2007-2015 David Robillard <http://drobilla.net>
+ Copyright 2007-2016 David Robillard <http://drobilla.net>
Copyright 2008 Krzysztof Foltman
Permission to use, copy, modify, and/or distribute this software for any
@@ -1419,6 +1419,7 @@ test_ui(void)
uint32_t atom_Float = 0;
float in = 1.0;
float out = 42.0;
+float control = 1234.0;
static const void*
get_port_value(const char* port_symbol,
@@ -1434,6 +1435,10 @@ get_port_value(const char* port_symbol,
*size = sizeof(float);
*type = atom_Float;
return &out;
+ } else if (!strcmp(port_symbol, "control")) {
+ *size = sizeof(float);
+ *type = atom_Float;
+ return &control;
} else {
fprintf(stderr, "error: get_port_value for nonexistent port `%s'\n",
port_symbol);
@@ -1453,6 +1458,8 @@ set_port_value(const char* port_symbol,
in = *(const float*)value;
} else if (!strcmp(port_symbol, "output")) {
out = *(const float*)value;
+ } else if (!strcmp(port_symbol, "control")) {
+ control = *(const float*)value;
} else {
fprintf(stderr, "error: set_port_value for nonexistent port `%s'\n",
port_symbol);
@@ -1624,6 +1631,16 @@ test_state(void)
"state/state.lv2/state.ttl");
TEST_ASSERT(lilv_state_equals(state, state5)); // Round trip accuracy
+ TEST_ASSERT(lilv_state_get_num_properties(state) == 8);
+
+ // Attempt to save state to nowhere (error)
+ ret = lilv_state_save(world, &map, &unmap, state, NULL, NULL, NULL);
+ TEST_ASSERT(ret);
+
+ // Save another state to the same directory (update manifest)
+ ret = lilv_state_save(world, &map, &unmap, state, NULL,
+ "state/state.lv2", "state2.ttl");
+ TEST_ASSERT(!ret);
// Save state with URI to a directory
const char* state_uri = "http://example.org/state";
@@ -2000,6 +2017,9 @@ test_reload_bundle(void)
TEST_ASSERT(!strcmp(lilv_node_as_string(name2), "Second name"));
lilv_node_free(name2);
+ // Load new bundle again (noop)
+ lilv_world_load_bundle(world, bundle_uri);
+
lilv_node_free(bundle_uri);
lilv_world_free(world);
world = NULL;
diff --git a/test/test.lv2/test.c b/test/test.lv2/test.c
index cd9a18c..27344e7 100644
--- a/test/test.lv2/test.c
+++ b/test/test.lv2/test.c
@@ -28,8 +28,9 @@
#define TEST_URI "http://example.org/lilv-test-plugin"
enum {
- TEST_INPUT = 0,
- TEST_OUTPUT = 1
+ TEST_INPUT = 0,
+ TEST_OUTPUT = 1,
+ TEST_CONTROL = 2
};
typedef struct {
@@ -73,6 +74,9 @@ connect_port(LV2_Handle instance,
case TEST_OUTPUT:
test->output = (float*)data;
break;
+ case TEST_CONTROL:
+ test->output = (float*)data;
+ break;
default:
break;
}
diff --git a/test/test.lv2/test.ttl.in b/test/test.lv2/test.ttl.in
index 6fb6aed..1c16b4c 100644
--- a/test/test.lv2/test.ttl.in
+++ b/test/test.lv2/test.ttl.in
@@ -37,4 +37,10 @@
lv2:index 1 ;
lv2:symbol "output" ;
lv2:name "Output"
+ ] , [
+ a lv2:InputPort ,
+ lv2:ControlPort ;
+ lv2:index 2 ;
+ lv2:symbol "control" ;
+ lv2:name "Control"
] .