From 12dc837f510c358801b1befd00258c75e98ec816 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 16 Sep 2015 15:26:40 +0200 Subject: [PATCH] Tests for entity cloning --- src/tests/CMakeLists.txt | 1 + src/tests/EntityCloneTest.cpp | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/tests/EntityCloneTest.cpp diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 3e955f3..ae7d47f 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCE_FILES FileWatcherTest.cpp EventTest.cpp ComponentCopyTest.cpp + EntityCloneTest.cpp ) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/src/tests/EntityCloneTest.cpp b/src/tests/EntityCloneTest.cpp new file mode 100644 index 0000000..041f594 --- /dev/null +++ b/src/tests/EntityCloneTest.cpp @@ -0,0 +1,46 @@ +#include +#include "Core/EventBroker.h" +#include "Core/World.h" +#include "Core/CTemplate.h" +using namespace dd; + +struct TestComponent : public Component +{ + int Int = 5; + float Float = 1.33333f; + double Double = 1.33333; + std::string String = "Hello World"; +}; + +BOOST_AUTO_TEST_CASE(EntityCloneTest) +{ + // Setup world + std::shared_ptr eventBroker = std::make_shared(); + World world(eventBroker); + world.ComponentFactory.Register(); + world.ComponentFactory.Register(); + + // Create our original entity + EntityID entOriginal = world.CreateEntity(); + world.AddComponent(entOriginal); + world.AddComponent(entOriginal); + + // Clone it + EntityID entClone = world.CloneEntity(entOriginal); + + // Check + // EntityID of clone should not be same as original (obviously) + BOOST_CHECK(entOriginal != entClone); + // Template component SHOULD be in clone + auto templateComponentClone = world.GetComponent(entClone); + BOOST_REQUIRE(templateComponentClone != nullptr); + // Values should be the same across the clone + auto testComponentOriginal = world.GetComponent(entOriginal); + BOOST_REQUIRE(testComponentOriginal != nullptr); + auto testComponentClone = world.GetComponent(entClone); + BOOST_REQUIRE(testComponentClone != nullptr); + BOOST_CHECK(testComponentClone->Int == testComponentOriginal->Int); + BOOST_CHECK(testComponentClone->Float == testComponentOriginal->Float); + BOOST_CHECK(testComponentClone->Double == testComponentOriginal->Double); + BOOST_CHECK(testComponentClone->String == testComponentOriginal->String); +} \ No newline at end of file