Skip to content

Commit c32eb97

Browse files
authored
Merge pull request #63 from klaussilveira/unit-tests
Added missing unit tests for cloning behavior
2 parents 801eef4 + b15327b commit c32eb97

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

test/Transformation.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "RadiantTest.h"
22

33
#include "ieclass.h"
4+
#include "ilayer.h"
5+
#include "iselection.h"
46
#include "scene/EntityNode.h"
57
#include "itransformable.h"
68
#include "icommandsystem.h"
@@ -9,6 +11,8 @@
911
#include "selection/SelectedPlaneSet.h"
1012
#include "render/View.h"
1113
#include "algorithm/View.h"
14+
#include "algorithm/Entity.h"
15+
#include "algorithm/Primitives.h"
1216

1317
namespace test
1418
{
@@ -151,4 +155,94 @@ TEST_F(TransformationTest, UniformLightDragResize)
151155
EXPECT_EQ(entityNode->worldAABB().getExtents(), Vector3(320, 320, 320));
152156
}
153157

158+
TEST_F(TransformationTest, CloneSelectedPlacesNodeInActiveLayer)
159+
{
160+
auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();
161+
162+
// Create a non-default layer and make it active
163+
auto testLayerId = layerManager.createLayer("TestLayer");
164+
layerManager.setActiveLayer(testLayerId);
165+
166+
// Create an entity on the default layer and select it
167+
auto entityNode = algorithm::createEntityByClassName("fixed_size_entity");
168+
GlobalMapModule().getRoot()->addChildNode(entityNode);
169+
entityNode->moveToLayer(0);
170+
Node_setSelected(entityNode, true);
171+
172+
EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 });
173+
174+
// Clone the selection
175+
GlobalCommandSystem().executeCommand("CloneSelection");
176+
177+
// The original should still be on layer 0
178+
EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 });
179+
180+
// The clone should be on the active layer
181+
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1);
182+
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
183+
{
184+
EXPECT_EQ(node->getLayers(), scene::LayerList{ testLayerId })
185+
<< "Cloned node should be placed in the active layer";
186+
});
187+
}
188+
189+
TEST_F(TransformationTest, CloneSelectedDefaultLayerStaysOnDefault)
190+
{
191+
auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();
192+
193+
// Active layer is already the default
194+
EXPECT_EQ(layerManager.getActiveLayer(), 0);
195+
196+
auto entityNode = algorithm::createEntityByClassName("fixed_size_entity");
197+
GlobalMapModule().getRoot()->addChildNode(entityNode);
198+
Node_setSelected(entityNode, true);
199+
200+
EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 });
201+
202+
GlobalCommandSystem().executeCommand("CloneSelection");
203+
204+
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1);
205+
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
206+
{
207+
EXPECT_EQ(node->getLayers(), scene::LayerList{ 0 })
208+
<< "Cloned node should be on the default layer when it is active";
209+
});
210+
}
211+
212+
TEST_F(TransformationTest, CloneSelectedMovesChildrenToActiveLayer)
213+
{
214+
auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();
215+
216+
auto testLayerId = layerManager.createLayer("TestLayer");
217+
layerManager.setActiveLayer(testLayerId);
218+
219+
// Create a func_static entity with a child brush on the default layer
220+
auto entityNode = algorithm::createEntityByClassName("func_static");
221+
GlobalMapModule().getRoot()->addChildNode(entityNode);
222+
auto brushNode = algorithm::createCubicBrush(entityNode);
223+
entityNode->moveToLayer(0);
224+
brushNode->moveToLayer(0);
225+
Node_setSelected(entityNode, true);
226+
227+
EXPECT_EQ(entityNode->getLayers(), scene::LayerList{ 0 });
228+
EXPECT_EQ(brushNode->getLayers(), scene::LayerList{ 0 });
229+
230+
GlobalCommandSystem().executeCommand("CloneSelection");
231+
232+
// The cloned entity and its child brush should both be on the active layer
233+
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1);
234+
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
235+
{
236+
EXPECT_EQ(node->getLayers(), scene::LayerList{ testLayerId })
237+
<< "Cloned entity should be on the active layer";
238+
239+
node->foreachNode([&](const scene::INodePtr& child)
240+
{
241+
EXPECT_EQ(child->getLayers(), scene::LayerList{ testLayerId })
242+
<< "Cloned child brush should be on the active layer";
243+
return true;
244+
});
245+
});
246+
}
247+
154248
}

0 commit comments

Comments
 (0)