diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 3a6b4ad..57823c2 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -65,3 +65,5 @@ jobs: - name: Build run: cmake --build ${{ github.workspace }}/build --config ${{ matrix.build_type }} + - name: Tests + run: ctest --test-dir ${{ github.workspace }}/build --output-on-failure -C ${{ matrix.build_type }} diff --git a/.github/workflows/meson-multi-platform.yml b/.github/workflows/meson-multi-platform.yml index 8f7c680..72a3c16 100644 --- a/.github/workflows/meson-multi-platform.yml +++ b/.github/workflows/meson-multi-platform.yml @@ -79,12 +79,11 @@ jobs: CC: ${{ matrix.c_compiler }} CXX: ${{ matrix.cpp_compiler }} -# Uncomment once tests are added: -# - name: Run Tests -# run: meson test -C builddir/ -v -# - name: Upload Test Log -# uses: actions/upload-artifact@v4 -# if: failure() -# with: -# name: ${{ matrix.os }}_Meson_Testlog -# path: builddir/meson-logs/testlog.txt + - name: Run Tests + run: meson test -C builddir/ -v + - name: Upload Test Log + uses: actions/upload-artifact@v4 + if: failure() + with: + name: ${{ matrix.os }}_${{ matrix.cpp_compiler }}_Meson_Testlog + path: builddir/meson-logs/testlog.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b886159..28fcf6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,9 @@ install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spatialaudio) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${PROJECT_BINARY_DIR}/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spatialaudio) +enable_testing() +add_subdirectory(tests) + #Tarballs generation set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) diff --git a/meson.build b/meson.build index 3634bce..d6458aa 100644 --- a/meson.build +++ b/meson.build @@ -44,3 +44,5 @@ pkg_mod.generate( description : 'Spatial audio rendering library', subdirs : 'spatialaudio', ) + +subdir('tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..d48fdf3 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +# Tests + +function(spaudio_add_test name) + add_executable(${name} "${name}.cpp") + target_link_libraries(${name} PRIVATE spatialaudio-static) + add_test(NAME ${name} + COMMAND $) +endfunction() + +#add_executable(TestInsideAngleRange tests/TestInsideAngleRange.cpp) +#target_link_libraries(TestInsideAngleRange PRIVATE spatialaudio-static) +#add_test(NAME TestInsideAngleRange +# COMMAND $) + +spaudio_add_test(TestInsideAngleRange) diff --git a/tests/TestInsideAngleRange.cpp b/tests/TestInsideAngleRange.cpp new file mode 100644 index 0000000..befaec1 --- /dev/null +++ b/tests/TestInsideAngleRange.cpp @@ -0,0 +1,27 @@ +#undef NDEBUG +#include + +#include + +int main() { + assert(spaudio::insideAngleRange(45., -180., 180., 1e-6)); + assert(spaudio::insideAngleRange(-30., -90., 90., 1e-6)); + assert(spaudio::insideAngleRange(-110., -120., -100.)); + assert(spaudio::insideAngleRange(0., -90., 90., 0.)); + assert(spaudio::insideAngleRange(91., -90., 90., 0.) == false); + assert(spaudio::insideAngleRange(95., -90., 90., 5.)); + assert(spaudio::insideAngleRange(95., 90., -90., 0.)); + assert(spaudio::insideAngleRange(85., 90., -90., 0.) == false); + assert(spaudio::insideAngleRange(85., 90., -90., 5.)); + assert(spaudio::insideAngleRange(0., 0., 0., 0.)); + assert(spaudio::insideAngleRange(1., 0., 0., 0.) == false); + assert(spaudio::insideAngleRange(180., 180., 180., 0.)); + assert(spaudio::insideAngleRange(180., -180., -180., 0.)); + assert(spaudio::insideAngleRange(179., -180., -180., 0.) == false); + assert(spaudio::insideAngleRange(175., 180., 180., 5.)); + assert(spaudio::insideAngleRange(170., 180., 180., 5.) == false); + assert(spaudio::insideAngleRange(180., -180., 180., 0.)); + assert(spaudio::insideAngleRange(270., -180., 180., 0.)); + assert(spaudio::insideAngleRange(-90., -180., 180., 0.)); + assert(spaudio::insideAngleRange(0., -180., 180., 0.)); +} diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..b808767 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,4 @@ +# Tests + +e = executable('TestInsideAngleRange', 'TestInsideAngleRange.cpp', dependencies: [libspatialaudio_dep]) +test('TestInsideAngleRange', e)