2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <utility>
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
#include "CommandTestBase.h"
|
2024-12-29 10:45:17 -06:00
|
|
|
#include "frc2/command/Commands.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
#include "frc2/command/RunCommand.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
class DefaultCommandTest : public CommandTestBase {};
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST_F(DefaultCommandTest, DefaultCommandSchedule) {
|
2019-08-25 23:55:59 -04:00
|
|
|
CommandScheduler scheduler = GetScheduler();
|
|
|
|
|
|
|
|
|
|
TestSubsystem subsystem;
|
|
|
|
|
|
2024-12-29 10:45:17 -06:00
|
|
|
auto command = cmd::Idle({&subsystem});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2024-12-29 10:45:17 -06:00
|
|
|
scheduler.SetDefaultCommand(&subsystem, std::move(command));
|
2019-08-25 23:55:59 -04:00
|
|
|
auto handle = scheduler.GetDefaultCommand(&subsystem);
|
|
|
|
|
scheduler.Run();
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(scheduler.IsScheduled(handle));
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST_F(DefaultCommandTest, DefaultCommandInterruptResume) {
|
2019-08-25 23:55:59 -04:00
|
|
|
CommandScheduler scheduler = GetScheduler();
|
|
|
|
|
|
|
|
|
|
TestSubsystem subsystem;
|
|
|
|
|
|
2024-12-29 10:45:17 -06:00
|
|
|
auto command1 = cmd::Idle({&subsystem});
|
|
|
|
|
auto command2 = cmd::Idle({&subsystem});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
scheduler.SetDefaultCommand(&subsystem, std::move(command1));
|
|
|
|
|
auto handle = scheduler.GetDefaultCommand(&subsystem);
|
|
|
|
|
scheduler.Run();
|
2024-12-29 10:45:17 -06:00
|
|
|
scheduler.Schedule(command2);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2024-12-29 10:45:17 -06:00
|
|
|
EXPECT_TRUE(scheduler.IsScheduled(command2));
|
2019-08-25 23:55:59 -04:00
|
|
|
EXPECT_FALSE(scheduler.IsScheduled(handle));
|
|
|
|
|
|
2024-12-29 10:45:17 -06:00
|
|
|
scheduler.Cancel(command2);
|
2019-08-25 23:55:59 -04:00
|
|
|
scheduler.Run();
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(scheduler.IsScheduled(handle));
|
|
|
|
|
}
|