From 93e767a39d298123d53b19929a78b0c91927489c Mon Sep 17 00:00:00 2001 From: Ashton Larkin Date: Thu, 29 Oct 2020 12:58:33 -0400 Subject: [PATCH 1/2] added tests for AnimationTime component Signed-off-by: Ashton Larkin --- test/integration/components.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/integration/components.cc b/test/integration/components.cc index 2b593e7c54..c4004d565f 100644 --- a/test/integration/components.cc +++ b/test/integration/components.cc @@ -140,6 +140,33 @@ TEST_F(ComponentsTest, AnimationName) EXPECT_EQ("comp3", comp3.Data()); } +///////////////////////////////////////////////// +TEST_F(ComponentsTest, AnimationTime) +{ + auto start = std::chrono::steady_clock::now(); + auto end1 = start + std::chrono::seconds(5); + auto end2 = start + std::chrono::seconds(10); + + // Create components + auto comp1 = components::AnimationTime(end1 - start); + auto comp2 = components::AnimationTime(end2 - start); + + // Equality operators + EXPECT_NE(comp1, comp2); + EXPECT_FALSE(comp1 == comp2); + EXPECT_TRUE(comp1 != comp2); + + // Stream operators + std::ostringstream ostr; + comp1.Serialize(ostr); + EXPECT_EQ("5000", ostr.str()); + + std::istringstream istr(ostr.str()); + components::AnimationTime comp3; + comp3.Deserialize(istr); + EXPECT_EQ(comp1, comp3); +} + ///////////////////////////////////////////////// TEST_F(ComponentsTest, AirPressureSensor) { From 02ad2db75ee0b6600d7d88c436c156e24b91e8e9 Mon Sep 17 00:00:00 2001 From: Ashton Larkin Date: Mon, 2 Nov 2020 11:10:12 -0500 Subject: [PATCH 2/2] using nanoseconds for serialization instead of milliseconds Signed-off-by: Ashton Larkin --- include/ignition/gazebo/components/Actor.hh | 5 +++-- test/integration/components.cc | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/ignition/gazebo/components/Actor.hh b/include/ignition/gazebo/components/Actor.hh index 44d8bbc19c..024aa64c42 100644 --- a/include/ignition/gazebo/components/Actor.hh +++ b/include/ignition/gazebo/components/Actor.hh @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -50,7 +51,7 @@ namespace serializers public: static std::ostream &Serialize(std::ostream &_out, const std::chrono::steady_clock::duration &_time) { - _out << std::chrono::duration_cast( + _out << std::chrono::duration_cast( _time).count(); return _out; } @@ -64,7 +65,7 @@ namespace serializers { int64_t time; _in >> time; - _time = std::chrono::duration(time); + _time = std::chrono::duration(time); return _in; } }; diff --git a/test/integration/components.cc b/test/integration/components.cc index c4004d565f..00649aa031 100644 --- a/test/integration/components.cc +++ b/test/integration/components.cc @@ -159,7 +159,7 @@ TEST_F(ComponentsTest, AnimationTime) // Stream operators std::ostringstream ostr; comp1.Serialize(ostr); - EXPECT_EQ("5000", ostr.str()); + EXPECT_EQ("5000000000", ostr.str()); std::istringstream istr(ostr.str()); components::AnimationTime comp3;