2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/Audio/Sound.hpp>
|
|
|
|
|
2023-04-16 10:50:24 +08:00
|
|
|
// Other 1st party headers
|
|
|
|
#include <SFML/Audio/SoundBuffer.hpp>
|
|
|
|
|
|
|
|
#include <SFML/System/Time.hpp>
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include <AudioUtil.hpp>
|
|
|
|
#include <SystemUtil.hpp>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-04-16 10:50:24 +08:00
|
|
|
TEST_CASE("[Audio] sf::Sound", runAudioDeviceTests())
|
|
|
|
{
|
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(!std::is_constructible_v<sf::Sound, sf::SoundBuffer&&>);
|
2024-06-24 05:38:16 +08:00
|
|
|
STATIC_CHECK(!std::is_constructible_v<sf::Sound, const sf::SoundBuffer&&>);
|
2023-04-16 10:50:24 +08:00
|
|
|
STATIC_CHECK(std::is_copy_constructible_v<sf::Sound>);
|
|
|
|
STATIC_CHECK(std::is_copy_assignable_v<sf::Sound>);
|
|
|
|
STATIC_CHECK(std::is_move_constructible_v<sf::Sound>);
|
|
|
|
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::Sound>);
|
|
|
|
STATIC_CHECK(std::is_move_assignable_v<sf::Sound>);
|
|
|
|
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::Sound>);
|
|
|
|
STATIC_CHECK(std::has_virtual_destructor_v<sf::Sound>);
|
|
|
|
}
|
|
|
|
|
2024-05-19 05:37:06 +08:00
|
|
|
const auto soundBuffer = sf::SoundBuffer::loadFromFile("Audio/ding.flac").value();
|
2023-04-16 10:50:24 +08:00
|
|
|
|
|
|
|
SECTION("Construction")
|
|
|
|
{
|
|
|
|
const sf::Sound sound(soundBuffer);
|
|
|
|
CHECK(&sound.getBuffer() == &soundBuffer);
|
|
|
|
CHECK(!sound.getLoop());
|
|
|
|
CHECK(sound.getPlayingOffset() == sf::Time::Zero);
|
2024-05-17 02:57:40 +08:00
|
|
|
CHECK(sound.getStatus() == sf::Sound::Status::Stopped);
|
2023-04-16 10:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Copy semantics")
|
|
|
|
{
|
|
|
|
const sf::Sound sound(soundBuffer);
|
|
|
|
|
|
|
|
SECTION("Construction")
|
|
|
|
{
|
|
|
|
const sf::Sound soundCopy(sound); // NOLINT(performance-unnecessary-copy-initialization)
|
|
|
|
CHECK(&soundCopy.getBuffer() == &soundBuffer);
|
|
|
|
CHECK(!soundCopy.getLoop());
|
|
|
|
CHECK(soundCopy.getPlayingOffset() == sf::Time::Zero);
|
2024-05-17 02:57:40 +08:00
|
|
|
CHECK(soundCopy.getStatus() == sf::Sound::Status::Stopped);
|
2023-04-16 10:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Assignment")
|
|
|
|
{
|
2024-05-19 05:37:06 +08:00
|
|
|
const sf::SoundBuffer otherSoundBuffer = sf::SoundBuffer::loadFromFile("Audio/ding.flac").value();
|
|
|
|
sf::Sound soundCopy(otherSoundBuffer);
|
2023-04-16 10:50:24 +08:00
|
|
|
soundCopy = sound;
|
|
|
|
CHECK(&soundCopy.getBuffer() == &soundBuffer);
|
|
|
|
CHECK(!soundCopy.getLoop());
|
|
|
|
CHECK(soundCopy.getPlayingOffset() == sf::Time::Zero);
|
2024-05-17 02:57:40 +08:00
|
|
|
CHECK(soundCopy.getStatus() == sf::Sound::Status::Stopped);
|
2023-04-16 10:50:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Set/get buffer")
|
|
|
|
{
|
2024-05-19 05:37:06 +08:00
|
|
|
const sf::SoundBuffer otherSoundBuffer = sf::SoundBuffer::loadFromFile("Audio/ding.flac").value();
|
2023-04-16 10:50:24 +08:00
|
|
|
sf::Sound sound(soundBuffer);
|
|
|
|
sound.setBuffer(otherSoundBuffer);
|
|
|
|
CHECK(&sound.getBuffer() == &otherSoundBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Set/get loop")
|
|
|
|
{
|
|
|
|
sf::Sound sound(soundBuffer);
|
|
|
|
sound.setLoop(true);
|
|
|
|
CHECK(sound.getLoop());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Set/get playing offset")
|
|
|
|
{
|
|
|
|
sf::Sound sound(soundBuffer);
|
|
|
|
sound.setPlayingOffset(sf::seconds(10));
|
|
|
|
CHECK(sound.getPlayingOffset() == sf::seconds(10));
|
|
|
|
}
|
|
|
|
}
|