Skip to content

Commit

Permalink
Add failing test for #1182, deleting a light
Browse files Browse the repository at this point in the history
  • Loading branch information
scpeters committed May 8, 2014
1 parent c78886e commit 6c6baf4
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions test/integration/world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,73 @@ TEST_F(WorldTest, ModifyLight)
Load("worlds/empty.world");
physics::WorldPtr world = physics::get_world("default");
ASSERT_TRUE(world);
msgs::Scene sceneMsg = world->GetSceneMsg();

// Make sure there is only one light, and it is named "sun"
EXPECT_EQ(sceneMsg.light_size(), 1);
EXPECT_STREQ(sceneMsg.light(0).name().c_str(), "sun");
{
msgs::Scene sceneMsg = world->GetSceneMsg();
EXPECT_EQ(sceneMsg.light_size(), 1);
EXPECT_STREQ(sceneMsg.light(0).name().c_str(), "sun");
}

transport::PublisherPtr lightPub = this->node->Advertise<msgs::Light>(
"~/light");

// Set the light to be green
msgs::Light lightMsg;
lightMsg.set_name("sun");
msgs::Set(lightMsg.mutable_diffuse(), common::Color(0, 1, 0));
lightPub->Publish(lightMsg);
{
msgs::Light lightMsg;
lightMsg.set_name("sun");
msgs::Set(lightMsg.mutable_diffuse(), common::Color(0, 1, 0));
lightPub->Publish(lightMsg);
}

// Allow the world time to process the messages
world->Step(10);

// Get the new scene, and make sure the color of the "sun" light is
// correct.
msgs::Scene sceneMsg2 = world->GetSceneMsg();
EXPECT_EQ(sceneMsg2.light_size(), 1);
EXPECT_STREQ(sceneMsg2.light(0).name().c_str(), "sun");
EXPECT_EQ(sceneMsg2.light(0).diffuse().r(), 0);
EXPECT_EQ(sceneMsg2.light(0).diffuse().g(), 1);
EXPECT_EQ(sceneMsg2.light(0).diffuse().b(), 0);
{
msgs::Scene sceneMsg = world->GetSceneMsg();
EXPECT_EQ(sceneMsg.light_size(), 1);
EXPECT_STREQ(sceneMsg.light(0).name().c_str(), "sun");
EXPECT_EQ(sceneMsg.light(0).diffuse().r(), 0);
EXPECT_EQ(sceneMsg.light(0).diffuse().g(), 1);
EXPECT_EQ(sceneMsg.light(0).diffuse().b(), 0);
}

// Add a new light
lightMsg.set_name("test_light");
msgs::Set(lightMsg.mutable_diffuse(), common::Color(1, 0, 1));
lightMsg.set_type(msgs::Light::POINT);
lightPub->Publish(lightMsg);
{
msgs::Light lightMsg;
lightMsg.set_name("test_light");
msgs::Set(lightMsg.mutable_diffuse(), common::Color(1, 0, 1));
lightMsg.set_type(msgs::Light::POINT);
lightPub->Publish(lightMsg);
}

// Allow the world time to process the messages
world->Step(10);

sceneMsg2 = world->GetSceneMsg();
EXPECT_EQ(sceneMsg2.light_size(), 2);
EXPECT_STREQ(sceneMsg2.light(1).name().c_str(), "test_light");
EXPECT_EQ(sceneMsg2.light(1).diffuse().r(), 1);
EXPECT_EQ(sceneMsg2.light(1).diffuse().g(), 0);
EXPECT_EQ(sceneMsg2.light(1).diffuse().b(), 1);
EXPECT_EQ(sceneMsg2.light(1).type(), msgs::Light::POINT);
{
msgs::Scene sceneMsg = world->GetSceneMsg();
EXPECT_EQ(sceneMsg.light_size(), 2);
EXPECT_STREQ(sceneMsg.light(1).name().c_str(), "test_light");
EXPECT_EQ(sceneMsg.light(1).diffuse().r(), 1);
EXPECT_EQ(sceneMsg.light(1).diffuse().g(), 0);
EXPECT_EQ(sceneMsg.light(1).diffuse().b(), 1);
EXPECT_EQ(sceneMsg.light(1).type(), msgs::Light::POINT);
}

// Delete the test_light
ServerFixture::RemoveModel("test_light");

// Allow the world time to process the messages
world->Step(10);

// Verify that the test_light is gone and that the sun remains
{
msgs::Scene sceneMsg = world->GetSceneMsg();
EXPECT_EQ(sceneMsg.light_size(), 1);
EXPECT_STREQ(sceneMsg.light(0).name().c_str(), "sun");
}
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 6c6baf4

Please sign in to comment.