2014-06-02 17:34:10 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
|
2014-06-02 17:34:10 -04:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "Timer.h"
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "gtest/gtest.h"
|
2014-06-07 17:37:51 -04:00
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "TestBench.h"
|
|
|
|
|
|
2014-06-07 17:37:51 -04:00
|
|
|
static const double kWaitTime = 0.5;
|
|
|
|
|
|
|
|
|
|
class TimerTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2016-05-20 17:30:37 -07:00
|
|
|
Timer* m_timer;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void SetUp() override { m_timer = new Timer; }
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void TearDown() override { delete m_timer; }
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
void Reset() { m_timer->Reset(); }
|
2014-06-07 17:37:51 -04:00
|
|
|
};
|
2014-06-02 17:34:10 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-06-07 17:37:51 -04:00
|
|
|
* Test if the Wait function works
|
2014-06-02 17:34:10 -04:00
|
|
|
*/
|
2014-06-07 17:37:51 -04:00
|
|
|
TEST_F(TimerTest, Wait) {
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2014-06-07 17:37:51 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
double initialTime = m_timer->GetFPGATimestamp();
|
|
|
|
|
|
|
|
|
|
Wait(kWaitTime);
|
|
|
|
|
|
|
|
|
|
double finalTime = m_timer->GetFPGATimestamp();
|
|
|
|
|
|
|
|
|
|
EXPECT_NEAR(kWaitTime, finalTime - initialTime, 0.001);
|
|
|
|
|
}
|