// Copyright 2021 DeepMind Technologies Limited // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Tests for user/user_objects.cc. #include #include #include #include #include #include #include #include #include #include "test/fixture.h" namespace mujoco { namespace { using MjCMeshTest = MujocoTest; // yuval: why do we want these anyway? why not string literals in the tests? // this does not improve readabillity IMO. static const char* const kDuplicateVerticesPath = "user/testdata/duplicate_vertices.xml"; static const char* const kCubePath = "user/testdata/cube.xml"; static const char* const kTorusPath = "user/testdata/torus.xml"; static const char* const kTorusQuadsPath = "user/testdata/torus_quads.xml"; static const char* const kTexturedTorusPath = "user/testdata/textured_torus.xml"; static const char* const kDuplicateOBJPath = "user/testdata/duplicate.xml"; // ------------- test vertex de-duplication (STL) ------------------------------ TEST_F(MjCMeshTest, DeDuplicateSTLVertices) { const std::string xml_path = GetTestDataFilePath(kDuplicateVerticesPath); char error[1024]; size_t error_sz = 1024; mjModel* model = mj_loadXML(xml_path.c_str(), 0, error, error_sz); ASSERT_EQ(model->nmeshvert, 4); mj_deleteModel(model); } // ------------- test OBJ loading ---------------------------------------------- using MjCMeshTest = MujocoTest; TEST_F(MjCMeshTest, LoadCube) { const std::string xml_path = GetTestDataFilePath(kCubePath); mjModel* model = mj_loadXML(xml_path.c_str(), 0, nullptr, 0); ASSERT_GT(model->ngeom, 0); ASSERT_EQ(model->nmeshvert, 8); mj_deleteModel(model); } TEST_F(MjCMeshTest, LoadTorus) { const std::string xml_path = GetTestDataFilePath(kTorusPath); std::array error; mjModel* model = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size()); ASSERT_GT(model->ngeom, 0); ASSERT_GT(model->nmeshvert, 0); mj_deleteModel(model); } TEST_F(MjCMeshTest, LoadTorusQuads) { const std::string xml_path = GetTestDataFilePath(kTorusQuadsPath); std::array error; mjModel* model = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size()); ASSERT_GT(model->ngeom, 0); ASSERT_GT(model->nmeshvert, 0); mj_deleteModel(model); } TEST_F(MjCMeshTest, LoadTexturedTorus) { const std::string xml_path = GetTestDataFilePath(kTexturedTorusPath); std::array error; mjModel* model = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size()); ASSERT_GT(model->ngeom, 0); ASSERT_GT(model->nmeshvert, 0); ASSERT_GT(model->ntex, 0); ASSERT_GT(model->ntexdata, 0); mj_deleteModel(model); } TEST_F(MjCMeshTest, KeepDuplicateOBJVertices) { const std::string xml_path = GetTestDataFilePath(kDuplicateOBJPath); char error[1024]; size_t error_sz = 1024; mjModel* model = mj_loadXML(xml_path.c_str(), 0, error, error_sz); ASSERT_EQ(model->nmeshvert, 12); mj_deleteModel(model); } TEST_F(MjCMeshTest, SaveMeshOnce) { const std::string xml_path = GetTestDataFilePath(kCubePath); std::array error; mjModel* model = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size()); std::string saved_xml = SaveAndReadXml(model); EXPECT_THAT(saved_xml, Not(testing::HasSubstr("vertex"))); mj_deleteModel(model); } } // namespace } // namespace mujoco