diff options
-rw-r--r-- | src/state.c | 21 | ||||
-rw-r--r-- | src/util.c | 38 | ||||
-rw-r--r-- | test/lilv_test.c | 37 | ||||
-rw-r--r-- | test/test_plugin.c | 10 | ||||
-rw-r--r-- | wscript | 54 |
5 files changed, 95 insertions, 65 deletions
diff --git a/src/state.c b/src/state.c index 53479ff..e8e3544 100644 --- a/src/state.c +++ b/src/state.c @@ -136,8 +136,8 @@ store_callback(void* handle, uint32_t flags) { LilvState* const state = (LilvState*)handle; - state->props = realloc(state->props, - (++state->num_props) * sizeof(Property)); + state->props = (Property*)realloc( + state->props, (++state->num_props) * sizeof(Property)); Property* const prop = &state->props[state->num_props - 1]; if ((flags & LV2_STATE_IS_POD) || type == state->state_Path) { @@ -246,7 +246,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, } // Add record to path mapping - PathMap* pm = malloc(sizeof(PathMap)); + PathMap* pm = (PathMap*)malloc(sizeof(PathMap)); pm->abs = real_path; pm->rel = lilv_strdup(path); zix_tree_insert(state->abs2rel, pm, NULL); @@ -369,9 +369,9 @@ lilv_state_new_from_instance(const LilvPlugin* plugin, // Store properties #ifdef HAVE_LV2_STATE - const LV2_Descriptor* descriptor = instance->lv2_descriptor; - const LV2_State_Interface* iface = (descriptor->extension_data) - ? descriptor->extension_data(LV2_STATE_INTERFACE_URI) + const LV2_Descriptor* desc = instance->lv2_descriptor; + const LV2_State_Interface* iface = (desc->extension_data) + ? (LV2_State_Interface*)desc->extension_data(LV2_STATE_INTERFACE_URI) : NULL; if (iface) { @@ -404,9 +404,9 @@ lilv_state_restore(const LilvState* state, const LV2_Feature** sfeatures = add_features(features, &map_feature, NULL); features = sfeatures; - const LV2_Descriptor* descriptor = instance->lv2_descriptor; - const LV2_State_Interface* iface = (descriptor->extension_data) - ? descriptor->extension_data(LV2_STATE_INTERFACE_URI) + const LV2_Descriptor* desc = instance->lv2_descriptor; + const LV2_State_Interface* iface = (desc->extension_data) + ? (LV2_State_Interface*)desc->extension_data(LV2_STATE_INTERFACE_URI) : NULL; if (iface) { @@ -1019,7 +1019,8 @@ lilv_state_save(LilvWorld* world, lilv_node_free(node); #ifdef HAVE_LV2_STATE } else if (!strcmp(type, NS_STATE "Path")) { - o = serd_node_from_string(SERD_LITERAL, prop->value); + o = serd_node_from_string(SERD_LITERAL, + (const uint8_t*)prop->value); t = serd_node_from_string(SERD_URI, (const uint8_t*)type); // <state> <key> "the/path"^^<state:Path> serd_writer_write_statement( @@ -159,8 +159,8 @@ char* lilv_expand(const char* path) { #ifdef _WIN32 - char* ret = (char*)malloc(MAX_PATH); - ExpandEnvironmentStrings(path, ret, MAX_PATH); + char* out = (char*)malloc(MAX_PATH); + ExpandEnvironmentStrings(path, out, MAX_PATH); #else char* out = NULL; size_t len = 0; @@ -198,21 +198,27 @@ lilv_expand(const char* path) if (*start) { out = strappend(out, &len, start, strlen(start)); } +#endif return out; -#endif +} + +static bool +lilv_is_dir_sep(const char c) +{ + return c == '/' || c == LILV_DIR_SEP[0]; } char* lilv_dirname(const char* path) { const char* s = path + strlen(path) - 1; // Last character - for (; s > path && *s == LILV_DIR_SEP[0]; --s) {} // Last non-slash - for (; s > path && *s != LILV_DIR_SEP[0]; --s) {} // Last internal slash - for (; s > path && *s == LILV_DIR_SEP[0]; --s) {} // Skip duplicates + for (; s > path && lilv_is_dir_sep(*s); --s) {} // Last non-slash + for (; s > path && !lilv_is_dir_sep(*s); --s) {} // Last internal slash + for (; s > path && lilv_is_dir_sep(*s); --s) {} // Skip duplicates if (s == path) { // Hit beginning - return (*s == '/') ? lilv_strdup("/") : lilv_strdup("."); + return lilv_is_dir_sep(*s) ? lilv_strdup("/") : lilv_strdup("."); } else { // Pointing to the last character of the result (inclusive) char* dirname = (char*)malloc(s - path + 2); memcpy(dirname, path, s - path + 1); @@ -283,12 +289,6 @@ lilv_copy_file(const char* src, const char* dst) return ret; } -static bool -lilv_is_dir_sep(const char c) -{ - return c == '/' || c == LILV_DIR_SEP[0]; -} - bool lilv_path_is_absolute(const char* path) { @@ -330,7 +330,7 @@ lilv_path_join(const char* a, const char* b) const size_t pre_len = a_len - (lilv_is_dir_sep(a[a_len - 1]) ? 1 : 0); char* path = (char*)calloc(1, a_len + b_len + 2); memcpy(path, a, pre_len); - path[pre_len] = LILV_DIR_SEP[0]; + path[pre_len] = '/'; if (b) { memcpy(path + pre_len + 1, b + (lilv_is_dir_sep(b[0]) ? 1 : 0), @@ -460,7 +460,7 @@ lilv_path_relative_to(const char* path, const char* base) const size_t suffix_len = path_len - last_shared_sep; char* rel = (char*)calloc(1, suffix_len + (up * 3) + 1); for (size_t i = 0; i < up; ++i) { - memcpy(rel + (i * 3), ".." LILV_DIR_SEP, 3); + memcpy(rel + (i * 3), "../", 3); } // Write suffix @@ -498,9 +498,11 @@ lilv_dir_for_each(const char* path, char* pat = lilv_path_join(path, "*"); WIN32_FIND_DATA fd; HANDLE fh = FindFirstFile(pat, &fd); - do { - f(path, fd.cFileName, data); - } while (FindNextFile(fh, &fd)); + if (fh != INVALID_HANDLE_VALUE) { + do { + f(path, fd.cFileName, data); + } while (FindNextFile(fh, &fd)); + } free(pat); #else DIR* dir = opendir(path); diff --git a/test/lilv_test.c b/test/lilv_test.c index f784fe4..55986c9 100644 --- a/test/lilv_test.c +++ b/test/lilv_test.c @@ -19,6 +19,7 @@ #include <assert.h> #include <ctype.h> +#include <errno.h> #include <float.h> #include <limits.h> #include <math.h> @@ -26,7 +27,16 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> -#include <unistd.h> + +#ifdef _MSC_VER +# include <direct.h> +# define mkdir(path, flags) _mkdir(path) +# define setenv(n, v, r) SetEnvironmentVariable((n), (v)) +# define unsetenv(n) SetEnvironmentVariable((n), NULL) +#else +# include <dirent.h> +# include <unistd.h> +#endif #include "lilv/lilv.h" #include "../src/lilv_internal.h" @@ -59,7 +69,7 @@ delete_bundle(void) { unlink(content_name); unlink(manifest_name); - rmdir(bundle_dir_name); + remove(bundle_dir_name); } void @@ -115,7 +125,7 @@ load_all_bundles(void) void create_bundle(char *manifest, char *content) { - if (mkdir(bundle_dir_name, 0700)) + if (mkdir(bundle_dir_name, 0700) && errno != EEXIST) fatal_error("Cannot create directory %s\n", bundle_dir_name); write_file(manifest_name, manifest); write_file(content_name, content); @@ -357,9 +367,9 @@ test_discovery(void) const LilvPlugins* plugins = lilv_world_get_all_plugins(world); TEST_ASSERT(lilv_plugins_size(plugins) > 0); - const const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); TEST_ASSERT(explug != NULL); - const const LilvPlugin* explug2 = lilv_plugins_get_by_uri(plugins, plugin2_uri_value); + const LilvPlugin* explug2 = lilv_plugins_get_by_uri(plugins, plugin2_uri_value); TEST_ASSERT(explug2 == NULL); if (explug) { @@ -385,6 +395,7 @@ test_discovery(void) int test_lv2_path(void) { +#ifndef _WIN32 char* orig_lv2_path = lilv_strdup(getenv("LV2_PATH")); setenv("LV2_PATH", "~/.lv2:/usr/local/lib/lv2:/usr/lib/lv2", 1); @@ -410,7 +421,7 @@ test_lv2_path(void) unsetenv("LV2_PATH"); } free(orig_lv2_path); - +#endif return 1; } @@ -431,7 +442,7 @@ test_verify(void) init_uris(); const LilvPlugins* plugins = lilv_world_get_all_plugins(world); - const const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); TEST_ASSERT(explug); TEST_ASSERT(lilv_plugin_verify(explug)); cleanup_uris(); @@ -484,7 +495,7 @@ test_classes(void) TEST_ASSERT(lilv_plugin_classes_size(classes) > lilv_plugin_classes_size(children)); TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_plugin_class_get_label(plugin)), "Plugin")); TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_plugin_class_get_uri(plugin)), - "http://lv2plug.in/ns/lv2core#Plugin")); + "http://lv2plug.in/ns/lv2core#Plugin")); LILV_FOREACH(plugin_classes, i, children) { TEST_ASSERT(lilv_node_equals( @@ -543,9 +554,9 @@ test_plugin(void) const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); TEST_ASSERT(plug); - const LilvPluginClass* class = lilv_plugin_get_class(plug); - const LilvNode* class_uri = lilv_plugin_class_get_uri(class); - TEST_ASSERT(!strcmp(lilv_node_as_string(class_uri), + const LilvPluginClass* klass = lilv_plugin_get_class(plug); + const LilvNode* klass_uri = lilv_plugin_class_get_uri(klass); + TEST_ASSERT(!strcmp(lilv_node_as_string(klass_uri), "http://lv2plug.in/ns/lv2core#CompressorPlugin")); const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug); @@ -1095,7 +1106,7 @@ map_uri(LV2_URID_Map_Handle handle, } } - uris = realloc(uris, ++n_uris * sizeof(char*)); + uris = (char**)realloc(uris, ++n_uris * sizeof(char*)); uris[n_uris - 1] = lilv_strdup(uri); return n_uris; } @@ -1441,6 +1452,7 @@ test_string(void) TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b")); free(s); TEST_ASSERT(!strcmp((s = lilv_path_join("/a", NULL)), "/a/")); free(s); +#ifndef _WIN32 setenv("LILV_TEST_1", "test", 1); char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL); TEST_ASSERT(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test")); free(s); @@ -1450,6 +1462,7 @@ test_string(void) TEST_ASSERT(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR")); free(s); free(home_foo); unsetenv("LILV_TEST_1"); +#endif return 1; } diff --git a/test/test_plugin.c b/test/test_plugin.c index 9eda8de..489ea26 100644 --- a/test/test_plugin.c +++ b/test/test_plugin.c @@ -96,7 +96,7 @@ instantiate(const LV2_Descriptor* descriptor, test->input = NULL; test->output = NULL; test->num_runs = 0; - test->tmp_file_path = malloc(L_tmpnam); + test->tmp_file_path = (char*)malloc(L_tmpnam); test->rec_file_path = NULL; test->rec_file = NULL; @@ -321,13 +321,11 @@ restore(LV2_Handle instance, &size, &type, &valflags); 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)) { + char* path = map_path->absolute_path(map_path->handle, apath); + if (strcmp(path, plugin->tmp_file_path)) { fprintf(stderr, "ERROR: Restored bad path `%s' != `%s'\n", - real_path, plugin->tmp_file_path); + path, plugin->tmp_file_path); } - free(real_path); free(path); } @@ -71,6 +71,11 @@ def configure(conf): else: conf.env.append_unique('CFLAGS', '-std=c99') + conf.env['BUILD_TESTS'] = Options.options.build_tests + conf.env['BUILD_UTILS'] = not Options.options.no_utils + conf.env['BUILD_STATIC'] = Options.options.static + conf.env['BASH_COMPLETION'] = not Options.options.no_bash_completion + autowaf.check_pkg(conf, 'lv2core', uselib_store='LV2CORE', mandatory=True) autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD', atleast_version='0.9.0', mandatory=True) @@ -85,6 +90,12 @@ def configure(conf): if Options.platform == 'darwin': defines += ['_DARWIN_C_SOURCE'] + # Check for gcov library (for test coverage) + if conf.env['BUILD_TESTS']: + conf.check_cc(lib='gcov', + define_name='HAVE_GCOV', + mandatory=False) + conf.check_cc(function_name='flock', header_name='sys/file.h', defines=defines, @@ -132,11 +143,6 @@ def configure(conf): '/usr/local/%s/lv2' % libdirname]) autowaf.define(conf, 'LILV_DEFAULT_LV2_PATH', lv2_path) - conf.env['BUILD_TESTS'] = Options.options.build_tests - conf.env['BUILD_UTILS'] = not Options.options.no_utils - conf.env['BUILD_STATIC'] = Options.options.static - conf.env['BASH_COMPLETION'] = not Options.options.no_bash_completion - conf.env['LIB_LILV'] = ['lilv-%s' % LILV_MAJOR_VERSION] conf.write_config_header('lilv_config.h', remove=False) @@ -153,6 +159,8 @@ def configure(conf): conf.is_defined('HAVE_LV2_STATE')) autowaf.display_msg(conf, "Python bindings", conf.is_defined('LILV_PYTHON')) + + conf.undefine('LILV_DEFAULT_LV2_PATH') # Cmd line errors with VC++ print('') def build(bld): @@ -181,8 +189,8 @@ def build(bld): src/zix/tree.c '''.split() - lib = [ 'dl' ] - libflags = [ '-fvisibility=hidden' ] + lib = ['dl'] + libflags = ['-fvisibility=hidden'] defines = [] if bld.env['MSVC_COMPILER']: lib = [] @@ -221,12 +229,18 @@ def build(bld): autowaf.use_lib(bld, obj, 'SORD LV2CORE LV2_STATE LV2_URID') if bld.env['BUILD_TESTS']: + test_libs = lib + test_cflags = [''] + if bld.is_defined('HAVE_GCOV'): + test_libs += ['gcov'] + test_cflags += ['-fprofile-arcs', '-ftest-coverage'] + # Test plugin library penv = bld.env.derive() shlib_pattern = penv['cshlib_PATTERN'] if shlib_pattern.startswith('lib'): shlib_pattern = shlib_pattern[3:] - penv['cshlib_PATTERN'] = shlib_pattern + penv['cshlib_PATTERN'] = shlib_pattern shlib_ext = shlib_pattern[shlib_pattern.rfind('.'):] obj = bld(features = 'c cshlib', @@ -236,6 +250,7 @@ def build(bld): target = 'test/test_plugin.lv2/test_plugin', install_path = None, defines = defines, + cflags = test_cflags, uselib = 'LV2CORE LV2_STATE LV2_URID') # Test plugin data files @@ -252,25 +267,25 @@ def build(bld): includes = ['.', './src'], name = 'liblilv_profiled', target = 'lilv_profiled', - install_path = '', - defines = defines, - cflags = [ '-fprofile-arcs', '-ftest-coverage', - '-DLILV_INTERNAL' ], - lib = lib + ['gcov']) + install_path = None, + defines = defines, + cflags = test_cflags + ['-DLILV_INTERNAL'], + lib = test_libs) autowaf.use_lib(bld, obj, 'SORD LV2CORE LV2_STATE LV2_URID') # Unit test program + bpath = os.path.abspath(os.path.join(out, 'test', 'test_plugin.lv2')) + bpath = bpath.replace('\\', '/') obj = bld(features = 'c cprogram', source = 'test/lilv_test.c', includes = ['.', './src'], use = 'liblilv_profiled', uselib = 'SORD LV2CORE', - lib = lib + ['gcov'], + lib = test_libs, target = 'test/lilv_test', - install_path = '', - defines = defines + ['LILV_TEST_BUNDLE=\"%s/\"' % os.path.abspath( - os.path.join(out, 'test', 'test_plugin.lv2'))], - cflags = [ '-fprofile-arcs', '-ftest-coverage' ]) + install_path = None, + defines = defines + ['LILV_TEST_BUNDLE=\"%s/\"' % bpath], + cflags = test_cflags) autowaf.use_lib(bld, obj, 'SORD LV2CORE LV2_STATE LV2_URID') # Utilities @@ -343,7 +358,8 @@ def upload_docs(ctx): def test(ctx): autowaf.pre_test(ctx, APPNAME) - autowaf.run_tests(ctx, APPNAME, ['test/lilv_test'], dirs=['./src','./test']) + os.environ['PATH'] = 'test' + os.pathsep + os.getenv('PATH') + autowaf.run_tests(ctx, APPNAME, ['lilv_test'], dirs=['./src','./test']) autowaf.post_test(ctx, APPNAME) def lint(ctx): |