2020-01-20 21:35:19 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include <frc/Joystick.h>
|
2020-07-15 23:48:09 -07:00
|
|
|
#include <frc/simulation/JoystickSim.h>
|
2020-01-20 21:35:19 -08:00
|
|
|
|
|
|
|
|
#include "CommandTestBase.h"
|
|
|
|
|
#include "frc2/command/CommandScheduler.h"
|
|
|
|
|
#include "frc2/command/RunCommand.h"
|
|
|
|
|
#include "frc2/command/WaitUntilCommand.h"
|
|
|
|
|
#include "frc2/command/button/POVButton.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
class POVButtonTest : public CommandTestBase {};
|
|
|
|
|
|
|
|
|
|
TEST_F(POVButtonTest, SetPOVTest) {
|
2020-07-15 23:48:09 -07:00
|
|
|
frc::sim::JoystickSim joysim(1);
|
|
|
|
|
joysim.SetPOV(0);
|
|
|
|
|
joysim.NotifyNewData();
|
2020-01-20 21:35:19 -08:00
|
|
|
|
|
|
|
|
auto& scheduler = CommandScheduler::GetInstance();
|
|
|
|
|
bool finished = false;
|
|
|
|
|
|
|
|
|
|
WaitUntilCommand command([&finished] { return finished; });
|
|
|
|
|
|
|
|
|
|
frc::Joystick joy(1);
|
|
|
|
|
POVButton(&joy, 90).WhenPressed(&command);
|
|
|
|
|
scheduler.Run();
|
|
|
|
|
EXPECT_FALSE(scheduler.IsScheduled(&command));
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
joysim.SetPOV(90);
|
|
|
|
|
joysim.NotifyNewData();
|
2020-01-20 21:35:19 -08:00
|
|
|
|
|
|
|
|
scheduler.Run();
|
|
|
|
|
EXPECT_TRUE(scheduler.IsScheduled(&command));
|
|
|
|
|
finished = true;
|
|
|
|
|
scheduler.Run();
|
|
|
|
|
EXPECT_FALSE(scheduler.IsScheduled(&command));
|
|
|
|
|
}
|