Skip to content

Commit

Permalink
Add UserCommands MaterialColor test.
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
  • Loading branch information
bperseghetti committed Jan 16, 2024
1 parent 7cc1d95 commit f05004a
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/integration/user_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<components::VisualCmd>(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<msgs::MaterialColor>(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))
{
Expand Down
59 changes: 59 additions & 0 deletions test/worlds/material_color.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<world name="material_color">
<physics name="1ms" type="ode">
<max_step_size>0.001</max_step_size>
<real_time_factor>0</real_time_factor>
</physics>
<plugin
filename="gz-sim-scene-broadcaster-system"
name="gz::sim::systems::SceneBroadcaster">
</plugin>
<plugin
filename="gz-sim-user-commands-system"
name="gz::sim::systems::UserCommands">
</plugin>
<plugin
filename="gz-sim-sensors-system"
name="gz::sim::systems::Sensors">
<render_engine>ogre2</render_engine>
</plugin>
<model name="camera_ball">
<pose>0 0.0 0.0 0 0 0</pose>
<link name="sphere">
<!-- Added a render sensor to trigger RenderUtil:Update -->
<sensor name="camera" type="camera">
<pose>1 0 1.3 0 0 0</pose>
<camera>
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>320</width>
<height>240</height>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>false</visualize>
<topic>camera</topic>
</sensor>
<visual name="sphere">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
<material>
<ambient>0.3 0.3 0.3 1</ambient>
<diffuse>0.3 0.3 0.3 1</diffuse>
<specular>0.3 0.3 0.3 1</specular>
<emmisive>0.3 0.3 0.3 1</emmisive>
</material>
</visual>
</link>
</model>
</world>
</sdf>

0 comments on commit f05004a

Please sign in to comment.