Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Ensure removed SDFormat elements raise errors in newer versions #490

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions test/integration/unknown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,55 @@ TEST(UnrecognizedElements, UnrecognizedElementsWithNamespaces)
const auto errors = root.Load(testFile, config);
EXPECT_TRUE(errors.empty());
}

/////////////////////////////////////////////////
/// Test that elements that aren't part of the version of the spec
/// cause an error (#327) - e.g. something that was valid in SDFormat 1.6 but
/// not in SDFormat>=1.7 (https://git.io/JtKKb).
TEST(UnrecognizedElements, OldElementsInNewSchemas)
{
// This should be valid in 1.6, but not in 1.8 (do to usage of
// `use_parent_model_frame`).
auto make_model_xml_string = [](std::string version)
{
return R"(
<?xml version="1.0" ?>
<sdf version=")" + version + R"(">
<model name="default">
<joint name="joint_WA" type="revolute">
<parent>world</parent>
<child>A</child>
<axis>
<xyz>0 1 0</xyz>
<use_parent_model_frame>1</use_parent_model_frame>
</axis>
</joint>
<link name="A"/>
</model>
</sdf>)";
};

sdf::ParserConfig config;
config.SetUnrecognizedElementsPolicy(sdf::EnforcementPolicy::ERR);

// Valid in 1.6.
{
sdf::Root root;
const auto errors = root.LoadSdfString(
make_model_xml_string("1.6"), config);
ASSERT_TRUE(errors.empty());
}

// Invalid in >=1.7.
{
sdf::Root root;
const auto errors = root.LoadSdfString(
make_model_xml_string("1.8"), config);
ASSERT_EQ(errors.size(), 1u);
constexpr char expectedMessage[] =
"XML Element[use_parent_model_frame], child of element[axis], not "
"defined in SDF. Copying[use_parent_model_frame] as children of "
"[axis].\n";
EXPECT_EQ(errors[0].Message(), expectedMessage);
}
}