Files
allwpilib/commandsv2/src/test/native/cpp/wpi/command/POVButtonTest.cpp
2026-06-09 22:16:26 -07:00

42 lines
1.2 KiB
C++

// 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.
#include "wpi/commands2/button/POVButton.hpp"
#include <gtest/gtest.h>
#include "CommandTestBase.hpp"
#include "wpi/commands2/CommandScheduler.hpp"
#include "wpi/commands2/WaitUntilCommand.hpp"
#include "wpi/driverstation/Joystick.hpp"
#include "wpi/simulation/JoystickSim.hpp"
using namespace wpi::cmd;
class POVButtonTest : public CommandTestBase {};
TEST_F(POVButtonTest, SetPOV) {
wpi::sim::JoystickSim joysim(1);
joysim.SetPOV(wpi::POVDirection::UP);
joysim.NotifyNewData();
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
WaitUntilCommand command([&finished] { return finished; });
wpi::Joystick joy(1);
POVButton(&joy, wpi::POVDirection::RIGHT).OnTrue(&command);
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
joysim.SetPOV(wpi::POVDirection::RIGHT);
joysim.NotifyNewData();
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
finished = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
}