From 044c5e3238ee82fe3e3c7c778d49a352c8fed0c7 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 24 Apr 2018 21:32:49 +0200 Subject: [PATCH] fuse preset iteration tests to preset+sample loading tests --- test/CMakeLists.txt | 3 +- test/test_defsfont_preset_iteration.c | 42 ----------- test/test_preset_sample_loading.c | 87 +++++++++++++++++++++++ test/test_sf3_defsfont_preset_iteration.c | 61 ---------------- 4 files changed, 88 insertions(+), 105 deletions(-) delete mode 100644 test/test_defsfont_preset_iteration.c create mode 100644 test/test_preset_sample_loading.c delete mode 100644 test/test_sf3_defsfont_preset_iteration.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9efb8e60..fa8e9c00 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,10 +11,9 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -C $ --output-on ## add unit tests here ## ADD_FLUID_TEST(test_sample_cache) ADD_FLUID_TEST(test_sfont_loading) -ADD_FLUID_TEST(test_defsfont_preset_iteration) ADD_FLUID_TEST(test_sample_rate_change) +ADD_FLUID_TEST(test_preset_sample_loading) if ( LIBSNDFILE_HASVORBIS ) ADD_FLUID_TEST(test_sf3_sfont_loading) - ADD_FLUID_TEST(test_sf3_defsfont_preset_iteration) endif ( LIBSNDFILE_HASVORBIS ) diff --git a/test/test_defsfont_preset_iteration.c b/test/test_defsfont_preset_iteration.c deleted file mode 100644 index 5b29e408..00000000 --- a/test/test_defsfont_preset_iteration.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test.h" -#include "fluidsynth.h" -#include "sfloader/fluid_sfont.h" -#include "utils/fluidsynth_priv.h" - -int main(void) -{ - int id; - fluid_sfont_t *sfont; - fluid_preset_t *preset; - fluid_preset_t *prev_preset = NULL; - int count = 0; - - /* setup */ - fluid_settings_t *settings = new_fluid_settings(); - fluid_synth_t *synth = new_fluid_synth(settings); - - /* Load the VintageDreams soundfont */ - id = fluid_synth_sfload(synth, TEST_SOUNDFONT, 1); - sfont = fluid_synth_get_sfont_by_id(synth, id); - - /* code under test */ - fluid_sfont_iteration_start(sfont); - - while ((preset = fluid_sfont_iteration_next(sfont)) != NULL) { - count++; - - /* make sure we actually got a different preset */ - TEST_ASSERT(preset != prev_preset); - - prev_preset = preset; - } - - /* VintageDreams has 136 presets */ - TEST_ASSERT(count == 136); - - /* teardown */ - delete_fluid_synth(synth); - delete_fluid_settings(settings); - - return EXIT_SUCCESS; -} diff --git a/test/test_preset_sample_loading.c b/test/test_preset_sample_loading.c new file mode 100644 index 00000000..0f0a2a35 --- /dev/null +++ b/test/test_preset_sample_loading.c @@ -0,0 +1,87 @@ +#include "test.h" +#include "fluidsynth.h" +#include "sfloader/fluid_sfont.h" +#include "sfloader/fluid_defsfont.h" +#include "utils/fluidsynth_priv.h" +#include "utils/fluid_list.h" + +// load our sf2 and sf3 test soundfonts, with and without dynamic sample loading +int main(void) +{ + int id[2], sfcount; + + /* setup */ + fluid_settings_t *settings = new_fluid_settings(); + + for(int dyn_sample=0; dyn_sample <= 1; dyn_sample++) + { + fluid_synth_t *synth; + fluid_settings_setint(settings, "synth.dynamic-sample-loading", dyn_sample); + synth = new_fluid_synth(settings); + id[0] = fluid_synth_sfload(synth, TEST_SOUNDFONT, 0); + id[1] = fluid_synth_sfload(synth, TEST_SOUNDFONT_SF3, 0); + sfcount = fluid_synth_sfcount(synth); + + TEST_ASSERT(id[0] != FLUID_FAILED); + +#if LIBSNDFILE_SUPPORT + TEST_ASSERT(id[1] != FLUID_FAILED); + TEST_ASSERT(sfcount == 2); +#else + TEST_ASSERT(id[1] == FLUID_FAILED); + TEST_ASSERT(sfcount == 1); +#endif + + for(int i=0; inotify != NULL) + { + preset->notify(preset, FLUID_PRESET_SELECTED, 0); + } + + /* make sure we actually got a different preset */ + TEST_ASSERT(preset != prev_preset); + prev_preset = preset; + } + /* VintageDreams has 136 presets */ + TEST_ASSERT(count == 136); + + /* Make sure we have the right number of samples */ + count = 0; + for (list = defsfont->sample; list; list = fluid_list_next(list)) + { + fluid_sample_t *sample = fluid_list_get(list); + if (sample->data != NULL) + { + count++; + } + + TEST_ASSERT(sample->amplitude_that_reaches_noise_floor_is_valid); + + /* Make sure we actually got a different sample */ + TEST_ASSERT(sample != prev_sample); + prev_sample = sample; + } + /* VintageDreams has 123 valid samples (one is a ROM sample and ignored) */ + TEST_ASSERT(count == 123); + } + /* teardown */ + delete_fluid_synth(synth); + } + delete_fluid_settings(settings); + + return EXIT_SUCCESS; +} diff --git a/test/test_sf3_defsfont_preset_iteration.c b/test/test_sf3_defsfont_preset_iteration.c deleted file mode 100644 index 9b131bd1..00000000 --- a/test/test_sf3_defsfont_preset_iteration.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "test.h" -#include "fluidsynth.h" -#include "sfloader/fluid_sfont.h" -#include "sfloader/fluid_defsfont.h" -#include "utils/fluidsynth_priv.h" -#include "utils/fluid_list.h" - -int main(void) -{ - int id; - fluid_sfont_t *sfont; - fluid_list_t *list; - fluid_preset_t *preset; - fluid_preset_t *prev_preset = NULL; - fluid_defsfont_t *defsfont; - fluid_sample_t *sample; - fluid_sample_t *prev_sample = NULL; - int count = 0; - - /* setup */ - fluid_settings_t *settings = new_fluid_settings(); - fluid_synth_t *synth = new_fluid_synth(settings); - id = fluid_synth_sfload(synth, TEST_SOUNDFONT_SF3, 1); - sfont = fluid_synth_get_sfont_by_id(synth, id); - defsfont = fluid_sfont_get_data(sfont); - - /* Make sure we have the right number of presets */ - fluid_sfont_iteration_start(sfont); - while ((preset = fluid_sfont_iteration_next(sfont)) != NULL) { - count++; - - /* make sure we actually got a different preset */ - TEST_ASSERT(preset != prev_preset); - prev_preset = preset; - } - /* VintageDreams has 136 presets */ - TEST_ASSERT(count == 136); - - /* Make sure we have the right number of samples */ - count = 0; - for (list = defsfont->sample; list; list = fluid_list_next(list)) - { - sample = fluid_list_get(list); - if (sample->data != NULL) - { - count++; - } - - /* Make sure we actually got a different sample */ - TEST_ASSERT(sample != prev_sample); - prev_sample = sample; - } - /* VintageDreams has 123 valid samples (one is a ROM sample and ignored) */ - TEST_ASSERT(count == 123); - - /* teardown */ - delete_fluid_synth(synth); - delete_fluid_settings(settings); - - return EXIT_SUCCESS; -}