From 42b869741cf4526ef5fbfea190da8cc84fd6e462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Fri, 11 Oct 2024 15:47:39 +0200 Subject: [PATCH] complete the test with other namespace strategies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Żak --- .../Tests/Frame/ROS2FrameComponentTest.cpp | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Gems/ROS2/Code/Tests/Frame/ROS2FrameComponentTest.cpp b/Gems/ROS2/Code/Tests/Frame/ROS2FrameComponentTest.cpp index c985cd596..8cbc1508f 100644 --- a/Gems/ROS2/Code/Tests/Frame/ROS2FrameComponentTest.cpp +++ b/Gems/ROS2/Code/Tests/Frame/ROS2FrameComponentTest.cpp @@ -136,7 +136,7 @@ namespace UnitTest } } - TEST_F(ROS2FrameComponentFixture, UpdateNamespace_Custom) + TEST_F(ROS2FrameComponentFixture, UpdateNamespace) { ROS2::ROS2FrameConfiguration config; @@ -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(); + newRootEntity.CreateComponent(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