Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for the AnimationTime component #433

Merged
merged 2 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/ignition/gazebo/components/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ignition/msgs/actor.pb.h>

#include <chrono>
#include <ratio>
#include <string>

#include <sdf/Actor.hh>
Expand Down Expand Up @@ -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<std::chrono::milliseconds>(
_out << std::chrono::duration_cast<std::chrono::nanoseconds>(
_time).count();
return _out;
}
Expand All @@ -64,7 +65,7 @@ namespace serializers
{
int64_t time;
_in >> time;
_time = std::chrono::duration<int64_t, std::milli>(time);
_time = std::chrono::duration<int64_t, std::nano>(time);
return _in;
}
};
Expand Down
27 changes: 27 additions & 0 deletions test/integration/components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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("5000000000", ostr.str());

std::istringstream istr(ostr.str());
components::AnimationTime comp3;
comp3.Deserialize(istr);
EXPECT_EQ(comp1, comp3);
}

/////////////////////////////////////////////////
TEST_F(ComponentsTest, AirPressureSensor)
{
Expand Down