From a886fddbdb55f84ad7e90a6547f8c6de8729fc32 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 4 Feb 2025 15:05:27 -0700 Subject: [PATCH] Add tests for `sf::OutputSoundFile` --- test/Audio/OutputSoundFile.test.cpp | 44 +++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/test/Audio/OutputSoundFile.test.cpp b/test/Audio/OutputSoundFile.test.cpp index b1aee5d5f..2b2509093 100644 --- a/test/Audio/OutputSoundFile.test.cpp +++ b/test/Audio/OutputSoundFile.test.cpp @@ -1,9 +1,43 @@ #include +#include +#include + #include -static_assert(std::is_default_constructible_v); -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); +TEST_CASE("[Audio] sf::OutputSoundFile") +{ + SECTION("Type traits") + { + STATIC_CHECK(std::is_default_constructible_v); + STATIC_CHECK(!std::is_copy_constructible_v); + STATIC_CHECK(!std::is_copy_assignable_v); + STATIC_CHECK(std::is_nothrow_move_constructible_v); + STATIC_CHECK(std::is_nothrow_move_assignable_v); + } + + const std::u32string stem = GENERATE(U"tmp", U"tmp-ń", U"tmp-🐌"); + const std::u32string extension = GENERATE(U".wav", U".ogg"); // , U".flac"); FLAC fails to handle Unicode strings + const auto filename = std::filesystem::temp_directory_path() / std::filesystem::path(stem + extension); + const std::vector channelMap{sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight}; + + INFO("Filename: " << reinterpret_cast(filename.u8string().c_str())); + + SECTION("Construction") + { + { + const sf::OutputSoundFile outputSoundFile(filename, 44'100, static_cast(channelMap.size()), channelMap); + CHECK(std::filesystem::exists(filename)); + } + CHECK(std::filesystem::remove(filename)); + } + + SECTION("openFromFile()") + { + sf::OutputSoundFile outputSoundFile; + CHECK(outputSoundFile.openFromFile(filename, 44'100, static_cast(channelMap.size()), channelMap)); + CHECK(std::filesystem::exists(filename)); + outputSoundFile.close(); + CHECK(std::filesystem::remove(filename)); + } +}