mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal, wpilib] Rewrite CAN APIs (#7798)
This commit is contained in:
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test;
|
||||
class DoubleSolenoidTestCTRE {
|
||||
@Test
|
||||
void testValidInitialization() {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(3, PneumaticsModuleType.CTREPCM, 2, 3)) {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(0, 3, PneumaticsModuleType.CTREPCM, 2, 3)) {
|
||||
solenoid.set(DoubleSolenoid.Value.kReverse);
|
||||
assertEquals(DoubleSolenoid.Value.kReverse, solenoid.get());
|
||||
|
||||
@@ -29,10 +29,10 @@ class DoubleSolenoidTestCTRE {
|
||||
void testThrowForwardPortAlreadyInitialized() {
|
||||
try (
|
||||
// Single solenoid that is reused for forward port
|
||||
Solenoid solenoid = new Solenoid(5, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
Solenoid solenoid = new Solenoid(0, 5, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
assertThrows(
|
||||
AllocationException.class,
|
||||
() -> new DoubleSolenoid(5, PneumaticsModuleType.CTREPCM, 2, 3));
|
||||
() -> new DoubleSolenoid(0, 5, PneumaticsModuleType.CTREPCM, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ class DoubleSolenoidTestCTRE {
|
||||
void testThrowReversePortAlreadyInitialized() {
|
||||
try (
|
||||
// Single solenoid that is reused for forward port
|
||||
Solenoid solenoid = new Solenoid(6, PneumaticsModuleType.CTREPCM, 3)) {
|
||||
Solenoid solenoid = new Solenoid(0, 6, PneumaticsModuleType.CTREPCM, 3)) {
|
||||
assertThrows(
|
||||
AllocationException.class,
|
||||
() -> new DoubleSolenoid(6, PneumaticsModuleType.CTREPCM, 2, 3));
|
||||
() -> new DoubleSolenoid(0, 6, PneumaticsModuleType.CTREPCM, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,17 +51,17 @@ class DoubleSolenoidTestCTRE {
|
||||
void testThrowBothPortsAlreadyInitialized() {
|
||||
try (
|
||||
// Single solenoid that is reused for forward port
|
||||
Solenoid solenoid0 = new Solenoid(6, PneumaticsModuleType.CTREPCM, 2);
|
||||
Solenoid solenoid1 = new Solenoid(6, PneumaticsModuleType.CTREPCM, 3)) {
|
||||
Solenoid solenoid0 = new Solenoid(0, 6, PneumaticsModuleType.CTREPCM, 2);
|
||||
Solenoid solenoid1 = new Solenoid(0, 6, PneumaticsModuleType.CTREPCM, 3)) {
|
||||
assertThrows(
|
||||
AllocationException.class,
|
||||
() -> new DoubleSolenoid(6, PneumaticsModuleType.CTREPCM, 2, 3));
|
||||
() -> new DoubleSolenoid(0, 6, PneumaticsModuleType.CTREPCM, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToggle() {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(4, PneumaticsModuleType.CTREPCM, 2, 3)) {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(0, 4, PneumaticsModuleType.CTREPCM, 2, 3)) {
|
||||
// Bootstrap it into reverse
|
||||
solenoid.set(DoubleSolenoid.Value.kReverse);
|
||||
|
||||
@@ -82,13 +82,13 @@ class DoubleSolenoidTestCTRE {
|
||||
void testInvalidForwardPort() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new DoubleSolenoid(0, PneumaticsModuleType.CTREPCM, 100, 1));
|
||||
() -> new DoubleSolenoid(0, 0, PneumaticsModuleType.CTREPCM, 100, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidReversePort() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new DoubleSolenoid(0, PneumaticsModuleType.CTREPCM, 0, 100));
|
||||
() -> new DoubleSolenoid(0, 0, PneumaticsModuleType.CTREPCM, 0, 100));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test;
|
||||
class DoubleSolenoidTestREV {
|
||||
@Test
|
||||
void testValidInitialization() {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(3, PneumaticsModuleType.REVPH, 2, 3)) {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(0, 3, PneumaticsModuleType.REVPH, 2, 3)) {
|
||||
solenoid.set(DoubleSolenoid.Value.kReverse);
|
||||
assertEquals(DoubleSolenoid.Value.kReverse, solenoid.get());
|
||||
|
||||
@@ -29,9 +29,10 @@ class DoubleSolenoidTestREV {
|
||||
void testThrowForwardPortAlreadyInitialized() {
|
||||
try (
|
||||
// Single solenoid that is reused for forward port
|
||||
Solenoid solenoid = new Solenoid(5, PneumaticsModuleType.REVPH, 2)) {
|
||||
Solenoid solenoid = new Solenoid(0, 5, PneumaticsModuleType.REVPH, 2)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new DoubleSolenoid(5, PneumaticsModuleType.REVPH, 2, 3));
|
||||
AllocationException.class,
|
||||
() -> new DoubleSolenoid(0, 5, PneumaticsModuleType.REVPH, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +40,10 @@ class DoubleSolenoidTestREV {
|
||||
void testThrowReversePortAlreadyInitialized() {
|
||||
try (
|
||||
// Single solenoid that is reused for forward port
|
||||
Solenoid solenoid = new Solenoid(6, PneumaticsModuleType.REVPH, 3)) {
|
||||
Solenoid solenoid = new Solenoid(0, 6, PneumaticsModuleType.REVPH, 3)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new DoubleSolenoid(6, PneumaticsModuleType.REVPH, 2, 3));
|
||||
AllocationException.class,
|
||||
() -> new DoubleSolenoid(0, 6, PneumaticsModuleType.REVPH, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,16 +51,17 @@ class DoubleSolenoidTestREV {
|
||||
void testThrowBothPortsAlreadyInitialized() {
|
||||
try (
|
||||
// Single solenoid that is reused for forward port
|
||||
Solenoid solenoid0 = new Solenoid(6, PneumaticsModuleType.REVPH, 2);
|
||||
Solenoid solenoid1 = new Solenoid(6, PneumaticsModuleType.REVPH, 3)) {
|
||||
Solenoid solenoid0 = new Solenoid(0, 6, PneumaticsModuleType.REVPH, 2);
|
||||
Solenoid solenoid1 = new Solenoid(0, 6, PneumaticsModuleType.REVPH, 3)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new DoubleSolenoid(6, PneumaticsModuleType.REVPH, 2, 3));
|
||||
AllocationException.class,
|
||||
() -> new DoubleSolenoid(0, 6, PneumaticsModuleType.REVPH, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToggle() {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(4, PneumaticsModuleType.REVPH, 2, 3)) {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(0, 4, PneumaticsModuleType.REVPH, 2, 3)) {
|
||||
// Bootstrap it into reverse
|
||||
solenoid.set(DoubleSolenoid.Value.kReverse);
|
||||
|
||||
@@ -79,13 +82,13 @@ class DoubleSolenoidTestREV {
|
||||
void testInvalidForwardPort() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new DoubleSolenoid(1, PneumaticsModuleType.REVPH, 100, 1));
|
||||
() -> new DoubleSolenoid(0, 1, PneumaticsModuleType.REVPH, 100, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidReversePort() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new DoubleSolenoid(1, PneumaticsModuleType.REVPH, 0, 100));
|
||||
() -> new DoubleSolenoid(0, 1, PneumaticsModuleType.REVPH, 0, 100));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class PowerDistributionTest {
|
||||
@Test
|
||||
void testGetAllCurrents() {
|
||||
HAL.initialize(500, 0);
|
||||
PowerDistribution pdp = new PowerDistribution(1, ModuleType.kRev);
|
||||
PowerDistribution pdp = new PowerDistribution(0, 1, ModuleType.kRev);
|
||||
PDPSim sim = new PDPSim(pdp);
|
||||
|
||||
for (int i = 0; i < pdp.getNumChannels(); i++) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
class SolenoidTestCTRE {
|
||||
@Test
|
||||
void testValidInitialization() {
|
||||
try (Solenoid solenoid = new Solenoid(3, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
try (Solenoid solenoid = new Solenoid(0, 3, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
assertEquals(2, solenoid.getChannel());
|
||||
|
||||
solenoid.set(true);
|
||||
@@ -28,29 +28,30 @@ class SolenoidTestCTRE {
|
||||
|
||||
@Test
|
||||
void testDoubleInitialization() {
|
||||
try (Solenoid solenoid = new Solenoid(3, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
try (Solenoid solenoid = new Solenoid(0, 3, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new Solenoid(3, PneumaticsModuleType.CTREPCM, 2));
|
||||
AllocationException.class, () -> new Solenoid(0, 3, PneumaticsModuleType.CTREPCM, 2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoubleInitializationFromDoubleSolenoid() {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(3, PneumaticsModuleType.CTREPCM, 2, 3)) {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(0, 3, PneumaticsModuleType.CTREPCM, 2, 3)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new Solenoid(3, PneumaticsModuleType.CTREPCM, 2));
|
||||
AllocationException.class, () -> new Solenoid(0, 3, PneumaticsModuleType.CTREPCM, 2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidChannel() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Solenoid(3, PneumaticsModuleType.CTREPCM, 100));
|
||||
IllegalArgumentException.class,
|
||||
() -> new Solenoid(0, 3, PneumaticsModuleType.CTREPCM, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToggle() {
|
||||
try (Solenoid solenoid = new Solenoid(3, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
try (Solenoid solenoid = new Solenoid(0, 3, PneumaticsModuleType.CTREPCM, 2)) {
|
||||
solenoid.set(true);
|
||||
assertTrue(solenoid.get());
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
class SolenoidTestREV {
|
||||
@Test
|
||||
void testValidInitialization() {
|
||||
try (Solenoid solenoid = new Solenoid(3, PneumaticsModuleType.REVPH, 2)) {
|
||||
try (Solenoid solenoid = new Solenoid(0, 3, PneumaticsModuleType.REVPH, 2)) {
|
||||
assertEquals(2, solenoid.getChannel());
|
||||
|
||||
solenoid.set(true);
|
||||
@@ -28,27 +28,29 @@ class SolenoidTestREV {
|
||||
|
||||
@Test
|
||||
void testDoubleInitialization() {
|
||||
try (Solenoid solenoid = new Solenoid(3, PneumaticsModuleType.REVPH, 2)) {
|
||||
assertThrows(AllocationException.class, () -> new Solenoid(3, PneumaticsModuleType.REVPH, 2));
|
||||
try (Solenoid solenoid = new Solenoid(0, 3, PneumaticsModuleType.REVPH, 2)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new Solenoid(0, 3, PneumaticsModuleType.REVPH, 2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoubleInitializationFromDoubleSolenoid() {
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(3, PneumaticsModuleType.REVPH, 2, 3)) {
|
||||
assertThrows(AllocationException.class, () -> new Solenoid(3, PneumaticsModuleType.REVPH, 2));
|
||||
try (DoubleSolenoid solenoid = new DoubleSolenoid(0, 3, PneumaticsModuleType.REVPH, 2, 3)) {
|
||||
assertThrows(
|
||||
AllocationException.class, () -> new Solenoid(0, 3, PneumaticsModuleType.REVPH, 2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidChannel() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> new Solenoid(3, PneumaticsModuleType.REVPH, 100));
|
||||
IllegalArgumentException.class, () -> new Solenoid(0, 3, PneumaticsModuleType.REVPH, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToggle() {
|
||||
try (Solenoid solenoid = new Solenoid(3, PneumaticsModuleType.REVPH, 2)) {
|
||||
try (Solenoid solenoid = new Solenoid(0, 3, PneumaticsModuleType.REVPH, 2)) {
|
||||
solenoid.set(true);
|
||||
assertTrue(solenoid.get());
|
||||
|
||||
|
||||
@@ -16,6 +16,6 @@ class CANStatusTest {
|
||||
void canStatusGetDoesntThrow() {
|
||||
HAL.initialize(500, 0);
|
||||
CANStatus status = new CANStatus();
|
||||
assertDoesNotThrow(() -> CANJNI.getCANStatus(status));
|
||||
assertDoesNotThrow(() -> CANJNI.getCANStatus(0, status));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user