Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Sep 21, 2023
1 parent 3550a64 commit 35860dd
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions test/integration/Factory_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,10 @@ TEST(FactoryTest, Type)
/////////////////////////////////////////////////
TEST(FactoryTest, New)
{
// Correct call, using periods, fully qualified
// Preferred call, using periods, fully qualified
auto msg = Factory::New<Vector3d>("gz.msgs.Vector3d");

ASSERT_TRUE(msg.get() != nullptr);

msg->set_x(1.0);
msg->set_y(2.0);
msg->set_z(3.0);

auto msgFilled = Factory::New<Vector3d>(
"gz_msgs.Vector3d", "x: 1.0, y: 2.0, z: 3.0");
ASSERT_TRUE(msgFilled.get() != nullptr);

EXPECT_DOUBLE_EQ(msg->x(), msgFilled->x());
EXPECT_DOUBLE_EQ(msg->y(), msgFilled->y());
EXPECT_DOUBLE_EQ(msg->z(), msgFilled->z());

// Various other supported ways of specifying gz.msgs
msg = Factory::New<Vector3d>("gz_msgs.Vector3d");
EXPECT_TRUE(msg.get() != nullptr);
Expand All @@ -81,6 +68,33 @@ TEST(FactoryTest, New)
EXPECT_TRUE(msg.get() != nullptr);
}

/////////////////////////////////////////////////
TEST(FactoryTest, NewWithWellFormedData)
{
gz::msgs::Vector3d msg;
msg.set_x(1.0);
msg.set_y(2.0);
msg.set_z(3.0);

auto msgFilled = Factory::New<gz::msgs::Vector3d>(
"gz.msgs.Vector3d", "x: 1.0, y: 2.0, z: 3.0");
ASSERT_TRUE(nullptr != msgFilled);

EXPECT_DOUBLE_EQ(msg.x(), msgFilled->x());
EXPECT_DOUBLE_EQ(msg.y(), msgFilled->y());
EXPECT_DOUBLE_EQ(msg.z(), msgFilled->z());
}


/////////////////////////////////////////////////
TEST(FactoryTest, NewWithMalformedData)
{
/// Passing bad data to New results in a nullptr
auto msgFilled = Factory::New<gz::msgs::Vector3d>(
"gz.msgs.Vector3d", "x: 1.0, y: asdf, z: 3.0");
ASSERT_TRUE(nullptr == msgFilled);
}

/////////////////////////////////////////////////
TEST(FactoryTest, DeprecatedNonFullyQualified)
{
Expand Down

0 comments on commit 35860dd

Please sign in to comment.