Hi,
I would like to test a Gazebo Model Plugin implemented for Gazebo 11 using gtest. The idea is to test sdf parsing at the plugin launch, in order to check that parameters are correctly parsed by the plugin and are set in the plugin private variables.
To do that, I need to provide a gazebo::physics::ModelPtr and a sdf::ElementPtr to the Load method of my plugin to test the parsing.
/// Gazebo calls this when the plugin is loaded.
/// \param[in] model Pointer to parent model.
/// \param[in] sdf SDF element containing user-defined parameters.
void Load(gazebo::physics::ModelPtr model, sdf::ElementPtr sdf);
I store an example SDF description of a functionnal world in a std::string variable of my test file in order to load it into an sdf::SDFPtr :
std::string sdf_world = R"( <?xml version="1.0"?>
<sdf version="1.7">
<world name="test">
<model name="cube">
...
<plugin name="..." filename="...">
<parameter>10</parameter>
</plugin>
</model>
</world>
</sdf>)";
// Creating sdf element pointer
sdf::SDFPtr worldSDF(new sdf::SDF);
worldSDF->SetFromString(sdf_world);
sdf::ElementPtr worldElem = worldSDF->Root()->GetElement("world");
Then I see two ways but nothing is working :
Create a
gazebo::physics::ModelPtr
, get ansdf::ElementPtr
to the plugin parameters in order to instanciate my plugin class and load these two object in theLoad
method, but I am not able to see what I need to provide as parentgazebo::physics::BasePtr
to instanciate theModelPtr
To avoid the previous problem, I think that instanciate a
gazebo::physics::WorldPtr
usinggazebo::physics::WorldPtr world = gazebo::physics::create_world("test");
andgazebo::physics::load_world(world, worldSDF->Root()->GetElement("world");
. Then I would be able to get Model by name using the standard api to get a ModelPtr to the cube in order to load it in an instance of my plugin, but thegazebo::physics::load_world
method is not working (it seems that's this method because when I'm commenting / decommenting only this line the test is passing and not passing ...)
The test did not generate a result file:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TestSuite
[ RUN ] TestSuite.testParameter
?[1;33mWarning [parser.cc:636]?[0m Converting a deprecated SDF source[data-string].
?[1;31mError [Element.cc:798]?[0m Missing element description for [scene]
Is there a better way to test the parameters parsing at my plugin load ?
If there is no better way could you help me to debug this test ?
Thanks in advance
Teusner