blob: 5543938a8ab69726419de5dd09d303d3f831d5d1 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* 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
12static const double kWaitTime = 0.5;
13
14class 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 */
28TEST_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}