Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2014-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 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 <Timer.h> |
| 9 | #include "gtest/gtest.h" |
| 10 | #include "TestBench.h" |
| 11 | |
| 12 | static const double kWaitTime = 0.5; |
| 13 | |
| 14 | class TimerTest : public testing::Test { |
| 15 | protected: |
| 16 | Timer *m_timer; |
| 17 | |
| 18 | virtual void SetUp() override { m_timer = new Timer; } |
| 19 | |
| 20 | virtual void TearDown() override { delete m_timer; } |
| 21 | |
| 22 | void Reset() { m_timer->Reset(); } |
| 23 | }; |
| 24 | |
| 25 | /** |
| 26 | * Test if the Wait function works |
| 27 | */ |
| 28 | TEST_F(TimerTest, Wait) { |
| 29 | Reset(); |
| 30 | |
| 31 | double initialTime = m_timer->GetFPGATimestamp(); |
| 32 | |
| 33 | Wait(kWaitTime); |
| 34 | |
| 35 | double finalTime = m_timer->GetFPGATimestamp(); |
| 36 | |
| 37 | EXPECT_NEAR(kWaitTime, finalTime - initialTime, 0.001); |
| 38 | } |