Merge branch 'fixDoubleSwap' into 'master'
Fix double swap See merge request !54
This commit is contained in:
@@ -109,6 +109,7 @@
|
|||||||
<b>IO</b>
|
<b>IO</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>OMWriter: fix crash in OMWriter when writing an empty mesh with colors</li>
|
<li>OMWriter: fix crash in OMWriter when writing an empty mesh with colors</li>
|
||||||
|
<li>Binary writers: Fixed double swap in string specialization. Added Unittest.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<b>VectorT</b>
|
<b>VectorT</b>
|
||||||
|
|||||||
@@ -238,8 +238,6 @@ template <> struct binary< std::string > {
|
|||||||
{
|
{
|
||||||
length_t len = length_t(_v.size());
|
length_t len = length_t(_v.size());
|
||||||
|
|
||||||
if (_swap) reverse_byte_order(len);
|
|
||||||
|
|
||||||
size_t bytes = binary<length_t>::store( _os, len, _swap );
|
size_t bytes = binary<length_t>::store( _os, len, _swap );
|
||||||
_os.write( _v.data(), len );
|
_os.write( _v.data(), len );
|
||||||
return _os.good() ? len+bytes : 0;
|
return _os.good() ? len+bytes : 0;
|
||||||
@@ -252,8 +250,6 @@ template <> struct binary< std::string > {
|
|||||||
{
|
{
|
||||||
length_t len;
|
length_t len;
|
||||||
size_t bytes = binary<length_t>::restore( _is, len, _swap );
|
size_t bytes = binary<length_t>::restore( _is, len, _swap );
|
||||||
if (_swap)
|
|
||||||
reverse_byte_order(len);
|
|
||||||
_val.resize(len);
|
_val.resize(len);
|
||||||
_is.read( const_cast<char*>(_val.data()), len );
|
_is.read( const_cast<char*>(_val.data()), len );
|
||||||
|
|
||||||
|
|||||||
88
src/Unittests/unittests_sr_binary.cc
Normal file
88
src/Unittests/unittests_sr_binary.cc
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <Unittests/unittests_common.hh>
|
||||||
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
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<std::string>::store(stream,testString,true);
|
||||||
|
std::stringstream stream2("");
|
||||||
|
OpenMesh::IO::binary<std::string>::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<std::string>::store(stream,testString,true);
|
||||||
|
std::stringstream stream2("");
|
||||||
|
OpenMesh::IO::binary<std::string>::store(stream2,testString,false);
|
||||||
|
|
||||||
|
|
||||||
|
std::string restored1, restored2;
|
||||||
|
OpenMesh::IO::binary<std::string>::restore(stream, restored1 , true);
|
||||||
|
OpenMesh::IO::binary<std::string>::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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user