|
24 | 24 | #include "sdf/Error.hh"
|
25 | 25 | #include "sdf/Param.hh"
|
26 | 26 | #include "sdf/Types.hh"
|
| 27 | +#include "sdf/World.hh" |
27 | 28 | #include "test_utils.hh"
|
| 29 | +#include "test_config.hh" |
28 | 30 |
|
29 | 31 | ////////////////////////////////////////
|
30 | 32 | // Test Param class for sdf::Errors outputs
|
@@ -243,3 +245,52 @@ TEST(ErrorOutput, PrintConfigErrorOutput)
|
243 | 245 | // Check nothing has been printed
|
244 | 246 | EXPECT_TRUE(buffer.str().empty()) << buffer.str();
|
245 | 247 | }
|
| 248 | + |
| 249 | +//////////////////////////////////////// |
| 250 | +// Test World class for sdf::Errors outputs |
| 251 | +TEST(ErrorOutput, WorldErrorOutput) |
| 252 | +{ |
| 253 | + std::stringstream buffer; |
| 254 | + sdf::testing::RedirectConsoleStream redir( |
| 255 | + sdf::Console::Instance()->GetMsgStream(), &buffer); |
| 256 | + |
| 257 | + sdf::Errors errors; |
| 258 | + |
| 259 | + std::ostringstream stream; |
| 260 | + stream << "<?xml version=\"1.0\"?>" |
| 261 | + << "<sdf version='1.8'>" |
| 262 | + << " <world name='test_world'>" |
| 263 | + << " <model name='common_name'>" |
| 264 | + << " <link name='a'>" |
| 265 | + << " </link>" |
| 266 | + << " </model>" |
| 267 | + << " <model name='common_name'>" |
| 268 | + << " <link name='a'>" |
| 269 | + << " </link>" |
| 270 | + << " </model>" |
| 271 | + << " <frame name='common_name'/>" |
| 272 | + << " </world>" |
| 273 | + << "</sdf>"; |
| 274 | + |
| 275 | + sdf::SDFPtr sdfParsed(new sdf::SDF()); |
| 276 | + sdf::init(sdfParsed); |
| 277 | + |
| 278 | + sdf::ParserConfig parserConfig; |
| 279 | + parserConfig.SetWarningsPolicy(sdf::EnforcementPolicy::ERR); |
| 280 | + sdf::readString(stream.str(), parserConfig, sdfParsed, errors); |
| 281 | + EXPECT_TRUE(errors.empty()); |
| 282 | + |
| 283 | + sdf::World world; |
| 284 | + errors = world.Load(sdfParsed->Root()->GetElement("world"), parserConfig); |
| 285 | + ASSERT_EQ(errors.size(), 3u); |
| 286 | + EXPECT_NE(std::string::npos, errors[0].Message().find( |
| 287 | + "Non-unique name[common_name] detected 3 times in XML children of world" |
| 288 | + " with name[test_world].")); |
| 289 | + EXPECT_NE(std::string::npos, errors[1].Message().find( |
| 290 | + "model with name[common_name] already exists.")); |
| 291 | + EXPECT_NE(std::string::npos, errors[2].Message().find( |
| 292 | + "Frame with name [common_name] in world with name [test_world] has a name" |
| 293 | + " collision, changing frame name to [common_name_frame].")); |
| 294 | + // Check nothing has been printed |
| 295 | + EXPECT_TRUE(buffer.str().empty()) << buffer.str(); |
| 296 | +} |
0 commit comments