From 03cf8e28f6fb5fb6c8f52c5c1c3462851ca7684e Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 2 Jan 2021 14:53:21 +0100 Subject: [PATCH] Add a unit test for issue 733 --- src/utils/fluid_settings.c | 4 + test/CMakeLists.txt | 1 + test/test_settings_unregister_callback.c | 95 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 test/test_settings_unregister_callback.c diff --git a/src/utils/fluid_settings.c b/src/utils/fluid_settings.c index 75248f42..979493f2 100644 --- a/src/utils/fluid_settings.c +++ b/src/utils/fluid_settings.c @@ -907,6 +907,10 @@ fluid_settings_get_hints(fluid_settings_t *settings, const char *name, int *hint * @param settings a settings object * @param name a setting's name * @return TRUE if the setting is changeable in real-time, FALSE otherwise + * + * @note Before using this function, make sure the @p settings object has already been used to create + * a synthesizer, a MIDI driver, an audio driver, a MIDI player, or a command handler (depending on + * which settings you want to query). */ int fluid_settings_is_realtime(fluid_settings_t *settings, const char *name) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d1325c5e..42b68fdd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,7 @@ ADD_FLUID_TEST(test_sfont_loading) ADD_FLUID_TEST(test_sample_rate_change) ADD_FLUID_TEST(test_preset_sample_loading) ADD_FLUID_TEST(test_bug_635) +ADD_FLUID_TEST(test_settings_unregister_callback) ADD_FLUID_TEST(test_pointer_alignment) ADD_FLUID_TEST(test_seqbind_unregister) ADD_FLUID_TEST(test_synth_chorus_reverb) diff --git a/test/test_settings_unregister_callback.c b/test/test_settings_unregister_callback.c new file mode 100644 index 00000000..e572fa6e --- /dev/null +++ b/test/test_settings_unregister_callback.c @@ -0,0 +1,95 @@ + +#include "test.h" +#include "fluidsynth.h" +#include "fluidsynth_priv.h" +#include "fluid_synth.h" +#include + +static fluid_list_t* realtime_int_settings = NULL; +static fluid_list_t* realtime_str_settings = NULL; +static fluid_list_t* realtime_num_settings = NULL; + +void iter_func (void *data, const char *name, int type) +{ + if(fluid_settings_is_realtime(data, name)) + { + switch(type) + { + case FLUID_INT_TYPE: + realtime_int_settings = fluid_list_prepend(realtime_int_settings, FLUID_STRDUP(name)); + break; + case FLUID_STR_TYPE: + realtime_str_settings = fluid_list_prepend(realtime_str_settings, FLUID_STRDUP(name)); + break; + case FLUID_NUM_TYPE: + realtime_num_settings = fluid_list_prepend(realtime_num_settings, FLUID_STRDUP(name)); + break; + case FLUID_SET_TYPE: + break; + default: + TEST_ASSERT(FALSE); + } + } +} + +// this test should make sure that sample rate changed are handled correctly +int main(void) +{ + fluid_list_t* list; + fluid_player_t* player; + fluid_synth_t *synth; + fluid_settings_t *settings = new_fluid_settings(); + TEST_ASSERT(settings != NULL); + + synth = new_fluid_synth(settings); + TEST_ASSERT(synth != NULL); + + player = new_fluid_player(synth); + TEST_ASSERT(player != NULL); + + // see which of the objects above has registered a realtime setting + fluid_settings_foreach(settings, settings, iter_func); + + // delete the objects + delete_fluid_player(player); + delete_fluid_synth(synth); + + // and now, start making changes to those realtime settings + // Anything below fluidsynth 2.1.5 will crash + + for(list = realtime_int_settings; list; list = fluid_list_next(list)) + { + int min, max; + char* name = fluid_list_get(list); + TEST_SUCCESS(fluid_settings_getint_range(settings, name, &min, &max)); + TEST_SUCCESS(fluid_settings_setint(settings, name, min)); + FLUID_FREE(name); + } + + delete_fluid_list(realtime_int_settings); + + for(list = realtime_num_settings; list; list = fluid_list_next(list)) + { + double min, max; + char* name = fluid_list_get(list); + TEST_SUCCESS(fluid_settings_getnum_range(settings, name, &min, &max)); + TEST_SUCCESS(fluid_settings_setnum(settings, name, min)); + FLUID_FREE(name); + } + + delete_fluid_list(realtime_num_settings); + + + for(list = realtime_str_settings; list; list = fluid_list_next(list)) + { + char* name = fluid_list_get(list); + TEST_SUCCESS(fluid_settings_setstr(settings, name, "ABCDEFG")); + FLUID_FREE(name); + } + + delete_fluid_list(realtime_str_settings); + + delete_fluid_settings(settings); + + return EXIT_SUCCESS; +}