From 9a2f59eb13a50b8461bb253725d862b493f13c49 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 23 Dec 2024 20:37:51 -0600 Subject: [PATCH] Add tests for `sfListener` --- test/Audio/Listener.test.cpp | 86 ++++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 1 + 2 files changed, 87 insertions(+) create mode 100644 test/Audio/Listener.test.cpp diff --git a/test/Audio/Listener.test.cpp b/test/Audio/Listener.test.cpp new file mode 100644 index 0000000..29fd1c0 --- /dev/null +++ b/test/Audio/Listener.test.cpp @@ -0,0 +1,86 @@ +#include + +#include + +TEST_CASE("[Audio] sfListener") +{ + SECTION("sfListenerCone") + { + constexpr sfListenerCone cone{}; + STATIC_CHECK(cone.innerAngle == 0); + STATIC_CHECK(cone.outerAngle == 0); + STATIC_CHECK(cone.outerGain == 0); + } + + SECTION("Set/get global volume") + { + CHECK(sfListener_getGlobalVolume() == 100); + sfListener_setGlobalVolume(42); + CHECK(sfListener_getGlobalVolume() == 42); + } + + SECTION("Set/get position") + { + sfVector3f position = sfListener_getPosition(); + CHECK(position.x == 0); + CHECK(position.y == 0); + CHECK(position.z == 0); + sfListener_setPosition({3, 4, 5}); + position = sfListener_getPosition(); + CHECK(position.x == 3); + CHECK(position.y == 4); + CHECK(position.z == 5); + } + + SECTION("Set/get direction") + { + sfVector3f direction = sfListener_getDirection(); + CHECK(direction.x == 0); + CHECK(direction.y == 0); + CHECK(direction.z == -1); + sfListener_setDirection({6, 7, 8}); + direction = sfListener_getDirection(); + CHECK(direction.x == 6); + CHECK(direction.y == 7); + CHECK(direction.z == 8); + } + + SECTION("Set/get velocity") + { + sfVector3f velocity = sfListener_getVelocity(); + CHECK(velocity.x == 0); + CHECK(velocity.y == 0); + CHECK(velocity.z == 0); + sfListener_setVelocity({9, 10, 11}); + velocity = sfListener_getVelocity(); + CHECK(velocity.x == 9); + CHECK(velocity.y == 10); + CHECK(velocity.z == 11); + } + + SECTION("Set/get cone") + { + sfListenerCone cone = sfListener_getCone(); + CHECK(cone.innerAngle == 360); + CHECK(cone.outerAngle == 360); + CHECK(cone.outerGain == 1); + sfListener_setCone({15, 30, 0.5f}); + cone = sfListener_getCone(); + CHECK(cone.innerAngle == 15); + CHECK(cone.outerAngle == 30); + CHECK(cone.outerGain == 0.5f); + } + + SECTION("Set/get up vector") + { + sfVector3f upVector = sfListener_getUpVector(); + CHECK(upVector.x == 0); + CHECK(upVector.y == 1); + CHECK(upVector.z == 0); + sfListener_setUpVector({12, 13, 14}); + upVector = sfListener_getUpVector(); + CHECK(upVector.x == 12); + CHECK(upVector.y == 13); + CHECK(upVector.z == 14); + } +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 928d1d5..8bb3ddb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -72,6 +72,7 @@ set_target_warnings(test-csfml-network) catch_discover_tests(test-csfml-network) add_executable(test-csfml-audio + Audio/Listener.test.cpp Audio/SoundChannel.test.cpp ) target_link_libraries(test-csfml-audio PRIVATE csfml-audio Catch2::Catch2WithMain SFML::Audio)