blob: e4a2721a48c1ed16cfde468ebe0cdda5fce9e398 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
Brian Silverman8fce7482020-01-05 13:18:21 -08004
5#include "frc/DriverStation.h" // NOLINT(build/include_order)
6
Austin Schuh812d0d12021-11-04 20:16:48 -07007#include <units/math.h>
8#include <units/time.h>
9
Brian Silverman8fce7482020-01-05 13:18:21 -080010#include "TestBench.h"
11#include "frc/RobotController.h"
12#include "gtest/gtest.h"
13
Austin Schuh812d0d12021-11-04 20:16:48 -070014#define EXPECT_NEAR_UNITS(val1, val2, eps) \
15 EXPECT_LE(units::math::abs(val1 - val2), eps)
Brian Silverman8fce7482020-01-05 13:18:21 -080016
17/**
18 * Test if the WaitForData function works
19 */
Austin Schuh812d0d12021-11-04 20:16:48 -070020TEST(DriverStationTest, WaitForData) {
21 units::microsecond_t initialTime(frc::RobotController::GetFPGATime());
Brian Silverman8fce7482020-01-05 13:18:21 -080022
Austin Schuh812d0d12021-11-04 20:16:48 -070023 // 20ms waiting intervals * 50 = 1s
Brian Silverman8fce7482020-01-05 13:18:21 -080024 for (int i = 0; i < 50; i++) {
Austin Schuh812d0d12021-11-04 20:16:48 -070025 frc::DriverStation::WaitForData();
Brian Silverman8fce7482020-01-05 13:18:21 -080026 }
27
Austin Schuh812d0d12021-11-04 20:16:48 -070028 units::microsecond_t finalTime(frc::RobotController::GetFPGATime());
Brian Silverman8fce7482020-01-05 13:18:21 -080029
Austin Schuh812d0d12021-11-04 20:16:48 -070030 EXPECT_NEAR_UNITS(1_s, finalTime - initialTime, 200_ms);
Brian Silverman8fce7482020-01-05 13:18:21 -080031}