Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
| 4 | |
| 5 | #include <hal/HAL.h> |
| 6 | |
| 7 | #include "frc/DoubleSolenoid.h" |
| 8 | #include "frc/PneumaticsControlModule.h" |
| 9 | #include "frc/Solenoid.h" |
| 10 | #include "gtest/gtest.h" |
| 11 | |
| 12 | namespace frc { |
| 13 | TEST(SolenoidCTRETest, ValidInitialization) { |
| 14 | Solenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2}; |
| 15 | EXPECT_EQ(2, solenoid.GetChannel()); |
| 16 | |
| 17 | solenoid.Set(true); |
| 18 | EXPECT_TRUE(solenoid.Get()); |
| 19 | |
| 20 | solenoid.Set(false); |
| 21 | EXPECT_FALSE(solenoid.Get()); |
| 22 | } |
| 23 | |
| 24 | TEST(SolenoidCTRETest, DoubleInitialization) { |
| 25 | Solenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2}; |
| 26 | EXPECT_THROW(Solenoid(3, frc::PneumaticsModuleType::CTREPCM, 2), |
| 27 | std::runtime_error); |
| 28 | } |
| 29 | |
| 30 | TEST(SolenoidCTRETest, DoubleInitializationFromDoubleSolenoid) { |
| 31 | DoubleSolenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2, 3}; |
| 32 | EXPECT_THROW(Solenoid(3, frc::PneumaticsModuleType::CTREPCM, 2), |
| 33 | std::runtime_error); |
| 34 | } |
| 35 | |
| 36 | TEST(SolenoidCTRETest, InvalidChannel) { |
| 37 | EXPECT_THROW(Solenoid(3, frc::PneumaticsModuleType::CTREPCM, 100), |
| 38 | std::runtime_error); |
| 39 | } |
| 40 | |
| 41 | TEST(SolenoidCTRETest, Toggle) { |
| 42 | Solenoid solenoid{3, frc::PneumaticsModuleType::CTREPCM, 2}; |
| 43 | solenoid.Set(true); |
| 44 | EXPECT_TRUE(solenoid.Get()); |
| 45 | |
| 46 | solenoid.Toggle(); |
| 47 | EXPECT_FALSE(solenoid.Get()); |
| 48 | |
| 49 | solenoid.Toggle(); |
| 50 | EXPECT_TRUE(solenoid.Get()); |
| 51 | } |
| 52 | } // namespace frc |