Files
allwpilib/commandsv2/src/test/native/cpp/wpi/command/button/RobotModeTriggersTest.cpp

51 lines
1.6 KiB
C++
Raw Normal View History

// 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.
2025-11-07 19:56:21 -05:00
#include "wpi/commands2/button/RobotModeTriggers.hpp"
#include "../CommandTestBase.hpp"
2025-11-07 19:56:21 -05:00
#include "wpi/commands2/button/Trigger.hpp"
2025-11-07 19:57:55 -05:00
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/hal/DriverStationTypes.h"
2025-11-07 19:57:55 -05:00
#include "wpi/simulation/DriverStationSim.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi::cmd;
using namespace wpi::sim;
class RobotModeTriggersTest : public CommandTestBase {};
TEST(RobotModeTriggersTest, Autonomous) {
DriverStationSim::ResetData();
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_AUTONOMOUS);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
Trigger autonomous = RobotModeTriggers::Autonomous();
EXPECT_TRUE(autonomous.Get());
}
TEST(RobotModeTriggersTest, Teleop) {
DriverStationSim::ResetData();
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
Trigger teleop = RobotModeTriggers::Teleop();
EXPECT_TRUE(teleop.Get());
}
TEST(RobotModeTriggersTest, Disabled) {
DriverStationSim::ResetData();
DriverStationSim::SetEnabled(false);
DriverStationSim::NotifyNewData();
Trigger disabled = RobotModeTriggers::Disabled();
EXPECT_TRUE(disabled.Get());
}
TEST(RobotModeTriggersTest, TestMode) {
DriverStationSim::ResetData();
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TEST);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
Trigger test = RobotModeTriggers::Test();
EXPECT_TRUE(test.Get());
}