diff --git a/test/CSG.cpp b/test/CSG.cpp index 42f9e484a4..a45548d4b8 100644 --- a/test/CSG.cpp +++ b/test/CSG.cpp @@ -1,9 +1,42 @@ #include "RadiantTest.h" +#include "imap.h" +#include "ibrush.h" +#include "entitylib.h" +#include "algorithm/Scene.h" + // Issue #5336: Crash when using CSG Merge on brushes that are entities TEST_F(RadiantTest, CSGMergeWithFuncStatic) { loadMap("csg_merge_with_func_static.map"); + // Locate the first worldspawn brush + scene::INodePtr firstBrush = test::algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0); + ASSERT_TRUE(firstBrush); + + // Locate the func_static in the map + EntityNodeFindByClassnameWalker walker("func_static"); + GlobalSceneGraph().root()->traverse(walker); + + auto entityNode = walker.getEntityNode(); + ASSERT_TRUE(entityNode); + ASSERT_TRUE(entityNode->hasChildNodes()); + + // Select both of them, the order is important + Node_setSelected(firstBrush, true); + Node_setSelected(entityNode, true); + + // CSG merge + GlobalCommandSystem().executeCommand("CSGMerge"); + + // No merge should have happened since the brushes + // are not part of the same entity + // So assume the scene didn't change + ASSERT_TRUE(test::algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0) == firstBrush); + + EntityNodeFindByClassnameWalker walker2("func_static"); + GlobalSceneGraph().root()->traverse(walker2); + ASSERT_TRUE(walker.getEntityNode()); + ASSERT_TRUE(walker.getEntityNode()->hasChildNodes()); } diff --git a/test/algorithm/Scene.h b/test/algorithm/Scene.h new file mode 100644 index 0000000000..ab128f0f79 --- /dev/null +++ b/test/algorithm/Scene.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include "inode.h" +#include "ientity.h" + +namespace test::algorithm +{ + +// Returns the n-th child of the given parent node +inline scene::INodePtr getNthChild(const scene::INodePtr& parent, std::size_t index) +{ + std::size_t n = 0; + scene::INodePtr candidate; + + parent->foreachNode([&](const scene::INodePtr& node) + { + if (n == index) + { + candidate = node; + return false; + } + + ++n; + return true; + }); + + return candidate; +} + +} diff --git a/tools/msvc/Tests/Tests.vcxproj b/tools/msvc/Tests/Tests.vcxproj index 952930c1ed..3c2529ea92 100644 --- a/tools/msvc/Tests/Tests.vcxproj +++ b/tools/msvc/Tests/Tests.vcxproj @@ -55,6 +55,7 @@ + diff --git a/tools/msvc/Tests/Tests.vcxproj.filters b/tools/msvc/Tests/Tests.vcxproj.filters new file mode 100644 index 0000000000..f8700109bc --- /dev/null +++ b/tools/msvc/Tests/Tests.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + + + + + + + + + algorithm + + + + + + + + {519b0a02-8afc-4b67-9fa3-aeed09412562} + + + \ No newline at end of file