1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-10-06 09:07:19 +02:00

Merge pull request #603 from ShFil119/sounds_tests

Prepare tests for Sound and SoundBuffer
This commit is contained in:
Daniel Evans 2018-08-29 20:30:13 +01:00 committed by GitHub
commit 26398ca636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 110 additions and 8 deletions

View File

@ -10,6 +10,7 @@ cache:
environment:
APPVEYOR_SAVE_CACHE_ON_ERROR: true
ALSOFT_DRIVERS: null
PYTHON: "C:\\Python36-x64"
CMAKE_GENERATOR_BASE: "Visual Studio 15 2017"
NAME_SUFFIX: "windows"

View File

@ -22,8 +22,8 @@ struct Sound {
size_t id = 0;
bool isLoaded = false;
std::shared_ptr<SoundSource> source = nullptr;
std::unique_ptr<SoundBuffer> buffer = nullptr;
std::shared_ptr<SoundSource> source;
std::unique_ptr<SoundBuffer> buffer;
Sound() = default;

View File

@ -9,10 +9,7 @@
/// OpenAL tool for playing
/// sound instance.
class SoundBuffer {
friend class SoundManager;
public:
struct SoundBuffer {
SoundBuffer();
bool bufferData(SoundSource& soundSource);
@ -30,7 +27,6 @@ public:
void setGain(float gain);
void setMaxDistance(float maxDist);
private:
ALuint source;
ALuint buffer;
};

View File

@ -28,6 +28,11 @@ Sound& SoundManager::getSoundRef(const std::string& name) {
return sounds[name]; // @todo reloading, how to check is it wav/mp3?
}
SoundManager::SoundManager() {
initializeOpenAL();
initializeAVCodec();
}
SoundManager::SoundManager(GameWorld* engine) : _engine(engine) {
auto sdtPath = _engine->data->index.findFilePath("audio/sfx.SDT");
auto rawPath = _engine->data->index.findFilePath("audio/sfx.RAW");

View File

@ -29,6 +29,7 @@ class ViewCamera;
/// instances simultaneously without duplicating raw source).
class SoundManager {
public:
SoundManager();
SoundManager(GameWorld* engine);
~SoundManager();

View File

@ -9,7 +9,7 @@
/// (loading and decoding sound)
class SoundSource {
friend class SoundManager;
friend class SoundBuffer;
friend struct SoundBuffer;
public:
/// Load sound from mp3/wav file

View File

@ -17,6 +17,7 @@ docker=$1
TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
TRAVIS_BRANCH=$TRAVIS_BRANCH \
USE_CONAN=$USE_CONAN \
ALSOFT_DRIVERS=null \
DEBUG=$DEBUG \
XDG_RUNTIME_DIR=/tmp

View File

@ -28,6 +28,7 @@ set(TESTS
ScriptMachine
State
StringEncoding
Sound
Text
TrafficDirector
Vehicle

97
tests/test_Sound.cpp Normal file
View File

@ -0,0 +1,97 @@
#include <iostream>
#include <boost/test/unit_test.hpp>
#include <audio/Sound.hpp>
#include <audio/SoundManager.hpp>
BOOST_AUTO_TEST_SUITE(SoundTests)
struct F {
SoundManager manager{};
Sound sound{};
};
BOOST_FIXTURE_TEST_CASE(creates_empty_sound, F) {
// buffer and source should be empty
BOOST_REQUIRE(sound.buffer == nullptr);
BOOST_REQUIRE(sound.source == nullptr);
}
// @todo Shfil119 implement
// This test requires assets
//BOOST_AUTO_TEST_CASE(testBufferIsPlaying) {
// sound.buffer = std::make_unique<SoundBuffer>();
// BOOST_REQUIRE(sound.isPlaying() == false);
// sound.play();
// BOOST_REQUIRE(sound.isPlaying() == true);
// sound.pause();
// BOOST_REQUIRE(sound.isPaused() == true);
// sound.stop();
// BOOST_REQUIRE(sound.isStopped() == true);
//}
BOOST_FIXTURE_TEST_CASE(sound_sets_openal_source_position, F) {
sound.buffer = std::make_unique<SoundBuffer>();
glm::vec3 position = {100.f, 100.f, 100.f};
sound.setPosition(position);
float x{0.f}, y{0.f}, z{0.f};
alGetSource3f(sound.buffer->source, AL_POSITION, &x, &y, &z);
BOOST_REQUIRE(x == position.x);
BOOST_REQUIRE(y == position.y);
BOOST_REQUIRE(z == position.z);
}
BOOST_FIXTURE_TEST_CASE(sound_sets_openal_source_looping, F) {
sound.buffer = std::make_unique<SoundBuffer>();
// Default state should be false
// openAL should change value of state
int state = static_cast<bool>(true);
alGetSourcei(sound.buffer->source, AL_LOOPING, &state);
BOOST_REQUIRE(static_cast<bool>(state) == false);
sound.setLooping(true);
alGetSourcei(sound.buffer->source, AL_LOOPING, &state);
BOOST_REQUIRE(static_cast<bool>(state) == true);
}
BOOST_FIXTURE_TEST_CASE(sound_sets_openal_source_pitch, F) {
sound.buffer = std::make_unique<SoundBuffer>();
sound.setPitch(0.5f);
float pitch{0.f};
alGetSourcef(sound.buffer->source, AL_PITCH, &pitch);
BOOST_REQUIRE(pitch == 0.5f);
}
BOOST_FIXTURE_TEST_CASE(sound_sets_openal_source_gain, F) {
sound.buffer = std::make_unique<SoundBuffer>();
sound.setGain(0.5f);
float gain{0.f};
alGetSourcef(sound.buffer->source, AL_GAIN, &gain);
BOOST_REQUIRE(gain == 0.5f);
}
BOOST_FIXTURE_TEST_CASE(sound_sets_openal_source_max_distance, F) {
sound.buffer = std::make_unique<SoundBuffer>();
sound.setMaxDistance(1000.f);
float maxDistance{0.f};
alGetSourcef(sound.buffer->source, AL_MAX_DISTANCE, &maxDistance);
BOOST_REQUIRE(maxDistance == 1000.f);
}
BOOST_AUTO_TEST_SUITE_END()