aboutsummaryrefslogtreecommitdiff
path: root/src/test/AudioTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/AudioTest.cpp')
-rw-r--r--src/test/AudioTest.cpp51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp
index 3be5afa..c6f0097 100644
--- a/src/test/AudioTest.cpp
+++ b/src/test/AudioTest.cpp
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
+#include <future>
#include <crepe/manager/ComponentManager.h>
#include <crepe/manager/ResourceManager.h>
@@ -7,6 +8,7 @@
#include <crepe/system/AudioSystem.h>
using namespace std;
+using namespace std::chrono_literals;
using namespace crepe;
using namespace testing;
@@ -17,14 +19,51 @@ public:
ResourceManager resource_manager{mediator};
AudioSystem system {mediator};
- void SetUp() override {
- auto & mgr = this->component_manager;
- GameObject entity = mgr.new_object("name");
- AudioSource & audio_source = entity.add_component<AudioSource>("mwe/audio/sfx1.wav");
- }
+private:
+ GameObject entity = component_manager.new_object("name");
+public:
+ AudioSource & bgm = entity.add_component<AudioSource>("mwe/audio/bgm.ogg");
+ AudioSource & sfx1 = entity.add_component<AudioSource>("mwe/audio/sfx1.wav");
+ AudioSource & sfx2 = entity.add_component<AudioSource>("mwe/audio/sfx2.wav");
+ AudioSource & sfx3 = entity.add_component<AudioSource>("mwe/audio/sfx3.wav");
+
};
TEST_F(AudioTest, Default) {
- system.update();
+ bool example_done = false;
+
+ future example = async([&](){
+ // Start the background track
+ bgm.play();
+
+ // Play each sample sequentially while pausing and resuming the background track
+ this_thread::sleep_for(500ms);
+ sfx1.play();
+ this_thread::sleep_for(500ms);
+ sfx2.play();
+ bgm.stop();
+ this_thread::sleep_for(500ms);
+ sfx3.play();
+ bgm.play();
+ this_thread::sleep_for(500ms);
+
+ // Play all samples simultaniously
+ sfx1.play();
+ sfx2.play();
+ sfx3.play();
+ this_thread::sleep_for(1000ms);
+ });
+
+ future system_loop = async([&](){
+ while (!example_done) {
+ auto next = chrono::steady_clock::now() + 25ms;
+ system.update();
+ this_thread::sleep_until(next);
+ }
+ });
+
+ example.wait();
+ example_done = true;
+ system_loop.wait();
}