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-10-06 11:18:47 -07:00
|
|
|
|
|
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
import org.junit.Test;
|
2016-10-06 11:18:47 -07:00
|
|
|
|
|
|
|
|
public class DriverStationTest extends AbstractComsSetup {
|
|
|
|
|
private static final Logger logger = Logger.getLogger(TimerTest.class.getName());
|
|
|
|
|
private static final double TIMER_TOLERANCE = 0.2;
|
|
|
|
|
private static final long TIMER_RUNTIME = 1000000; // 1 second
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void waitForDataTest() {
|
2017-12-10 21:52:49 -08:00
|
|
|
long startTime = RobotController.getFPGATime();
|
2016-10-06 11:18:47 -07:00
|
|
|
|
|
|
|
|
// Wait for data 50 times
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
2021-06-15 23:06:03 -07:00
|
|
|
DriverStation.waitForData();
|
2016-10-06 11:18:47 -07:00
|
|
|
}
|
2017-12-10 21:52:49 -08:00
|
|
|
long endTime = RobotController.getFPGATime();
|
2016-10-06 11:18:47 -07:00
|
|
|
long difference = endTime - startTime;
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
assertEquals(
|
|
|
|
|
"DriverStation waitForData did not wait long enough",
|
|
|
|
|
TIMER_RUNTIME,
|
|
|
|
|
difference,
|
2016-10-06 11:18:47 -07:00
|
|
|
TIMER_TOLERANCE * TIMER_RUNTIME);
|
|
|
|
|
}
|
|
|
|
|
}
|