diff --git a/test/integration/user_commands.cc b/test/integration/user_commands.cc index a6e3f2f3400..300280bbe99 100644 --- a/test/integration/user_commands.cc +++ b/test/integration/user_commands.cc @@ -1046,6 +1046,95 @@ TEST_F(UserCommandsTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light)) spotLightComp->Data().Diffuse()); } +///////////////////////////////////////////////// +TEST_F(UserCommandsTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(MaterialColor)) +{ + // Start server + ServerConfig serverConfig; + const auto sdfFile = gz::common::joinPaths( + std::string(PROJECT_SOURCE_PATH), "test", "worlds", "material_color.sdf"); + serverConfig.SetSdfFile(sdfFile); + + Server server(serverConfig); + EXPECT_FALSE(server.Running()); + EXPECT_FALSE(*server.Running(0)); + + // Create a system just to get the ECM + EntityComponentManager *ecm{nullptr}; + test::Relay testSystem; + testSystem.OnPreUpdate([&](const sim::UpdateInfo &, + sim::EntityComponentManager &_ecm) + { + ecm = &_ecm; + }); + + server.AddSystem(testSystem.systemPtr); + + // Run server and check we have the ECM + EXPECT_EQ(nullptr, ecm); + server.Run(true, 1, false); + EXPECT_NE(nullptr, ecm); + + msgs::Boolean res; + transport::Node node; + bool result; + + // Camera Ball + auto CameraBallEntity = ecm->EntityByComponents( + components::Name("camera_ball")); + auto CameraBallEntityVisualLink = ecm->ChildrenByComponents( + components::Name("visual")); + auto visualEntity = + ecm->ChildrenByComponents(CameraBallEntityVisualLink[0], + components::Name("visual")); + EXPECT_NE(kNullEntity, visualEntity); + + // Check visual entity has not been edited yet - Initial values + auto visualComp = + ecm->Component(visualEntity); + ASSERT_NE(nullptr, visualComp); + EXPECT_EQ(math::Color(0.3f, 0.3f, 0.3f, 1.0f), + visualComp->Data().Ambient()); + EXPECT_EQ(math::Color(0.3f, 0.3f, 0.3f, 1.0f), + visualComp->Data().Diffuse()); + EXPECT_EQ(math::Color(0.3f, 0.3f, 0.3f, 1.0f), + visualComp->Data().Specular()); + EXPECT_EQ(math::Color(0.3f, 0.3f, 0.3f, 1.0f), + visualComp->Data().Emissive()); + + // Test material_color topic + const std::string materialColorTopic = "/world/material_color/material_color"; + + msgs::MaterialColor materialColorMsg; + materialColorMsg.set_name("spot"); + materialColorMsg.set_parent_name("camera_ball"); + gz::msgs::Set(materialColorMsg.mutable_ambient(), + gz::math::Color(1.0f, 1.0f, 1.0f, 1.0f)); + gz::msgs::Set(materialColorMsg.mutable_diffuse(), + gz::math::Color(1.0f, 1.0f, 1.0f, 1.0f)); + gz::msgs::Set(materialColorMsg.mutable_specular(), + gz::math::Color(1.0f, 1.0f, 1.0f, 1.0f)); + gz::msgs::Set(materialColorMsg.mutable_emissive(), + gz::math::Color(1.0f, 1.0f, 1.0f, 1.0f)); + + // Publish material color + auto pub = node.Advertise(materialColorTopic); + pub.Publish(materialColorMsg); + + server.Run(true, 100, false); + // Sleep for a small duration to allow Run thread to start + GZ_SLEEP_MS(10); + + EXPECT_EQ(math::Color(1.0f, 1.0f, 1.0f, 1.0f), + visualComp->Data().Ambient()); + EXPECT_EQ(math::Color(1.0f, 1.0f, 1.0f, 1.0f), + visualComp->Data().Diffuse()); + EXPECT_EQ(math::Color(1.0f, 1.0f, 1.0f, 1.0f), + visualComp->Data().Specular()); + EXPECT_EQ(math::Color(1.0f, 1.0f, 1.0f, 1.0f), + visualComp->Data().Emissive()); +} + ///////////////////////////////////////////////// TEST_F(UserCommandsTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(Physics)) { diff --git a/test/worlds/material_color.sdf b/test/worlds/material_color.sdf new file mode 100644 index 00000000000..f9443bdb40d --- /dev/null +++ b/test/worlds/material_color.sdf @@ -0,0 +1,59 @@ + + + + + 0.001 + 0 + + + + + + + ogre2 + + + 0 0.0 0.0 0 0 0 + + + + 1 0 1.3 0 0 0 + + 1.047 + + 320 + 240 + + + 0.1 + 100 + + + 1 + 30 + false + camera + + + + + 0.5 + + + + 0.3 0.3 0.3 1 + 0.3 0.3 0.3 1 + 0.3 0.3 0.3 1 + 0.3 0.3 0.3 1 + + + + + +