2021-08-05 22:04:51 -04: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.
|
|
|
|
|
|
|
|
|
|
#include <hal/HAL.h>
|
|
|
|
|
|
|
|
|
|
#include "frc/DoubleSolenoid.h"
|
|
|
|
|
#include "frc/PneumaticsControlModule.h"
|
|
|
|
|
#include "frc/Solenoid.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
TEST(SolenoidTest, ValidInitialization) {
|
2021-09-16 18:50:27 -07:00
|
|
|
Solenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2};
|
2021-08-05 22:04:51 -04:00
|
|
|
EXPECT_EQ(2, solenoid.GetChannel());
|
|
|
|
|
|
|
|
|
|
solenoid.Set(true);
|
|
|
|
|
EXPECT_TRUE(solenoid.Get());
|
|
|
|
|
|
|
|
|
|
solenoid.Set(false);
|
|
|
|
|
EXPECT_FALSE(solenoid.Get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SolenoidTest, DoubleInitialization) {
|
2021-09-16 18:50:27 -07:00
|
|
|
Solenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2};
|
|
|
|
|
EXPECT_THROW(Solenoid(3, frc::PneumaticsModuleType::CTREPCM, 2),
|
|
|
|
|
std::runtime_error);
|
2021-08-05 22:04:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SolenoidTest, DoubleInitializationFromDoubleSolenoid) {
|
2021-09-16 18:50:27 -07:00
|
|
|
DoubleSolenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2, 3};
|
|
|
|
|
EXPECT_THROW(Solenoid(3, frc::PneumaticsModuleType::CTREPCM, 2),
|
|
|
|
|
std::runtime_error);
|
2021-08-05 22:04:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SolenoidTest, InvalidChannel) {
|
2021-09-16 18:50:27 -07:00
|
|
|
EXPECT_THROW(Solenoid(3, frc::PneumaticsModuleType::CTREPCM, 100),
|
|
|
|
|
std::runtime_error);
|
2021-08-05 22:04:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SolenoidTest, Toggle) {
|
2021-09-16 18:50:27 -07:00
|
|
|
Solenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2};
|
2021-08-05 22:04:51 -04:00
|
|
|
solenoid.Set(true);
|
|
|
|
|
EXPECT_TRUE(solenoid.Get());
|
|
|
|
|
|
|
|
|
|
solenoid.Toggle();
|
|
|
|
|
EXPECT_FALSE(solenoid.Get());
|
|
|
|
|
|
|
|
|
|
solenoid.Toggle();
|
|
|
|
|
EXPECT_TRUE(solenoid.Get());
|
|
|
|
|
}
|
|
|
|
|
} // namespace frc
|