Skip to content

Commit

Permalink
#6107: Add an example layer hierarchy in mapx and map formats to test…
Browse files Browse the repository at this point in the history
… the restore code
  • Loading branch information
codereader committed Oct 1, 2022
1 parent 1fd7312 commit 08e5830
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/LayerManipulation.cpp
Expand Up @@ -570,6 +570,54 @@ TEST_F(LayerTest, LayerHierarchyIsPersistedToMap)
runLayerHierarchyPersistenceTest(tempPath.string());
}

TEST_F(LayerTest, LayerHierarchyIsRestoredFromMapx)
{
// The .mapx file contains a hierarchy that should be restored
// without running into crashes (layer 3 is a child of layer 9)
auto mapFilePath = _context.getTestProjectPath() + "maps/layer_hierarchy_restore.mapx";

GlobalCommandSystem().executeCommand("OpenMap", mapFilePath);

auto unsortedLayerIds = getAllLayerIds();
auto layerIds = std::set(unsortedLayerIds.begin(), unsortedLayerIds.end());

for (int i = 0; i <= 9; ++i)
{
EXPECT_EQ(layerIds.count(0), 1) << "Layer with ID " << i << " not present";
}

auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();
EXPECT_EQ(layerManager.getParentLayer(0), -1) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(3), 9) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(4), 2) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(5), 3) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(9), 2) << "Hierarchy has not been restored";
}

TEST_F(LayerTest, LayerHierarchyIsRestoredFromMap)
{
// The .darkradiant file contains a hierarchy that should be restored
// without running into crashes (layer 3 is a child of layer 9)
auto mapFilePath = _context.getTestProjectPath() + "maps/layer_hierarchy_restore.map";

GlobalCommandSystem().executeCommand("OpenMap", mapFilePath);

auto unsortedLayerIds = getAllLayerIds();
auto layerIds = std::set(unsortedLayerIds.begin(), unsortedLayerIds.end());

for (int i = 0; i <= 9; ++i)
{
EXPECT_EQ(layerIds.count(0), 1) << "Layer with ID " << i << " not present";
}

auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();
EXPECT_EQ(layerManager.getParentLayer(0), -1) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(3), 9) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(4), 2) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(5), 3) << "Hierarchy has not been restored";
EXPECT_EQ(layerManager.getParentLayer(9), 2) << "Hierarchy has not been restored";
}

TEST_F(LayerTest, CreateLayerMarksMapAsModified)
{
loadMap("general_purpose.mapx");
Expand Down
53 changes: 53 additions & 0 deletions test/resources/tdm/maps/layer_hierarchy_restore.darkradiant
@@ -0,0 +1,53 @@
DarkRadiant Map Information File Version 2
{
MapProperties
{
KeyValue { "EditTimeInSeconds" "34" }
KeyValue { "LastCameraAngle" "0 0 0" }
KeyValue { "LastCameraPosition" "0 0 30" }
}
MapEditTimings
{
TotalSecondsEdited { 34 }
}
Layers
{
Layer 0 { Default }
Layer 1 { box }
Layer 2 { BoardsandStuff }
Layer 3 { Tst }
Layer 4 { Test2 }
Layer 5 { Test3 }
Layer 6 { Test4 }
Layer 7 { Test6 }
Layer 8 { Test7 }
Layer 9 { Test8 }
}
LayerHierarchy
{
Layer 0 Parent { -1 }
Layer 1 Parent { -1 }
Layer 2 Parent { -1 }
Layer 3 Parent { 9 }
Layer 4 Parent { 2 }
Layer 5 Parent { 3 }
Layer 6 Parent { 3 }
Layer 7 Parent { 3 }
Layer 8 Parent { 4 }
Layer 9 Parent { 2 }
}
NodeToLayerMapping
{
Node { 0 } // entity (world)
Node { 0 } // brush (Brush)
}
SelectionSets
{
}
SelectionGroups
{
}
SelectionGroupNodeMapping
{
}
}
17 changes: 17 additions & 0 deletions test/resources/tdm/maps/layer_hierarchy_restore.map
@@ -0,0 +1,17 @@
Version 2
// entity 0
{
"classname" "worldspawn"
// primitive 0
{
brushDef3
{
( 0 0 1 -64 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 1 0 -84 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 -177 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 0 -1 -64 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 -1 0 24 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( -1 0 0 96 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
}
}
}
79 changes: 79 additions & 0 deletions test/resources/tdm/maps/layer_hierarchy_restore.mapx
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<map version="1" format="portable">
<layers>
<layer id="0" name="Default" parentId="-1"/>
<layer id="1" name="box" parentId="-1"/>
<layer id="2" name="BoardsandStuff" parentId="-1"/>
<layer id="3" name="Tst" parentId="9"/>
<layer id="4" name="Test2" parentId="2"/>
<layer id="5" name="Test3" parentId="3"/>
<layer id="6" name="Test4" parentId="3"/>
<layer id="7" name="Test6" parentId="3"/>
<layer id="8" name="Test7" parentId="4"/>
<layer id="9" name="Test8" parentId="2"/>
</layers>
<selectionGroups/>
<selectionSets/>
<properties>
<property key="EditTimeInSeconds" value="752"/>
<property key="LastCameraAngle" value="0 0 0"/>
<property key="LastCameraPosition" value="0 0 30"/>
</properties>
<entity number="0">
<primitives>
<brush number="0">
<faces>
<face>
<plane x="0" y="0" z="1.000000" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name=""/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="1.000000" z="0" d="-84.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name=""/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="1.000000" y="0" z="0" d="-177.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name=""/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="0" z="-1.000000" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name=""/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="-1.000000" z="0" d="24.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name=""/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-1.000000" y="0" z="0" d="96.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name=""/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
</primitives>
<keyValues>
<keyValue key="classname" value="worldspawn"/>
</keyValues>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</entity>
</map>

0 comments on commit 08e5830

Please sign in to comment.