From 9cc885fe6df62f698b72e665ab47f4188db25700 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 12 Feb 2015 22:15:46 +0100 Subject: Add new LV2 unit test. --- test/lv2.cc | 332 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 test/lv2.cc (limited to 'test/lv2.cc') diff --git a/test/lv2.cc b/test/lv2.cc new file mode 100644 index 0000000..d38aa06 --- /dev/null +++ b/test/lv2.cc @@ -0,0 +1,332 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * lv2.cc + * + * Thu Feb 12 14:55:41 CET 2015 + * Copyright 2015 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 + * (at your option) any later version. + * + * DrumGizmo 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. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +#include +#include +#include +#include + +#include "lv2_test_host.h" + +#define DG_URI "http://drumgizmo.org/lv2" + +/** + * Tests that should be performed: + * ------------------------------- + * - Run without port connects (shouldn't crash) + * - Run without output ports connects (shouldn't crash) + * - Run with buffer size 0 + * - Run with VERY LARGE buffer size (>1MB?) + * - Run with buffer size a prime number (and thereby not power of 2) + * - Run with HUGE number of midi events in one buffer (10000) + */ +class test_lv2 : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(test_lv2); + CPPUNIT_TEST(open_and_verify); + CPPUNIT_TEST(run_no_ports_connected); + CPPUNIT_TEST(run_no_output_ports_connected); + CPPUNIT_TEST(test1); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void open_and_verify() + { + int res; + + LV2TestHost h("/home/deva/docs/c/drumgizmo/install/lib/lv2"); + + res = h.open(DG_URI); + CPPUNIT_ASSERT(res == 0); + + res = h.verify(); + CPPUNIT_ASSERT(res == 0); + + res = h.close(); + CPPUNIT_ASSERT(res == 0); + } + + void run_no_ports_connected() + { + int res; + + LV2TestHost h("/home/deva/docs/c/drumgizmo/install/lib/lv2"); + + res = h.open(DG_URI); + CPPUNIT_ASSERT(res == 0); + + res = h.verify(); + CPPUNIT_ASSERT(res == 0); + + res = h.createInstance(); + CPPUNIT_ASSERT(res == 0); + + const char config_fmt[] = + "\n" + " %s\n" + " %s\n" + " %s\n" + " %f\n" + " %f\n" + " %s\n" + " %f\n" + " %s\n" + ""; + + const char drumkitfile[] = "kit/kit1.xml"; + const char midimapfile[] = "kit/midimap.xml"; + bool enable_velocity_modifier = true; + float velocity_modifier_falloff = 0.5; + float velocity_modifier_weight = 0.25; + bool enable_velocity_randomiser = false; + float velocity_randomiser_weight = 0.1; + bool enable_resampling = false; + + char config[sizeof(config_fmt) * 2]; + sprintf(config, config_fmt, + drumkitfile, + midimapfile, + enable_velocity_modifier?"true":"false", + velocity_modifier_falloff, + velocity_modifier_weight, + enable_velocity_randomiser?"true":"false", + velocity_randomiser_weight, + enable_resampling?"true":"false" + ); + + res = h.loadConfig(config, strlen(config)); + CPPUNIT_ASSERT(res == 0); + + // run for 1 samples to trigger kit loading + res = h.run(1); + CPPUNIT_ASSERT(res == 0); + sleep(1); // wait for kit to get loaded (async), + + res = h.run(100); + CPPUNIT_ASSERT(res == 0); + + res = h.destroyInstance(); + CPPUNIT_ASSERT(res == 0); + + res = h.close(); + CPPUNIT_ASSERT(res == 0); + } + + void run_no_output_ports_connected() + { + int res; + + LV2TestHost h("/home/deva/docs/c/drumgizmo/install/lib/lv2"); + + res = h.open(DG_URI); + CPPUNIT_ASSERT(res == 0); + + res = h.verify(); + CPPUNIT_ASSERT(res == 0); + + res = h.createInstance(); + CPPUNIT_ASSERT(res == 0); + + const char config_fmt[] = + "\n" + " %s\n" + " %s\n" + " %s\n" + " %f\n" + " %f\n" + " %s\n" + " %f\n" + " %s\n" + ""; + + const char drumkitfile[] = "kit/kit1.xml"; + const char midimapfile[] = "kit/midimap.xml"; + bool enable_velocity_modifier = true; + float velocity_modifier_falloff = 0.5; + float velocity_modifier_weight = 0.25; + bool enable_velocity_randomiser = false; + float velocity_randomiser_weight = 0.1; + bool enable_resampling = false; + + char config[sizeof(config_fmt) * 2]; + sprintf(config, config_fmt, + drumkitfile, + midimapfile, + enable_velocity_modifier?"true":"false", + velocity_modifier_falloff, + velocity_modifier_weight, + enable_velocity_randomiser?"true":"false", + velocity_randomiser_weight, + enable_resampling?"true":"false" + ); + + res = h.loadConfig(config, strlen(config)); + CPPUNIT_ASSERT(res == 0); + + // Port buffers: + char sequence_buffer[4096]; + + LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); + res = h.connectPort(0, seq.data()); + CPPUNIT_ASSERT(res == 0); + + // run for 1 samples to trigger kit loading + res = h.run(1); + CPPUNIT_ASSERT(res == 0); + sleep(1); // wait for kit to get loaded (async), + + seq.addMidiNote(5, 1, 127); + res = h.run(100); + CPPUNIT_ASSERT(res == 0); + + res = h.destroyInstance(); + CPPUNIT_ASSERT(res == 0); + + res = h.close(); + CPPUNIT_ASSERT(res == 0); + } + + void test1() + { + int res; + + LV2TestHost h("/home/deva/docs/c/drumgizmo/install/lib/lv2"); + + res = h.open(DG_URI); + CPPUNIT_ASSERT(res == 0); + + res = h.verify(); + CPPUNIT_ASSERT(res == 0); + + res = h.createInstance(); + CPPUNIT_ASSERT(res == 0); + + const char config_fmt[] = + "\n" + " %s\n" + " %s\n" + " %s\n" + " %f\n" + " %f\n" + " %s\n" + " %f\n" + " %s\n" + ""; + + const char drumkitfile[] = "kit/kit1.xml"; + const char midimapfile[] = "kit/midimap.xml"; + bool enable_velocity_modifier = true; + float velocity_modifier_falloff = 0.5; + float velocity_modifier_weight = 0.25; + bool enable_velocity_randomiser = false; + float velocity_randomiser_weight = 0.1; + bool enable_resampling = false; + + char config[sizeof(config_fmt) * 2]; + sprintf(config, config_fmt, + drumkitfile, + midimapfile, + enable_velocity_modifier?"true":"false", + velocity_modifier_falloff, + velocity_modifier_weight, + enable_velocity_randomiser?"true":"false", + velocity_randomiser_weight, + enable_resampling?"true":"false" + ); + + res = h.loadConfig(config, strlen(config)); + CPPUNIT_ASSERT(res == 0); + + // Port buffers: + char sequence_buffer[4096]; + float pcm_buffer[16][10]; + + LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); + res = h.connectPort(0, seq.data()); + CPPUNIT_ASSERT(res == 0); + + for(int i = 1; i <= 16; i++) { + memset(pcm_buffer, 1, sizeof(pcm_buffer)); + res += h.connectPort(i, pcm_buffer[i-1]); + } + CPPUNIT_ASSERT(res == 0); + + // run for 1 samples to trigger kit loading + res = h.run(1); + CPPUNIT_ASSERT(res == 0); + sleep(1); // wait for kit to get loaded (async), + + /* + seq.addMidiNote(5, 1, 127); + for(int i = 0; i < 10; i++) { + res = h.run(10); + CPPUNIT_ASSERT(res == 0); + + printf("Iteration:\n"); + for(int k = 0; k < 4; k++) { + printf("#%d ", k); + for(int j = 0; j < 10; j++) printf("[%f]", pcm_buffer[k][j]); + printf("\n"); + } + printf("\n"); + + seq.clear(); + } + */ + + seq.addMidiNote(5, 1, 127); + res = h.run(10); + CPPUNIT_ASSERT(res == 0); + + union { + float f; + unsigned int u; + } comp_val; + + comp_val.u = 1040744448; + + for(int k = 0; k < 4; k++) { + for(int j = 0; j < 10; j++) { + CPPUNIT_ASSERT(pcm_buffer[k][j] == ((j==4)?comp_val.f:0)); + } + } + seq.clear(); + + res = h.destroyInstance(); + CPPUNIT_ASSERT(res == 0); + + res = h.close(); + CPPUNIT_ASSERT(res == 0); + } +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_lv2); -- cgit v1.2.3