diff --git a/test/SelectionAlgorithm.cpp b/test/SelectionAlgorithm.cpp new file mode 100644 index 0000000000..3061753c13 --- /dev/null +++ b/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); +} + +} diff --git a/test/resources/tdm/def/entity_with_model.def b/test/resources/tdm/def/entity_with_model.def new file mode 100644 index 0000000000..bc618cca2c --- /dev/null +++ b/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" +} diff --git a/test/resources/tdm/maps/select_items_by_model.map b/test/resources/tdm/maps/select_items_by_model.map new file mode 100644 index 0000000000..2a6fec4b2a --- /dev/null +++ b/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" +} diff --git a/tools/msvc/Tests/Tests.vcxproj b/tools/msvc/Tests/Tests.vcxproj index fe1466dfca..2899ba3db6 100644 --- a/tools/msvc/Tests/Tests.vcxproj +++ b/tools/msvc/Tests/Tests.vcxproj @@ -64,6 +64,7 @@ + diff --git a/tools/msvc/Tests/Tests.vcxproj.filters b/tools/msvc/Tests/Tests.vcxproj.filters index b8576799d7..2c64f0b325 100644 --- a/tools/msvc/Tests/Tests.vcxproj.filters +++ b/tools/msvc/Tests/Tests.vcxproj.filters @@ -4,6 +4,7 @@ +