diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/AudioTest.cpp | 27 | ||||
-rw-r--r-- | src/test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/test/ResourceManagerTest.cpp | 75 | ||||
-rw-r--r-- | src/test/main.cpp | 13 |
4 files changed, 110 insertions, 7 deletions
diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp new file mode 100644 index 0000000..afd2672 --- /dev/null +++ b/src/test/AudioTest.cpp @@ -0,0 +1,27 @@ +#include <gtest/gtest.h> + +#include <crepe/manager/ComponentManager.h> +#include <crepe/api/AudioSource.h> +#include <crepe/api/GameObject.h> +#include <crepe/system/AudioSystem.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +class AudioTest : public Test { + Mediator mediator; +public: + ComponentManager component_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"); + } +}; + +TEST_F(AudioTest, Default) { +} + diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index d3e27b0..4174926 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -3,7 +3,9 @@ target_sources(test_main PUBLIC PhysicsTest.cpp ScriptTest.cpp ParticleTest.cpp + AudioTest.cpp AssetTest.cpp + ResourceManagerTest.cpp OptionalRefTest.cpp RenderSystemTest.cpp EventTest.cpp diff --git a/src/test/ResourceManagerTest.cpp b/src/test/ResourceManagerTest.cpp new file mode 100644 index 0000000..1f56e23 --- /dev/null +++ b/src/test/ResourceManagerTest.cpp @@ -0,0 +1,75 @@ +#include <gtest/gtest.h> + +#define private public +#define protected public + +#include <crepe/util/Log.h> +#include <crepe/manager/ResourceManager.h> +#include <crepe/api/GameObject.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +class ResourceManagerTest : public Test { + Mediator mediator; +public: + ResourceManager resource_manager{mediator}; + + Asset asset_a{"asset/texture/img.png"}; + Asset asset_b{"asset/texture/ERROR.png"}; + + class TestResource : public Resource { + public: + static unsigned instances; + + public: + const unsigned instance; + TestResource(const Asset & src) + : Resource(src), + instance(this->instances++) { } + ~TestResource() { this->instances--; } + bool operator == (const TestResource & other) const { + return this->instance == other.instance; + } + }; + +private: + void SetUp() override { + TestResource::instances = 0; + } +}; +unsigned ResourceManagerTest::TestResource::instances = 0; + +TEST_F(ResourceManagerTest, Default) { + TestResource & res_1 = resource_manager.get<TestResource>(asset_a); + TestResource & res_2 = resource_manager.get<TestResource>(asset_a); + TestResource & res_3 = resource_manager.get<TestResource>(asset_b); + TestResource & res_4 = resource_manager.get<TestResource>(asset_b); + + ASSERT_EQ(res_1, res_2); + ASSERT_EQ(res_3, res_4); + EXPECT_NE(res_1, res_3); + + EXPECT_EQ(TestResource::instances, 2); + + resource_manager.clear(); +} + +TEST_F(ResourceManagerTest, Persistent) { + resource_manager.set_persistent(asset_a, true); + EXPECT_EQ(TestResource::instances, 0); + + resource_manager.get<TestResource>(asset_a); + resource_manager.get<TestResource>(asset_a); + resource_manager.get<TestResource>(asset_b); + resource_manager.get<TestResource>(asset_b); + EXPECT_EQ(TestResource::instances, 2); + + resource_manager.clear(); + EXPECT_EQ(TestResource::instances, 1); + + resource_manager.clear_all(); + EXPECT_EQ(TestResource::instances, 0); +} + diff --git a/src/test/main.cpp b/src/test/main.cpp index aece72d..54f74fd 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -1,8 +1,4 @@ #include <gtest/gtest.h> - -#define protected public -#define private public - #include <crepe/api/Config.h> using namespace crepe; @@ -11,12 +7,14 @@ using namespace testing; class GlobalConfigReset : public EmptyTestEventListener { public: Config & cfg = Config::get_instance(); - Config cfg_default = Config(); // This function is called before each test void OnTestStart(const TestInfo &) override { - cfg = cfg_default; - cfg.log.level = Log::Level::WARNING; + cfg = { + .log = { + .level = Log::Level::WARNING, + }, + }; } }; @@ -28,3 +26,4 @@ int main(int argc, char ** argv) { return RUN_ALL_TESTS(); } + |