2020-12-26 14:12:05 -08: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.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-06-17 11:10:45 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2014-06-17 11:10:45 -04:00
|
|
|
|
2017-08-28 00:32:53 -07:00
|
|
|
import edu.wpi.first.networktables.NetworkTable;
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
2014-06-17 11:10:45 -04:00
|
|
|
import edu.wpi.first.wpilibj.Relay.Direction;
|
|
|
|
|
import edu.wpi.first.wpilibj.Relay.InvalidValueException;
|
|
|
|
|
import edu.wpi.first.wpilibj.Relay.Value;
|
2015-09-01 06:02:05 -07:00
|
|
|
import edu.wpi.first.wpilibj.fixtures.RelayCrossConnectFixture;
|
2017-12-04 23:28:33 -08:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
|
2014-06-17 11:10:45 -04:00
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.TestBench;
|
2020-12-29 22:45:16 -08:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
2014-06-17 11:10:45 -04:00
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
/** Tests the {@link RelayCrossConnectFixture}. */
|
2014-06-17 11:10:45 -04:00
|
|
|
public class RelayCrossConnectTest extends AbstractComsSetup {
|
2015-06-25 15:07:55 -04:00
|
|
|
private static final Logger logger = Logger.getLogger(RelayCrossConnectTest.class.getName());
|
2017-08-28 00:32:53 -07:00
|
|
|
private static final NetworkTable table =
|
|
|
|
|
NetworkTableInstance.getDefault().getTable("_RELAY_CROSS_CONNECT_TEST_");
|
2016-05-20 12:07:40 -04:00
|
|
|
private RelayCrossConnectFixture m_relayFixture;
|
2017-12-04 23:28:33 -08:00
|
|
|
private SendableBuilderImpl m_builder;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
@Before
|
2019-08-01 01:19:48 -04:00
|
|
|
public void setUp() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture = TestBench.getRelayCrossConnectFixture();
|
|
|
|
|
m_relayFixture.setup();
|
2017-12-04 23:28:33 -08:00
|
|
|
m_builder = new SendableBuilderImpl();
|
|
|
|
|
m_builder.setTable(table);
|
|
|
|
|
m_relayFixture.getRelay().initSendable(m_builder);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
2019-08-01 01:19:48 -04:00
|
|
|
public void tearDown() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture.reset();
|
|
|
|
|
m_relayFixture.teardown();
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testBothHigh() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kBoth);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kOn);
|
2021-06-13 16:38:05 -07:00
|
|
|
m_builder.update();
|
2020-12-29 22:45:16 -08:00
|
|
|
assertTrue(
|
|
|
|
|
"Input one was not high when relay set both high", m_relayFixture.getInputOne().get());
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Input two was not high when relay set both high", m_relayFixture.getInputTwo().get());
|
2017-05-08 21:54:03 -07:00
|
|
|
assertEquals(Value.kOn, m_relayFixture.getRelay().get());
|
2017-08-28 00:32:53 -07:00
|
|
|
assertEquals("On", table.getEntry("Value").getString(""));
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testFirstHigh() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kBoth);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kForward);
|
2021-06-13 16:38:05 -07:00
|
|
|
m_builder.update();
|
2020-12-29 22:45:16 -08:00
|
|
|
assertFalse(
|
|
|
|
|
"Input one was not low when relay set Value.kForward", m_relayFixture.getInputOne().get());
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Input two was not high when relay set Value.kForward", m_relayFixture.getInputTwo().get());
|
2017-05-08 21:54:03 -07:00
|
|
|
assertEquals(Value.kForward, m_relayFixture.getRelay().get());
|
2017-08-28 00:32:53 -07:00
|
|
|
assertEquals("Forward", table.getEntry("Value").getString(""));
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSecondHigh() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kBoth);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kReverse);
|
2021-06-13 16:38:05 -07:00
|
|
|
m_builder.update();
|
2020-12-29 22:45:16 -08:00
|
|
|
assertTrue(
|
|
|
|
|
"Input one was not high when relay set Value.kReverse", m_relayFixture.getInputOne().get());
|
|
|
|
|
assertFalse(
|
|
|
|
|
"Input two was not low when relay set Value.kReverse", m_relayFixture.getInputTwo().get());
|
2017-05-08 21:54:03 -07:00
|
|
|
assertEquals(Value.kReverse, m_relayFixture.getRelay().get());
|
2017-08-28 00:32:53 -07:00
|
|
|
assertEquals("Reverse", table.getEntry("Value").getString(""));
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2017-05-08 21:54:03 -07:00
|
|
|
@Test
|
|
|
|
|
public void testForwardDirection() {
|
|
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kForward);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kOn);
|
2021-06-13 16:38:05 -07:00
|
|
|
m_builder.update();
|
2020-12-29 22:45:16 -08:00
|
|
|
assertFalse(
|
|
|
|
|
"Input one was not low when relay set Value.kOn in kForward Direction",
|
2017-05-08 21:54:03 -07:00
|
|
|
m_relayFixture.getInputOne().get());
|
2020-12-29 22:45:16 -08:00
|
|
|
assertTrue(
|
|
|
|
|
"Input two was not high when relay set Value.kOn in kForward Direction",
|
2017-05-08 21:54:03 -07:00
|
|
|
m_relayFixture.getInputTwo().get());
|
|
|
|
|
assertEquals(Value.kOn, m_relayFixture.getRelay().get());
|
2017-08-28 00:32:53 -07:00
|
|
|
assertEquals("On", table.getEntry("Value").getString(""));
|
2017-05-08 21:54:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testReverseDirection() {
|
|
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kReverse);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kOn);
|
2021-06-13 16:38:05 -07:00
|
|
|
m_builder.update();
|
2020-12-29 22:45:16 -08:00
|
|
|
assertTrue(
|
|
|
|
|
"Input one was not high when relay set Value.kOn in kReverse Direction",
|
2017-05-08 21:54:03 -07:00
|
|
|
m_relayFixture.getInputOne().get());
|
2020-12-29 22:45:16 -08:00
|
|
|
assertFalse(
|
|
|
|
|
"Input two was not low when relay set Value.kOn in kReverse Direction",
|
2017-05-08 21:54:03 -07:00
|
|
|
m_relayFixture.getInputTwo().get());
|
|
|
|
|
assertEquals(Value.kOn, m_relayFixture.getRelay().get());
|
2017-08-28 00:32:53 -07:00
|
|
|
assertEquals("On", table.getEntry("Value").getString(""));
|
2017-05-08 21:54:03 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
@Test(expected = InvalidValueException.class)
|
|
|
|
|
public void testSetValueForwardWithDirectionReverseThrowingException() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kForward);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kReverse);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = InvalidValueException.class)
|
|
|
|
|
public void testSetValueReverseWithDirectionForwardThrowingException() {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kReverse);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kForward);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInitialSettings() {
|
2021-06-13 16:38:05 -07:00
|
|
|
m_builder.update();
|
2016-05-20 12:07:40 -04:00
|
|
|
assertEquals(Value.kOff, m_relayFixture.getRelay().get());
|
2015-06-25 15:07:55 -04:00
|
|
|
// Initially both outputs should be off
|
2016-05-20 12:07:40 -04:00
|
|
|
assertFalse(m_relayFixture.getInputOne().get());
|
|
|
|
|
assertFalse(m_relayFixture.getInputTwo().get());
|
2017-08-28 00:32:53 -07:00
|
|
|
assertEquals("Off", table.getEntry("Value").getString(""));
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
2014-06-17 11:10:45 -04:00
|
|
|
}
|