From f2900dc9b3e05c8bb58e48e055e275176f548253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Fri, 15 Nov 2024 16:33:46 -0500 Subject: [PATCH] [tests] Add basic catch2 test infrastructure --- cmake/avendish.tests.cmake | 24 ++++++++++++++++++++++++ tests/objects/gain.cpp | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/objects/gain.cpp diff --git a/cmake/avendish.tests.cmake b/cmake/avendish.tests.cmake index bf1b859e..3467e207 100644 --- a/cmake/avendish.tests.cmake +++ b/cmake/avendish.tests.cmake @@ -10,7 +10,28 @@ function(avnd_add_executable_test theTarget theFile) avnd_common_setup("" "${theTarget}") endfunction() +function(avnd_add_catch_test theTarget theFile) + add_executable("${theTarget}" "${theFile}") + avnd_common_setup("" "${theTarget}") + target_link_libraries("${theTarget}" PRIVATE Catch2::Catch2WithMain) +endfunction() + if(BUILD_TESTING) + if(NOT TARGET Catch2::Catch2WithMain) + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.4.0 + ) + + FetchContent_MakeAvailable(Catch2) + if(NOT TARGET Catch2::Catch2WithMain) + message(WARNING "libremidi: Catch2::Catch2WithMain target not found") + return() + endif() + endif() + + avnd_add_static_test(test_introspection tests/test_introspection.cpp) avnd_add_static_test(test_introspection_rec tests/test_introspection_rec.cpp) avnd_add_static_test(test_predicate tests/test_predicate.cpp) @@ -21,4 +42,7 @@ if(BUILD_TESTING) avnd_add_static_test(test_index_in_struct tests/test_index_in_struct.cpp) avnd_add_executable_test(test_introspection_many tests/test_introspection_many.cpp) + + avnd_add_catch_test(test_gain tests/objects/gain.cpp) endif() + diff --git a/tests/objects/gain.cpp b/tests/objects/gain.cpp new file mode 100644 index 00000000..ead596ec --- /dev/null +++ b/tests/objects/gain.cpp @@ -0,0 +1,17 @@ +#include + +#include +TEST_CASE("Gain test", "[gain]") +{ + ao::Gain gain; + GIVEN("Correct input") + { + ao::Gain::inputs inputs; + inputs.gain.value = 0.5f; + THEN("Correct output") + { + double res = gain(1.5, inputs); + REQUIRE(res == 1.5 * 0.5); + } + } +}