Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "frc/Timer.h" // NOLINT(build/include_order) |
| 9 | |
| 10 | #include "TestBench.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | using namespace frc; |
| 14 | |
| 15 | static const double kWaitTime = 0.5; |
| 16 | |
| 17 | class TimerTest : public testing::Test { |
| 18 | protected: |
| 19 | Timer* m_timer; |
| 20 | |
| 21 | void SetUp() override { m_timer = new Timer; } |
| 22 | |
| 23 | void TearDown() override { delete m_timer; } |
| 24 | |
| 25 | void Reset() { m_timer->Reset(); } |
| 26 | }; |
| 27 | |
| 28 | /** |
| 29 | * Test if the Wait function works |
| 30 | */ |
| 31 | TEST_F(TimerTest, Wait) { |
| 32 | Reset(); |
| 33 | |
| 34 | double initialTime = m_timer->GetFPGATimestamp(); |
| 35 | |
| 36 | Wait(kWaitTime); |
| 37 | |
| 38 | double finalTime = m_timer->GetFPGATimestamp(); |
| 39 | |
| 40 | EXPECT_NEAR(kWaitTime, finalTime - initialTime, 0.001); |
| 41 | } |