1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#include <SFML/Audio/SoundFileFactory.hpp>
// Other 1st party headers
#include <SFML/Audio/SoundChannel.hpp>
#include <SFML/Audio/SoundFileReader.hpp>
#include <SFML/Audio/SoundFileWriter.hpp>
#include <SFML/System/FileInputStream.hpp>
#include <SFML/System/InputStream.hpp>
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <type_traits>
#include <cstdint>
namespace
{
struct NoopSoundFileReader : sf::SoundFileReader
{
static bool check(sf::InputStream&)
{
return false;
}
std::optional<Info> 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<sf::SoundChannel>&) 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<sf::SoundFileFactory>);
STATIC_CHECK(std::is_copy_assignable_v<sf::SoundFileFactory>);
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::SoundFileFactory>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::SoundFileFactory>);
}
SECTION("isReaderRegistered()")
{
CHECK(!sf::SoundFileFactory::isReaderRegistered<NoopSoundFileReader>());
sf::SoundFileFactory::registerReader<NoopSoundFileReader>();
CHECK(sf::SoundFileFactory::isReaderRegistered<NoopSoundFileReader>());
sf::SoundFileFactory::unregisterReader<NoopSoundFileReader>();
CHECK(!sf::SoundFileFactory::isReaderRegistered<NoopSoundFileReader>());
}
SECTION("isWriterRegistered()")
{
CHECK(!sf::SoundFileFactory::isWriterRegistered<NoopSoundFileWriter>());
sf::SoundFileFactory::registerWriter<NoopSoundFileWriter>();
CHECK(sf::SoundFileFactory::isWriterRegistered<NoopSoundFileWriter>());
sf::SoundFileFactory::unregisterWriter<NoopSoundFileWriter>();
CHECK(!sf::SoundFileFactory::isWriterRegistered<NoopSoundFileWriter>());
}
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("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"));
}
}
}
|