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

Test included model folders missing model.config #422

Merged
merged 3 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ std::string getModelFilePath(const std::string &_modelDirPath)
if (!sdf::filesystem::exists(configFilePath))
{
// We didn't find manifest.xml either, output an error and get out.
sdferr << "Could not find model.config or manifest.xml for the model\n";
sdferr << "Could not find model.config or manifest.xml in ["
<< _modelDirPath << "]\n";
return std::string();
}
else
Expand Down Expand Up @@ -932,6 +933,15 @@ bool readXml(TiXmlElement *_xml, ElementPtr _sdf, Errors &_errors)

// Get the config.xml filename
filename = getModelFilePath(modelPath);

if (filename.empty())
{
_errors.push_back({ErrorCode::URI_LOOKUP,
chapulina marked this conversation as resolved.
Show resolved Hide resolved
"Unable to resolve uri[" + uri + "] to model path [" +
modelPath + "] since it does not contain a model.config " +
"file."});
continue;
}
}
else
{
Expand Down
37 changes: 37 additions & 0 deletions test/integration/includes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,40 @@ TEST(IncludesTest, Includes_15_convert)
EXPECT_EQ("1.6", modelElem->OriginalVersion());
EXPECT_EQ("1.6", linkElem->OriginalVersion());
}

//////////////////////////////////////////////////
TEST(IncludesTest, IncludeModelMissingConfig)
{
sdf::setFindCallback(findFileCb);

std::ostringstream stream;
stream
<< "<sdf version='" << SDF_VERSION << "'>"
<< "<include>"
<< " <uri>box_missing_config</uri>"
<< "</include>"
<< "</sdf>";

sdf::SDFPtr sdfParsed(new sdf::SDF());
sdf::init(sdfParsed);
sdf::Errors errors;
ASSERT_TRUE(sdf::readString(stream.str(), sdfParsed, errors));

ASSERT_GE(1u, errors.size());
EXPECT_EQ(1u, errors.size());
std::cout << errors[0] << std::endl;
EXPECT_EQ(errors[0].Code(), sdf::ErrorCode::URI_LOOKUP);
EXPECT_NE(std::string::npos, errors[0].Message().find(
"Unable to resolve uri[box_missing_config] to model path")) << errors[0];
EXPECT_NE(std::string::npos, errors[0].Message().find(
"box_missing_config] since it does not contain a model.config file"))
<< errors[0];

sdf::Root root;
errors = root.Load(sdfParsed);
for (auto e : errors)
std::cout << e.Message() << std::endl;
EXPECT_TRUE(errors.empty());
chapulina marked this conversation as resolved.
Show resolved Hide resolved

EXPECT_EQ(0u, root.ModelCount());
}
22 changes: 22 additions & 0 deletions test/integration/model/box_missing_config/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" ?>
<sdf version="1.5">
<model name="box">
<pose>0 0 0.5 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</visual>
</link>
</model>
</sdf>