2020-11-13 14:11:10 -05: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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2020-11-14 15:00:56 -05:00
|
|
|
#include <string>
|
2020-11-13 14:11:10 -05:00
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
|
|
#include "frc/DriverStation.h"
|
2020-11-14 15:00:56 -05:00
|
|
|
#include "frc/Joystick.h"
|
2020-11-13 14:11:10 -05:00
|
|
|
#include "frc/simulation/DriverStationSim.h"
|
2020-11-14 15:00:56 -05:00
|
|
|
#include "frc/simulation/SimHooks.h"
|
2020-11-13 14:11:10 -05:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
class IsJoystickConnectedParametersTests
|
|
|
|
|
: public ::testing::TestWithParam<std::tuple<int, int, int, bool>> {};
|
|
|
|
|
|
|
|
|
|
TEST_P(IsJoystickConnectedParametersTests, IsJoystickConnected) {
|
|
|
|
|
frc::sim::DriverStationSim::SetJoystickAxisCount(1, std::get<0>(GetParam()));
|
|
|
|
|
frc::sim::DriverStationSim::SetJoystickButtonCount(1,
|
|
|
|
|
std::get<1>(GetParam()));
|
|
|
|
|
frc::sim::DriverStationSim::SetJoystickPOVCount(1, std::get<2>(GetParam()));
|
|
|
|
|
frc::sim::DriverStationSim::NotifyNewData();
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(std::get<3>(GetParam()),
|
|
|
|
|
frc::DriverStation::GetInstance().IsJoystickConnected(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(IsConnectedTests, IsJoystickConnectedParametersTests,
|
|
|
|
|
::testing::Values(std::make_tuple(0, 0, 0, false),
|
|
|
|
|
std::make_tuple(1, 0, 0, true),
|
|
|
|
|
std::make_tuple(0, 1, 0, true),
|
|
|
|
|
std::make_tuple(0, 0, 1, true),
|
|
|
|
|
std::make_tuple(1, 1, 1, true),
|
|
|
|
|
std::make_tuple(4, 10, 1, true)));
|
2020-11-14 15:00:56 -05:00
|
|
|
class JoystickConnectionWarningTests
|
|
|
|
|
: public ::testing::TestWithParam<
|
|
|
|
|
std::tuple<bool, bool, bool, std::string>> {};
|
|
|
|
|
|
|
|
|
|
TEST_P(JoystickConnectionWarningTests, JoystickConnectionWarnings) {
|
|
|
|
|
// Capture all output to stderr.
|
|
|
|
|
::testing::internal::CaptureStderr();
|
|
|
|
|
|
|
|
|
|
// Set FMS and Silence settings
|
|
|
|
|
frc::sim::DriverStationSim::SetFmsAttached(std::get<0>(GetParam()));
|
|
|
|
|
frc::sim::DriverStationSim::NotifyNewData();
|
|
|
|
|
frc::DriverStation::GetInstance().SilenceJoystickConnectionWarning(
|
|
|
|
|
std::get<1>(GetParam()));
|
|
|
|
|
|
|
|
|
|
// Create joystick and attempt to retrieve button.
|
|
|
|
|
frc::Joystick joystick(0);
|
|
|
|
|
joystick.GetRawButton(1);
|
|
|
|
|
|
|
|
|
|
frc::sim::StepTiming(1_s);
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
frc::DriverStation::GetInstance().IsJoystickConnectionWarningSilenced(),
|
|
|
|
|
std::get<2>(GetParam()));
|
|
|
|
|
EXPECT_EQ(::testing::internal::GetCapturedStderr(), std::get<3>(GetParam()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
|
|
|
DriverStation, JoystickConnectionWarningTests,
|
|
|
|
|
::testing::Values(std::make_tuple(false, true, true, ""),
|
|
|
|
|
std::make_tuple(false, false, false,
|
|
|
|
|
"Joystick Button missing, check if all "
|
|
|
|
|
"controllers are plugged in\n"),
|
|
|
|
|
std::make_tuple(true, true, false,
|
|
|
|
|
"Joystick Button missing, check if all "
|
|
|
|
|
"controllers are plugged in\n"),
|
|
|
|
|
std::make_tuple(true, false, false,
|
|
|
|
|
"Joystick Button missing, check if all "
|
|
|
|
|
"controllers are plugged in\n")));
|