blob: faa6ada180327a57343378a4bdc2b9d413c5fa3d [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2014. 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 <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}