From 504b66c923a82a16ce4f3f0f587ee8e0b288635b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Thu, 24 Sep 2020 12:40:44 +0200 Subject: [PATCH] Added unittest to check for the space bool bug --- src/Unittests/unittests_read_write_OM.cc | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/Unittests/unittests_read_write_OM.cc b/src/Unittests/unittests_read_write_OM.cc index 35e4522d..2c437537 100644 --- a/src/Unittests/unittests_read_write_OM.cc +++ b/src/Unittests/unittests_read_write_OM.cc @@ -1509,4 +1509,62 @@ TEST_F(OpenMeshReadWriteOM, WriteAndLoadDoubles) { EXPECT_EQ(mesh.normal(OpenMesh::FaceHandle(0)), mesh2.normal(OpenMesh::FaceHandle(0))); } + + +/* + * Try to write and load bool property + */ +TEST_F(OpenMeshReadWriteOM, WriteAndLoadBoolCheckSpaces) { + + typedef OpenMesh::PolyMesh_ArrayKernelT DoublePolyMesh; + + DoublePolyMesh mesh; + + OpenMesh::VPropHandleT prop; + mesh.add_property(prop,"VBProp"); + mesh.property(prop).set_persistent(true); + + + // Generate a bool property which will be packed into a space character + + std::vector vertices; + for (unsigned int i = 0; i < 8; ++i) + { + vertices.push_back(mesh.add_vertex(DoublePolyMesh::Point(0.0, 0.0, 0.0))); + + if ( i == 5) + mesh.property(prop,vertices[i]) = true; + else + mesh.property(prop,vertices[i]) = false; + } + + std::string file_name = "bool-space-test.om"; + + OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default; + ASSERT_TRUE(OpenMesh::IO::write_mesh(mesh, file_name, opt)) << "Could not write file " << file_name; + + + // ==================================================== + // Now read it back + // ==================================================== + + DoublePolyMesh mesh2; + OpenMesh::VPropHandleT prop2; + mesh2.add_property(prop2,"VBProp"); + mesh2.property(prop2).set_persistent(true); + + ASSERT_TRUE(OpenMesh::IO::read_mesh(mesh2, file_name, opt)) << "Could not read file " << file_name; + + // Check if the property is still ok + for (unsigned int i = 0; i < 8; ++i) + { + if ( i == 5) + EXPECT_TRUE( mesh.property(prop,mesh2.vertex_handle((i)) ) ); + else + EXPECT_FALSE(mesh.property(prop,mesh2.vertex_handle((i)))); + } +} + + + }