From e21ba4dc950bbe49a676d1dd5c8c1b3f604a438f Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 11 Nov 2024 11:45:16 -0700 Subject: [PATCH] Add more robust tests for `sf::Music::setLoopPoints` --- test/Audio/Music.test.cpp | 41 ++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/test/Audio/Music.test.cpp b/test/Audio/Music.test.cpp index 91a605b79..d2a573916 100644 --- a/test/Audio/Music.test.cpp +++ b/test/Audio/Music.test.cpp @@ -241,11 +241,42 @@ TEST_CASE("[Audio] sf::Music", runAudioDeviceTests()) SECTION("setLoopPoints()") { - sf::Music music("Audio/killdeer.wav"); - music.setLoopPoints({sf::seconds(1), sf::seconds(2)}); - const auto [offset, length] = music.getLoopPoints(); - CHECK(offset == sf::seconds(1)); - CHECK(length == sf::seconds(2)); + sf::Music music; + + SECTION("Uninitalized") + { + music.setLoopPoints({sf::seconds(1), sf::seconds(2)}); + const auto [offset, length] = music.getLoopPoints(); + CHECK(offset == sf::seconds(0)); + CHECK(length == sf::seconds(0)); + } + + REQUIRE(music.openFromFile("Audio/killdeer.wav")); + + SECTION("Within range") + { + music.setLoopPoints({sf::seconds(1), sf::seconds(2)}); + const auto [offset, length] = music.getLoopPoints(); + CHECK(offset == sf::seconds(1)); + CHECK(length == sf::seconds(2)); + } + + SECTION("Duration too long") + { + music.setLoopPoints({sf::seconds(1), sf::seconds(1'000)}); + const auto [offset, length] = music.getLoopPoints(); + CHECK(offset == sf::seconds(1)); + CHECK(length == sf::microseconds(4'122'040)); + } + + SECTION("Offset too long") + { + music.setLoopPoints({sf::seconds(1'000), sf::milliseconds(10)}); + const auto [offset, length] = music.getLoopPoints(); + CHECK(offset == sf::seconds(0)); + CHECK(length == sf::microseconds(5'122'040)); + } + CHECK(music.getChannelCount() == 1); CHECK(music.getSampleRate() == 22050); CHECK(music.getStatus() == sf::Music::Status::Stopped);