From c9cbda76adefa60887a6d42c63995bbf0fb3fd9c Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Sun, 31 Jan 2021 14:47:38 +0000 Subject: [PATCH] Add two new tests for entity selection Test that selecting an entity propagates the selected node to the selection system (which passes), and test that we can destroy a selected entity (which currently fails due to trying to call shared_from_this() in a destructor). --- test/Entity.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/Entity.cpp b/test/Entity.cpp index 87c94ce8a0..f1c5a9c24a 100644 --- a/test/Entity.cpp +++ b/test/Entity.cpp @@ -4,6 +4,7 @@ #include "ientity.h" #include "irendersystemfactory.h" #include "iselectable.h" +#include "iselection.h" #include "render/NopVolumeTest.h" @@ -276,10 +277,35 @@ namespace }; } +TEST_F(EntityTest, SelectEntity) +{ + auto light = createByClassName("light"); + + // Confirm that setting entity node's selection status propagates to the + // selection system + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0); + Node_getSelectable(light)->setSelected(true); + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1); + Node_getSelectable(light)->setSelected(false); + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0); +} + +TEST_F(EntityTest, DestroySelectedEntity) +{ + auto light = createByClassName("light"); + + // Confirm that setting entity node's selection status propagates to the + // selection system + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0); + Node_getSelectable(light)->setSelected(true); + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1); + + // Destructor called here and should not crash +} + TEST_F(EntityTest, RenderLightEntity) { auto light = createByClassName("light"); - auto& spawnArgs = light->getEntity(); // Rendering requires a backend and a volume test auto backend = GlobalRenderSystemFactory().createRenderSystem(); @@ -292,6 +318,7 @@ TEST_F(EntityTest, RenderLightEntity) light->setRenderSystem(backend); light->renderWireframe(wireframeRenderer, volumeTest); EXPECT_EQ(wireframeRenderer.renderables, 1); + EXPECT_EQ(wireframeRenderer.lights, 0); } // With the light selected, we should get the origin diamond, the radius and @@ -302,6 +329,12 @@ TEST_F(EntityTest, RenderLightEntity) light->setRenderSystem(backend); light->renderWireframe(wireframeRenderer, volumeTest); EXPECT_EQ(wireframeRenderer.renderables, 3); + EXPECT_EQ(wireframeRenderer.lights, 0); + + // Destroying a selected entity causes a crash (destructor tries to + // unselect the entity in the RadiantSelectionSystem which requires a + // call to Node::self() which crashes due to trying to create a new + // shared_ptr in the destructor). Node_getSelectable(light)->setSelected(false); } }