Skip to content

Commit

Permalink
#5622: Brush fingerprint unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 23, 2021
1 parent ffe86cf commit be56c0e
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@ add_executable(drtest
ImageLoading.cpp
LayerManipulation.cpp
MapExport.cpp
MapMerging.cpp
MapSavingLoading.cpp
MaterialExport.cpp
Materials.cpp
Expand Down
71 changes: 71 additions & 0 deletions test/MapMerging.cpp
@@ -0,0 +1,71 @@
#include "RadiantTest.h"

#include "icommandsystem.h"
#include "itransformable.h"
#include "ibrush.h"
#include "icomparablenode.h"
#include "algorithm/Scene.h"
#include "registry/registry.h"

namespace test
{

using MapMergeTest = RadiantTest;

TEST_F(MapMergeTest, BrushFingerprint)
{
GlobalCommandSystem().executeCommand("OpenMap", cmd::Argument("maps/fingerprinting.mapx"));

auto originalMaterial = "textures/numbers/1";
auto brush = std::dynamic_pointer_cast<IBrushNode>(algorithm::findFirstBrushWithMaterial(
GlobalMapModule().findOrInsertWorldspawn(), originalMaterial));

auto comparable = std::dynamic_pointer_cast<scene::IComparableNode>(brush);
EXPECT_TRUE(comparable) << "BrushNode is not implementing IComparableNode";

auto originalFingerprint = comparable->getFingerprint();

EXPECT_NE(originalFingerprint, 0); // shouldn't be empty

// Calling it twice shouldn't change the value
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);

// Change the material of this brush, the fingerprint should change now
brush->getIBrush().setShader("textures/somethingelse");
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);

// Change it back
brush->getIBrush().setShader(originalMaterial);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);

// Change the contents flags, fingerprint should change
brush->getIBrush().setDetailFlag(IBrush::Detail);
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);

// Change it back
brush->getIBrush().setDetailFlag(IBrush::Structural);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);

// Get the first face and tinker with it
auto& face = brush->getIBrush().getFace(0);

auto lastFingerprint = comparable->getFingerprint();

// Changing the texture should modify the fingerprint
face.flipTexture(0);
EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
lastFingerprint = comparable->getFingerprint();

// Disable texture lock
registry::setValue(RKEY_ENABLE_TEXTURE_LOCK, false);

// Changing the planes
auto transformable = std::dynamic_pointer_cast<ITransformable>(brush);
transformable->setTranslation(Vector3(10,0,0));
transformable->freezeTransform();

EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
lastFingerprint = comparable->getFingerprint();
}

}
316 changes: 316 additions & 0 deletions test/resources/tdm/maps/fingerprinting.mapx
@@ -0,0 +1,316 @@
<?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="257"/>
<property key="LastCameraAngle" value="-36.9 45.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>
<patch number="4" width="3" height="3" fixedSubdivisions="false">
<material name="textures/numbers/1"/>
<controlVertices>
<controlVertex row="0" column="0" x="-64.000043" y="63.999957" z="0" u="0" v="0"/>
<controlVertex row="1" column="0" x="-64.000043" y="95.999978" z="0" u="0" v="-1.000001"/>
<controlVertex row="2" column="0" x="-64.000043" y="128.000000" z="0" u="0" v="-2.000001"/>
<controlVertex row="0" column="1" x="-32.000022" y="63.999957" z="0" u="1.000001" v="0"/>
<controlVertex row="1" column="1" x="-32.000022" y="95.999978" z="0" u="1.000001" v="-1.000001"/>
<controlVertex row="2" column="1" x="-32.000022" y="128.000000" z="0" u="1.000001" v="-2.000001"/>
<controlVertex row="0" column="2" x="0" y="63.999957" z="0" u="2.000001" v="0"/>
<controlVertex row="1" column="2" x="0" y="95.999978" z="0" u="2.000001" v="-1.000001"/>
<controlVertex row="2" column="2" x="0" y="128.000000" z="0" u="2.000001" v="-2.000001"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="5" width="3" height="3" fixedSubdivisions="false">
<material name="textures/numbers/2"/>
<controlVertices>
<controlVertex row="0" column="0" x="-0.000043" y="63.999957" z="0" u="1.999999" v="-0.000001"/>
<controlVertex row="1" column="0" x="-0.000043" y="95.999978" z="0" u="2.999999" v="-0.000001"/>
<controlVertex row="2" column="0" x="-0.000043" y="128.000000" z="0" u="4.000000" v="-0.000001"/>
<controlVertex row="0" column="1" x="31.999978" y="63.999957" z="0" u="1.999999" v="0.999999"/>
<controlVertex row="1" column="1" x="31.999978" y="95.999978" z="0" u="2.999999" v="0.999999"/>
<controlVertex row="2" column="1" x="31.999978" y="128.000000" z="0" u="4.000000" v="0.999999"/>
<controlVertex row="0" column="2" x="64.000000" y="63.999957" z="0" u="1.999999" v="2.000000"/>
<controlVertex row="1" column="2" x="64.000000" y="95.999978" z="0" u="2.999999" v="2.000000"/>
<controlVertex row="2" column="2" x="64.000000" y="128.000000" z="0" u="4.000000" v="2.000000"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
</primitives>
<keyValues>
<keyValue key="classname" value="worldspawn"/>
<keyValue key="description" value="Items 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>

0 comments on commit be56c0e

Please sign in to comment.