Skip to content

Commit

Permalink
complete the test with other namespace strategies
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Żak <[email protected]>
  • Loading branch information
zakmat committed Oct 11, 2024
1 parent 6a47d0c commit 42b8697
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Gems/ROS2/Code/Tests/Frame/ROS2FrameComponentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace UnitTest
}
}

TEST_F(ROS2FrameComponentFixture, UpdateNamespace_Custom)
TEST_F(ROS2FrameComponentFixture, UpdateNamespace)
{
ROS2::ROS2FrameConfiguration config;

Expand All @@ -149,9 +149,34 @@ namespace UnitTest
entity.Init();
entity.Activate();

ASSERT_STREQ(frame->GetNamespace().c_str(), ("o3de_" + entityName).c_str());
auto rosifiedName = "o3de_" + entityName;
ASSERT_STREQ(frame->GetNamespace().c_str(), rosifiedName.c_str());

// Note that namespace parameter is only applied using Custom strategy
frame->UpdateNamespaceConfiguration("MyCustomNamespace", ROS2::NamespaceConfiguration::NamespaceStrategy::Custom);
EXPECT_STREQ(frame->GetNamespace().c_str(), "MyCustomNamespace");
// Empty strategy clears the namespace
frame->UpdateNamespaceConfiguration("MyCustomNamespace", ROS2::NamespaceConfiguration::NamespaceStrategy::Empty);
EXPECT_STREQ(frame->GetNamespace().c_str(), "");
// From Entity Name strategy uses rosified version of Entity Name
frame->UpdateNamespaceConfiguration("MyCustomNamespace", ROS2::NamespaceConfiguration::NamespaceStrategy::FromEntityName);
EXPECT_STREQ(frame->GetNamespace().c_str(), rosifiedName.c_str());
// Default strategy is like From Entity Name strategy if the entity is on top of hierarchy ...
frame->UpdateNamespaceConfiguration("MyCustomNamespace", ROS2::NamespaceConfiguration::NamespaceStrategy::Default);
EXPECT_STREQ(frame->GetNamespace().c_str(), rosifiedName.c_str());

AZ::Entity newRootEntity;
AZStd::string newRootName = "new_root";
newRootEntity.SetName(newRootName);
newRootEntity.CreateComponent<AzFramework::TransformComponent>();
newRootEntity.CreateComponent<ROS2::ROS2FrameComponent>(config);
newRootEntity.Init();
newRootEntity.Activate();
AZ::TransformBus::Event(entity.GetId(), &AZ::TransformBus::Events::SetParent, newRootEntity.GetId());

// If there is a parent Default strategy concatenates parent's namespace with rosified name
frame->UpdateNamespaceConfiguration("MyCustomNamespace", ROS2::NamespaceConfiguration::NamespaceStrategy::Default);
EXPECT_STREQ(frame->GetNamespace().c_str(), AZStd::string::format("%s/%s", newRootName.c_str(), rosifiedName.c_str()).c_str());
}

} // namespace UnitTest
Expand Down

0 comments on commit 42b8697

Please sign in to comment.