From 8277fe17101c8608918b1a2757f828bca292b18e Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 4 Jul 2024 13:50:52 -0600 Subject: [PATCH] Test that music objects can't be used in a way that triggers a crash --- test/Audio/Music.test.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/Audio/Music.test.cpp b/test/Audio/Music.test.cpp index c40a42c00..43348f77e 100644 --- a/test/Audio/Music.test.cpp +++ b/test/Audio/Music.test.cpp @@ -10,8 +10,34 @@ #include #include +namespace +{ +template +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 + { + std::optional 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);