mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
Make Fw::TimeInterval an FPP Struct (#3834)
* Update Fw/Time/TimeInterval to use an FPP struct * Spelling; add TimeInterval UTs; remove UT-only stdout << method which is autocoded now for TimeInterval * Add TimeInterval sub tests * Re-factor tests into TestMain/Tester format files, separating Time and TimeInterval * Add TimeIntervalTester as friend, for consistency * Address build errors * Update fpp comments * Update TimeInterval to use FPP struct as underlying member variable type, only * Upate CMake for build errors
This commit is contained in:
parent
e3376dca9e
commit
ebaf92b2c6
2
.github/actions/spelling/expect.txt
vendored
2
.github/actions/spelling/expect.txt
vendored
@ -258,8 +258,10 @@ gcov
|
||||
gdiplus
|
||||
GENHUB
|
||||
getfooter
|
||||
getseconds
|
||||
getstatements
|
||||
gettime
|
||||
getuseconds
|
||||
getty
|
||||
ghprb
|
||||
gitmodules
|
||||
|
||||
@ -13,7 +13,9 @@ set(SOURCE_FILES
|
||||
register_fprime_module()
|
||||
### UTs ###
|
||||
set(UT_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TimeTest.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TimeTestMain.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TimeTester.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TimeIntervalTester.cpp"
|
||||
)
|
||||
set(UT_MOD_DEPS
|
||||
"${FPRIME_FRAMEWORK_PATH}/Fw/Time"
|
||||
|
||||
@ -1,17 +1,23 @@
|
||||
module Fw {
|
||||
|
||||
|
||||
type Time
|
||||
|
||||
@ Time port
|
||||
port Time(
|
||||
ref $time: Fw.Time @< Reference to Time object
|
||||
)
|
||||
ref $time: Fw.Time @< Reference to Time object
|
||||
)
|
||||
|
||||
@ Data structure for Time Interval
|
||||
struct TimeIntervalValue {
|
||||
seconds: U32 @< seconds portion of TimeInterval
|
||||
useconds: U32 @< microseconds portion of TimeInterval
|
||||
}
|
||||
|
||||
type TimeInterval
|
||||
|
||||
@ Time interval port
|
||||
port TimeInterval(
|
||||
ref timeInterval: Fw.TimeInterval @< Reference to TimeInterval object
|
||||
)
|
||||
ref timeInterval: Fw.TimeInterval @< Reference to TimeInterval object
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
namespace Fw {
|
||||
TimeInterval::TimeInterval(const TimeInterval& other) : Serializable() {
|
||||
this->set(other.m_seconds,other.m_useconds);
|
||||
this->m_val = other.m_val;
|
||||
}
|
||||
|
||||
TimeInterval::TimeInterval(U32 seconds, U32 useconds) : Serializable() {
|
||||
@ -11,70 +11,58 @@ namespace Fw {
|
||||
}
|
||||
|
||||
void TimeInterval::set(U32 seconds, U32 useconds) {
|
||||
this->m_seconds = seconds;
|
||||
this->m_useconds = useconds;
|
||||
this->m_val.set(seconds, useconds);
|
||||
}
|
||||
|
||||
TimeInterval& TimeInterval::operator=(const TimeInterval& other) {
|
||||
this->m_useconds = other.m_useconds;
|
||||
this->m_seconds = other.m_seconds;
|
||||
|
||||
if (this != &other) {
|
||||
this->m_val = other.m_val;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool TimeInterval::operator==(const TimeInterval& other) const {
|
||||
return (TimeInterval::compare(*this,other) == EQ);
|
||||
return (TimeInterval::compare(*this, other) == EQ);
|
||||
}
|
||||
|
||||
bool TimeInterval::operator!=(const TimeInterval& other) const {
|
||||
return (TimeInterval::compare(*this,other) != EQ);
|
||||
return (TimeInterval::compare(*this, other) != EQ);
|
||||
}
|
||||
|
||||
bool TimeInterval::operator>(const TimeInterval& other) const {
|
||||
return (TimeInterval::compare(*this,other) == GT);
|
||||
return (TimeInterval::compare(*this, other) == GT);
|
||||
}
|
||||
|
||||
bool TimeInterval::operator<(const TimeInterval& other) const {
|
||||
return (TimeInterval::compare(*this,other) == LT);
|
||||
return (TimeInterval::compare(*this, other) == LT);
|
||||
}
|
||||
|
||||
bool TimeInterval::operator>=(const TimeInterval& other) const {
|
||||
TimeInterval::Comparison c = TimeInterval::compare(*this,other);
|
||||
TimeInterval::Comparison c = TimeInterval::compare(*this, other);
|
||||
return ((GT == c) or (EQ == c));
|
||||
}
|
||||
|
||||
bool TimeInterval::operator<=(const TimeInterval& other) const {
|
||||
TimeInterval::Comparison c = TimeInterval::compare(*this,other);
|
||||
TimeInterval::Comparison c = TimeInterval::compare(*this, other);
|
||||
return ((LT == c) or (EQ == c));
|
||||
}
|
||||
|
||||
SerializeStatus TimeInterval::serialize(SerializeBufferBase& buffer) const {
|
||||
// serialize members
|
||||
SerializeStatus stat = Fw::FW_SERIALIZE_OK;
|
||||
stat = buffer.serialize(this->m_seconds);
|
||||
if (stat != FW_SERIALIZE_OK) {
|
||||
return stat;
|
||||
}
|
||||
return buffer.serialize(this->m_useconds);
|
||||
// Use TimeIntervalValue's built-in serialization
|
||||
return this->m_val.serialize(buffer);
|
||||
}
|
||||
|
||||
SerializeStatus TimeInterval::deserialize(SerializeBufferBase& buffer) {
|
||||
|
||||
SerializeStatus stat = Fw::FW_SERIALIZE_OK;
|
||||
stat = buffer.deserialize(this->m_seconds);
|
||||
if (stat != FW_SERIALIZE_OK) {
|
||||
return stat;
|
||||
}
|
||||
|
||||
return buffer.deserialize(this->m_useconds);
|
||||
// Use TimeIntervalValue's built-in deserialization
|
||||
return this->m_val.deserialize(buffer);
|
||||
}
|
||||
|
||||
U32 TimeInterval::getSeconds() const {
|
||||
return this->m_seconds;
|
||||
return this->m_val.getseconds();
|
||||
}
|
||||
|
||||
U32 TimeInterval::getUSeconds() const {
|
||||
return this->m_useconds;
|
||||
return this->m_val.getuseconds();
|
||||
}
|
||||
|
||||
TimeInterval::Comparison TimeInterval ::
|
||||
@ -139,13 +127,14 @@ namespace Fw {
|
||||
}
|
||||
|
||||
void TimeInterval::add(U32 seconds, U32 useconds) {
|
||||
this->m_seconds += seconds;
|
||||
this->m_useconds += useconds;
|
||||
FW_ASSERT(this->m_useconds < 1999999, static_cast<FwAssertArgType>(this->m_useconds));
|
||||
if (this->m_useconds >= 1000000) {
|
||||
this->m_seconds += 1;
|
||||
this->m_useconds -= 1000000;
|
||||
U32 newSeconds = this->m_val.getseconds() + seconds;
|
||||
U32 newUSeconds = this->m_val.getuseconds() + useconds;
|
||||
FW_ASSERT(newUSeconds < 1999999, static_cast<FwAssertArgType>(newUSeconds));
|
||||
if (newUSeconds >= 1000000) {
|
||||
newSeconds += 1;
|
||||
newUSeconds -= 1000000;
|
||||
}
|
||||
this->m_val.set(newSeconds, newUSeconds);
|
||||
}
|
||||
|
||||
#ifdef BUILD_UT
|
||||
@ -156,4 +145,4 @@ namespace Fw {
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@
|
||||
#include <Fw/FPrimeBasicTypes.hpp>
|
||||
#include <Fw/Types/Assert.hpp>
|
||||
#include <Fw/Types/Serializable.hpp>
|
||||
#include <Fw/Time/TimeIntervalValueSerializableAc.hpp>
|
||||
|
||||
//!
|
||||
//! @class TimeInterval
|
||||
@ -81,10 +82,9 @@ namespace Fw {
|
||||
friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val);
|
||||
#endif
|
||||
private:
|
||||
U32 m_seconds; // !< seconds portion of TimeInterval
|
||||
U32 m_useconds; // !< microseconds portion of TimeInterval
|
||||
TimeIntervalValue m_val; // !< TimeInterval value
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
128
Fw/Time/test/ut/TimeIntervalTester.cpp
Normal file
128
Fw/Time/test/ut/TimeIntervalTester.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
#include "TimeIntervalTester.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace Fw {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Construction and destruction
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
TimeIntervalTester::TimeIntervalTester() {
|
||||
}
|
||||
|
||||
TimeIntervalTester::~TimeIntervalTester() {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void TimeIntervalTester::test_TimeIntervalInstantiateTest() {
|
||||
Fw::TimeInterval time(1,2);
|
||||
ASSERT_EQ(time.getSeconds(), 1);
|
||||
ASSERT_EQ(time.getUSeconds(), 2);
|
||||
std::cout << time << std::endl;
|
||||
|
||||
Fw::TimeInterval time2(time);
|
||||
ASSERT_EQ(time.getSeconds(), 1);
|
||||
ASSERT_EQ(time.getUSeconds(), 2);
|
||||
std::cout << time2 << std::endl;
|
||||
}
|
||||
|
||||
void TimeIntervalTester::test_TimeIntervalComparisonTest() {
|
||||
Fw::TimeInterval t1(1, 0);
|
||||
Fw::TimeInterval t2(1, 0);
|
||||
Fw::TimeInterval t3(2, 0);
|
||||
Fw::TimeInterval t4(1, 500000);
|
||||
|
||||
// Equality operators
|
||||
ASSERT_TRUE(t1 == t2);
|
||||
ASSERT_FALSE(t1 == t3);
|
||||
ASSERT_FALSE(t1 == t4);
|
||||
|
||||
// Inequality operators
|
||||
ASSERT_FALSE(t1 != t2);
|
||||
ASSERT_TRUE(t1 != t3);
|
||||
ASSERT_TRUE(t1 != t4);
|
||||
|
||||
// Greater than operators
|
||||
ASSERT_TRUE(t3 > t1);
|
||||
ASSERT_FALSE(t1 > t3);
|
||||
ASSERT_TRUE(t4 > t1);
|
||||
|
||||
// Less than operators
|
||||
ASSERT_TRUE(t1 < t3);
|
||||
ASSERT_FALSE(t3 < t1);
|
||||
ASSERT_TRUE(t1 < t4);
|
||||
|
||||
// Greater than or equal operators
|
||||
ASSERT_TRUE(t1 >= t2);
|
||||
ASSERT_TRUE(t3 >= t1);
|
||||
ASSERT_FALSE(t1 >= t3);
|
||||
|
||||
// Less than or equal operators
|
||||
ASSERT_TRUE(t1 <= t2);
|
||||
ASSERT_TRUE(t1 <= t3);
|
||||
ASSERT_FALSE(t3 <= t1);
|
||||
}
|
||||
|
||||
void TimeIntervalTester::test_TimeIntervalAdditionTest() {
|
||||
Fw::TimeInterval t1(1, 500000);
|
||||
Fw::TimeInterval t2(2, 600000);
|
||||
|
||||
// Test instance add method
|
||||
t1.add(3, 700000);
|
||||
// 1 + 3 = 4s, 500000us + 700000us = 1s + 200000us -> 5s, 200000us
|
||||
ASSERT_EQ(t1.getSeconds(), 5);
|
||||
ASSERT_EQ(t1.getUSeconds(), 200000);
|
||||
|
||||
// Test static add method
|
||||
Fw::TimeInterval result = Fw::TimeInterval::add(t1, t2);
|
||||
// 5 + 2 = 7s, 200000us + 600000us = 800000us
|
||||
ASSERT_EQ(result.getSeconds(), 7);
|
||||
ASSERT_EQ(result.getUSeconds(), 800000);
|
||||
}
|
||||
|
||||
void TimeIntervalTester::test_TimeIntervalCompareStaticTest() {
|
||||
Fw::TimeInterval t1(1, 0);
|
||||
Fw::TimeInterval t2(1, 0);
|
||||
Fw::TimeInterval t3(2, 0);
|
||||
Fw::TimeInterval t4(1, 500000);
|
||||
|
||||
// Test static compare method
|
||||
ASSERT_EQ(Fw::TimeInterval::compare(t1, t2), Fw::TimeInterval::EQ);
|
||||
ASSERT_EQ(Fw::TimeInterval::compare(t1, t3), Fw::TimeInterval::LT);
|
||||
ASSERT_EQ(Fw::TimeInterval::compare(t3, t1), Fw::TimeInterval::GT);
|
||||
ASSERT_EQ(Fw::TimeInterval::compare(t1, t4), Fw::TimeInterval::LT);
|
||||
ASSERT_EQ(Fw::TimeInterval::compare(t4, t1), Fw::TimeInterval::GT);
|
||||
}
|
||||
|
||||
void TimeIntervalTester::test_TimeIntervalSubtractionTest() {
|
||||
Fw::TimeInterval t1(5, 500000);
|
||||
Fw::TimeInterval t2(2, 300000);
|
||||
Fw::TimeInterval result1 = Fw::TimeInterval::sub(t1, t2);
|
||||
// 5s - 2s = 3s, 500000us - 300000us = 200000us
|
||||
ASSERT_EQ(result1.getSeconds(), 3);
|
||||
ASSERT_EQ(result1.getUSeconds(), 200000);
|
||||
|
||||
// should be the same due to absolute value
|
||||
Fw::TimeInterval result2 = Fw::TimeInterval::sub(t2, t1);
|
||||
ASSERT_EQ(result2.getSeconds(), 3);
|
||||
ASSERT_EQ(result2.getUSeconds(), 200000);
|
||||
|
||||
Fw::TimeInterval t3(5, 200000);
|
||||
Fw::TimeInterval t4(2, 500000);
|
||||
Fw::TimeInterval result3 = Fw::TimeInterval::sub(t3, t4);
|
||||
// 5s - 2s = 3s, 200000us - 500000us requires borrow
|
||||
// So it's 2s + 700000us
|
||||
ASSERT_EQ(result3.getSeconds(), 2);
|
||||
ASSERT_EQ(result3.getUSeconds(), 700000);
|
||||
|
||||
Fw::TimeInterval t5(3, 400000);
|
||||
Fw::TimeInterval t6(3, 400000);
|
||||
Fw::TimeInterval result4 = Fw::TimeInterval::sub(t5, t6);
|
||||
ASSERT_EQ(result4.getSeconds(), 0);
|
||||
ASSERT_EQ(result4.getUSeconds(), 0);
|
||||
}
|
||||
|
||||
} // namespace Fw
|
||||
27
Fw/Time/test/ut/TimeIntervalTester.hpp
Normal file
27
Fw/Time/test/ut/TimeIntervalTester.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef FW_TIME_INTERVAL_TESTER_HPP
|
||||
#define FW_TIME_INTERVAL_TESTER_HPP
|
||||
|
||||
#include <Fw/Time/TimeInterval.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Fw {
|
||||
class TimeIntervalTester {
|
||||
public:
|
||||
// ----------------------------------------------------------------------
|
||||
// Construction and destruction
|
||||
// ----------------------------------------------------------------------
|
||||
TimeIntervalTester();
|
||||
~TimeIntervalTester();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------
|
||||
void test_TimeIntervalInstantiateTest();
|
||||
void test_TimeIntervalComparisonTest();
|
||||
void test_TimeIntervalCompareStaticTest();
|
||||
void test_TimeIntervalAdditionTest();
|
||||
void test_TimeIntervalSubtractionTest();
|
||||
};
|
||||
} // namespace Fw
|
||||
|
||||
#endif // FW_TIME_INTERVAL_TESTER_HPP
|
||||
@ -1,164 +0,0 @@
|
||||
/*
|
||||
* TimeTest.cpp
|
||||
*
|
||||
* Created on: Apr 22, 2016
|
||||
* Author: tcanham
|
||||
*/
|
||||
|
||||
#include <Fw/Time/Time.hpp>
|
||||
#include <iostream>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
namespace Fw {
|
||||
class TimeTester{
|
||||
|
||||
public:
|
||||
// ----------------------------------------------------------------------
|
||||
// Construction and destruction
|
||||
// ----------------------------------------------------------------------
|
||||
TimeTester()
|
||||
{
|
||||
}
|
||||
|
||||
~TimeTester()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------
|
||||
void test_MathTest()
|
||||
{
|
||||
Fw::Time time1;
|
||||
Fw::Time time2;
|
||||
|
||||
// Comparison
|
||||
time1.set(1000,1000);
|
||||
time2.set(1000,1000);
|
||||
ASSERT_TRUE(time1 == time2);
|
||||
ASSERT_TRUE(time1 >= time2);
|
||||
ASSERT_TRUE(time1 <= time2);
|
||||
|
||||
time1.set(1000,1000);
|
||||
time2.set(2000,1000);
|
||||
ASSERT_TRUE(time1 != time2);
|
||||
ASSERT_TRUE(time1 < time2);
|
||||
ASSERT_TRUE(time1 <= time2);
|
||||
|
||||
time1.set(2000,1000);
|
||||
time2.set(1000,1000);
|
||||
ASSERT_TRUE(time1 > time2);
|
||||
ASSERT_TRUE(time1 >= time2);
|
||||
|
||||
// Addition
|
||||
time1.set(1000,1000);
|
||||
time2.set(4000,2000);
|
||||
Fw::Time time_sum = Fw::Time::add(time1,time2);
|
||||
ASSERT_EQ(time_sum.m_seconds,5000);
|
||||
ASSERT_EQ(time_sum.m_useconds,3000);
|
||||
|
||||
// Normal subtraction
|
||||
time1.set(1000,1000);
|
||||
time2.set(4000,2000);
|
||||
Fw::Time time3 = Fw::Time::sub(time2,time1);
|
||||
ASSERT_EQ(time3.m_timeBase,TB_NONE);
|
||||
ASSERT_EQ(time3.m_timeContext,0);
|
||||
ASSERT_EQ(time3.m_seconds,3000);
|
||||
ASSERT_EQ(time3.m_useconds,1000);
|
||||
|
||||
// Rollover subtraction
|
||||
time1.set(1,999999);
|
||||
time2.set(2,000001);
|
||||
time3 = Fw::Time::sub(time2,time1);
|
||||
ASSERT_EQ(time3.m_timeBase,TB_NONE);
|
||||
ASSERT_EQ(time3.m_timeContext,0);
|
||||
EXPECT_EQ(time3.m_seconds,0);
|
||||
EXPECT_EQ(time3.m_useconds,2);
|
||||
}
|
||||
|
||||
void test_InstantiateTest()
|
||||
{
|
||||
Fw::Time time(TB_NONE,1,2);
|
||||
ASSERT_EQ(time.m_timeBase,TB_NONE);
|
||||
ASSERT_EQ(time.m_timeContext,0);
|
||||
ASSERT_EQ(time.m_seconds,1);
|
||||
ASSERT_EQ(time.m_useconds,2);
|
||||
std::cout << time << std::endl;
|
||||
}
|
||||
|
||||
void test_CopyTest()
|
||||
{
|
||||
Fw::Time time0;
|
||||
|
||||
// make time that's guaranteed to be different from default
|
||||
Fw::Time time1(
|
||||
(time0.getTimeBase() != TB_NONE ? TB_NONE : TB_PROC_TIME),
|
||||
static_cast<FwTimeContextStoreType>(time0.getContext()+1),
|
||||
time0.getSeconds()+1,
|
||||
time0.getUSeconds()+1
|
||||
);
|
||||
|
||||
// copy construction
|
||||
Fw::Time time2 = time1;
|
||||
ASSERT_EQ(time1.getSeconds(), time2.getSeconds());
|
||||
ASSERT_EQ(time1.getUSeconds(), time2.getUSeconds());
|
||||
ASSERT_EQ(time1.getTimeBase(), time2.getTimeBase());
|
||||
ASSERT_EQ(time1.getContext(), time2.getContext());
|
||||
|
||||
// assignment operator
|
||||
Fw::Time time3;
|
||||
time3 = time1;
|
||||
ASSERT_EQ(time1.getSeconds(), time3.getSeconds());
|
||||
ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds());
|
||||
ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase());
|
||||
ASSERT_EQ(time1.getContext(), time3.getContext());
|
||||
|
||||
// set method
|
||||
Fw::Time time4;
|
||||
time4.set(time1.getTimeBase(), time1.getContext(), time1.getSeconds(), time1.getUSeconds());
|
||||
ASSERT_EQ(time1.getSeconds(), time3.getSeconds());
|
||||
ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds());
|
||||
ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase());
|
||||
ASSERT_EQ(time1.getContext(), time3.getContext());
|
||||
|
||||
}
|
||||
|
||||
void test_ZeroTimeEquality()
|
||||
{
|
||||
Fw::Time time(TB_PROC_TIME,1,2);
|
||||
ASSERT_NE(time, Fw::ZERO_TIME);
|
||||
Fw::Time time2;
|
||||
ASSERT_EQ(time2, Fw::ZERO_TIME);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
TEST(TimeTestNominal,InstantiateTest) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_InstantiateTest();
|
||||
}
|
||||
|
||||
TEST(TimeTestNominal,MathTest) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_MathTest();
|
||||
|
||||
}
|
||||
|
||||
TEST(TimeTestNominal,CopyTest) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_CopyTest();
|
||||
}
|
||||
|
||||
TEST(TimeTestNominal,ZeroTimeEquality) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_ZeroTimeEquality();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
61
Fw/Time/test/ut/TimeTestMain.cpp
Normal file
61
Fw/Time/test/ut/TimeTestMain.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* TimeTest.cpp
|
||||
*
|
||||
* Created on: Apr 22, 2016
|
||||
* Author: tcanham
|
||||
*/
|
||||
|
||||
#include "TimeTester.hpp"
|
||||
#include "TimeIntervalTester.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// Time tests
|
||||
TEST(TimeTestNominal, InstantiateTest) {
|
||||
Fw::TimeTester tester;
|
||||
}
|
||||
|
||||
TEST(TimeTestNominal, MathTest) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_MathTest();
|
||||
}
|
||||
|
||||
TEST(TimeTestNominal, CopyTest) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_CopyTest();
|
||||
}
|
||||
|
||||
TEST(TimeTestNominal, ZeroTimeEquality) {
|
||||
Fw::TimeTester tester;
|
||||
tester.test_ZeroTimeEquality();
|
||||
}
|
||||
|
||||
// TimeInterval tests
|
||||
TEST(TimeIntervalTestNominal, test_TimeIntervalInstantiateTest) {
|
||||
Fw::TimeIntervalTester tester;
|
||||
tester.test_TimeIntervalInstantiateTest();
|
||||
}
|
||||
|
||||
TEST(TimeIntervalTestNominal, test_TimeIntervalComparisonTest) {
|
||||
Fw::TimeIntervalTester tester;
|
||||
tester.test_TimeIntervalComparisonTest();
|
||||
}
|
||||
|
||||
TEST(TimeIntervalTestNominal, test_TimeIntervalCompareStaticTest) {
|
||||
Fw::TimeIntervalTester tester;
|
||||
tester.test_TimeIntervalCompareStaticTest();
|
||||
}
|
||||
|
||||
TEST(TimeIntervalTestNominal, test_TimeIntervalAdditionTest) {
|
||||
Fw::TimeIntervalTester tester;
|
||||
tester.test_TimeIntervalAdditionTest();
|
||||
}
|
||||
|
||||
TEST(TimeIntervalTestNominal, test_TimeIntervalSubtractionTest) {
|
||||
Fw::TimeIntervalTester tester;
|
||||
tester.test_TimeIntervalSubtractionTest();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
119
Fw/Time/test/ut/TimeTester.cpp
Normal file
119
Fw/Time/test/ut/TimeTester.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include "TimeTester.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace Fw {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Construction and destruction
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
TimeTester::TimeTester() {
|
||||
}
|
||||
|
||||
TimeTester::~TimeTester() {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void TimeTester::test_InstantiateTest() {
|
||||
Fw::Time time(TB_NONE,1,2);
|
||||
ASSERT_EQ(time.m_timeBase,TB_NONE);
|
||||
ASSERT_EQ(time.m_timeContext,0);
|
||||
ASSERT_EQ(time.m_seconds,1);
|
||||
ASSERT_EQ(time.m_useconds,2);
|
||||
std::cout << time << std::endl;
|
||||
}
|
||||
|
||||
void TimeTester::test_MathTest() {
|
||||
Fw::Time time1;
|
||||
Fw::Time time2;
|
||||
|
||||
// Comparison
|
||||
time1.set(1000,1000);
|
||||
time2.set(1000,1000);
|
||||
ASSERT_TRUE(time1 == time2);
|
||||
ASSERT_TRUE(time1 >= time2);
|
||||
ASSERT_TRUE(time1 <= time2);
|
||||
|
||||
time1.set(1000,1000);
|
||||
time2.set(2000,1000);
|
||||
ASSERT_TRUE(time1 != time2);
|
||||
ASSERT_TRUE(time1 < time2);
|
||||
ASSERT_TRUE(time1 <= time2);
|
||||
|
||||
time1.set(2000,1000);
|
||||
time2.set(1000,1000);
|
||||
ASSERT_TRUE(time1 > time2);
|
||||
ASSERT_TRUE(time1 >= time2);
|
||||
|
||||
// Addition
|
||||
time1.set(1000,1000);
|
||||
time2.set(4000,2000);
|
||||
Fw::Time time_sum = Fw::Time::add(time1,time2);
|
||||
ASSERT_EQ(time_sum.m_seconds,5000);
|
||||
ASSERT_EQ(time_sum.m_useconds,3000);
|
||||
|
||||
// Normal subtraction
|
||||
time1.set(1000,1000);
|
||||
time2.set(4000,2000);
|
||||
Fw::Time time3 = Fw::Time::sub(time2,time1);
|
||||
ASSERT_EQ(time3.m_timeBase,TB_NONE);
|
||||
ASSERT_EQ(time3.m_timeContext,0);
|
||||
ASSERT_EQ(time3.m_seconds,3000);
|
||||
ASSERT_EQ(time3.m_useconds,1000);
|
||||
|
||||
// Rollover subtraction
|
||||
time1.set(1,999999);
|
||||
time2.set(2,000001);
|
||||
time3 = Fw::Time::sub(time2,time1);
|
||||
ASSERT_EQ(time3.m_timeBase,TB_NONE);
|
||||
ASSERT_EQ(time3.m_timeContext,0);
|
||||
EXPECT_EQ(time3.m_seconds,0);
|
||||
EXPECT_EQ(time3.m_useconds,2);
|
||||
}
|
||||
|
||||
void TimeTester::test_CopyTest() {
|
||||
Fw::Time time0;
|
||||
|
||||
// make time that's guaranteed to be different from default
|
||||
Fw::Time time1(
|
||||
(time0.getTimeBase() != TB_NONE ? TB_NONE : TB_PROC_TIME),
|
||||
static_cast<FwTimeContextStoreType>(time0.getContext()+1),
|
||||
time0.getSeconds()+1,
|
||||
time0.getUSeconds()+1
|
||||
);
|
||||
|
||||
// copy construction
|
||||
Fw::Time time2 = time1;
|
||||
ASSERT_EQ(time1.getSeconds(), time2.getSeconds());
|
||||
ASSERT_EQ(time1.getUSeconds(), time2.getUSeconds());
|
||||
ASSERT_EQ(time1.getTimeBase(), time2.getTimeBase());
|
||||
ASSERT_EQ(time1.getContext(), time2.getContext());
|
||||
|
||||
// assignment operator
|
||||
Fw::Time time3;
|
||||
time3 = time1;
|
||||
ASSERT_EQ(time1.getSeconds(), time3.getSeconds());
|
||||
ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds());
|
||||
ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase());
|
||||
ASSERT_EQ(time1.getContext(), time3.getContext());
|
||||
|
||||
// set method
|
||||
Fw::Time time4;
|
||||
time4.set(time1.getTimeBase(), time1.getContext(), time1.getSeconds(), time1.getUSeconds());
|
||||
ASSERT_EQ(time1.getSeconds(), time3.getSeconds());
|
||||
ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds());
|
||||
ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase());
|
||||
ASSERT_EQ(time1.getContext(), time3.getContext());
|
||||
}
|
||||
|
||||
void TimeTester::test_ZeroTimeEquality() {
|
||||
Fw::Time time(TB_PROC_TIME,1,2);
|
||||
ASSERT_NE(time, Fw::ZERO_TIME);
|
||||
Fw::Time time2;
|
||||
ASSERT_EQ(time2, Fw::ZERO_TIME);
|
||||
}
|
||||
|
||||
} // namespace Fw
|
||||
26
Fw/Time/test/ut/TimeTester.hpp
Normal file
26
Fw/Time/test/ut/TimeTester.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef FW_TIME_TESTER_HPP
|
||||
#define FW_TIME_TESTER_HPP
|
||||
|
||||
#include <Fw/Time/Time.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Fw {
|
||||
class TimeTester {
|
||||
public:
|
||||
// ----------------------------------------------------------------------
|
||||
// Construction and destruction
|
||||
// ----------------------------------------------------------------------
|
||||
TimeTester();
|
||||
~TimeTester();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------
|
||||
void test_InstantiateTest();
|
||||
void test_MathTest();
|
||||
void test_CopyTest();
|
||||
void test_ZeroTimeEquality();
|
||||
};
|
||||
} // namespace Fw
|
||||
|
||||
#endif // FW_TIME_TESTER_HPP
|
||||
@ -37,6 +37,7 @@ function(add_named_os_module NAMES)
|
||||
HEADERS
|
||||
${HEADER_INPUTS}
|
||||
DEPENDS
|
||||
Fw_Time
|
||||
Fw_Types ${ARGN}
|
||||
)
|
||||
fprime_target_dependencies(Os PUBLIC "${OS_MODULE_NAME}")
|
||||
@ -88,6 +89,7 @@ function(add_fprime_supplied_os_module NAMES SUFFIX)
|
||||
HEADERS
|
||||
${HEADER_INPUTS}
|
||||
DEPENDS
|
||||
Fw_Time
|
||||
Fw_Types
|
||||
"Os_${FIRST_ITEM}"
|
||||
${ARGN}
|
||||
@ -99,6 +101,7 @@ function(add_fprime_supplied_os_module NAMES SUFFIX)
|
||||
IMPLEMENTS
|
||||
"Os_${FIRST_ITEM}"
|
||||
DEPENDS
|
||||
Fw_Time
|
||||
Fw_Types
|
||||
"${OS_MODULE_NAME}_Implementation"
|
||||
)
|
||||
@ -124,6 +127,7 @@ register_fprime_module(
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ValidatedFile.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Os.hpp"
|
||||
DEPENDS
|
||||
Fw_Time
|
||||
Fw_Types
|
||||
)
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ register_fprime_module(
|
||||
HEADERS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/error.hpp"
|
||||
DEPENDS
|
||||
Fw_Time
|
||||
Fw_Types
|
||||
)
|
||||
|
||||
|
||||
@ -6,5 +6,6 @@ register_fprime_implementation(
|
||||
"${CMAKE_CURRENT_LIST_DIR}/RawTimeTester.cpp"
|
||||
DEPENDS
|
||||
Fw_Types
|
||||
Fw_Time
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user