Skip to content

Commit

Permalink
#5235: Add unit tests covering "SelectItemsByModel" & "DeselectItemsB…
Browse files Browse the repository at this point in the history
…yModel"
  • Loading branch information
codereader committed Oct 9, 2020
1 parent be81e5e commit 6014e4d
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/SelectionAlgorithm.cpp
@@ -0,0 +1,36 @@
#include "RadiantTest.h"

#include "iselection.h"
#include "icommandsystem.h"
#include "selectionlib.h"

namespace test
{

TEST_F(RadiantTest, SelectItemsByModel)
{
loadMap("select_items_by_model.map");

auto staticMeshPath = "models/just_a_static_mesh.ase";
auto md5MeshPath = "just_an_md5.md5mesh";

GlobalSelectionSystem().setSelectedAll(false);
ASSERT_TRUE(GlobalSelectionSystem().getSelectionInfo().totalCount == 0);

// Select the two entities with the regular "model" "" spawnarg
GlobalCommandSystem().executeCommand("SelectItemsByModel", { staticMeshPath });
ASSERT_TRUE(GlobalSelectionSystem().getSelectionInfo().entityCount == 2);

// Deselect the two entities with the regular "model" "" spawnarg
GlobalCommandSystem().executeCommand("DeselectItemsByModel", { staticMeshPath });
ASSERT_TRUE(GlobalSelectionSystem().getSelectionInfo().totalCount == 0);

// Select the three entities that reference the md5 mesh through a model def
GlobalCommandSystem().executeCommand("SelectItemsByModel", { md5MeshPath });
ASSERT_TRUE(GlobalSelectionSystem().getSelectionInfo().entityCount == 3);

GlobalCommandSystem().executeCommand("DeselectItemsByModel", { md5MeshPath });
ASSERT_TRUE(GlobalSelectionSystem().getSelectionInfo().totalCount == 0);
}

}
10 changes: 10 additions & 0 deletions test/resources/tdm/def/entity_with_model.def
@@ -0,0 +1,10 @@
model just_a_model
{
mesh just_an_md5.md5mesh
}

entityDef dr:entity_using_modeldef
{
"model" "just_a_model"
"random" "1"
}
122 changes: 122 additions & 0 deletions test/resources/tdm/maps/select_items_by_model.map
@@ -0,0 +1,122 @@
Version 2
// entity 0
{
"classname" "worldspawn"
// primitive 0
{
brushDef3
{
( 0 0 1 -208 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 1 0 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 -384 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 -1 0 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( -1 0 0 -64 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 0 -1 192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
}
}
// primitive 1
{
brushDef3
{
( 0 0 1 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 1 0 -208 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 -384 ) ( ( 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
( -1 0 0 -64 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 -1 0 192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
}
}
// primitive 2
{
brushDef3
{
( 0 0 1 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 1 0 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 -400 ) ( ( 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 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( -1 0 0 384 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
}
}
// primitive 3
{
brushDef3
{
( 0 1 0 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 -384 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 0 -1 -80 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 -1 0 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( -1 0 0 -64 ) ( ( 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
}
}
// primitive 4
{
brushDef3
{
( 0 0 1 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 -384 ) ( ( 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 -208 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( -1 0 0 -64 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 1 0 192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
}
}
// primitive 5
{
brushDef3
{
( 0 0 1 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 0 1 0 -192 ) ( ( 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 -192 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( -1 0 0 -80 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
( 1 0 0 64 ) ( ( 0.03125 0 0 ) ( 0 0.03125 0 ) ) "_default" 0 0 0
}
}
}
// entity 1
{
"classname" "dr:entity_using_modeldef"
"name" "dr_entity_using_modeldef_1"
"origin" "96 0 -63.0868"
"rotation" "1 0 0 0 1 0 0 0 1"
}
// entity 2
{
"classname" "dr:entity_using_modeldef"
"name" "dr_entity_using_modeldef_2"
"origin" "208 -80 -63.0868"
"rotation" "1 0 0 0 1 0 0 0 1"
}
// entity 3
{
"classname" "dr:entity_using_modeldef"
"name" "dr_entity_using_modeldef_3"
"origin" "272 48 -63.0868"
"rotation" "1 0 0 0 1 0 0 0 1"
}
// entity 4
{
"classname" "light"
"name" "light_1"
"origin" "32 112 -48"
"light_center" "0 0 0"
"light_radius" "160 176 320"
}
// entity 5
{
"classname" "func_static"
"name" "func_static_1"
"origin" "96 -64 -48"
"rotation" "1 0 0 0 1 0 0 0 1"
"model" "models/just_a_static_mesh.ase"
}
// entity 6
{
"classname" "func_static"
"name" "func_static_2"
"origin" "96 -112 -48"
"rotation" "1 0 0 0 1 0 0 0 1"
"model" "models/just_a_static_mesh.ase"
}
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -64,6 +64,7 @@
<ClCompile Include="..\..\..\test\Camera.cpp" />
<ClCompile Include="..\..\..\test\CSG.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
</ItemGroup>
<ItemDefinitionGroup />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -4,6 +4,7 @@
<ClCompile Include="..\..\..\test\CSG.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
<ClCompile Include="..\..\..\test\Camera.cpp" />
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit 6014e4d

Please sign in to comment.