Throw an error if multiple orientation specifiers are used in the same element.

- Applies to [orientation specifiers](https://mujoco.readthedocs.io/en/latest/modeling.html#frame-orientations) in `body`, `inertial`, `geom`, `site`, `camera`.
- Before this change the check was done only for multiple *alternative* specifiers, but not for `quat` and an alternative specifier.
- Moved the check from the compiler to the parser.
- Added tests.

PiperOrigin-RevId: 453201981
Change-Id: I20907361f211dae904e734cd083e9df0efe4f654
This commit is contained in:
Alessio Quaglino
2022-06-06 08:12:32 -07:00
committed by Copybara-Service
parent 652bab3eec
commit 16baac9353
4 changed files with 52 additions and 16 deletions
+43
View File
@@ -192,6 +192,49 @@ TEST_F(UserDataTest, AllowsSpaces) {
mj_deleteModel(model);
}
TEST_F(UserDataTest, InvalidDoubleOrientation) {
std::string prefix = "<mujoco><worldbody><";
std::string suffix = "/></worldbody></mujoco>";
std::vector<std::string> orientations = {
R"( quat="0 1 0 0" )",
R"( euler="1.7 2.9 0.1" )",
R"( zaxis="1.7 2.9 0.1" )",
R"( axisangle="1.7 2.9 0.1 0" )",
R"( xyaxes="1.7 2.9 0.1 0.4 1.4 0.6" )",
};
std::vector<std::string> fields = {
"geom", "body", "camera", "site"
};
for (auto const& field : fields) {
for (auto const& orient1 : orientations) {
for (auto const& orient2 : orientations) {
if (orient1 == orient2) continue;
std::string xml = prefix + field + orient1 + orient2 + suffix;
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml.c_str(), error.data(), error.size());
ASSERT_THAT(model, IsNull());
EXPECT_THAT(error.data(), HasSubstr("multiple orientation specifiers for the same field"));
}
}
}
}
TEST_F(UserDataTest, InvalidInertialOrientation) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body>
<inertial pos="0 0 0" mass="1" quat="1 0 0 0" fullinertia="1 1 1 0 0 0"/>
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, IsNull());
EXPECT_THAT(error.data(), HasSubstr("multiple orientation specifiers for the same field"));
}
// ------------- test relative frame sensor parsing ----------------------------
using RelativeFrameSensorParsingTest = MujocoTest;