Skip to content

Commit

Permalink
lestarch: fixing Fw::Time to allow comparisons across different time … (
Browse files Browse the repository at this point in the history
#803)

* lestarch: fixing Fw::Time to allow comparisons across different time bases

* lestarch: changing to proc time for zero time test
  • Loading branch information
LeStarch authored Jul 7, 2021
1 parent 4e6d413 commit 927d2f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Fw/Time/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion Fw/Time/Time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace Fw {
typedef enum {
LT = -1,
EQ = 0,
GT = 1
GT = 1,
INCOMPARABLE = 2
} Comparison;

//! \return time zero
Expand Down
7 changes: 7 additions & 0 deletions Fw/Time/test/ut/TimeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 927d2f0

Please sign in to comment.