Robotics StackExchange | Archived questions

Unitesting Gazebo Model Plugin

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 :

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

Asked by Teusner on 2021-09-07 08:29:26 UTC

Comments

Answers