Add missing default namespaces.

Fixes #2162.

PiperOrigin-RevId: 688575676
Change-Id: I6c43e33ebead68dece0f779e6f031e90a5e19096
This commit is contained in:
Alessio Quaglino
2024-10-22 09:15:29 -07:00
committed by Copybara-Service
parent 708fd83a49
commit 4a3f77dd1f
2 changed files with 57 additions and 40 deletions
+47
View File
@@ -14,6 +14,7 @@
// Tests for xml/xml_native_writer.cc.
#include <memory>
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#endif
@@ -1476,5 +1477,51 @@ TEST_F(DecompilerTest, VeryLargeNumbers) {
mj_deleteModel(model);
}
TEST_F(XMLWriterTest, ExpandAttach) {
static constexpr char xml_parent[] = R"(
<mujoco>
<asset>
<model name="b" file="b.xml" />
</asset>
<worldbody>
<attach model="b" body="b" prefix="b" />
</worldbody>
</mujoco>
)";
static constexpr char xml_child[] = R"(
<mujoco>
<default>
<default class="b"/>
</default>
<worldbody>
<body name="b">
<geom type="box" size="0.1 0.1 0.1"/>
<joint name="b"/>
</body>
</worldbody>
<actuator>
<position joint="b" class="b"/>
</actuator>
</mujoco>
)";
auto vfs = std::make_unique<mjVFS>();
mj_defaultVFS(vfs.get());
mj_addBufferVFS(vfs.get(), "b.xml", xml_child, sizeof(xml_child));
std::array<char, 1024> er;
mjModel* m = LoadModelFromString(xml_parent, er.data(), er.size(), vfs.get());
ASSERT_THAT(m, NotNull()) << er.data();
std::string saved_xml = SaveAndReadXml(m);
EXPECT_THAT(saved_xml, HasSubstr("class=\"bb\""));
mj_deleteModel(m);
mj_deleteVFS(vfs.get());
}
} // namespace
} // namespace mujoco