aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-29 17:30:45 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-29 17:30:45 +0100
commit693355f55193cb2ea4c29616073227e37665afc1 (patch)
tree37d2bd3e916b909fbac58ae836e8001166edf384 /src/test
parentc59d460f12e1393e0ddbaaa1c6f5522eb12f8ff9 (diff)
more audio system WIP
Diffstat (limited to 'src/test')
-rw-r--r--src/test/AudioTest.cpp51
-rw-r--r--src/test/PrivateTest.cpp92
2 files changed, 137 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();
}
diff --git a/src/test/PrivateTest.cpp b/src/test/PrivateTest.cpp
index f0d2b1a..0ea67d6 100644
--- a/src/test/PrivateTest.cpp
+++ b/src/test/PrivateTest.cpp
@@ -64,3 +64,95 @@ TEST_F(PrivateTest, IncorrectTypeException) {
EXPECT_NO_THROW(foo.get<TestClass>());
}
+TEST_F(PrivateTest, MoveConstructor) {
+ {
+ Private foo;
+ foo.set<TestClass>();
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+
+ Private bar(std::move(foo));
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+ }
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 1);
+}
+
+TEST_F(PrivateTest, MoveOperator) {
+ {
+ Private foo;
+ foo.set<TestClass>();
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+
+ Private bar = std::move(foo);
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+ }
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 1);
+}
+
+TEST_F(PrivateTest, CopyConstructor) {
+ {
+ Private foo;
+ foo.set<TestClass>();
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+
+ Private bar(foo);
+
+ EXPECT_TRUE(bar.empty());
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+ }
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 1);
+}
+
+TEST_F(PrivateTest, CopyOperator) {
+ {
+ Private foo;
+ foo.set<TestClass>();
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+
+ Private bar = foo;
+
+ EXPECT_TRUE(bar.empty());
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+ }
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 1);
+}
+
+TEST_F(PrivateTest, DoubleAssignment) {
+ {
+ Private foo;
+ foo.set<TestClass>();
+
+ EXPECT_EQ(PrivateTest::constructors, 1);
+ EXPECT_EQ(PrivateTest::destructors, 0);
+
+ foo.set<TestClass>();
+
+ EXPECT_EQ(PrivateTest::constructors, 2);
+ EXPECT_EQ(PrivateTest::destructors, 1);
+ }
+
+ EXPECT_EQ(PrivateTest::constructors, 2);
+ EXPECT_EQ(PrivateTest::destructors, 2);
+}
+