From e7ed1ca1e0b149bd6279862693213da4da79cf1d Mon Sep 17 00:00:00 2001 From: Martin Schultz Date: Thu, 14 Apr 2016 12:52:21 +0200 Subject: [PATCH 1/4] fixes #17 by removing the swap of len in string serialization specification --- src/OpenMesh/Core/IO/SR_binary_spec.hh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/OpenMesh/Core/IO/SR_binary_spec.hh b/src/OpenMesh/Core/IO/SR_binary_spec.hh index 25e2a1e6..956b6e8f 100644 --- a/src/OpenMesh/Core/IO/SR_binary_spec.hh +++ b/src/OpenMesh/Core/IO/SR_binary_spec.hh @@ -238,8 +238,6 @@ template <> struct binary< std::string > { { length_t len = length_t(_v.size()); - if (_swap) reverse_byte_order(len); - size_t bytes = binary::store( _os, len, _swap ); _os.write( _v.data(), len ); return _os.good() ? len+bytes : 0; @@ -252,8 +250,6 @@ template <> struct binary< std::string > { { length_t len; size_t bytes = binary::restore( _is, len, _swap ); - if (_swap) - reverse_byte_order(len); _val.resize(len); _is.read( const_cast(_val.data()), len ); From 7e1d9e0c168669a702f80dca541310ef5f5faaf3 Mon Sep 17 00:00:00 2001 From: Martin Schultz Date: Thu, 14 Apr 2016 12:54:50 +0200 Subject: [PATCH 2/4] adds unittests for binary serialization of strings --- src/Unittests/unittests_sr_binary.cc | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/Unittests/unittests_sr_binary.cc diff --git a/src/Unittests/unittests_sr_binary.cc b/src/Unittests/unittests_sr_binary.cc new file mode 100644 index 00000000..dbfc38e6 --- /dev/null +++ b/src/Unittests/unittests_sr_binary.cc @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +namespace { + +class OpenMeshSRBinary : public testing::Test { + + protected: + + // This function is called before each test is run + virtual void SetUp() { + + // Do some initial stuff with the member data here... + } + + // This function is called after all tests are through + virtual void TearDown() { + + // Do some final stuff with the member data here... + } + +}; + + + +/* + * ==================================================================== + * Define tests below + * ==================================================================== + */ + +/* Check if len is swapped correctly + * when storing strings using the binary serializer. + * + */ +TEST_F(OpenMeshSRBinary, CheckStringSwap) { + std::string testString = "OpenMesh String"; + std::stringstream stream(""); + OpenMesh::IO::binary::store(stream,testString,true); + std::stringstream stream2(""); + OpenMesh::IO::binary::store(stream2,testString,false); + std::string res2 = stream2.str(); + std::string res = stream.str(); + uint16_t len, len2; + stream.read((char*)&len,2); + + stream2.read( (char*)&len2,2); + + EXPECT_EQ(len2,testString.length()); + EXPECT_EQ(len,(testString.length()>>8)|(testString.length()<<8)); + EXPECT_NE(len,len2); +} + +/* Check if storing and restoring a string gives proper result + * Do that with and without swapping the byte order + */ +TEST_F(OpenMeshSRBinary, StringStoreRestore) { + + + std::string testString = "OpenMesh String"; + std::stringstream stream(""); + OpenMesh::IO::binary::store(stream,testString,true); + std::stringstream stream2(""); + OpenMesh::IO::binary::store(stream2,testString,false); + + + std::string restored1, restored2; + OpenMesh::IO::binary::restore(stream, restored1 , true); + OpenMesh::IO::binary::restore(stream2, restored2 , false); + + EXPECT_EQ(restored1.length(), restored2.length()); + EXPECT_EQ(restored1.length(), testString.length()); + for(size_t i = 0 ; i < testString.length() ; ++i) + { + EXPECT_EQ(restored1[i] , testString[i]); + EXPECT_EQ(restored2[i] , testString[i]); + } + + +} + + + +} From 0a0d7e1fad1b2a6cc79aaf29de4a4bbdccf2205e Mon Sep 17 00:00:00 2001 From: Martin Schultz Date: Thu, 14 Apr 2016 13:06:17 +0200 Subject: [PATCH 3/4] fix c++98 compiler error on gcc --- src/Unittests/unittests_sr_binary.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Unittests/unittests_sr_binary.cc b/src/Unittests/unittests_sr_binary.cc index dbfc38e6..36115d86 100644 --- a/src/Unittests/unittests_sr_binary.cc +++ b/src/Unittests/unittests_sr_binary.cc @@ -2,6 +2,8 @@ #include #include #include +#include + namespace { From 6c14c0fc5ec1cf2f59ffd245a0836b90ff073b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Thu, 14 Apr 2016 15:19:05 +0200 Subject: [PATCH 4/4] Updated changelog --- Doc/changelog.docu | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/changelog.docu b/Doc/changelog.docu index 820466d7..d5275e01 100644 --- a/Doc/changelog.docu +++ b/Doc/changelog.docu @@ -94,6 +94,7 @@ IO
  • OMWriter: fix crash in OMWriter when writing an empty mesh with colors
  • +
  • Binary writers: Fixed double swap in string specialization. Added Unittest.
VectorT