@@ -51,20 +51,39 @@ class MeshInertiaCalculationTest : public InternalFixture<::testing::Test>
51
51
{
52
52
};
53
53
54
- TEST (MeshInertiaCalculationTest, CylinderColladaMeshInertiaCalculation)
54
+ // / \brief Load an SDF world and run mesh inertia tests. Two tests are run
55
+ // / one after another: 1) the server is launched with path to SDF file, and
56
+ // / 2) ther server is launched from an sdf string.
57
+ // / \param[in] _path Path to SDF
58
+ // / \param[in] _testFunc Test function that checks mesh inertia values
59
+ void loadSdfAndTest (const std::string &_path,
60
+ std::function<void (const gz::sim::ServerConfig &)> _testFunc)
55
61
{
56
- size_t kIter = 100u ;
57
-
58
- // Start server and run.
62
+ // Test mesh inertial calculator with sdf loaded from file
59
63
gz::sim::ServerConfig serverConfig;
60
- serverConfig.SetSdfFile (common::joinPaths (
61
- PROJECT_SOURCE_PATH, " test" , " worlds" , " mesh_inertia_calculation.sdf" ));
62
-
64
+ serverConfig.SetSdfFile (_path);
63
65
common::setenv (
64
66
" GZ_SIM_RESOURCE_PATH" ,
65
67
common::joinPaths (PROJECT_SOURCE_PATH, " test" , " worlds" , " models" ));
68
+ _testFunc (serverConfig);
66
69
67
- gz::sim::Server server (serverConfig);
70
+
71
+ // Test mesh inertial calculator with sdf loaded from string
72
+ std::ifstream sdfFile (_path);
73
+ std::stringstream buffer;
74
+ buffer << sdfFile.rdbuf ();
75
+ gz::sim::ServerConfig serverConfigSdfStr;
76
+ serverConfigSdfStr.SetSdfString (buffer.str ());
77
+ _testFunc (serverConfigSdfStr);
78
+ }
79
+
80
+ void cylinderColladaMeshInertiaCalculation (
81
+ const gz::sim::ServerConfig &_serverConfig)
82
+ {
83
+ size_t kIter = 100u ;
84
+
85
+ // Start server and run.
86
+ gz::sim::Server server (_serverConfig);
68
87
69
88
// Create a system just to get the ECM
70
89
EntityComponentManager *ecm;
@@ -127,21 +146,20 @@ TEST(MeshInertiaCalculationTest, CylinderColladaMeshInertiaCalculation)
127
146
EXPECT_EQ (link .WorldInertialPose (*ecm).value (), gz::math::Pose3d::Zero);
128
147
}
129
148
130
- TEST (MeshInertiaCalculationTest,
131
- CylinderColladaMeshWithNonCenterOriginInertiaCalculation)
149
+ TEST (MeshInertiaCalculationTest, CylinderColladaMeshInertiaCalculation)
150
+ {
151
+ std::string sdfFilePath = common::joinPaths (
152
+ PROJECT_SOURCE_PATH, " test" , " worlds" , " mesh_inertia_calculation.sdf" );
153
+ loadSdfAndTest (sdfFilePath, cylinderColladaMeshInertiaCalculation);
154
+ }
155
+
156
+ void cylinderColladaMeshWithNonCenterOriginInertiaCalculation (
157
+ const gz::sim::ServerConfig &_serverConfig)
132
158
{
133
159
size_t kIter = 100u ;
134
160
135
161
// Start server and run.
136
- gz::sim::ServerConfig serverConfig;
137
- serverConfig.SetSdfFile (common::joinPaths (
138
- PROJECT_SOURCE_PATH, " test" , " worlds" , " mesh_inertia_calculation.sdf" ));
139
-
140
- common::setenv (
141
- " GZ_SIM_RESOURCE_PATH" ,
142
- common::joinPaths (PROJECT_SOURCE_PATH, " test" , " worlds" , " models" ));
143
-
144
- gz::sim::Server server (serverConfig);
162
+ gz::sim::Server server (_serverConfig);
145
163
146
164
// Create a system just to get the ECM
147
165
EntityComponentManager *ecm;
@@ -207,6 +225,16 @@ TEST(MeshInertiaCalculationTest,
207
225
// the center of mass (inertial pose) will be 1m above the ground
208
226
EXPECT_EQ (link .WorldInertialPose (*ecm).value (),
209
227
gz::math::Pose3d (0 , 0 , 1 , 0 , 0 , 0 ));
228
+
229
+ }
230
+
231
+ TEST (MeshInertiaCalculationTest,
232
+ CylinderColladaMeshWithNonCenterOriginInertiaCalculation)
233
+ {
234
+ std::string sdfFilePath = common::joinPaths (
235
+ PROJECT_SOURCE_PATH, " test" , " worlds" , " mesh_inertia_calculation.sdf" );
236
+
237
+ loadSdfAndTest (sdfFilePath, cylinderColladaMeshInertiaCalculation);
210
238
}
211
239
212
240
TEST (MeshInertiaCalculationTest, CylinderColladaOptimizedMeshInertiaCalculation)
0 commit comments