Test that music objects can't be used in a way that triggers a crash

This commit is contained in:
Chris Thrasher 2024-07-04 13:50:52 -06:00
parent fbd8407a5f
commit 8277fe1710
No known key found for this signature in database
GPG Key ID: 56FB686C9DFC8E2C

View File

@ -10,8 +10,34 @@
#include <thread>
#include <type_traits>
namespace
{
template <typename T>
struct Singleton
{
static T& getInstance()
{
static T instance;
return instance;
}
};
} // namespace
TEST_CASE("[Audio] sf::Music", runAudioDeviceTests())
{
// Section must be placed first within this TEST_CASE or else it will always pass
SECTION("Construction/destruction order")
{
struct MusicSingleton : Singleton<MusicSingleton>
{
std::optional<sf::Music> music;
};
MusicSingleton::getInstance();
MusicSingleton::getInstance().music = sf::Music::openFromFile("Audio/ding.flac").value();
CHECK(true); // Lack of a crash due to assertion failure signals success
}
SECTION("Type traits")
{
STATIC_CHECK(!std::is_copy_constructible_v<sf::Music>);