Skip to content

Commit

Permalink
[tests] Add basic catch2 test infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Nov 26, 2024
1 parent aeb569b commit f2900dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmake/avendish.tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

17 changes: 17 additions & 0 deletions tests/objects/gain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <catch2/catch_all.hpp>

#include <examples/Advanced/Utilities/Gain.hpp>
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);
}
}
}

0 comments on commit f2900dc

Please sign in to comment.