diff --git a/test/Audio/SoundFileFactory.test.cpp b/test/Audio/SoundFileFactory.test.cpp new file mode 100644 index 000000000..ab688682c --- /dev/null +++ b/test/Audio/SoundFileFactory.test.cpp @@ -0,0 +1,89 @@ +#include + +// Other 1st party headers +#include +#include + +#include + +#include + +#include + +TEST_CASE("[Audio] sf::SoundFileFactory") +{ + SECTION("Type traits") + { + 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); + } + + SECTION("createReaderFromFilename()") + { + SECTION("Missing file") + { + CHECK(!sf::SoundFileFactory::createReaderFromFilename("does/not/exist.wav")); + } + + SECTION("Valid file") + { + CHECK(sf::SoundFileFactory::createReaderFromFilename("Audio/ding.flac")); + CHECK(sf::SoundFileFactory::createReaderFromFilename("Audio/ding.mp3")); + CHECK(sf::SoundFileFactory::createReaderFromFilename("Audio/doodle_pop.ogg")); + CHECK(sf::SoundFileFactory::createReaderFromFilename("Audio/killdeer.wav")); + } + } + + SECTION("createReaderFromStream()") + { + sf::FileInputStream stream; + + SECTION("Invalid stream") + { + CHECK(!sf::SoundFileFactory::createReaderFromStream(stream)); + } + + SECTION("Valid file") + { + SECTION("flac") + { + REQUIRE(stream.open("Audio/ding.flac")); + } + + SECTION("mp3") + { + REQUIRE(stream.open("Audio/ding.mp3")); + } + + SECTION("ogg") + { + REQUIRE(stream.open("Audio/doodle_pop.ogg")); + } + + SECTION("wav") + { + REQUIRE(stream.open("Audio/killdeer.wav")); + } + + CHECK(sf::SoundFileFactory::createReaderFromStream(stream)); + } + } + + SECTION("createWriterFromFilename()") + { + SECTION("Invalid extension") + { + CHECK(!sf::SoundFileFactory::createWriterFromFilename("cannot/write/to.txt")); + } + + SECTION("Valid extension") + { + CHECK(sf::SoundFileFactory::createWriterFromFilename("file.flac")); + CHECK(!sf::SoundFileFactory::createWriterFromFilename("file.mp3")); // Mp3 writing not yet implemented + CHECK(sf::SoundFileFactory::createWriterFromFilename("file.ogg")); + CHECK(sf::SoundFileFactory::createWriterFromFilename("file.wav")); + } + } +} diff --git a/test/Audio/ding.flac b/test/Audio/ding.flac new file mode 100644 index 000000000..9c873290e Binary files /dev/null and b/test/Audio/ding.flac differ diff --git a/test/Audio/ding.mp3 b/test/Audio/ding.mp3 new file mode 100644 index 000000000..ef47fd329 Binary files /dev/null and b/test/Audio/ding.mp3 differ diff --git a/test/Audio/doodle_pop.ogg b/test/Audio/doodle_pop.ogg new file mode 100644 index 000000000..555ea3480 Binary files /dev/null and b/test/Audio/doodle_pop.ogg differ diff --git a/test/Audio/killdeer.wav b/test/Audio/killdeer.wav new file mode 100644 index 000000000..46080e9fd Binary files /dev/null and b/test/Audio/killdeer.wav differ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04f87f056..16436d024 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -133,6 +133,7 @@ set(AUDIO_SRC Audio/Sound.test.cpp Audio/SoundBuffer.test.cpp Audio/SoundBufferRecorder.test.cpp + Audio/SoundFileFactory.test.cpp Audio/SoundRecorder.test.cpp Audio/SoundSource.test.cpp Audio/SoundStream.test.cpp