2014-06-17 11:10:45 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-23 22:06:13 -07:00
|
|
|
/* Copyright (c) 2008-2017 FIRST. All Rights Reserved. */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2014-06-17 11:10:45 -04:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* the project. */
|
2014-06-17 11:10:45 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-06-17 11:10:45 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
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;
|
2014-06-17 11:10:45 -04:00
|
|
|
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.TestBench;
|
|
|
|
|
|
2016-05-20 12:07:40 -04: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
|
|
|
/**
|
2016-05-20 12:07:40 -04: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());
|
|
|
|
|
private static final NetworkTable table = NetworkTable.getTable("_RELAY_CROSS_CONNECT_TEST_");
|
2016-05-20 12:07:40 -04:00
|
|
|
private RelayCrossConnectFixture m_relayFixture;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void setUp() throws Exception {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_relayFixture = TestBench.getRelayCrossConnectFixture();
|
|
|
|
|
m_relayFixture.setup();
|
|
|
|
|
m_relayFixture.getRelay().initTable(table);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
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);
|
|
|
|
|
m_relayFixture.getRelay().updateTable();
|
|
|
|
|
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-18 21:35:53 -07:00
|
|
|
assertEquals("On", table.getString("Value", ""));
|
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);
|
|
|
|
|
m_relayFixture.getRelay().updateTable();
|
|
|
|
|
assertFalse("Input one was not low when relay set Value.kForward", m_relayFixture.getInputOne()
|
2015-06-25 15:07:55 -04:00
|
|
|
.get());
|
2016-05-20 12:07:40 -04:00
|
|
|
assertTrue("Input two was not high when relay set Value.kForward", m_relayFixture
|
|
|
|
|
.getInputTwo()
|
2015-06-25 15:07:55 -04:00
|
|
|
.get());
|
2017-05-08 21:54:03 -07:00
|
|
|
assertEquals(Value.kForward, m_relayFixture.getRelay().get());
|
2017-08-18 21:35:53 -07:00
|
|
|
assertEquals("Forward", table.getString("Value", ""));
|
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);
|
|
|
|
|
m_relayFixture.getRelay().updateTable();
|
|
|
|
|
assertTrue("Input one was not high when relay set Value.kReverse", m_relayFixture.getInputOne()
|
2015-06-25 15:07:55 -04:00
|
|
|
.get());
|
2016-05-20 12:07:40 -04:00
|
|
|
assertFalse("Input two was not low when relay set Value.kReverse", m_relayFixture
|
|
|
|
|
.getInputTwo()
|
2015-06-25 15:07:55 -04:00
|
|
|
.get());
|
2017-05-08 21:54:03 -07:00
|
|
|
assertEquals(Value.kReverse, m_relayFixture.getRelay().get());
|
2017-08-18 21:35:53 -07:00
|
|
|
assertEquals("Reverse", table.getString("Value", ""));
|
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);
|
|
|
|
|
m_relayFixture.getRelay().updateTable();
|
|
|
|
|
assertFalse("Input one was not low when relay set Value.kOn in kForward Direction",
|
|
|
|
|
m_relayFixture.getInputOne().get());
|
|
|
|
|
assertTrue("Input two was not high when relay set Value.kOn in kForward Direction",
|
|
|
|
|
m_relayFixture.getInputTwo().get());
|
|
|
|
|
assertEquals(Value.kOn, m_relayFixture.getRelay().get());
|
2017-08-18 21:35:53 -07:00
|
|
|
assertEquals("On", table.getString("Value", ""));
|
2017-05-08 21:54:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testReverseDirection() {
|
|
|
|
|
m_relayFixture.getRelay().setDirection(Direction.kReverse);
|
|
|
|
|
m_relayFixture.getRelay().set(Value.kOn);
|
|
|
|
|
m_relayFixture.getRelay().updateTable();
|
|
|
|
|
assertTrue("Input one was not high when relay set Value.kOn in kReverse Direction",
|
|
|
|
|
m_relayFixture.getInputOne().get());
|
|
|
|
|
assertFalse("Input two was not low when relay set Value.kOn in kReverse Direction",
|
|
|
|
|
m_relayFixture.getInputTwo().get());
|
|
|
|
|
assertEquals(Value.kOn, m_relayFixture.getRelay().get());
|
2017-08-18 21:35:53 -07:00
|
|
|
assertEquals("On", table.getString("Value", ""));
|
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() {
|
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-18 21:35:53 -07:00
|
|
|
assertEquals("Off", table.getString("Value", ""));
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
2014-06-17 11:10:45 -04:00
|
|
|
|
|
|
|
|
}
|