Allow detaching from a compiled model.

PiperOrigin-RevId: 638299270
Change-Id: I944d2a24578b63463eddfa55d89f39fcfbafd2b4
This commit is contained in:
Alessio Quaglino
2024-05-29 08:46:19 -07:00
committed by Copybara-Service
parent 195bd32aa6
commit dec55b59fa
2 changed files with 47 additions and 13 deletions
+10 -1
View File
@@ -650,7 +650,7 @@ TEST_F(MujocoTest, AttachFrame) {
mj_deleteModel(m_expected);
}
TEST_F(MujocoTest, DetachBody) {
void TestDetachBody(bool compile) {
std::array<char, 1000> er;
mjtNum tol = 0;
std::string field = "";
@@ -679,6 +679,9 @@ TEST_F(MujocoTest, DetachBody) {
mjSpec* child = ParseSpecFromString(xml_child, er.data(), er.size());
EXPECT_THAT(child, NotNull()) << er.data();
// compile model (for testing double compilation)
mjModel* m_child = compile ? mjs_compile(child, 0) : nullptr;
// get subtree
mjsBody* body = mjs_findBody(child, "body");
EXPECT_THAT(body, NotNull());
@@ -701,6 +704,12 @@ TEST_F(MujocoTest, DetachBody) {
mjs_deleteSpec(child);
mj_deleteModel(m_detached);
mj_deleteModel(m_expected);
if (m_child) mj_deleteModel(m_child);
}
TEST_F(MujocoTest, DetachBody) {
TestDetachBody(/*compile=*/false);
TestDetachBody(/*compile=*/true);
}
} // namespace