Skip to content

Commit

Permalink
#5788: Add unit test checking the to-be-introduced command "PlacePlay…
Browse files Browse the repository at this point in the history
…erStart"
  • Loading branch information
codereader committed Oct 29, 2021
1 parent 7f50a99 commit 09721b8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/Entity.cpp
Expand Up @@ -18,6 +18,7 @@
#include "string/join.h"
#include "scenelib.h"
#include "algorithm/Entity.h"
#include "algorithm/Scene.h"

namespace test
{
Expand Down Expand Up @@ -1561,4 +1562,56 @@ TEST_F(EntityTest, KeyObserverKeyRemoval)
keyValue->detach(observer);
}

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

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

return found == nullptr;
});

return found;
}

TEST_F(EntityTest, AddPlayerStart)
{
// Empty map, check prerequisites
EXPECT_EQ(findPlayerStartEntity(), nullptr) << "Empty map shouldn't have a player start";

Vector3 position(50, 30, 40);
GlobalCommandSystem().executeCommand("PlacePlayerStart", cmd::Argument(position));

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";

// Ensure this action is undoable
GlobalUndoSystem().undo();
EXPECT_EQ(findPlayerStartEntity(), nullptr) << "Couldn't undo the place player start action";
}

TEST_F(EntityTest, MovePlayerStart)
{
// Empty map, check prerequisites
auto originalPosition = "50 30 47";
auto playerStart = GlobalEntityModule().createEntity(GlobalEntityClassManager().findOrInsert("info_player_start", false));
scene::addNodeToContainer(playerStart, GlobalMapModule().getRoot());
Node_getEntity(playerStart)->setKeyValue("origin", originalPosition);

Vector3 position(7, 2, -4);
GlobalCommandSystem().executeCommand("PlacePlayerStart", cmd::Argument(position));
EXPECT_EQ(Node_getEntity(playerStart)->getKeyValue("origin"), string::to_string(position)) << "Origin didn't get updated";

// Ensure this action is undoable
GlobalUndoSystem().undo();
EXPECT_EQ(Node_getEntity(playerStart)->getKeyValue("origin"), originalPosition) << "Origin change didn't get undone";
}

}
12 changes: 12 additions & 0 deletions test/resources/tdm/def/player.def
@@ -0,0 +1,12 @@
entityDef info_player_start
{
"spawnclass" "idPlayerStart"

"editor_color" "1 0 0"
"editor_mins" "-16 -16 0"
"editor_maxs" "16 16 64"
"editor_showangle" "1"

"editor_usage" "The spawning position for the player."
"editor_var skin" "Skin to use for player model."
}

0 comments on commit 09721b8

Please sign in to comment.