#include // Other 1st party headers #include #include #include #include #include #include #include #include #include #include namespace { struct NoopSoundFileReader : sf::SoundFileReader { static bool check(sf::InputStream&) { return false; } std::optional open(sf::InputStream&) override { return {}; } void seek(std::uint64_t) override { } std::uint64_t read(std::int16_t*, std::uint64_t) override { return 0; } }; struct NoopSoundFileWriter : sf::SoundFileWriter { static bool check(const std::filesystem::path&) { return false; } bool open(const std::filesystem::path&, unsigned int, unsigned int, const std::vector&) override { return false; } void write(const std::int16_t*, std::uint64_t) override { } }; } // namespace 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("isReaderRegistered()") { CHECK(!sf::SoundFileFactory::isReaderRegistered()); sf::SoundFileFactory::registerReader(); CHECK(sf::SoundFileFactory::isReaderRegistered()); sf::SoundFileFactory::unregisterReader(); CHECK(!sf::SoundFileFactory::isReaderRegistered()); } SECTION("isWriterRegistered()") { CHECK(!sf::SoundFileFactory::isWriterRegistered()); sf::SoundFileFactory::registerWriter(); CHECK(sf::SoundFileFactory::isWriterRegistered()); sf::SoundFileFactory::unregisterWriter(); CHECK(!sf::SoundFileFactory::isWriterRegistered()); } 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()") { std::optional stream; SECTION("flac") { stream = sf::FileInputStream::create("Audio/ding.flac"); } SECTION("mp3") { stream = sf::FileInputStream::create("Audio/ding.mp3"); } SECTION("ogg") { stream = sf::FileInputStream::create("Audio/doodle_pop.ogg"); } SECTION("wav") { stream = sf::FileInputStream::create("Audio/killdeer.wav"); } REQUIRE(stream); 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")); } } }