Skip to content

Commit

Permalink
#401: test calling a Command with an int argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Jul 5, 2022
1 parent b7d87a4 commit e54c61d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/CommandSystem.cpp
Expand Up @@ -28,6 +28,34 @@ TEST_F(CommandSystemTest, AddAndRunCommand)
EXPECT_EQ(runCount, 2);
}

TEST_F(CommandSystemTest, AddAndRunCommandWithArgs)
{
const char* COMMAND_NAME = "testCmdWithArgs";
ASSERT_FALSE(GlobalCommandSystem().commandExists(COMMAND_NAME));

// Create a test command object which stores its args
struct TestCmd {
int runCount = 0;
cmd::ArgumentList args;

void exec(const cmd::ArgumentList& a)
{
++runCount;
args = a;
}
};
TestCmd cmd;
GlobalCommandSystem().addCommand(COMMAND_NAME,
[&cmd](const cmd::ArgumentList& args) { cmd.exec(args); },
{cmd::ARGTYPE_INT});

// Call the command and check the args
GlobalCommandSystem().executeCommand(COMMAND_NAME, 27);
EXPECT_EQ(cmd.runCount, 1);
ASSERT_EQ(cmd.args.size(), 1);
EXPECT_EQ(cmd.args.at(0).getInt(), 27);
}

TEST_F(CommandSystemTest, RunCommandSequence)
{
const char* FIRST_COMMAND = "firstRunCountCommand";
Expand Down

0 comments on commit e54c61d

Please sign in to comment.