Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5972: Unit tests checking that the player start entity is selected a…
…fter placement
  • Loading branch information
codereader committed Jun 16, 2022
1 parent ba96f62 commit 2e82b61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
16 changes: 10 additions & 6 deletions test/Entity.cpp
Expand Up @@ -1928,15 +1928,15 @@ TEST_F(EntityTest, EntityNodeObserveKeyAutoDisconnect)
spawnArgs->setKeyValue(TEST_KEY, "whatever");
}

inline Entity* findPlayerStartEntity()
inline IEntityNodePtr findPlayerStartEntity()
{
Entity* found = nullptr;
IEntityNodePtr found;

algorithm::findFirstEntity(GlobalMapModule().getRoot(), [&](IEntityNode& entityNode)
algorithm::findFirstEntity(GlobalMapModule().getRoot(), [&](const IEntityNodePtr& entity)
{
if (entityNode.getEntity().getEntityClass()->getName() == "info_player_start")
if (entity->getEntity().getEntityClass()->getName() == "info_player_start")
{
found = &entityNode.getEntity();
found = entity;
}

return found == nullptr;
Expand All @@ -1956,7 +1956,9 @@ TEST_F(EntityTest, AddPlayerStart)
auto playerStart = findPlayerStartEntity();
EXPECT_TRUE(playerStart) << "Couldn't find the player start entity after placing it";

EXPECT_EQ(playerStart->getKeyValue("origin"), string::to_string(position)) << "Origin has the wrong value";
EXPECT_EQ(playerStart->getEntity().getKeyValue("origin"), string::to_string(position)) << "Origin has the wrong value";

EXPECT_TRUE(Node_isSelected(playerStart)) << "Player start should be selected after placement";

// Ensure this action is undoable
GlobalUndoSystem().undo();
Expand All @@ -1977,6 +1979,8 @@ TEST_F(EntityTest, MovePlayerStart)
GlobalCommandSystem().executeCommand("PlacePlayerStart", cmd::Argument(position));
EXPECT_EQ(Node_getEntity(playerStart)->getKeyValue("origin"), string::to_string(position)) << "Origin didn't get updated";

EXPECT_TRUE(Node_isSelected(playerStart)) << "Player start should be selected after placement";

// Ensure this action is undoable
GlobalUndoSystem().undo();
EXPECT_EQ(Node_getEntity(playerStart)->getKeyValue("origin"), originalPosition) << "Origin change didn't get undone";
Expand Down
12 changes: 6 additions & 6 deletions test/algorithm/Scene.h
Expand Up @@ -101,15 +101,15 @@ inline scene::INodePtr findFirstPatchWithMaterial(const scene::INodePtr& parent,
}

inline scene::INodePtr findFirstEntity(const scene::INodePtr& parent,
const std::function<bool(IEntityNode&)>& predicate)
const std::function<bool(const IEntityNodePtr&)>& predicate)
{
IEntityNodePtr candidate;

parent->foreachNode([&](const scene::INodePtr& node)
{
auto entity = std::dynamic_pointer_cast<IEntityNode>(node);

if (entity && predicate(*entity))
if (entity && predicate(entity))
{
candidate = entity;
return false;
Expand All @@ -123,17 +123,17 @@ inline scene::INodePtr findFirstEntity(const scene::INodePtr& parent,

inline scene::INodePtr findWorldspawn(const scene::INodePtr& root)
{
return findFirstEntity(root, [&](IEntityNode& entity)
return findFirstEntity(root, [&](const IEntityNodePtr& entity)
{
return entity.getEntity().isWorldspawn();
return entity->getEntity().isWorldspawn();
});
}

inline scene::INodePtr getEntityByName(const scene::INodePtr& parent, const std::string& name)
{
return findFirstEntity(parent, [&](IEntityNode& entity)
return findFirstEntity(parent, [&](const IEntityNodePtr& entity)
{
return entity.getEntity().getKeyValue("name") == name;
return entity->getEntity().getKeyValue("name") == name;
});
}

Expand Down

0 comments on commit 2e82b61

Please sign in to comment.