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
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/DriverStation.h" // NOLINT(build/include_order)
|
2016-10-06 11:18:47 -07:00
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
#include <units/math.h>
|
|
|
|
|
#include <units/time.h>
|
|
|
|
|
|
2016-10-06 11:18:47 -07:00
|
|
|
#include "TestBench.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/RobotController.h"
|
2016-10-06 11:18:47 -07:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
|
|
|
|
|
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
2016-10-06 11:18:47 -07:00
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
using namespace frc;
|
2016-10-06 11:18:47 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if the WaitForData function works
|
|
|
|
|
*/
|
2021-05-28 22:06:59 -07:00
|
|
|
TEST(DriverStationTest, WaitForData) {
|
|
|
|
|
units::microsecond_t initialTime(RobotController::GetFPGATime());
|
2016-10-06 11:18:47 -07:00
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
// 20ms waiting intervals * 50 = 1s
|
2016-10-06 11:18:47 -07:00
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
|
DriverStation::GetInstance().WaitForData();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
units::microsecond_t finalTime(RobotController::GetFPGATime());
|
2016-10-06 11:18:47 -07:00
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
EXPECT_NEAR_UNITS(1_s, finalTime - initialTime, 200_ms);
|
2016-10-06 11:18:47 -07:00
|
|
|
}
|