diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-10 13:40:42 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-10 13:40:42 +0100 |
commit | d80c98ee03e59e0c38e025a7fe83ab4c39115fb8 (patch) | |
tree | c31c861b82d384e64071b4e7f64dfafe99b888c0 /src/test/AudioTest.cpp | |
parent | b2c72ee8ce282bb13b0fbeb2ddb01fdfd6ad1280 (diff) | |
parent | 7a8657dfe019104aced61a5b63e63f61ad919f7a (diff) |
font progress
Diffstat (limited to 'src/test/AudioTest.cpp')
-rw-r--r-- | src/test/AudioTest.cpp | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp new file mode 100644 index 0000000..774fdb8 --- /dev/null +++ b/src/test/AudioTest.cpp @@ -0,0 +1,152 @@ +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +#include <crepe/api/AudioSource.h> +#include <crepe/api/GameObject.h> +#include <crepe/manager/ComponentManager.h> +#include <crepe/manager/ResourceManager.h> +#include <crepe/system/AudioSystem.h> + +using namespace std; +using namespace std::chrono_literals; +using namespace crepe; +using namespace testing; + +class AudioTest : public Test { +private: + class TestSoundContext : public SoundContext { + public: + MOCK_METHOD(SoundHandle, play, (Sound & resource), (override)); + MOCK_METHOD(void, stop, (const SoundHandle &), (override)); + MOCK_METHOD(void, set_volume, (const SoundHandle &, float), (override)); + MOCK_METHOD(void, set_loop, (const SoundHandle &, bool), (override)); + }; + + class TestAudioSystem : public AudioSystem { + public: + using AudioSystem::AudioSystem; + StrictMock<TestSoundContext> context; + virtual SoundContext & get_context() { return this->context; } + }; + +private: + Mediator mediator; + ComponentManager component_manager{mediator}; + ResourceManager resource_manager{mediator}; + +public: + TestAudioSystem system{mediator}; + TestSoundContext & context = system.context; + +private: + GameObject entity = component_manager.new_object("name"); + +public: + AudioSource & component = entity.add_component<AudioSource>("mwe/audio/bgm.ogg"); +}; + +TEST_F(AudioTest, Default) { + EXPECT_CALL(context, play(_)).Times(0); + EXPECT_CALL(context, stop(_)).Times(0); + EXPECT_CALL(context, set_volume(_, _)).Times(0); + EXPECT_CALL(context, set_loop(_, _)).Times(0); + system.update(); +} + +TEST_F(AudioTest, Play) { + system.update(); + + { + InSequence seq; + + EXPECT_CALL(context, play(_)).Times(0); + component.play(); + } + + { + InSequence seq; + + EXPECT_CALL(context, play(_)).Times(1); + system.update(); + } +} + +TEST_F(AudioTest, Stop) { + system.update(); + + { + InSequence seq; + + EXPECT_CALL(context, stop(_)).Times(0); + component.stop(); + } + + { + InSequence seq; + + EXPECT_CALL(context, stop(_)).Times(1); + system.update(); + } +} + +TEST_F(AudioTest, Volume) { + system.update(); + + { + InSequence seq; + + EXPECT_CALL(context, set_volume(_, _)).Times(0); + component.volume += 0.2; + } + + { + InSequence seq; + + EXPECT_CALL(context, set_volume(_, component.volume)).Times(1); + system.update(); + } +} + +TEST_F(AudioTest, Looping) { + system.update(); + + { + InSequence seq; + + EXPECT_CALL(context, set_loop(_, _)).Times(0); + component.loop = !component.loop; + } + + { + InSequence seq; + + EXPECT_CALL(context, set_loop(_, component.loop)).Times(1); + system.update(); + } +} + +TEST_F(AudioTest, StopOnDeactivate) { + system.update(); + + { + InSequence seq; + + EXPECT_CALL(context, stop(_)).Times(1); + component.active = false; + system.update(); + } +} + +TEST_F(AudioTest, PlayOnActive) { + component.active = false; + component.play_on_awake = true; + system.update(); + + { + InSequence seq; + + EXPECT_CALL(context, play(_)).Times(1); + component.active = true; + system.update(); + } +} |