From 927d2f0a21ecf648e36db8a4d846605a2b86d9e3 Mon Sep 17 00:00:00 2001 From: M Starch Date: Wed, 7 Jul 2021 10:45:05 -0700 Subject: [PATCH] =?UTF-8?q?lestarch:=20fixing=20Fw::Time=20to=20allow=20co?= =?UTF-8?q?mparisons=20across=20different=20time=20=E2=80=A6=20(#803)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lestarch: fixing Fw::Time to allow comparisons across different time bases * lestarch: changing to proc time for zero time test --- Fw/Time/Time.cpp | 8 ++++++-- Fw/Time/Time.hpp | 3 ++- Fw/Time/test/ut/TimeTest.cpp | 7 +++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Fw/Time/Time.cpp b/Fw/Time/Time.cpp index a8879b336b..48bdbeee44 100644 --- a/Fw/Time/Time.cpp +++ b/Fw/Time/Time.cpp @@ -161,10 +161,14 @@ namespace Fw { ) { #if FW_USE_TIME_BASE - FW_ASSERT(time1.getTimeBase() == time2.getTimeBase(), time1.getTimeBase(), time2.getTimeBase() ); + if (time1.getTimeBase() != time2.getTimeBase()) { + return INCOMPARABLE; + } #endif #if FW_USE_TIME_CONTEXT - FW_ASSERT(time1.getContext() == time2.getContext(), time1.getContext(), time2.getContext() ); + if (time1.getContext() != time2.getContext()) { + return INCOMPARABLE; + } #endif const U32 s1 = time1.getSeconds(); const U32 s2 = time2.getSeconds(); diff --git a/Fw/Time/Time.hpp b/Fw/Time/Time.hpp index b76eac7be2..ff70aa5592 100644 --- a/Fw/Time/Time.hpp +++ b/Fw/Time/Time.hpp @@ -46,7 +46,8 @@ namespace Fw { typedef enum { LT = -1, EQ = 0, - GT = 1 + GT = 1, + INCOMPARABLE = 2 } Comparison; //! \return time zero diff --git a/Fw/Time/test/ut/TimeTest.cpp b/Fw/Time/test/ut/TimeTest.cpp index 6d62d87087..87ffaa6311 100644 --- a/Fw/Time/test/ut/TimeTest.cpp +++ b/Fw/Time/test/ut/TimeTest.cpp @@ -89,6 +89,13 @@ TEST(TimeTestNominal,CopyTest) { } +TEST(TimeTestNominal,ZeroTimeEquality) { + Fw::Time time(TB_PROC_TIME,1,2); + ASSERT_NE(time, Fw::ZERO_TIME); + Fw::Time time2; + ASSERT_EQ(time2, Fw::ZERO_TIME); +} + int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();