Skip to content

Commit

Permalink
#5451: Add (failing) unit tests asserting that create, rename and del…
Browse files Browse the repository at this point in the history
…ete layer operations mark the map as modified
  • Loading branch information
codereader committed Dec 24, 2020
1 parent 6b7f8b5 commit 36180a4
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Expand Up @@ -7,6 +7,7 @@ add_executable(drtest
FileTypes.cpp
HeadlessOpenGLContext.cpp
ImageLoading.cpp
LayerManipulation.cpp
MapExport.cpp
MapSavingLoading.cpp
Materials.cpp
Expand Down
51 changes: 51 additions & 0 deletions test/LayerManipulation.cpp
@@ -0,0 +1,51 @@
#include "RadiantTest.h"

#include "imap.h"
#include "ilayer.h"
#include "algorithm/Scene.h"

namespace test
{

using LayerTest = RadiantTest;

TEST_F(LayerTest, CreateLayerMarksMapAsModified)
{
loadMap("general_purpose.mapx");

EXPECT_FALSE(GlobalMapModule().isModified());

GlobalMapModule().getRoot()->getLayerManager().createLayer("Testlayer");

EXPECT_TRUE(GlobalMapModule().isModified());
}

TEST_F(LayerTest, RenameLayerMarksMapAsModified)
{
loadMap("general_purpose.mapx");

auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();

EXPECT_FALSE(GlobalMapModule().isModified());
EXPECT_NE(layerManager.getLayerID("Second Layer"), -1);

layerManager.renameLayer(layerManager.getLayerID("Second Layer"), "Renamed Layer");

EXPECT_TRUE(GlobalMapModule().isModified());
}

TEST_F(LayerTest, DeleteLayerMarksMapAsModified)
{
loadMap("general_purpose.mapx");

auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();

EXPECT_FALSE(GlobalMapModule().isModified());
EXPECT_NE(layerManager.getLayerID("Second Layer"), -1);

layerManager.deleteLayer("Second Layer");

EXPECT_TRUE(GlobalMapModule().isModified());
}

}
278 changes: 278 additions & 0 deletions test/resources/tdm/maps/general_purpose.mapx
@@ -0,0 +1,278 @@
<?xml version="1.0" encoding="utf-8"?>
<map version="1" format="portable">
<layers>
<layer id="0" name="Default"/>
<layer id="1" name="Second Layer"/>
<layer id="2" name="Third Layer"/>
</layers>
<selectionGroups/>
<selectionSets/>
<properties>
<property key="EditTimeInSeconds" value="126"/>
<property key="LastCameraAngle" value="-46.8 33.6 0"/>
<property key="LastCameraPosition" value="-81.4144 -139.899 261.902"/>
<property key="LastShaderClipboardMaterial" value="textures/numbers/2"/>
</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="textures/numbers/1"/>
<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="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="-1.000000" z="0" d="0"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-1.000000" y="0" z="0" d="64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0.707107" y="0.707107" z="0" d="-90.509666"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
<brush number="1">
<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="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="1.000000" z="0" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="1.000000" y="0" z="0" d="-128.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<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="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-0.707107" y="-0.707107" z="0" d="90.509666"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
<brush number="2">
<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="62.000000"/>
<material name="textures/numbers/4"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="1.000000" z="0" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/4"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="1.000000" y="0" z="0" d="-192.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/4"/>
<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="2.000000"/>
<material name="textures/numbers/4"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-0.707107" y="-0.707107" z="0" d="135.764511"/>
<textureProjection xx="0.031250" yx="0" tx="126.585785" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/4"/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="1"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
<brush number="3">
<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="62.000000"/>
<material name="textures/numbers/3"/>
<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="2.000000"/>
<material name="textures/numbers/3"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="-1.000000" z="0" d="0"/>
<textureProjection xx="0.031250" yx="0" tx="62.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/3"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-1.000000" y="0" z="0" d="128.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/3"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0.707107" y="0.707107" z="0" d="-135.764511"/>
<textureProjection xx="0.031250" yx="0" tx="1.414214" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/3"/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
</primitives>
<keyValues>
<keyValue key="classname" value="worldspawn"/>
<keyValue key="description" value="Brushes in this map have numbers as their material names, such that the unit test algorithm can find them"/>
</keyValues>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</entity>
<entity number="1">
<primitives>
<brush number="0">
<faces>
<face>
<plane x="0" y="0" z="1.000000" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="0" z="-1.000000" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="-1.000000" z="0" d="-32.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-1.000000" y="0" z="0" d="-32.000000"/>
<textureProjection xx="0.031250" yx="0" tx="62.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0.707107" y="0.707107" z="0" d="0"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/1"/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
<brush number="1">
<faces>
<face>
<plane x="0" y="0" z="1.000000" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="1.000000" z="0" d="-32.000000"/>
<textureProjection xx="0.031250" yx="0" tx="0" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="1.000000" y="0" z="0" d="-32.000000"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="0" y="0" z="-1.000000" d="-64.000000"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
<face>
<plane x="-0.707107" y="-0.707107" z="0" d="0"/>
<textureProjection xx="0.031250" yx="0" tx="2.000000" xy="0" yy="0.031250" ty="0"/>
<material name="textures/numbers/2"/>
<contentsFlag value="0"/>
</face>
</faces>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</brush>
</primitives>
<keyValues>
<keyValue key="classname" value="func_static"/>
<keyValue key="name" value="func_static_1"/>
<keyValue key="model" value="func_static_1"/>
<keyValue key="origin" value="96 -32 0"/>
</keyValues>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</entity>
</map>
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -76,6 +76,7 @@
<ClCompile Include="..\..\..\test\FileTypes.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
<ClCompile Include="..\..\..\test\ImageLoading.cpp" />
<ClCompile Include="..\..\..\test\LayerManipulation.cpp" />
<ClCompile Include="..\..\..\test\MapExport.cpp" />
<ClCompile Include="..\..\..\test\MapSavingLoading.cpp" />
<ClCompile Include="..\..\..\test\Materials.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -34,6 +34,7 @@
<ClCompile Include="..\..\..\test\PatchWelding.cpp" />
<ClCompile Include="..\..\..\test\PatchIterators.cpp" />
<ClCompile Include="..\..\..\test\ImageLoading.cpp" />
<ClCompile Include="..\..\..\test\LayerManipulation.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit 36180a4

Please sign in to comment.