From b81d3d955f1117a87a42766db57c18e3fea002f2 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 25 Sep 2020 03:10:20 +0100 Subject: [PATCH] Add a test for carla-host-plugin usage --- source/tests/Makefile | 17 +++-- source/tests/ansi-pedantic-test.c | 2 +- source/tests/carla-host-plugin.c | 110 ++++++++++++++++++++++++++++++ source/tests/valgrind.supp | 14 ++++ 4 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 source/tests/carla-host-plugin.c create mode 100644 source/tests/valgrind.supp diff --git a/source/tests/Makefile b/source/tests/Makefile index 4687f72f5..3bc3a568d 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -74,7 +74,8 @@ TARGETS = \ ansi-pedantic-test_cxx_ansi_run \ ansi-pedantic-test_cxx98_run \ ansi-pedantic-test_cxx03_run \ - ansi-pedantic-test_cxx11_run + ansi-pedantic-test_cxx11_run \ + carla-host-plugin_run # --------------------------------------------------------------------------------------------------------------------- @@ -82,8 +83,11 @@ all: $(TARGETS) # --------------------------------------------------------------------------------------------------------------------- -%_run: $(BINDIR)/% - $(BINDIR)/$* +ansi-%_run: $(BINDIR)/ansi-% + $(BINDIR)/ansi-$* + +carla-%_run: $(BINDIR)/carla-% + valgrind --leak-check=full --show-leak-kinds=all --suppressions=valgrind.supp $(BINDIR)/carla-$* # --------------------------------------------------------------------------------------------------------------------- @@ -115,8 +119,13 @@ $(BINDIR)/ansi-pedantic-test_cxx11: ansi-pedantic-test.cpp ../backend/Carla*.h . # --------------------------------------------------------------------------------------------------------------------- +$(BINDIR)/carla-host-plugin: carla-host-plugin.c + $(CC) $< $(PEDANTIC_CFLAGS) $(PEDANTIC_LDFLAGS) -Wno-declaration-after-statement -Wno-pedantic -lcarla_host-plugin -ansi -o $@ + +# --------------------------------------------------------------------------------------------------------------------- + clean: - rm -f $(BINDIR)/ansi-pedantic-test_* + rm -f $(BINDIR)/ansi-pedantic-test_* $(BINDIR)/carla-host-plugin debug: $(MAKE) DEBUG=true diff --git a/source/tests/ansi-pedantic-test.c b/source/tests/ansi-pedantic-test.c index f13c5418a..248f1d932 100644 --- a/source/tests/ansi-pedantic-test.c +++ b/source/tests/ansi-pedantic-test.c @@ -1,6 +1,6 @@ /* * ANSI pedantic test for the Carla Backend & Host API - * Copyright (C) 2013-2019 Filipe Coelho + * Copyright (C) 2013-2020 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as diff --git a/source/tests/carla-host-plugin.c b/source/tests/carla-host-plugin.c new file mode 100644 index 000000000..81437067f --- /dev/null +++ b/source/tests/carla-host-plugin.c @@ -0,0 +1,110 @@ +/* + * Carla Host Plugin test + * Copyright (C) 2020 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#include "CarlaNativePlugin.h" + +#include + +static uint32_t get_buffer_size(NativeHostHandle h) +{ + return 128; + + /* unused */ + (void)h; +} + +static double get_sample_rate(NativeHostHandle h) +{ + return 44100.0; + + /* unused */ + (void)h; +} + +static bool is_offline(NativeHostHandle h) +{ + return false; + + /* unused */ + (void)h; +} + +static intptr_t dispatcher(NativeHostHandle h, NativeHostDispatcherOpcode c, int32_t i, intptr_t v, void* p, float o) +{ + return 0; + + /* unused */ + (void)h; + (void)c; + (void)i; + (void)v; + (void)p; + (void)o; +} + +static const NativeHostDescriptor host_descriptor = { + .resourceDir = "", + .uiName = "", + .get_buffer_size = get_buffer_size, + .get_sample_rate = get_sample_rate, + .is_offline = is_offline, + .dispatcher = dispatcher +}; + +int main(void) +{ + const char* const standalone_filename = carla_standalone_get_library_filename(); + assert(standalone_filename != NULL && standalone_filename[0] != '\0'); + + const char* const utils_filename = carla_utils_get_library_filename(); + assert(utils_filename != NULL && utils_filename[0] != '\0'); + + const char* const standalone_folder = carla_standalone_get_library_folder(); + assert(standalone_folder != NULL && standalone_folder[0] != '\0'); + + const char* const utils_folder = carla_utils_get_library_folder(); + assert(utils_folder != NULL && utils_folder[0] != '\0'); +/* + carla_juce_init();*/ + + const NativePluginDescriptor* const rack = carla_get_native_rack_plugin(); + assert(rack != NULL); + + const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin(); + assert(patchbay != NULL); + + const NativePluginHandle rack_handle = rack->instantiate(&host_descriptor); + assert(rack_handle != NULL); + + const NativePluginHandle patchbay_handle = patchbay->instantiate(&host_descriptor); + assert(patchbay_handle != NULL); + + const CarlaHostHandle rack_host_handle = carla_create_native_plugin_host_handle(rack, rack_handle); + assert(rack_host_handle); + + const CarlaHostHandle patchbay_host_handle = carla_create_native_plugin_host_handle(patchbay, patchbay_handle); + assert(patchbay_host_handle); + + rack->cleanup(patchbay_handle); + rack->cleanup(rack_handle); + + carla_host_handle_free(patchbay_host_handle); + carla_host_handle_free(rack_host_handle); + /* + carla_juce_cleanup();*/ + return 0; +} diff --git a/source/tests/valgrind.supp b/source/tests/valgrind.supp new file mode 100644 index 000000000..007f7b825 --- /dev/null +++ b/source/tests/valgrind.supp @@ -0,0 +1,14 @@ +{ + libdl init part 1 + Memcheck:Leak + fun:calloc + ... + fun:_dl_init +} +{ + libdl init part 2 + Memcheck:Leak + fun:malloc + ... + fun:_dl_init +}