diff options
author | David Robillard <d@drobilla.net> | 2008-12-13 04:37:57 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-12-13 04:37:57 +0000 |
commit | c854c1f24f41844f0c95e8943738a820d8a283e5 (patch) | |
tree | cd192e47417aa4f6f9369b8f8922fb4af243cfc1 | |
parent | cfaf7d029da6f66bddfd91c7874d4019c502ea5c (diff) | |
download | lilv-c854c1f24f41844f0c95e8943738a820d8a283e5.tar.gz lilv-c854c1f24f41844f0c95e8943738a820d8a283e5.tar.bz2 lilv-c854c1f24f41844f0c95e8943738a820d8a283e5.zip |
Add constructors slv2_value_new_int, slv2_value_new_float, slv2_value_new_string.
Fix slv2_value_get_turtle_token for floats.
Nearly complete test coverage for value stuff: 73.5% coverage
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1858 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | slv2/value.h | 26 | ||||
-rw-r--r-- | src/slv2_internal.h | 17 | ||||
-rw-r--r-- | src/value.c | 27 | ||||
-rw-r--r-- | test/slv2_test.c | 124 | ||||
-rwxr-xr-x | test/test_coverage.sh | 2 | ||||
-rw-r--r-- | test/wscript | 1 | ||||
-rw-r--r-- | wscript | 5 |
8 files changed, 147 insertions, 61 deletions
@@ -1,3 +1,9 @@ +slv2 (0.6.3) unstable; urgency=low + + * Fix illegal output of slv2_value_get_turtle_token for floats. + + -- Dave Robillard <dave@drobilla.net> Fri, 12 Dec 2008 23:23:47 -0500 + slv2 (0.6.2) unstable; urgency=high * Fix bug introduced with I18N in 0.6.1 which broke feature detection. diff --git a/slv2/value.h b/slv2/value.h index 53bad8c..db447dd 100644 --- a/slv2/value.h +++ b/slv2/value.h @@ -33,12 +33,36 @@ extern "C" { /** Create a new URI value. * - * Returned value must be freed by called with slv2_value_free. + * Returned value must be freed by caller with slv2_value_free. */ SLV2Value slv2_value_new_uri(SLV2World world, const char* uri); +/** Create a new string value (with no language). + * + * Returned value must be freed by caller with slv2_value_free. + */ +SLV2Value +slv2_value_new_string(SLV2World world, const char* str); + + +/** Create a new integer value. + * + * Returned value must be freed by caller with slv2_value_free. + */ +SLV2Value +slv2_value_new_int(SLV2World world, int val); + + +/** Create a new floating point value. + * + * Returned value must be freed by caller with slv2_value_free. + */ +SLV2Value +slv2_value_new_float(SLV2World world, float val); + + /** Free an SLV2Value. */ void diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 48193c7..a3e8d04 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -32,10 +32,8 @@ extern "C" { #include "slv2/lv2_ui.h" - /* ********* PORT ********* */ - /** Reference to a port on some plugin. */ struct _SLV2Port { uint32_t index; ///< lv2:index @@ -49,10 +47,8 @@ SLV2Port slv2_port_new(SLV2World world, uint32_t index, const char* symbol); void slv2_port_free(SLV2Port port); - /* ********* Plugin ********* */ - /** Record of an installed/available plugin. * * A simple reference to a plugin somewhere on the system. This just holds @@ -81,10 +77,8 @@ librdf_query_results* slv2_plugin_query(SLV2Plugin plugin, const char* sparql_str); - /* ********* Plugins ********* */ - /** Create a new, empty plugin list. * * Returned object must be freed with slv2_plugins_free. @@ -93,10 +87,8 @@ SLV2Plugins slv2_plugins_new(); - /* ********* Instance ********* */ - /** Pimpl portion of SLV2Instance */ struct _InstanceImpl { void* lib_handle; @@ -104,6 +96,7 @@ struct _InstanceImpl { /* ********* UI Instance ********* */ + struct _SLV2UIInstanceImpl { void* lib_handle; const LV2UI_Descriptor* lv2ui_descriptor; @@ -114,7 +107,6 @@ struct _SLV2UIInstanceImpl { /* ********* Plugin Class ********* */ - struct _SLV2PluginClass { struct _SLV2World* world; SLV2Value parent_uri; @@ -127,15 +119,12 @@ SLV2PluginClass slv2_plugin_class_new(SLV2World world, librdf_uri* parent_uri, void slv2_plugin_class_free(SLV2PluginClass plugin_class); - /* ********* Plugin Classes ********* */ - SLV2PluginClasses slv2_plugin_classes_new(); void slv2_plugin_classes_free(); - /* ********* World ********* */ /** Model of LV2 (RDF) data loaded from bundles. @@ -240,11 +229,9 @@ SLV2ScalePoint slv2_scale_point_new(SLV2Value value, SLV2Value label); void slv2_scale_point_free(SLV2ScalePoint point); -/* String utility functions */ +/* ********* Utilities ********* */ char* slv2_strjoin(const char* first, ...); - -/* I18N utility functions */ char* slv2_get_lang(); diff --git a/src/value.c b/src/value.c index a8ef85a..0e474fb 100644 --- a/src/value.c +++ b/src/value.c @@ -141,6 +141,31 @@ slv2_value_new_uri(SLV2World world, const char* uri) SLV2Value +slv2_value_new_string(SLV2World world, const char* str) +{ + return slv2_value_new(world, SLV2_VALUE_STRING, str); +} + + +SLV2Value +slv2_value_new_int(SLV2World world, int val) +{ + char str[32]; + snprintf(str, 32, "%d", val); + return slv2_value_new(world, SLV2_VALUE_INT, str); +} + + +SLV2Value +slv2_value_new_float(SLV2World world, float val) +{ + char str[32]; + snprintf(str, 32, "%f", val); + return slv2_value_new(world, SLV2_VALUE_FLOAT, str); +} + + +SLV2Value slv2_value_duplicate(SLV2Value val) { SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); @@ -229,7 +254,7 @@ slv2_value_get_turtle_token(SLV2Value value) len = 20; // FIXME: proper maximum value? result = calloc(len, sizeof(char)); setlocale(LC_NUMERIC, "POSIX"); - snprintf(result, len, ".1%f", value->val.float_val); + snprintf(result, len, "%f", value->val.float_val); setlocale(LC_NUMERIC, locale); break; } diff --git a/test/slv2_test.c b/test/slv2_test.c index c8b8a4f..3a394e3 100644 --- a/test/slv2_test.c +++ b/test/slv2_test.c @@ -27,6 +27,8 @@ #include <librdf.h> #include <sys/stat.h> #include <limits.h> +#include <float.h> +#include <math.h> #include "slv2/slv2.h" #define TEST_PATH_MAX 1024 @@ -210,47 +212,83 @@ test_utils() int test_value() { - const char *uri = "http://example.com/"; - char *res; + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary <foo.so> ; rdfs:seeAlso <plugin.ttl> .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; " + "] .", + 1)) + return 0; - init_world(); - SLV2Value v1 = slv2_value_new_uri(world, "http://example.com/"); - TEST_ASSERT(v1); - TEST_ASSERT(slv2_value_is_uri(v1)); - TEST_ASSERT(!strcmp(slv2_value_as_uri(v1), uri)); - TEST_ASSERT(!slv2_value_is_literal(v1)); - TEST_ASSERT(!slv2_value_is_string(v1)); - TEST_ASSERT(!slv2_value_is_float(v1)); - TEST_ASSERT(!slv2_value_is_int(v1)); - res = slv2_value_get_turtle_token(v1); - TEST_ASSERT(!strcmp(res, "<http://example.com/>")); - - SLV2Value v2 = slv2_value_new_uri(world, uri); - TEST_ASSERT(v2); - TEST_ASSERT(slv2_value_is_uri(v2)); - TEST_ASSERT(!strcmp(slv2_value_as_uri(v2), uri)); - - TEST_ASSERT(slv2_value_equals(v1, v2)); - - SLV2Value v3 = slv2_value_new_uri(world, "http://example.com/another"); - TEST_ASSERT(v3); - TEST_ASSERT(slv2_value_is_uri(v3)); - TEST_ASSERT(!strcmp(slv2_value_as_uri(v3), "http://example.com/another")); - TEST_ASSERT(!slv2_value_equals(v1, v3)); - - slv2_value_free(v2); - v2 = slv2_value_duplicate(v1); - TEST_ASSERT(slv2_value_equals(v1, v2)); - TEST_ASSERT(slv2_value_is_uri(v2)); - TEST_ASSERT(!strcmp(slv2_value_as_uri(v2), uri)); - TEST_ASSERT(!slv2_value_is_literal(v2)); - TEST_ASSERT(!slv2_value_is_string(v2)); - TEST_ASSERT(!slv2_value_is_float(v2)); - TEST_ASSERT(!slv2_value_is_int(v2)); - - slv2_value_free(v3); - slv2_value_free(v2); - slv2_value_free(v1); + init_uris(); + + SLV2Value uval = slv2_value_new_uri(world, "http://example.org"); + SLV2Value sval = slv2_value_new_string(world, "Foo"); + SLV2Value ival = slv2_value_new_int(world, 42); + SLV2Value fval = slv2_value_new_float(world, 1.6180); + + TEST_ASSERT(slv2_value_is_uri(uval)); + TEST_ASSERT(slv2_value_is_string(sval)); + TEST_ASSERT(slv2_value_is_int(ival)); + TEST_ASSERT(slv2_value_is_float(fval)); + + TEST_ASSERT(!slv2_value_is_literal(uval)); + TEST_ASSERT(slv2_value_is_literal(sval)); + TEST_ASSERT(slv2_value_is_literal(ival)); + TEST_ASSERT(slv2_value_is_literal(fval)); + + TEST_ASSERT(!strcmp(slv2_value_as_uri(uval), "http://example.org")); + TEST_ASSERT(!strcmp(slv2_value_as_string(sval), "Foo")); + TEST_ASSERT(slv2_value_as_int(ival) == 42); + TEST_ASSERT(fabs(slv2_value_as_float(fval) - 1.6180) < FLT_EPSILON); + + TEST_ASSERT(!strcmp(slv2_value_get_turtle_token(uval), "<http://example.org>")); + TEST_ASSERT(!strcmp(slv2_value_get_turtle_token(sval), "Foo")); + TEST_ASSERT(!strcmp(slv2_value_get_turtle_token(ival), "42")); + TEST_ASSERT(!strncmp(slv2_value_get_turtle_token(fval), "1.6180", 6)); + + SLV2Value uval_e = slv2_value_new_uri(world, "http://example.org"); + SLV2Value sval_e = slv2_value_new_string(world, "Foo"); + SLV2Value ival_e = slv2_value_new_int(world, 42); + SLV2Value fval_e = slv2_value_new_float(world, 1.6180); + SLV2Value uval_ne = slv2_value_new_uri(world, "http://no-example.org"); + SLV2Value sval_ne = slv2_value_new_string(world, "Bar"); + SLV2Value ival_ne = slv2_value_new_int(world, 24); + SLV2Value fval_ne = slv2_value_new_float(world, 3.14159); + + TEST_ASSERT(slv2_value_equals(uval, uval_e)); + TEST_ASSERT(slv2_value_equals(sval, sval_e)); + TEST_ASSERT(slv2_value_equals(ival, ival_e)); + TEST_ASSERT(slv2_value_equals(fval, fval_e)); + + TEST_ASSERT(!slv2_value_equals(uval, uval_ne)); + TEST_ASSERT(!slv2_value_equals(sval, sval_ne)); + TEST_ASSERT(!slv2_value_equals(ival, ival_ne)); + TEST_ASSERT(!slv2_value_equals(fval, fval_ne)); + + SLV2Value uval_dup = slv2_value_duplicate(uval); + TEST_ASSERT(slv2_value_equals(uval, uval_dup)); + + slv2_value_free(uval); + slv2_value_free(sval); + slv2_value_free(ival); + slv2_value_free(fval); + slv2_value_free(uval_e); + slv2_value_free(sval_e); + slv2_value_free(ival_e); + slv2_value_free(fval_e); + slv2_value_free(uval_ne); + slv2_value_free(sval_ne); + slv2_value_free(ival_ne); + slv2_value_free(fval_ne); + slv2_value_free(uval_dup); + + cleanup_uris(); return 1; } @@ -483,6 +521,7 @@ test_classes() return 1; } + /*****************************************************************************/ int @@ -532,6 +571,10 @@ test_plugin() slv2_value_as_string(plug_bundle_uri), "manifest.ttl"); snprintf(data_uri, TEST_PATH_MAX, "%s%s", slv2_value_as_string(plug_bundle_uri), "plugin.ttl"); + + SLV2Value manifest_uri_val = slv2_value_new_uri(world, manifest_uri); + TEST_ASSERT(slv2_values_contains(data_uris, manifest_uri_val)); + slv2_value_free(manifest_uri_val); TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(data_uris, 0)), manifest_uri)); TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(data_uris, 1)), data_uri)); @@ -569,7 +612,6 @@ test_plugin() slv2_value_free(audio_class); slv2_value_free(in_class); slv2_value_free(out_class); - slv2_plugins_free(world, plugins); cleanup_uris(); return 1; } diff --git a/test/test_coverage.sh b/test/test_coverage.sh index 9df5ebc..045f136 100755 --- a/test/test_coverage.sh +++ b/test/test_coverage.sh @@ -8,7 +8,7 @@ cd ../build/default lcov -d ./src -z ./test/slv2_test -lcov -d ./src -b .. -c > coverage.lcov +lcov -d ./src -d ./test -b .. -c > coverage.lcov mkdir -p ./coverage genhtml -o coverage coverage.lcov echo "Report written to:" diff --git a/test/wscript b/test/wscript index d328efa..cd42778 100644 --- a/test/wscript +++ b/test/wscript @@ -14,4 +14,5 @@ def build(bld): obj.libs = 'gcov' obj.target = i obj.install_path = '' + obj.ccflags = '-fprofile-arcs -ftest-coverage' @@ -3,7 +3,7 @@ import autowaf import Options # Version of this package (even if built as a child) -SLV2_VERSION = '0.6.2' +SLV2_VERSION = '0.6.3' # Library version (UNIX style major, minor, micro) # major increment <=> incompatible changes @@ -26,7 +26,8 @@ SLV2_VERSION = '0.6.2' # 0.6.0 = 9,0,0 (SVN r1282) # 0.6.1 = 9,1,0 # 0.6.2 = 9,1,1 -SLV2_LIB_VERSION = '9.1.1' +# current svn = 9,1,2 +SLV2_LIB_VERSION = '9.1.2' # Variables for 'waf dist' APPNAME = 'slv2' |