Add defaults to attach tests.

PiperOrigin-RevId: 627526669
Change-Id: I5fc7955bacc459c637fce8e88e9da7bbfd7fb011
This commit is contained in:
Yuval Tassa
2024-04-23 15:40:03 -07:00
committed by Copybara-Service
parent d15db54537
commit 80810391ab
+59 -10
View File
@@ -36,7 +36,7 @@ using ::testing::HasSubstr;
using ::testing::NotNull; using ::testing::NotNull;
// ----------------------------- test set/get -------------------------------- // ----------------------------- test set/get ---------------------------------
TEST_F(MujocoTest, ReadWriteData) { TEST_F(MujocoTest, ReadWriteData) {
mjSpec* spec = mjs_createSpec(); mjSpec* spec = mjs_createSpec();
@@ -63,7 +63,7 @@ TEST_F(MujocoTest, ReadWriteData) {
mjs_deleteSpec(spec); mjs_deleteSpec(spec);
} }
// ------------------- test recompilation multiple files ---------------------- // ------------------- test recompilation multiple files -----------------------
TEST_F(PluginTest, RecompileCompare) { TEST_F(PluginTest, RecompileCompare) {
mjtNum tol = 0; mjtNum tol = 0;
std::string field = ""; std::string field = "";
@@ -195,15 +195,21 @@ TEST_F(PluginTest, RecompileCompareCache) {
mj_deleteVFS(vfs.get()); mj_deleteVFS(vfs.get());
} }
// -------------------------------- test attach ------------------------------- // -------------------------------- test attach --------------------------------
static constexpr char xml_child[] = R"( static constexpr char xml_child[] = R"(
<mujoco> <mujoco>
<default>
<default class="cylinder">
<geom type="cylinder" size=".1 1 0"/>
</default>
</default>
<worldbody> <worldbody>
<frame name="pframe"> <frame name="pframe">
<frame name="cframe"> <frame name="cframe">
<body name="body"> <body name="body">
<joint type="hinge" name="hinge"/> <joint type="hinge" name="hinge"/>
<geom type="cylinder" size=".1 1 0"/> <geom class="cylinder"/>
<light mode="targetbody" target="targetbody"/> <light mode="targetbody" target="targetbody"/>
<body name="targetbody"/> <body name="targetbody"/>
<body/> <body/>
@@ -213,19 +219,23 @@ static constexpr char xml_child[] = R"(
<body name="ignore"/> <body name="ignore"/>
<frame name="frame" pos=".1 0 0" euler="0 90 0"/> <frame name="frame" pos=".1 0 0" euler="0 90 0"/>
</worldbody> </worldbody>
<sensor> <sensor>
<framepos name="sensor" objtype="body" objname="body"/> <framepos name="sensor" objtype="body" objname="body"/>
<framepos name="ignore" objtype="body" objname="ignore"/> <framepos name="ignore" objtype="body" objname="ignore"/>
</sensor> </sensor>
<tendon> <tendon>
<fixed name="fixed"> <fixed name="fixed">
<joint joint="hinge" coef="2"/> <joint joint="hinge" coef="2"/>
</fixed> </fixed>
</tendon> </tendon>
<actuator> <actuator>
<position name="hinge" joint="hinge"/> <position name="hinge" joint="hinge"/>
<position name="fixed" tendon="fixed"/> <position name="fixed" tendon="fixed"/>
</actuator> </actuator>
<contact> <contact>
<exclude body1="body" body2="targetbody"/> <exclude body1="body" body2="targetbody"/>
</contact> </contact>
@@ -238,10 +248,16 @@ TEST_F(MujocoTest, AttachSame) {
static constexpr char xml_result[] = R"( static constexpr char xml_result[] = R"(
<mujoco> <mujoco>
<default>
<default class="cylinder">
<geom type="cylinder" size=".1 1 0"/>
</default>
</default>
<worldbody> <worldbody>
<body name="body"> <body name="body">
<joint type="hinge" name="hinge"/> <joint type="hinge" name="hinge"/>
<geom type="cylinder" size=".1 1 0"/> <geom class="cylinder"/>
<light mode="targetbody" target="targetbody"/> <light mode="targetbody" target="targetbody"/>
<body name="targetbody"/> <body name="targetbody"/>
<body/> <body/>
@@ -250,18 +266,20 @@ TEST_F(MujocoTest, AttachSame) {
<frame name="frame" pos=".1 0 0" euler="0 90 0"> <frame name="frame" pos=".1 0 0" euler="0 90 0">
<body name="attached-body-1"> <body name="attached-body-1">
<joint type="hinge" name="attached-hinge-1"/> <joint type="hinge" name="attached-hinge-1"/>
<geom type="cylinder" size=".1 1 0"/> <geom class="cylinder"/>
<light mode="targetbody" target="attached-targetbody-1"/> <light mode="targetbody" target="attached-targetbody-1"/>
<body name="attached-targetbody-1"/> <body name="attached-targetbody-1"/>
<body/> <body/>
</body> </body>
</frame> </frame>
</worldbody> </worldbody>
<sensor> <sensor>
<framepos name="sensor" objtype="body" objname="body"/> <framepos name="sensor" objtype="body" objname="body"/>
<framepos name="ignore" objtype="body" objname="ignore"/> <framepos name="ignore" objtype="body" objname="ignore"/>
<framepos name="attached-sensor-1" objtype="body" objname="attached-body-1"/> <framepos name="attached-sensor-1" objtype="body" objname="attached-body-1"/>
</sensor> </sensor>
<tendon> <tendon>
<fixed name="fixed"> <fixed name="fixed">
<joint joint="hinge" coef="2"/> <joint joint="hinge" coef="2"/>
@@ -270,12 +288,14 @@ TEST_F(MujocoTest, AttachSame) {
<joint joint="attached-hinge-1" coef="2"/> <joint joint="attached-hinge-1" coef="2"/>
</fixed> </fixed>
</tendon> </tendon>
<actuator> <actuator>
<position name="hinge" joint="hinge"/> <position name="hinge" joint="hinge"/>
<position name="fixed" tendon="fixed"/> <position name="fixed" tendon="fixed"/>
<position name="attached-hinge-1" joint="attached-hinge-1"/> <position name="attached-hinge-1" joint="attached-hinge-1"/>
<position name="attached-fixed-1" tendon="attached-fixed-1"/> <position name="attached-fixed-1" tendon="attached-fixed-1"/>
</actuator> </actuator>
<contact> <contact>
<exclude body1="body" body2="targetbody"/> <exclude body1="body" body2="targetbody"/>
<exclude body1="attached-body-1" body2="attached-targetbody-1"/> <exclude body1="attached-body-1" body2="attached-targetbody-1"/>
@@ -328,10 +348,16 @@ TEST_F(MujocoTest, AttachDifferent) {
static constexpr char xml_parent[] = R"( static constexpr char xml_parent[] = R"(
<mujoco> <mujoco>
<default>
<default class="geom_size">
<geom size="0.1"/>
</default>
</default>
<worldbody> <worldbody>
<body name="sphere"> <body name="sphere">
<freejoint/> <freejoint/>
<geom size=".1"/> <geom class="geom_size"/>
<frame name="frame" pos=".1 0 0" euler="0 90 0"/> <frame name="frame" pos=".1 0 0" euler="0 90 0"/>
</body> </body>
</worldbody> </worldbody>
@@ -339,14 +365,23 @@ TEST_F(MujocoTest, AttachDifferent) {
static constexpr char xml_result[] = R"( static constexpr char xml_result[] = R"(
<mujoco> <mujoco>
<default>
<default class="geom_size">
<geom size="0.1"/>
</default>
<default class="attached-cylinder-1">
<geom type="cylinder" size=".1 1 0"/>
</default>
</default>
<worldbody> <worldbody>
<body name="sphere"> <body name="sphere">
<freejoint/> <freejoint/>
<geom size=".1"/> <geom class="geom_size"/>
<frame name="frame" pos=".1 0 0" euler="0 90 0"> <frame name="frame" pos=".1 0 0" euler="0 90 0">
<body name="attached-body-1"> <body name="attached-body-1">
<joint type="hinge" name="attached-hinge-1"/> <joint type="hinge" name="attached-hinge-1"/>
<geom type="cylinder" size=".1 1 0"/> <geom class="attached-cylinder-1"/>
<light mode="targetbody" target="attached-targetbody-1"/> <light mode="targetbody" target="attached-targetbody-1"/>
<body name="attached-targetbody-1"/> <body name="attached-targetbody-1"/>
<body/> <body/>
@@ -354,18 +389,22 @@ TEST_F(MujocoTest, AttachDifferent) {
</frame> </frame>
</body> </body>
</worldbody> </worldbody>
<sensor> <sensor>
<framepos name="attached-sensor-1" objtype="body" objname="attached-body-1"/> <framepos name="attached-sensor-1" objtype="body" objname="attached-body-1"/>
</sensor> </sensor>
<tendon> <tendon>
<fixed name="attached-fixed-1"> <fixed name="attached-fixed-1">
<joint joint="attached-hinge-1" coef="2"/> <joint joint="attached-hinge-1" coef="2"/>
</fixed> </fixed>
</tendon> </tendon>
<actuator> <actuator>
<position name="attached-hinge-1" joint="attached-hinge-1"/> <position name="attached-hinge-1" joint="attached-hinge-1"/>
<position name="attached-fixed-1" tendon="attached-fixed-1"/> <position name="attached-fixed-1" tendon="attached-fixed-1"/>
</actuator> </actuator>
<contact> <contact>
<exclude body1="attached-body-1" body2="attached-targetbody-1"/> <exclude body1="attached-body-1" body2="attached-targetbody-1"/>
</contact> </contact>
@@ -433,6 +472,12 @@ TEST_F(MujocoTest, AttachFrame) {
static constexpr char xml_result[] = R"( static constexpr char xml_result[] = R"(
<mujoco> <mujoco>
<default>
<default class="attached-cylinder-1">
<geom type="cylinder" size=".1 1 0"/>
</default>
</default>
<worldbody> <worldbody>
<body name="sphere"> <body name="sphere">
<freejoint/> <freejoint/>
@@ -442,7 +487,7 @@ TEST_F(MujocoTest, AttachFrame) {
<frame name="cframe"> <frame name="cframe">
<body name="attached-body-1"> <body name="attached-body-1">
<joint type="hinge" name="attached-hinge-1"/> <joint type="hinge" name="attached-hinge-1"/>
<geom type="cylinder" size=".1 1 0"/> <geom class="attached-cylinder-1"/>
<light mode="targetbody" target="attached-targetbody-1"/> <light mode="targetbody" target="attached-targetbody-1"/>
<body name="attached-targetbody-1"/> <body name="attached-targetbody-1"/>
<body/> <body/>
@@ -451,18 +496,22 @@ TEST_F(MujocoTest, AttachFrame) {
</frame> </frame>
</body> </body>
</worldbody> </worldbody>
<sensor> <sensor>
<framepos name="attached-sensor-1" objtype="body" objname="attached-body-1"/> <framepos name="attached-sensor-1" objtype="body" objname="attached-body-1"/>
</sensor> </sensor>
<tendon> <tendon>
<fixed name="attached-fixed-1"> <fixed name="attached-fixed-1">
<joint joint="attached-hinge-1" coef="2"/> <joint joint="attached-hinge-1" coef="2"/>
</fixed> </fixed>
</tendon> </tendon>
<actuator> <actuator>
<position name="attached-hinge-1" joint="attached-hinge-1"/> <position name="attached-hinge-1" joint="attached-hinge-1"/>
<position name="attached-fixed-1" tendon="attached-fixed-1"/> <position name="attached-fixed-1" tendon="attached-fixed-1"/>
</actuator> </actuator>
<contact> <contact>
<exclude body1="attached-body-1" body2="attached-targetbody-1"/> <exclude body1="attached-body-1" body2="attached-targetbody-1"/>
</contact> </contact>