Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenMesh
OpenMesh
Commits
7e1d9e0c
Commit
7e1d9e0c
authored
Apr 14, 2016
by
Martin Schultz
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds unittests for binary serialization of strings
parent
e7ed1ca1
Pipeline
#1255
failed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
src/Unittests/unittests_sr_binary.cc
src/Unittests/unittests_sr_binary.cc
+86
-0
No files found.
src/Unittests/unittests_sr_binary.cc
0 → 100644
View file @
7e1d9e0c
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <iostream>
#include <list>
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
]);
}
}
}
Martin Schultz
@schultz
mentioned in commit
80559431
·
Apr 14, 2016
mentioned in commit
80559431
mentioned in commit 80559431a596077c98acf5e9dd49ff946c2f81c7
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment