diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-29 16:23:52 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-29 16:23:52 +0100 |
commit | c59d460f12e1393e0ddbaaa1c6f5522eb12f8ff9 (patch) | |
tree | e7d7ceabbb5b538b8fc57704750ccae9135be735 /src/test | |
parent | c2ef6a36532c8c078fd7836325d6be277b946cbf (diff) |
more utility classes for Audio system
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/AudioTest.cpp | 5 | ||||
-rw-r--r-- | src/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/test/PrivateTest.cpp | 66 |
3 files changed, 71 insertions, 1 deletions
diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp index afd2672..3be5afa 100644 --- a/src/test/AudioTest.cpp +++ b/src/test/AudioTest.cpp @@ -1,6 +1,7 @@ #include <gtest/gtest.h> #include <crepe/manager/ComponentManager.h> +#include <crepe/manager/ResourceManager.h> #include <crepe/api/AudioSource.h> #include <crepe/api/GameObject.h> #include <crepe/system/AudioSystem.h> @@ -13,15 +14,17 @@ class AudioTest : public Test { Mediator mediator; public: ComponentManager component_manager{mediator}; + ResourceManager resource_manager{mediator}; AudioSystem system {mediator}; void SetUp() override { auto & mgr = this->component_manager; GameObject entity = mgr.new_object("name"); - entity.add_component<AudioSource>("mwe/audio/sfx1.wav"); + AudioSource & audio_source = entity.add_component<AudioSource>("mwe/audio/sfx1.wav"); } }; TEST_F(AudioTest, Default) { + system.update(); } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 4174926..8c4b855 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -16,4 +16,5 @@ target_sources(test_main PUBLIC Vector2Test.cpp ScriptEventTest.cpp ScriptSceneTest.cpp + PrivateTest.cpp ) diff --git a/src/test/PrivateTest.cpp b/src/test/PrivateTest.cpp new file mode 100644 index 0000000..f0d2b1a --- /dev/null +++ b/src/test/PrivateTest.cpp @@ -0,0 +1,66 @@ +#include <gtest/gtest.h> + +#include <crepe/util/Private.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +class PrivateTest : public Test { +public: + static unsigned constructors; + static unsigned destructors; + + void SetUp() override { + PrivateTest::constructors = 0; + PrivateTest::destructors = 0; + } + + class TestClass { + public: + TestClass() { PrivateTest::constructors++; } + ~TestClass() { PrivateTest::destructors++; } + }; + class Unrelated {}; +}; +unsigned PrivateTest::constructors; +unsigned PrivateTest::destructors; + +TEST_F(PrivateTest, Empty) { + { + Private foo; + } + + EXPECT_EQ(PrivateTest::constructors, 0); + EXPECT_EQ(PrivateTest::destructors, 0); +} + +TEST_F(PrivateTest, WithObject) { + { + Private foo; + foo.set<TestClass>(); + + EXPECT_EQ(PrivateTest::constructors, 1); + EXPECT_EQ(PrivateTest::destructors, 0); + } + + EXPECT_EQ(PrivateTest::constructors, 1); + EXPECT_EQ(PrivateTest::destructors, 1); +} + +TEST_F(PrivateTest, EmptyException) { + Private foo; + EXPECT_THROW(foo.get<TestClass>(), std::out_of_range); + + foo.set<TestClass>(); + EXPECT_NO_THROW(foo.get<TestClass>()); +} + +TEST_F(PrivateTest, IncorrectTypeException) { + Private foo; + foo.set<TestClass>(); + + EXPECT_THROW(foo.get<Unrelated>(), std::logic_error); + EXPECT_NO_THROW(foo.get<TestClass>()); +} + |