mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[commands] Add ConditionalCommand getInterruptionBehavior (#5161)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "CommandTestBase.h"
|
||||
#include "frc2/command/Commands.h"
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
#include "frc2/command/InstantCommand.h"
|
||||
#include "frc2/command/SelectCommand.h"
|
||||
@@ -51,3 +52,87 @@ TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) {
|
||||
EXPECT_TRUE(scheduler.IsScheduled(&command3));
|
||||
EXPECT_FALSE(scheduler.IsScheduled(&conditional));
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, AllTrue) {
|
||||
CommandPtr command =
|
||||
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
|
||||
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
|
||||
[] { return true; });
|
||||
EXPECT_EQ(true, command.get()->RunsWhenDisabled());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, AllFalse) {
|
||||
CommandPtr command =
|
||||
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
|
||||
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
|
||||
[] { return true; });
|
||||
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, OneTrueOneFalse) {
|
||||
CommandPtr command =
|
||||
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
|
||||
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
|
||||
[] { return true; });
|
||||
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, TwoFalseOneTrue) {
|
||||
CommandPtr command =
|
||||
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
|
||||
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
|
||||
[] { return true; });
|
||||
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, AllCancelSelf) {
|
||||
CommandPtr command = cmd::Either(
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
|
||||
[] { return true; });
|
||||
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
|
||||
command.get()->GetInterruptionBehavior());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, AllCancelIncoming) {
|
||||
CommandPtr command = cmd::Either(
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
|
||||
[] { return false; });
|
||||
EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming,
|
||||
command.get()->GetInterruptionBehavior());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) {
|
||||
CommandPtr command = cmd::Either(
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
|
||||
[] { return false; });
|
||||
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
|
||||
command.get()->GetInterruptionBehavior());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalCommandTest, OneCancelIncomingOneSelf) {
|
||||
CommandPtr command = cmd::Either(
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
|
||||
cmd::WaitUntil([] {
|
||||
return false;
|
||||
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
|
||||
[] { return false; });
|
||||
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
|
||||
command.get()->GetInterruptionBehavior());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user