summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-12-13 05:23:25 +0000
committerDavid Robillard <d@drobilla.net>2008-12-13 05:23:25 +0000
commitbaa2354cf47b093117206fd1fc1bae45e46b03c3 (patch)
treeda51033f5060badca53d52aa1bce4c2076cb9fcf
parentc854c1f24f41844f0c95e8943738a820d8a283e5 (diff)
downloadlilv-baa2354cf47b093117206fd1fc1bae45e46b03c3.tar.gz
lilv-baa2354cf47b093117206fd1fc1bae45e46b03c3.tar.bz2
lilv-baa2354cf47b093117206fd1fc1bae45e46b03c3.zip
Factor out "load plugin if necessary" concept.
Test plugin features: 78.1% coverage. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1859 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/plugin.c33
-rw-r--r--src/query.c3
-rw-r--r--src/slv2_internal.h1
-rw-r--r--src/value.c3
-rw-r--r--test/slv2_test.c45
5 files changed, 66 insertions, 19 deletions
diff --git a/src/plugin.c b/src/plugin.c
index b9bc9b2..6ac5094 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -105,6 +105,15 @@ slv2_port_compare_by_index(const void* a, const void* b)
#endif
+/* private */
+void
+slv2_plugin_load_if_necessary(SLV2Plugin p)
+{
+ if (!p->rdf)
+ slv2_plugin_load(p);
+}
+
+
void
slv2_plugin_load(SLV2Plugin p)
{
@@ -290,8 +299,7 @@ SLV2Value
slv2_plugin_get_library_uri(SLV2Plugin p)
{
assert(p);
- if (!p->binary_uri && !p->rdf)
- slv2_plugin_load(p);
+ slv2_plugin_load_if_necessary(p);
return p->binary_uri;
}
@@ -309,9 +317,7 @@ slv2_plugin_get_class(SLV2Plugin p)
// FIXME: Typical use case this will bring every single plugin model
// into memory
- if (!p->rdf)
- slv2_plugin_load(p);
-
+ slv2_plugin_load_if_necessary(p);
return p->plugin_class;
}
@@ -525,9 +531,7 @@ slv2_plugin_get_hints(SLV2Plugin p)
uint32_t
slv2_plugin_get_num_ports(SLV2Plugin p)
{
- if (!p->rdf)
- slv2_plugin_load(p);
-
+ slv2_plugin_load_if_necessary(p);
return raptor_sequence_size(p->ports);
}
@@ -537,12 +541,11 @@ slv2_plugin_get_port_float_values(SLV2Plugin p,
const char* qname,
float* values)
{
- if (!p->rdf)
- slv2_plugin_load(p);
-
const unsigned char* query;
librdf_query* q;
librdf_query_results* results;
+
+ slv2_plugin_load_if_necessary(p);
for (int i = 0; i < raptor_sequence_size(p->ports); ++i)
values[i] = NAN;
@@ -717,9 +720,7 @@ SLV2Port
slv2_plugin_get_port_by_index(SLV2Plugin p,
uint32_t index)
{
- if (!p->rdf)
- slv2_plugin_load(p);
-
+ slv2_plugin_load_if_necessary(p);
return raptor_sequence_get_at(p->ports, (int)index);
}
@@ -728,9 +729,7 @@ SLV2Port
slv2_plugin_get_port_by_symbol(SLV2Plugin p,
SLV2Value symbol)
{
- if (!p->rdf)
- slv2_plugin_load(p);
-
+ slv2_plugin_load_if_necessary(p);
for (int i=0; i < raptor_sequence_size(p->ports); ++i) {
SLV2Port port = raptor_sequence_get_at(p->ports, i);
if (slv2_value_equals(port->symbol, symbol))
diff --git a/src/query.c b/src/query.c
index 540d11a..f4a6a0d 100644
--- a/src/query.c
+++ b/src/query.c
@@ -126,8 +126,7 @@ librdf_query_results*
slv2_plugin_query(SLV2Plugin plugin,
const char* sparql_str)
{
- if (!plugin->rdf)
- slv2_plugin_load(plugin);
+ slv2_plugin_load_if_necessary(plugin);
librdf_uri* base_uri = slv2_value_as_librdf_uri(plugin->plugin_uri);
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index a3e8d04..9d5b17a 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -68,6 +68,7 @@ struct _SLV2Plugin {
SLV2Plugin slv2_plugin_new(SLV2World world, SLV2Value uri, librdf_uri* bundle_uri);
void slv2_plugin_load(SLV2Plugin p);
+void slv2_plugin_load_if_necessary(SLV2Plugin p);
void slv2_plugin_free(SLV2Plugin plugin);
void slv2_plugin_get_port_float_values(SLV2Plugin p,
const char* qname,
diff --git a/src/value.c b/src/value.c
index 0e474fb..08c27e5 100644
--- a/src/value.c
+++ b/src/value.c
@@ -168,6 +168,9 @@ slv2_value_new_float(SLV2World world, float val)
SLV2Value
slv2_value_duplicate(SLV2Value val)
{
+ if (val == NULL)
+ return val;
+
SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value));
result->type = val->type;
diff --git a/test/slv2_test.c b/test/slv2_test.c
index 3a394e3..ca747e6 100644
--- a/test/slv2_test.c
+++ b/test/slv2_test.c
@@ -271,9 +271,24 @@ test_value()
TEST_ASSERT(!slv2_value_equals(ival, ival_ne));
TEST_ASSERT(!slv2_value_equals(fval, fval_ne));
+ TEST_ASSERT(!slv2_value_equals(uval, sval));
+ TEST_ASSERT(!slv2_value_equals(sval, ival));
+ TEST_ASSERT(!slv2_value_equals(ival, fval));
+
SLV2Value uval_dup = slv2_value_duplicate(uval);
TEST_ASSERT(slv2_value_equals(uval, uval_dup));
+ SLV2Value ifval = slv2_value_new_float(world, 42.0);
+ TEST_ASSERT(!slv2_value_equals(ival, ifval));
+
+ SLV2Value nil = NULL;
+ TEST_ASSERT(!slv2_value_equals(uval, nil));
+ TEST_ASSERT(!slv2_value_equals(nil, uval));
+ TEST_ASSERT(slv2_value_equals(nil, nil));
+
+ SLV2Value nil2 = slv2_value_duplicate(nil);
+ TEST_ASSERT(slv2_value_equals(nil, nil2));
+
slv2_value_free(uval);
slv2_value_free(sval);
slv2_value_free(ival);
@@ -533,6 +548,8 @@ test_plugin()
":plug a lv2:Plugin ; a lv2:CompressorPlugin ; "
PLUGIN_NAME("Test plugin") " ; "
LICENSE_GPL " ; "
+ "lv2:optionalFeature lv2:hardRtCapable ; "
+ "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
"lv2:port [ "
" a lv2:ControlPort ; a lv2:InputPort ; "
" lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; "
@@ -608,6 +625,24 @@ test_plugin()
TEST_ASSERT(slv2_plugin_has_latency(plug));
TEST_ASSERT(slv2_plugin_get_latency_port_index(plug) == 2);
+ SLV2Value rt_feature = slv2_value_new_uri(world,
+ "http://lv2plug.in/ns/lv2core#hardRtCapable");
+ SLV2Value event_feature = slv2_value_new_uri(world,
+ "http://lv2plug.in/ns/ext/event");
+ SLV2Value pretend_feature = slv2_value_new_uri(world,
+ "http://example.org/solvesWorldHunger");
+
+ TEST_ASSERT(slv2_plugin_has_feature(plug, rt_feature));
+ TEST_ASSERT(slv2_plugin_has_feature(plug, event_feature));
+ TEST_ASSERT(!slv2_plugin_has_feature(plug, pretend_feature));
+
+ SLV2Values supported = slv2_plugin_get_supported_features(plug);
+ SLV2Values required = slv2_plugin_get_required_features(plug);
+ SLV2Values optional = slv2_plugin_get_optional_features(plug);
+ TEST_ASSERT(slv2_values_size(supported) == 2);
+ TEST_ASSERT(slv2_values_size(required) == 1);
+ TEST_ASSERT(slv2_values_size(optional) == 1);
+
slv2_value_free(control_class);
slv2_value_free(audio_class);
slv2_value_free(in_class);
@@ -632,6 +667,7 @@ test_port()
" a lv2:ControlPort ; a lv2:InputPort ; "
" lv2:index 0 ; lv2:symbol \"foo\" ; "
" lv2:name \"bar\" ; lv2:name \"le bar\"@fr ; "
+ " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 ; "
" lv2:scalePoint [ rdfs:label \"Sin\"; rdf:value 3 ] ; "
" lv2:scalePoint [ rdfs:label \"Cos\"; rdf:value 4 ] ; "
"] .",
@@ -695,6 +731,15 @@ test_port()
TEST_ASSERT(slv2_plugin_query_count(plug, "SELECT DISTINCT ?parent WHERE {\n"
"<> rdfs:subClassOf ?parent . }") == 0);
+ SLV2Value min, max, def;
+ slv2_port_get_range(plug, p, &def, &min, &max);
+ TEST_ASSERT(def);
+ TEST_ASSERT(min);
+ TEST_ASSERT(max);
+ TEST_ASSERT(slv2_value_as_float(def) == 0.5);
+ TEST_ASSERT(slv2_value_as_float(min) == -1.0);
+ TEST_ASSERT(slv2_value_as_float(max) == 1.0);
+
slv2_value_free(homepage_p);
slv2_values_free(homepages);