Move ComputeTest,GraphicsTest,RenderTest and Std140Debug to the tests folder
Also renamed NazaraUnitTests to UnitTests
This commit is contained in:
20
tests/UnitTests/Engine/Audio/AlgorithmAudioTest.cpp
Normal file
20
tests/UnitTests/Engine/Audio/AlgorithmAudioTest.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <Nazara/Audio/Algorithm.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
TEST_CASE("MixToMono", "[AUDIO][ALGORITHM]")
|
||||
{
|
||||
SECTION("Mix two channels together")
|
||||
{
|
||||
std::array<int, 4> input = { { 1, 3, 5, 3 } };
|
||||
std::array<int, 2> output = { { 0, 0 } };
|
||||
|
||||
// Two channels and two frames !
|
||||
Nz::MixToMono(input.data(), output.data(), 2, 2);
|
||||
|
||||
std::array<int, 2> theoric = { { 2, 4 } }; // It's the mean of the two channels
|
||||
CHECK(output == theoric);
|
||||
}
|
||||
}
|
||||
109
tests/UnitTests/Engine/Audio/MusicTest.cpp
Normal file
109
tests/UnitTests/Engine/Audio/MusicTest.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <Nazara/Audio/Music.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("Music", "[AUDIO][MUSIC]")
|
||||
{
|
||||
GIVEN("A music")
|
||||
{
|
||||
Nz::Music music;
|
||||
|
||||
WHEN("We load our music")
|
||||
{
|
||||
REQUIRE(music.OpenFromFile(GetAssetDir() / "Audio/The_Brabanconne.ogg"));
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(music.GetDuration() == 63059); // 1 min 03 = 63s = 63000ms
|
||||
CHECK(music.GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(music.GetPlayingOffset() == 0);
|
||||
CHECK(music.GetSampleCount() <= 64 * 44100 * 2); // * 2 (stereo)
|
||||
CHECK(music.GetSampleCount() >= 63 * 44100 * 2); // * 2 (stereo)
|
||||
CHECK(music.GetSampleRate() == 44100 /* Hz */);
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Stopped);
|
||||
CHECK_FALSE(music.IsLooping());
|
||||
CHECK(music.IsSpatializationEnabled());
|
||||
CHECK(music.GetMinDistance() == 1.f);
|
||||
CHECK(music.GetPitch() == 1.f);
|
||||
CHECK(music.GetPlayingOffset() == 0);
|
||||
CHECK(music.GetPosition() == Nz::Vector3f::Zero());
|
||||
CHECK(music.GetVelocity() == Nz::Vector3f::Zero());
|
||||
CHECK(music.GetVolume() == 1.f);
|
||||
}
|
||||
|
||||
THEN("We can play it and get the time offset")
|
||||
{
|
||||
Nz::Audio::Instance()->GetDefaultDevice()->SetGlobalVolume(0.f);
|
||||
|
||||
music.Play();
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
CHECK(music.GetPlayingOffset() >= 950);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
CHECK(music.GetPlayingOffset() <= 1500);
|
||||
|
||||
music.SetPlayingOffset(4200);
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(music.GetPlayingOffset() >= 4150);
|
||||
CHECK(music.GetPlayingOffset() < 4500);
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
|
||||
music.Pause();
|
||||
Nz::UInt32 playingOffset = music.GetPlayingOffset();
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Paused);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Paused);
|
||||
CHECK(music.GetPlayingOffset() == playingOffset);
|
||||
|
||||
music.SetPlayingOffset(3500);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
CHECK(music.GetPlayingOffset() == 3500);
|
||||
|
||||
music.Play();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(music.GetPlayingOffset() >= 3650);
|
||||
|
||||
AND_WHEN("We let the sound stop by itself")
|
||||
{
|
||||
REQUIRE(music.GetDuration() == 63059);
|
||||
|
||||
music.SetPlayingOffset(62900);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Stopped);
|
||||
CHECK(music.GetPlayingOffset() == 0);
|
||||
|
||||
music.SetPlayingOffset(64000);
|
||||
music.Play();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(music.GetPlayingOffset() < 100);
|
||||
|
||||
music.Stop();
|
||||
music.SetPlayingOffset(62900);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Stopped);
|
||||
CHECK(music.GetPlayingOffset() == 0); //< playing offset has no effect until Play()
|
||||
|
||||
AND_WHEN("We enable looping")
|
||||
{
|
||||
music.EnableLooping(true);
|
||||
CHECK(music.IsLooping());
|
||||
music.Play();
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(music.GetPlayingOffset() >= 62900);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(music.GetPlayingOffset() < 300);
|
||||
}
|
||||
}
|
||||
Nz::Audio::Instance()->GetDefaultDevice()->SetGlobalVolume(100.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
tests/UnitTests/Engine/Audio/SoundBufferTest.cpp
Normal file
63
tests/UnitTests/Engine/Audio/SoundBufferTest.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("SoundBuffer", "[AUDIO][SOUNDBUFFER]")
|
||||
{
|
||||
GIVEN("A sound buffer")
|
||||
{
|
||||
WHEN("We load a .flac file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetAssetDir() / "Audio/Cat.flac");
|
||||
REQUIRE(soundBuffer);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundBuffer->GetDuration() == 8192);
|
||||
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(soundBuffer->GetSampleRate() == 96000);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We load a .mp3 file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetAssetDir() / "Audio/file_example_MP3_700KB.mp3");
|
||||
REQUIRE(soundBuffer);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundBuffer->GetDuration() == 27193);
|
||||
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(soundBuffer->GetSampleRate() == 32000);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We load a .ogg file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetAssetDir() / "Audio/The_Brabanconne.ogg");
|
||||
REQUIRE(soundBuffer);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundBuffer->GetDuration() == 63059);
|
||||
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(soundBuffer->GetSampleRate() == 44100);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We load a .wav file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetAssetDir() / "Audio/explosion1.wav");
|
||||
REQUIRE(soundBuffer);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundBuffer->GetDuration() == 2490);
|
||||
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Mono);
|
||||
CHECK(soundBuffer->GetSampleRate() == 44100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
tests/UnitTests/Engine/Audio/SoundEmitterTest.cpp
Normal file
42
tests/UnitTests/Engine/Audio/SoundEmitterTest.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <Nazara/Audio/Sound.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("SoundEmitter", "[AUDIO][SOUNDEMITTER]")
|
||||
{
|
||||
GIVEN("A sound emitter")
|
||||
{
|
||||
Nz::Sound sound;
|
||||
|
||||
WHEN("We load our sound")
|
||||
{
|
||||
REQUIRE(sound.LoadFromFile(GetAssetDir() / "Audio/Cat.flac"));
|
||||
|
||||
THEN("We can ask information about position and velocity")
|
||||
{
|
||||
sound.EnableSpatialization(true);
|
||||
sound.SetPosition(Nz::Vector3f::Zero());
|
||||
sound.SetVelocity(Nz::Vector3f::UnitX());
|
||||
|
||||
REQUIRE(sound.IsSpatializationEnabled());
|
||||
REQUIRE(sound.GetPosition() == Nz::Vector3f::Zero());
|
||||
REQUIRE(sound.GetVelocity() == Nz::Vector3f::UnitX());
|
||||
}
|
||||
|
||||
THEN("We can ask information about attenuation, pitch, ...")
|
||||
{
|
||||
sound.SetAttenuation(0.4f);
|
||||
sound.SetMinDistance(40.f);
|
||||
sound.SetPitch(0.8f);
|
||||
sound.SetVolume(50.f);
|
||||
|
||||
REQUIRE(Catch::Approx(sound.GetAttenuation()) == 0.4f);
|
||||
REQUIRE(Catch::Approx(sound.GetMinDistance()) == 40.f);
|
||||
REQUIRE(Catch::Approx(sound.GetPitch()) == 0.8f);
|
||||
REQUIRE(Catch::Approx(sound.GetVolume()) == 50.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
tests/UnitTests/Engine/Audio/SoundStreamTest.cpp
Normal file
63
tests/UnitTests/Engine/Audio/SoundStreamTest.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <Nazara/Audio/SoundStream.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("SoundStream", "[AUDIO][SoundStream]")
|
||||
{
|
||||
GIVEN("A sound buffer")
|
||||
{
|
||||
WHEN("We load a .flac file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundStream> soundStream = Nz::SoundStream::OpenFromFile(GetAssetDir() / "Audio/Cat.flac");
|
||||
REQUIRE(soundStream);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundStream->GetDuration() == 8192);
|
||||
CHECK(soundStream->GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(soundStream->GetSampleRate() == 96000);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We load a .mp3 file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundStream> soundStream = Nz::SoundStream::OpenFromFile(GetAssetDir() / "Audio/file_example_MP3_700KB.mp3");
|
||||
REQUIRE(soundStream);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundStream->GetDuration() == 27193);
|
||||
CHECK(soundStream->GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(soundStream->GetSampleRate() == 32000);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We load a .ogg file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundStream> soundStream = Nz::SoundStream::OpenFromFile(GetAssetDir() / "Audio/The_Brabanconne.ogg");
|
||||
REQUIRE(soundStream);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundStream->GetDuration() == 63059);
|
||||
CHECK(soundStream->GetFormat() == Nz::AudioFormat::I16_Stereo);
|
||||
CHECK(soundStream->GetSampleRate() == 44100);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We load a .wav file")
|
||||
{
|
||||
std::shared_ptr<Nz::SoundStream> soundStream = Nz::SoundStream::OpenFromFile(GetAssetDir() / "Audio/explosion1.wav");
|
||||
REQUIRE(soundStream);
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(soundStream->GetDuration() == 2490);
|
||||
CHECK(soundStream->GetFormat() == Nz::AudioFormat::I16_Mono);
|
||||
CHECK(soundStream->GetSampleRate() == 44100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
95
tests/UnitTests/Engine/Audio/SoundTest.cpp
Normal file
95
tests/UnitTests/Engine/Audio/SoundTest.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <Nazara/Audio/Sound.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("Sound", "[AUDIO][SOUND]")
|
||||
{
|
||||
GIVEN("A sound")
|
||||
{
|
||||
Nz::Sound sound;
|
||||
|
||||
WHEN("We load our sound")
|
||||
{
|
||||
REQUIRE(sound.LoadFromFile(GetAssetDir() / "Audio/Cat.flac"));
|
||||
|
||||
THEN("We can ask the informations of the file")
|
||||
{
|
||||
CHECK(sound.GetDuration() == 8192);
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Stopped);
|
||||
CHECK_FALSE(sound.IsLooping());
|
||||
CHECK(sound.IsPlayable());
|
||||
CHECK(sound.IsSpatializationEnabled());
|
||||
CHECK(sound.GetMinDistance() == 1.f);
|
||||
CHECK(sound.GetPitch() == 1.f);
|
||||
CHECK(sound.GetPlayingOffset() == 0);
|
||||
CHECK(sound.GetPosition() == Nz::Vector3f::Zero());
|
||||
CHECK(sound.GetVelocity() == Nz::Vector3f::Zero());
|
||||
CHECK(sound.GetVolume() == 1.f);
|
||||
}
|
||||
|
||||
THEN("We can play it and get the time offset")
|
||||
{
|
||||
Nz::Audio::Instance()->GetDefaultDevice()->SetGlobalVolume(0.f);
|
||||
|
||||
sound.Play();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
CHECK(sound.GetPlayingOffset() >= 950);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
CHECK(sound.GetPlayingOffset() <= 1500);
|
||||
sound.Pause();
|
||||
Nz::UInt32 playingOffset = sound.GetPlayingOffset();
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Paused);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Paused);
|
||||
CHECK(sound.GetPlayingOffset() == playingOffset);
|
||||
|
||||
sound.SetPlayingOffset(3500);
|
||||
CHECK(sound.GetPlayingOffset() == 3500);
|
||||
|
||||
sound.Play();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
CHECK(sound.GetPlayingOffset() >= 1650);
|
||||
|
||||
AND_WHEN("We let the sound stop by itself")
|
||||
{
|
||||
REQUIRE(sound.GetDuration() == 8192);
|
||||
|
||||
sound.SetPlayingOffset(8000);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Stopped);
|
||||
CHECK(sound.GetPlayingOffset() == 0);
|
||||
|
||||
sound.SetPlayingOffset(9000);
|
||||
sound.Play();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Playing);
|
||||
|
||||
sound.Stop();
|
||||
sound.SetPlayingOffset(8000);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Stopped);
|
||||
CHECK(sound.GetPlayingOffset() == 0); //< playing offset has no effect until Play()
|
||||
|
||||
AND_WHEN("We enable looping")
|
||||
{
|
||||
sound.EnableLooping(true);
|
||||
CHECK(sound.IsLooping());
|
||||
sound.Play();
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(sound.GetPlayingOffset() >= 8000);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
CHECK(sound.GetStatus() == Nz::SoundStatus::Playing);
|
||||
CHECK(sound.GetPlayingOffset() < 300);
|
||||
}
|
||||
}
|
||||
|
||||
Nz::Audio::Instance()->GetDefaultDevice()->SetGlobalVolume(100.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user