diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eed3bf5..19994656 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ option ( enable-fpe-check "enable Floating Point Exception checks and debug mess option ( enable-portaudio "compile PortAudio support" off ) option ( enable-profiling "profile the dsp code" off ) option ( enable-trap-on-fpe "enable SIGFPE trap on Floating Point Exceptions" off ) +option ( enable-tests "build unit tests (implicitly disables BUILD_SHARED_LIBS and overrides DEFAULT_SOUNDFONT)" off ) # Options enabled by default option ( enable-aufile "compile support for sound file output" on ) @@ -500,16 +501,27 @@ else ( enable-readline ) endif ( enable-readline ) +if(enable-tests) + # manipulate some variables to setup a proper test env + set(DEFAULT_SOUNDFONT "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf2") + + # force to build a static lib, in order to bypass the visibility control, allowing us + # to test fluidsynths private/internal functions + set(BUILD_SHARED_LIBS OFF) + + add_subdirectory ( test ) +endif(enable-tests) + + # General configuration file configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake ${CMAKE_BINARY_DIR}/config.h ) + # Process subdirectories add_subdirectory ( src ) add_subdirectory ( doc ) -add_subdirectory ( test ) - # pkg-config support set ( prefix "${CMAKE_INSTALL_PREFIX}" ) set ( exec_prefix "\${prefix}" ) diff --git a/cmake_admin/FluidUnitTest.cmake b/cmake_admin/FluidUnitTest.cmake index 4ffbdeea..93416956 100644 --- a/cmake_admin/FluidUnitTest.cmake +++ b/cmake_admin/FluidUnitTest.cmake @@ -5,8 +5,10 @@ macro ( ADD_FLUID_TEST _test ) # use the local include path to look for fluidsynth.h, as we cannot be sure fluidsynth is already installed target_include_directories(${_test} PUBLIC - $ - $) + $ # include auto generated headers + $ # include "normal" public (sub-)headers + $ # include private headers + ) ADD_TEST(NAME ${_test} COMMAND ${_test}) endmacro ( ADD_FLUID_TEST ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b8aecdca..8703c167 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,9 +4,12 @@ project(fluidsynth-test) ENABLE_TESTING() include ( FluidUnitTest ) - +## add unit tests here ## ADD_FLUID_TEST(test_sample_cache) -# make test only runs tests, but doesnt build them -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_sample_cache) +add_custom_target(check +COMMAND ${CMAKE_CTEST_COMMAND} -C $ --verbose --output-on-failure +DEPENDS +test_sample_cache +) diff --git a/test/test_sample_cache.c b/test/test_sample_cache.c index 07fbbd0a..6d3455d6 100644 --- a/test/test_sample_cache.c +++ b/test/test_sample_cache.c @@ -23,6 +23,8 @@ int main() TEST_ASSERT_NEQ(s[0], '\0'); + printf("Attempt to open %s\n", s); + // load a sfont to synth1 TEST_SUCCESS(fluid_synth_sfload(synth1, s, 1));